From c23b2cfe2c825c7c33bd2e1748dfe81160defed1 Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Wed, 19 Mar 2025 14:12:18 +0000 Subject: [PATCH 01/10] Add Smart Link Status taxonomy instead of relying on post meta --- build/content-helper/editor-sidebar.asset.php | 2 +- build/content-helper/editor-sidebar.js | 24 +- src/Models/class-inbound-smart-link.php | 12 +- src/Models/class-smart-link.php | 256 ++++++++++++------ .../smart-linking/class-smart-linking.php | 5 +- .../editor-sidebar/smart-linking/provider.ts | 8 + .../editor-sidebar/smart-linking/utils.ts | 1 + .../class-endpoint-smart-linking.php | 6 +- .../class-endpoint-traffic-boost.php | 4 +- 9 files changed, 209 insertions(+), 109 deletions(-) diff --git a/build/content-helper/editor-sidebar.asset.php b/build/content-helper/editor-sidebar.asset.php index 815956bf2a..4b38bcf1fb 100644 --- a/build/content-helper/editor-sidebar.asset.php +++ b/build/content-helper/editor-sidebar.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '90c4afecba6511c1d990'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => 'b8170c2ebb9580794bad'); diff --git a/build/content-helper/editor-sidebar.js b/build/content-helper/editor-sidebar.js index fc0b715bfa..6278a1b41a 100644 --- a/build/content-helper/editor-sidebar.js +++ b/build/content-helper/editor-sidebar.js @@ -1,20 +1,20 @@ -!function(){"use strict";var e={20:function(e,t,n){var r=n(609),i=Symbol.for("react.element"),o=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var r,o={},c=null,u=null;for(r in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)s.call(t,r)&&!l.hasOwnProperty(r)&&(o[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===o[r]&&(o[r]=t[r]);return{$$typeof:i,type:e,key:c,ref:u,props:o,_owner:a.current}}t.Fragment=o,t.jsx=c,t.jsxs=c},848:function(e,t,n){e.exports=n(20)},609:function(e){e.exports=window.React}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(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.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){n.d({},{w:function(){return Lr},_:function(){return Nr}});var e,t,r,i,o,s,a,l,c,u,p,d,f=n(848),h=window.wp.components,v=window.wp.data,g=window.wp.domReady,y=n.n(g),m=window.wp.element,w=window.wp.i18n,b=window.wp.primitives,x=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",d:"M11.25 5h1.5v15h-1.5V5zM6 10h1.5v10H6V10zm12 4h-1.5v6H18v-6z",clipRule:"evenodd"})}),_=window.wp.plugins;void 0!==window.wp&&(p=null!==(t=null===(e=window.wp.editor)||void 0===e?void 0:e.PluginDocumentSettingPanel)&&void 0!==t?t:null!==(i=null===(r=window.wp.editPost)||void 0===r?void 0:r.PluginDocumentSettingPanel)&&void 0!==i?i:null===(o=window.wp.editSite)||void 0===o?void 0:o.PluginDocumentSettingPanel,d=null!==(a=null===(s=window.wp.editor)||void 0===s?void 0:s.PluginSidebar)&&void 0!==a?a:null!==(c=null===(l=window.wp.editPost)||void 0===l?void 0:l.PluginSidebar)&&void 0!==c?c:null===(u=window.wp.editSite)||void 0===u?void 0:u.PluginSidebar);var k=function(){function e(){this._tkq=[],this.isLoaded=!1,this.isEnabled=!1,"undefined"!=typeof wpParselyTracksTelemetry&&(this.isEnabled=!0,this.loadTrackingLibrary())}return e.getInstance=function(){return window.wpParselyTelemetryInstance||Object.defineProperty(window,"wpParselyTelemetryInstance",{value:new e,writable:!1,configurable:!1,enumerable:!1}),window.wpParselyTelemetryInstance},e.prototype.loadTrackingLibrary=function(){var e=this,t=document.createElement("script");t.async=!0,t.src="//stats.wp.com/w.js",t.onload=function(){e.isLoaded=!0,e._tkq=window._tkq||[]},document.head.appendChild(t)},e.trackEvent=function(t){return n=this,r=arguments,o=function(t,n){var r;return void 0===n&&(n={}),function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]=1e4&&(clearInterval(o),n("Telemetry library not loaded"))}),100);else n("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,n){var r;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(n=this.prepareProperties(n),null===(r=this._tkq)||void 0===r||r.push(["recordEvent",t,n])):console.error("Error tracking event: Invalid event name")):console.error("Error tracking event: Telemetry not loaded")},e.prototype.isTelemetryEnabled=function(){return this.isEnabled},e.prototype.isProprietyValid=function(t){return e.PROPERTY_REGEX.test(t)},e.prototype.isEventNameValid=function(t){return e.EVENT_NAME_REGEX.test(t)},e.prototype.prepareProperties=function(e){return(e=this.sanitizeProperties(e)).parsely_version=wpParselyTracksTelemetry.version,wpParselyTracksTelemetry.user&&(e._ut=wpParselyTracksTelemetry.user.type,e._ui=wpParselyTracksTelemetry.user.id),wpParselyTracksTelemetry.vipgo_env&&(e.vipgo_env=wpParselyTracksTelemetry.vipgo_env),this.sanitizeProperties(e)},e.prototype.sanitizeProperties=function(e){var t=this,n={};return Object.keys(e).forEach((function(r){t.isProprietyValid(r)&&(n[r]=e[r])})),n},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),S=(k.trackEvent,function(){return(0,f.jsx)(h.SVG,{"aria-hidden":"true",version:"1.1",viewBox:"0 0 15 15",width:"15",height:"15",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(h.Path,{d:"M0 14.0025V11.0025L7.5 3.5025L10.5 6.5025L3 14.0025H0ZM12 5.0025L13.56 3.4425C14.15 2.8525 14.15 1.9025 13.56 1.3225L12.68 0.4425C12.09 -0.1475 11.14 -0.1475 10.56 0.4425L9 2.0025L12 5.0025Z"})})}),j=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{className:i,height:n,viewBox:"0 0 60 65",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M23.72,51.53c0-.18,0-.34-.06-.52a13.11,13.11,0,0,0-2.1-5.53A14.74,14.74,0,0,0,19.12,43c-.27-.21-.5-.11-.51.22l-.24,3.42c0,.33-.38.35-.49,0l-1.5-4.8a1.4,1.4,0,0,0-.77-.78,23.91,23.91,0,0,0-3.1-.84c-1.38-.24-3.39-.39-3.39-.39-.34,0-.45.21-.25.49l2.06,3.76c.2.27,0,.54-.29.33l-4.51-3.6a3.68,3.68,0,0,0-2.86-.48c-1,.16-2.44.46-2.44.46a.68.68,0,0,0-.39.25.73.73,0,0,0-.14.45S.41,43,.54,44a3.63,3.63,0,0,0,1.25,2.62L6.48,50c.28.2.09.49-.23.37l-4.18-.94c-.32-.12-.5,0-.4.37,0,0,.69,1.89,1.31,3.16a24,24,0,0,0,1.66,2.74,1.34,1.34,0,0,0,1,.52l5,.13c.33,0,.41.38.1.48L7.51,58c-.31.1-.34.35-.07.55a14.29,14.29,0,0,0,3.05,1.66,13.09,13.09,0,0,0,5.9.5,25.13,25.13,0,0,0,4.34-1,9.55,9.55,0,0,1-.08-1.2,9.32,9.32,0,0,1,3.07-6.91"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M59.7,41.53a.73.73,0,0,0-.14-.45.68.68,0,0,0-.39-.25s-1.43-.3-2.44-.46a3.64,3.64,0,0,0-2.86.48l-4.51,3.6c-.26.21-.49-.06-.29-.33l2.06-3.76c.2-.28.09-.49-.25-.49,0,0-2,.15-3.39.39a23.91,23.91,0,0,0-3.1.84,1.4,1.4,0,0,0-.77.78l-1.5,4.8c-.11.32-.48.3-.49,0l-.24-3.42c0-.33-.24-.43-.51-.22a14.74,14.74,0,0,0-2.44,2.47A13.11,13.11,0,0,0,36.34,51c0,.18,0,.34-.06.52a9.26,9.26,0,0,1,3,8.1,24.1,24.1,0,0,0,4.34,1,13.09,13.09,0,0,0,5.9-.5,14.29,14.29,0,0,0,3.05-1.66c.27-.2.24-.45-.07-.55l-3.22-1.17c-.31-.1-.23-.47.1-.48l5-.13a1.38,1.38,0,0,0,1-.52A24.6,24.6,0,0,0,57,52.92c.61-1.27,1.31-3.16,1.31-3.16.1-.33-.08-.49-.4-.37l-4.18.94c-.32.12-.51-.17-.23-.37l4.69-3.34A3.63,3.63,0,0,0,59.46,44c.13-1,.24-2.47.24-2.47"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M46.5,25.61c0-.53-.35-.72-.8-.43l-4.86,2.66c-.45.28-.56-.27-.23-.69l4.66-6.23a2,2,0,0,0,.28-1.68,36.51,36.51,0,0,0-2.19-4.89,34,34,0,0,0-2.81-3.94c-.33-.41-.74-.35-.91.16l-2.28,5.68c-.16.5-.6.48-.59-.05l.28-8.93a2.54,2.54,0,0,0-.66-1.64S35,4.27,33.88,3.27,30.78.69,30.78.69a1.29,1.29,0,0,0-1.54,0s-1.88,1.49-3.12,2.59-2.48,2.35-2.48,2.35A2.5,2.5,0,0,0,23,7.27l.27,8.93c0,.53-.41.55-.58.05l-2.29-5.69c-.17-.5-.57-.56-.91-.14a35.77,35.77,0,0,0-3,4.2,35.55,35.55,0,0,0-2,4.62,2,2,0,0,0,.27,1.67l4.67,6.24c.33.42.23,1-.22.69l-4.87-2.66c-.45-.29-.82-.1-.82.43a18.6,18.6,0,0,0,.83,5.07,20.16,20.16,0,0,0,5.37,7.77c3.19,3,5.93,7.8,7.45,11.08A9.6,9.6,0,0,1,30,49.09a9.31,9.31,0,0,1,2.86.45c1.52-3.28,4.26-8.11,7.44-11.09a20.46,20.46,0,0,0,5.09-7,19,19,0,0,0,1.11-5.82"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M36.12,58.44A6.12,6.12,0,1,1,30,52.32a6.11,6.11,0,0,1,6.12,6.12"})]})},P=function(){return P=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0?"".concat(i," ").concat(n):n)||this).hint=null,o.name=o.constructor.name,o.code=r;var s=[U.AccessToFeatureDisabled,U.ParselyApiForbidden,U.ParselyApiResponseContainsError,U.ParselyApiReturnedNoData,U.ParselyApiReturnedTooManyResults,U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsApiSecretNotSet,U.PluginSettingsSiteIdNotSet,U.PostIsNotPublished,U.UnknownError,U.ParselySuggestionsApiAuthUnavailable,U.ParselySuggestionsApiNoAuthentication,U.ParselySuggestionsApiNoAuthorization,U.ParselySuggestionsApiNoData,U.ParselySuggestionsApiSchemaError];return o.retryFetch=!s.includes(o.code),Object.setPrototypeOf(o,t.prototype),o.code===U.AccessToFeatureDisabled?o.message=(0,w.__)("Access to this feature is disabled by the site's administration.","wp-parsely"):o.code===U.ParselySuggestionsApiNoAuthorization?o.message=(0,w.__)('This AI-powered feature is opt-in. To gain access, please submit a request here.',"wp-parsely"):o.code===U.ParselySuggestionsApiOpenAiError||o.code===U.ParselySuggestionsApiOpenAiUnavailable?o.message=(0,w.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):o.code===U.HttpRequestFailed&&o.message.includes("cURL error 28")?o.message=(0,w.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):o.code===U.ParselySuggestionsApiSchemaError?o.message=(0,w.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):o.code===U.ParselySuggestionsApiNoData?o.message=(0,w.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):o.code===U.ParselySuggestionsApiOpenAiSchema?o.message=(0,w.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):o.code===U.ParselySuggestionsApiAuthUnavailable&&(o.message=(0,w.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),o}return ee(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsSiteIdNotSet,U.PluginSettingsApiSecretNotSet].includes(this.code)?Q(e):(this.code===U.FetchError&&(this.hint=this.Hint((0,w.__)("This error can sometimes be caused by ad-blockers or browser tracking protections. Please add this site to any applicable allow lists and try again.","wp-parsely"))),this.code!==U.ParselyApiForbidden&&this.code!==U.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,w.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===U.HttpRequestFailed&&(this.hint=this.Hint((0,w.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,f.jsx)(X,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

").concat(this.hint?this.hint:"")}))},t.prototype.Hint=function(e){return'

'.concat((0,w.__)("Hint:","wp-parsely")," ").concat(e,"

")},t.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,v.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),ne=window.wp.compose,re=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})}),ie=(0,m.forwardRef)((function({icon:e,size:t=24,...n},r){return(0,m.cloneElement)(e,{width:t,height:t,...n,ref:r})})),oe=function(){return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:(0,f.jsx)(h.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M13.5034 7.91642L9 12.0104L4.49662 7.91642L5.25337 7.08398L8.99999 10.49L12.7466 7.08398L13.5034 7.91642Z",fill:"#1E1E1E"})})},se={journalist:{label:(0,w.__)("Journalist","wp-parsely")},editorialWriter:{label:(0,w.__)("Editorial Writer","wp-parsely")},investigativeReporter:{label:(0,w.__)("Investigative Reporter","wp-parsely")},techAnalyst:{label:(0,w.__)("Tech Analyst","wp-parsely")},businessAnalyst:{label:(0,w.__)("Business Analyst","wp-parsely")},culturalCommentator:{label:(0,w.__)("Cultural Commentator","wp-parsely")},scienceCorrespondent:{label:(0,w.__)("Science Correspondent","wp-parsely")},politicalAnalyst:{label:(0,w.__)("Political Analyst","wp-parsely")},healthWellnessAdvocate:{label:(0,w.__)("Health and Wellness Advocate","wp-parsely")},environmentalJournalist:{label:(0,w.__)("Environmental Journalist","wp-parsely")},custom:{label:(0,w.__)("Custom Persona","wp-parsely"),icon:re}},ae=Object.keys(se),le=function(e){return"custom"===e||""===e?se.custom.label:ce(e)?e:se[e].label},ce=function(e){return!ae.includes(e)||"custom"===e},ue=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],o=r[1],s=(0,ne.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-persona-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom persona…","wp-parsely"),onChange:function(e){if(""===e)return n(""),void o("");e.length>32&&(e=e.slice(0,32)),s(e),o(e)}})})},pe=function(e){var t=e.persona,n=e.value,r=void 0===n?(0,w.__)("Select a persona…","wp-parsely"):n,i=e.label,o=void 0===i?(0,w.__)("Persona","wp-parsely"):i,s=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u;return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[o&&(0,f.jsx)("div",{className:"wp-parsely-dropdown-label",children:o}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Persona","wp-parsely"),className:"parsely-persona-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-persona-selector-label",children:ce(t)?se.custom.label:r}),(0,f.jsx)(oe,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Persona","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:ae.map((function(e){if(!p&&"custom"===e)return null;var r=se[e],i=e===t||ce(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),s(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-persona-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ie,{icon:r.icon}),r.label]},e)}))})})}}),p&&ce(t)&&(0,f.jsx)(ue,{onChange:function(e){s(""!==e?e:"custom")},value:"custom"===t?"":t})]})},de={neutral:{label:(0,w.__)("Neutral","wp-parsely")},formal:{label:(0,w.__)("Formal","wp-parsely")},humorous:{label:(0,w.__)("Humorous","wp-parsely")},confident:{label:(0,w.__)("Confident","wp-parsely")},provocative:{label:(0,w.__)("Provocative","wp-parsely")},serious:{label:(0,w.__)("Serious","wp-parsely")},inspirational:{label:(0,w.__)("Inspirational","wp-parsely")},skeptical:{label:(0,w.__)("Skeptical","wp-parsely")},conversational:{label:(0,w.__)("Conversational","wp-parsely")},analytical:{label:(0,w.__)("Analytical","wp-parsely")},custom:{label:(0,w.__)("Custom Tone","wp-parsely"),icon:re}},fe=Object.keys(de),he=function(e){return"custom"===e||""===e?de.custom.label:ve(e)?e:de[e].label},ve=function(e){return!fe.includes(e)||"custom"===e},ge=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],o=r[1],s=(0,ne.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-tone-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom tone","wp-parsely"),onChange:function(e){if(""===e)return n(""),void o("");e.length>32&&(e=e.slice(0,32)),s(e),o(e)}})})},ye=function(e){var t=e.tone,n=e.value,r=void 0===n?(0,w.__)("Select a tone","wp-parsely"):n,i=e.label,o=void 0===i?(0,w.__)("Tone","wp-parsely"):i,s=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u;return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[(0,f.jsx)("div",{className:"wp-parsely-dropdown-label",children:o}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Tone","wp-parsely"),className:"parsely-tone-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-tone-selector-label",children:ve(t)?de.custom.label:r}),(0,f.jsx)(oe,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Select a tone","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:fe.map((function(e){if(!p&&"custom"===e)return null;var r=de[e],i=e===t||ve(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),s(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-tone-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ie,{icon:r.icon}),r.label]},e)}))})})}}),p&&ve(t)&&(0,f.jsx)(ge,{onChange:function(e){s(""!==e?e:"custom")},value:"custom"===t?"":t})]})},me=function(e){var t=e.isLoading,n=e.onPersonaChange,r=e.onToneChange,i=e.persona,o=e.tone;return(0,f.jsxs)("div",{className:"excerpt-suggestions-settings",children:[(0,f.jsx)(ye,{tone:o,value:he(o),onChange:function(e){r(e)},onDropdownChange:function(e){k.trackEvent("excerpt_generator_ai_tone_changed",{selectedTone:e})},disabled:t,allowCustom:!0}),(0,f.jsx)(pe,{persona:i,value:le(i),onChange:function(e){n(e)},onDropdownChange:function(e){k.trackEvent("excerpt_generator_ai_persona_changed",{persona:e})},disabled:t,allowCustom:!0})]})},we=window.wp.url,be=function(){function e(){this.abortControllers=new Map}return e.prototype.cancelRequest=function(e){if(e)(t=this.abortControllers.get(e))&&(t.abort(),this.abortControllers.delete(e));else{var t,n=Array.from(this.abortControllers.keys()).pop();n&&(t=this.abortControllers.get(n))&&(t.abort(),this.abortControllers.delete(n))}},e.prototype.cancelAll=function(){this.abortControllers.forEach((function(e){return e.abort()})),this.abortControllers.clear()},e.prototype.getOrCreateController=function(e){if(e&&this.abortControllers.has(e))return{abortController:this.abortControllers.get(e),abortId:e};var t=null!=e?e:"auto-"+Date.now(),n=new AbortController;return this.abortControllers.set(t,n),{abortController:n,abortId:t}},e.prototype.fetch=function(e,t){return n=this,r=void 0,o=function(){var n,r,i,o,s,a;return function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,w.sprintf)( +!function(){"use strict";var e={20:function(e,t,n){var r=n(609),i=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var r,s={},c=null,u=null;for(r in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,r)&&!l.hasOwnProperty(r)&&(s[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===s[r]&&(s[r]=t[r]);return{$$typeof:i,type:e,key:c,ref:u,props:s,_owner:a.current}}t.Fragment=s,t.jsx=c,t.jsxs=c},848:function(e,t,n){e.exports=n(20)},609:function(e){e.exports=window.React}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(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.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){n.d({},{w:function(){return Nr},_:function(){return Cr}});var e,t,r,i,s,o,a,l,c,u,p,d,f=n(848),h=window.wp.components,v=window.wp.data,g=window.wp.domReady,y=n.n(g),m=window.wp.element,w=window.wp.i18n,b=window.wp.primitives,_=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",d:"M11.25 5h1.5v15h-1.5V5zM6 10h1.5v10H6V10zm12 4h-1.5v6H18v-6z",clipRule:"evenodd"})}),x=window.wp.plugins;void 0!==window.wp&&(p=null!==(t=null===(e=window.wp.editor)||void 0===e?void 0:e.PluginDocumentSettingPanel)&&void 0!==t?t:null!==(i=null===(r=window.wp.editPost)||void 0===r?void 0:r.PluginDocumentSettingPanel)&&void 0!==i?i:null===(s=window.wp.editSite)||void 0===s?void 0:s.PluginDocumentSettingPanel,d=null!==(a=null===(o=window.wp.editor)||void 0===o?void 0:o.PluginSidebar)&&void 0!==a?a:null!==(c=null===(l=window.wp.editPost)||void 0===l?void 0:l.PluginSidebar)&&void 0!==c?c:null===(u=window.wp.editSite)||void 0===u?void 0:u.PluginSidebar);var k=function(){function e(){this._tkq=[],this.isLoaded=!1,this.isEnabled=!1,"undefined"!=typeof wpParselyTracksTelemetry&&(this.isEnabled=!0,this.loadTrackingLibrary())}return e.getInstance=function(){return window.wpParselyTelemetryInstance||Object.defineProperty(window,"wpParselyTelemetryInstance",{value:new e,writable:!1,configurable:!1,enumerable:!1}),window.wpParselyTelemetryInstance},e.prototype.loadTrackingLibrary=function(){var e=this,t=document.createElement("script");t.async=!0,t.src="//stats.wp.com/w.js",t.onload=function(){e.isLoaded=!0,e._tkq=window._tkq||[]},document.head.appendChild(t)},e.trackEvent=function(t){return n=this,r=arguments,s=function(t,n){var r;return void 0===n&&(n={}),function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]=1e4&&(clearInterval(s),n("Telemetry library not loaded"))}),100);else n("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,n){var r;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(n=this.prepareProperties(n),null===(r=this._tkq)||void 0===r||r.push(["recordEvent",t,n])):console.error("Error tracking event: Invalid event name")):console.error("Error tracking event: Telemetry not loaded")},e.prototype.isTelemetryEnabled=function(){return this.isEnabled},e.prototype.isProprietyValid=function(t){return e.PROPERTY_REGEX.test(t)},e.prototype.isEventNameValid=function(t){return e.EVENT_NAME_REGEX.test(t)},e.prototype.prepareProperties=function(e){return(e=this.sanitizeProperties(e)).parsely_version=wpParselyTracksTelemetry.version,wpParselyTracksTelemetry.user&&(e._ut=wpParselyTracksTelemetry.user.type,e._ui=wpParselyTracksTelemetry.user.id),wpParselyTracksTelemetry.vipgo_env&&(e.vipgo_env=wpParselyTracksTelemetry.vipgo_env),this.sanitizeProperties(e)},e.prototype.sanitizeProperties=function(e){var t=this,n={};return Object.keys(e).forEach((function(r){t.isProprietyValid(r)&&(n[r]=e[r])})),n},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),S=(k.trackEvent,function(){return(0,f.jsx)(h.SVG,{"aria-hidden":"true",version:"1.1",viewBox:"0 0 15 15",width:"15",height:"15",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(h.Path,{d:"M0 14.0025V11.0025L7.5 3.5025L10.5 6.5025L3 14.0025H0ZM12 5.0025L13.56 3.4425C14.15 2.8525 14.15 1.9025 13.56 1.3225L12.68 0.4425C12.09 -0.1475 11.14 -0.1475 10.56 0.4425L9 2.0025L12 5.0025Z"})})}),j=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{className:i,height:n,viewBox:"0 0 60 65",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M23.72,51.53c0-.18,0-.34-.06-.52a13.11,13.11,0,0,0-2.1-5.53A14.74,14.74,0,0,0,19.12,43c-.27-.21-.5-.11-.51.22l-.24,3.42c0,.33-.38.35-.49,0l-1.5-4.8a1.4,1.4,0,0,0-.77-.78,23.91,23.91,0,0,0-3.1-.84c-1.38-.24-3.39-.39-3.39-.39-.34,0-.45.21-.25.49l2.06,3.76c.2.27,0,.54-.29.33l-4.51-3.6a3.68,3.68,0,0,0-2.86-.48c-1,.16-2.44.46-2.44.46a.68.68,0,0,0-.39.25.73.73,0,0,0-.14.45S.41,43,.54,44a3.63,3.63,0,0,0,1.25,2.62L6.48,50c.28.2.09.49-.23.37l-4.18-.94c-.32-.12-.5,0-.4.37,0,0,.69,1.89,1.31,3.16a24,24,0,0,0,1.66,2.74,1.34,1.34,0,0,0,1,.52l5,.13c.33,0,.41.38.1.48L7.51,58c-.31.1-.34.35-.07.55a14.29,14.29,0,0,0,3.05,1.66,13.09,13.09,0,0,0,5.9.5,25.13,25.13,0,0,0,4.34-1,9.55,9.55,0,0,1-.08-1.2,9.32,9.32,0,0,1,3.07-6.91"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M59.7,41.53a.73.73,0,0,0-.14-.45.68.68,0,0,0-.39-.25s-1.43-.3-2.44-.46a3.64,3.64,0,0,0-2.86.48l-4.51,3.6c-.26.21-.49-.06-.29-.33l2.06-3.76c.2-.28.09-.49-.25-.49,0,0-2,.15-3.39.39a23.91,23.91,0,0,0-3.1.84,1.4,1.4,0,0,0-.77.78l-1.5,4.8c-.11.32-.48.3-.49,0l-.24-3.42c0-.33-.24-.43-.51-.22a14.74,14.74,0,0,0-2.44,2.47A13.11,13.11,0,0,0,36.34,51c0,.18,0,.34-.06.52a9.26,9.26,0,0,1,3,8.1,24.1,24.1,0,0,0,4.34,1,13.09,13.09,0,0,0,5.9-.5,14.29,14.29,0,0,0,3.05-1.66c.27-.2.24-.45-.07-.55l-3.22-1.17c-.31-.1-.23-.47.1-.48l5-.13a1.38,1.38,0,0,0,1-.52A24.6,24.6,0,0,0,57,52.92c.61-1.27,1.31-3.16,1.31-3.16.1-.33-.08-.49-.4-.37l-4.18.94c-.32.12-.51-.17-.23-.37l4.69-3.34A3.63,3.63,0,0,0,59.46,44c.13-1,.24-2.47.24-2.47"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M46.5,25.61c0-.53-.35-.72-.8-.43l-4.86,2.66c-.45.28-.56-.27-.23-.69l4.66-6.23a2,2,0,0,0,.28-1.68,36.51,36.51,0,0,0-2.19-4.89,34,34,0,0,0-2.81-3.94c-.33-.41-.74-.35-.91.16l-2.28,5.68c-.16.5-.6.48-.59-.05l.28-8.93a2.54,2.54,0,0,0-.66-1.64S35,4.27,33.88,3.27,30.78.69,30.78.69a1.29,1.29,0,0,0-1.54,0s-1.88,1.49-3.12,2.59-2.48,2.35-2.48,2.35A2.5,2.5,0,0,0,23,7.27l.27,8.93c0,.53-.41.55-.58.05l-2.29-5.69c-.17-.5-.57-.56-.91-.14a35.77,35.77,0,0,0-3,4.2,35.55,35.55,0,0,0-2,4.62,2,2,0,0,0,.27,1.67l4.67,6.24c.33.42.23,1-.22.69l-4.87-2.66c-.45-.29-.82-.1-.82.43a18.6,18.6,0,0,0,.83,5.07,20.16,20.16,0,0,0,5.37,7.77c3.19,3,5.93,7.8,7.45,11.08A9.6,9.6,0,0,1,30,49.09a9.31,9.31,0,0,1,2.86.45c1.52-3.28,4.26-8.11,7.44-11.09a20.46,20.46,0,0,0,5.09-7,19,19,0,0,0,1.11-5.82"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M36.12,58.44A6.12,6.12,0,1,1,30,52.32a6.11,6.11,0,0,1,6.12,6.12"})]})},P=function(){return P=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0?"".concat(i," ").concat(n):n)||this).hint=null,s.name=s.constructor.name,s.code=r;var o=[U.AccessToFeatureDisabled,U.ParselyApiForbidden,U.ParselyApiResponseContainsError,U.ParselyApiReturnedNoData,U.ParselyApiReturnedTooManyResults,U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsApiSecretNotSet,U.PluginSettingsSiteIdNotSet,U.PostIsNotPublished,U.UnknownError,U.ParselySuggestionsApiAuthUnavailable,U.ParselySuggestionsApiNoAuthentication,U.ParselySuggestionsApiNoAuthorization,U.ParselySuggestionsApiNoData,U.ParselySuggestionsApiSchemaError];return s.retryFetch=!o.includes(s.code),Object.setPrototypeOf(s,t.prototype),s.code===U.AccessToFeatureDisabled?s.message=(0,w.__)("Access to this feature is disabled by the site's administration.","wp-parsely"):s.code===U.ParselySuggestionsApiNoAuthorization?s.message=(0,w.__)('This AI-powered feature is opt-in. To gain access, please submit a request here.',"wp-parsely"):s.code===U.ParselySuggestionsApiOpenAiError||s.code===U.ParselySuggestionsApiOpenAiUnavailable?s.message=(0,w.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):s.code===U.HttpRequestFailed&&s.message.includes("cURL error 28")?s.message=(0,w.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):s.code===U.ParselySuggestionsApiSchemaError?s.message=(0,w.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):s.code===U.ParselySuggestionsApiNoData?s.message=(0,w.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):s.code===U.ParselySuggestionsApiOpenAiSchema?s.message=(0,w.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):s.code===U.ParselySuggestionsApiAuthUnavailable&&(s.message=(0,w.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),s}return ee(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsSiteIdNotSet,U.PluginSettingsApiSecretNotSet].includes(this.code)?Q(e):(this.code===U.FetchError&&(this.hint=this.Hint((0,w.__)("This error can sometimes be caused by ad-blockers or browser tracking protections. Please add this site to any applicable allow lists and try again.","wp-parsely"))),this.code!==U.ParselyApiForbidden&&this.code!==U.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,w.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===U.HttpRequestFailed&&(this.hint=this.Hint((0,w.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,f.jsx)(X,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

").concat(this.hint?this.hint:"")}))},t.prototype.Hint=function(e){return'

'.concat((0,w.__)("Hint:","wp-parsely")," ").concat(e,"

")},t.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,v.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),ne=window.wp.compose,re=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})}),ie=(0,m.forwardRef)((function({icon:e,size:t=24,...n},r){return(0,m.cloneElement)(e,{width:t,height:t,...n,ref:r})})),se=function(){return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:(0,f.jsx)(h.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M13.5034 7.91642L9 12.0104L4.49662 7.91642L5.25337 7.08398L8.99999 10.49L12.7466 7.08398L13.5034 7.91642Z",fill:"#1E1E1E"})})},oe={journalist:{label:(0,w.__)("Journalist","wp-parsely")},editorialWriter:{label:(0,w.__)("Editorial Writer","wp-parsely")},investigativeReporter:{label:(0,w.__)("Investigative Reporter","wp-parsely")},techAnalyst:{label:(0,w.__)("Tech Analyst","wp-parsely")},businessAnalyst:{label:(0,w.__)("Business Analyst","wp-parsely")},culturalCommentator:{label:(0,w.__)("Cultural Commentator","wp-parsely")},scienceCorrespondent:{label:(0,w.__)("Science Correspondent","wp-parsely")},politicalAnalyst:{label:(0,w.__)("Political Analyst","wp-parsely")},healthWellnessAdvocate:{label:(0,w.__)("Health and Wellness Advocate","wp-parsely")},environmentalJournalist:{label:(0,w.__)("Environmental Journalist","wp-parsely")},custom:{label:(0,w.__)("Custom Persona","wp-parsely"),icon:re}},ae=Object.keys(oe),le=function(e){return"custom"===e||""===e?oe.custom.label:ce(e)?e:oe[e].label},ce=function(e){return!ae.includes(e)||"custom"===e},ue=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],s=r[1],o=(0,ne.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-persona-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom persona…","wp-parsely"),onChange:function(e){if(""===e)return n(""),void s("");e.length>32&&(e=e.slice(0,32)),o(e),s(e)}})})},pe=function(e){var t=e.persona,n=e.value,r=void 0===n?(0,w.__)("Select a persona…","wp-parsely"):n,i=e.label,s=void 0===i?(0,w.__)("Persona","wp-parsely"):i,o=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u;return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[s&&(0,f.jsx)("div",{className:"wp-parsely-dropdown-label",children:s}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Persona","wp-parsely"),className:"parsely-persona-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-persona-selector-label",children:ce(t)?oe.custom.label:r}),(0,f.jsx)(se,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Persona","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:ae.map((function(e){if(!p&&"custom"===e)return null;var r=oe[e],i=e===t||ce(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),o(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-persona-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ie,{icon:r.icon}),r.label]},e)}))})})}}),p&&ce(t)&&(0,f.jsx)(ue,{onChange:function(e){o(""!==e?e:"custom")},value:"custom"===t?"":t})]})},de={neutral:{label:(0,w.__)("Neutral","wp-parsely")},formal:{label:(0,w.__)("Formal","wp-parsely")},humorous:{label:(0,w.__)("Humorous","wp-parsely")},confident:{label:(0,w.__)("Confident","wp-parsely")},provocative:{label:(0,w.__)("Provocative","wp-parsely")},serious:{label:(0,w.__)("Serious","wp-parsely")},inspirational:{label:(0,w.__)("Inspirational","wp-parsely")},skeptical:{label:(0,w.__)("Skeptical","wp-parsely")},conversational:{label:(0,w.__)("Conversational","wp-parsely")},analytical:{label:(0,w.__)("Analytical","wp-parsely")},custom:{label:(0,w.__)("Custom Tone","wp-parsely"),icon:re}},fe=Object.keys(de),he=function(e){return"custom"===e||""===e?de.custom.label:ve(e)?e:de[e].label},ve=function(e){return!fe.includes(e)||"custom"===e},ge=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],s=r[1],o=(0,ne.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-tone-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom tone","wp-parsely"),onChange:function(e){if(""===e)return n(""),void s("");e.length>32&&(e=e.slice(0,32)),o(e),s(e)}})})},ye=function(e){var t=e.tone,n=e.value,r=void 0===n?(0,w.__)("Select a tone","wp-parsely"):n,i=e.label,s=void 0===i?(0,w.__)("Tone","wp-parsely"):i,o=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u;return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[(0,f.jsx)("div",{className:"wp-parsely-dropdown-label",children:s}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Tone","wp-parsely"),className:"parsely-tone-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-tone-selector-label",children:ve(t)?de.custom.label:r}),(0,f.jsx)(se,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Select a tone","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:fe.map((function(e){if(!p&&"custom"===e)return null;var r=de[e],i=e===t||ve(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),o(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-tone-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ie,{icon:r.icon}),r.label]},e)}))})})}}),p&&ve(t)&&(0,f.jsx)(ge,{onChange:function(e){o(""!==e?e:"custom")},value:"custom"===t?"":t})]})},me=function(e){var t=e.isLoading,n=e.onPersonaChange,r=e.onToneChange,i=e.persona,s=e.tone;return(0,f.jsxs)("div",{className:"excerpt-suggestions-settings",children:[(0,f.jsx)(ye,{tone:s,value:he(s),onChange:function(e){r(e)},onDropdownChange:function(e){k.trackEvent("excerpt_generator_ai_tone_changed",{selectedTone:e})},disabled:t,allowCustom:!0}),(0,f.jsx)(pe,{persona:i,value:le(i),onChange:function(e){n(e)},onDropdownChange:function(e){k.trackEvent("excerpt_generator_ai_persona_changed",{persona:e})},disabled:t,allowCustom:!0})]})},we=window.wp.url,be=function(){function e(){this.abortControllers=new Map}return e.prototype.cancelRequest=function(e){if(e)(t=this.abortControllers.get(e))&&(t.abort(),this.abortControllers.delete(e));else{var t,n=Array.from(this.abortControllers.keys()).pop();n&&(t=this.abortControllers.get(n))&&(t.abort(),this.abortControllers.delete(n))}},e.prototype.cancelAll=function(){this.abortControllers.forEach((function(e){return e.abort()})),this.abortControllers.clear()},e.prototype.getOrCreateController=function(e){if(e&&this.abortControllers.has(e))return{abortController:this.abortControllers.get(e),abortId:e};var t=null!=e?e:"auto-"+Date.now(),n=new AbortController;return this.abortControllers.set(t,n),{abortController:n,abortId:t}},e.prototype.fetch=function(e,t){return n=this,r=void 0,s=function(){var n,r,i,s,o,a;return function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,w.sprintf)( // Translators: %1$s the number of words in the excerpt. // Translators: %1$s the number of words in the excerpt. -(0,w._n)("%1$s word","%1$s words",e,"wp-parsely"),e):"")}),[u.currentExcerpt,D]),(0,m.useEffect)((function(){var e=document.querySelector(".editor-post-excerpt textarea");e&&(e.scrollTop=0)}),[u.newExcerptGeneratedCount]);var G=(0,f.jsxs)("div",{className:"wp-parsely-excerpt-generator-header",children:[(0,f.jsx)(j,{size:16}),(0,f.jsx)("div",{className:"wp-parsely-excerpt-generator-header-label",children:(0,w.__)("Generate With Parse.ly","wp-parsely")})]}),H=n?(0,w.__)("Write an excerpt (optional)","wp-parsely"):(0,w.__)("Excerpt","wp-parsely");return(0,f.jsxs)("div",{className:"editor-post-excerpt",children:[!n&&(0,f.jsxs)("div",{className:"excerpt-suggestions-text",children:[(0,w.__)("Use Parse.ly AI to generate a concise, engaging excerpt for your post.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),(0,f.jsxs)("div",{style:{position:"relative"},children:[g&&(0,f.jsx)("div",{className:"editor-post-excerpt__loading_animation",children:(0,f.jsx)(Te,{})}),(0,f.jsx)(h.TextareaControl,{__nextHasNoMarginBottom:!0,label:H,className:"editor-post-excerpt__textarea",onChange:function(e){u.isUnderReview||R({excerpt:e}),p(ke(ke({},u),{currentExcerpt:e})),_(!0)},onKeyUp:function(){var e;if(x)_(!1);else{var t=document.querySelector(".editor-post-excerpt textarea"),n=null!==(e=null==t?void 0:t.textContent)&&void 0!==e?e:"";p(ke(ke({},u),{currentExcerpt:n}))}},value:g?"":u.isUnderReview?u.currentExcerpt:D,help:A||null})]}),n&&(0,f.jsxs)(h.Button,{href:(0,w.__)("https://wordpress.org/documentation/article/page-post-settings-sidebar/#excerpt"),target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about manual excerpts","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]}),(0,f.jsxs)("div",{className:"wp-parsely-excerpt-generator"+(n?" is-doc-set-panel":""),children:[a&&(0,f.jsx)(h.Notice,{className:"wp-parsely-excerpt-generator-error",onRemove:function(){return l(void 0)},status:"info",children:a.Message()}),u.isUnderReview?(0,f.jsxs)(f.Fragment,{children:[n&&G,(0,f.jsxs)("div",{className:"wp-parsely-excerpt-suggestions-review-controls",children:[(0,f.jsx)(h.Button,{variant:"secondary",onClick:function(){return Se(void 0,void 0,void 0,(function(){return je(this,(function(e){switch(e.label){case 0:return[4,R({excerpt:u.currentExcerpt})];case 1:return e.sent(),p(ke(ke({},u),{isUnderReview:!1})),k.trackEvent("excerpt_generator_accepted"),[2]}}))}))},children:(0,w.__)("Accept","wp-parsely")}),(0,f.jsx)(h.Button,{isDestructive:!0,variant:"secondary",onClick:function(){return Se(void 0,void 0,void 0,(function(){return je(this,(function(e){return R({excerpt:u.oldExcerpt}),p(ke(ke({},u),{currentExcerpt:u.oldExcerpt,isUnderReview:!1})),k.trackEvent("excerpt_generator_discarded"),[2]}))}))},children:(0,w.__)("Discard","wp-parsely")})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(me,{isLoading:g,onPersonaChange:function(e){B("Persona",e),T(e)},onSettingChange:B,onToneChange:function(e){B("Tone",e),N(e)},persona:i.ExcerptSuggestions.Persona,tone:i.ExcerptSuggestions.Tone}),n&&G,(0,f.jsx)("div",{className:"excerpt-suggestions-generate",children:(0,f.jsxs)(h.Button,{onClick:function(){return Se(void 0,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:y(!0),l(void 0),n.label=1;case 1:return n.trys.push([1,3,4,5]),k.trackEvent("excerpt_generator_pressed"),[4,_e.getInstance().generateExcerpt(V,F,P,L)];case 2:return e=n.sent(),p({currentExcerpt:e,isUnderReview:!0,newExcerptGeneratedCount:u.newExcerptGeneratedCount+1,oldExcerpt:D}),[3,5];case 3:return(t=n.sent())instanceof te?l(t):(l(new te((0,w.__)("An unknown error occurred.","wp-parsely"),U.UnknownError)),console.error(t)),[3,5];case 4:return y(!1),[7];case 5:return[2]}}))}))},variant:"primary",isBusy:g,disabled:g||!F,children:[g&&(0,w.__)("Generating Excerpt…","wp-parsely"),!g&&u.newExcerptGeneratedCount>0&&(0,w.__)("Regenerate Excerpt","wp-parsely"),!g&&0===u.newExcerptGeneratedCount&&(0,w.__)("Generate Excerpt","wp-parsely")]})})]}),n&&(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]})]})},Te=function(){return(0,f.jsx)(h.Animate,{type:"loading",children:function(e){var t=e.className;return(0,f.jsx)("span",{className:t,children:(0,w.__)("Generating…","wp-parsely")})}})},Ee=function(){return(0,f.jsx)(q.PostTypeSupportCheck,{supportKeys:"excerpt",children:(0,f.jsx)(p,{name:"parsely-post-excerpt",title:(0,w.__)("Excerpt","wp-parsely"),children:(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Nr(window.wpParselyContentHelperSettings),children:(0,f.jsx)(Pe,{isDocumentSettingPanel:!0})})})})},Le=function(e,t){var n,r,i;return t!==Lr?e:H().ExcerptSuggestions?((null===(n=null===window||void 0===window?void 0:window.Jetpack_Editor_Initial_State)||void 0===n?void 0:n.available_blocks["ai-content-lens"])&&(console.log("Parse.ly: Jetpack AI is enabled and will be disabled."),(0,K.removeFilter)("blocks.registerBlockType","jetpack/ai-content-lens-features")),(0,_.registerPlugin)("wp-parsely-excerpt-suggestions",{render:function(){return(0,f.jsx)(Ee,{})}}),(null===(r=(0,v.dispatch)("core/editor"))||void 0===r?void 0:r.removeEditorPanel)?null===(i=(0,v.dispatch)("core/editor"))||void 0===i||i.removeEditorPanel("post-excerpt"):null==Y||Y.removeEditorPanel("post-excerpt"),e):e};function Ne(){(0,K.addFilter)("plugins.registerPlugin","wp-parsely-excerpt-suggestions",Le,1e3)}var Ce=window.wp.blockEditor;function Ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Oe=function(){return Oe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0)return r(e.innerBlocks,t[o].innerBlocks);if(JSON.stringify(e)!==JSON.stringify(t[o])){var s=t[o],a=i.parseFromString(e.attributes.content||"","text/html"),l=i.parseFromString((null==s?void 0:s.attributes.content)||"","text/html"),c=Array.from(a.querySelectorAll("a[data-smartlink]")),u=Array.from(l.querySelectorAll("a[data-smartlink]")),p=c.filter((function(e){return!u.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),d=u.filter((function(e){return!c.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),f=c.filter((function(e){var t=u.find((function(t){return t.dataset.smartlink===e.dataset.smartlink}));return t&&t.outerHTML!==e.outerHTML}));(p.length>0||d.length>0||f.length>0)&&n.push({block:e,prevBlock:s,addedLinks:p,removedLinks:d,changedLinks:f})}}}))};return r(e,t),n}(a,l.current);s.length>0&&(s.forEach((function(e){e.changedLinks.length>0&&n&&n(e),e.addedLinks.length>0&&i&&i(e),e.removedLinks.length>0&&r&&r(e)})),l.current=a)}),s);return e(t),function(){e.cancel()}}),[a,s,t,i,n,r]),null},Me=function(e){var t=e.value,n=e.onChange,r=e.max,i=e.min,o=e.suffix,s=e.size,a=e.label,l=e.initialPosition,c=e.disabled,u=e.className;return(0,f.jsxs)("div",{className:"parsely-inputrange-control ".concat(u||""),children:[(0,f.jsx)(h.__experimentalHeading,{className:"parsely-inputrange-control__label",level:3,children:a}),(0,f.jsxs)("div",{className:"parsely-inputrange-control__controls",children:[(0,f.jsx)(h.__experimentalNumberControl,{disabled:c,value:t,suffix:(0,f.jsx)(h.__experimentalInputControlSuffixWrapper,{children:o}),size:null!=s?s:"__unstable-large",min:i,max:r,onChange:function(e){var t=parseInt(e,10);isNaN(t)||n(t)}}),(0,f.jsx)(h.RangeControl,{disabled:c,value:t,showTooltip:!1,initialPosition:l,onChange:function(e){n(e)},withInputField:!1,min:i,max:r})]})]})},De=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))},Fe=function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]

","\n\x3c!-- /wp:paragraph --\x3e");t&&d((0,Re.parse)(n))}),[o]),(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:s,right:a,up:s,down:a}}),(0,f.jsx)("div",{className:"review-suggestion-post-title",children:null===(t=o.post_data)||void 0===t?void 0:t.title}),(0,f.jsxs)("div",{className:"review-suggestion-preview",children:[!(null===(n=o.post_data)||void 0===n?void 0:n.is_first_paragraph)&&(0,f.jsx)(jt,{topOrBottom:"top"}),(0,f.jsx)(St,{block:p[0],link:o,useOriginalBlock:!0}),!(null===(r=o.post_data)||void 0===r?void 0:r.is_last_paragraph)&&(0,f.jsx)(jt,{topOrBottom:"bottom"})]}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(Pt,{link:o}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:s,icon:bt,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsx)("div",{className:"reviews-controls-middle",children:(0,f.jsx)(h.Button,{target:"_blank",href:(null===(i=o.post_data)||void 0===i?void 0:i.edit_link)+"&smart-link="+o.uid,variant:"secondary",onClick:function(){k.trackEvent("smart_linking_open_in_editor_pressed",{type:"inbound",uid:o.uid})},children:(0,w.__)("Open in the Editor","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:a,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ie,{icon:xt})]})})]})]})},Et=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",className:i,width:n,height:n,viewBox:"0 0 24 24",fill:"none",children:[(0,f.jsx)(h.Path,{d:"M8.18983 5.90381L8.83642 7.54325L10.4758 8.18983L8.83642 8.8364L8.18983 10.4759L7.54324 8.8364L5.90381 8.18983L7.54324 7.54325L8.18983 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M15.048 5.90381L15.9101 8.08972L18.0961 8.95186L15.9101 9.81397L15.048 11.9999L14.1859 9.81397L12 8.95186L14.1859 8.08972L15.048 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M11.238 10.4761L12.3157 13.2085L15.048 14.2861L12.3157 15.3638L11.238 18.0962L10.1603 15.3638L7.42798 14.2861L10.1603 13.2085L11.238 10.4761Z"})]})},Lt=function(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;ii.bottom)&&(n.scrollTop=r.offsetTop-n.offsetTop)}}}}),[t,l]);var u=function(){var e=document.querySelector(".smart-linking-review-sidebar-tabs [data-active-item]"),t=null==e?void 0:e.nextElementSibling;t||(t=document.querySelector('.smart-linking-review-sidebar-tabs [role="tab"]')),t&&t.click()},p=(0,f.jsxs)("span",{className:"smart-linking-menu-label",children:[(0,w.__)("NEW","wp-parsely"),(0,f.jsx)(Et,{})]}),d=[];n&&n.length>0&&d.push({name:"outbound",title:(0,w.__)("Outbound","wp-parsely")}),r&&r.length>0&&d.push({name:"inbound",title:(0,w.__)("Inbound","wp-parsely")});var v="outbound";return d=d.filter((function(e){return"outbound"===e.name&&r&&0===r.length&&(e.title=(0,w.__)("Outbound Smart Links","wp-parsely"),v="outbound"),"inbound"===e.name&&n&&0===n.length&&(e.title=(0,w.__)("Inbound Smart Links","wp-parsely"),v="inbound"),e})),(0,f.jsxs)("div",{className:"smart-linking-review-sidebar",ref:o,children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{tab:function(){return u()},"shift+tab":function(){return u()}}}),(0,f.jsx)(h.TabPanel,{className:"smart-linking-review-sidebar-tabs",initialTabName:v,tabs:d,onSelect:function(e){var t,o;"outbound"===e&&n&&n.length>0&&i(n[0]),"inbound"===e&&r&&r.length>0&&i(r[0]),k.trackEvent("smart_linking_modal_tab_selected",{tab:e,total_inbound:null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0,total_outbound:null!==(o=null==n?void 0:n.length)&&void 0!==o?o:0})},children:function(e){return(0,f.jsxs)(f.Fragment,{children:["outbound"===e.name&&(0,f.jsx)(f.Fragment,{children:n&&0!==n.length?n.map((function(e,n){return(0,f.jsxs)(h.MenuItem,{ref:function(e){s.current[n]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:[(0,f.jsx)("span",{className:"smart-linking-menu-item",children:e.text}),!e.applied&&p]},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No outbound links found.","wp-parsely")]})}),"inbound"===e.name&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"review-sidebar-tip",children:(0,w.__)("This section shows external posts that link back to the current post.","wp-parsely")}),r&&0!==r.length?r.map((function(e,r){var o;return(0,f.jsx)(h.MenuItem,{ref:function(e){s.current[(n?n.length:0)+r]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:(0,f.jsx)("span",{className:"smart-linking-menu-item",children:null===(o=e.post_data)||void 0===o?void 0:o.title})},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No inbound links found.","wp-parsely")]})]})]})}})]})},Ct=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm.5 16c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V7h15v12zM9 10H7v2h2v-2zm0 4H7v2h2v-2zm4-4h-2v2h2v-2zm4 0h-2v2h2v-2zm-4 4h-2v2h2v-2zm4 0h-2v2h2v-2z"})}),At=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10 4.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm2.25 7.5v-1A2.75 2.75 0 0011 8.25H7A2.75 2.75 0 004.25 11v1h1.5v-1c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v1h1.5zM4 20h9v-1.5H4V20zm16-4H4v-1.5h16V16z",fillRule:"evenodd",clipRule:"evenodd"})}),Ot=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m7.3 9.7 1.4 1.4c.2-.2.3-.3.4-.5 0 0 0-.1.1-.1.3-.5.4-1.1.3-1.6L12 7 9 4 7.2 6.5c-.6-.1-1.1 0-1.6.3 0 0-.1 0-.1.1-.3.1-.4.2-.6.4l1.4 1.4L4 11v1h1l2.3-2.3zM4 20h9v-1.5H4V20zm0-5.5V16h16v-1.5H4z"})}),It=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M3.99961 13C4.67043 13.3354 4.6703 13.3357 4.67017 13.3359L4.67298 13.3305C4.67621 13.3242 4.68184 13.3135 4.68988 13.2985C4.70595 13.2686 4.7316 13.2218 4.76695 13.1608C4.8377 13.0385 4.94692 12.8592 5.09541 12.6419C5.39312 12.2062 5.84436 11.624 6.45435 11.0431C7.67308 9.88241 9.49719 8.75 11.9996 8.75C14.502 8.75 16.3261 9.88241 17.5449 11.0431C18.1549 11.624 18.6061 12.2062 18.9038 12.6419C19.0523 12.8592 19.1615 13.0385 19.2323 13.1608C19.2676 13.2218 19.2933 13.2686 19.3093 13.2985C19.3174 13.3135 19.323 13.3242 19.3262 13.3305L19.3291 13.3359C19.3289 13.3357 19.3288 13.3354 19.9996 13C20.6704 12.6646 20.6703 12.6643 20.6701 12.664L20.6697 12.6632L20.6688 12.6614L20.6662 12.6563L20.6583 12.6408C20.6517 12.6282 20.6427 12.6108 20.631 12.5892C20.6078 12.5459 20.5744 12.4852 20.5306 12.4096C20.4432 12.2584 20.3141 12.0471 20.1423 11.7956C19.7994 11.2938 19.2819 10.626 18.5794 9.9569C17.1731 8.61759 14.9972 7.25 11.9996 7.25C9.00203 7.25 6.82614 8.61759 5.41987 9.9569C4.71736 10.626 4.19984 11.2938 3.85694 11.7956C3.68511 12.0471 3.55605 12.2584 3.4686 12.4096C3.42484 12.4852 3.39142 12.5459 3.36818 12.5892C3.35656 12.6108 3.34748 12.6282 3.34092 12.6408L3.33297 12.6563L3.33041 12.6614L3.32948 12.6632L3.32911 12.664C3.32894 12.6643 3.32879 12.6646 3.99961 13ZM11.9996 16C13.9326 16 15.4996 14.433 15.4996 12.5C15.4996 10.567 13.9326 9 11.9996 9C10.0666 9 8.49961 10.567 8.49961 12.5C8.49961 14.433 10.0666 16 11.9996 16Z"})}),Rt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})}),Bt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"})}),Mt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),Dt=function(e){var t,n,r=e.post,i=e.imageUrl,o=e.icon,s=void 0===o?wt:o,a=e.size,l=void 0===a?100:a,c=e.className,u=void 0===c?"":c,p=null!==(t=null==r?void 0:r.thumbnail)&&void 0!==t?t:i,d=null!==(n=null==r?void 0:r.title.rendered)&&void 0!==n?n:"";return(0,f.jsx)("div",{className:"parsely-thumbnail ".concat(u),style:{width:l,height:l},children:p?(0,f.jsx)("img",{src:p,alt:d,width:l,height:l,loading:"lazy","aria-hidden":""===d}):(0,f.jsx)("div",{className:"parsely-thumbnail-icon-container",children:(0,f.jsx)(h.Icon,{icon:s,size:l})})})};function Ft(e,t,n){void 0===t&&(t=1),void 0===n&&(n="");var r=parseInt(e.replace(/\D/g,""),10);if(r<1e3)return e;r<1e4&&(t=1);var i=r,o=r.toString(),s="",a=0;return Object.entries({1e3:"k","1,000,000":"M","1,000,000,000":"B","1,000,000,000,000":"T","1,000,000,000,000,000":"Q"}).forEach((function(e){var n=e[0],l=e[1],c=parseInt(n.replace(/\D/g,""),10);if(r>=c){var u=t;(i=r/c)%1>1/a&&(u=i>10?1:2),u=parseFloat(i.toFixed(2))===parseFloat(i.toFixed(0))?0:u,o=i.toFixed(u),s=l}a=c})),o+n+s}var Vt,Gt=function(e){var t,n,r,i,o=null===(t=e.link.match)||void 0===t?void 0:t.blockId,s=(0,v.useSelect)((function(e){var t=e("core/block-editor"),n=t.getBlock,r=t.getBlockParents;return o?{block:n(o),parents:r(o).map((function(e){return n(e)})).filter((function(e){return void 0!==e}))}:{block:void 0,parents:[]}}),[o]),a=s.block,l=s.parents;return a?(0,f.jsxs)("div",{className:"review-suggestions-breadcrumbs",children:[l.map((function(e,t){var n;return(0,f.jsxs)("span",{children:[(0,f.jsx)("span",{className:"breadcrumbs-parent-block",children:null===(n=(0,Re.getBlockType)(e.name))||void 0===n?void 0:n.title}),(0,f.jsx)("span",{className:"breadcrumbs-parent-separator",children:" / "})]},t)})),(0,f.jsxs)("span",{className:"breadcrumbs-current-block",children:[(0,f.jsx)("span",{className:"breadcrumbs-current-block-type",children:null===(n=(0,Re.getBlockType)(a.name))||void 0===n?void 0:n.title}),(null===(i=null===(r=a.attributes)||void 0===r?void 0:r.metadata)||void 0===i?void 0:i.name)&&(0,f.jsx)("span",{className:"breadcrumbs-current-block-name",children:a.attributes.metadata.name})]})]}):(0,f.jsx)(f.Fragment,{})},Ht=function(e){var t,n,r,i,o,s=e.link,a=null!==(t=s.wp_post_meta.author)&&void 0!==t?t:(0,w.__)("N/A","wp-parsely"),l=null!==(n=s.post_stats.avg_engaged)&&void 0!==n?n:(0,w.__)("N/A","wp-parsely"),c=s.wp_post_meta.date?function(e){if(!1===function(e){return!isNaN(+e)&&0!==e.getTime()}(e))return ut;var t=lt;return e.getUTCFullYear()===(new Date).getUTCFullYear()&&(t=ct),Intl.DateTimeFormat(document.documentElement.lang||"en",t).format(e)}(new Date(s.wp_post_meta.date)):(0,w.__)("N/A","wp-parsely"),u=null!==(r=s.wp_post_meta.thumbnail)&&void 0!==r&&r,p=null!==(i=s.wp_post_meta.title)&&void 0!==i?i:(0,w.__)("N/A","wp-parsely"),d=null!==(o=s.wp_post_meta.type)&&void 0!==o?o:(0,w.__)("External","wp-parsely"),v=s.wp_post_meta.url,g=s.post_stats.views?Ft(s.post_stats.views):(0,w.__)("N/A","wp-parsely"),y=s.post_stats.visitors?Ft(s.post_stats.visitors):(0,w.__)("N/A","wp-parsely");return(0,f.jsxs)("div",{className:"wp-parsely-link-suggestion-link-details",children:[(0,f.jsx)("div",{className:"thumbnail-column",children:u?(0,f.jsx)(Dt,{imageUrl:u,size:52}):(0,f.jsx)(Dt,{icon:wt,size:52})}),(0,f.jsxs)("div",{className:"data-column",children:[(0,f.jsxs)("div",{className:"title-row",children:[(0,f.jsx)(h.Tooltip,{text:p,children:(0,f.jsx)("span",{children:p})}),v&&(0,f.jsx)(h.Button,{href:v,target:"_blank",variant:"link",rel:"noopener",children:(0,f.jsx)(ie,{icon:$,size:18})})]}),(0,f.jsxs)("div",{className:"data-row",children:[(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:Ct,size:16}),(0,f.jsx)("span",{children:c})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ie,{icon:At,size:16}),(0,f.jsx)(h.Tooltip,{text:a,children:(0,f.jsx)("span",{children:a})})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ie,{icon:Ot,size:16}),(0,f.jsx)(h.Tooltip,{text:d,children:(0,f.jsx)("span",{children:d})})]})]}),(0,f.jsxs)("div",{className:"data-row",children:[(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:It,size:16}),(0,f.jsx)("span",{children:g})]}),(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:Rt,size:16}),(0,f.jsx)("span",{children:y})]}),(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(h.Dashicon,{icon:"clock",size:16}),(0,f.jsx)("span",{children:l})]})]})]})]})},zt=function(e){var t=e.link,n=e.onNext,r=e.onPrevious,i=e.onAccept,o=e.onReject,s=e.onRemove,a=e.onSelectInEditor,l=e.hasPrevious,c=e.hasNext;if(t&&void 0!==t.post_data)return(0,f.jsx)(Tt,{link:t,onNext:n,onPrevious:r,onAccept:i,onReject:o,onRemove:s,onSelectInEditor:a,hasPrevious:l,hasNext:c});if(!(null==t?void 0:t.match))return(0,f.jsx)(f.Fragment,{children:(0,w.__)("This Smart Link does not have any matches in the current content.","wp-parsely")});var u=t.match.blockId,p=(0,v.select)("core/block-editor").getBlock(u),d=t.applied;return p?(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:r,right:n,up:r,down:n,a:function(){t&&!t.applied&&i()},r:function(){t&&(t.applied?s():o())}}}),(0,f.jsx)(Gt,{link:t}),(0,f.jsx)("div",{className:"review-suggestion-preview",children:(0,f.jsx)(St,{block:p,link:t})}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(Ht,{link:t}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:r,icon:bt,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsxs)("div",{className:"reviews-controls-middle",children:[!d&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Reject","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:Bt,onClick:o,variant:"secondary",children:(0,w.__)("Reject","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"A",text:(0,w.__)("Accept","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",icon:Mt,onClick:i,variant:"secondary",children:(0,w.__)("Accept","wp-parsely")})})]}),d&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Remove","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:Bt,onClick:s,variant:"secondary",children:(0,w.__)("Remove","wp-parsely")})}),(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",onClick:a,variant:"secondary",children:(0,w.__)("Select in Editor","wp-parsely")})]})]}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:n,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ie,{icon:xt})]})})]})]}):(0,f.jsx)(f.Fragment,{children:(0,w.__)("No block is selected.","wp-parsely")})},Ut=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))},qt=function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&(a=s[0],(l=a.parentNode)&&(c=document.createTextNode(null!==(u=a.textContent)&&void 0!==u?u:""),l.replaceChild(c,a),Z.updateBlockAttributes(n,{content:o.innerHTML}))),[4,L(t.uid)]):[2]):[2];case 1:return p.sent(),[2]}}))}))},C=(0,m.useCallback)((function(){c(!1),x().filter((function(e){return!e.applied})).length>0?s(!0):(W.unlockPostAutosaving("smart-linking-review-modal"),t())}),[x,t]),A=function(e){s(!1),e?(c(!1),T().then((function(){C()}))):c(!0)},O=function(){if(Ge(S)){var e=g.indexOf(S);if(!g[t=e+1])return;j(g[t])}else{var t;if(e=d.indexOf(S),!d[t=e+1])return;j(d[t])}},I=function(){if(Ge(S)){var e=g.indexOf(S);if(!g[t=e-1])return;j(g[t])}else{var t;if(e=d.indexOf(S),!d[t=e-1])return;j(d[t])}};return(0,m.useEffect)((function(){l?W.lockPostAutosaving("smart-linking-review-modal"):l&&0===p.length&&C()}),[l,t,p,C]),(0,m.useEffect)((function(){c(n)}),[n]),(0,f.jsxs)(f.Fragment,{children:[l&&(0,f.jsx)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),className:"wp-parsely-smart-linking-review-modal",onRequestClose:C,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,children:(0,f.jsxs)("div",{className:"smart-linking-modal-body",children:[(0,f.jsx)(Nt,{outboundLinks:d,inboundLinks:g,activeLink:S,setSelectedLink:j}),S&&(Ge(S)?(0,f.jsx)(Tt,{link:S,onNext:O,onPrevious:I,hasNext:g.indexOf(S)0}):(0,f.jsx)(zt,{link:S,hasNext:b().indexOf(S)0,onNext:O,onPrevious:I,onAccept:function(){return Ut(void 0,void 0,void 0,(function(){var e,t;return qt(this,(function(n){switch(n.label){case 0:return S.match?(r(S),[4,(i=S.match.blockId,o=S,Ut(void 0,void 0,void 0,(function(){var e,t;return qt(this,(function(n){switch(n.label){case 0:return(e=document.createElement("a")).href=o.href,e.title=o.title,e.setAttribute("data-smartlink",o.uid),(t=(0,v.select)("core/block-editor").getBlock(i))?(Ue(t,o,e),o.applied=!0,[4,E(o)]):[2];case 1:return n.sent(),[2]}}))})))]):[2];case 1:return n.sent(),k.trackEvent("smart_linking_link_accepted",{link:S.href,title:S.title,text:S.text,uid:S.uid}),0===y().length?(C(),[2]):(e=d.indexOf(S),d[t=e+1]?j(d[t]):j(d[0]),[2])}var i,o}))}))},onReject:function(){return Ut(void 0,void 0,void 0,(function(){var e,t;return qt(this,(function(n){switch(n.label){case 0:return e=d.indexOf(S),d[t=e+1]?j(d[t]):d[0]?j(d[0]):C(),[4,L(S.uid)];case 1:return n.sent(),k.trackEvent("smart_linking_link_rejected",{link:S.href,title:S.title,text:S.text,uid:S.uid}),[2]}}))}))},onRemove:function(){return Ut(void 0,void 0,void 0,(function(){var e,t,n,r;return qt(this,(function(i){switch(i.label){case 0:return S.match?(e=(0,v.select)("core/block-editor").getBlock(S.match.blockId))?(t=b(),n=t.indexOf(S),r=n-1,[4,N(e,S)]):[3,2]:[2];case 1:if(i.sent(),k.trackEvent("smart_linking_link_removed",{link:S.href,title:S.title,text:S.text,uid:S.uid}),0===(t=b()).length&&g.length>0)return j(g[0]),[2];if(0===t.length&&0===g.length)return C(),[2];if(t[r])return j(t[r]),[2];j(t[0]),i.label=2;case 2:return[2]}}))}))},onSelectInEditor:function(){if(S.match){var e=(0,v.select)("core/block-editor").getBlock(S.match.blockId);if(e){Z.selectBlock(e.clientId);var t=document.querySelector('[data-block="'.concat(e.clientId,'"]'));t&&et(t,S.uid),k.trackEvent("smart_linking_select_in_editor_pressed",{type:"outbound",uid:S.uid}),C()}}}}))]})}),o&&(0,f.jsxs)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),onRequestClose:function(){return A(!1)},className:"wp-parsely-smart-linking-close-dialog",children:[(0,w.__)("Are you sure you want to close? All un-accepted smart links will not be added.","wp-parsely"),(0,f.jsxs)("div",{className:"smart-linking-close-dialog-actions",children:[(0,f.jsx)(h.Button,{variant:"secondary",onClick:function(){return A(!1)},children:(0,w.__)("Go Back","wp-parsely")}),(0,f.jsx)(h.Button,{variant:"primary",onClick:function(){return A(!0)},children:(0,w.__)("Close","wp-parsely")})]})]})]})})),Zt=function(){return Zt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&S("success",/* translators: %d: number of smart links applied */ /* translators: %d: number of smart links applied */ -(0,w.sprintf)((0,w.__)("%s smart links successfully applied.","wp-parsely"),g),{type:"snackbar"}):y(0)}),[x]),(0,m.useEffect)((function(){if(!(Object.keys(R).length>0)){var e={maxLinksPerPost:a.SmartLinking.MaxLinks};ee(e)}}),[ee,a]);var de=(0,v.useSelect)((function(e){var t=e("core/block-editor"),r=t.getSelectedBlock,i=t.getBlock,o=t.getBlocks,s=e("core/editor"),a=s.getEditedPostContent,l=s.getCurrentPostAttribute;return{allBlocks:o(),selectedBlock:n?i(n):r(),postContent:a(),postPermalink:l("link")}}),[n]),fe=de.allBlocks,he=de.selectedBlock,ve=de.postContent,ge=de.postPermalink,ye=function(e){return Wt(void 0,void 0,void 0,(function(){var t,n,r,i,o;return Yt(this,(function(s){switch(s.label){case 0:t=[],s.label=1;case 1:return s.trys.push([1,4,,9]),[4,re((n=L||!he)?Xe.All:Xe.Selected)];case 2:return s.sent(),a=ge.replace(/^https?:\/\//i,""),r=["http://"+a,"https://"+a],i=function(e){return e.map((function(e){return e.href}))}(F),r.push.apply(r,i),[4,gt.getInstance().generateSmartLinks(he&&!n?(0,Re.getBlockContent)(he):ve,O,r)];case 3:return t=s.sent(),[3,9];case 4:if((o=s.sent()).code&&o.code===U.ParselyAborted)throw o.numRetries=3-e,o;return e>0&&o.retryFetch?(console.error(o),[4,se(!0)]):[3,8];case 5:return s.sent(),[4,ae()];case 6:return s.sent(),[4,ye(e-1)];case 7:return[2,s.sent()];case 8:throw o;case 9:return[2,t]}var a}))}))},me=function(){for(var e=[],t=0;t[type="button"]').forEach((function(e){e.setAttribute("disabled","disabled")}))},xe=function(){document.querySelectorAll('.edit-post-header__settings>[type="button"]').forEach((function(e){e.removeAttribute("disabled")})),W.unlockPostSaving("wp-parsely-block-overlay")};return(0,f.jsxs)("div",{className:"wp-parsely-smart-linking",children:[(0,f.jsx)(Be,{isDetectingEnabled:!E,onLinkRemove:function(e){!function(e){De(this,void 0,void 0,(function(){var t,n,r;return Fe(this,(function(i){switch(i.label){case 0:return[4,$e((0,Re.getBlockContent)(e),e.clientId)];case 1:return t=i.sent(),n=t.missingSmartLinks,r=t.didAnyFixes,n.forEach((function(e){(0,v.dispatch)(it).removeSmartLink(e.uid)})),[2,r]}}))}))}(e.block)}}),(0,f.jsxs)(h.PanelRow,{className:t,children:[(0,f.jsxs)("div",{className:"smart-linking-text",children:[(0,w.__)("Automatically insert links to your most relevant, top performing content.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/smart-linking/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(ie,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),C&&(0,f.jsx)(h.Notice,{status:"info",onRemove:function(){return Z(null)},className:"wp-parsely-content-helper-error",children:C.Message()}),x&&g>0&&(0,f.jsx)(h.Notice,{status:"success",onRemove:function(){return _(!1)},className:"wp-parsely-smart-linking-suggested-links",children:(0,w.sprintf)(/* translators: 1 - number of smart links generated */ /* translators: 1 - number of smart links generated */ -(0,w.__)("Successfully added %s smart links.","wp-parsely"),g>0?g:A.length)}),(0,f.jsx)(at,{disabled:T,selectedBlock:he,onSettingChange:function(e,t){var n;p({SmartLinking:Zt(Zt({},a.SmartLinking),(n={},n[e]=t,n))}),"MaxLinks"===e&&oe(t)}}),(0,f.jsx)("div",{className:"smart-linking-generate",children:(0,f.jsx)(h.Button,{onClick:function(){return Wt(void 0,void 0,void 0,(function(){var e,t,n,r,o,s,a,l;return Yt(this,(function(c){switch(c.label){case 0:return[4,K(!0)];case 1:return c.sent(),[4,le()];case 2:return c.sent(),[4,Z(null)];case 3:return c.sent(),_(!1),k.trackEvent("smart_linking_generate_pressed",{is_full_content:L,selected_block:null!==(s=null==he?void 0:he.name)&&void 0!==s?s:"none",context:i}),[4,me(L?"all":null==he?void 0:he.clientId)];case 4:c.sent(),e=setTimeout((function(){var e;K(!1),k.trackEvent("smart_linking_generate_timeout",{is_full_content:L,selected_block:null!==(e=null==he?void 0:he.name)&&void 0!==e?e:"none",context:i}),we(L?"all":null==he?void 0:he.clientId)}),18e4),t=B,c.label=5;case 5:return c.trys.push([5,8,10,15]),[4,ye(3)];case 6:return n=c.sent(),[4,(u=n,Wt(void 0,void 0,void 0,(function(){var e;return Yt(this,(function(t){switch(t.label){case 0:return u=u.filter((function(e){return!F.some((function(t){return t.uid===e.uid&&t.applied}))})),e=ge.replace(/^https?:\/\//,"").replace(/\/+$/,""),u=(u=u.filter((function(t){return!t.href.includes(e)||(console.warn("PCH Smart Linking: Skipping self-reference link: ".concat(t.href)),!1)}))).filter((function(e){return!F.some((function(t){return t.href===e.href?(console.warn("PCH Smart Linking: Skipping duplicate link: ".concat(e.href)),!0):t.text===e.text&&t.offset!==e.offset&&(console.warn("PCH Smart Linking: Skipping duplicate link text: ".concat(e.text)),!0)}))})),u=(u=Ze(L?fe:[he],u,{}).filter((function(e){return e.match}))).filter((function(e){if(!e.match)return!1;var t=e.match.blockLinkPosition,n=t+e.text.length;return!F.some((function(r){if(!r.match)return!1;if(e.match.blockId!==r.match.blockId)return!1;var i=r.match.blockLinkPosition,o=i+r.text.length;return t>=i&&n<=o}))})),[4,Y(u)];case 1:return t.sent(),[2,u]}}))})))];case 7:if(0===c.sent().length)throw new te((0,w.__)("No smart links were generated.","wp-parsely"),U.ParselySuggestionsApiNoData,"");return ce(!0),[3,15];case 8:return r=c.sent(),o=new te(null!==(a=r.message)&&void 0!==a?a:"An unknown error has occurred.",null!==(l=r.code)&&void 0!==l?l:U.UnknownError),r.code&&r.code===U.ParselyAborted&&(o.message=(0,w.sprintf)(/* translators: %d: number of retry attempts, %s: attempt plural */ /* translators: %d: number of retry attempts, %s: attempt plural */ -(0,w.__)("The Smart Linking process was cancelled after %1$d %2$s.","wp-parsely"),r.numRetries,(0,w._n)("attempt","attempts",r.numRetries,"wp-parsely"))),console.error(r),[4,Z(o)];case 9:return c.sent(),o.createErrorSnackbar(),[3,15];case 10:return[4,K(!1)];case 11:return c.sent(),[4,re(t)];case 12:return c.sent(),[4,se(!1)];case 13:return c.sent(),[4,we(L?"all":null==he?void 0:he.clientId)];case 14:return c.sent(),clearTimeout(e),[7];case 15:return[2]}var u}))}))},variant:"primary",isBusy:T,disabled:T,children:M?(0,w.sprintf)(/* translators: %1$d: number of retry attempts, %2$d: maximum number of retries */ /* translators: %1$d: number of retry attempts, %2$d: maximum number of retries */ -(0,w.__)("Retrying… Attempt %1$d of %2$d","wp-parsely"),D,3):T?(0,w.__)("Generating Smart Links…","wp-parsely"):(0,w.__)("Add Smart Links","wp-parsely")})}),(G.length>0||V.length>0)&&(0,f.jsx)("div",{className:"smart-linking-manage",children:(0,f.jsx)(h.Button,{onClick:function(){return Wt(void 0,void 0,void 0,(function(){var e,t;return Yt(this,(function(n){switch(n.label){case 0:return[4,Je()];case 1:return e=n.sent(),t=We(),[4,Y(t)];case 2:return n.sent(),ce(!0),k.trackEvent("smart_linking_review_pressed",{num_smart_links:F.length,has_fixed_links:e,context:i}),[2]}}))}))},variant:"secondary",disabled:T,children:(0,w.__)("Review Smart Links","wp-parsely")})})]}),E&&(0,f.jsx)(Kt,{isOpen:E,onAppliedLink:function(){y((function(e){return e+1}))},onClose:function(){_(!0),ce(!1)}})]})},Qt=function(){return Qt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0)&&(t(),e())}))}))]}))},new((n=void 0)||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}));var e,t,n,r}().then((function(){var t=document.querySelector(".wp-block-post-content");et(t,e)}))})))},dn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M7 11.5h10V13H7z"})}),fn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"})}),hn=function(e){var t=e.title,n=e.icon,r=e.subtitle,i=e.level,o=void 0===i?2:i,s=e.children,a=e.controls,l=e.onClick,c=e.isOpen,u=e.isLoading,p=e.dropdownChildren;return(0,f.jsxs)("div",{className:"performance-stat-panel",children:[(0,f.jsxs)(h.__experimentalHStack,{className:"panel-header level-"+o,children:[(0,f.jsx)(h.__experimentalHeading,{level:o,children:t}),r&&!c&&(0,f.jsx)("span",{className:"panel-subtitle",children:r}),a&&!p&&(0,f.jsx)(h.DropdownMenu,{icon:n,label:(0,w.__)("Settings","wp-parsely"),className:"panel-settings-button",controls:a}),p&&(0,f.jsx)(h.DropdownMenu,{icon:n,label:(0,w.__)("Settings","wp-parsely"),className:"panel-settings-button",children:p}),n&&!p&&!a&&(0,f.jsx)(h.Button,{icon:n,className:"panel-settings-button",isPressed:c,onClick:l})]}),(0,f.jsx)("div",{className:"panel-body",children:u?(0,f.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,f.jsx)(h.Spinner,{})}):s})]})},vn=function(e){var t=e.data,n=e.isLoading,r=(0,m.useState)(B.Views),i=r[0],o=r[1],s=(0,m.useState)(!1),a=s[0],l=s[1];n||delete t.referrers.types.totals;var c=function(e){switch(e){case"social":return(0,w.__)("Social","wp-parsely");case"search":return(0,w.__)("Search","wp-parsely");case"other":return(0,w.__)("Other","wp-parsely");case"internal":return(0,w.__)("Internal","wp-parsely");case"direct":return(0,w.__)("Direct","wp-parsely")}return e},u=(0,w.sprintf)((0,w.__)("By %s","wp-parsely"),G(i)); -/* translators: %s: metric description */return(0,f.jsxs)(hn,{title:(0,w.__)("Categories","wp-parsely"),level:3,subtitle:u,isOpen:a,onClick:function(){return l(!a)},children:[a&&(0,f.jsx)("div",{className:"panel-settings",children:(0,f.jsx)(h.SelectControl,{value:i,prefix:(0,w.__)("By:","wp-parsely"),onChange:function(e){F(e,B)&&o(e)},children:Object.values(B).map((function(e){return(0,f.jsxs)("option",{value:e,disabled:"avg_engaged"===e,children:[G(e),"avg_engaged"===e&&" "+(0,w.__)("(coming soon)","wp-parsely")]},e)}))})}),n?(0,f.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,f.jsx)(h.Spinner,{})}):(0,f.jsxs)("div",{children:[(0,f.jsx)("div",{className:"multi-percentage-bar",children:Object.entries(t.referrers.types).map((function(e){var t=e[0],n=e[1],r=(0,w.sprintf)(/* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ /* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ +(0,w._n)("%1$s word","%1$s words",e,"wp-parsely"),e):"")}),[u.currentExcerpt,D]),(0,m.useEffect)((function(){var e=document.querySelector(".editor-post-excerpt textarea");e&&(e.scrollTop=0)}),[u.newExcerptGeneratedCount]);var G=(0,f.jsxs)("div",{className:"wp-parsely-excerpt-generator-header",children:[(0,f.jsx)(j,{size:16}),(0,f.jsx)("div",{className:"wp-parsely-excerpt-generator-header-label",children:(0,w.__)("Generate With Parse.ly","wp-parsely")})]}),H=n?(0,w.__)("Write an excerpt (optional)","wp-parsely"):(0,w.__)("Excerpt","wp-parsely");return(0,f.jsxs)("div",{className:"editor-post-excerpt",children:[!n&&(0,f.jsxs)("div",{className:"excerpt-suggestions-text",children:[(0,w.__)("Use Parse.ly AI to generate a concise, engaging excerpt for your post.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),(0,f.jsxs)("div",{style:{position:"relative"},children:[g&&(0,f.jsx)("div",{className:"editor-post-excerpt__loading_animation",children:(0,f.jsx)(Te,{})}),(0,f.jsx)(h.TextareaControl,{__nextHasNoMarginBottom:!0,label:H,className:"editor-post-excerpt__textarea",onChange:function(e){u.isUnderReview||R({excerpt:e}),p(ke(ke({},u),{currentExcerpt:e})),x(!0)},onKeyUp:function(){var e;if(_)x(!1);else{var t=document.querySelector(".editor-post-excerpt textarea"),n=null!==(e=null==t?void 0:t.textContent)&&void 0!==e?e:"";p(ke(ke({},u),{currentExcerpt:n}))}},value:g?"":u.isUnderReview?u.currentExcerpt:D,help:A||null})]}),n&&(0,f.jsxs)(h.Button,{href:(0,w.__)("https://wordpress.org/documentation/article/page-post-settings-sidebar/#excerpt"),target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about manual excerpts","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]}),(0,f.jsxs)("div",{className:"wp-parsely-excerpt-generator"+(n?" is-doc-set-panel":""),children:[a&&(0,f.jsx)(h.Notice,{className:"wp-parsely-excerpt-generator-error",onRemove:function(){return l(void 0)},status:"info",children:a.Message()}),u.isUnderReview?(0,f.jsxs)(f.Fragment,{children:[n&&G,(0,f.jsxs)("div",{className:"wp-parsely-excerpt-suggestions-review-controls",children:[(0,f.jsx)(h.Button,{variant:"secondary",onClick:function(){return Se(void 0,void 0,void 0,(function(){return je(this,(function(e){switch(e.label){case 0:return[4,R({excerpt:u.currentExcerpt})];case 1:return e.sent(),p(ke(ke({},u),{isUnderReview:!1})),k.trackEvent("excerpt_generator_accepted"),[2]}}))}))},children:(0,w.__)("Accept","wp-parsely")}),(0,f.jsx)(h.Button,{isDestructive:!0,variant:"secondary",onClick:function(){return Se(void 0,void 0,void 0,(function(){return je(this,(function(e){return R({excerpt:u.oldExcerpt}),p(ke(ke({},u),{currentExcerpt:u.oldExcerpt,isUnderReview:!1})),k.trackEvent("excerpt_generator_discarded"),[2]}))}))},children:(0,w.__)("Discard","wp-parsely")})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(me,{isLoading:g,onPersonaChange:function(e){B("Persona",e),T(e)},onSettingChange:B,onToneChange:function(e){B("Tone",e),N(e)},persona:i.ExcerptSuggestions.Persona,tone:i.ExcerptSuggestions.Tone}),n&&G,(0,f.jsx)("div",{className:"excerpt-suggestions-generate",children:(0,f.jsxs)(h.Button,{onClick:function(){return Se(void 0,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:y(!0),l(void 0),n.label=1;case 1:return n.trys.push([1,3,4,5]),k.trackEvent("excerpt_generator_pressed"),[4,xe.getInstance().generateExcerpt(V,F,P,L)];case 2:return e=n.sent(),p({currentExcerpt:e,isUnderReview:!0,newExcerptGeneratedCount:u.newExcerptGeneratedCount+1,oldExcerpt:D}),[3,5];case 3:return(t=n.sent())instanceof te?l(t):(l(new te((0,w.__)("An unknown error occurred.","wp-parsely"),U.UnknownError)),console.error(t)),[3,5];case 4:return y(!1),[7];case 5:return[2]}}))}))},variant:"primary",isBusy:g,disabled:g||!F,children:[g&&(0,w.__)("Generating Excerpt…","wp-parsely"),!g&&u.newExcerptGeneratedCount>0&&(0,w.__)("Regenerate Excerpt","wp-parsely"),!g&&0===u.newExcerptGeneratedCount&&(0,w.__)("Generate Excerpt","wp-parsely")]})})]}),n&&(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]})]})},Te=function(){return(0,f.jsx)(h.Animate,{type:"loading",children:function(e){var t=e.className;return(0,f.jsx)("span",{className:t,children:(0,w.__)("Generating…","wp-parsely")})}})},Ee=function(){return(0,f.jsx)(q.PostTypeSupportCheck,{supportKeys:"excerpt",children:(0,f.jsx)(p,{name:"parsely-post-excerpt",title:(0,w.__)("Excerpt","wp-parsely"),children:(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Cr(window.wpParselyContentHelperSettings),children:(0,f.jsx)(Pe,{isDocumentSettingPanel:!0})})})})},Le=function(e,t){var n,r,i;return t!==Nr?e:H().ExcerptSuggestions?((null===(n=null===window||void 0===window?void 0:window.Jetpack_Editor_Initial_State)||void 0===n?void 0:n.available_blocks["ai-content-lens"])&&(console.log("Parse.ly: Jetpack AI is enabled and will be disabled."),(0,K.removeFilter)("blocks.registerBlockType","jetpack/ai-content-lens-features")),(0,x.registerPlugin)("wp-parsely-excerpt-suggestions",{render:function(){return(0,f.jsx)(Ee,{})}}),(null===(r=(0,v.dispatch)("core/editor"))||void 0===r?void 0:r.removeEditorPanel)?null===(i=(0,v.dispatch)("core/editor"))||void 0===i||i.removeEditorPanel("post-excerpt"):null==Y||Y.removeEditorPanel("post-excerpt"),e):e};function Ne(){(0,K.addFilter)("plugins.registerPlugin","wp-parsely-excerpt-suggestions",Le,1e3)}var Ce=window.wp.blockEditor;function Ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Oe=function(){return Oe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0)return r(e.innerBlocks,t[s].innerBlocks);if(JSON.stringify(e)!==JSON.stringify(t[s])){var o=t[s],a=i.parseFromString(e.attributes.content||"","text/html"),l=i.parseFromString((null==o?void 0:o.attributes.content)||"","text/html"),c=Array.from(a.querySelectorAll("a[data-smartlink]")),u=Array.from(l.querySelectorAll("a[data-smartlink]")),p=c.filter((function(e){return!u.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),d=u.filter((function(e){return!c.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),f=c.filter((function(e){var t=u.find((function(t){return t.dataset.smartlink===e.dataset.smartlink}));return t&&t.outerHTML!==e.outerHTML}));(p.length>0||d.length>0||f.length>0)&&n.push({block:e,prevBlock:o,addedLinks:p,removedLinks:d,changedLinks:f})}}}))};return r(e,t),n}(a,l.current);o.length>0&&(o.forEach((function(e){e.changedLinks.length>0&&n&&n(e),e.addedLinks.length>0&&i&&i(e),e.removedLinks.length>0&&r&&r(e)})),l.current=a)}),o);return e(t),function(){e.cancel()}}),[a,o,t,i,n,r]),null},Me=function(e){var t=e.value,n=e.onChange,r=e.max,i=e.min,s=e.suffix,o=e.size,a=e.label,l=e.initialPosition,c=e.disabled,u=e.className;return(0,f.jsxs)("div",{className:"parsely-inputrange-control ".concat(u||""),children:[(0,f.jsx)(h.__experimentalHeading,{className:"parsely-inputrange-control__label",level:3,children:a}),(0,f.jsxs)("div",{className:"parsely-inputrange-control__controls",children:[(0,f.jsx)(h.__experimentalNumberControl,{disabled:c,value:t,suffix:(0,f.jsx)(h.__experimentalInputControlSuffixWrapper,{children:s}),size:null!=o?o:"__unstable-large",min:i,max:r,onChange:function(e){var t=parseInt(e,10);isNaN(t)||n(t)}}),(0,f.jsx)(h.RangeControl,{disabled:c,value:t,showTooltip:!1,initialPosition:l,onChange:function(e){n(e)},withInputField:!1,min:i,max:r})]})]})},De=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}l((r=r.apply(e,t||[])).next())}))},Fe=function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]

","\n\x3c!-- /wp:paragraph --\x3e");t&&d((0,Re.parse)(n))}),[s]),(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:o,right:a,up:o,down:a}}),(0,f.jsx)("div",{className:"review-suggestion-post-title",children:null===(t=s.post_data)||void 0===t?void 0:t.title}),(0,f.jsxs)("div",{className:"review-suggestion-preview",children:[!(null===(n=s.post_data)||void 0===n?void 0:n.is_first_paragraph)&&(0,f.jsx)(Pt,{topOrBottom:"top"}),(0,f.jsx)(jt,{block:p[0],link:s,useOriginalBlock:!0}),!(null===(r=s.post_data)||void 0===r?void 0:r.is_last_paragraph)&&(0,f.jsx)(Pt,{topOrBottom:"bottom"})]}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(Tt,{link:s}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:o,icon:_t,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsx)("div",{className:"reviews-controls-middle",children:(0,f.jsx)(h.Button,{target:"_blank",href:(null===(i=s.post_data)||void 0===i?void 0:i.edit_link)+"&smart-link="+s.uid,variant:"secondary",onClick:function(){k.trackEvent("smart_linking_open_in_editor_pressed",{type:"inbound",uid:s.uid})},children:(0,w.__)("Open in the Editor","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:a,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ie,{icon:xt})]})})]})]})},Lt=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",className:i,width:n,height:n,viewBox:"0 0 24 24",fill:"none",children:[(0,f.jsx)(h.Path,{d:"M8.18983 5.90381L8.83642 7.54325L10.4758 8.18983L8.83642 8.8364L8.18983 10.4759L7.54324 8.8364L5.90381 8.18983L7.54324 7.54325L8.18983 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M15.048 5.90381L15.9101 8.08972L18.0961 8.95186L15.9101 9.81397L15.048 11.9999L14.1859 9.81397L12 8.95186L14.1859 8.08972L15.048 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M11.238 10.4761L12.3157 13.2085L15.048 14.2861L12.3157 15.3638L11.238 18.0962L10.1603 15.3638L7.42798 14.2861L10.1603 13.2085L11.238 10.4761Z"})]})},Nt=function(e,t,n){if(n||2===arguments.length)for(var r,i=0,s=t.length;ii.bottom)&&(n.scrollTop=r.offsetTop-n.offsetTop)}}}}),[t,l]);var u=function(){var e=document.querySelector(".smart-linking-review-sidebar-tabs [data-active-item]"),t=null==e?void 0:e.nextElementSibling;t||(t=document.querySelector('.smart-linking-review-sidebar-tabs [role="tab"]')),t&&t.click()},p=(0,f.jsxs)("span",{className:"smart-linking-menu-label",children:[(0,w.__)("NEW","wp-parsely"),(0,f.jsx)(Lt,{})]}),d=[];n&&n.length>0&&d.push({name:"outbound",title:(0,w.__)("Outbound","wp-parsely")}),r&&r.length>0&&d.push({name:"inbound",title:(0,w.__)("Inbound","wp-parsely")});var v="outbound";return d=d.filter((function(e){return"outbound"===e.name&&r&&0===r.length&&(e.title=(0,w.__)("Outbound Smart Links","wp-parsely"),v="outbound"),"inbound"===e.name&&n&&0===n.length&&(e.title=(0,w.__)("Inbound Smart Links","wp-parsely"),v="inbound"),e})),(0,f.jsxs)("div",{className:"smart-linking-review-sidebar",ref:s,children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{tab:function(){return u()},"shift+tab":function(){return u()}}}),(0,f.jsx)(h.TabPanel,{className:"smart-linking-review-sidebar-tabs",initialTabName:v,tabs:d,onSelect:function(e){var t,s;"outbound"===e&&n&&n.length>0&&i(n[0]),"inbound"===e&&r&&r.length>0&&i(r[0]),k.trackEvent("smart_linking_modal_tab_selected",{tab:e,total_inbound:null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0,total_outbound:null!==(s=null==n?void 0:n.length)&&void 0!==s?s:0})},children:function(e){return(0,f.jsxs)(f.Fragment,{children:["outbound"===e.name&&(0,f.jsx)(f.Fragment,{children:n&&0!==n.length?n.map((function(e,n){return(0,f.jsxs)(h.MenuItem,{ref:function(e){o.current[n]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:[(0,f.jsx)("span",{className:"smart-linking-menu-item",children:e.text}),!e.applied&&p]},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No outbound links found.","wp-parsely")]})}),"inbound"===e.name&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"review-sidebar-tip",children:(0,w.__)("This section shows external posts that link back to the current post.","wp-parsely")}),r&&0!==r.length?r.map((function(e,r){var s;return(0,f.jsx)(h.MenuItem,{ref:function(e){o.current[(n?n.length:0)+r]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:(0,f.jsx)("span",{className:"smart-linking-menu-item",children:null===(s=e.post_data)||void 0===s?void 0:s.title})},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No inbound links found.","wp-parsely")]})]})]})}})]})},At=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm.5 16c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V7h15v12zM9 10H7v2h2v-2zm0 4H7v2h2v-2zm4-4h-2v2h2v-2zm4 0h-2v2h2v-2zm-4 4h-2v2h2v-2zm4 0h-2v2h2v-2z"})}),Ot=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10 4.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm2.25 7.5v-1A2.75 2.75 0 0011 8.25H7A2.75 2.75 0 004.25 11v1h1.5v-1c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v1h1.5zM4 20h9v-1.5H4V20zm16-4H4v-1.5h16V16z",fillRule:"evenodd",clipRule:"evenodd"})}),It=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m7.3 9.7 1.4 1.4c.2-.2.3-.3.4-.5 0 0 0-.1.1-.1.3-.5.4-1.1.3-1.6L12 7 9 4 7.2 6.5c-.6-.1-1.1 0-1.6.3 0 0-.1 0-.1.1-.3.1-.4.2-.6.4l1.4 1.4L4 11v1h1l2.3-2.3zM4 20h9v-1.5H4V20zm0-5.5V16h16v-1.5H4z"})}),Rt=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M3.99961 13C4.67043 13.3354 4.6703 13.3357 4.67017 13.3359L4.67298 13.3305C4.67621 13.3242 4.68184 13.3135 4.68988 13.2985C4.70595 13.2686 4.7316 13.2218 4.76695 13.1608C4.8377 13.0385 4.94692 12.8592 5.09541 12.6419C5.39312 12.2062 5.84436 11.624 6.45435 11.0431C7.67308 9.88241 9.49719 8.75 11.9996 8.75C14.502 8.75 16.3261 9.88241 17.5449 11.0431C18.1549 11.624 18.6061 12.2062 18.9038 12.6419C19.0523 12.8592 19.1615 13.0385 19.2323 13.1608C19.2676 13.2218 19.2933 13.2686 19.3093 13.2985C19.3174 13.3135 19.323 13.3242 19.3262 13.3305L19.3291 13.3359C19.3289 13.3357 19.3288 13.3354 19.9996 13C20.6704 12.6646 20.6703 12.6643 20.6701 12.664L20.6697 12.6632L20.6688 12.6614L20.6662 12.6563L20.6583 12.6408C20.6517 12.6282 20.6427 12.6108 20.631 12.5892C20.6078 12.5459 20.5744 12.4852 20.5306 12.4096C20.4432 12.2584 20.3141 12.0471 20.1423 11.7956C19.7994 11.2938 19.2819 10.626 18.5794 9.9569C17.1731 8.61759 14.9972 7.25 11.9996 7.25C9.00203 7.25 6.82614 8.61759 5.41987 9.9569C4.71736 10.626 4.19984 11.2938 3.85694 11.7956C3.68511 12.0471 3.55605 12.2584 3.4686 12.4096C3.42484 12.4852 3.39142 12.5459 3.36818 12.5892C3.35656 12.6108 3.34748 12.6282 3.34092 12.6408L3.33297 12.6563L3.33041 12.6614L3.32948 12.6632L3.32911 12.664C3.32894 12.6643 3.32879 12.6646 3.99961 13ZM11.9996 16C13.9326 16 15.4996 14.433 15.4996 12.5C15.4996 10.567 13.9326 9 11.9996 9C10.0666 9 8.49961 10.567 8.49961 12.5C8.49961 14.433 10.0666 16 11.9996 16Z"})}),Bt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})}),Mt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"})}),Dt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),Ft=function(e){var t,n,r=e.post,i=e.imageUrl,s=e.icon,o=void 0===s?bt:s,a=e.size,l=void 0===a?100:a,c=e.className,u=void 0===c?"":c,p=null!==(t=null==r?void 0:r.thumbnail)&&void 0!==t?t:i,d=null!==(n=null==r?void 0:r.title.rendered)&&void 0!==n?n:"";return(0,f.jsx)("div",{className:"parsely-thumbnail ".concat(u),style:{width:l,height:l},children:p?(0,f.jsx)("img",{src:p,alt:d,width:l,height:l,loading:"lazy","aria-hidden":""===d}):(0,f.jsx)("div",{className:"parsely-thumbnail-icon-container",children:(0,f.jsx)(h.Icon,{icon:o,size:l})})})};function Vt(e,t,n){void 0===t&&(t=1),void 0===n&&(n="");var r=parseInt(e.replace(/\D/g,""),10);if(r<1e3)return e;r<1e4&&(t=1);var i=r,s=r.toString(),o="",a=0;return Object.entries({1e3:"k","1,000,000":"M","1,000,000,000":"B","1,000,000,000,000":"T","1,000,000,000,000,000":"Q"}).forEach((function(e){var n=e[0],l=e[1],c=parseInt(n.replace(/\D/g,""),10);if(r>=c){var u=t;(i=r/c)%1>1/a&&(u=i>10?1:2),u=parseFloat(i.toFixed(2))===parseFloat(i.toFixed(0))?0:u,s=i.toFixed(u),o=l}a=c})),s+n+o}var Gt,Ht=function(e){var t,n,r,i,s=null===(t=e.link.match)||void 0===t?void 0:t.blockId,o=(0,v.useSelect)((function(e){var t=e("core/block-editor"),n=t.getBlock,r=t.getBlockParents;return s?{block:n(s),parents:r(s).map((function(e){return n(e)})).filter((function(e){return void 0!==e}))}:{block:void 0,parents:[]}}),[s]),a=o.block,l=o.parents;return a?(0,f.jsxs)("div",{className:"review-suggestions-breadcrumbs",children:[l.map((function(e,t){var n;return(0,f.jsxs)("span",{children:[(0,f.jsx)("span",{className:"breadcrumbs-parent-block",children:null===(n=(0,Re.getBlockType)(e.name))||void 0===n?void 0:n.title}),(0,f.jsx)("span",{className:"breadcrumbs-parent-separator",children:" / "})]},t)})),(0,f.jsxs)("span",{className:"breadcrumbs-current-block",children:[(0,f.jsx)("span",{className:"breadcrumbs-current-block-type",children:null===(n=(0,Re.getBlockType)(a.name))||void 0===n?void 0:n.title}),(null===(i=null===(r=a.attributes)||void 0===r?void 0:r.metadata)||void 0===i?void 0:i.name)&&(0,f.jsx)("span",{className:"breadcrumbs-current-block-name",children:a.attributes.metadata.name})]})]}):(0,f.jsx)(f.Fragment,{})},zt=function(e){var t,n,r,i,s,o,a,l,c,u,p,d,v,g,y=e.link,m=null!==(n=null===(t=y.wp_post_meta)||void 0===t?void 0:t.author)&&void 0!==n?n:(0,w.__)("N/A","wp-parsely"),b=null!==(i=null===(r=y.post_stats)||void 0===r?void 0:r.avg_engaged)&&void 0!==i?i:(0,w.__)("N/A","wp-parsely"),_=(null===(s=y.wp_post_meta)||void 0===s?void 0:s.date)?function(e){if(!1===function(e){return!isNaN(+e)&&0!==e.getTime()}(e))return pt;var t=ct;return e.getUTCFullYear()===(new Date).getUTCFullYear()&&(t=ut),Intl.DateTimeFormat(document.documentElement.lang||"en",t).format(e)}(new Date(y.wp_post_meta.date)):(0,w.__)("N/A","wp-parsely"),x=null!==(a=null===(o=y.wp_post_meta)||void 0===o?void 0:o.thumbnail)&&void 0!==a&&a,k=null!==(c=null===(l=y.wp_post_meta)||void 0===l?void 0:l.title)&&void 0!==c?c:(0,w.__)("N/A","wp-parsely"),S=null!==(p=null===(u=y.wp_post_meta)||void 0===u?void 0:u.type)&&void 0!==p?p:(0,w.__)("External","wp-parsely"),j=null===(d=y.wp_post_meta)||void 0===d?void 0:d.url,P=(null===(v=y.post_stats)||void 0===v?void 0:v.views)?Vt(y.post_stats.views):(0,w.__)("N/A","wp-parsely"),T=(null===(g=y.post_stats)||void 0===g?void 0:g.visitors)?Vt(y.post_stats.visitors):(0,w.__)("N/A","wp-parsely");return(0,f.jsxs)("div",{className:"wp-parsely-link-suggestion-link-details",children:[(0,f.jsx)("div",{className:"thumbnail-column",children:x?(0,f.jsx)(Ft,{imageUrl:x,size:52}):(0,f.jsx)(Ft,{icon:bt,size:52})}),(0,f.jsxs)("div",{className:"data-column",children:[(0,f.jsxs)("div",{className:"title-row",children:[(0,f.jsx)(h.Tooltip,{text:k,children:(0,f.jsx)("span",{children:k})}),j&&(0,f.jsx)(h.Button,{href:j,target:"_blank",variant:"link",rel:"noopener",children:(0,f.jsx)(ie,{icon:$,size:18})})]}),(0,f.jsxs)("div",{className:"data-row",children:[(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:At,size:16}),(0,f.jsx)("span",{children:_})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ie,{icon:Ot,size:16}),(0,f.jsx)(h.Tooltip,{text:m,children:(0,f.jsx)("span",{children:m})})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ie,{icon:It,size:16}),(0,f.jsx)(h.Tooltip,{text:S,children:(0,f.jsx)("span",{children:S})})]})]}),y.post_stats&&(0,f.jsxs)("div",{className:"data-row",children:[P&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:Rt,size:16}),(0,f.jsx)("span",{children:P})]}),T&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:Bt,size:16}),(0,f.jsx)("span",{children:T})]}),b&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(h.Dashicon,{icon:"clock",size:16}),(0,f.jsx)("span",{children:b})]})]})]})]})},Ut=function(e){var t=e.link,n=e.onNext,r=e.onPrevious,i=e.onAccept,s=e.onReject,o=e.onRemove,a=e.onSelectInEditor,l=e.hasPrevious,c=e.hasNext;if(t&&void 0!==t.post_data)return(0,f.jsx)(Et,{link:t,onNext:n,onPrevious:r,onAccept:i,onReject:s,onRemove:o,onSelectInEditor:a,hasPrevious:l,hasNext:c});if(!(null==t?void 0:t.match))return(0,f.jsx)(f.Fragment,{children:(0,w.__)("This Smart Link does not have any matches in the current content.","wp-parsely")});var u=t.match.blockId,p=(0,v.select)("core/block-editor").getBlock(u),d=t.applied;return p?(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:r,right:n,up:r,down:n,a:function(){t&&!t.applied&&i()},r:function(){t&&(t.applied?o():s())}}}),(0,f.jsx)(Ht,{link:t}),(0,f.jsx)("div",{className:"review-suggestion-preview",children:(0,f.jsx)(jt,{block:p,link:t})}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(zt,{link:t}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:r,icon:_t,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsxs)("div",{className:"reviews-controls-middle",children:[!d&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Reject","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:Mt,onClick:s,variant:"secondary",children:(0,w.__)("Reject","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"A",text:(0,w.__)("Accept","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",icon:Dt,onClick:i,variant:"secondary",children:(0,w.__)("Accept","wp-parsely")})})]}),d&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Remove","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:Mt,onClick:o,variant:"secondary",children:(0,w.__)("Remove","wp-parsely")})}),(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",onClick:a,variant:"secondary",children:(0,w.__)("Select in Editor","wp-parsely")})]})]}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:n,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ie,{icon:xt})]})})]})]}):(0,f.jsx)(f.Fragment,{children:(0,w.__)("No block is selected.","wp-parsely")})},qt=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}l((r=r.apply(e,t||[])).next())}))},Kt=function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&(a=o[0],(l=a.parentNode)&&(c=document.createTextNode(null!==(u=a.textContent)&&void 0!==u?u:""),l.replaceChild(c,a),Z.updateBlockAttributes(n,{content:s.innerHTML}))),[4,L(t.uid)]):[2]):[2];case 1:return p.sent(),[2]}}))}))},C=(0,m.useCallback)((function(){c(!1),_().filter((function(e){return!e.applied})).length>0?o(!0):(W.unlockPostAutosaving("smart-linking-review-modal"),t())}),[_,t]),A=function(e){o(!1),e?(c(!1),T().then((function(){C()}))):c(!0)},O=function(){if(Ge(S)){var e=g.indexOf(S);if(!g[t=e+1])return;j(g[t])}else{var t;if(e=d.indexOf(S),!d[t=e+1])return;j(d[t])}},I=function(){if(Ge(S)){var e=g.indexOf(S);if(!g[t=e-1])return;j(g[t])}else{var t;if(e=d.indexOf(S),!d[t=e-1])return;j(d[t])}};return(0,m.useEffect)((function(){l?W.lockPostAutosaving("smart-linking-review-modal"):l&&0===p.length&&C()}),[l,t,p,C]),(0,m.useEffect)((function(){c(n)}),[n]),(0,f.jsxs)(f.Fragment,{children:[l&&(0,f.jsx)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),className:"wp-parsely-smart-linking-review-modal",onRequestClose:C,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,children:(0,f.jsxs)("div",{className:"smart-linking-modal-body",children:[(0,f.jsx)(Ct,{outboundLinks:d,inboundLinks:g,activeLink:S,setSelectedLink:j}),S&&(Ge(S)?(0,f.jsx)(Et,{link:S,onNext:O,onPrevious:I,hasNext:g.indexOf(S)0}):(0,f.jsx)(Ut,{link:S,hasNext:b().indexOf(S)0,onNext:O,onPrevious:I,onAccept:function(){return qt(void 0,void 0,void 0,(function(){var e,t;return Kt(this,(function(n){switch(n.label){case 0:return S.match?(r(S),[4,(i=S.match.blockId,s=S,qt(void 0,void 0,void 0,(function(){var e,t;return Kt(this,(function(n){switch(n.label){case 0:return(e=document.createElement("a")).href=s.href.itm,e.title=s.title,e.setAttribute("data-smartlink",s.uid),(t=(0,v.select)("core/block-editor").getBlock(i))?(Ue(t,s,e),s.applied=!0,[4,E(s)]):[2];case 1:return n.sent(),[2]}}))})))]):[2];case 1:return n.sent(),k.trackEvent("smart_linking_link_accepted",{link:S.href.raw,title:S.title,text:S.text,uid:S.uid}),0===y().length?(C(),[2]):(e=d.indexOf(S),d[t=e+1]?j(d[t]):j(d[0]),[2])}var i,s}))}))},onReject:function(){return qt(void 0,void 0,void 0,(function(){var e,t;return Kt(this,(function(n){switch(n.label){case 0:return e=d.indexOf(S),d[t=e+1]?j(d[t]):d[0]?j(d[0]):C(),[4,L(S.uid)];case 1:return n.sent(),k.trackEvent("smart_linking_link_rejected",{link:S.href.raw,title:S.title,text:S.text,uid:S.uid}),[2]}}))}))},onRemove:function(){return qt(void 0,void 0,void 0,(function(){var e,t,n,r;return Kt(this,(function(i){switch(i.label){case 0:return S.match?(e=(0,v.select)("core/block-editor").getBlock(S.match.blockId))?(t=b(),n=t.indexOf(S),r=n-1,[4,N(e,S)]):[3,2]:[2];case 1:if(i.sent(),k.trackEvent("smart_linking_link_removed",{link:S.href.raw,title:S.title,text:S.text,uid:S.uid}),0===(t=b()).length&&g.length>0)return j(g[0]),[2];if(0===t.length&&0===g.length)return C(),[2];if(t[r])return j(t[r]),[2];j(t[0]),i.label=2;case 2:return[2]}}))}))},onSelectInEditor:function(){if(S.match){var e=(0,v.select)("core/block-editor").getBlock(S.match.blockId);if(e){Z.selectBlock(e.clientId);var t=document.querySelector('[data-block="'.concat(e.clientId,'"]'));t&&Xe(t,S.uid),k.trackEvent("smart_linking_select_in_editor_pressed",{type:"outbound",uid:S.uid}),C()}}}}))]})}),s&&(0,f.jsxs)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),onRequestClose:function(){return A(!1)},className:"wp-parsely-smart-linking-close-dialog",children:[(0,w.__)("Are you sure you want to close? All un-accepted smart links will not be added.","wp-parsely"),(0,f.jsxs)("div",{className:"smart-linking-close-dialog-actions",children:[(0,f.jsx)(h.Button,{variant:"secondary",onClick:function(){return A(!1)},children:(0,w.__)("Go Back","wp-parsely")}),(0,f.jsx)(h.Button,{variant:"primary",onClick:function(){return A(!0)},children:(0,w.__)("Close","wp-parsely")})]})]})]})})),Wt=function(){return Wt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&S("success",/* translators: %d: number of smart links applied */ /* translators: %d: number of smart links applied */ +(0,w.sprintf)((0,w.__)("%s smart links successfully applied.","wp-parsely"),g),{type:"snackbar"}):y(0)}),[_]),(0,m.useEffect)((function(){if(!(Object.keys(R).length>0)){var e={maxLinksPerPost:a.SmartLinking.MaxLinks};ee(e)}}),[ee,a]);var de=(0,v.useSelect)((function(e){var t=e("core/block-editor"),r=t.getSelectedBlock,i=t.getBlock,s=t.getBlocks,o=e("core/editor"),a=o.getEditedPostContent,l=o.getCurrentPostAttribute;return{allBlocks:s(),selectedBlock:n?i(n):r(),postContent:a(),postPermalink:l("link")}}),[n]),fe=de.allBlocks,he=de.selectedBlock,ve=de.postContent,ge=de.postPermalink,ye=function(e){return Yt(void 0,void 0,void 0,(function(){var t,n,r,i,s;return $t(this,(function(o){switch(o.label){case 0:t=[],o.label=1;case 1:return o.trys.push([1,4,,9]),[4,re((n=L||!he)?et.All:et.Selected)];case 2:return o.sent(),a=ge.replace(/^https?:\/\//i,""),r=["http://"+a,"https://"+a],i=function(e){return e.map((function(e){return e.href.raw}))}(F),r.push.apply(r,i),[4,yt.getInstance().generateSmartLinks(he&&!n?(0,Re.getBlockContent)(he):ve,O,r)];case 3:return t=o.sent(),[3,9];case 4:if((s=o.sent()).code&&s.code===U.ParselyAborted)throw s.numRetries=3-e,s;return e>0&&s.retryFetch?(console.error(s),[4,oe(!0)]):[3,8];case 5:return o.sent(),[4,ae()];case 6:return o.sent(),[4,ye(e-1)];case 7:return[2,o.sent()];case 8:throw s;case 9:return[2,t]}var a}))}))},me=function(){for(var e=[],t=0;t[type="button"]').forEach((function(e){e.setAttribute("disabled","disabled")}))},_e=function(){document.querySelectorAll('.edit-post-header__settings>[type="button"]').forEach((function(e){e.removeAttribute("disabled")})),W.unlockPostSaving("wp-parsely-block-overlay")};return(0,f.jsxs)("div",{className:"wp-parsely-smart-linking",children:[(0,f.jsx)(Be,{isDetectingEnabled:!E,onLinkRemove:function(e){!function(e){De(this,void 0,void 0,(function(){var t,n,r;return Fe(this,(function(i){switch(i.label){case 0:return[4,$e((0,Re.getBlockContent)(e),e.clientId)];case 1:return t=i.sent(),n=t.missingSmartLinks,r=t.didAnyFixes,n.forEach((function(e){(0,v.dispatch)(st).removeSmartLink(e.uid)})),[2,r]}}))}))}(e.block)}}),(0,f.jsxs)(h.PanelRow,{className:t,children:[(0,f.jsxs)("div",{className:"smart-linking-text",children:[(0,w.__)("Automatically insert links to your most relevant, top performing content.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/smart-linking/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(ie,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),C&&(0,f.jsx)(h.Notice,{status:"info",onRemove:function(){return Z(null)},className:"wp-parsely-content-helper-error",children:C.Message()}),_&&g>0&&(0,f.jsx)(h.Notice,{status:"success",onRemove:function(){return x(!1)},className:"wp-parsely-smart-linking-suggested-links",children:(0,w.sprintf)(/* translators: 1 - number of smart links generated */ /* translators: 1 - number of smart links generated */ +(0,w.__)("Successfully added %s smart links.","wp-parsely"),g>0?g:A.length)}),(0,f.jsx)(lt,{disabled:T,selectedBlock:he,onSettingChange:function(e,t){var n;p({SmartLinking:Wt(Wt({},a.SmartLinking),(n={},n[e]=t,n))}),"MaxLinks"===e&&se(t)}}),(0,f.jsx)("div",{className:"smart-linking-generate",children:(0,f.jsx)(h.Button,{onClick:function(){return Yt(void 0,void 0,void 0,(function(){var e,t,n,r,s,o,a,l;return $t(this,(function(c){switch(c.label){case 0:return[4,K(!0)];case 1:return c.sent(),[4,le()];case 2:return c.sent(),[4,Z(null)];case 3:return c.sent(),x(!1),k.trackEvent("smart_linking_generate_pressed",{is_full_content:L,selected_block:null!==(o=null==he?void 0:he.name)&&void 0!==o?o:"none",context:i}),[4,me(L?"all":null==he?void 0:he.clientId)];case 4:c.sent(),e=setTimeout((function(){var e;K(!1),k.trackEvent("smart_linking_generate_timeout",{is_full_content:L,selected_block:null!==(e=null==he?void 0:he.name)&&void 0!==e?e:"none",context:i}),we(L?"all":null==he?void 0:he.clientId)}),18e4),t=B,c.label=5;case 5:return c.trys.push([5,8,10,15]),[4,ye(3)];case 6:return n=c.sent(),[4,(u=n,Yt(void 0,void 0,void 0,(function(){var e;return $t(this,(function(t){switch(t.label){case 0:return u=u.filter((function(e){return!F.some((function(t){return t.uid===e.uid&&t.applied}))})),e=ge.replace(/^https?:\/\//,"").replace(/\/+$/,""),u=(u=u.filter((function(t){return!t.href.raw.includes(e)||(console.warn("PCH Smart Linking: Skipping self-reference link: ".concat(t.href)),!1)}))).filter((function(e){return!F.some((function(t){return t.href===e.href?(console.warn("PCH Smart Linking: Skipping duplicate link: ".concat(e.href)),!0):t.text===e.text&&t.offset!==e.offset&&(console.warn("PCH Smart Linking: Skipping duplicate link text: ".concat(e.text)),!0)}))})),u=(u=Ze(L?fe:[he],u,{}).filter((function(e){return e.match}))).filter((function(e){if(!e.match)return!1;var t=e.match.blockLinkPosition,n=t+e.text.length;return!F.some((function(r){if(!r.match)return!1;if(e.match.blockId!==r.match.blockId)return!1;var i=r.match.blockLinkPosition,s=i+r.text.length;return t>=i&&n<=s}))})),[4,Y(u)];case 1:return t.sent(),[2,u]}}))})))];case 7:if(0===c.sent().length)throw new te((0,w.__)("No smart links were generated.","wp-parsely"),U.ParselySuggestionsApiNoData,"");return ce(!0),[3,15];case 8:return r=c.sent(),s=new te(null!==(a=r.message)&&void 0!==a?a:"An unknown error has occurred.",null!==(l=r.code)&&void 0!==l?l:U.UnknownError),r.code&&r.code===U.ParselyAborted&&(s.message=(0,w.sprintf)(/* translators: %d: number of retry attempts, %s: attempt plural */ /* translators: %d: number of retry attempts, %s: attempt plural */ +(0,w.__)("The Smart Linking process was cancelled after %1$d %2$s.","wp-parsely"),r.numRetries,(0,w._n)("attempt","attempts",r.numRetries,"wp-parsely"))),console.error(r),[4,Z(s)];case 9:return c.sent(),s.createErrorSnackbar(),[3,15];case 10:return[4,K(!1)];case 11:return c.sent(),[4,re(t)];case 12:return c.sent(),[4,oe(!1)];case 13:return c.sent(),[4,we(L?"all":null==he?void 0:he.clientId)];case 14:return c.sent(),clearTimeout(e),[7];case 15:return[2]}var u}))}))},variant:"primary",isBusy:T,disabled:T,children:M?(0,w.sprintf)(/* translators: %1$d: number of retry attempts, %2$d: maximum number of retries */ /* translators: %1$d: number of retry attempts, %2$d: maximum number of retries */ +(0,w.__)("Retrying… Attempt %1$d of %2$d","wp-parsely"),D,3):T?(0,w.__)("Generating Smart Links…","wp-parsely"):(0,w.__)("Add Smart Links","wp-parsely")})}),(G.length>0||V.length>0)&&(0,f.jsx)("div",{className:"smart-linking-manage",children:(0,f.jsx)(h.Button,{onClick:function(){return Yt(void 0,void 0,void 0,(function(){var e,t;return $t(this,(function(n){switch(n.label){case 0:return[4,Je()];case 1:return e=n.sent(),t=We(),[4,Y(t)];case 2:return n.sent(),ce(!0),k.trackEvent("smart_linking_review_pressed",{num_smart_links:F.length,has_fixed_links:e,context:i}),[2]}}))}))},variant:"secondary",disabled:T,children:(0,w.__)("Review Smart Links","wp-parsely")})})]}),E&&(0,f.jsx)(Zt,{isOpen:E,onAppliedLink:function(){y((function(e){return e+1}))},onClose:function(){x(!0),ce(!1)}})]})},en=function(){return en=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0)&&(t(),e())}))}))]}))},new((n=void 0)||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}l((r=r.apply(e,t||[])).next())}));var e,t,n,r}().then((function(){var t=document.querySelector(".wp-block-post-content");Xe(t,e)}))})))},fn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M7 11.5h10V13H7z"})}),hn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"})}),vn=function(e){var t=e.title,n=e.icon,r=e.subtitle,i=e.level,s=void 0===i?2:i,o=e.children,a=e.controls,l=e.onClick,c=e.isOpen,u=e.isLoading,p=e.dropdownChildren;return(0,f.jsxs)("div",{className:"performance-stat-panel",children:[(0,f.jsxs)(h.__experimentalHStack,{className:"panel-header level-"+s,children:[(0,f.jsx)(h.__experimentalHeading,{level:s,children:t}),r&&!c&&(0,f.jsx)("span",{className:"panel-subtitle",children:r}),a&&!p&&(0,f.jsx)(h.DropdownMenu,{icon:n,label:(0,w.__)("Settings","wp-parsely"),className:"panel-settings-button",controls:a}),p&&(0,f.jsx)(h.DropdownMenu,{icon:n,label:(0,w.__)("Settings","wp-parsely"),className:"panel-settings-button",children:p}),n&&!p&&!a&&(0,f.jsx)(h.Button,{icon:n,className:"panel-settings-button",isPressed:c,onClick:l})]}),(0,f.jsx)("div",{className:"panel-body",children:u?(0,f.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,f.jsx)(h.Spinner,{})}):o})]})},gn=function(e){var t=e.data,n=e.isLoading,r=(0,m.useState)(B.Views),i=r[0],s=r[1],o=(0,m.useState)(!1),a=o[0],l=o[1];n||delete t.referrers.types.totals;var c=function(e){switch(e){case"social":return(0,w.__)("Social","wp-parsely");case"search":return(0,w.__)("Search","wp-parsely");case"other":return(0,w.__)("Other","wp-parsely");case"internal":return(0,w.__)("Internal","wp-parsely");case"direct":return(0,w.__)("Direct","wp-parsely")}return e},u=(0,w.sprintf)((0,w.__)("By %s","wp-parsely"),G(i)); +/* translators: %s: metric description */return(0,f.jsxs)(vn,{title:(0,w.__)("Categories","wp-parsely"),level:3,subtitle:u,isOpen:a,onClick:function(){return l(!a)},children:[a&&(0,f.jsx)("div",{className:"panel-settings",children:(0,f.jsx)(h.SelectControl,{value:i,prefix:(0,w.__)("By:","wp-parsely"),onChange:function(e){F(e,B)&&s(e)},children:Object.values(B).map((function(e){return(0,f.jsxs)("option",{value:e,disabled:"avg_engaged"===e,children:[G(e),"avg_engaged"===e&&" "+(0,w.__)("(coming soon)","wp-parsely")]},e)}))})}),n?(0,f.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,f.jsx)(h.Spinner,{})}):(0,f.jsxs)("div",{children:[(0,f.jsx)("div",{className:"multi-percentage-bar",children:Object.entries(t.referrers.types).map((function(e){var t=e[0],n=e[1],r=(0,w.sprintf)(/* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ /* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ (0,w.__)("%1$s: %2$s%%","wp-parsely"),c(t),n.viewsPercentage);return(0,f.jsx)(h.Tooltip /* translators: %s: percentage value */,{ /* translators: %s: percentage value */ -text:"".concat(c(t)," - ").concat((0,w.sprintf)((0,w.__)("%s%%","wp-parsely"),n.viewsPercentage)),delay:150,children:(0,f.jsx)("div",{"aria-label":r,className:"bar-fill "+t,style:{width:n.viewsPercentage+"%"}})},t)}))}),(0,f.jsx)("div",{className:"percentage-bar-labels",children:Object.entries(t.referrers.types).map((function(e){var t=e[0],n=e[1];return(0,f.jsxs)("div",{className:"single-label "+t,children:[(0,f.jsx)("div",{className:"label-color "+t}),(0,f.jsx)("div",{className:"label-text",children:c(t)}),(0,f.jsx)("div",{className:"label-value",children:Ft(n.views)})]},t)}))})]})]})},gn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M12 4V2.2L9 4.8l3 2.5V5.5c3.6 0 6.5 2.9 6.5 6.5 0 2.9-1.9 5.3-4.5 6.2v.2l-.1-.2c-.4.1-.7.2-1.1.2l.2 1.5c.3 0 .6-.1 1-.2 3.5-.9 6-4 6-7.7 0-4.4-3.6-8-8-8zm-7.9 7l1.5.2c.1-1.2.5-2.3 1.2-3.2l-1.1-.9C4.8 8.2 4.3 9.6 4.1 11zm1.5 1.8l-1.5.2c.1.7.3 1.4.5 2 .3.7.6 1.3 1 1.8l1.2-.8c-.3-.5-.6-1-.8-1.5s-.4-1.1-.4-1.7zm1.5 5.5c1.1.9 2.4 1.4 3.8 1.6l.2-1.5c-1.1-.1-2.2-.5-3.1-1.2l-.9 1.1z"})}),yn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M11 13h2v-2h-2v2zm-6 0h2v-2H5v2zm12-2v2h2v-2h-2z"})}),mn=function(){return mn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]%s has 0 views, or the Parse.ly API returned no data.","wp-parsely"),r),U.ParselyApiReturnedNoData,""))]):n.length>1?[2,Promise.reject(new te((0,w.sprintf)(/* translators: URL of the published post */ /* translators: URL of the published post */ -(0,w.__)("Multiple results were returned for the post %d by the Parse.ly API.","wp-parsely"),t),U.ParselyApiReturnedTooManyResults))]:[2,n[0]]}}))}))},t.prototype.fetchReferrerDataFromWpEndpoint=function(e,t,n){return Nn(this,void 0,void 0,(function(){return Cn(this,(function(r){switch(r.label){case 0:return[4,this.fetch({path:(0,we.addQueryArgs)("/wp-parsely/v2/stats/post/".concat(t,"/referrers"),Ln(Ln({},pt(e)),{itm_source:this.itmSource,total_views:n}))})];case 1:return[2,r.sent()]}}))}))},t}(be),On=function(){return On=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return t.sent(),[4,n(r-1)];case 2:return t.sent(),[3,4];case 3:a(e),i(!1),t.label=4;case 4:return[2]}}))}))})),[2]}))}))};return i(!0),n(1),function(){a(void 0)}}),[t]),(0,f.jsxs)("div",{className:"wp-parsely-performance-panel",children:[(0,f.jsx)(hn,{title:(0,w.__)("Performance Stats","wp-parsely"),icon:fn,dropdownChildren:function(e){var t=e.onClose;return(0,f.jsx)(Fn,{onClose:t})},children:(0,f.jsx)("div",{className:"panel-settings",children:(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:d.PerformanceStats.Period,prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Period:","wp-parsely")}),onChange:function(e){F(e,R)&&(v({PerformanceStats:On(On({},d.PerformanceStats),{Period:e})}),k.trackEvent("editor_sidebar_performance_period_changed",{period:e}))},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})})}),s?s.Message():(0,f.jsxs)(f.Fragment,{children:[Dn(d,"overview")&&(0,f.jsx)(Pn,{data:c,isLoading:r}),Dn(d,"categories")&&(0,f.jsx)(vn,{data:c,isLoading:r}),Dn(d,"referrers")&&(0,f.jsx)(Tn,{data:c,isLoading:r})]}),window.wpParselyPostUrl&&(0,f.jsx)(h.Button,{className:"wp-parsely-view-post",variant:"primary",onClick:function(){k.trackEvent("editor_sidebar_view_post_pressed")},href:window.wpParselyPostUrl,rel:"noopener",target:"_blank",children:(0,w.__)("View this in Parse.ly","wp-parsely")})]})},Gn=function(e){var t=e.period;return(0,f.jsx)(h.Panel,{children:(0,f.jsx)(Ie,{children:(0,f.jsx)(Vn,{period:t})})})},Hn=function(e){var t=e.filters,n=e.postData,r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Author","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Author)},options:i,value:t.author}),n.categories.length>=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Section","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Section)},options:o,value:t.section}),n.tags.length>=1&&(0,f.jsx)(h.FormTokenField,{__experimentalShowHowTo:!1,__next40pxDefaultSize:!0,label:"",placeholder:(0,w.__)("Tags","wp-parsely"),onChange:function(e){return r.onFiltersChange(e.toString(),M.Tag)},value:t.tags,suggestions:n.tags,maxLength:5})]})},zn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z"})}),Un=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M5.625 5.5h9.75c.069 0 .125.056.125.125v9.75a.125.125 0 0 1-.125.125h-9.75a.125.125 0 0 1-.125-.125v-9.75c0-.069.056-.125.125-.125ZM4 5.625C4 4.728 4.728 4 5.625 4h9.75C16.273 4 17 4.728 17 5.625v9.75c0 .898-.727 1.625-1.625 1.625h-9.75A1.625 1.625 0 0 1 4 15.375v-9.75Zm14.5 11.656v-9H20v9C20 18.8 18.77 20 17.251 20H6.25v-1.5h11.001c.69 0 1.249-.528 1.249-1.219Z"})}),qn=function(e){var t=e.size,n=void 0===t?40:t;return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"1",height:n,viewBox:"0 0 1 ".concat(n),fill:"none",children:(0,f.jsx)(h.Rect,{width:"1",height:n,fill:"#cccccc"})})};function Kn(e){var t=e.metric,n=e.post,r=e.avgEngagedIcon,i=e.viewsIcon;return"views"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Number of Views","wp-parsely")}),i,Ft(n.views.toString())]}):"avg_engaged"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Average Time","wp-parsely")}),r,n.avgEngaged]}):(0,f.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}var Zn,Wn=function(e){var t,n,r=e.metric,i=e.post,o=e.postContent,s=(0,v.useDispatch)("core/notices").createNotice,a=o&&(t=o,n=Ae(i.rawUrl),new RegExp("]*href=[\"'](http://|https://)?.*".concat(n,".*[\"'][^>]*>"),"i").test(t));return(0,f.jsxs)("div",{className:"related-post-single","data-testid":"related-post-single",children:[(0,f.jsx)("div",{className:"related-post-title",children:(0,f.jsxs)("a",{href:i.url,target:"_blank",rel:"noreferrer",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("View on website (opens new tab)","wp-parsely")}),i.title]})}),(0,f.jsx)("div",{className:"related-post-actions",children:(0,f.jsxs)("div",{className:"related-post-info",children:[(0,f.jsxs)("div",{children:[(0,f.jsx)("div",{className:"related-post-metric",children:(0,f.jsx)(Kn,{metric:r,post:i,viewsIcon:(0,f.jsx)(ie,{icon:It}),avgEngagedIcon:(0,f.jsx)(h.Dashicon,{icon:"clock",size:24})})}),a&&(0,f.jsx)("div",{className:"related-post-linked",children:(0,f.jsx)(h.Tooltip,{text:(0,w.__)("This post is linked in the content","wp-parsely"),children:(0,f.jsx)(ie,{icon:zn,size:24})})})]}),(0,f.jsx)(qn,{}),(0,f.jsxs)("div",{children:[(0,f.jsx)(h.Button,{icon:Un,iconSize:24,onClick:function(){navigator.clipboard.writeText(i.rawUrl).then((function(){s("success",(0,w.__)("URL copied to clipboard","wp-parsely"),{type:"snackbar"})}))},label:(0,w.__)("Copy URL to clipboard","wp-parsely")}),(0,f.jsx)(h.Button,{icon:(0,f.jsx)(j,{}),iconSize:18,href:i.dashUrl,target:"_blank",label:(0,w.__)("View in Parse.ly","wp-parsely")})]})]})})]})},Yn=window.wp.coreData,$n=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function __(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(__.prototype=n.prototype,new __)}}(),Jn=function(){return Jn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&f.every(Number.isInteger)?null!==(n=l("taxonomy","category",{include:f,context:"view"}))&&void 0!==n?n:void 0:null,tagRecords:s=Array.isArray(h)&&h.length>0&&h.every(Number.isInteger)?null!==(r=l("taxonomy","post_tag",{include:h,context:"view"}))&&void 0!==r?r:void 0:null,isLoading:u("getEntityRecords",["root","user",{include:[d],context:"view"}])||u("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||u("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}]),hasResolved:(c("getEntityRecords",["root","user",{include:[d],context:"view"}])||null===i)&&(c("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||null===o)&&(c("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}])||null===s)}}),[]);return(0,m.useEffect)((function(){var e=r.authorRecords,t=r.categoryRecords,i=r.tagRecords,o=r.isLoading;r.hasResolved&&!o&&n({authors:e,categories:t,tags:i,isReady:!0})}),[r]),t}(),c=l.authors,u=l.categories,p=l.tags,d=l.isReady;(0,m.useEffect)((function(){if(d){var e=function(e){return function(e){return!(!Array.isArray(e)||0===e.length)&&e.every((function(e){return"name"in e&&"id"in e&&"slug"in e&&"description"in e&&"link"in e}))}(e)?e.map((function(e){return e.name})):[]};a({authors:e(c),categories:e(u),tags:e(p)})}}),[c,u,p,d]);var g=(0,m.useState)(!0),y=g[0],b=g[1],x=(0,m.useState)(),_=x[0],S=x[1],j=(0,m.useState)([]),P=j[0],T=j[1],E=(0,m.useState)({author:"",section:"",tags:[]}),L=E[0],N=E[1],C=(0,m.useState)(void 0),A=C[0],O=C[1],D=(0,ne.useDebounce)(O,1e3);return(0,v.useSelect)((function(e){if("undefined"==typeof jest){var t=e("core/editor").getEditedPostContent;D(t())}else D("Jest test is running")}),[D]),(0,m.useEffect)((function(){var e=function(t){return nr(void 0,void 0,void 0,(function(){return rr(this,(function(n){return er.getInstance().getRelatedPosts(r,i,L).then((function(e){T(e),b(!1)})).catch((function(n){return nr(void 0,void 0,void 0,(function(){return rr(this,(function(r){switch(r.label){case 0:return t>0&&n.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,e(t-1)];case 2:return r.sent(),[3,4];case 3:b(!1),S(n),r.label=4;case 4:return[2]}}))}))})),[2]}))}))};return b(!0),e(1),function(){b(!1),T([]),S(void 0)}}),[r,i,L,s]),0===s.authors.length&&0===s.categories.length&&0===s.tags.length&&d?(0,f.jsx)("div",{className:"wp-parsely-related-posts",children:(0,f.jsx)("div",{className:"related-posts-body",children:(0,w.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,f.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,f.jsx)("div",{className:"related-posts-description",children:(0,w.__)("Find top-performing related posts.","wp-parsely")}),(0,f.jsxs)("div",{className:"related-posts-body",children:[(0,f.jsxs)("div",{className:"related-posts-settings",children:[(0,f.jsx)(h.SelectControl,{size:"__unstable-large",onChange:function(e){var r;F(r=e,B)&&(n({RelatedPosts:tr(tr({},t.RelatedPosts),{Metric:r})}),k.trackEvent("related_posts_metric_changed",{metric:r}))},prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Metric:","wp-parsely")}),value:i,children:Object.values(B).map((function(e){return(0,f.jsx)("option",{value:e,children:G(e)},e)}))}),(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:r,prefix:(0,f.jsxs)(h.__experimentalInputControlPrefixWrapper,{children:[(0,w.__)("Period:","wp-parsely")," "]}),onChange:function(e){return function(e){F(e,R)&&(n({RelatedPosts:tr(tr({},t.RelatedPosts),{Period:e})}),k.trackEvent("related_posts_period_changed",{period:e}))}(e)},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})]}),(0,f.jsx)(Hn,{label:(0,w.__)("Filter by","wp-parsely"),filters:L,onFiltersChange:function(e,t){var n;if(null==e&&(e=""),M.Tag===t){var r=[];""!==e&&(r=e.split(",").map((function(e){return e.trim()}))),N(tr(tr({},L),{tags:r}))}else N(tr(tr({},L),((n={})[t]=e,n)))},postData:s}),(0,f.jsxs)("div",{className:"related-posts-wrapper",children:[_&&_.Message(),y&&(0,f.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,w.__)("Loading…","wp-parsely")}),!y&&!_&&0===P.length&&(0,f.jsx)("div",{className:"related-posts-empty",children:(0,w.__)("No related posts found.","wp-parsely")}),!y&&P.length>0&&(0,f.jsx)("div",{className:"related-posts-list",children:P.map((function(e){return(0,f.jsx)(Wn,{metric:i,post:e,postContent:A},e.id)}))})]})]})]})},or=(0,f.jsx)(b.SVG,{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10.97 10.159a3.382 3.382 0 0 0-2.857.955l1.724 1.723-2.836 2.913L7 17h1.25l2.913-2.837 1.723 1.723a3.38 3.38 0 0 0 .606-.825c.33-.63.446-1.343.35-2.032L17 10.695 13.305 7l-2.334 3.159Z"})}),sr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M18.3 11.7c-.6-.6-1.4-.9-2.3-.9H6.7l2.9-3.3-1.1-1-4.5 5L8.5 16l1-1-2.7-2.7H16c.5 0 .9.2 1.3.5 1 1 1 3.4 1 4.5v.3h1.5v-.2c0-1.5 0-4.3-1.5-5.7z"})}),ar=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z"})}),lr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m21.5 9.1-6.6-6.6-4.2 5.6c-1.2-.1-2.4.1-3.6.7-.1 0-.1.1-.2.1-.5.3-.9.6-1.2.9l3.7 3.7-5.7 5.7v1.1h1.1l5.7-5.7 3.7 3.7c.4-.4.7-.8.9-1.2.1-.1.1-.2.2-.3.6-1.1.8-2.4.6-3.6l5.6-4.1zm-7.3 3.5.1.9c.1.9 0 1.8-.4 2.6l-6-6c.8-.4 1.7-.5 2.6-.4l.9.1L15 4.9 19.1 9l-4.9 3.6z"})}),cr=function(){return cr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,f.jsx)("span",{className:"parsely-write-titles-text",children:(0,m.createInterpolateElement)( +(0,w.__)("Multiple results were returned for the post %d by the Parse.ly API.","wp-parsely"),t),U.ParselyApiReturnedTooManyResults))]:[2,n[0]]}}))}))},t.prototype.fetchReferrerDataFromWpEndpoint=function(e,t,n){return Cn(this,void 0,void 0,(function(){return An(this,(function(r){switch(r.label){case 0:return[4,this.fetch({path:(0,we.addQueryArgs)("/wp-parsely/v2/stats/post/".concat(t,"/referrers"),Nn(Nn({},dt(e)),{itm_source:this.itmSource,total_views:n}))})];case 1:return[2,r.sent()]}}))}))},t}(be),In=function(){return In=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return t.sent(),[4,n(r-1)];case 2:return t.sent(),[3,4];case 3:a(e),i(!1),t.label=4;case 4:return[2]}}))}))})),[2]}))}))};return i(!0),n(1),function(){a(void 0)}}),[t]),(0,f.jsxs)("div",{className:"wp-parsely-performance-panel",children:[(0,f.jsx)(vn,{title:(0,w.__)("Performance Stats","wp-parsely"),icon:hn,dropdownChildren:function(e){var t=e.onClose;return(0,f.jsx)(Vn,{onClose:t})},children:(0,f.jsx)("div",{className:"panel-settings",children:(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:d.PerformanceStats.Period,prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Period:","wp-parsely")}),onChange:function(e){F(e,R)&&(v({PerformanceStats:In(In({},d.PerformanceStats),{Period:e})}),k.trackEvent("editor_sidebar_performance_period_changed",{period:e}))},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})})}),o?o.Message():(0,f.jsxs)(f.Fragment,{children:[Fn(d,"overview")&&(0,f.jsx)(Tn,{data:c,isLoading:r}),Fn(d,"categories")&&(0,f.jsx)(gn,{data:c,isLoading:r}),Fn(d,"referrers")&&(0,f.jsx)(En,{data:c,isLoading:r})]}),window.wpParselyPostUrl&&(0,f.jsx)(h.Button,{className:"wp-parsely-view-post",variant:"primary",onClick:function(){k.trackEvent("editor_sidebar_view_post_pressed")},href:window.wpParselyPostUrl,rel:"noopener",target:"_blank",children:(0,w.__)("View this in Parse.ly","wp-parsely")})]})},Hn=function(e){var t=e.period;return(0,f.jsx)(h.Panel,{children:(0,f.jsx)(Ie,{children:(0,f.jsx)(Gn,{period:t})})})},zn=function(e){var t=e.filters,n=e.postData,r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Author","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Author)},options:i,value:t.author}),n.categories.length>=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Section","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Section)},options:s,value:t.section}),n.tags.length>=1&&(0,f.jsx)(h.FormTokenField,{__experimentalShowHowTo:!1,__next40pxDefaultSize:!0,label:"",placeholder:(0,w.__)("Tags","wp-parsely"),onChange:function(e){return r.onFiltersChange(e.toString(),M.Tag)},value:t.tags,suggestions:n.tags,maxLength:5})]})},Un=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z"})}),qn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M5.625 5.5h9.75c.069 0 .125.056.125.125v9.75a.125.125 0 0 1-.125.125h-9.75a.125.125 0 0 1-.125-.125v-9.75c0-.069.056-.125.125-.125ZM4 5.625C4 4.728 4.728 4 5.625 4h9.75C16.273 4 17 4.728 17 5.625v9.75c0 .898-.727 1.625-1.625 1.625h-9.75A1.625 1.625 0 0 1 4 15.375v-9.75Zm14.5 11.656v-9H20v9C20 18.8 18.77 20 17.251 20H6.25v-1.5h11.001c.69 0 1.249-.528 1.249-1.219Z"})}),Kn=function(e){var t=e.size,n=void 0===t?40:t;return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"1",height:n,viewBox:"0 0 1 ".concat(n),fill:"none",children:(0,f.jsx)(h.Rect,{width:"1",height:n,fill:"#cccccc"})})};function Zn(e){var t=e.metric,n=e.post,r=e.avgEngagedIcon,i=e.viewsIcon;return"views"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Number of Views","wp-parsely")}),i,Vt(n.views.toString())]}):"avg_engaged"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Average Time","wp-parsely")}),r,n.avgEngaged]}):(0,f.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}var Wn,Yn=function(e){var t,n,r=e.metric,i=e.post,s=e.postContent,o=(0,v.useDispatch)("core/notices").createNotice,a=s&&(t=s,n=Ae(i.rawUrl),new RegExp("]*href=[\"'](http://|https://)?.*".concat(n,".*[\"'][^>]*>"),"i").test(t));return(0,f.jsxs)("div",{className:"related-post-single","data-testid":"related-post-single",children:[(0,f.jsx)("div",{className:"related-post-title",children:(0,f.jsxs)("a",{href:i.url,target:"_blank",rel:"noreferrer",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("View on website (opens new tab)","wp-parsely")}),i.title]})}),(0,f.jsx)("div",{className:"related-post-actions",children:(0,f.jsxs)("div",{className:"related-post-info",children:[(0,f.jsxs)("div",{children:[(0,f.jsx)("div",{className:"related-post-metric",children:(0,f.jsx)(Zn,{metric:r,post:i,viewsIcon:(0,f.jsx)(ie,{icon:Rt}),avgEngagedIcon:(0,f.jsx)(h.Dashicon,{icon:"clock",size:24})})}),a&&(0,f.jsx)("div",{className:"related-post-linked",children:(0,f.jsx)(h.Tooltip,{text:(0,w.__)("This post is linked in the content","wp-parsely"),children:(0,f.jsx)(ie,{icon:Un,size:24})})})]}),(0,f.jsx)(Kn,{}),(0,f.jsxs)("div",{children:[(0,f.jsx)(h.Button,{icon:qn,iconSize:24,onClick:function(){navigator.clipboard.writeText(i.rawUrl).then((function(){o("success",(0,w.__)("URL copied to clipboard","wp-parsely"),{type:"snackbar"})}))},label:(0,w.__)("Copy URL to clipboard","wp-parsely")}),(0,f.jsx)(h.Button,{icon:(0,f.jsx)(j,{}),iconSize:18,href:i.dashUrl,target:"_blank",label:(0,w.__)("View in Parse.ly","wp-parsely")})]})]})})]})},$n=window.wp.coreData,Jn=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function __(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(__.prototype=n.prototype,new __)}}(),Xn=function(){return Xn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&f.every(Number.isInteger)?null!==(n=l("taxonomy","category",{include:f,context:"view"}))&&void 0!==n?n:void 0:null,tagRecords:o=Array.isArray(h)&&h.length>0&&h.every(Number.isInteger)?null!==(r=l("taxonomy","post_tag",{include:h,context:"view"}))&&void 0!==r?r:void 0:null,isLoading:u("getEntityRecords",["root","user",{include:[d],context:"view"}])||u("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||u("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}]),hasResolved:(c("getEntityRecords",["root","user",{include:[d],context:"view"}])||null===i)&&(c("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||null===s)&&(c("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}])||null===o)}}),[]);return(0,m.useEffect)((function(){var e=r.authorRecords,t=r.categoryRecords,i=r.tagRecords,s=r.isLoading;r.hasResolved&&!s&&n({authors:e,categories:t,tags:i,isReady:!0})}),[r]),t}(),c=l.authors,u=l.categories,p=l.tags,d=l.isReady;(0,m.useEffect)((function(){if(d){var e=function(e){return function(e){return!(!Array.isArray(e)||0===e.length)&&e.every((function(e){return"name"in e&&"id"in e&&"slug"in e&&"description"in e&&"link"in e}))}(e)?e.map((function(e){return e.name})):[]};a({authors:e(c),categories:e(u),tags:e(p)})}}),[c,u,p,d]);var g=(0,m.useState)(!0),y=g[0],b=g[1],_=(0,m.useState)(),x=_[0],S=_[1],j=(0,m.useState)([]),P=j[0],T=j[1],E=(0,m.useState)({author:"",section:"",tags:[]}),L=E[0],N=E[1],C=(0,m.useState)(void 0),A=C[0],O=C[1],D=(0,ne.useDebounce)(O,1e3);return(0,v.useSelect)((function(e){if("undefined"==typeof jest){var t=e("core/editor").getEditedPostContent;D(t())}else D("Jest test is running")}),[D]),(0,m.useEffect)((function(){var e=function(t){return rr(void 0,void 0,void 0,(function(){return ir(this,(function(n){return tr.getInstance().getRelatedPosts(r,i,L).then((function(e){T(e),b(!1)})).catch((function(n){return rr(void 0,void 0,void 0,(function(){return ir(this,(function(r){switch(r.label){case 0:return t>0&&n.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,e(t-1)];case 2:return r.sent(),[3,4];case 3:b(!1),S(n),r.label=4;case 4:return[2]}}))}))})),[2]}))}))};return b(!0),e(1),function(){b(!1),T([]),S(void 0)}}),[r,i,L,o]),0===o.authors.length&&0===o.categories.length&&0===o.tags.length&&d?(0,f.jsx)("div",{className:"wp-parsely-related-posts",children:(0,f.jsx)("div",{className:"related-posts-body",children:(0,w.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,f.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,f.jsx)("div",{className:"related-posts-description",children:(0,w.__)("Find top-performing related posts.","wp-parsely")}),(0,f.jsxs)("div",{className:"related-posts-body",children:[(0,f.jsxs)("div",{className:"related-posts-settings",children:[(0,f.jsx)(h.SelectControl,{size:"__unstable-large",onChange:function(e){var r;F(r=e,B)&&(n({RelatedPosts:nr(nr({},t.RelatedPosts),{Metric:r})}),k.trackEvent("related_posts_metric_changed",{metric:r}))},prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Metric:","wp-parsely")}),value:i,children:Object.values(B).map((function(e){return(0,f.jsx)("option",{value:e,children:G(e)},e)}))}),(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:r,prefix:(0,f.jsxs)(h.__experimentalInputControlPrefixWrapper,{children:[(0,w.__)("Period:","wp-parsely")," "]}),onChange:function(e){return function(e){F(e,R)&&(n({RelatedPosts:nr(nr({},t.RelatedPosts),{Period:e})}),k.trackEvent("related_posts_period_changed",{period:e}))}(e)},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})]}),(0,f.jsx)(zn,{label:(0,w.__)("Filter by","wp-parsely"),filters:L,onFiltersChange:function(e,t){var n;if(null==e&&(e=""),M.Tag===t){var r=[];""!==e&&(r=e.split(",").map((function(e){return e.trim()}))),N(nr(nr({},L),{tags:r}))}else N(nr(nr({},L),((n={})[t]=e,n)))},postData:o}),(0,f.jsxs)("div",{className:"related-posts-wrapper",children:[x&&x.Message(),y&&(0,f.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,w.__)("Loading…","wp-parsely")}),!y&&!x&&0===P.length&&(0,f.jsx)("div",{className:"related-posts-empty",children:(0,w.__)("No related posts found.","wp-parsely")}),!y&&P.length>0&&(0,f.jsx)("div",{className:"related-posts-list",children:P.map((function(e){return(0,f.jsx)(Yn,{metric:i,post:e,postContent:A},e.id)}))})]})]})]})},or=(0,f.jsx)(b.SVG,{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10.97 10.159a3.382 3.382 0 0 0-2.857.955l1.724 1.723-2.836 2.913L7 17h1.25l2.913-2.837 1.723 1.723a3.38 3.38 0 0 0 .606-.825c.33-.63.446-1.343.35-2.032L17 10.695 13.305 7l-2.334 3.159Z"})}),ar=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M18.3 11.7c-.6-.6-1.4-.9-2.3-.9H6.7l2.9-3.3-1.1-1-4.5 5L8.5 16l1-1-2.7-2.7H16c.5 0 .9.2 1.3.5 1 1 1 3.4 1 4.5v.3h1.5v-.2c0-1.5 0-4.3-1.5-5.7z"})}),lr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z"})}),cr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m21.5 9.1-6.6-6.6-4.2 5.6c-1.2-.1-2.4.1-3.6.7-.1 0-.1.1-.2.1-.5.3-.9.6-1.2.9l3.7 3.7-5.7 5.7v1.1h1.1l5.7-5.7 3.7 3.7c.4-.4.7-.8.9-1.2.1-.1.1-.2.2-.3.6-1.1.8-2.4.6-3.6l5.6-4.1zm-7.3 3.5.1.9c.1.9 0 1.8-.4 2.6l-6-6c.8-.4 1.7-.5 2.6-.4l.9.1L15 4.9 19.1 9l-4.9 3.6z"})}),ur=function(){return ur=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,f.jsx)("span",{className:"parsely-write-titles-text",children:(0,m.createInterpolateElement)( // translators: %1$s is the tone, %2$s is the persona. // translators: %1$s is the tone, %2$s is the persona. -(0,w.__)("We've generated a few titles based on the content of your post, written as a .","wp-parsely"),{tone:(0,f.jsx)("strong",{children:he(a)}),persona:(0,f.jsx)("strong",{children:le(u)})})}):(0,w.__)("Use Parse.ly AI to generate a title for your post.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/title-suggestions/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(ie,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),i&&(0,f.jsx)(h.Notice,{className:"wp-parsely-content-helper-error",onRemove:function(){return o(void 0)},status:"info",children:i.Message()}),void 0!==S&&(0,f.jsx)(gr,{title:S,type:Zn.PostTitle,isOriginal:!0}),00&&(0,f.jsx)(yr,{pinnedTitles:b,isOpen:!0}),y.length>0&&(0,f.jsx)(wr,{suggestions:y,isOpen:!0,isLoading:g})]}),(0,f.jsx)(mr,{isLoading:g,onPersonaChange:function(e){C("Persona",e),p(e)},onSettingChange:C,onToneChange:function(e){C("Tone",e),l(e)},persona:t.TitleSuggestions.Persona,tone:t.TitleSuggestions.Tone}),(0,f.jsx)("div",{className:"title-suggestions-generate",children:(0,f.jsxs)(h.Button,{variant:"primary",isBusy:g,disabled:g||"custom"===a||"custom"===u,onClick:function(){return kr(void 0,void 0,void 0,(function(){return Sr(this,(function(e){switch(e.label){case 0:return o(void 0),!1!==g?[3,2]:(k.trackEvent("title_suggestions_generate_pressed",{request_more:y.length>0,total_titles:y.length,total_pinned:y.filter((function(e){return e.isPinned})).length,tone:a,persona:u}),[4,(t=Zn.PostTitle,n=A,r=a,i=u,kr(void 0,void 0,void 0,(function(){var e,s,a;return Sr(this,(function(l){switch(l.label){case 0:return[4,T(!0)];case 1:l.sent(),e=xr.getInstance(),l.label=2;case 2:return l.trys.push([2,5,,6]),[4,e.generateTitles(n,3,r,i)];case 3:return s=l.sent(),[4,P(t,s)];case 4:return l.sent(),[3,6];case 5:return a=l.sent(),o(a),P(t,[]),[3,6];case 6:return[4,T(!1)];case 7:return l.sent(),[2]}}))})))]);case 1:e.sent(),e.label=2;case 2:return[2]}var t,n,r,i}))}))},children:[g&&(0,w.__)("Generating Titles…","wp-parsely"),!g&&x.length>0&&(0,w.__)("Generate More","wp-parsely"),!g&&0===x.length&&(0,w.__)("Generate Titles","wp-parsely")]})})]})})},Pr=function(){return Pr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n titles based on the content of your post, written as a .","wp-parsely"),{tone:(0,f.jsx)("strong",{children:he(a)}),persona:(0,f.jsx)("strong",{children:le(u)})})}):(0,w.__)("Use Parse.ly AI to generate a title for your post.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/title-suggestions/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(ie,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),i&&(0,f.jsx)(h.Notice,{className:"wp-parsely-content-helper-error",onRemove:function(){return s(void 0)},status:"info",children:i.Message()}),void 0!==S&&(0,f.jsx)(yr,{title:S,type:Wn.PostTitle,isOriginal:!0}),0<_.length&&(0,f.jsxs)(f.Fragment,{children:[b.length>0&&(0,f.jsx)(mr,{pinnedTitles:b,isOpen:!0}),y.length>0&&(0,f.jsx)(br,{suggestions:y,isOpen:!0,isLoading:g})]}),(0,f.jsx)(wr,{isLoading:g,onPersonaChange:function(e){C("Persona",e),p(e)},onSettingChange:C,onToneChange:function(e){C("Tone",e),l(e)},persona:t.TitleSuggestions.Persona,tone:t.TitleSuggestions.Tone}),(0,f.jsx)("div",{className:"title-suggestions-generate",children:(0,f.jsxs)(h.Button,{variant:"primary",isBusy:g,disabled:g||"custom"===a||"custom"===u,onClick:function(){return Sr(void 0,void 0,void 0,(function(){return jr(this,(function(e){switch(e.label){case 0:return s(void 0),!1!==g?[3,2]:(k.trackEvent("title_suggestions_generate_pressed",{request_more:y.length>0,total_titles:y.length,total_pinned:y.filter((function(e){return e.isPinned})).length,tone:a,persona:u}),[4,(t=Wn.PostTitle,n=A,r=a,i=u,Sr(void 0,void 0,void 0,(function(){var e,o,a;return jr(this,(function(l){switch(l.label){case 0:return[4,T(!0)];case 1:l.sent(),e=xr.getInstance(),l.label=2;case 2:return l.trys.push([2,5,,6]),[4,e.generateTitles(n,3,r,i)];case 3:return o=l.sent(),[4,P(t,o)];case 4:return l.sent(),[3,6];case 5:return a=l.sent(),s(a),P(t,[]),[3,6];case 6:return[4,T(!1)];case 7:return l.sent(),[2]}}))})))]);case 1:e.sent(),e.label=2;case 2:return[2]}var t,n,r,i}))}))},children:[g&&(0,w.__)("Generating Titles…","wp-parsely"),!g&&_.length>0&&(0,w.__)("Generate More","wp-parsely"),!g&&0===_.length&&(0,w.__)("Generate Titles","wp-parsely")]})})]})})},Tr=function(){return Tr=Object.assign||function(e){for(var t,n=1,r=arguments.length;napplied ) { + if ( ! $this->is_applied() ) { return false; } @@ -389,7 +389,7 @@ private function get_paragraph( \WP_Post $post ) { /** @var \DOMElement $p The paragraph element. */ foreach ( $paragraphs as $p ) { // If the smart link is applied, we need to find the paragraph that contains the smart link. - if ( $this->applied ) { + if ( $this->is_applied() ) { // Check each anchor tag within the paragraph. $anchors = $p->getElementsByTagName( 'a' ); /** @var \DOMElement $anchor The anchor element. */ @@ -651,7 +651,7 @@ private function find_smart_link_anchor( $node ) { */ public function apply() { /* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */ - if ( $this->applied ) { + if ( $this->is_applied() ) { return new \WP_Error( 'traffic_boost_already_applied', __( 'Smart link already applied', 'wp-parsely' ) ); } @@ -836,7 +836,7 @@ public function apply() { self::flush_cache_by_post_id( $this->source_post_id ); // Set the applied flag to true. - $this->applied = true; + $this->set_status( Smart_Link_Status::APPLIED ); // Save the smart link. $this->save(); @@ -857,7 +857,7 @@ public function apply() { public function remove( $restore_original_link = false, $delete_smart_link = true ) { /* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */ // If the smart link is not applied, we can just delete it. - if ( ! $this->applied ) { + if ( ! $this->is_applied() ) { if ( $delete_smart_link ) { return $this->delete(); } @@ -966,7 +966,7 @@ public function remove( $restore_original_link = false, $delete_smart_link = tru self::flush_cache_by_post_id( $this->source_post_id ); // Set the applied flag to false. - $this->applied = false; + $this->set_status( Smart_Link_Status::PENDING ); // Delete the smart link. if ( $delete_smart_link ) { diff --git a/src/Models/class-smart-link.php b/src/Models/class-smart-link.php index 24a75771b6..a5a2861ddd 100644 --- a/src/Models/class-smart-link.php +++ b/src/Models/class-smart-link.php @@ -113,12 +113,12 @@ class Smart_Link extends Base_Model { public $uid; /** - * Whether the link has been applied. + * The status of the smart link. * - * @since 3.16.0 - * @var bool Whether the link has been applied. + * @since 3.18.0 + * @var string|null The status of the smart link. */ - public $applied = false; + private $status = null; /** * Whether the smart link exists on the database. @@ -248,11 +248,35 @@ private function load(): bool { // Load the Smart Link properties from the post meta. $this->load_post_meta(); - $this->title = $this->get_string_meta( '_smart_link_title' ); - $this->href = $this->get_string_meta( '_smart_link_href' ); - $this->text = $this->get_string_meta( '_smart_link_text' ); - $this->offset = $this->get_int_meta( '_smart_link_offset' ); - $this->applied = $this->get_bool_meta( '_smart_link_applied', true ); + $this->title = $this->get_string_meta( '_smart_link_title' ); + $this->href = $this->get_string_meta( '_smart_link_href' ); + $this->text = $this->get_string_meta( '_smart_link_text' ); + $this->offset = $this->get_int_meta( '_smart_link_offset' ); + + // If the deprecated applied meta key exists, set the status accordingly. + $has_applied_meta = array_key_exists( '_smart_link_applied', $this->smart_link_post_meta ); + if ( $has_applied_meta ) { + $applied_meta = $this->get_bool_meta( '_smart_link_applied', true ); + $this->set_status( $applied_meta ? Smart_Link_Status::APPLIED : Smart_Link_Status::PENDING ); + + // Remove the deprecated meta key. + delete_post_meta( $this->smart_link_id, '_smart_link_applied' ); + } + + // If the status term does not exist, and the meta key is not set, we need to + // consider the smart link as accepted, for backwards compatibility with + // Parse.ly < 3.18.0. + $status_term = wp_get_post_terms( $this->smart_link_id, 'smart_link_status' ); + if ( is_wp_error( $status_term ) || count( $status_term ) === 0 ) { + if ( ! $has_applied_meta ) { + $this->set_status( Smart_Link_Status::APPLIED, true ); + } else { + $this->set_status( Smart_Link_Status::PENDING, true ); + } + } else { + // Otherwise, get the status from the term. + $this->status = $status_term[0]->slug; + } // Load the source post ID. $source_terms = wp_get_post_terms( $this->smart_link_id, 'smart_link_source' ); @@ -347,11 +371,10 @@ public function save(): bool { // Update the smart link meta. $meta = array( - '_smart_link_title' => $this->title, - '_smart_link_href' => $this->href, - '_smart_link_text' => $this->text, - '_smart_link_offset' => $this->offset, - '_smart_link_applied' => $this->applied ? 'true' : 'false', + '_smart_link_title' => $this->title, + '_smart_link_href' => $this->href, + '_smart_link_text' => $this->text, + '_smart_link_offset' => $this->offset, ); foreach ( $meta as $key => $value ) { @@ -368,6 +391,13 @@ public function save(): bool { wp_set_post_terms( $this->smart_link_id, 'external', 'smart_link_destination' ); } + // Update the status term. + if ( null !== $this->status && Smart_Link_Status::is_valid_status( $this->status ) ) { + wp_set_post_terms( $this->smart_link_id, $this->status, 'smart_link_status' ); + } else { + wp_set_post_terms( $this->smart_link_id, Smart_Link_Status::PENDING, 'smart_link_status' ); + } + // Flush all the associated cache on the source and destination posts. $this->flush_all_cache(); @@ -401,6 +431,7 @@ public function delete(): bool { if ( false !== $deleted && null !== $deleted && is_a( $deleted, 'WP_Post' ) ) { $this->smart_link_id = 0; $this->exists = false; + $this->status = null; $this->flush_all_cache(); return true; } @@ -434,6 +465,68 @@ public function exists(): bool { return false; } + /** + * Gets the status of the smart link. + * + * If the smart link does not have a valid status, it is pending. + * + * @since 3.18.0 + * + * @return string The status of the smart link. + */ + public function get_status(): string { + if ( null !== $this->status && Smart_Link_Status::is_valid_status( $this->status ) ) { + return $this->status; + } + + $status_terms = wp_get_post_terms( $this->smart_link_id, 'smart_link_status' ); + + if ( is_wp_error( $status_terms ) || count( $status_terms ) === 0 ) { + return Smart_Link_Status::PENDING; + } + + $term = $status_terms[0]->slug; + + if ( ! Smart_Link_Status::is_valid_status( $term ) ) { + return Smart_Link_Status::PENDING; + } + + $this->status = $term; + return $term; + } + + /** + * Checks if the smart link is applied. + * + * @since 3.18.0 + * + * @return bool True if the smart link is applied, false otherwise. + */ + public function is_applied(): bool { + return $this->get_status() === Smart_Link_Status::APPLIED; + } + + /** + * Sets the status of the smart link. + * + * @since 3.18.0 + * + * @param string $status The status to set. + * @param bool $save Whether to save the status to the database. + * @throws \InvalidArgumentException If the status is invalid. + */ + public function set_status( string $status, bool $save = false ): void { + if ( ! Smart_Link_Status::is_valid_status( $status ) ) { + throw new \InvalidArgumentException( 'Invalid status' ); + } + + if ( $save && null !== $this->smart_link_id ) { + wp_set_post_terms( $this->smart_link_id, $status, 'smart_link_status' ); + } + + $this->status = $status; + } + /** * Loads the post meta of the smart link object. * @@ -666,7 +759,8 @@ public function to_array(): array { 'title' => $this->title, 'text' => $this->text, 'offset' => $this->offset, - 'applied' => $this->applied, + 'status' => $this->status, + 'applied' => $this->is_applied(), 'source' => array( 'post_type' => $this->source_post_type, 'post_id' => $this->source_post_id, @@ -774,49 +868,46 @@ public static function get_outbound_smart_links( int $post_id, string $status = return $smart_links; } - $query_args = array( - 'post_type' => 'parsely_smart_link', - 'posts_per_page' => -1, - 'fields' => 'ids', // Only get the post IDs to improve performance. - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query - 'tax_query' => array( - array( - 'taxonomy' => 'smart_link_source', - 'include_children' => false, // Performance optimization. - 'field' => 'name', - 'terms' => (string) $post_id, - ), + // Build the tax query. + $tax_query = array( + 'relation' => 'AND', + array( + 'taxonomy' => 'smart_link_source', + 'include_children' => false, // Performance optimization. + 'field' => 'name', + 'terms' => (string) $post_id, ), - 'orderby' => 'date', - 'order' => 'DESC', ); + // Add the status term to the tax query. if ( Smart_Link_Status::APPLIED === $status ) { - // For retrocompatibility, we consider that not having the meta field is the same as applied. - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query - $query_args['meta_query'] = array( - 'relation' => 'OR', - array( - 'key' => '_smart_link_applied', - 'value' => 'false', - 'compare' => '!=', - ), - array( - 'key' => '_smart_link_applied', - 'compare' => 'NOT EXISTS', - ), + $tax_query[] = array( + 'taxonomy' => 'smart_link_status', + 'include_children' => false, + 'field' => 'name', + 'terms' => Smart_Link_Status::APPLIED, ); } elseif ( Smart_Link_Status::PENDING === $status ) { - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query - $query_args['meta_query'] = array( - array( - 'key' => '_smart_link_applied', - 'value' => 'false', - 'compare' => '=', - ), + $tax_query[] = array( + 'taxonomy' => 'smart_link_status', + 'include_children' => false, + 'field' => 'name', + 'terms' => Smart_Link_Status::PENDING, ); } + // Build the query arguments. + $query_args = array( + 'post_type' => 'parsely_smart_link', + 'posts_per_page' => -1, + 'fields' => 'ids', // Only get the post IDs to improve performance. + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query + 'tax_query' => $tax_query, + 'orderby' => 'date', + 'order' => 'DESC', + ); + + // Get the smart links. $smart_links = new \WP_Query( $query_args ); $links = array(); @@ -866,49 +957,46 @@ public static function get_inbound_smart_links( int $post_id, string $status = S return $smart_links; } - $query_args = array( - 'post_type' => 'parsely_smart_link', - 'posts_per_page' => -1, - 'fields' => 'ids', // Only get the post IDs to improve performance. - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query - 'tax_query' => array( - array( - 'taxonomy' => 'smart_link_destination', - 'include_children' => false, // Performance optimization. - 'field' => 'name', - 'terms' => (string) $post_id, - ), + // Build the tax query. + $tax_query = array( + 'relation' => 'AND', + array( + 'taxonomy' => 'smart_link_destination', + 'include_children' => false, // Performance optimization. + 'field' => 'name', + 'terms' => (string) $post_id, ), - 'orderby' => 'date modified', - 'order' => 'ASC', ); + // Add the status term to the tax query. if ( Smart_Link_Status::APPLIED === $status ) { - // For retrocompatibility, we consider that not having the meta field is the same as applied. - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query - $query_args['meta_query'] = array( - 'relation' => 'OR', - array( - 'key' => '_smart_link_applied', - 'value' => 'false', - 'compare' => '!=', - ), - array( - 'key' => '_smart_link_applied', - 'compare' => 'NOT EXISTS', - ), + $tax_query[] = array( + 'taxonomy' => 'smart_link_status', + 'include_children' => false, + 'field' => 'name', + 'terms' => Smart_Link_Status::APPLIED, ); } elseif ( Smart_Link_Status::PENDING === $status ) { - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query - $query_args['meta_query'] = array( - array( - 'key' => '_smart_link_applied', - 'value' => 'false', - 'compare' => '=', - ), + $tax_query[] = array( + 'taxonomy' => 'smart_link_status', + 'include_children' => false, + 'field' => 'name', + 'terms' => Smart_Link_Status::PENDING, ); } + // Build the query arguments. + $query_args = array( + 'post_type' => 'parsely_smart_link', + 'posts_per_page' => -1, + 'fields' => 'ids', // Only get the post IDs to improve performance. + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query + 'tax_query' => $tax_query, + 'orderby' => 'date modified', + 'order' => 'ASC', + ); + + // Get the smart links. $smart_links = new \WP_Query( $query_args ); $links = array(); @@ -924,7 +1012,7 @@ public static function get_inbound_smart_links( int $post_id, string $status = S // Check if this inbound smart link is still linked to a post. // If not, do not add it to the array, and instead remove it. - if ( $smart_link->applied && ! $smart_link->is_linked() ) { + if ( $smart_link->get_status() === Smart_Link_Status::APPLIED && ! $smart_link->is_linked() ) { $smart_link->delete(); continue; } diff --git a/src/content-helper/editor-sidebar/smart-linking/class-smart-linking.php b/src/content-helper/editor-sidebar/smart-linking/class-smart-linking.php index 56546772ad..0c23d534fc 100644 --- a/src/content-helper/editor-sidebar/smart-linking/class-smart-linking.php +++ b/src/content-helper/editor-sidebar/smart-linking/class-smart-linking.php @@ -75,6 +75,7 @@ public function run(): void { // Register the taxonomies for the Smart Links. $this->register_taxonomy( 'smart_link_source', __( 'Smart Link Source', 'wp-parsely' ) ); $this->register_taxonomy( 'smart_link_destination', __( 'Smart Link Destination', 'wp-parsely' ) ); + $this->register_taxonomy( 'smart_link_status', __( 'Smart Link Status', 'wp-parsely' ) ); } /** @@ -91,7 +92,7 @@ private function register_post_type(): void { 'singular_name' => __( 'Smart Link', 'wp-parsely' ), ), 'supports' => array( 'title', 'custom-fields' ), - 'taxonomies' => array( 'smart_link_source', 'smart_link_destination' ), + 'taxonomies' => array( 'smart_link_source', 'smart_link_destination', 'smart_link_status' ), 'hierarchical' => false, 'public' => false, 'show_ui' => false, @@ -136,6 +137,7 @@ private function register_taxonomy( string $taxonomy, string $singular_name ): v ), ) ); + register_taxonomy_for_object_type( $taxonomy, 'parsely_smart_link' ); } /** @@ -204,5 +206,6 @@ public function purge_smart_links( int $post_id ): void { // Remove any source and destination terms that have the post ID. wp_delete_term( $post_id, 'smart_link_source' ); wp_delete_term( $post_id, 'smart_link_destination' ); + wp_delete_term( $post_id, 'smart_link_status' ); } } diff --git a/src/content-helper/editor-sidebar/smart-linking/provider.ts b/src/content-helper/editor-sidebar/smart-linking/provider.ts index c4d3092bb1..5efb8059c2 100644 --- a/src/content-helper/editor-sidebar/smart-linking/provider.ts +++ b/src/content-helper/editor-sidebar/smart-linking/provider.ts @@ -14,6 +14,13 @@ import { Metric, Period } from '../../common/utils/constants'; import { PerformanceData } from '../performance-stats/model'; import { DEFAULT_MAX_LINKS } from './smart-linking'; +/** + * The status of a smart link. + * + * @since 3.18.0 + */ +type SmartLinkStatus = 'applied' | 'pending'; + /** * Structure of a link suggestion returned by the * 'content-suggestions/suggest-linked-reference' endpoint. @@ -29,6 +36,7 @@ export type SmartLink = { title: string; offset: number; applied: boolean; + status: SmartLinkStatus; match?: SmartLinkMatch; source?: LinkedPost; destination?: LinkedPost; diff --git a/src/content-helper/editor-sidebar/smart-linking/utils.ts b/src/content-helper/editor-sidebar/smart-linking/utils.ts index 1a2a8f00a8..fbe9be7157 100644 --- a/src/content-helper/editor-sidebar/smart-linking/utils.ts +++ b/src/content-helper/editor-sidebar/smart-linking/utils.ts @@ -454,6 +454,7 @@ export function getAllSmartLinksInPost(): SmartLink[] { href, text, title, + status: 'applied', applied: true, offset: getLinkOffset( link, doc ), match: { diff --git a/src/rest-api/content-helper/class-endpoint-smart-linking.php b/src/rest-api/content-helper/class-endpoint-smart-linking.php index c47d516900..d8e7593968 100644 --- a/src/rest-api/content-helper/class-endpoint-smart-linking.php +++ b/src/rest-api/content-helper/class-endpoint-smart-linking.php @@ -319,7 +319,7 @@ public function add_smart_link( WP_REST_Request $request ): WP_REST_Response { } // Mark as applied. - $smart_link->applied = true; + $smart_link->set_status( Smart_Link_Status::APPLIED ); // The smart link properties are set in the validate callback. $saved = $smart_link->save(); @@ -375,7 +375,7 @@ public function add_multiple_smart_links( WP_REST_Request $request ): WP_REST_Re $updated_link = $smart_link->exists() && $should_update; // Mark as applied. - $smart_link->applied = true; + $smart_link->set_status( Smart_Link_Status::APPLIED ); // The smart link properties are set in the validate callback. $saved = $smart_link->save(); @@ -468,7 +468,7 @@ public function set_smart_links( WP_REST_Request $request ): WP_REST_Response { foreach ( $smart_links as $smart_link ) { // Mark as applied. - $smart_link->applied = true; + $smart_link->set_status( Smart_Link_Status::APPLIED ); // The smart link properties are set in the validate callback. $saved = $smart_link->save(); diff --git a/src/rest-api/content-helper/class-endpoint-traffic-boost.php b/src/rest-api/content-helper/class-endpoint-traffic-boost.php index f6bad85015..5bacc24055 100644 --- a/src/rest-api/content-helper/class-endpoint-traffic-boost.php +++ b/src/rest-api/content-helper/class-endpoint-traffic-boost.php @@ -383,7 +383,7 @@ public function generate_link_suggestions( WP_REST_Request $request ) { $suggestions = array_map( function ( Inbound_Smart_Link $link ) use ( $save ) { - $link->applied = false; + $link->set_status( Smart_Link_Status::PENDING ); // If the save flag is set, save the smart link. if ( $save ) { @@ -797,7 +797,7 @@ public function accept_suggestion( WP_REST_Request $request ) { $inbound_link->offset = $offset; } - if ( $inbound_link->applied ) { + if ( $inbound_link->is_applied() ) { return new WP_Error( 'parsely_smart_link_already_applied', __( 'Smart link already applied.', 'wp-parsely' ) From 390313622ad8596d9a3bfe626b59ab4f56289e8e Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Thu, 20 Mar 2025 10:06:47 +0000 Subject: [PATCH 02/10] Add handling of data schema updates --- src/Models/class-smart-link.php | 99 +++++++++------------------------ wp-parsely.php | 85 ++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 73 deletions(-) diff --git a/src/Models/class-smart-link.php b/src/Models/class-smart-link.php index a5a2861ddd..6623fade53 100644 --- a/src/Models/class-smart-link.php +++ b/src/Models/class-smart-link.php @@ -118,7 +118,7 @@ class Smart_Link extends Base_Model { * @since 3.18.0 * @var string|null The status of the smart link. */ - private $status = null; + protected $status = null; /** * Whether the smart link exists on the database. @@ -253,30 +253,7 @@ private function load(): bool { $this->text = $this->get_string_meta( '_smart_link_text' ); $this->offset = $this->get_int_meta( '_smart_link_offset' ); - // If the deprecated applied meta key exists, set the status accordingly. - $has_applied_meta = array_key_exists( '_smart_link_applied', $this->smart_link_post_meta ); - if ( $has_applied_meta ) { - $applied_meta = $this->get_bool_meta( '_smart_link_applied', true ); - $this->set_status( $applied_meta ? Smart_Link_Status::APPLIED : Smart_Link_Status::PENDING ); - - // Remove the deprecated meta key. - delete_post_meta( $this->smart_link_id, '_smart_link_applied' ); - } - - // If the status term does not exist, and the meta key is not set, we need to - // consider the smart link as accepted, for backwards compatibility with - // Parse.ly < 3.18.0. - $status_term = wp_get_post_terms( $this->smart_link_id, 'smart_link_status' ); - if ( is_wp_error( $status_term ) || count( $status_term ) === 0 ) { - if ( ! $has_applied_meta ) { - $this->set_status( Smart_Link_Status::APPLIED, true ); - } else { - $this->set_status( Smart_Link_Status::PENDING, true ); - } - } else { - // Otherwise, get the status from the term. - $this->status = $status_term[0]->slug; - } + $this->status = $this->get_status(); // Load the source post ID. $source_terms = wp_get_post_terms( $this->smart_link_id, 'smart_link_source' ); @@ -521,7 +498,7 @@ public function set_status( string $status, bool $save = false ): void { } if ( $save && null !== $this->smart_link_id ) { - wp_set_post_terms( $this->smart_link_id, $status, 'smart_link_status' ); + $result = wp_set_post_terms( $this->smart_link_id, $status, 'smart_link_status' ); } $this->status = $status; @@ -578,32 +555,6 @@ private function get_int_meta( string $meta_key, int $default_value = 0 ): int { return (int) $value; } - /** - * Gets a boolean meta value from the smart link post. - * - * @since 3.18.0 - * - * @param string $meta_key The meta key to get the value for. - * @param bool $default_value The default value to return if the meta value is not a boolean. - * @return bool The meta value. - */ - private function get_bool_meta( string $meta_key, bool $default_value = false ): bool { - if ( ! isset( $this->smart_link_post_meta[ $meta_key ] ) ) { - return $default_value; - } - - $meta_value = $this->smart_link_post_meta[ $meta_key ][0]; - if ( 'true' === $meta_value || '1' === $meta_value ) { - return true; - } - - if ( 'false' === $meta_value || '0' === $meta_value ) { - return false; - } - - return $default_value; - } - /** * Sets the source post from a post object. * @@ -836,7 +787,7 @@ public static function get_smart_link( string $uid, int $post_id ): Smart_Link { * @param int $smart_link_id The ID of the smart link. * @return Smart_Link|false The smart link object, or false if it does not exist. */ - protected static function get_smart_link_by_id( int $smart_link_id ) { + public static function get_smart_link_by_id( int $smart_link_id ) { $smart_link = new Smart_Link( '', '', '', 0 ); $smart_link->smart_link_id = $smart_link_id; if ( $smart_link->load() ) { @@ -859,6 +810,11 @@ protected static function get_smart_link_by_id( int $smart_link_id ) { * @return array The smart links in the post. */ public static function get_outbound_smart_links( int $post_id, string $status = Smart_Link_Status::ALL ): array { + if ( ! Smart_Link_Status::is_valid_status( $status ) ) { + $status = 'all'; + _doing_it_wrong( __METHOD__, 'Invalid status, defaulting to all.', '3.18.0' ); + } + $cache_key = 'outbound-' . $post_id . '-' . $status; $smart_links = wp_cache_get( $cache_key, self::get_cache_group_for_post( $post_id ) ); @@ -880,19 +836,12 @@ public static function get_outbound_smart_links( int $post_id, string $status = ); // Add the status term to the tax query. - if ( Smart_Link_Status::APPLIED === $status ) { + if ( Smart_Link_Status::ALL !== $status ) { $tax_query[] = array( 'taxonomy' => 'smart_link_status', 'include_children' => false, 'field' => 'name', - 'terms' => Smart_Link_Status::APPLIED, - ); - } elseif ( Smart_Link_Status::PENDING === $status ) { - $tax_query[] = array( - 'taxonomy' => 'smart_link_status', - 'include_children' => false, - 'field' => 'name', - 'terms' => Smart_Link_Status::PENDING, + 'terms' => $status, ); } @@ -948,6 +897,8 @@ public static function get_inbound_smart_links( int $post_id, string $status = S _doing_it_wrong( __METHOD__, 'Invalid status, defaulting to all.', '3.18.0' ); } + //$status = 'all'; + $cache_key = 'inbound-' . $post_id . '-' . $status; $smart_links = wp_cache_get( $cache_key, self::get_cache_group_for_post( $post_id ) ); @@ -969,19 +920,12 @@ public static function get_inbound_smart_links( int $post_id, string $status = S ); // Add the status term to the tax query. - if ( Smart_Link_Status::APPLIED === $status ) { - $tax_query[] = array( - 'taxonomy' => 'smart_link_status', - 'include_children' => false, - 'field' => 'name', - 'terms' => Smart_Link_Status::APPLIED, - ); - } elseif ( Smart_Link_Status::PENDING === $status ) { + if ( Smart_Link_Status::ALL !== $status ) { $tax_query[] = array( 'taxonomy' => 'smart_link_status', 'include_children' => false, 'field' => 'name', - 'terms' => Smart_Link_Status::PENDING, + 'terms' => $status, ); } @@ -1009,11 +953,20 @@ public static function get_inbound_smart_links( int $post_id, string $status = S } $smart_link = Inbound_Smart_Link::from_smart_link( $smart_link ); + $is_linked = $smart_link->is_linked(); + $status = $smart_link->get_status(); + + // If the smart link is linked and the status is pending, set the status to applied. + // This is to ensure backwards compatibility with Parse.ly < 3.18.0. + if ( $is_linked && $status === Smart_Link_Status::PENDING ) { + $smart_link->set_status( Smart_Link_Status::APPLIED, true ); + $status = Smart_Link_Status::APPLIED; + } // Check if this inbound smart link is still linked to a post. // If not, do not add it to the array, and instead remove it. - if ( $smart_link->get_status() === Smart_Link_Status::APPLIED && ! $smart_link->is_linked() ) { - $smart_link->delete(); + if ( $status === Smart_Link_Status::APPLIED && ! $is_linked ) { + //$smart_link->delete(); TODO: Uncomment this when we are ready to delete the deprecated _smart_link_applied meta. continue; } diff --git a/wp-parsely.php b/wp-parsely.php index 25c93dc49f..68d319dec2 100644 --- a/wp-parsely.php +++ b/wp-parsely.php @@ -51,6 +51,7 @@ const PARSELY_VERSION = '3.17.0'; const PARSELY_FILE = __FILE__; +const PARSELY_DATA_SCHEMA_VERSION = '1'; if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { require_once __DIR__ . '/vendor/autoload.php'; @@ -227,3 +228,87 @@ function parsely_integrations( $parsely = null ): Integrations { return $parsely_integrations; } + + +add_action( 'admin_init', __NAMESPACE__ . '\\check_data_scheme_updates', 999 ); +/** + * Checks and performs any data scheme updates. + * + * @since 3.18.0 Handles the update from schema version 0 to 1. + */ +function check_data_scheme_updates(): void { + $current_data_schema_version = get_option( 'parsely_data_schema_version' ) ?? 0; + + if ( PARSELY_DATA_SCHEMA_VERSION <= $current_data_schema_version ) { + return; + } + + /** + * Updates the smart links to have the Smart Link Status terms, + * and deletes the _smart_link_applied meta. + * + * Schema version 1. + * + * @since 3.18.0 + */ + if ( 0 === $current_data_schema_version ) { + global $wpdb; + + // Get all the smart links that do not have any Smart Link Status terms. + $smart_links_without_status = get_posts( array( + 'post_type' => 'parsely_smart_link', + 'posts_per_page' => -1, + 'fields' => 'ids', + 'suppress_filters' => false, + 'tax_query' => array( + array( + 'taxonomy' => 'smart_link_status', + 'field' => 'name', + 'terms' => array( + \Parsely\Models\Smart_Link_Status::get_all_statuses(), + ), + 'operator' => 'NOT IN', + ), + ), + ) ); + + if ( count( $smart_links_without_status ) === 0 ) { + update_option( 'parsely_data_schema_version', PARSELY_DATA_SCHEMA_VERSION ); + return; + } + + // Loop through the smart links and update them to have the Smart Link Status terms. + foreach ( $smart_links_without_status as $post_id ) { + $smart_link = \Parsely\Models\Smart_Link::get_smart_link_by_id( intval( $post_id ) ); + if( false === $smart_link ) { + continue; + } + + $meta_exists = metadata_exists( 'post', $post_id, '_smart_link_applied' ); + + // If there is no meta, it means that the smart link is considered applied, + // for backwards compatibility with Parse.ly < 3.18.0. + if ( ! $meta_exists ) { + $smart_link->set_status( \Parsely\Models\Smart_Link_Status::APPLIED, true ); + continue; + } + + // Get the value of the _smart_link_applied meta. + $meta_value = get_post_meta( $post_id, '_smart_link_applied', true ); + + // If the meta value is true, then the smart link is considered applied. + if ( $meta_value === 'true' || $meta_value === true ) { + $smart_link->set_status( \Parsely\Models\Smart_Link_Status::APPLIED, true ); + } else { + // If the meta value is not true, then the smart link is considered pending. + $smart_link->set_status( \Parsely\Models\Smart_Link_Status::PENDING, true ); + } + + // Delete the deprecated _smart_link_applied meta. + delete_post_meta( $post_id, '_smart_link_applied' ); + } + + update_option( 'parsely_data_schema_version', PARSELY_DATA_SCHEMA_VERSION ); + return; + } +} From 1728304efff8d7f1ff656e02b8a899f4a6189594 Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Thu, 20 Mar 2025 10:52:43 +0000 Subject: [PATCH 03/10] Rebuild assets --- build/content-helper/editor-sidebar.asset.php | 2 +- build/content-helper/editor-sidebar.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/content-helper/editor-sidebar.asset.php b/build/content-helper/editor-sidebar.asset.php index e7e99610cc..452e75d09e 100644 --- a/build/content-helper/editor-sidebar.asset.php +++ b/build/content-helper/editor-sidebar.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '1727f7296110931bb26b'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '69cf69eaf87e6e1ab47d'); diff --git a/build/content-helper/editor-sidebar.js b/build/content-helper/editor-sidebar.js index fd71d4e74a..7ec31a240e 100644 --- a/build/content-helper/editor-sidebar.js +++ b/build/content-helper/editor-sidebar.js @@ -1,7 +1,7 @@ !function(){"use strict";var e={20:function(e,t,n){var r=n(609),i=Symbol.for("react.element"),o=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var r,o={},c=null,u=null;for(r in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)s.call(t,r)&&!l.hasOwnProperty(r)&&(o[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===o[r]&&(o[r]=t[r]);return{$$typeof:i,type:e,key:c,ref:u,props:o,_owner:a.current}}t.Fragment=o,t.jsx=c,t.jsxs=c},848:function(e,t,n){e.exports=n(20)},609:function(e){e.exports=window.React}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(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.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){n.d({},{w:function(){return Lr},_:function(){return Nr}});var e,t,r,i,o,s,a,l,c,u,p,d,f=n(848),h=window.wp.components,v=window.wp.data,g=window.wp.domReady,y=n.n(g),m=window.wp.element,w=window.wp.i18n,b=window.wp.primitives,x=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",d:"M11.25 5h1.5v15h-1.5V5zM6 10h1.5v10H6V10zm12 4h-1.5v6H18v-6z",clipRule:"evenodd"})}),_=window.wp.plugins;void 0!==window.wp&&(p=null!==(t=null===(e=window.wp.editor)||void 0===e?void 0:e.PluginDocumentSettingPanel)&&void 0!==t?t:null!==(i=null===(r=window.wp.editPost)||void 0===r?void 0:r.PluginDocumentSettingPanel)&&void 0!==i?i:null===(o=window.wp.editSite)||void 0===o?void 0:o.PluginDocumentSettingPanel,d=null!==(a=null===(s=window.wp.editor)||void 0===s?void 0:s.PluginSidebar)&&void 0!==a?a:null!==(c=null===(l=window.wp.editPost)||void 0===l?void 0:l.PluginSidebar)&&void 0!==c?c:null===(u=window.wp.editSite)||void 0===u?void 0:u.PluginSidebar);var k=function(){function e(){this._tkq=[],this.isLoaded=!1,this.isEnabled=!1,"undefined"!=typeof wpParselyTracksTelemetry&&(this.isEnabled=!0,this.loadTrackingLibrary())}return e.getInstance=function(){return window.wpParselyTelemetryInstance||Object.defineProperty(window,"wpParselyTelemetryInstance",{value:new e,writable:!1,configurable:!1,enumerable:!1}),window.wpParselyTelemetryInstance},e.prototype.loadTrackingLibrary=function(){var e=this,t=document.createElement("script");t.async=!0,t.src="//stats.wp.com/w.js",t.onload=function(){e.isLoaded=!0,e._tkq=window._tkq||[]},document.head.appendChild(t)},e.trackEvent=function(t){return n=this,r=arguments,o=function(t,n){var r;return void 0===n&&(n={}),function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]=1e4&&(clearInterval(o),n("Telemetry library not loaded"))}),100);else n("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,n){var r;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(n=this.prepareProperties(n),null===(r=this._tkq)||void 0===r||r.push(["recordEvent",t,n])):console.error("Error tracking event: Invalid event name")):console.error("Error tracking event: Telemetry not loaded")},e.prototype.isTelemetryEnabled=function(){return this.isEnabled},e.prototype.isProprietyValid=function(t){return e.PROPERTY_REGEX.test(t)},e.prototype.isEventNameValid=function(t){return e.EVENT_NAME_REGEX.test(t)},e.prototype.prepareProperties=function(e){return(e=this.sanitizeProperties(e)).parsely_version=wpParselyTracksTelemetry.version,wpParselyTracksTelemetry.user&&(e._ut=wpParselyTracksTelemetry.user.type,e._ui=wpParselyTracksTelemetry.user.id),wpParselyTracksTelemetry.vipgo_env&&(e.vipgo_env=wpParselyTracksTelemetry.vipgo_env),this.sanitizeProperties(e)},e.prototype.sanitizeProperties=function(e){var t=this,n={};return Object.keys(e).forEach((function(r){t.isProprietyValid(r)&&(n[r]=e[r])})),n},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),S=(k.trackEvent,function(){return(0,f.jsx)(h.SVG,{"aria-hidden":"true",version:"1.1",viewBox:"0 0 15 15",width:"15",height:"15",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(h.Path,{d:"M0 14.0025V11.0025L7.5 3.5025L10.5 6.5025L3 14.0025H0ZM12 5.0025L13.56 3.4425C14.15 2.8525 14.15 1.9025 13.56 1.3225L12.68 0.4425C12.09 -0.1475 11.14 -0.1475 10.56 0.4425L9 2.0025L12 5.0025Z"})})}),j=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{className:i,height:n,viewBox:"0 0 60 65",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M23.72,51.53c0-.18,0-.34-.06-.52a13.11,13.11,0,0,0-2.1-5.53A14.74,14.74,0,0,0,19.12,43c-.27-.21-.5-.11-.51.22l-.24,3.42c0,.33-.38.35-.49,0l-1.5-4.8a1.4,1.4,0,0,0-.77-.78,23.91,23.91,0,0,0-3.1-.84c-1.38-.24-3.39-.39-3.39-.39-.34,0-.45.21-.25.49l2.06,3.76c.2.27,0,.54-.29.33l-4.51-3.6a3.68,3.68,0,0,0-2.86-.48c-1,.16-2.44.46-2.44.46a.68.68,0,0,0-.39.25.73.73,0,0,0-.14.45S.41,43,.54,44a3.63,3.63,0,0,0,1.25,2.62L6.48,50c.28.2.09.49-.23.37l-4.18-.94c-.32-.12-.5,0-.4.37,0,0,.69,1.89,1.31,3.16a24,24,0,0,0,1.66,2.74,1.34,1.34,0,0,0,1,.52l5,.13c.33,0,.41.38.1.48L7.51,58c-.31.1-.34.35-.07.55a14.29,14.29,0,0,0,3.05,1.66,13.09,13.09,0,0,0,5.9.5,25.13,25.13,0,0,0,4.34-1,9.55,9.55,0,0,1-.08-1.2,9.32,9.32,0,0,1,3.07-6.91"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M59.7,41.53a.73.73,0,0,0-.14-.45.68.68,0,0,0-.39-.25s-1.43-.3-2.44-.46a3.64,3.64,0,0,0-2.86.48l-4.51,3.6c-.26.21-.49-.06-.29-.33l2.06-3.76c.2-.28.09-.49-.25-.49,0,0-2,.15-3.39.39a23.91,23.91,0,0,0-3.1.84,1.4,1.4,0,0,0-.77.78l-1.5,4.8c-.11.32-.48.3-.49,0l-.24-3.42c0-.33-.24-.43-.51-.22a14.74,14.74,0,0,0-2.44,2.47A13.11,13.11,0,0,0,36.34,51c0,.18,0,.34-.06.52a9.26,9.26,0,0,1,3,8.1,24.1,24.1,0,0,0,4.34,1,13.09,13.09,0,0,0,5.9-.5,14.29,14.29,0,0,0,3.05-1.66c.27-.2.24-.45-.07-.55l-3.22-1.17c-.31-.1-.23-.47.1-.48l5-.13a1.38,1.38,0,0,0,1-.52A24.6,24.6,0,0,0,57,52.92c.61-1.27,1.31-3.16,1.31-3.16.1-.33-.08-.49-.4-.37l-4.18.94c-.32.12-.51-.17-.23-.37l4.69-3.34A3.63,3.63,0,0,0,59.46,44c.13-1,.24-2.47.24-2.47"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M46.5,25.61c0-.53-.35-.72-.8-.43l-4.86,2.66c-.45.28-.56-.27-.23-.69l4.66-6.23a2,2,0,0,0,.28-1.68,36.51,36.51,0,0,0-2.19-4.89,34,34,0,0,0-2.81-3.94c-.33-.41-.74-.35-.91.16l-2.28,5.68c-.16.5-.6.48-.59-.05l.28-8.93a2.54,2.54,0,0,0-.66-1.64S35,4.27,33.88,3.27,30.78.69,30.78.69a1.29,1.29,0,0,0-1.54,0s-1.88,1.49-3.12,2.59-2.48,2.35-2.48,2.35A2.5,2.5,0,0,0,23,7.27l.27,8.93c0,.53-.41.55-.58.05l-2.29-5.69c-.17-.5-.57-.56-.91-.14a35.77,35.77,0,0,0-3,4.2,35.55,35.55,0,0,0-2,4.62,2,2,0,0,0,.27,1.67l4.67,6.24c.33.42.23,1-.22.69l-4.87-2.66c-.45-.29-.82-.1-.82.43a18.6,18.6,0,0,0,.83,5.07,20.16,20.16,0,0,0,5.37,7.77c3.19,3,5.93,7.8,7.45,11.08A9.6,9.6,0,0,1,30,49.09a9.31,9.31,0,0,1,2.86.45c1.52-3.28,4.26-8.11,7.44-11.09a20.46,20.46,0,0,0,5.09-7,19,19,0,0,0,1.11-5.82"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M36.12,58.44A6.12,6.12,0,1,1,30,52.32a6.11,6.11,0,0,1,6.12,6.12"})]})},P=function(){return P=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0?"".concat(i," ").concat(n):n)||this).hint=null,o.name=o.constructor.name,o.code=r;var s=[U.AccessToFeatureDisabled,U.ParselyApiForbidden,U.ParselyApiResponseContainsError,U.ParselyApiReturnedNoData,U.ParselyApiReturnedTooManyResults,U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsApiSecretNotSet,U.PluginSettingsSiteIdNotSet,U.PostIsNotPublished,U.UnknownError,U.ParselySuggestionsApiAuthUnavailable,U.ParselySuggestionsApiNoAuthentication,U.ParselySuggestionsApiNoAuthorization,U.ParselySuggestionsApiNoData,U.ParselySuggestionsApiSchemaError];return o.retryFetch=!s.includes(o.code),Object.setPrototypeOf(o,t.prototype),o.code===U.AccessToFeatureDisabled?o.message=(0,w.__)("Access to this feature is disabled by the site's administration.","wp-parsely"):o.code===U.ParselySuggestionsApiNoAuthorization?o.message=(0,w.__)('This AI-powered feature is opt-in. To gain access, please submit a request here.',"wp-parsely"):o.code===U.ParselySuggestionsApiOpenAiError||o.code===U.ParselySuggestionsApiOpenAiUnavailable?o.message=(0,w.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):o.code===U.HttpRequestFailed&&o.message.includes("cURL error 28")?o.message=(0,w.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):o.code===U.ParselySuggestionsApiSchemaError?o.message=(0,w.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):o.code===U.ParselySuggestionsApiNoData?o.message=(0,w.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):o.code===U.ParselySuggestionsApiOpenAiSchema?o.message=(0,w.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):o.code===U.ParselySuggestionsApiAuthUnavailable&&(o.message=(0,w.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),o}return ee(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsSiteIdNotSet,U.PluginSettingsApiSecretNotSet].includes(this.code)?Q(e):(this.code===U.FetchError&&(this.hint=this.Hint((0,w.__)("This error can sometimes be caused by ad-blockers or browser tracking protections. Please add this site to any applicable allow lists and try again.","wp-parsely"))),this.code!==U.ParselyApiForbidden&&this.code!==U.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,w.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===U.HttpRequestFailed&&(this.hint=this.Hint((0,w.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,f.jsx)(X,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

").concat(this.hint?this.hint:"")}))},t.prototype.Hint=function(e){return'

'.concat((0,w.__)("Hint:","wp-parsely")," ").concat(e,"

")},t.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,v.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),ne=window.wp.compose,re=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})}),ie=(0,m.forwardRef)((function({icon:e,size:t=24,...n},r){return(0,m.cloneElement)(e,{width:t,height:t,...n,ref:r})})),oe=function(){return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:(0,f.jsx)(h.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M13.5034 7.91642L9 12.0104L4.49662 7.91642L5.25337 7.08398L8.99999 10.49L12.7466 7.08398L13.5034 7.91642Z",fill:"#1E1E1E"})})},se={journalist:{label:(0,w.__)("Journalist","wp-parsely")},editorialWriter:{label:(0,w.__)("Editorial Writer","wp-parsely")},investigativeReporter:{label:(0,w.__)("Investigative Reporter","wp-parsely")},techAnalyst:{label:(0,w.__)("Tech Analyst","wp-parsely")},businessAnalyst:{label:(0,w.__)("Business Analyst","wp-parsely")},culturalCommentator:{label:(0,w.__)("Cultural Commentator","wp-parsely")},scienceCorrespondent:{label:(0,w.__)("Science Correspondent","wp-parsely")},politicalAnalyst:{label:(0,w.__)("Political Analyst","wp-parsely")},healthWellnessAdvocate:{label:(0,w.__)("Health and Wellness Advocate","wp-parsely")},environmentalJournalist:{label:(0,w.__)("Environmental Journalist","wp-parsely")},custom:{label:(0,w.__)("Custom Persona","wp-parsely"),icon:re}},ae=Object.keys(se),le=function(e){return"custom"===e||""===e?se.custom.label:ce(e)?e:se[e].label},ce=function(e){return!ae.includes(e)||"custom"===e},ue=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],o=r[1],s=(0,ne.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-persona-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom persona…","wp-parsely"),onChange:function(e){if(""===e)return n(""),void o("");e.length>32&&(e=e.slice(0,32)),s(e),o(e)}})})},pe=function(e){var t=e.persona,n=e.value,r=void 0===n?(0,w.__)("Select a persona…","wp-parsely"):n,i=e.label,o=void 0===i?(0,w.__)("Persona","wp-parsely"):i,s=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u;return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[o&&(0,f.jsx)("div",{className:"wp-parsely-dropdown-label",children:o}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Persona","wp-parsely"),className:"parsely-persona-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-persona-selector-label",children:ce(t)?se.custom.label:r}),(0,f.jsx)(oe,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Persona","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:ae.map((function(e){if(!p&&"custom"===e)return null;var r=se[e],i=e===t||ce(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),s(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-persona-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ie,{icon:r.icon}),r.label]},e)}))})})}}),p&&ce(t)&&(0,f.jsx)(ue,{onChange:function(e){s(""!==e?e:"custom")},value:"custom"===t?"":t})]})},de={neutral:{label:(0,w.__)("Neutral","wp-parsely")},formal:{label:(0,w.__)("Formal","wp-parsely")},humorous:{label:(0,w.__)("Humorous","wp-parsely")},confident:{label:(0,w.__)("Confident","wp-parsely")},provocative:{label:(0,w.__)("Provocative","wp-parsely")},serious:{label:(0,w.__)("Serious","wp-parsely")},inspirational:{label:(0,w.__)("Inspirational","wp-parsely")},skeptical:{label:(0,w.__)("Skeptical","wp-parsely")},conversational:{label:(0,w.__)("Conversational","wp-parsely")},analytical:{label:(0,w.__)("Analytical","wp-parsely")},custom:{label:(0,w.__)("Custom Tone","wp-parsely"),icon:re}},fe=Object.keys(de),he=function(e){return"custom"===e||""===e?de.custom.label:ve(e)?e:de[e].label},ve=function(e){return!fe.includes(e)||"custom"===e},ge=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],o=r[1],s=(0,ne.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-tone-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom tone","wp-parsely"),onChange:function(e){if(""===e)return n(""),void o("");e.length>32&&(e=e.slice(0,32)),s(e),o(e)}})})},ye=function(e){var t=e.tone,n=e.value,r=void 0===n?(0,w.__)("Select a tone","wp-parsely"):n,i=e.label,o=void 0===i?(0,w.__)("Tone","wp-parsely"):i,s=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u;return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[(0,f.jsx)("div",{className:"wp-parsely-dropdown-label",children:o}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Tone","wp-parsely"),className:"parsely-tone-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-tone-selector-label",children:ve(t)?de.custom.label:r}),(0,f.jsx)(oe,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Select a tone","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:fe.map((function(e){if(!p&&"custom"===e)return null;var r=de[e],i=e===t||ve(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),s(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-tone-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ie,{icon:r.icon}),r.label]},e)}))})})}}),p&&ve(t)&&(0,f.jsx)(ge,{onChange:function(e){s(""!==e?e:"custom")},value:"custom"===t?"":t})]})},me=function(e){var t=e.isLoading,n=e.onPersonaChange,r=e.onToneChange,i=e.persona,o=e.tone;return(0,f.jsxs)("div",{className:"excerpt-suggestions-settings",children:[(0,f.jsx)(ye,{tone:o,value:he(o),onChange:function(e){r(e)},onDropdownChange:function(e){k.trackEvent("excerpt_generator_ai_tone_changed",{selectedTone:e})},disabled:t,allowCustom:!0}),(0,f.jsx)(pe,{persona:i,value:le(i),onChange:function(e){n(e)},onDropdownChange:function(e){k.trackEvent("excerpt_generator_ai_persona_changed",{persona:e})},disabled:t,allowCustom:!0})]})},we=window.wp.url,be=function(){function e(){this.abortControllers=new Map}return e.prototype.cancelRequest=function(e){if(e)(t=this.abortControllers.get(e))&&(t.abort(),this.abortControllers.delete(e));else{var t,n=Array.from(this.abortControllers.keys()).pop();n&&(t=this.abortControllers.get(n))&&(t.abort(),this.abortControllers.delete(n))}},e.prototype.cancelAll=function(){this.abortControllers.forEach((function(e){return e.abort()})),this.abortControllers.clear()},e.prototype.getOrCreateController=function(e){if(e&&this.abortControllers.has(e))return{abortController:this.abortControllers.get(e),abortId:e};var t=null!=e?e:"auto-"+Date.now(),n=new AbortController;return this.abortControllers.set(t,n),{abortController:n,abortId:t}},e.prototype.fetch=function(e,t){return n=this,r=void 0,o=function(){var n,r,i,o,s,a;return function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,w.sprintf)( // Translators: %1$s the number of words in the excerpt. // Translators: %1$s the number of words in the excerpt. -(0,w._n)("%1$s word","%1$s words",e,"wp-parsely"),e):"")}),[u.currentExcerpt,D]),(0,m.useEffect)((function(){var e=document.querySelector(".editor-post-excerpt textarea");e&&(e.scrollTop=0)}),[u.newExcerptGeneratedCount]);var G=(0,f.jsxs)("div",{className:"wp-parsely-excerpt-generator-header",children:[(0,f.jsx)(j,{size:16}),(0,f.jsx)("div",{className:"wp-parsely-excerpt-generator-header-label",children:(0,w.__)("Generate With Parse.ly","wp-parsely")})]}),H=n?(0,w.__)("Write an excerpt (optional)","wp-parsely"):(0,w.__)("Excerpt","wp-parsely");return(0,f.jsxs)("div",{className:"editor-post-excerpt",children:[!n&&(0,f.jsxs)("div",{className:"excerpt-suggestions-text",children:[(0,w.__)("Use Parse.ly AI to generate a concise, engaging excerpt for your post.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),(0,f.jsxs)("div",{style:{position:"relative"},children:[g&&(0,f.jsx)("div",{className:"editor-post-excerpt__loading_animation",children:(0,f.jsx)(Te,{})}),(0,f.jsx)(h.TextareaControl,{__nextHasNoMarginBottom:!0,label:H,className:"editor-post-excerpt__textarea",onChange:function(e){u.isUnderReview||R({excerpt:e}),p(ke(ke({},u),{currentExcerpt:e})),_(!0)},onKeyUp:function(){var e;if(x)_(!1);else{var t=document.querySelector(".editor-post-excerpt textarea"),n=null!==(e=null==t?void 0:t.textContent)&&void 0!==e?e:"";p(ke(ke({},u),{currentExcerpt:n}))}},value:g?"":u.isUnderReview?u.currentExcerpt:D,help:A||null})]}),n&&(0,f.jsxs)(h.Button,{href:(0,w.__)("https://wordpress.org/documentation/article/page-post-settings-sidebar/#excerpt"),target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about manual excerpts","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]}),(0,f.jsxs)("div",{className:"wp-parsely-excerpt-generator"+(n?" is-doc-set-panel":""),children:[a&&(0,f.jsx)(h.Notice,{className:"wp-parsely-excerpt-generator-error",onRemove:function(){return l(void 0)},status:"info",children:a.Message()}),u.isUnderReview?(0,f.jsxs)(f.Fragment,{children:[n&&G,(0,f.jsxs)("div",{className:"wp-parsely-excerpt-suggestions-review-controls",children:[(0,f.jsx)(h.Button,{variant:"secondary",onClick:function(){return Se(void 0,void 0,void 0,(function(){return je(this,(function(e){switch(e.label){case 0:return[4,R({excerpt:u.currentExcerpt})];case 1:return e.sent(),p(ke(ke({},u),{isUnderReview:!1})),k.trackEvent("excerpt_generator_accepted"),[2]}}))}))},children:(0,w.__)("Accept","wp-parsely")}),(0,f.jsx)(h.Button,{isDestructive:!0,variant:"secondary",onClick:function(){return Se(void 0,void 0,void 0,(function(){return je(this,(function(e){return R({excerpt:u.oldExcerpt}),p(ke(ke({},u),{currentExcerpt:u.oldExcerpt,isUnderReview:!1})),k.trackEvent("excerpt_generator_discarded"),[2]}))}))},children:(0,w.__)("Discard","wp-parsely")})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(me,{isLoading:g,onPersonaChange:function(e){B("Persona",e),T(e)},onSettingChange:B,onToneChange:function(e){B("Tone",e),N(e)},persona:i.ExcerptSuggestions.Persona,tone:i.ExcerptSuggestions.Tone}),n&&G,(0,f.jsx)("div",{className:"excerpt-suggestions-generate",children:(0,f.jsxs)(h.Button,{onClick:function(){return Se(void 0,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:y(!0),l(void 0),n.label=1;case 1:return n.trys.push([1,3,4,5]),k.trackEvent("excerpt_generator_pressed"),[4,_e.getInstance().generateExcerpt(V,F,P,L)];case 2:return e=n.sent(),p({currentExcerpt:e,isUnderReview:!0,newExcerptGeneratedCount:u.newExcerptGeneratedCount+1,oldExcerpt:D}),[3,5];case 3:return(t=n.sent())instanceof te?l(t):(l(new te((0,w.__)("An unknown error occurred.","wp-parsely"),U.UnknownError)),console.error(t)),[3,5];case 4:return y(!1),[7];case 5:return[2]}}))}))},variant:"primary",isBusy:g,disabled:g||!F,children:[g&&(0,w.__)("Generating Excerpt…","wp-parsely"),!g&&u.newExcerptGeneratedCount>0&&(0,w.__)("Regenerate Excerpt","wp-parsely"),!g&&0===u.newExcerptGeneratedCount&&(0,w.__)("Generate Excerpt","wp-parsely")]})})]}),n&&(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]})]})},Te=function(){return(0,f.jsx)(h.Animate,{type:"loading",children:function(e){var t=e.className;return(0,f.jsx)("span",{className:t,children:(0,w.__)("Generating…","wp-parsely")})}})},Ee=function(){return(0,f.jsx)(q.PostTypeSupportCheck,{supportKeys:"excerpt",children:(0,f.jsx)(p,{name:"parsely-post-excerpt",title:(0,w.__)("Excerpt","wp-parsely"),children:(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Nr(window.wpParselyContentHelperSettings),children:(0,f.jsx)(Pe,{isDocumentSettingPanel:!0})})})})},Le=function(e,t){var n,r,i;return t!==Lr?e:H().ExcerptSuggestions?((null===(n=null===window||void 0===window?void 0:window.Jetpack_Editor_Initial_State)||void 0===n?void 0:n.available_blocks["ai-content-lens"])&&(console.log("Parse.ly: Jetpack AI is enabled and will be disabled."),(0,K.removeFilter)("blocks.registerBlockType","jetpack/ai-content-lens-features")),(0,_.registerPlugin)("wp-parsely-excerpt-suggestions",{render:function(){return(0,f.jsx)(Ee,{})}}),(null===(r=(0,v.dispatch)("core/editor"))||void 0===r?void 0:r.removeEditorPanel)?null===(i=(0,v.dispatch)("core/editor"))||void 0===i||i.removeEditorPanel("post-excerpt"):null==Y||Y.removeEditorPanel("post-excerpt"),e):e};function Ne(){(0,K.addFilter)("plugins.registerPlugin","wp-parsely-excerpt-suggestions",Le,1e3)}var Ce=window.wp.blockEditor;function Ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Oe=function(){return Oe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0)return r(e.innerBlocks,t[o].innerBlocks);if(JSON.stringify(e)!==JSON.stringify(t[o])){var s=t[o],a=i.parseFromString(e.attributes.content||"","text/html"),l=i.parseFromString((null==s?void 0:s.attributes.content)||"","text/html"),c=Array.from(a.querySelectorAll("a[data-smartlink]")),u=Array.from(l.querySelectorAll("a[data-smartlink]")),p=c.filter((function(e){return!u.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),d=u.filter((function(e){return!c.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),f=c.filter((function(e){var t=u.find((function(t){return t.dataset.smartlink===e.dataset.smartlink}));return t&&t.outerHTML!==e.outerHTML}));(p.length>0||d.length>0||f.length>0)&&n.push({block:e,prevBlock:s,addedLinks:p,removedLinks:d,changedLinks:f})}}}))};return r(e,t),n}(a,l.current);s.length>0&&(s.forEach((function(e){e.changedLinks.length>0&&n&&n(e),e.addedLinks.length>0&&i&&i(e),e.removedLinks.length>0&&r&&r(e)})),l.current=a)}),s);return e(t),function(){e.cancel()}}),[a,s,t,i,n,r]),null},Me=function(e){var t=e.value,n=e.onChange,r=e.max,i=e.min,o=e.suffix,s=e.size,a=e.label,l=e.initialPosition,c=e.disabled,u=e.className;return(0,f.jsxs)("div",{className:"parsely-inputrange-control ".concat(u||""),children:[(0,f.jsx)(h.__experimentalHeading,{className:"parsely-inputrange-control__label",level:3,children:a}),(0,f.jsxs)("div",{className:"parsely-inputrange-control__controls",children:[(0,f.jsx)(h.__experimentalNumberControl,{disabled:c,value:t,suffix:(0,f.jsx)(h.__experimentalInputControlSuffixWrapper,{children:o}),size:null!=s?s:"__unstable-large",min:i,max:r,onChange:function(e){var t=parseInt(e,10);isNaN(t)||n(t)}}),(0,f.jsx)(h.RangeControl,{disabled:c,value:t,showTooltip:!1,initialPosition:l,onChange:function(e){n(e)},withInputField:!1,min:i,max:r})]})]})},De=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))},Fe=function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&(0,w.__)("Regenerate Excerpt","wp-parsely"),!g&&0===u.newExcerptGeneratedCount&&(0,w.__)("Generate Excerpt","wp-parsely")]})})]}),n&&(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]})]})},Te=function(){return(0,f.jsx)(h.Animate,{type:"loading",children:function(e){var t=e.className;return(0,f.jsx)("span",{className:t,children:(0,w.__)("Generating…","wp-parsely")})}})},Ee=function(){return(0,f.jsx)(q.PostTypeSupportCheck,{supportKeys:"excerpt",children:(0,f.jsx)(p,{name:"parsely-post-excerpt",title:(0,w.__)("Excerpt","wp-parsely"),children:(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Nr(window.wpParselyContentHelperSettings),children:(0,f.jsx)(Pe,{isDocumentSettingPanel:!0})})})})},Le=function(e,t){var n,r,i;return t!==Lr?e:H().ExcerptSuggestions?((null===(n=null===window||void 0===window?void 0:window.Jetpack_Editor_Initial_State)||void 0===n?void 0:n.available_blocks["ai-content-lens"])&&(console.log("Parse.ly: Jetpack AI is enabled and will be disabled."),(0,K.removeFilter)("blocks.registerBlockType","jetpack/ai-content-lens-features")),(0,_.registerPlugin)("wp-parsely-excerpt-suggestions",{render:function(){return(0,f.jsx)(Ee,{})}}),(null===(r=(0,v.dispatch)("core/editor"))||void 0===r?void 0:r.removeEditorPanel)?null===(i=(0,v.dispatch)("core/editor"))||void 0===i||i.removeEditorPanel("post-excerpt"):null==Y||Y.removeEditorPanel("post-excerpt"),e):e};function Ne(){(0,K.addFilter)("plugins.registerPlugin","wp-parsely-excerpt-suggestions",Le,1e3)}var Ce=window.wp.blockEditor;function Ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Oe=function(){return Oe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0)return r(e.innerBlocks,t[o].innerBlocks);if(JSON.stringify(e)!==JSON.stringify(t[o])){var s=t[o],a=i.parseFromString(e.attributes.content||"","text/html"),l=i.parseFromString((null==s?void 0:s.attributes.content)||"","text/html"),c=Array.from(a.querySelectorAll("a[data-smartlink]")),u=Array.from(l.querySelectorAll("a[data-smartlink]")),p=c.filter((function(e){return!u.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),d=u.filter((function(e){return!c.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),f=c.filter((function(e){var t=u.find((function(t){return t.dataset.smartlink===e.dataset.smartlink}));return t&&t.outerHTML!==e.outerHTML}));(p.length>0||d.length>0||f.length>0)&&n.push({block:e,prevBlock:s,addedLinks:p,removedLinks:d,changedLinks:f})}}}))};return r(e,t),n}(a,l.current);s.length>0&&(s.forEach((function(e){e.changedLinks.length>0&&n&&n(e),e.addedLinks.length>0&&i&&i(e),e.removedLinks.length>0&&r&&r(e)})),l.current=a)}),s);return e(t),function(){e.cancel()}}),[a,s,t,i,n,r]),null},Me=function(e){var t=e.value,n=e.onChange,r=e.max,i=e.min,o=e.suffix,s=e.size,a=e.label,l=e.initialPosition,c=e.disabled,u=e.className;return(0,f.jsxs)("div",{className:"parsely-inputrange-control ".concat(u||""),children:[(0,f.jsx)(h.__experimentalHeading,{className:"parsely-inputrange-control__label",level:3,children:a}),(0,f.jsxs)("div",{className:"parsely-inputrange-control__controls",children:[(0,f.jsx)(h.__experimentalNumberControl,{disabled:c,value:t,suffix:(0,f.jsx)(h.__experimentalInputControlSuffixWrapper,{children:o}),size:null!=s?s:"__unstable-large",min:i,max:r,onChange:function(e){var t=parseInt(e,10);isNaN(t)||n(t)}}),(0,f.jsx)(h.RangeControl,{disabled:c,value:t,showTooltip:!1,initialPosition:l,onChange:function(e){n(e)},withInputField:!1,min:i,max:r})]})]})},De=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))},Fe=function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]

","\n\x3c!-- /wp:paragraph --\x3e");t&&d((0,Re.parse)(n))}),[o]),(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:s,right:a,up:s,down:a}}),(0,f.jsx)("div",{className:"review-suggestion-post-title",children:null===(t=o.post_data)||void 0===t?void 0:t.title}),(0,f.jsxs)("div",{className:"review-suggestion-preview",children:[!(null===(n=o.post_data)||void 0===n?void 0:n.is_first_paragraph)&&(0,f.jsx)(jt,{topOrBottom:"top"}),(0,f.jsx)(St,{block:p[0],link:o,useOriginalBlock:!0}),!(null===(r=o.post_data)||void 0===r?void 0:r.is_last_paragraph)&&(0,f.jsx)(jt,{topOrBottom:"bottom"})]}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(Pt,{link:o}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:s,icon:bt,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsx)("div",{className:"reviews-controls-middle",children:(0,f.jsx)(h.Button,{target:"_blank",href:(null===(i=o.post_data)||void 0===i?void 0:i.edit_link)+"&smart-link="+o.uid,variant:"secondary",onClick:function(){k.trackEvent("smart_linking_open_in_editor_pressed",{type:"inbound",uid:o.uid})},children:(0,w.__)("Open in the Editor","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:a,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ie,{icon:xt})]})})]})]})},Et=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",className:i,width:n,height:n,viewBox:"0 0 24 24",fill:"none",children:[(0,f.jsx)(h.Path,{d:"M8.18983 5.90381L8.83642 7.54325L10.4758 8.18983L8.83642 8.8364L8.18983 10.4759L7.54324 8.8364L5.90381 8.18983L7.54324 7.54325L8.18983 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M15.048 5.90381L15.9101 8.08972L18.0961 8.95186L15.9101 9.81397L15.048 11.9999L14.1859 9.81397L12 8.95186L14.1859 8.08972L15.048 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M11.238 10.4761L12.3157 13.2085L15.048 14.2861L12.3157 15.3638L11.238 18.0962L10.1603 15.3638L7.42798 14.2861L10.1603 13.2085L11.238 10.4761Z"})]})},Lt=function(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;ii.bottom)&&(n.scrollTop=r.offsetTop-n.offsetTop)}}}}),[t,l]);var u=function(){var e=document.querySelector(".smart-linking-review-sidebar-tabs [data-active-item]"),t=null==e?void 0:e.nextElementSibling;t||(t=document.querySelector('.smart-linking-review-sidebar-tabs [role="tab"]')),t&&t.click()},p=(0,f.jsxs)("span",{className:"smart-linking-menu-label",children:[(0,w.__)("NEW","wp-parsely"),(0,f.jsx)(Et,{})]}),d=[];n&&n.length>0&&d.push({name:"outbound",title:(0,w.__)("Outbound","wp-parsely")}),r&&r.length>0&&d.push({name:"inbound",title:(0,w.__)("Inbound","wp-parsely")});var v="outbound";return d=d.filter((function(e){return"outbound"===e.name&&r&&0===r.length&&(e.title=(0,w.__)("Outbound Smart Links","wp-parsely"),v="outbound"),"inbound"===e.name&&n&&0===n.length&&(e.title=(0,w.__)("Inbound Smart Links","wp-parsely"),v="inbound"),e})),(0,f.jsxs)("div",{className:"smart-linking-review-sidebar",ref:o,children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{tab:function(){return u()},"shift+tab":function(){return u()}}}),(0,f.jsx)(h.TabPanel,{className:"smart-linking-review-sidebar-tabs",initialTabName:v,tabs:d,onSelect:function(e){var t,o;"outbound"===e&&n&&n.length>0&&i(n[0]),"inbound"===e&&r&&r.length>0&&i(r[0]),k.trackEvent("smart_linking_modal_tab_selected",{tab:e,total_inbound:null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0,total_outbound:null!==(o=null==n?void 0:n.length)&&void 0!==o?o:0})},children:function(e){return(0,f.jsxs)(f.Fragment,{children:["outbound"===e.name&&(0,f.jsx)(f.Fragment,{children:n&&0!==n.length?n.map((function(e,n){return(0,f.jsxs)(h.MenuItem,{ref:function(e){s.current[n]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:[(0,f.jsx)("span",{className:"smart-linking-menu-item",children:e.text}),!e.applied&&p]},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No outbound links found.","wp-parsely")]})}),"inbound"===e.name&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"review-sidebar-tip",children:(0,w.__)("This section shows external posts that link back to the current post.","wp-parsely")}),r&&0!==r.length?r.map((function(e,r){var o;return(0,f.jsx)(h.MenuItem,{ref:function(e){s.current[(n?n.length:0)+r]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:(0,f.jsx)("span",{className:"smart-linking-menu-item",children:null===(o=e.post_data)||void 0===o?void 0:o.title})},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No inbound links found.","wp-parsely")]})]})]})}})]})},Ct=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm.5 16c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V7h15v12zM9 10H7v2h2v-2zm0 4H7v2h2v-2zm4-4h-2v2h2v-2zm4 0h-2v2h2v-2zm-4 4h-2v2h2v-2zm4 0h-2v2h2v-2z"})}),At=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10 4.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm2.25 7.5v-1A2.75 2.75 0 0011 8.25H7A2.75 2.75 0 004.25 11v1h1.5v-1c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v1h1.5zM4 20h9v-1.5H4V20zm16-4H4v-1.5h16V16z",fillRule:"evenodd",clipRule:"evenodd"})}),Ot=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m7.3 9.7 1.4 1.4c.2-.2.3-.3.4-.5 0 0 0-.1.1-.1.3-.5.4-1.1.3-1.6L12 7 9 4 7.2 6.5c-.6-.1-1.1 0-1.6.3 0 0-.1 0-.1.1-.3.1-.4.2-.6.4l1.4 1.4L4 11v1h1l2.3-2.3zM4 20h9v-1.5H4V20zm0-5.5V16h16v-1.5H4z"})}),It=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M3.99961 13C4.67043 13.3354 4.6703 13.3357 4.67017 13.3359L4.67298 13.3305C4.67621 13.3242 4.68184 13.3135 4.68988 13.2985C4.70595 13.2686 4.7316 13.2218 4.76695 13.1608C4.8377 13.0385 4.94692 12.8592 5.09541 12.6419C5.39312 12.2062 5.84436 11.624 6.45435 11.0431C7.67308 9.88241 9.49719 8.75 11.9996 8.75C14.502 8.75 16.3261 9.88241 17.5449 11.0431C18.1549 11.624 18.6061 12.2062 18.9038 12.6419C19.0523 12.8592 19.1615 13.0385 19.2323 13.1608C19.2676 13.2218 19.2933 13.2686 19.3093 13.2985C19.3174 13.3135 19.323 13.3242 19.3262 13.3305L19.3291 13.3359C19.3289 13.3357 19.3288 13.3354 19.9996 13C20.6704 12.6646 20.6703 12.6643 20.6701 12.664L20.6697 12.6632L20.6688 12.6614L20.6662 12.6563L20.6583 12.6408C20.6517 12.6282 20.6427 12.6108 20.631 12.5892C20.6078 12.5459 20.5744 12.4852 20.5306 12.4096C20.4432 12.2584 20.3141 12.0471 20.1423 11.7956C19.7994 11.2938 19.2819 10.626 18.5794 9.9569C17.1731 8.61759 14.9972 7.25 11.9996 7.25C9.00203 7.25 6.82614 8.61759 5.41987 9.9569C4.71736 10.626 4.19984 11.2938 3.85694 11.7956C3.68511 12.0471 3.55605 12.2584 3.4686 12.4096C3.42484 12.4852 3.39142 12.5459 3.36818 12.5892C3.35656 12.6108 3.34748 12.6282 3.34092 12.6408L3.33297 12.6563L3.33041 12.6614L3.32948 12.6632L3.32911 12.664C3.32894 12.6643 3.32879 12.6646 3.99961 13ZM11.9996 16C13.9326 16 15.4996 14.433 15.4996 12.5C15.4996 10.567 13.9326 9 11.9996 9C10.0666 9 8.49961 10.567 8.49961 12.5C8.49961 14.433 10.0666 16 11.9996 16Z"})}),Rt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})}),Bt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"})}),Mt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),Dt=function(e){var t,n,r=e.post,i=e.imageUrl,o=e.icon,s=void 0===o?wt:o,a=e.size,l=void 0===a?100:a,c=e.className,u=void 0===c?"":c,p=null!==(t=null==r?void 0:r.thumbnail)&&void 0!==t?t:i,d=null!==(n=null==r?void 0:r.title.rendered)&&void 0!==n?n:"";return(0,f.jsx)("div",{className:"parsely-thumbnail ".concat(u),style:{width:l,height:l},children:p?(0,f.jsx)("img",{src:p,alt:d,width:l,height:l,loading:"lazy","aria-hidden":""===d}):(0,f.jsx)("div",{className:"parsely-thumbnail-icon-container",children:(0,f.jsx)(h.Icon,{icon:s,size:l})})})};function Ft(e,t,n){void 0===t&&(t=1),void 0===n&&(n="");var r=parseInt(e.replace(/\D/g,""),10);if(r<1e3)return e;r<1e4&&(t=1);var i=r,o=r.toString(),s="",a=0;return Object.entries({1e3:"k","1,000,000":"M","1,000,000,000":"B","1,000,000,000,000":"T","1,000,000,000,000,000":"Q"}).forEach((function(e){var n=e[0],l=e[1],c=parseInt(n.replace(/\D/g,""),10);if(r>=c){var u=t;(i=r/c)%1>1/a&&(u=i>10?1:2),u=parseFloat(i.toFixed(2))===parseFloat(i.toFixed(0))?0:u,o=i.toFixed(u),s=l}a=c})),o+n+s}var Vt,Gt=function(e){var t,n,r,i,o=null===(t=e.link.match)||void 0===t?void 0:t.blockId,s=(0,v.useSelect)((function(e){var t=e("core/block-editor"),n=t.getBlock,r=t.getBlockParents;return o?{block:n(o),parents:r(o).map((function(e){return n(e)})).filter((function(e){return void 0!==e}))}:{block:void 0,parents:[]}}),[o]),a=s.block,l=s.parents;return a?(0,f.jsxs)("div",{className:"review-suggestions-breadcrumbs",children:[l.map((function(e,t){var n;return(0,f.jsxs)("span",{children:[(0,f.jsx)("span",{className:"breadcrumbs-parent-block",children:null===(n=(0,Re.getBlockType)(e.name))||void 0===n?void 0:n.title}),(0,f.jsx)("span",{className:"breadcrumbs-parent-separator",children:" / "})]},t)})),(0,f.jsxs)("span",{className:"breadcrumbs-current-block",children:[(0,f.jsx)("span",{className:"breadcrumbs-current-block-type",children:null===(n=(0,Re.getBlockType)(a.name))||void 0===n?void 0:n.title}),(null===(i=null===(r=a.attributes)||void 0===r?void 0:r.metadata)||void 0===i?void 0:i.name)&&(0,f.jsx)("span",{className:"breadcrumbs-current-block-name",children:a.attributes.metadata.name})]})]}):(0,f.jsx)(f.Fragment,{})},Ht=function(e){var t,n,r,i,o,s,a,l,c,u,p,d,v,g,y=e.link,m=null!==(n=null===(t=y.wp_post_meta)||void 0===t?void 0:t.author)&&void 0!==n?n:(0,w.__)("N/A","wp-parsely"),b=null!==(i=null===(r=y.post_stats)||void 0===r?void 0:r.avg_engaged)&&void 0!==i?i:(0,w.__)("N/A","wp-parsely"),x=(null===(o=y.wp_post_meta)||void 0===o?void 0:o.date)?function(e){if(!1===function(e){return!isNaN(+e)&&0!==e.getTime()}(e))return ut;var t=lt;return e.getUTCFullYear()===(new Date).getUTCFullYear()&&(t=ct),Intl.DateTimeFormat(document.documentElement.lang||"en",t).format(e)}(new Date(y.wp_post_meta.date)):(0,w.__)("N/A","wp-parsely"),_=null!==(a=null===(s=y.wp_post_meta)||void 0===s?void 0:s.thumbnail)&&void 0!==a&&a,k=null!==(c=null===(l=y.wp_post_meta)||void 0===l?void 0:l.title)&&void 0!==c?c:(0,w.__)("N/A","wp-parsely"),S=null!==(p=null===(u=y.wp_post_meta)||void 0===u?void 0:u.type)&&void 0!==p?p:(0,w.__)("External","wp-parsely"),j=null===(d=y.wp_post_meta)||void 0===d?void 0:d.url,P=(null===(v=y.post_stats)||void 0===v?void 0:v.views)?Ft(y.post_stats.views):(0,w.__)("N/A","wp-parsely"),T=(null===(g=y.post_stats)||void 0===g?void 0:g.visitors)?Ft(y.post_stats.visitors):(0,w.__)("N/A","wp-parsely");return(0,f.jsxs)("div",{className:"wp-parsely-link-suggestion-link-details",children:[(0,f.jsx)("div",{className:"thumbnail-column",children:_?(0,f.jsx)(Dt,{imageUrl:_,size:52}):(0,f.jsx)(Dt,{icon:wt,size:52})}),(0,f.jsxs)("div",{className:"data-column",children:[(0,f.jsxs)("div",{className:"title-row",children:[(0,f.jsx)(h.Tooltip,{text:k,children:(0,f.jsx)("span",{children:k})}),j&&(0,f.jsx)(h.Button,{href:j,target:"_blank",variant:"link",rel:"noopener",children:(0,f.jsx)(ie,{icon:$,size:18})})]}),(0,f.jsxs)("div",{className:"data-row",children:[(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:Ct,size:16}),(0,f.jsx)("span",{children:x})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ie,{icon:At,size:16}),(0,f.jsx)(h.Tooltip,{text:m,children:(0,f.jsx)("span",{children:m})})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ie,{icon:Ot,size:16}),(0,f.jsx)(h.Tooltip,{text:S,children:(0,f.jsx)("span",{children:S})})]})]}),y.post_stats&&(0,f.jsxs)("div",{className:"data-row",children:[P&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:It,size:16}),(0,f.jsx)("span",{children:P})]}),T&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:Rt,size:16}),(0,f.jsx)("span",{children:T})]}),b&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(h.Dashicon,{icon:"clock",size:16}),(0,f.jsx)("span",{children:b})]})]})]})]})},zt=function(e){var t=e.link,n=e.onNext,r=e.onPrevious,i=e.onAccept,o=e.onReject,s=e.onRemove,a=e.onSelectInEditor,l=e.hasPrevious,c=e.hasNext;if(t&&void 0!==t.post_data)return(0,f.jsx)(Tt,{link:t,onNext:n,onPrevious:r,onAccept:i,onReject:o,onRemove:s,onSelectInEditor:a,hasPrevious:l,hasNext:c});if(!(null==t?void 0:t.match))return(0,f.jsx)(f.Fragment,{children:(0,w.__)("This Smart Link does not have any matches in the current content.","wp-parsely")});var u=t.match.blockId,p=(0,v.select)("core/block-editor").getBlock(u),d=t.applied;return p?(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:r,right:n,up:r,down:n,a:function(){t&&!t.applied&&i()},r:function(){t&&(t.applied?s():o())}}}),(0,f.jsx)(Gt,{link:t}),(0,f.jsx)("div",{className:"review-suggestion-preview",children:(0,f.jsx)(St,{block:p,link:t})}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(Ht,{link:t}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:r,icon:bt,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsxs)("div",{className:"reviews-controls-middle",children:[!d&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Reject","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:Bt,onClick:o,variant:"secondary",children:(0,w.__)("Reject","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"A",text:(0,w.__)("Accept","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",icon:Mt,onClick:i,variant:"secondary",children:(0,w.__)("Accept","wp-parsely")})})]}),d&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Remove","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:Bt,onClick:s,variant:"secondary",children:(0,w.__)("Remove","wp-parsely")})}),(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",onClick:a,variant:"secondary",children:(0,w.__)("Select in Editor","wp-parsely")})]})]}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:n,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ie,{icon:xt})]})})]})]}):(0,f.jsx)(f.Fragment,{children:(0,w.__)("No block is selected.","wp-parsely")})},Ut=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))},qt=function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&(a=s[0],(l=a.parentNode)&&(c=document.createTextNode(null!==(u=a.textContent)&&void 0!==u?u:""),l.replaceChild(c,a),Z.updateBlockAttributes(n,{content:o.innerHTML}))),[4,L(t.uid)]):[2]):[2];case 1:return p.sent(),[2]}}))}))},C=(0,m.useCallback)((function(){c(!1),x().filter((function(e){return!e.applied})).length>0?s(!0):(W.unlockPostAutosaving("smart-linking-review-modal"),t())}),[x,t]),A=function(e){s(!1),e?(c(!1),T().then((function(){C()}))):c(!0)},O=function(){if(Ge(S)){var e=g.indexOf(S);if(!g[t=e+1])return;j(g[t])}else{var t;if(e=d.indexOf(S),!d[t=e+1])return;j(d[t])}},I=function(){if(Ge(S)){var e=g.indexOf(S);if(!g[t=e-1])return;j(g[t])}else{var t;if(e=d.indexOf(S),!d[t=e-1])return;j(d[t])}};return(0,m.useEffect)((function(){l?W.lockPostAutosaving("smart-linking-review-modal"):l&&0===p.length&&C()}),[l,t,p,C]),(0,m.useEffect)((function(){c(n)}),[n]),(0,f.jsxs)(f.Fragment,{children:[l&&(0,f.jsx)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),className:"wp-parsely-smart-linking-review-modal",onRequestClose:C,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,children:(0,f.jsxs)("div",{className:"smart-linking-modal-body",children:[(0,f.jsx)(Nt,{outboundLinks:d,inboundLinks:g,activeLink:S,setSelectedLink:j}),S&&(Ge(S)?(0,f.jsx)(Tt,{link:S,onNext:O,onPrevious:I,hasNext:g.indexOf(S)0}):(0,f.jsx)(zt,{link:S,hasNext:b().indexOf(S)0,onNext:O,onPrevious:I,onAccept:function(){return Ut(void 0,void 0,void 0,(function(){var e,t;return qt(this,(function(n){switch(n.label){case 0:return S.match?(r(S),[4,(i=S.match.blockId,o=S,Ut(void 0,void 0,void 0,(function(){var e,t;return qt(this,(function(n){switch(n.label){case 0:return(e=document.createElement("a")).href=o.href,e.title=o.title,e.setAttribute("data-smartlink",o.uid),(t=(0,v.select)("core/block-editor").getBlock(i))?(Ue(t,o,e),o.applied=!0,[4,E(o)]):[2];case 1:return n.sent(),[2]}}))})))]):[2];case 1:return n.sent(),k.trackEvent("smart_linking_link_accepted",{link:S.href,title:S.title,text:S.text,uid:S.uid}),0===y().length?(C(),[2]):(e=d.indexOf(S),d[t=e+1]?j(d[t]):j(d[0]),[2])}var i,o}))}))},onReject:function(){return Ut(void 0,void 0,void 0,(function(){var e,t;return qt(this,(function(n){switch(n.label){case 0:return e=d.indexOf(S),d[t=e+1]?j(d[t]):d[0]?j(d[0]):C(),[4,L(S.uid)];case 1:return n.sent(),k.trackEvent("smart_linking_link_rejected",{link:S.href,title:S.title,text:S.text,uid:S.uid}),[2]}}))}))},onRemove:function(){return Ut(void 0,void 0,void 0,(function(){var e,t,n,r;return qt(this,(function(i){switch(i.label){case 0:return S.match?(e=(0,v.select)("core/block-editor").getBlock(S.match.blockId))?(t=b(),n=t.indexOf(S),r=n-1,[4,N(e,S)]):[3,2]:[2];case 1:if(i.sent(),k.trackEvent("smart_linking_link_removed",{link:S.href,title:S.title,text:S.text,uid:S.uid}),0===(t=b()).length&&g.length>0)return j(g[0]),[2];if(0===t.length&&0===g.length)return C(),[2];if(t[r])return j(t[r]),[2];j(t[0]),i.label=2;case 2:return[2]}}))}))},onSelectInEditor:function(){if(S.match){var e=(0,v.select)("core/block-editor").getBlock(S.match.blockId);if(e){Z.selectBlock(e.clientId);var t=document.querySelector('[data-block="'.concat(e.clientId,'"]'));t&&et(t,S.uid),k.trackEvent("smart_linking_select_in_editor_pressed",{type:"outbound",uid:S.uid}),C()}}}}))]})}),o&&(0,f.jsxs)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),onRequestClose:function(){return A(!1)},className:"wp-parsely-smart-linking-close-dialog",children:[(0,w.__)("Are you sure you want to close? All un-accepted smart links will not be added.","wp-parsely"),(0,f.jsxs)("div",{className:"smart-linking-close-dialog-actions",children:[(0,f.jsx)(h.Button,{variant:"secondary",onClick:function(){return A(!1)},children:(0,w.__)("Go Back","wp-parsely")}),(0,f.jsx)(h.Button,{variant:"primary",onClick:function(){return A(!0)},children:(0,w.__)("Close","wp-parsely")})]})]})]})})),Zt=function(){return Zt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&S("success",/* translators: %d: number of smart links applied */ /* translators: %d: number of smart links applied */ (0,w.sprintf)((0,w.__)("%s smart links successfully applied.","wp-parsely"),g),{type:"snackbar"}):y(0)}),[x]),(0,m.useEffect)((function(){if(!(Object.keys(R).length>0)){var e={maxLinksPerPost:a.SmartLinking.MaxLinks};ee(e)}}),[ee,a]);var de=(0,v.useSelect)((function(e){var t=e("core/block-editor"),r=t.getSelectedBlock,i=t.getBlock,o=t.getBlocks,s=e("core/editor"),a=s.getEditedPostContent,l=s.getCurrentPostAttribute;return{allBlocks:o(),selectedBlock:n?i(n):r(),postContent:a(),postPermalink:l("link")}}),[n]),fe=de.allBlocks,he=de.selectedBlock,ve=de.postContent,ge=de.postPermalink,ye=function(e){return Wt(void 0,void 0,void 0,(function(){var t,n,r,i,o;return Yt(this,(function(s){switch(s.label){case 0:t=[],s.label=1;case 1:return s.trys.push([1,4,,9]),[4,re((n=L||!he)?Xe.All:Xe.Selected)];case 2:return s.sent(),a=ge.replace(/^https?:\/\//i,""),r=["http://"+a,"https://"+a],i=function(e){return e.map((function(e){return e.href}))}(F),r.push.apply(r,i),[4,gt.getInstance().generateSmartLinks(he&&!n?(0,Re.getBlockContent)(he):ve,O,r)];case 3:return t=s.sent(),[3,9];case 4:if((o=s.sent()).code&&o.code===U.ParselyAborted)throw o.numRetries=3-e,o;return e>0&&o.retryFetch?(console.error(o),[4,se(!0)]):[3,8];case 5:return s.sent(),[4,ae()];case 6:return s.sent(),[4,ye(e-1)];case 7:return[2,s.sent()];case 8:throw o;case 9:return[2,t]}var a}))}))},me=function(){for(var e=[],t=0;t[type="button"]').forEach((function(e){e.setAttribute("disabled","disabled")}))},xe=function(){document.querySelectorAll('.edit-post-header__settings>[type="button"]').forEach((function(e){e.removeAttribute("disabled")})),W.unlockPostSaving("wp-parsely-block-overlay")};return(0,f.jsxs)("div",{className:"wp-parsely-smart-linking",children:[(0,f.jsx)(Be,{isDetectingEnabled:!E,onLinkRemove:function(e){!function(e){De(this,void 0,void 0,(function(){var t,n,r;return Fe(this,(function(i){switch(i.label){case 0:return[4,$e((0,Re.getBlockContent)(e),e.clientId)];case 1:return t=i.sent(),n=t.missingSmartLinks,r=t.didAnyFixes,n.forEach((function(e){(0,v.dispatch)(it).removeSmartLink(e.uid)})),[2,r]}}))}))}(e.block)}}),(0,f.jsxs)(h.PanelRow,{className:t,children:[(0,f.jsxs)("div",{className:"smart-linking-text",children:[(0,w.__)("Automatically insert links to your most relevant, top performing content.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/smart-linking/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(ie,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),C&&(0,f.jsx)(h.Notice,{status:"info",onRemove:function(){return Z(null)},className:"wp-parsely-content-helper-error",children:C.Message()}),x&&g>0&&(0,f.jsx)(h.Notice,{status:"success",onRemove:function(){return _(!1)},className:"wp-parsely-smart-linking-suggested-links",children:(0,w.sprintf)(/* translators: 1 - number of smart links generated */ /* translators: 1 - number of smart links generated */ (0,w.__)("Successfully added %s smart links.","wp-parsely"),g>0?g:A.length)}),(0,f.jsx)(at,{disabled:T,selectedBlock:he,onSettingChange:function(e,t){var n;p({SmartLinking:Zt(Zt({},a.SmartLinking),(n={},n[e]=t,n))}),"MaxLinks"===e&&oe(t)}}),(0,f.jsx)("div",{className:"smart-linking-generate",children:(0,f.jsx)(h.Button,{onClick:function(){return Wt(void 0,void 0,void 0,(function(){var e,t,n,r,o,s,a,l;return Yt(this,(function(c){switch(c.label){case 0:return[4,K(!0)];case 1:return c.sent(),[4,le()];case 2:return c.sent(),[4,Z(null)];case 3:return c.sent(),_(!1),k.trackEvent("smart_linking_generate_pressed",{is_full_content:L,selected_block:null!==(s=null==he?void 0:he.name)&&void 0!==s?s:"none",context:i}),[4,me(L?"all":null==he?void 0:he.clientId)];case 4:c.sent(),e=setTimeout((function(){var e;K(!1),k.trackEvent("smart_linking_generate_timeout",{is_full_content:L,selected_block:null!==(e=null==he?void 0:he.name)&&void 0!==e?e:"none",context:i}),we(L?"all":null==he?void 0:he.clientId)}),18e4),t=B,c.label=5;case 5:return c.trys.push([5,8,10,15]),[4,ye(3)];case 6:return n=c.sent(),[4,(u=n,Wt(void 0,void 0,void 0,(function(){var e;return Yt(this,(function(t){switch(t.label){case 0:return u=u.filter((function(e){return!F.some((function(t){return t.uid===e.uid&&t.applied}))})),e=ge.replace(/^https?:\/\//,"").replace(/\/+$/,""),u=(u=u.filter((function(t){return!t.href.includes(e)||(console.warn("PCH Smart Linking: Skipping self-reference link: ".concat(t.href)),!1)}))).filter((function(e){return!F.some((function(t){return t.href===e.href?(console.warn("PCH Smart Linking: Skipping duplicate link: ".concat(e.href)),!0):t.text===e.text&&t.offset!==e.offset&&(console.warn("PCH Smart Linking: Skipping duplicate link text: ".concat(e.text)),!0)}))})),u=(u=Ze(L?fe:[he],u,{}).filter((function(e){return e.match}))).filter((function(e){if(!e.match)return!1;var t=e.match.blockLinkPosition,n=t+e.text.length;return!F.some((function(r){if(!r.match)return!1;if(e.match.blockId!==r.match.blockId)return!1;var i=r.match.blockLinkPosition,o=i+r.text.length;return t>=i&&n<=o}))})),[4,Y(u)];case 1:return t.sent(),[2,u]}}))})))];case 7:if(0===c.sent().length)throw new te((0,w.__)("No smart links were generated.","wp-parsely"),U.ParselySuggestionsApiNoData,"");return ce(!0),[3,15];case 8:return r=c.sent(),o=new te(null!==(a=r.message)&&void 0!==a?a:"An unknown error has occurred.",null!==(l=r.code)&&void 0!==l?l:U.UnknownError),r.code&&r.code===U.ParselyAborted&&(o.message=(0,w.sprintf)(/* translators: %d: number of retry attempts, %s: attempt plural */ /* translators: %d: number of retry attempts, %s: attempt plural */ From 654f0442620cad37046384b3831c1752e8b6f4b9 Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Thu, 20 Mar 2025 11:06:04 +0000 Subject: [PATCH 04/10] Fix queries & linting --- src/Models/class-inbound-smart-link.php | 13 +++--- src/Models/class-smart-link.php | 12 +++-- wp-parsely.php | 59 +++++++++++++------------ 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/Models/class-inbound-smart-link.php b/src/Models/class-inbound-smart-link.php index b8e2c66d41..697402a43f 100644 --- a/src/Models/class-inbound-smart-link.php +++ b/src/Models/class-inbound-smart-link.php @@ -1080,26 +1080,25 @@ public static function get_existing_suggestions( int $post_id ): array { */ public static function delete_pending_suggestions( int $post_id ): array { // Get all posts of type parsely_smart_link that have the destination taxonomy set to the post_id - // and the _smart_link_applied meta set to false. + // and the smart_link_status set to pending. $args = array( 'post_type' => 'parsely_smart_link', 'posts_per_page' => -1, 'fields' => 'ids', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 'tax_query' => array( + 'relation' => 'AND', array( 'taxonomy' => 'smart_link_destination', 'field' => 'name', 'include_children' => false, 'terms' => (string) $post_id, ), - ), - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query - 'meta_query' => array( array( - 'key' => '_smart_link_applied', - 'value' => 'false', - 'compare' => '=', + 'taxonomy' => 'smart_link_status', + 'field' => 'name', + 'include_children' => false, + 'terms' => Smart_Link_Status::PENDING, ), ), ); diff --git a/src/Models/class-smart-link.php b/src/Models/class-smart-link.php index 6623fade53..2634971899 100644 --- a/src/Models/class-smart-link.php +++ b/src/Models/class-smart-link.php @@ -897,8 +897,6 @@ public static function get_inbound_smart_links( int $post_id, string $status = S _doing_it_wrong( __METHOD__, 'Invalid status, defaulting to all.', '3.18.0' ); } - //$status = 'all'; - $cache_key = 'inbound-' . $post_id . '-' . $status; $smart_links = wp_cache_get( $cache_key, self::get_cache_group_for_post( $post_id ) ); @@ -953,20 +951,20 @@ public static function get_inbound_smart_links( int $post_id, string $status = S } $smart_link = Inbound_Smart_Link::from_smart_link( $smart_link ); - $is_linked = $smart_link->is_linked(); - $status = $smart_link->get_status(); + $is_linked = $smart_link->is_linked(); + $status = $smart_link->get_status(); // If the smart link is linked and the status is pending, set the status to applied. // This is to ensure backwards compatibility with Parse.ly < 3.18.0. - if ( $is_linked && $status === Smart_Link_Status::PENDING ) { + if ( $is_linked && Smart_Link_Status::PENDING === $status ) { $smart_link->set_status( Smart_Link_Status::APPLIED, true ); $status = Smart_Link_Status::APPLIED; } // Check if this inbound smart link is still linked to a post. // If not, do not add it to the array, and instead remove it. - if ( $status === Smart_Link_Status::APPLIED && ! $is_linked ) { - //$smart_link->delete(); TODO: Uncomment this when we are ready to delete the deprecated _smart_link_applied meta. + if ( Smart_Link_Status::APPLIED === $status && ! $is_linked ) { + $smart_link->delete(); continue; } diff --git a/wp-parsely.php b/wp-parsely.php index 68d319dec2..00de541783 100644 --- a/wp-parsely.php +++ b/wp-parsely.php @@ -49,8 +49,8 @@ return; } -const PARSELY_VERSION = '3.17.0'; -const PARSELY_FILE = __FILE__; +const PARSELY_VERSION = '3.17.0'; +const PARSELY_FILE = __FILE__; const PARSELY_DATA_SCHEMA_VERSION = '1'; if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { @@ -229,15 +229,18 @@ function parsely_integrations( $parsely = null ): Integrations { return $parsely_integrations; } - -add_action( 'admin_init', __NAMESPACE__ . '\\check_data_scheme_updates', 999 ); +add_action( 'admin_init', __NAMESPACE__ . '\\parsely_check_data_scheme_updates', 999 ); /** * Checks and performs any data scheme updates. * * @since 3.18.0 Handles the update from schema version 0 to 1. */ -function check_data_scheme_updates(): void { - $current_data_schema_version = get_option( 'parsely_data_schema_version' ) ?? 0; +function parsely_check_data_scheme_updates(): void { + $current_data_schema_version = get_option( 'parsely_data_schema_version' ); + + if ( false === $current_data_schema_version ) { + $current_data_schema_version = 0; + } if ( PARSELY_DATA_SCHEMA_VERSION <= $current_data_schema_version ) { return; @@ -245,32 +248,31 @@ function check_data_scheme_updates(): void { /** * Updates the smart links to have the Smart Link Status terms, - * and deletes the _smart_link_applied meta. - * + * and deletes the _smart_link_applied meta, if it exists. + * * Schema version 1. - * + * * @since 3.18.0 */ if ( 0 === $current_data_schema_version ) { - global $wpdb; - // Get all the smart links that do not have any Smart Link Status terms. - $smart_links_without_status = get_posts( array( - 'post_type' => 'parsely_smart_link', - 'posts_per_page' => -1, - 'fields' => 'ids', - 'suppress_filters' => false, - 'tax_query' => array( - array( - 'taxonomy' => 'smart_link_status', - 'field' => 'name', - 'terms' => array( - \Parsely\Models\Smart_Link_Status::get_all_statuses(), + // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_posts + $smart_links_without_status = get_posts( + array( + 'post_type' => 'parsely_smart_link', + 'posts_per_page' => -1, + 'fields' => 'ids', + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query + 'tax_query' => array( + array( + 'taxonomy' => 'smart_link_status', + 'field' => 'name', + 'terms' => \Parsely\Models\Smart_Link_Status::get_all_statuses(), + 'operator' => 'NOT IN', ), - 'operator' => 'NOT IN', ), - ), - ) ); + ) + ); if ( count( $smart_links_without_status ) === 0 ) { update_option( 'parsely_data_schema_version', PARSELY_DATA_SCHEMA_VERSION ); @@ -279,8 +281,9 @@ function check_data_scheme_updates(): void { // Loop through the smart links and update them to have the Smart Link Status terms. foreach ( $smart_links_without_status as $post_id ) { - $smart_link = \Parsely\Models\Smart_Link::get_smart_link_by_id( intval( $post_id ) ); - if( false === $smart_link ) { + $smart_link = \Parsely\Models\Smart_Link::get_smart_link_by_id( intval( $post_id ) ); + + if ( false === $smart_link ) { continue; } @@ -297,7 +300,7 @@ function check_data_scheme_updates(): void { $meta_value = get_post_meta( $post_id, '_smart_link_applied', true ); // If the meta value is true, then the smart link is considered applied. - if ( $meta_value === 'true' || $meta_value === true ) { + if ( 'true' === $meta_value || true === $meta_value ) { $smart_link->set_status( \Parsely\Models\Smart_Link_Status::APPLIED, true ); } else { // If the meta value is not true, then the smart link is considered pending. From 1ae96b978c86dca8aacdcbcd829f9f5d453f144d Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Thu, 20 Mar 2025 11:29:32 +0000 Subject: [PATCH 05/10] Flush caches afterwards. --- src/Models/class-smart-link.php | 2 +- wp-parsely.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Models/class-smart-link.php b/src/Models/class-smart-link.php index 2634971899..73ff02622d 100644 --- a/src/Models/class-smart-link.php +++ b/src/Models/class-smart-link.php @@ -1003,7 +1003,7 @@ protected function flush_cache(): void { * * @since 3.18.0 */ - protected function flush_all_cache(): void { + public function flush_all_cache(): void { $this->flush_cache(); if ( $this->source_post_id > 0 ) { self::flush_cache_by_post_id( $this->source_post_id ); diff --git a/wp-parsely.php b/wp-parsely.php index 00de541783..0adb400d77 100644 --- a/wp-parsely.php +++ b/wp-parsely.php @@ -307,6 +307,9 @@ function parsely_check_data_scheme_updates(): void { $smart_link->set_status( \Parsely\Models\Smart_Link_Status::PENDING, true ); } + // Flush the cache for the smart link. + $smart_link->flush_all_cache(); + // Delete the deprecated _smart_link_applied meta. delete_post_meta( $post_id, '_smart_link_applied' ); } From 8b11ea99dce8655d269ccc9ee535062a097c042b Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Thu, 20 Mar 2025 12:25:52 +0000 Subject: [PATCH 06/10] Rebuild assets --- build/content-helper/editor-sidebar.asset.php | 2 +- build/content-helper/editor-sidebar.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/content-helper/editor-sidebar.asset.php b/build/content-helper/editor-sidebar.asset.php index 1726bb6883..4b38bcf1fb 100644 --- a/build/content-helper/editor-sidebar.asset.php +++ b/build/content-helper/editor-sidebar.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '2674d449e64ff022e0ea'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => 'b8170c2ebb9580794bad'); diff --git a/build/content-helper/editor-sidebar.js b/build/content-helper/editor-sidebar.js index 17193f4682..b41e72a884 100644 --- a/build/content-helper/editor-sidebar.js +++ b/build/content-helper/editor-sidebar.js @@ -1,7 +1,7 @@ !function(){"use strict";var e={20:function(e,t,n){var r=n(609),i=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var r,s={},c=null,u=null;for(r in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,r)&&!l.hasOwnProperty(r)&&(s[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===s[r]&&(s[r]=t[r]);return{$$typeof:i,type:e,key:c,ref:u,props:s,_owner:a.current}}t.Fragment=s,t.jsx=c,t.jsxs=c},848:function(e,t,n){e.exports=n(20)},609:function(e){e.exports=window.React}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(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.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){n.d({},{w:function(){return Nr},_:function(){return Cr}});var e,t,r,i,s,o,a,l,c,u,p,d,f=n(848),h=window.wp.components,v=window.wp.data,g=window.wp.domReady,y=n.n(g),m=window.wp.element,w=window.wp.i18n,b=window.wp.primitives,_=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",d:"M11.25 5h1.5v15h-1.5V5zM6 10h1.5v10H6V10zm12 4h-1.5v6H18v-6z",clipRule:"evenodd"})}),x=window.wp.plugins;void 0!==window.wp&&(p=null!==(t=null===(e=window.wp.editor)||void 0===e?void 0:e.PluginDocumentSettingPanel)&&void 0!==t?t:null!==(i=null===(r=window.wp.editPost)||void 0===r?void 0:r.PluginDocumentSettingPanel)&&void 0!==i?i:null===(s=window.wp.editSite)||void 0===s?void 0:s.PluginDocumentSettingPanel,d=null!==(a=null===(o=window.wp.editor)||void 0===o?void 0:o.PluginSidebar)&&void 0!==a?a:null!==(c=null===(l=window.wp.editPost)||void 0===l?void 0:l.PluginSidebar)&&void 0!==c?c:null===(u=window.wp.editSite)||void 0===u?void 0:u.PluginSidebar);var k=function(){function e(){this._tkq=[],this.isLoaded=!1,this.isEnabled=!1,"undefined"!=typeof wpParselyTracksTelemetry&&(this.isEnabled=!0,this.loadTrackingLibrary())}return e.getInstance=function(){return window.wpParselyTelemetryInstance||Object.defineProperty(window,"wpParselyTelemetryInstance",{value:new e,writable:!1,configurable:!1,enumerable:!1}),window.wpParselyTelemetryInstance},e.prototype.loadTrackingLibrary=function(){var e=this,t=document.createElement("script");t.async=!0,t.src="//stats.wp.com/w.js",t.onload=function(){e.isLoaded=!0,e._tkq=window._tkq||[]},document.head.appendChild(t)},e.trackEvent=function(t){return n=this,r=arguments,s=function(t,n){var r;return void 0===n&&(n={}),function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]=1e4&&(clearInterval(s),n("Telemetry library not loaded"))}),100);else n("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,n){var r;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(n=this.prepareProperties(n),null===(r=this._tkq)||void 0===r||r.push(["recordEvent",t,n])):console.error("Error tracking event: Invalid event name")):console.error("Error tracking event: Telemetry not loaded")},e.prototype.isTelemetryEnabled=function(){return this.isEnabled},e.prototype.isProprietyValid=function(t){return e.PROPERTY_REGEX.test(t)},e.prototype.isEventNameValid=function(t){return e.EVENT_NAME_REGEX.test(t)},e.prototype.prepareProperties=function(e){return(e=this.sanitizeProperties(e)).parsely_version=wpParselyTracksTelemetry.version,wpParselyTracksTelemetry.user&&(e._ut=wpParselyTracksTelemetry.user.type,e._ui=wpParselyTracksTelemetry.user.id),wpParselyTracksTelemetry.vipgo_env&&(e.vipgo_env=wpParselyTracksTelemetry.vipgo_env),this.sanitizeProperties(e)},e.prototype.sanitizeProperties=function(e){var t=this,n={};return Object.keys(e).forEach((function(r){t.isProprietyValid(r)&&(n[r]=e[r])})),n},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),S=(k.trackEvent,function(){return(0,f.jsx)(h.SVG,{"aria-hidden":"true",version:"1.1",viewBox:"0 0 15 15",width:"15",height:"15",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(h.Path,{d:"M0 14.0025V11.0025L7.5 3.5025L10.5 6.5025L3 14.0025H0ZM12 5.0025L13.56 3.4425C14.15 2.8525 14.15 1.9025 13.56 1.3225L12.68 0.4425C12.09 -0.1475 11.14 -0.1475 10.56 0.4425L9 2.0025L12 5.0025Z"})})}),j=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{className:i,height:n,viewBox:"0 0 60 65",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M23.72,51.53c0-.18,0-.34-.06-.52a13.11,13.11,0,0,0-2.1-5.53A14.74,14.74,0,0,0,19.12,43c-.27-.21-.5-.11-.51.22l-.24,3.42c0,.33-.38.35-.49,0l-1.5-4.8a1.4,1.4,0,0,0-.77-.78,23.91,23.91,0,0,0-3.1-.84c-1.38-.24-3.39-.39-3.39-.39-.34,0-.45.21-.25.49l2.06,3.76c.2.27,0,.54-.29.33l-4.51-3.6a3.68,3.68,0,0,0-2.86-.48c-1,.16-2.44.46-2.44.46a.68.68,0,0,0-.39.25.73.73,0,0,0-.14.45S.41,43,.54,44a3.63,3.63,0,0,0,1.25,2.62L6.48,50c.28.2.09.49-.23.37l-4.18-.94c-.32-.12-.5,0-.4.37,0,0,.69,1.89,1.31,3.16a24,24,0,0,0,1.66,2.74,1.34,1.34,0,0,0,1,.52l5,.13c.33,0,.41.38.1.48L7.51,58c-.31.1-.34.35-.07.55a14.29,14.29,0,0,0,3.05,1.66,13.09,13.09,0,0,0,5.9.5,25.13,25.13,0,0,0,4.34-1,9.55,9.55,0,0,1-.08-1.2,9.32,9.32,0,0,1,3.07-6.91"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M59.7,41.53a.73.73,0,0,0-.14-.45.68.68,0,0,0-.39-.25s-1.43-.3-2.44-.46a3.64,3.64,0,0,0-2.86.48l-4.51,3.6c-.26.21-.49-.06-.29-.33l2.06-3.76c.2-.28.09-.49-.25-.49,0,0-2,.15-3.39.39a23.91,23.91,0,0,0-3.1.84,1.4,1.4,0,0,0-.77.78l-1.5,4.8c-.11.32-.48.3-.49,0l-.24-3.42c0-.33-.24-.43-.51-.22a14.74,14.74,0,0,0-2.44,2.47A13.11,13.11,0,0,0,36.34,51c0,.18,0,.34-.06.52a9.26,9.26,0,0,1,3,8.1,24.1,24.1,0,0,0,4.34,1,13.09,13.09,0,0,0,5.9-.5,14.29,14.29,0,0,0,3.05-1.66c.27-.2.24-.45-.07-.55l-3.22-1.17c-.31-.1-.23-.47.1-.48l5-.13a1.38,1.38,0,0,0,1-.52A24.6,24.6,0,0,0,57,52.92c.61-1.27,1.31-3.16,1.31-3.16.1-.33-.08-.49-.4-.37l-4.18.94c-.32.12-.51-.17-.23-.37l4.69-3.34A3.63,3.63,0,0,0,59.46,44c.13-1,.24-2.47.24-2.47"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M46.5,25.61c0-.53-.35-.72-.8-.43l-4.86,2.66c-.45.28-.56-.27-.23-.69l4.66-6.23a2,2,0,0,0,.28-1.68,36.51,36.51,0,0,0-2.19-4.89,34,34,0,0,0-2.81-3.94c-.33-.41-.74-.35-.91.16l-2.28,5.68c-.16.5-.6.48-.59-.05l.28-8.93a2.54,2.54,0,0,0-.66-1.64S35,4.27,33.88,3.27,30.78.69,30.78.69a1.29,1.29,0,0,0-1.54,0s-1.88,1.49-3.12,2.59-2.48,2.35-2.48,2.35A2.5,2.5,0,0,0,23,7.27l.27,8.93c0,.53-.41.55-.58.05l-2.29-5.69c-.17-.5-.57-.56-.91-.14a35.77,35.77,0,0,0-3,4.2,35.55,35.55,0,0,0-2,4.62,2,2,0,0,0,.27,1.67l4.67,6.24c.33.42.23,1-.22.69l-4.87-2.66c-.45-.29-.82-.1-.82.43a18.6,18.6,0,0,0,.83,5.07,20.16,20.16,0,0,0,5.37,7.77c3.19,3,5.93,7.8,7.45,11.08A9.6,9.6,0,0,1,30,49.09a9.31,9.31,0,0,1,2.86.45c1.52-3.28,4.26-8.11,7.44-11.09a20.46,20.46,0,0,0,5.09-7,19,19,0,0,0,1.11-5.82"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M36.12,58.44A6.12,6.12,0,1,1,30,52.32a6.11,6.11,0,0,1,6.12,6.12"})]})},P=function(){return P=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0?"".concat(i," ").concat(n):n)||this).hint=null,s.name=s.constructor.name,s.code=r;var o=[U.AccessToFeatureDisabled,U.ParselyApiForbidden,U.ParselyApiResponseContainsError,U.ParselyApiReturnedNoData,U.ParselyApiReturnedTooManyResults,U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsApiSecretNotSet,U.PluginSettingsSiteIdNotSet,U.PostIsNotPublished,U.UnknownError,U.ParselySuggestionsApiAuthUnavailable,U.ParselySuggestionsApiNoAuthentication,U.ParselySuggestionsApiNoAuthorization,U.ParselySuggestionsApiNoData,U.ParselySuggestionsApiSchemaError];return s.retryFetch=!o.includes(s.code),Object.setPrototypeOf(s,t.prototype),s.code===U.AccessToFeatureDisabled?s.message=(0,w.__)("Access to this feature is disabled by the site's administration.","wp-parsely"):s.code===U.ParselySuggestionsApiNoAuthorization?s.message=(0,w.__)('This AI-powered feature is opt-in. To gain access, please submit a request here.',"wp-parsely"):s.code===U.ParselySuggestionsApiOpenAiError||s.code===U.ParselySuggestionsApiOpenAiUnavailable?s.message=(0,w.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):s.code===U.HttpRequestFailed&&s.message.includes("cURL error 28")?s.message=(0,w.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):s.code===U.ParselySuggestionsApiSchemaError?s.message=(0,w.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):s.code===U.ParselySuggestionsApiNoData?s.message=(0,w.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):s.code===U.ParselySuggestionsApiOpenAiSchema?s.message=(0,w.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):s.code===U.ParselySuggestionsApiAuthUnavailable&&(s.message=(0,w.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),s}return ee(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsSiteIdNotSet,U.PluginSettingsApiSecretNotSet].includes(this.code)?Q(e):(this.code===U.FetchError&&(this.hint=this.Hint((0,w.__)("This error can sometimes be caused by ad-blockers or browser tracking protections. Please add this site to any applicable allow lists and try again.","wp-parsely"))),this.code!==U.ParselyApiForbidden&&this.code!==U.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,w.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===U.HttpRequestFailed&&(this.hint=this.Hint((0,w.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,f.jsx)(X,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

").concat(this.hint?this.hint:"")}))},t.prototype.Hint=function(e){return'

'.concat((0,w.__)("Hint:","wp-parsely")," ").concat(e,"

")},t.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,v.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),ne=window.wp.compose,re=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})}),ie=(0,m.forwardRef)((function({icon:e,size:t=24,...n},r){return(0,m.cloneElement)(e,{width:t,height:t,...n,ref:r})})),se=function(){return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:(0,f.jsx)(h.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M13.5034 7.91642L9 12.0104L4.49662 7.91642L5.25337 7.08398L8.99999 10.49L12.7466 7.08398L13.5034 7.91642Z",fill:"#1E1E1E"})})},oe={journalist:{label:(0,w.__)("Journalist","wp-parsely")},editorialWriter:{label:(0,w.__)("Editorial Writer","wp-parsely")},investigativeReporter:{label:(0,w.__)("Investigative Reporter","wp-parsely")},techAnalyst:{label:(0,w.__)("Tech Analyst","wp-parsely")},businessAnalyst:{label:(0,w.__)("Business Analyst","wp-parsely")},culturalCommentator:{label:(0,w.__)("Cultural Commentator","wp-parsely")},scienceCorrespondent:{label:(0,w.__)("Science Correspondent","wp-parsely")},politicalAnalyst:{label:(0,w.__)("Political Analyst","wp-parsely")},healthWellnessAdvocate:{label:(0,w.__)("Health and Wellness Advocate","wp-parsely")},environmentalJournalist:{label:(0,w.__)("Environmental Journalist","wp-parsely")},custom:{label:(0,w.__)("Custom Persona","wp-parsely"),icon:re}},ae=Object.keys(oe),le=function(e){return"custom"===e||""===e?oe.custom.label:ce(e)?e:oe[e].label},ce=function(e){return!ae.includes(e)||"custom"===e},ue=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],s=r[1],o=(0,ne.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-persona-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom persona…","wp-parsely"),onChange:function(e){if(""===e)return n(""),void s("");e.length>32&&(e=e.slice(0,32)),o(e),s(e)}})})},pe=function(e){var t=e.persona,n=e.value,r=void 0===n?(0,w.__)("Select a persona…","wp-parsely"):n,i=e.label,s=void 0===i?(0,w.__)("Persona","wp-parsely"):i,o=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u;return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[s&&(0,f.jsx)("div",{className:"wp-parsely-dropdown-label",children:s}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Persona","wp-parsely"),className:"parsely-persona-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-persona-selector-label",children:ce(t)?oe.custom.label:r}),(0,f.jsx)(se,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Persona","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:ae.map((function(e){if(!p&&"custom"===e)return null;var r=oe[e],i=e===t||ce(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),o(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-persona-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ie,{icon:r.icon}),r.label]},e)}))})})}}),p&&ce(t)&&(0,f.jsx)(ue,{onChange:function(e){o(""!==e?e:"custom")},value:"custom"===t?"":t})]})},de={neutral:{label:(0,w.__)("Neutral","wp-parsely")},formal:{label:(0,w.__)("Formal","wp-parsely")},humorous:{label:(0,w.__)("Humorous","wp-parsely")},confident:{label:(0,w.__)("Confident","wp-parsely")},provocative:{label:(0,w.__)("Provocative","wp-parsely")},serious:{label:(0,w.__)("Serious","wp-parsely")},inspirational:{label:(0,w.__)("Inspirational","wp-parsely")},skeptical:{label:(0,w.__)("Skeptical","wp-parsely")},conversational:{label:(0,w.__)("Conversational","wp-parsely")},analytical:{label:(0,w.__)("Analytical","wp-parsely")},custom:{label:(0,w.__)("Custom Tone","wp-parsely"),icon:re}},fe=Object.keys(de),he=function(e){return"custom"===e||""===e?de.custom.label:ve(e)?e:de[e].label},ve=function(e){return!fe.includes(e)||"custom"===e},ge=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],s=r[1],o=(0,ne.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-tone-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom tone","wp-parsely"),onChange:function(e){if(""===e)return n(""),void s("");e.length>32&&(e=e.slice(0,32)),o(e),s(e)}})})},ye=function(e){var t=e.tone,n=e.value,r=void 0===n?(0,w.__)("Select a tone","wp-parsely"):n,i=e.label,s=void 0===i?(0,w.__)("Tone","wp-parsely"):i,o=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u;return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[(0,f.jsx)("div",{className:"wp-parsely-dropdown-label",children:s}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Tone","wp-parsely"),className:"parsely-tone-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-tone-selector-label",children:ve(t)?de.custom.label:r}),(0,f.jsx)(se,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Select a tone","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:fe.map((function(e){if(!p&&"custom"===e)return null;var r=de[e],i=e===t||ve(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),o(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-tone-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ie,{icon:r.icon}),r.label]},e)}))})})}}),p&&ve(t)&&(0,f.jsx)(ge,{onChange:function(e){o(""!==e?e:"custom")},value:"custom"===t?"":t})]})},me=function(e){var t=e.isLoading,n=e.onPersonaChange,r=e.onToneChange,i=e.persona,s=e.tone;return(0,f.jsxs)("div",{className:"excerpt-suggestions-settings",children:[(0,f.jsx)(ye,{tone:s,value:he(s),onChange:function(e){r(e)},onDropdownChange:function(e){k.trackEvent("excerpt_generator_ai_tone_changed",{selectedTone:e})},disabled:t,allowCustom:!0}),(0,f.jsx)(pe,{persona:i,value:le(i),onChange:function(e){n(e)},onDropdownChange:function(e){k.trackEvent("excerpt_generator_ai_persona_changed",{persona:e})},disabled:t,allowCustom:!0})]})},we=window.wp.url,be=function(){function e(){this.abortControllers=new Map}return e.prototype.cancelRequest=function(e){if(e)(t=this.abortControllers.get(e))&&(t.abort(),this.abortControllers.delete(e));else{var t,n=Array.from(this.abortControllers.keys()).pop();n&&(t=this.abortControllers.get(n))&&(t.abort(),this.abortControllers.delete(n))}},e.prototype.cancelAll=function(){this.abortControllers.forEach((function(e){return e.abort()})),this.abortControllers.clear()},e.prototype.getOrCreateController=function(e){if(e&&this.abortControllers.has(e))return{abortController:this.abortControllers.get(e),abortId:e};var t=null!=e?e:"auto-"+Date.now(),n=new AbortController;return this.abortControllers.set(t,n),{abortController:n,abortId:t}},e.prototype.fetch=function(e,t){return n=this,r=void 0,s=function(){var n,r,i,s,o,a;return function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,w.sprintf)( // Translators: %1$s the number of words in the excerpt. // Translators: %1$s the number of words in the excerpt. -(0,w._n)("%1$s word","%1$s words",e,"wp-parsely"),e):"")}),[u.currentExcerpt,D]),(0,m.useEffect)((function(){var e=document.querySelector(".editor-post-excerpt textarea");e&&(e.scrollTop=0)}),[u.newExcerptGeneratedCount]);var G=(0,f.jsxs)("div",{className:"wp-parsely-excerpt-generator-header",children:[(0,f.jsx)(j,{size:16}),(0,f.jsx)("div",{className:"wp-parsely-excerpt-generator-header-label",children:(0,w.__)("Generate With Parse.ly","wp-parsely")})]}),H=n?(0,w.__)("Write an excerpt (optional)","wp-parsely"):(0,w.__)("Excerpt","wp-parsely");return(0,f.jsxs)("div",{className:"editor-post-excerpt",children:[!n&&(0,f.jsxs)("div",{className:"excerpt-suggestions-text",children:[(0,w.__)("Use Parse.ly AI to generate a concise, engaging excerpt for your post.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),(0,f.jsxs)("div",{style:{position:"relative"},children:[g&&(0,f.jsx)("div",{className:"editor-post-excerpt__loading_animation",children:(0,f.jsx)(Te,{})}),(0,f.jsx)(h.TextareaControl,{__nextHasNoMarginBottom:!0,label:H,className:"editor-post-excerpt__textarea",onChange:function(e){u.isUnderReview||R({excerpt:e}),p(ke(ke({},u),{currentExcerpt:e})),x(!0)},onKeyUp:function(){var e;if(_)x(!1);else{var t=document.querySelector(".editor-post-excerpt textarea"),n=null!==(e=null==t?void 0:t.textContent)&&void 0!==e?e:"";p(ke(ke({},u),{currentExcerpt:n}))}},value:g?"":u.isUnderReview?u.currentExcerpt:D,help:A||null})]}),n&&(0,f.jsxs)(h.Button,{href:(0,w.__)("https://wordpress.org/documentation/article/page-post-settings-sidebar/#excerpt"),target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about manual excerpts","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]}),(0,f.jsxs)("div",{className:"wp-parsely-excerpt-generator"+(n?" is-doc-set-panel":""),children:[a&&(0,f.jsx)(h.Notice,{className:"wp-parsely-excerpt-generator-error",onRemove:function(){return l(void 0)},status:"info",children:a.Message()}),u.isUnderReview?(0,f.jsxs)(f.Fragment,{children:[n&&G,(0,f.jsxs)("div",{className:"wp-parsely-excerpt-suggestions-review-controls",children:[(0,f.jsx)(h.Button,{variant:"secondary",onClick:function(){return Se(void 0,void 0,void 0,(function(){return je(this,(function(e){switch(e.label){case 0:return[4,R({excerpt:u.currentExcerpt})];case 1:return e.sent(),p(ke(ke({},u),{isUnderReview:!1})),k.trackEvent("excerpt_generator_accepted"),[2]}}))}))},children:(0,w.__)("Accept","wp-parsely")}),(0,f.jsx)(h.Button,{isDestructive:!0,variant:"secondary",onClick:function(){return Se(void 0,void 0,void 0,(function(){return je(this,(function(e){return R({excerpt:u.oldExcerpt}),p(ke(ke({},u),{currentExcerpt:u.oldExcerpt,isUnderReview:!1})),k.trackEvent("excerpt_generator_discarded"),[2]}))}))},children:(0,w.__)("Discard","wp-parsely")})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(me,{isLoading:g,onPersonaChange:function(e){B("Persona",e),T(e)},onSettingChange:B,onToneChange:function(e){B("Tone",e),N(e)},persona:i.ExcerptSuggestions.Persona,tone:i.ExcerptSuggestions.Tone}),n&&G,(0,f.jsx)("div",{className:"excerpt-suggestions-generate",children:(0,f.jsxs)(h.Button,{onClick:function(){return Se(void 0,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:y(!0),l(void 0),n.label=1;case 1:return n.trys.push([1,3,4,5]),k.trackEvent("excerpt_generator_pressed"),[4,xe.getInstance().generateExcerpt(V,F,P,L)];case 2:return e=n.sent(),p({currentExcerpt:e,isUnderReview:!0,newExcerptGeneratedCount:u.newExcerptGeneratedCount+1,oldExcerpt:D}),[3,5];case 3:return(t=n.sent())instanceof te?l(t):(l(new te((0,w.__)("An unknown error occurred.","wp-parsely"),U.UnknownError)),console.error(t)),[3,5];case 4:return y(!1),[7];case 5:return[2]}}))}))},variant:"primary",isBusy:g,disabled:g||!F,children:[g&&(0,w.__)("Generating Excerpt…","wp-parsely"),!g&&u.newExcerptGeneratedCount>0&&(0,w.__)("Regenerate Excerpt","wp-parsely"),!g&&0===u.newExcerptGeneratedCount&&(0,w.__)("Generate Excerpt","wp-parsely")]})})]}),n&&(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]})]})},Te=function(){return(0,f.jsx)(h.Animate,{type:"loading",children:function(e){var t=e.className;return(0,f.jsx)("span",{className:t,children:(0,w.__)("Generating…","wp-parsely")})}})},Ee=function(){return(0,f.jsx)(q.PostTypeSupportCheck,{supportKeys:"excerpt",children:(0,f.jsx)(p,{name:"parsely-post-excerpt",title:(0,w.__)("Excerpt","wp-parsely"),children:(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Cr(window.wpParselyContentHelperSettings),children:(0,f.jsx)(Pe,{isDocumentSettingPanel:!0})})})})},Le=function(e,t){var n,r,i;return t!==Nr?e:H().ExcerptSuggestions?((null===(n=null===window||void 0===window?void 0:window.Jetpack_Editor_Initial_State)||void 0===n?void 0:n.available_blocks["ai-content-lens"])&&(console.log("Parse.ly: Jetpack AI is enabled and will be disabled."),(0,K.removeFilter)("blocks.registerBlockType","jetpack/ai-content-lens-features")),(0,x.registerPlugin)("wp-parsely-excerpt-suggestions",{render:function(){return(0,f.jsx)(Ee,{})}}),(null===(r=(0,v.dispatch)("core/editor"))||void 0===r?void 0:r.removeEditorPanel)?null===(i=(0,v.dispatch)("core/editor"))||void 0===i||i.removeEditorPanel("post-excerpt"):null==Y||Y.removeEditorPanel("post-excerpt"),e):e};function Ne(){(0,K.addFilter)("plugins.registerPlugin","wp-parsely-excerpt-suggestions",Le,1e3)}var Ce=window.wp.blockEditor;function Ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Oe=function(){return Oe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0)return r(e.innerBlocks,t[s].innerBlocks);if(JSON.stringify(e)!==JSON.stringify(t[s])){var o=t[s],a=i.parseFromString(e.attributes.content||"","text/html"),l=i.parseFromString((null==o?void 0:o.attributes.content)||"","text/html"),c=Array.from(a.querySelectorAll("a[data-smartlink]")),u=Array.from(l.querySelectorAll("a[data-smartlink]")),p=c.filter((function(e){return!u.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),d=u.filter((function(e){return!c.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),f=c.filter((function(e){var t=u.find((function(t){return t.dataset.smartlink===e.dataset.smartlink}));return t&&t.outerHTML!==e.outerHTML}));(p.length>0||d.length>0||f.length>0)&&n.push({block:e,prevBlock:o,addedLinks:p,removedLinks:d,changedLinks:f})}}}))};return r(e,t),n}(a,l.current);o.length>0&&(o.forEach((function(e){e.changedLinks.length>0&&n&&n(e),e.addedLinks.length>0&&i&&i(e),e.removedLinks.length>0&&r&&r(e)})),l.current=a)}),o);return e(t),function(){e.cancel()}}),[a,o,t,i,n,r]),null},Me=function(e){var t=e.value,n=e.onChange,r=e.max,i=e.min,s=e.suffix,o=e.size,a=e.label,l=e.initialPosition,c=e.disabled,u=e.className;return(0,f.jsxs)("div",{className:"parsely-inputrange-control ".concat(u||""),children:[(0,f.jsx)(h.__experimentalHeading,{className:"parsely-inputrange-control__label",level:3,children:a}),(0,f.jsxs)("div",{className:"parsely-inputrange-control__controls",children:[(0,f.jsx)(h.__experimentalNumberControl,{disabled:c,value:t,suffix:(0,f.jsx)(h.__experimentalInputControlSuffixWrapper,{children:s}),size:null!=o?o:"__unstable-large",min:i,max:r,onChange:function(e){var t=parseInt(e,10);isNaN(t)||n(t)}}),(0,f.jsx)(h.RangeControl,{disabled:c,value:t,showTooltip:!1,initialPosition:l,onChange:function(e){n(e)},withInputField:!1,min:i,max:r})]})]})},De=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}l((r=r.apply(e,t||[])).next())}))},Fe=function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&(0,w.__)("Regenerate Excerpt","wp-parsely"),!g&&0===u.newExcerptGeneratedCount&&(0,w.__)("Generate Excerpt","wp-parsely")]})})]}),n&&(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/excerpt-suggestions/",target:"_blank",variant:"link",rel:"noopener",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]})]})},Te=function(){return(0,f.jsx)(h.Animate,{type:"loading",children:function(e){var t=e.className;return(0,f.jsx)("span",{className:t,children:(0,w.__)("Generating…","wp-parsely")})}})},Ee=function(){return(0,f.jsx)(q.PostTypeSupportCheck,{supportKeys:"excerpt",children:(0,f.jsx)(p,{name:"parsely-post-excerpt",title:(0,w.__)("Excerpt","wp-parsely"),children:(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Cr(window.wpParselyContentHelperSettings),children:(0,f.jsx)(Pe,{isDocumentSettingPanel:!0})})})})},Le=function(e,t){var n,r,i;return t!==Nr?e:H().ExcerptSuggestions?((null===(n=null===window||void 0===window?void 0:window.Jetpack_Editor_Initial_State)||void 0===n?void 0:n.available_blocks["ai-content-lens"])&&(console.log("Parse.ly: Jetpack AI is enabled and will be disabled."),(0,K.removeFilter)("blocks.registerBlockType","jetpack/ai-content-lens-features")),(0,x.registerPlugin)("wp-parsely-excerpt-suggestions",{render:function(){return(0,f.jsx)(Ee,{})}}),(null===(r=(0,v.dispatch)("core/editor"))||void 0===r?void 0:r.removeEditorPanel)?null===(i=(0,v.dispatch)("core/editor"))||void 0===i||i.removeEditorPanel("post-excerpt"):null==Y||Y.removeEditorPanel("post-excerpt"),e):e};function Ne(){(0,K.addFilter)("plugins.registerPlugin","wp-parsely-excerpt-suggestions",Le,1e3)}var Ce=window.wp.blockEditor;function Ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Oe=function(){return Oe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0)return r(e.innerBlocks,t[s].innerBlocks);if(JSON.stringify(e)!==JSON.stringify(t[s])){var o=t[s],a=i.parseFromString(e.attributes.content||"","text/html"),l=i.parseFromString((null==o?void 0:o.attributes.content)||"","text/html"),c=Array.from(a.querySelectorAll("a[data-smartlink]")),u=Array.from(l.querySelectorAll("a[data-smartlink]")),p=c.filter((function(e){return!u.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),d=u.filter((function(e){return!c.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),f=c.filter((function(e){var t=u.find((function(t){return t.dataset.smartlink===e.dataset.smartlink}));return t&&t.outerHTML!==e.outerHTML}));(p.length>0||d.length>0||f.length>0)&&n.push({block:e,prevBlock:o,addedLinks:p,removedLinks:d,changedLinks:f})}}}))};return r(e,t),n}(a,l.current);o.length>0&&(o.forEach((function(e){e.changedLinks.length>0&&n&&n(e),e.addedLinks.length>0&&i&&i(e),e.removedLinks.length>0&&r&&r(e)})),l.current=a)}),o);return e(t),function(){e.cancel()}}),[a,o,t,i,n,r]),null},Me=function(e){var t=e.value,n=e.onChange,r=e.max,i=e.min,s=e.suffix,o=e.size,a=e.label,l=e.initialPosition,c=e.disabled,u=e.className;return(0,f.jsxs)("div",{className:"parsely-inputrange-control ".concat(u||""),children:[(0,f.jsx)(h.__experimentalHeading,{className:"parsely-inputrange-control__label",level:3,children:a}),(0,f.jsxs)("div",{className:"parsely-inputrange-control__controls",children:[(0,f.jsx)(h.__experimentalNumberControl,{disabled:c,value:t,suffix:(0,f.jsx)(h.__experimentalInputControlSuffixWrapper,{children:s}),size:null!=o?o:"__unstable-large",min:i,max:r,onChange:function(e){var t=parseInt(e,10);isNaN(t)||n(t)}}),(0,f.jsx)(h.RangeControl,{disabled:c,value:t,showTooltip:!1,initialPosition:l,onChange:function(e){n(e)},withInputField:!1,min:i,max:r})]})]})},De=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}l((r=r.apply(e,t||[])).next())}))},Fe=function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]

","\n\x3c!-- /wp:paragraph --\x3e");t&&d((0,Re.parse)(n))}),[s]),(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:o,right:a,up:o,down:a}}),(0,f.jsx)("div",{className:"review-suggestion-post-title",children:null===(t=s.post_data)||void 0===t?void 0:t.title}),(0,f.jsxs)("div",{className:"review-suggestion-preview",children:[!(null===(n=s.post_data)||void 0===n?void 0:n.is_first_paragraph)&&(0,f.jsx)(Pt,{topOrBottom:"top"}),(0,f.jsx)(jt,{block:p[0],link:s,useOriginalBlock:!0}),!(null===(r=s.post_data)||void 0===r?void 0:r.is_last_paragraph)&&(0,f.jsx)(Pt,{topOrBottom:"bottom"})]}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(Tt,{link:s}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:o,icon:_t,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsx)("div",{className:"reviews-controls-middle",children:(0,f.jsx)(h.Button,{target:"_blank",href:(null===(i=s.post_data)||void 0===i?void 0:i.edit_link)+"&smart-link="+s.uid,variant:"secondary",onClick:function(){k.trackEvent("smart_linking_open_in_editor_pressed",{type:"inbound",uid:s.uid})},children:(0,w.__)("Open in the Editor","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:a,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ie,{icon:xt})]})})]})]})},Lt=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",className:i,width:n,height:n,viewBox:"0 0 24 24",fill:"none",children:[(0,f.jsx)(h.Path,{d:"M8.18983 5.90381L8.83642 7.54325L10.4758 8.18983L8.83642 8.8364L8.18983 10.4759L7.54324 8.8364L5.90381 8.18983L7.54324 7.54325L8.18983 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M15.048 5.90381L15.9101 8.08972L18.0961 8.95186L15.9101 9.81397L15.048 11.9999L14.1859 9.81397L12 8.95186L14.1859 8.08972L15.048 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M11.238 10.4761L12.3157 13.2085L15.048 14.2861L12.3157 15.3638L11.238 18.0962L10.1603 15.3638L7.42798 14.2861L10.1603 13.2085L11.238 10.4761Z"})]})},Nt=function(e,t,n){if(n||2===arguments.length)for(var r,i=0,s=t.length;ii.bottom)&&(n.scrollTop=r.offsetTop-n.offsetTop)}}}}),[t,l]);var u=function(){var e=document.querySelector(".smart-linking-review-sidebar-tabs [data-active-item]"),t=null==e?void 0:e.nextElementSibling;t||(t=document.querySelector('.smart-linking-review-sidebar-tabs [role="tab"]')),t&&t.click()},p=(0,f.jsxs)("span",{className:"smart-linking-menu-label",children:[(0,w.__)("NEW","wp-parsely"),(0,f.jsx)(Lt,{})]}),d=[];n&&n.length>0&&d.push({name:"outbound",title:(0,w.__)("Outbound","wp-parsely")}),r&&r.length>0&&d.push({name:"inbound",title:(0,w.__)("Inbound","wp-parsely")});var v="outbound";return d=d.filter((function(e){return"outbound"===e.name&&r&&0===r.length&&(e.title=(0,w.__)("Outbound Smart Links","wp-parsely"),v="outbound"),"inbound"===e.name&&n&&0===n.length&&(e.title=(0,w.__)("Inbound Smart Links","wp-parsely"),v="inbound"),e})),(0,f.jsxs)("div",{className:"smart-linking-review-sidebar",ref:s,children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{tab:function(){return u()},"shift+tab":function(){return u()}}}),(0,f.jsx)(h.TabPanel,{className:"smart-linking-review-sidebar-tabs",initialTabName:v,tabs:d,onSelect:function(e){var t,s;"outbound"===e&&n&&n.length>0&&i(n[0]),"inbound"===e&&r&&r.length>0&&i(r[0]),k.trackEvent("smart_linking_modal_tab_selected",{tab:e,total_inbound:null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0,total_outbound:null!==(s=null==n?void 0:n.length)&&void 0!==s?s:0})},children:function(e){return(0,f.jsxs)(f.Fragment,{children:["outbound"===e.name&&(0,f.jsx)(f.Fragment,{children:n&&0!==n.length?n.map((function(e,n){return(0,f.jsxs)(h.MenuItem,{ref:function(e){o.current[n]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:[(0,f.jsx)("span",{className:"smart-linking-menu-item",children:e.text}),!e.applied&&p]},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No outbound links found.","wp-parsely")]})}),"inbound"===e.name&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"review-sidebar-tip",children:(0,w.__)("This section shows external posts that link back to the current post.","wp-parsely")}),r&&0!==r.length?r.map((function(e,r){var s;return(0,f.jsx)(h.MenuItem,{ref:function(e){o.current[(n?n.length:0)+r]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:(0,f.jsx)("span",{className:"smart-linking-menu-item",children:null===(s=e.post_data)||void 0===s?void 0:s.title})},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No inbound links found.","wp-parsely")]})]})]})}})]})},At=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm.5 16c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V7h15v12zM9 10H7v2h2v-2zm0 4H7v2h2v-2zm4-4h-2v2h2v-2zm4 0h-2v2h2v-2zm-4 4h-2v2h2v-2zm4 0h-2v2h2v-2z"})}),Ot=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10 4.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm2.25 7.5v-1A2.75 2.75 0 0011 8.25H7A2.75 2.75 0 004.25 11v1h1.5v-1c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v1h1.5zM4 20h9v-1.5H4V20zm16-4H4v-1.5h16V16z",fillRule:"evenodd",clipRule:"evenodd"})}),It=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m7.3 9.7 1.4 1.4c.2-.2.3-.3.4-.5 0 0 0-.1.1-.1.3-.5.4-1.1.3-1.6L12 7 9 4 7.2 6.5c-.6-.1-1.1 0-1.6.3 0 0-.1 0-.1.1-.3.1-.4.2-.6.4l1.4 1.4L4 11v1h1l2.3-2.3zM4 20h9v-1.5H4V20zm0-5.5V16h16v-1.5H4z"})}),Rt=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M3.99961 13C4.67043 13.3354 4.6703 13.3357 4.67017 13.3359L4.67298 13.3305C4.67621 13.3242 4.68184 13.3135 4.68988 13.2985C4.70595 13.2686 4.7316 13.2218 4.76695 13.1608C4.8377 13.0385 4.94692 12.8592 5.09541 12.6419C5.39312 12.2062 5.84436 11.624 6.45435 11.0431C7.67308 9.88241 9.49719 8.75 11.9996 8.75C14.502 8.75 16.3261 9.88241 17.5449 11.0431C18.1549 11.624 18.6061 12.2062 18.9038 12.6419C19.0523 12.8592 19.1615 13.0385 19.2323 13.1608C19.2676 13.2218 19.2933 13.2686 19.3093 13.2985C19.3174 13.3135 19.323 13.3242 19.3262 13.3305L19.3291 13.3359C19.3289 13.3357 19.3288 13.3354 19.9996 13C20.6704 12.6646 20.6703 12.6643 20.6701 12.664L20.6697 12.6632L20.6688 12.6614L20.6662 12.6563L20.6583 12.6408C20.6517 12.6282 20.6427 12.6108 20.631 12.5892C20.6078 12.5459 20.5744 12.4852 20.5306 12.4096C20.4432 12.2584 20.3141 12.0471 20.1423 11.7956C19.7994 11.2938 19.2819 10.626 18.5794 9.9569C17.1731 8.61759 14.9972 7.25 11.9996 7.25C9.00203 7.25 6.82614 8.61759 5.41987 9.9569C4.71736 10.626 4.19984 11.2938 3.85694 11.7956C3.68511 12.0471 3.55605 12.2584 3.4686 12.4096C3.42484 12.4852 3.39142 12.5459 3.36818 12.5892C3.35656 12.6108 3.34748 12.6282 3.34092 12.6408L3.33297 12.6563L3.33041 12.6614L3.32948 12.6632L3.32911 12.664C3.32894 12.6643 3.32879 12.6646 3.99961 13ZM11.9996 16C13.9326 16 15.4996 14.433 15.4996 12.5C15.4996 10.567 13.9326 9 11.9996 9C10.0666 9 8.49961 10.567 8.49961 12.5C8.49961 14.433 10.0666 16 11.9996 16Z"})}),Bt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})}),Mt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"})}),Dt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),Ft=function(e){var t,n,r=e.post,i=e.imageUrl,s=e.icon,o=void 0===s?bt:s,a=e.size,l=void 0===a?100:a,c=e.className,u=void 0===c?"":c,p=null!==(t=null==r?void 0:r.thumbnail)&&void 0!==t?t:i,d=null!==(n=null==r?void 0:r.title.rendered)&&void 0!==n?n:"";return(0,f.jsx)("div",{className:"parsely-thumbnail ".concat(u),style:{width:l,height:l},children:p?(0,f.jsx)("img",{src:p,alt:d,width:l,height:l,loading:"lazy","aria-hidden":""===d}):(0,f.jsx)("div",{className:"parsely-thumbnail-icon-container",children:(0,f.jsx)(h.Icon,{icon:o,size:l})})})};function Vt(e,t,n){void 0===t&&(t=1),void 0===n&&(n="");var r=parseInt(e.replace(/\D/g,""),10);if(r<1e3)return e;r<1e4&&(t=1);var i=r,s=r.toString(),o="",a=0;return Object.entries({1e3:"k","1,000,000":"M","1,000,000,000":"B","1,000,000,000,000":"T","1,000,000,000,000,000":"Q"}).forEach((function(e){var n=e[0],l=e[1],c=parseInt(n.replace(/\D/g,""),10);if(r>=c){var u=t;(i=r/c)%1>1/a&&(u=i>10?1:2),u=parseFloat(i.toFixed(2))===parseFloat(i.toFixed(0))?0:u,s=i.toFixed(u),o=l}a=c})),s+n+o}var Gt,Ht=function(e){var t,n,r,i,s=null===(t=e.link.match)||void 0===t?void 0:t.blockId,o=(0,v.useSelect)((function(e){var t=e("core/block-editor"),n=t.getBlock,r=t.getBlockParents;return s?{block:n(s),parents:r(s).map((function(e){return n(e)})).filter((function(e){return void 0!==e}))}:{block:void 0,parents:[]}}),[s]),a=o.block,l=o.parents;return a?(0,f.jsxs)("div",{className:"review-suggestions-breadcrumbs",children:[l.map((function(e,t){var n;return(0,f.jsxs)("span",{children:[(0,f.jsx)("span",{className:"breadcrumbs-parent-block",children:null===(n=(0,Re.getBlockType)(e.name))||void 0===n?void 0:n.title}),(0,f.jsx)("span",{className:"breadcrumbs-parent-separator",children:" / "})]},t)})),(0,f.jsxs)("span",{className:"breadcrumbs-current-block",children:[(0,f.jsx)("span",{className:"breadcrumbs-current-block-type",children:null===(n=(0,Re.getBlockType)(a.name))||void 0===n?void 0:n.title}),(null===(i=null===(r=a.attributes)||void 0===r?void 0:r.metadata)||void 0===i?void 0:i.name)&&(0,f.jsx)("span",{className:"breadcrumbs-current-block-name",children:a.attributes.metadata.name})]})]}):(0,f.jsx)(f.Fragment,{})},zt=function(e){var t,n,r,i,s,o,a,l,c,u,p,d,v,g,y=e.link,m=null!==(n=null===(t=y.wp_post_meta)||void 0===t?void 0:t.author)&&void 0!==n?n:(0,w.__)("N/A","wp-parsely"),b=null!==(i=null===(r=y.post_stats)||void 0===r?void 0:r.avg_engaged)&&void 0!==i?i:(0,w.__)("N/A","wp-parsely"),_=(null===(s=y.wp_post_meta)||void 0===s?void 0:s.date)?function(e){if(!1===function(e){return!isNaN(+e)&&0!==e.getTime()}(e))return pt;var t=ct;return e.getUTCFullYear()===(new Date).getUTCFullYear()&&(t=ut),Intl.DateTimeFormat(document.documentElement.lang||"en",t).format(e)}(new Date(y.wp_post_meta.date)):(0,w.__)("N/A","wp-parsely"),x=null!==(a=null===(o=y.wp_post_meta)||void 0===o?void 0:o.thumbnail)&&void 0!==a&&a,k=null!==(c=null===(l=y.wp_post_meta)||void 0===l?void 0:l.title)&&void 0!==c?c:(0,w.__)("N/A","wp-parsely"),S=null!==(p=null===(u=y.wp_post_meta)||void 0===u?void 0:u.type)&&void 0!==p?p:(0,w.__)("External","wp-parsely"),j=null===(d=y.wp_post_meta)||void 0===d?void 0:d.url,P=(null===(v=y.post_stats)||void 0===v?void 0:v.views)?Vt(y.post_stats.views):(0,w.__)("N/A","wp-parsely"),T=(null===(g=y.post_stats)||void 0===g?void 0:g.visitors)?Vt(y.post_stats.visitors):(0,w.__)("N/A","wp-parsely");return(0,f.jsxs)("div",{className:"wp-parsely-link-suggestion-link-details",children:[(0,f.jsx)("div",{className:"thumbnail-column",children:x?(0,f.jsx)(Ft,{imageUrl:x,size:52}):(0,f.jsx)(Ft,{icon:bt,size:52})}),(0,f.jsxs)("div",{className:"data-column",children:[(0,f.jsxs)("div",{className:"title-row",children:[(0,f.jsx)(h.Tooltip,{text:k,children:(0,f.jsx)("span",{children:k})}),j&&(0,f.jsx)(h.Button,{href:j,target:"_blank",variant:"link",rel:"noopener",children:(0,f.jsx)(ie,{icon:$,size:18})})]}),(0,f.jsxs)("div",{className:"data-row",children:[(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:At,size:16}),(0,f.jsx)("span",{children:_})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ie,{icon:Ot,size:16}),(0,f.jsx)(h.Tooltip,{text:m,children:(0,f.jsx)("span",{children:m})})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ie,{icon:It,size:16}),(0,f.jsx)(h.Tooltip,{text:S,children:(0,f.jsx)("span",{children:S})})]})]}),y.post_stats&&(0,f.jsxs)("div",{className:"data-row",children:[P&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:Rt,size:16}),(0,f.jsx)("span",{children:P})]}),T&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ie,{icon:Bt,size:16}),(0,f.jsx)("span",{children:T})]}),b&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(h.Dashicon,{icon:"clock",size:16}),(0,f.jsx)("span",{children:b})]})]})]})]})},Ut=function(e){var t=e.link,n=e.onNext,r=e.onPrevious,i=e.onAccept,s=e.onReject,o=e.onRemove,a=e.onSelectInEditor,l=e.hasPrevious,c=e.hasNext;if(t&&void 0!==t.post_data)return(0,f.jsx)(Et,{link:t,onNext:n,onPrevious:r,onAccept:i,onReject:s,onRemove:o,onSelectInEditor:a,hasPrevious:l,hasNext:c});if(!(null==t?void 0:t.match))return(0,f.jsx)(f.Fragment,{children:(0,w.__)("This Smart Link does not have any matches in the current content.","wp-parsely")});var u=t.match.blockId,p=(0,v.select)("core/block-editor").getBlock(u),d=t.applied;return p?(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:r,right:n,up:r,down:n,a:function(){t&&!t.applied&&i()},r:function(){t&&(t.applied?o():s())}}}),(0,f.jsx)(Ht,{link:t}),(0,f.jsx)("div",{className:"review-suggestion-preview",children:(0,f.jsx)(jt,{block:p,link:t})}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(zt,{link:t}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:r,icon:_t,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsxs)("div",{className:"reviews-controls-middle",children:[!d&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Reject","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:Mt,onClick:s,variant:"secondary",children:(0,w.__)("Reject","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"A",text:(0,w.__)("Accept","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",icon:Dt,onClick:i,variant:"secondary",children:(0,w.__)("Accept","wp-parsely")})})]}),d&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Remove","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:Mt,onClick:o,variant:"secondary",children:(0,w.__)("Remove","wp-parsely")})}),(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",onClick:a,variant:"secondary",children:(0,w.__)("Select in Editor","wp-parsely")})]})]}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:n,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ie,{icon:xt})]})})]})]}):(0,f.jsx)(f.Fragment,{children:(0,w.__)("No block is selected.","wp-parsely")})},qt=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}l((r=r.apply(e,t||[])).next())}))},Kt=function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&(a=o[0],(l=a.parentNode)&&(c=document.createTextNode(null!==(u=a.textContent)&&void 0!==u?u:""),l.replaceChild(c,a),Z.updateBlockAttributes(n,{content:s.innerHTML}))),[4,L(t.uid)]):[2]):[2];case 1:return p.sent(),[2]}}))}))},C=(0,m.useCallback)((function(){c(!1),_().filter((function(e){return!e.applied})).length>0?o(!0):(W.unlockPostAutosaving("smart-linking-review-modal"),t())}),[_,t]),A=function(e){o(!1),e?(c(!1),T().then((function(){C()}))):c(!0)},O=function(){if(Ge(S)){var e=g.indexOf(S);if(!g[t=e+1])return;j(g[t])}else{var t;if(e=d.indexOf(S),!d[t=e+1])return;j(d[t])}},I=function(){if(Ge(S)){var e=g.indexOf(S);if(!g[t=e-1])return;j(g[t])}else{var t;if(e=d.indexOf(S),!d[t=e-1])return;j(d[t])}};return(0,m.useEffect)((function(){l?W.lockPostAutosaving("smart-linking-review-modal"):l&&0===p.length&&C()}),[l,t,p,C]),(0,m.useEffect)((function(){c(n)}),[n]),(0,f.jsxs)(f.Fragment,{children:[l&&(0,f.jsx)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),className:"wp-parsely-smart-linking-review-modal",onRequestClose:C,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,children:(0,f.jsxs)("div",{className:"smart-linking-modal-body",children:[(0,f.jsx)(Ct,{outboundLinks:d,inboundLinks:g,activeLink:S,setSelectedLink:j}),S&&(Ge(S)?(0,f.jsx)(Et,{link:S,onNext:O,onPrevious:I,hasNext:g.indexOf(S)0}):(0,f.jsx)(Ut,{link:S,hasNext:b().indexOf(S)0,onNext:O,onPrevious:I,onAccept:function(){return qt(void 0,void 0,void 0,(function(){var e,t;return Kt(this,(function(n){switch(n.label){case 0:return S.match?(r(S),[4,(i=S.match.blockId,s=S,qt(void 0,void 0,void 0,(function(){var e,t;return Kt(this,(function(n){switch(n.label){case 0:return(e=document.createElement("a")).href=s.href.itm,e.title=s.title,e.setAttribute("data-smartlink",s.uid),(t=(0,v.select)("core/block-editor").getBlock(i))?(Ue(t,s,e),s.applied=!0,[4,E(s)]):[2];case 1:return n.sent(),[2]}}))})))]):[2];case 1:return n.sent(),k.trackEvent("smart_linking_link_accepted",{link:S.href.raw,title:S.title,text:S.text,uid:S.uid}),0===y().length?(C(),[2]):(e=d.indexOf(S),d[t=e+1]?j(d[t]):j(d[0]),[2])}var i,s}))}))},onReject:function(){return qt(void 0,void 0,void 0,(function(){var e,t;return Kt(this,(function(n){switch(n.label){case 0:return e=d.indexOf(S),d[t=e+1]?j(d[t]):d[0]?j(d[0]):C(),[4,L(S.uid)];case 1:return n.sent(),k.trackEvent("smart_linking_link_rejected",{link:S.href.raw,title:S.title,text:S.text,uid:S.uid}),[2]}}))}))},onRemove:function(){return qt(void 0,void 0,void 0,(function(){var e,t,n,r;return Kt(this,(function(i){switch(i.label){case 0:return S.match?(e=(0,v.select)("core/block-editor").getBlock(S.match.blockId))?(t=b(),n=t.indexOf(S),r=n-1,[4,N(e,S)]):[3,2]:[2];case 1:if(i.sent(),k.trackEvent("smart_linking_link_removed",{link:S.href.raw,title:S.title,text:S.text,uid:S.uid}),0===(t=b()).length&&g.length>0)return j(g[0]),[2];if(0===t.length&&0===g.length)return C(),[2];if(t[r])return j(t[r]),[2];j(t[0]),i.label=2;case 2:return[2]}}))}))},onSelectInEditor:function(){if(S.match){var e=(0,v.select)("core/block-editor").getBlock(S.match.blockId);if(e){Z.selectBlock(e.clientId);var t=document.querySelector('[data-block="'.concat(e.clientId,'"]'));t&&Xe(t,S.uid),k.trackEvent("smart_linking_select_in_editor_pressed",{type:"outbound",uid:S.uid}),C()}}}}))]})}),s&&(0,f.jsxs)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),onRequestClose:function(){return A(!1)},className:"wp-parsely-smart-linking-close-dialog",children:[(0,w.__)("Are you sure you want to close? All un-accepted smart links will not be added.","wp-parsely"),(0,f.jsxs)("div",{className:"smart-linking-close-dialog-actions",children:[(0,f.jsx)(h.Button,{variant:"secondary",onClick:function(){return A(!1)},children:(0,w.__)("Go Back","wp-parsely")}),(0,f.jsx)(h.Button,{variant:"primary",onClick:function(){return A(!0)},children:(0,w.__)("Close","wp-parsely")})]})]})]})})),Wt=function(){return Wt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&S("success",/* translators: %d: number of smart links applied */ /* translators: %d: number of smart links applied */ (0,w.sprintf)((0,w.__)("%s smart links successfully applied.","wp-parsely"),g),{type:"snackbar"}):y(0)}),[_]),(0,m.useEffect)((function(){if(!(Object.keys(R).length>0)){var e={maxLinksPerPost:a.SmartLinking.MaxLinks};ee(e)}}),[ee,a]);var de=(0,v.useSelect)((function(e){var t=e("core/block-editor"),r=t.getSelectedBlock,i=t.getBlock,s=t.getBlocks,o=e("core/editor"),a=o.getEditedPostContent,l=o.getCurrentPostAttribute;return{allBlocks:s(),selectedBlock:n?i(n):r(),postContent:a(),postPermalink:l("link")}}),[n]),fe=de.allBlocks,he=de.selectedBlock,ve=de.postContent,ge=de.postPermalink,ye=function(e){return Yt(void 0,void 0,void 0,(function(){var t,n,r,i,s;return $t(this,(function(o){switch(o.label){case 0:t=[],o.label=1;case 1:return o.trys.push([1,4,,9]),[4,re((n=L||!he)?et.All:et.Selected)];case 2:return o.sent(),a=ge.replace(/^https?:\/\//i,""),r=["http://"+a,"https://"+a],i=function(e){return e.map((function(e){return e.href.raw}))}(F),r.push.apply(r,i),[4,yt.getInstance().generateSmartLinks(he&&!n?(0,Re.getBlockContent)(he):ve,O,r)];case 3:return t=o.sent(),[3,9];case 4:if((s=o.sent()).code&&s.code===U.ParselyAborted)throw s.numRetries=3-e,s;return e>0&&s.retryFetch?(console.error(s),[4,oe(!0)]):[3,8];case 5:return o.sent(),[4,ae()];case 6:return o.sent(),[4,ye(e-1)];case 7:return[2,o.sent()];case 8:throw s;case 9:return[2,t]}var a}))}))},me=function(){for(var e=[],t=0;t[type="button"]').forEach((function(e){e.setAttribute("disabled","disabled")}))},_e=function(){document.querySelectorAll('.edit-post-header__settings>[type="button"]').forEach((function(e){e.removeAttribute("disabled")})),W.unlockPostSaving("wp-parsely-block-overlay")};return(0,f.jsxs)("div",{className:"wp-parsely-smart-linking",children:[(0,f.jsx)(Be,{isDetectingEnabled:!E,onLinkRemove:function(e){!function(e){De(this,void 0,void 0,(function(){var t,n,r;return Fe(this,(function(i){switch(i.label){case 0:return[4,$e((0,Re.getBlockContent)(e),e.clientId)];case 1:return t=i.sent(),n=t.missingSmartLinks,r=t.didAnyFixes,n.forEach((function(e){(0,v.dispatch)(st).removeSmartLink(e.uid)})),[2,r]}}))}))}(e.block)}}),(0,f.jsxs)(h.PanelRow,{className:t,children:[(0,f.jsxs)("div",{className:"smart-linking-text",children:[(0,w.__)("Automatically insert links to your most relevant, top performing content.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/smart-linking/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(ie,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),C&&(0,f.jsx)(h.Notice,{status:"info",onRemove:function(){return Z(null)},className:"wp-parsely-content-helper-error",children:C.Message()}),_&&g>0&&(0,f.jsx)(h.Notice,{status:"success",onRemove:function(){return x(!1)},className:"wp-parsely-smart-linking-suggested-links",children:(0,w.sprintf)(/* translators: 1 - number of smart links generated */ /* translators: 1 - number of smart links generated */ (0,w.__)("Successfully added %s smart links.","wp-parsely"),g>0?g:A.length)}),(0,f.jsx)(lt,{disabled:T,selectedBlock:he,onSettingChange:function(e,t){var n;p({SmartLinking:Wt(Wt({},a.SmartLinking),(n={},n[e]=t,n))}),"MaxLinks"===e&&se(t)}}),(0,f.jsx)("div",{className:"smart-linking-generate",children:(0,f.jsx)(h.Button,{onClick:function(){return Yt(void 0,void 0,void 0,(function(){var e,t,n,r,s,o,a,l;return $t(this,(function(c){switch(c.label){case 0:return[4,K(!0)];case 1:return c.sent(),[4,le()];case 2:return c.sent(),[4,Z(null)];case 3:return c.sent(),x(!1),k.trackEvent("smart_linking_generate_pressed",{is_full_content:L,selected_block:null!==(o=null==he?void 0:he.name)&&void 0!==o?o:"none",context:i}),[4,me(L?"all":null==he?void 0:he.clientId)];case 4:c.sent(),e=setTimeout((function(){var e;K(!1),k.trackEvent("smart_linking_generate_timeout",{is_full_content:L,selected_block:null!==(e=null==he?void 0:he.name)&&void 0!==e?e:"none",context:i}),we(L?"all":null==he?void 0:he.clientId)}),18e4),t=B,c.label=5;case 5:return c.trys.push([5,8,10,15]),[4,ye(3)];case 6:return n=c.sent(),[4,(u=n,Yt(void 0,void 0,void 0,(function(){var e;return $t(this,(function(t){switch(t.label){case 0:return u=u.filter((function(e){return!F.some((function(t){return t.uid===e.uid&&t.applied}))})),e=ge.replace(/^https?:\/\//,"").replace(/\/+$/,""),u=(u=u.filter((function(t){return!t.href.raw.includes(e)||(console.warn("PCH Smart Linking: Skipping self-reference link: ".concat(t.href)),!1)}))).filter((function(e){return!F.some((function(t){return t.href===e.href?(console.warn("PCH Smart Linking: Skipping duplicate link: ".concat(e.href)),!0):t.text===e.text&&t.offset!==e.offset&&(console.warn("PCH Smart Linking: Skipping duplicate link text: ".concat(e.text)),!0)}))})),u=(u=Ze(L?fe:[he],u,{}).filter((function(e){return e.match}))).filter((function(e){if(!e.match)return!1;var t=e.match.blockLinkPosition,n=t+e.text.length;return!F.some((function(r){if(!r.match)return!1;if(e.match.blockId!==r.match.blockId)return!1;var i=r.match.blockLinkPosition,s=i+r.text.length;return t>=i&&n<=s}))})),[4,Y(u)];case 1:return t.sent(),[2,u]}}))})))];case 7:if(0===c.sent().length)throw new te((0,w.__)("No smart links were generated.","wp-parsely"),U.ParselySuggestionsApiNoData,"");return ce(!0),[3,15];case 8:return r=c.sent(),s=new te(null!==(a=r.message)&&void 0!==a?a:"An unknown error has occurred.",null!==(l=r.code)&&void 0!==l?l:U.UnknownError),r.code&&r.code===U.ParselyAborted&&(s.message=(0,w.sprintf)(/* translators: %d: number of retry attempts, %s: attempt plural */ /* translators: %d: number of retry attempts, %s: attempt plural */ From a072507edc3ee5a878700b4a0b88ac1c8d23eabd Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Thu, 20 Mar 2025 12:27:56 +0000 Subject: [PATCH 07/10] Address SonarCloud feedback --- src/Models/class-smart-link.php | 2 +- wp-parsely.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Models/class-smart-link.php b/src/Models/class-smart-link.php index ccdfe16699..ebedba1f3d 100644 --- a/src/Models/class-smart-link.php +++ b/src/Models/class-smart-link.php @@ -521,7 +521,7 @@ public function set_status( string $status, bool $save = false ): void { } if ( $save && null !== $this->smart_link_id ) { - $result = wp_set_post_terms( $this->smart_link_id, $status, 'smart_link_status' ); + wp_set_post_terms( $this->smart_link_id, $status, 'smart_link_status' ); } $this->status = $status; diff --git a/wp-parsely.php b/wp-parsely.php index 0adb400d77..29e931dc07 100644 --- a/wp-parsely.php +++ b/wp-parsely.php @@ -271,7 +271,7 @@ function parsely_check_data_scheme_updates(): void { 'operator' => 'NOT IN', ), ), - ) + ) ); if ( count( $smart_links_without_status ) === 0 ) { @@ -315,6 +315,5 @@ function parsely_check_data_scheme_updates(): void { } update_option( 'parsely_data_schema_version', PARSELY_DATA_SCHEMA_VERSION ); - return; } } From 384a2412c2041304df14da4cc154bfd62ed360ed Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Fri, 21 Mar 2025 10:41:50 +0000 Subject: [PATCH 08/10] Fix duplicated code as flagged by SonarCloud --- src/Models/class-smart-link.php | 261 +++++++++++++++++--------------- 1 file changed, 142 insertions(+), 119 deletions(-) diff --git a/src/Models/class-smart-link.php b/src/Models/class-smart-link.php index ebedba1f3d..1ab707d3ca 100644 --- a/src/Models/class-smart-link.php +++ b/src/Models/class-smart-link.php @@ -824,85 +824,153 @@ public static function get_smart_link_by_id( int $smart_link_id ) { } /** - * Gets the outbound smart links in a post. - * - * Outbound smart links are smart links that link to other posts. + * Gets smart links based on the specified parameters. * - * @since 3.16.0 - * @since 3.18.0 Added status parameter. + * @since 3.18.0 * - * @param int $post_id The post ID to get the smart links for. - * @param string $status The status of the smart links to get. - * @return array The smart links in the post. + * @param int $post_id The post ID to get the smart links for. + * @param string $type The type of smart links to get (outbound or inbound or all). + * @param string $status The status of the smart links to get (all or pending or applied). + * @param array $args WP_Query arguments to pass to the query. + * @param callable(Smart_Link):(Smart_Link|Inbound_Smart_Link|false|null)|null $process_smart_link_callback A callback to process each individual smart link. + * @return array The smart links. */ - public static function get_outbound_smart_links( int $post_id, string $status = Smart_Link_Status::ALL ): array { + public static function get_smart_links( int $post_id, string $type, string $status, array $args = array(), $process_smart_link_callback = null ): array { if ( ! Smart_Link_Status::is_valid_status( $status ) ) { $status = 'all'; _doing_it_wrong( __METHOD__, 'Invalid status, defaulting to all.', '3.18.0' ); } - $cache_key = 'outbound-' . $post_id . '-' . $status; - $smart_links = wp_cache_get( $cache_key, self::get_cache_group_for_post( $post_id ) ); + if ( ! in_array( $type, array( 'outbound', 'inbound', 'all' ), true ) ) { + _doing_it_wrong( __METHOD__, 'Invalid type, defaulting to outbound.', '3.18.0' ); + $type = 'outbound'; + } - // If the smart links are cached, return them. - if ( false !== $smart_links ) { - /** @var array $smart_links */ - return $smart_links; + $skip_cache = isset( $args['skip_cache'] ) && true === $args['skip_cache']; + $cache_key = $type . '-' . $post_id . '-' . $status; + + // If the cache is not being skipped, get the smart links from the cache. + if ( ! $skip_cache ) { + /** @var array|false $smart_links */ + $smart_links = wp_cache_get( $cache_key, self::get_cache_group_for_post( $post_id ) ); + + if ( false !== $smart_links && count( $smart_links ) > 0 ) { + /** @var array $smart_links */ + return $smart_links; + } } - // Build the tax query. - $tax_query = array( - 'relation' => 'AND', - array( + $tax_query = array(); + + // Add the tax query for the type of smart links to get. + if ( 'outbound' === $type ) { + $tax_query[] = array( 'taxonomy' => 'smart_link_source', 'include_children' => false, // Performance optimization. 'field' => 'name', 'terms' => (string) $post_id, - ), - ); + ); + } elseif ( 'inbound' === $type ) { + $tax_query[] = array( + 'taxonomy' => 'smart_link_destination', + 'include_children' => false, // Performance optimization. + 'field' => 'name', + 'terms' => (string) $post_id, + ); + } - // Add the status term to the tax query. - if ( Smart_Link_Status::ALL !== $status ) { + // Add the tax query for the status of the smart links to get. + if ( Smart_Link_Status::ALL === $status ) { $tax_query[] = array( 'taxonomy' => 'smart_link_status', 'include_children' => false, 'field' => 'name', - 'terms' => $status, + 'terms' => Smart_Link_Status::get_all_statuses(), + ); + } else { + $tax_query[] = array( + 'taxonomy' => 'smart_link_status', + 'include_children' => false, + 'field' => 'name', + 'terms' => array( $status ), ); } - // Build the query arguments. $query_args = array( 'post_type' => 'parsely_smart_link', 'posts_per_page' => -1, 'fields' => 'ids', // Only get the post IDs to improve performance. // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query - 'tax_query' => $tax_query, - 'orderby' => 'date', - 'order' => 'DESC', + 'tax_query' => array_merge( array( 'relation' => 'AND' ), $tax_query ), ); - // Get the smart links. - $smart_links = new \WP_Query( $query_args ); + // Merge the query arguments with the additional arguments. + $query_args = array_merge( $query_args, $args ); - $links = array(); - foreach ( $smart_links->posts as $smart_link_id ) { - if ( ! is_int( $smart_link_id ) ) { - continue; - } + // Get the smart links post objects. + $smart_links_query = new \WP_Query( $query_args ); + + // Create and process the smart links. + $smart_links = array(); + foreach ( $smart_links_query->posts as $smart_link_id ) { + /** @var int $smart_link_id */ $smart_link = self::get_smart_link_by_id( $smart_link_id ); if ( false === $smart_link ) { continue; } - $links[] = $smart_link; + if ( is_callable( $process_smart_link_callback ) ) { + /** + * The processed smart link after it has been processed by the callback. + * + * This callback is used to modify the smart link before it is added to the array, + * or false if the smart link should be skipped. + * + * @since 3.18.0 + * + * @var Smart_Link|Inbound_Smart_Link|false|null $smart_link + * */ + $smart_link = $process_smart_link_callback( $smart_link ); + } + + if ( false === $smart_link || null === $smart_link ) { + continue; + } + + $smart_links[] = $smart_link; } - // Cache the smart links. - wp_cache_set( $cache_key, $links, self::get_cache_group_for_post( $post_id ) ); + // Cache the smart links, even if the cache is being skipped, to ensure that + // the existing cache stays fresh. + wp_cache_set( $cache_key, $smart_links, self::get_cache_group_for_post( $post_id ) ); - return $links; + return $smart_links; + } + + /** + * Gets the outbound smart links in a post. + * + * Outbound smart links are smart links that link to other posts. + * + * @since 3.16.0 + * @since 3.18.0 Added status parameter. + * + * @param int $post_id The post ID to get the smart links for. + * @param string $status The status of the smart links to get. + * @return array The smart links in the post. + */ + public static function get_outbound_smart_links( int $post_id, string $status = Smart_Link_Status::ALL ): array { + /** @var array */ + return self::get_smart_links( + $post_id, + 'outbound', + $status, + array( + 'orderby' => 'date', + 'order' => 'ASC', + ) + ); } /** @@ -918,89 +986,44 @@ public static function get_outbound_smart_links( int $post_id, string $status = * @return array The smart links in the post. */ public static function get_inbound_smart_links( int $post_id, string $status = Smart_Link_Status::ALL ): array { - if ( ! Smart_Link_Status::is_valid_status( $status ) ) { - $status = 'all'; - _doing_it_wrong( __METHOD__, 'Invalid status, defaulting to all.', '3.18.0' ); - } - - $cache_key = 'inbound-' . $post_id . '-' . $status; - $smart_links = wp_cache_get( $cache_key, self::get_cache_group_for_post( $post_id ) ); - - // If the smart links are cached, return them. - if ( false !== $smart_links ) { - /** @var array $smart_links */ - return $smart_links; - } - - // Build the tax query. - $tax_query = array( - 'relation' => 'AND', + /** @var array */ + return self::get_smart_links( + $post_id, + 'inbound', + $status, array( - 'taxonomy' => 'smart_link_destination', - 'include_children' => false, // Performance optimization. - 'field' => 'name', - 'terms' => (string) $post_id, + 'orderby' => 'date modified', + 'order' => 'ASC', ), - ); - - // Add the status term to the tax query. - if ( Smart_Link_Status::ALL !== $status ) { - $tax_query[] = array( - 'taxonomy' => 'smart_link_status', - 'include_children' => false, - 'field' => 'name', - 'terms' => $status, - ); - } - - // Build the query arguments. - $query_args = array( - 'post_type' => 'parsely_smart_link', - 'posts_per_page' => -1, - 'fields' => 'ids', // Only get the post IDs to improve performance. - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query - 'tax_query' => $tax_query, - 'orderby' => 'date modified', - 'order' => 'ASC', - ); - - // Get the smart links. - $smart_links = new \WP_Query( $query_args ); - - $links = array(); - foreach ( $smart_links->posts as $smart_link_id ) { - /** @var int $smart_link_id */ - $smart_link = self::get_smart_link_by_id( $smart_link_id ); - - if ( false === $smart_link ) { - continue; + /** + * Process the smart link to convert it to an inbound smart link. + * + * @param Smart_Link $smart_link The smart link to process. + * @return Inbound_Smart_Link|false The processed smart link. + */ + function ( Smart_Link $smart_link ) { + $smart_link = Inbound_Smart_Link::from_smart_link( $smart_link ); + $is_linked = $smart_link->is_linked(); + $status = $smart_link->get_status(); + + // If the smart link is linked and the status is pending, set the status to applied. + // This is to ensure backwards compatibility with Parse.ly < 3.18.0. + if ( $is_linked && Smart_Link_Status::PENDING === $status ) { + $smart_link->set_status( Smart_Link_Status::APPLIED, true ); + $status = Smart_Link_Status::APPLIED; + } + + // Check if this inbound smart link is still linked to a post. + // If not, do not add it to the array, and instead remove it. + if ( Smart_Link_Status::APPLIED === $status && ! $is_linked ) { + $smart_link->delete(); + return false; + } + + /** @var Inbound_Smart_Link */ + return $smart_link; } - - $smart_link = Inbound_Smart_Link::from_smart_link( $smart_link ); - $is_linked = $smart_link->is_linked(); - $status = $smart_link->get_status(); - - // If the smart link is linked and the status is pending, set the status to applied. - // This is to ensure backwards compatibility with Parse.ly < 3.18.0. - if ( $is_linked && Smart_Link_Status::PENDING === $status ) { - $smart_link->set_status( Smart_Link_Status::APPLIED, true ); - $status = Smart_Link_Status::APPLIED; - } - - // Check if this inbound smart link is still linked to a post. - // If not, do not add it to the array, and instead remove it. - if ( Smart_Link_Status::APPLIED === $status && ! $is_linked ) { - $smart_link->delete(); - continue; - } - - $links[] = $smart_link; - } - - // Cache the smart links. - wp_cache_set( $cache_key, $links, self::get_cache_group_for_post( $post_id ) ); - - return $links; + ); } /** From 3e16f6ba35968d62050c38d573385ef54036d385 Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Fri, 21 Mar 2025 10:48:42 +0000 Subject: [PATCH 09/10] Prevent returning validation data on applied inbound smart links. --- src/Models/class-inbound-smart-link.php | 33 ++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Models/class-inbound-smart-link.php b/src/Models/class-inbound-smart-link.php index 68878cfbb2..8a91476798 100644 --- a/src/Models/class-inbound-smart-link.php +++ b/src/Models/class-inbound-smart-link.php @@ -88,23 +88,28 @@ public function to_array(): array { $data['post_data'] = $this->get_post_data(); - $has_valid_placement = $this->has_valid_placement( true ); + // If the smart link is not applied, check if it has a valid placement. + if ( ! $this->is_applied() ) { + $has_valid_placement = $this->has_valid_placement( true ); - if ( is_wp_error( $has_valid_placement ) ) { - $data['validation'] = array( - 'valid' => false, - 'reason' => $has_valid_placement->get_error_message(), - ); - } else { - $data['validation'] = array( - 'valid' => true, - ); + if ( is_wp_error( $has_valid_placement ) ) { + $data['validation'] = array( + 'valid' => false, + 'reason' => $has_valid_placement->get_error_message(), + ); + } else { + $data['validation'] = array( + 'valid' => true, + ); + } } - $previous_link_attributes = get_post_meta( $this->smart_link_id, '_traffic_boost_original_link_attributes', true ); - - if ( '' !== $previous_link_attributes ) { - $data['is_link_replacement'] = true; + // If the smart link is applied, check if it is a link replacement. + if ( $this->is_applied() ) { + $previous_link_attributes = get_post_meta( $this->smart_link_id, '_traffic_boost_original_link_attributes', true ); + if ( '' !== $previous_link_attributes ) { + $data['is_link_replacement'] = true; + } } return $data; From ee1f9745ccf63d1a28008f71a9c385fb2c193cb0 Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Fri, 21 Mar 2025 15:30:16 +0000 Subject: [PATCH 10/10] Do not remove the _smart_link_applied meta key. --- wp-parsely.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/wp-parsely.php b/wp-parsely.php index 29e931dc07..60954c7682 100644 --- a/wp-parsely.php +++ b/wp-parsely.php @@ -229,13 +229,13 @@ function parsely_integrations( $parsely = null ): Integrations { return $parsely_integrations; } -add_action( 'admin_init', __NAMESPACE__ . '\\parsely_check_data_scheme_updates', 999 ); +add_action( 'admin_init', __NAMESPACE__ . '\\parsely_check_data_schema_updates', 999 ); /** - * Checks and performs any data scheme updates. + * Checks and performs any data schema updates. * * @since 3.18.0 Handles the update from schema version 0 to 1. */ -function parsely_check_data_scheme_updates(): void { +function parsely_check_data_schema_updates(): void { $current_data_schema_version = get_option( 'parsely_data_schema_version' ); if ( false === $current_data_schema_version ) { @@ -248,7 +248,7 @@ function parsely_check_data_scheme_updates(): void { /** * Updates the smart links to have the Smart Link Status terms, - * and deletes the _smart_link_applied meta, if it exists. + * and checks the _smart_link_applied meta, if it exists. * * Schema version 1. * @@ -309,9 +309,6 @@ function parsely_check_data_scheme_updates(): void { // Flush the cache for the smart link. $smart_link->flush_all_cache(); - - // Delete the deprecated _smart_link_applied meta. - delete_post_meta( $post_id, '_smart_link_applied' ); } update_option( 'parsely_data_schema_version', PARSELY_DATA_SCHEMA_VERSION );