diff --git a/build/content-helper/dashboard-widget.asset.php b/build/content-helper/dashboard-widget.asset.php index 52faf9ad6..ec6f8b673 100644 --- a/build/content-helper/dashboard-widget.asset.php +++ b/build/content-helper/dashboard-widget.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '44e72ea772ae2dc442a3'); + array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '20fc48e438e82a58464f'); diff --git a/build/content-helper/dashboard-widget.js b/build/content-helper/dashboard-widget.js index 9e66f2a20..1f1a88dcd 100644 --- a/build/content-helper/dashboard-widget.js +++ b/build/content-helper/dashboard-widget.js @@ -1 +1 @@ -!function(){"use strict";var e={20:function(e,t,r){var n=r(609),a=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,r){var n,s={},c=null,u=null;for(n in void 0!==r&&(c=""+r),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,n)&&!l.hasOwnProperty(n)&&(s[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===s[n]&&(s[n]=t[n]);return{$$typeof:a,type:e,key:c,ref:u,props:s,_owner:i.current}}t.Fragment=s,t.jsx=c,t.jsxs=c},848:function(e,t,r){e.exports=r(20)},609:function(e){e.exports=window.React}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e,t,n,a=r(848),s=window.wp.element,o=window.wp.i18n,i=function(e){void 0===e&&(e=null);var t="";(null==e?void 0:e.children)&&(t=e.children);var r="content-helper-error-message";return(null==e?void 0:e.className)&&(r+=" "+e.className),(0,a.jsx)("div",{className:r,"data-testid":null==e?void 0:e.testId,dangerouslySetInnerHTML:{__html:t}})},l=function(e){var t;return void 0===e&&(e=null),(0,a.jsx)(i,{className:null==e?void 0:e.className,testId:"empty-credentials-message",children:null!==(t=window.wpParselyEmptyCredentialsMessage)&&void 0!==t?t:(0,o.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely")})},c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]=1e4&&(clearInterval(s),r("Telemetry library not loaded"))}),100);else r("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,r){var n;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(r=this.prepareProperties(r),null===(n=this._tkq)||void 0===n||n.push(["recordEvent",t,r])):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,r={};return Object.keys(e).forEach((function(n){t.isProprietyValid(n)&&(r[n]=e[n])})),r},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),h=(d.trackEvent,function(e){var t=e.defaultValue,r=e.items,n=e.onChange;return(0,a.jsx)("select",{onChange:n,value:t,children:r.map((function(e){return(0,a.jsx)("option",{value:e[0],children:e[1]},e[0])}))})}),f=window.wp.data,y=function(){return y=Object.assign||function(e){for(var t,r=1,n=arguments.length;rhere.',"wp-parsely"):s.code===N.ParselySuggestionsApiOpenAiError||s.code===N.ParselySuggestionsApiOpenAiUnavailable?s.message=(0,o.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):s.code===N.HttpRequestFailed&&s.message.includes("cURL error 28")?s.message=(0,o.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):s.code===N.ParselySuggestionsApiSchemaError?s.message=(0,o.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):s.code===N.ParselySuggestionsApiNoData?s.message=(0,o.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):s.code===N.ParselySuggestionsApiOpenAiSchema?s.message=(0,o.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):s.code===N.ParselySuggestionsApiAuthUnavailable&&(s.message=(0,o.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),s}return C(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[N.PluginCredentialsNotSetMessageDetected,N.PluginSettingsSiteIdNotSet,N.PluginSettingsApiSecretNotSet].includes(this.code)?l(e):(this.code===N.FetchError&&(this.hint=this.Hint((0,o.__)("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!==N.ParselyApiForbidden&&this.code!==N.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,o.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===N.HttpRequestFailed&&(this.hint=this.Hint((0,o.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,a.jsx)(i,{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,o.__)("Hint:","wp-parsely")," ").concat(e,"

")},t}(Error),k=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,r=Array.from(this.abortControllers.keys()).pop();r&&(t=this.abortControllers.get(r))&&(t.abort(),this.abortControllers.delete(r))}},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(),r=new AbortController;return this.abortControllers.set(t,r),{abortController:r,abortId:t}},e.prototype.fetch=function(e,t){return r=this,n=void 0,s=function(){var r,n,a,s,i;return function(e,t){var r,n,a,s,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(l){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(o=0)),o;)try{if(r=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]=c){var u=t;(a=n/c)%1>1/i&&(u=a>10?1:2),u=parseFloat(a.toFixed(2))===parseFloat(a.toFixed(0))?0:u,s=a.toFixed(u),o=l}i=c})),s+r+o}function z(e){var t=e.metric,r=e.post,n=e.avgEngagedIcon,s=e.viewsIcon;return"views"===t?(0,a.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Number of Views","wp-parsely")}),s,$(r.views.toString())]}):"avg_engaged"===t?(0,a.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Average Time","wp-parsely")}),n,r.avgEngaged]}):(0,a.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}function X(e){var t,r=e.metric,n=e.post;return(0,a.jsx)("li",{className:"parsely-top-post",children:(0,a.jsxs)("div",{className:"parsely-top-post-content",children:[(0,a.jsx)(B,{post:n}),(0,a.jsxs)("div",{className:"parsely-top-post-data",children:[(0,a.jsx)(z,{metric:r,post:n}),(0,a.jsx)(Z,{post:n}),(0,a.jsxs)("a",{className:"parsely-top-post-icon-link",href:n.url,target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("View Post (opens in new tab)","wp-parsely")}),(0,a.jsx)(q,{})]}),0!==n.postId&&(0,a.jsxs)("a",{className:"parsely-top-post-icon-link",href:(t=n.postId,"/wp-admin/post.php?post=".concat(t,"&action=edit")),target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Edit Post (opens in new tab)","wp-parsely")}),(0,a.jsx)(G,{})]}),(0,a.jsxs)("div",{className:"parsely-top-post-metadata",children:[(0,a.jsxs)("span",{className:"parsely-top-post-date",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Date","wp-parsely")}),M(new Date(n.date))]}),(0,a.jsxs)("span",{className:"parsely-top-post-author",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Author","wp-parsely")}),n.author]})]})]})]})},n.id)}function B(e){var t=e.post;return t.thumbnailUrl?(0,a.jsxs)("div",{className:"parsely-top-post-thumbnail",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Thumbnail","wp-parsely")}),(0,a.jsx)("img",{src:t.thumbnailUrl,alt:(0,o.__)("Post thumbnail","wp-parsely")})]}):(0,a.jsx)("div",{className:"parsely-top-post-thumbnail",children:(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Post thumbnail not available","wp-parsely")})})}function Z(e){var t=e.post;return(0,a.jsxs)("a",{className:"parsely-top-post-title",href:t.dashUrl,target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("View in Parse.ly (opens in new tab)","wp-parsely")}),t.title]})}var W=function(){return W=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,t(n-1)];case 2:return r.sent(),[3,4];case 3:f(!1),v(e),r.label=4;case 4:return[2]}}))}))})),[2]}))}))};return f(!0),t(1),function(){f(!1),m([]),v(void 0)}}),[i,S]);var N=function(e,t){d.trackEvent("dash_widget_filter_changed",W({filter:e},t))},T=(0,a.jsxs)("div",{className:"parsely-top-posts-filters",children:[(0,a.jsx)(h,{defaultValue:i.Period,items:Object.values(e).map((function(e){return[e,A(e)]})),onChange:function(t){x(t.target.value,e)&&(l({Period:t.target.value}),N("period",{period:t.target.value}),j(1))}}),(0,a.jsx)(h,{defaultValue:i.Metric,items:Object.values(t).map((function(e){return[e,E(e)]})),onChange:function(e){x(e.target.value,t)&&(l({Metric:e.target.value}),N("metric",{metric:e.target.value}),j(1))}})]}),C=(0,a.jsxs)("div",{className:"parsely-top-posts-navigation",children:[(0,a.jsx)("button",{className:"parsely-top-posts-navigation-prev",disabled:S<=1,"aria-label":(0,o.__)("Previous page","wp-parsely"),onClick:function(){j(S-1),d.trackEvent("dash_widget_navigation",{navigation:"previous",to_page:S-1})},children:(0,o.__)("<< Previous","wp-parsely")}),(0,o.sprintf)(/* translators: 1: Current page */ /* translators: 1: Current page */(0,o.__)("Page %1$d","wp-parsely"),S),(0,a.jsx)("button",{className:"parsely-top-posts-navigation-next",disabled:!u&&_.length<5,"aria-label":(0,o.__)("Next page","wp-parsely"),onClick:function(){j(S+1),d.trackEvent("dash_widget_navigation",{navigation:"next",to_page:S+1})},children:(0,o.__)("Next >>","wp-parsely")})]});if(g)return(0,a.jsxs)(a.Fragment,{children:[T,g.Message(),S>1&&C]});var O=(0,a.jsx)("div",{className:"parsely-spinner-wrapper",children:(0,a.jsx)(p.Spinner,{})});return(0,a.jsxs)(a.Fragment,{children:[T,u?O:(0,a.jsx)("ol",{className:"parsely-top-posts",style:{counterReset:"item "+5*(S-1)},children:_.map((function(e){return(0,a.jsx)(X,{metric:i.Metric,post:e},e.id)}))}),(_.length>=5||S>1)&&C]})}var J=function(r){var n;try{n=JSON.parse(r)}catch(r){return{Metric:t.Views,Period:e.Days7}}return x(null==n?void 0:n.Metric,t)||(n.Metric=t.Views),x(null==n?void 0:n.Period,e)||(n.Period=e.Days7),n};window.addEventListener("load",(function(){var e=document.querySelector("#wp-parsely-dashboard-widget > .inside");if(null!==e){var t=(0,a.jsx)(S,{endpoint:"dashboard-widget-settings",defaultSettings:J(window.wpParselyContentHelperSettings),children:(0,a.jsx)(u,{children:(0,a.jsx)(Q,{})})});s.createRoot?(0,s.createRoot)(e).render(t):(0,s.render)(t,e)}}),!1)}()}(); \ No newline at end of file +!function(){"use strict";var e={20:function(e,t,r){var n=r(609),a=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,r){var n,s={},c=null,u=null;for(n in void 0!==r&&(c=""+r),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,n)&&!l.hasOwnProperty(n)&&(s[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===s[n]&&(s[n]=t[n]);return{$$typeof:a,type:e,key:c,ref:u,props:s,_owner:i.current}}t.Fragment=s,t.jsx=c,t.jsxs=c},848:function(e,t,r){e.exports=r(20)},609:function(e){e.exports=window.React}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e,t,n,a=r(848),s=window.wp.element,o=window.wp.i18n,i=function(e){void 0===e&&(e=null);var t="";(null==e?void 0:e.children)&&(t=e.children);var r="content-helper-error-message";return(null==e?void 0:e.className)&&(r+=" "+e.className),(0,a.jsx)("div",{className:r,"data-testid":null==e?void 0:e.testId,dangerouslySetInnerHTML:{__html:t}})},l=function(e){var t;return void 0===e&&(e=null),(0,a.jsx)(i,{className:null==e?void 0:e.className,testId:"empty-credentials-message",children:null!==(t=window.wpParselyEmptyCredentialsMessage)&&void 0!==t?t:(0,o.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely")})},c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]=1e4&&(clearInterval(s),r("Telemetry library not loaded"))}),100);else r("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,r){var n;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(r=this.prepareProperties(r),null===(n=this._tkq)||void 0===n||n.push(["recordEvent",t,r])):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,r={};return Object.keys(e).forEach((function(n){t.isProprietyValid(n)&&(r[n]=e[n])})),r},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),h=(d.trackEvent,function(e){var t=e.defaultValue,r=e.items,n=e.onChange;return(0,a.jsx)("select",{onChange:n,value:t,children:r.map((function(e){return(0,a.jsx)("option",{value:e[0],children:e[1]},e[0])}))})}),f=window.wp.data,y=function(){return y=Object.assign||function(e){for(var t,r=1,n=arguments.length;rhere.',"wp-parsely"):s.code===j.ParselySuggestionsApiOpenAiError||s.code===j.ParselySuggestionsApiOpenAiUnavailable?s.message=(0,o.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):s.code===j.HttpRequestFailed&&s.message.includes("cURL error 28")?s.message=(0,o.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):s.code===j.ParselySuggestionsApiSchemaError?s.message=(0,o.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):s.code===j.ParselySuggestionsApiNoData?s.message=(0,o.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):s.code===j.ParselySuggestionsApiOpenAiSchema?s.message=(0,o.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):s.code===j.ParselySuggestionsApiAuthUnavailable&&(s.message=(0,o.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),s}return C(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[j.PluginCredentialsNotSetMessageDetected,j.PluginSettingsSiteIdNotSet,j.PluginSettingsApiSecretNotSet].includes(this.code)?l(e):(this.code===j.FetchError&&(this.hint=this.Hint((0,o.__)("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!==j.ParselyApiForbidden&&this.code!==j.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,o.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===j.HttpRequestFailed&&(this.hint=this.Hint((0,o.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,a.jsx)(i,{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,o.__)("Hint:","wp-parsely")," ").concat(e,"

")},t}(Error),k=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,r=Array.from(this.abortControllers.keys()).pop();r&&(t=this.abortControllers.get(r))&&(t.abort(),this.abortControllers.delete(r))}},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(),r=new AbortController;return this.abortControllers.set(t,r),{abortController:r,abortId:t}},e.prototype.fetch=function(e,t){return r=this,n=void 0,s=function(){var r,n,a,s,i;return function(e,t){var r,n,a,s,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(l){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(o=0)),o;)try{if(r=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]=c){var u=t;(a=n/c)%1>1/i&&(u=a>10?1:2),u=parseFloat(a.toFixed(2))===parseFloat(a.toFixed(0))?0:u,s=a.toFixed(u),o=l}i=c})),s+r+o}function z(e){var t=e.metric,r=e.post,n=e.avgEngagedIcon,s=e.viewsIcon;return"views"===t?(0,a.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Number of Views","wp-parsely")}),s,$(r.views.toString())]}):"avg_engaged"===t?(0,a.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Average Time","wp-parsely")}),n,r.avgEngaged]}):(0,a.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}function X(e){var t,r=e.metric,n=e.post;return(0,a.jsx)("li",{className:"parsely-top-post",children:(0,a.jsxs)("div",{className:"parsely-top-post-content",children:[(0,a.jsx)(B,{post:n}),(0,a.jsxs)("div",{className:"parsely-top-post-data",children:[(0,a.jsx)(z,{metric:r,post:n}),(0,a.jsx)(Z,{post:n}),(0,a.jsxs)("a",{className:"parsely-top-post-icon-link",href:n.url,target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("View Post (opens in new tab)","wp-parsely")}),(0,a.jsx)(q,{})]}),0!==n.postId&&(0,a.jsxs)("a",{className:"parsely-top-post-icon-link",href:(t=n.postId,"/wp-admin/post.php?post=".concat(t,"&action=edit")),target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Edit Post (opens in new tab)","wp-parsely")}),(0,a.jsx)(G,{})]}),(0,a.jsxs)("div",{className:"parsely-top-post-metadata",children:[(0,a.jsxs)("span",{className:"parsely-top-post-date",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Date","wp-parsely")}),M(new Date(n.date))]}),(0,a.jsxs)("span",{className:"parsely-top-post-author",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Author","wp-parsely")}),n.author]})]})]})]})},n.id)}function B(e){var t=e.post;return t.thumbnailUrl?(0,a.jsxs)("div",{className:"parsely-top-post-thumbnail",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Thumbnail","wp-parsely")}),(0,a.jsx)("img",{src:t.thumbnailUrl,alt:(0,o.__)("Post thumbnail","wp-parsely")})]}):(0,a.jsx)("div",{className:"parsely-top-post-thumbnail",children:(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Post thumbnail not available","wp-parsely")})})}function Z(e){var t=e.post;return(0,a.jsxs)("a",{className:"parsely-top-post-title",href:t.dashUrl,target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("View in Parse.ly (opens in new tab)","wp-parsely")}),t.title]})}var W=function(){return W=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,t(n-1)];case 2:return r.sent(),[3,4];case 3:f(!1),v(e),r.label=4;case 4:return[2]}}))}))})),[2]}))}))};return f(!0),t(1),function(){f(!1),b([]),v(void 0)}}),[i,S]);var j=function(e,t){d.trackEvent("dash_widget_filter_changed",W({filter:e},t))},N=(0,a.jsxs)("div",{className:"parsely-top-posts-filters",children:[(0,a.jsx)(h,{defaultValue:i.Period,items:Object.values(e).map((function(e){return[e,A(e)]})),onChange:function(t){x(t.target.value,e)&&(l({Period:t.target.value}),j("period",{period:t.target.value}),T(1))}}),(0,a.jsx)(h,{defaultValue:i.Metric,items:Object.values(t).map((function(e){return[e,E(e)]})),onChange:function(e){x(e.target.value,t)&&(l({Metric:e.target.value}),j("metric",{metric:e.target.value}),T(1))}})]}),C=(0,a.jsxs)("div",{className:"parsely-top-posts-navigation",children:[(0,a.jsx)("button",{className:"parsely-top-posts-navigation-prev",disabled:S<=1,"aria-label":(0,o.__)("Previous page","wp-parsely"),onClick:function(){T(S-1),d.trackEvent("dash_widget_navigation",{navigation:"previous",to_page:S-1})},children:(0,o.__)("<< Previous","wp-parsely")}),(0,o.sprintf)(/* translators: 1: Current page */ /* translators: 1: Current page */(0,o.__)("Page %1$d","wp-parsely"),S),(0,a.jsx)("button",{className:"parsely-top-posts-navigation-next",disabled:!u&&_.length<5,"aria-label":(0,o.__)("Next page","wp-parsely"),onClick:function(){T(S+1),d.trackEvent("dash_widget_navigation",{navigation:"next",to_page:S+1})},children:(0,o.__)("Next >>","wp-parsely")})]});if(g)return(0,a.jsxs)(a.Fragment,{children:[N,g.Message(),S>1&&C]});var O=(0,a.jsx)("div",{className:"parsely-spinner-wrapper",children:(0,a.jsx)(p.Spinner,{})});return(0,a.jsxs)(a.Fragment,{children:[N,u?O:(0,a.jsx)("ol",{className:"parsely-top-posts",style:{counterReset:"item "+5*(S-1)},children:_.map((function(e){return(0,a.jsx)(X,{metric:i.Metric,post:e},e.id)}))}),(_.length>=5||S>1)&&C]})}var J=function(r){var n;try{n=JSON.parse(r)}catch(r){return{Metric:t.Views,Period:e.Days7}}return x(null==n?void 0:n.Metric,t)||(n.Metric=t.Views),x(null==n?void 0:n.Period,e)||(n.Period=e.Days7),n};window.addEventListener("load",(function(){var e=document.querySelector("#wp-parsely-dashboard-widget > .inside");if(null!==e){var t=(0,a.jsx)(S,{endpoint:"dashboard-widget-settings",defaultSettings:J(window.wpParselyContentHelperSettings),children:(0,a.jsx)(u,{children:(0,a.jsx)(Q,{})})});s.createRoot?(0,s.createRoot)(e).render(t):(0,s.render)(t,e)}}),!1)}()}(); \ No newline at end of file diff --git a/build/content-helper/editor-sidebar.asset.php b/build/content-helper/editor-sidebar.asset.php index dc53b368c..ecc395f09 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-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '76e4c5e6b210712984df'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '1f97f0ca87e022ed4921'); diff --git a/build/content-helper/editor-sidebar.js b/build/content-helper/editor-sidebar.js index b01274062..4811865c7 100644 --- a/build/content-helper/editor-sidebar.js +++ b/build/content-helper/editor-sidebar.js @@ -1,27 +1,27 @@ -!function(){"use strict";var e={20:function(e,t,n){var r=n(609),i=Symbol.for("react.element"),s=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,o=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)a.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:o.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({},{_:function(){return Wn}});var e,t,r,i=n(848),s=window.wp.components,a=window.wp.data,o=window.wp.domReady,l=n.n(o),c=window.wp.editPost,u=window.wp.element,p=window.wp.i18n,d=window.wp.primitives,f=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{fillRule:"evenodd",d:"M11.25 5h1.5v15h-1.5V5zM6 10h1.5v10H6V10zm12 4h-1.5v6H18v-6z",clipRule:"evenodd"})}),h=window.wp.plugins,v=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,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function o(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,o[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(),g=(v.trackEvent,function(){return(0,i.jsx)(s.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,i.jsx)(s.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"})})}),y=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,a=void 0===r?"wp-parsely-icon":r;return(0,i.jsxs)(s.SVG,{className:a,height:n,viewBox:"0 0 60 65",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)(s.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,i.jsx)(s.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,i.jsx)(s.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,i.jsx)(s.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"})]})},m=function(){return m=Object.assign||function(e){for(var t,n=1,r=arguments.length;nhere.',"wp-parsely"):s.code===B.ParselySuggestionsApiOpenAiError||s.code===B.ParselySuggestionsApiOpenAiUnavailable?s.message=(0,p.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):s.code===B.HttpRequestFailed&&s.message.includes("cURL error 28")?s.message=(0,p.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):s.code===B.ParselySuggestionsApiSchemaError?s.message=(0,p.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):s.code===B.ParselySuggestionsApiNoData?s.message=(0,p.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):s.code===B.ParselySuggestionsApiOpenAiSchema?s.message=(0,p.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):s.code===B.ParselySuggestionsApiAuthUnavailable&&(s.message=(0,p.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),s}return Z(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[B.PluginCredentialsNotSetMessageDetected,B.PluginSettingsSiteIdNotSet,B.PluginSettingsApiSecretNotSet].includes(this.code)?D(e):(this.code===B.FetchError&&(this.hint=this.Hint((0,p.__)("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!==B.ParselyApiForbidden&&this.code!==B.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,p.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===B.HttpRequestFailed&&(this.hint=this.Hint((0,p.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,i.jsx)(M,{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,p.__)("Hint:","wp-parsely")," ").concat(e,"

")},t}(Error),$=function(e){var t=e.isDetectingEnabled,n=e.onLinkChange,r=e.onLinkRemove,i=e.onLinkAdd,s=e.debounceValue,o=void 0===s?500:s,l=(0,a.useSelect)((function(e){return{blocks:(0,e("core/block-editor").getBlocks)()}}),[]).blocks,c=(0,u.useRef)(l),p=(0,u.useRef)(t);return(0,u.useEffect)((function(){var e=(0,A.debounce)((function(){for(var t=[],s=0;s0)return r(e.innerBlocks,t[s].innerBlocks);if(JSON.stringify(e)!==JSON.stringify(t[s])){var a=t[s],o=i.parseFromString(e.attributes.content||"","text/html"),l=i.parseFromString((null==a?void 0:a.attributes.content)||"","text/html"),c=Array.from(o.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:a,addedLinks:p,removedLinks:d,changedLinks:f})}}}))};return r(e,t),n}(l,c.current);a.length>0&&(a.forEach((function(e){e.changedLinks.length>0&&n&&n(e),e.addedLinks.length>0&&i&&i(e),e.removedLinks.length>0&&r&&r(e)})),c.current=l)}),o);return e(t),function(){e.cancel()}}),[l,o,t,i,n,r]),null},K=function(e){var t=e.value,n=e.onChange,r=e.max,a=e.min,o=e.suffix,l=e.size,c=e.label,u=e.initialPosition,p=e.disabled,d=e.className;return(0,i.jsxs)("div",{className:"parsely-inputrange-control ".concat(d||""),children:[(0,i.jsx)(s.__experimentalHeading,{className:"parsely-inputrange-control__label",level:3,children:c}),(0,i.jsxs)("div",{className:"parsely-inputrange-control__controls",children:[(0,i.jsx)(s.__experimentalNumberControl,{disabled:p,value:t,suffix:(0,i.jsx)(s.__experimentalInputControlSuffixWrapper,{children:o}),size:null!=l?l:"__unstable-large",min:a,max:r,onChange:function(e){var t=parseInt(e,10);isNaN(t)||n(t)}}),(0,i.jsx)(s.RangeControl,{disabled:p,value:t,showTooltip:!1,initialPosition:u,onChange:function(e){n(e)},withInputField:!1,min:a,max:r})]})]})},Y=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function a(e){try{l(r.next(e))}catch(e){s(e)}}function o(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(a,o)}l((r=r.apply(e,t||[])).next())}))},Q=function(e,t){var n,r,i,s,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function o(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,o[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]

","\n\x3c!-- /wp:paragraph --\x3e");t&&g((0,G.parse)(n))}),[o]),(0,i.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,i.jsx)(s.KeyboardShortcuts,{shortcuts:{left:l,right:c,up:l,down:c}}),(0,i.jsx)("div",{className:"review-suggestion-post-title",children:null===(t=o.post_data)||void 0===t?void 0:t.title}),(0,i.jsxs)("div",{className:"review-suggestion-preview",children:[!(null===(n=o.post_data)||void 0===n?void 0:n.is_first_paragraph)&&(0,i.jsx)(Oe,{topOrBottom:"top"}),(0,i.jsx)(Ae,{block:v[0],link:o,useOriginalBlock:!0}),!(null===(r=o.post_data)||void 0===r?void 0:r.is_last_paragraph)&&(0,i.jsx)(Oe,{topOrBottom:"bottom"})]}),(0,i.jsx)(s.__experimentalDivider,{}),(0,i.jsx)(Re,{link:o}),(0,i.jsxs)("div",{className:"review-controls",children:[(0,i.jsx)(s.Tooltip,{shortcut:"←",text:(0,p.__)("Previous","wp-parsely"),children:(0,i.jsx)(s.Button,{disabled:!d,className:"wp-parsely-review-suggestion-previous",onClick:l,icon:Le,children:(0,p.__)("Previous","wp-parsely")})}),(0,i.jsx)("div",{className:"reviews-controls-middle",children:(0,i.jsx)(s.Button,{target:"_blank",href:(null===(a=o.post_data)||void 0===a?void 0:a.edit_link)+"&smart-link="+o.uid,variant:"secondary",children:(0,p.__)("Open in the Editor","wp-parsely")})}),(0,i.jsx)(s.Tooltip,{shortcut:"→",text:(0,p.__)("Next","wp-parsely"),children:(0,i.jsxs)(s.Button,{disabled:!f,onClick:c,className:"wp-parsely-review-suggestion-next",children:[(0,p.__)("Next","wp-parsely"),(0,i.jsx)(H,{icon:Ee})]})})]})]})},Be=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,a=void 0===r?"wp-parsely-icon":r;return(0,i.jsxs)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",className:a,width:n,height:n,viewBox:"0 0 24 24",fill:"none",children:[(0,i.jsx)(s.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,i.jsx)(s.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,i.jsx)(s.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"})]})},Me=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,d]);var h=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()},v=(0,i.jsxs)("span",{className:"smart-linking-menu-label",children:[(0,p.__)("NEW","wp-parsely"),(0,i.jsx)(Be,{})]}),g=[];n&&n.length>0&&g.push({name:"outbound",title:(0,p.__)("Outbound","wp-parsely")}),r&&r.length>0&&g.push({name:"inbound",title:(0,p.__)("Inbound","wp-parsely")});var y="outbound";return g=g.filter((function(e){return"outbound"===e.name&&r&&0===r.length&&(e.title=(0,p.__)("Outbound Smart Links","wp-parsely"),y="outbound"),"inbound"===e.name&&n&&0===n.length&&(e.title=(0,p.__)("Inbound Smart Links","wp-parsely"),y="inbound"),e})),(0,i.jsxs)("div",{className:"smart-linking-review-sidebar",ref:o,children:[(0,i.jsx)(s.KeyboardShortcuts,{shortcuts:{tab:function(){return h()},"shift+tab":function(){return h()}}}),(0,i.jsx)(s.TabPanel,{className:"smart-linking-review-sidebar-tabs",initialTabName:y,tabs:g,onSelect:function(e){"outbound"===e&&n&&n.length>0&&a(n[0]),"inbound"===e&&r&&r.length>0&&a(r[0])},children:function(e){return(0,i.jsxs)(i.Fragment,{children:["outbound"===e.name&&(0,i.jsx)(i.Fragment,{children:n&&0!==n.length?n.map((function(e,n){return(0,i.jsxs)(s.MenuItem,{ref:function(e){l.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 a(e)},children:[(0,i.jsx)("span",{className:"smart-linking-menu-item",children:e.text}),!e.applied&&v]},e.uid)})):(0,i.jsxs)(i.Fragment,{children:[" ",(0,p.__)("No outbound links found.","wp-parsely")]})}),"inbound"===e.name&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"review-sidebar-tip",children:(0,p.__)("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,i.jsx)(s.MenuItem,{ref:function(e){l.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 a(e)},children:(0,i.jsx)("span",{className:"smart-linking-menu-item",children:null===(o=e.post_data)||void 0===o?void 0:o.title})},e.uid)})):(0,i.jsxs)(i.Fragment,{children:[" ",(0,p.__)("No inbound links found.","wp-parsely")]})]})]})}})]})},Fe=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),Ve=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),Ge=function(e){var t,n,r,s,o=null===(t=e.link.match)||void 0===t?void 0:t.blockId,l=(0,a.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]),c=l.block,u=l.parents;return c?(0,i.jsxs)("div",{className:"review-suggestions-breadcrumbs",children:[u.map((function(e,t){var n;return(0,i.jsxs)("span",{children:[(0,i.jsx)("span",{className:"breadcrumbs-parent-block",children:null===(n=(0,G.getBlockType)(e.name))||void 0===n?void 0:n.title}),(0,i.jsx)("span",{className:"breadcrumbs-parent-separator",children:" / "})]},t)})),(0,i.jsxs)("span",{className:"breadcrumbs-current-block",children:[(0,i.jsx)("span",{className:"breadcrumbs-current-block-type",children:null===(n=(0,G.getBlockType)(c.name))||void 0===n?void 0:n.title}),(null===(s=null===(r=c.attributes)||void 0===r?void 0:r.metadata)||void 0===s?void 0:s.name)&&(0,i.jsx)("span",{className:"breadcrumbs-current-block-name",children:c.attributes.metadata.name})]})]}):(0,i.jsx)(i.Fragment,{})},He=function(e){var t,n=e.link,r=(0,u.useState)(n.href),o=r[0],l=r[1],c=(0,u.useState)(null===(t=n.destination)||void 0===t?void 0:t.post_type),d=c[0],f=c[1],h=(0,u.useRef)(null),v=(0,a.useDispatch)(ve).updateSmartLink;return(0,u.useEffect)((function(){n.destination?f(n.destination.post_type):(f((0,p.__)("External","wp-parsely")),Se.getInstance().getPostTypeByURL(n.href).then((function(e){e&&f(e.post_type),n.destination=e,v(n)})))}),[n,v]),(0,u.useEffect)((function(){var e=function(){if(h.current){var e=h.current.offsetWidth,t=Math.floor(e/8);l(function(e,t){var n=e.replace(/(^\w+:|^)\/\//,"").replace(/^www\./,"");if(!t||n.length<=t)return n;var r=n.split("/")[0],i=n.substring(r.length);t-=r.length;var s=Math.floor((t-3)/2),a=i.substring(0,s),o=i.substring(i.length-s);return"".concat(r).concat(a,"...").concat(o)}(n.href,t))}};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[n]),(0,i.jsx)(s.MenuItem,{ref:h,info:o,iconPosition:"left",icon:Te,shortcut:d,className:"block-editor-link-control__search-item wp-parsely-link-suggestion-link-details",children:n.title})},ze=function(e){var t=e.link,n=e.onNext,r=e.onPrevious,o=e.onAccept,l=e.onReject,c=e.onRemove,u=e.onSelectInEditor,d=e.hasPrevious,f=e.hasNext;if(t&&void 0!==t.post_data)return(0,i.jsx)(Ie,{link:t,onNext:n,onPrevious:r,onAccept:o,onReject:l,onRemove:c,onSelectInEditor:u,hasPrevious:d,hasNext:f});if(!(null==t?void 0:t.match))return(0,i.jsx)(i.Fragment,{children:(0,p.__)("This Smart Link does not have any matches in the current content.","wp-parsely")});var h=t.match.blockId,v=(0,a.select)("core/block-editor").getBlock(h),g=t.applied;return v?(0,i.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,i.jsx)(s.KeyboardShortcuts,{shortcuts:{left:r,right:n,up:r,down:n,a:function(){t&&!t.applied&&o()},r:function(){t&&(t.applied?c():l())}}}),(0,i.jsx)(Ge,{link:t}),(0,i.jsx)("div",{className:"review-suggestion-preview",children:(0,i.jsx)(Ae,{block:v,link:t})}),(0,i.jsx)(s.__experimentalDivider,{}),(0,i.jsx)(He,{link:t}),(0,i.jsxs)("div",{className:"review-controls",children:[(0,i.jsx)(s.Tooltip,{shortcut:"←",text:(0,p.__)("Previous","wp-parsely"),children:(0,i.jsx)(s.Button,{disabled:!d,className:"wp-parsely-review-suggestion-previous",onClick:r,icon:Le,children:(0,p.__)("Previous","wp-parsely")})}),(0,i.jsxs)("div",{className:"reviews-controls-middle",children:[!g&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.Tooltip,{shortcut:"R",text:(0,p.__)("Reject","wp-parsely"),children:(0,i.jsx)(s.Button,{className:"wp-parsely-review-suggestion-reject",icon:Fe,onClick:l,variant:"secondary",children:(0,p.__)("Reject","wp-parsely")})}),(0,i.jsx)(s.Tooltip,{shortcut:"A",text:(0,p.__)("Accept","wp-parsely"),children:(0,i.jsx)(s.Button,{className:"wp-parsely-review-suggestion-accept",icon:Ve,onClick:o,variant:"secondary",children:(0,p.__)("Accept","wp-parsely")})})]}),g&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.Tooltip,{shortcut:"R",text:(0,p.__)("Remove","wp-parsely"),children:(0,i.jsx)(s.Button,{className:"wp-parsely-review-suggestion-reject",icon:Fe,onClick:c,variant:"secondary",children:(0,p.__)("Remove","wp-parsely")})}),(0,i.jsx)(s.Button,{className:"wp-parsely-review-suggestion-accept",onClick:u,variant:"secondary",children:(0,p.__)("Select in Editor","wp-parsely")})]})]}),(0,i.jsx)(s.Tooltip,{shortcut:"→",text:(0,p.__)("Next","wp-parsely"),children:(0,i.jsxs)(s.Button,{disabled:!f,onClick:n,className:"wp-parsely-review-suggestion-next",children:[(0,p.__)("Next","wp-parsely"),(0,i.jsx)(H,{icon:Ee})]})})]})]}):(0,i.jsx)(i.Fragment,{children:(0,p.__)("No block is selected.","wp-parsely")})},Ue=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function a(e){try{l(r.next(e))}catch(e){s(e)}}function o(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(a,o)}l((r=r.apply(e,t||[])).next())}))},qe=function(e,t){var n,r,i,s,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function o(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,o[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&(o=a[0],(l=o.parentNode)&&(c=document.createTextNode(null!==(u=o.textContent)&&void 0!==u?u:""),l.replaceChild(c,o),U.updateBlockAttributes(n,{content:s.innerHTML}))),[4,L(t.uid)]):[2]):[2];case 1:return p.sent(),[2]}}))}))},N=(0,u.useCallback)((function(){h(!1),_().filter((function(e){return!e.applied})).length>0?c(!0):(q.unlockPostAutosaving("smart-linking-review-modal"),t())}),[_,t]),C=function(e){c(!1),e?(h(!1),j().then((function(){N()}))):h(!0)},A=function(){if(J(k)){var e=m.indexOf(k);if(!m[t=e+1])return;S(m[t])}else{var t;if(e=y.indexOf(k),!y[t=e+1])return;S(y[t])}},O=function(){if(J(k)){var e=m.indexOf(k);if(!m[t=e-1])return;S(m[t])}else{var t;if(e=y.indexOf(k),!y[t=e-1])return;S(y[t])}};return(0,u.useEffect)((function(){f?q.lockPostAutosaving("smart-linking-review-modal"):f&&0===g.length&&N()}),[f,t,g,N]),(0,u.useEffect)((function(){h(n)}),[n]),(0,i.jsxs)(i.Fragment,{children:[f&&(0,i.jsx)(s.Modal,{title:(0,p.__)("Review Smart Links","wp-parsely"),className:"wp-parsely-smart-linking-review-modal",onRequestClose:N,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,children:(0,i.jsxs)("div",{className:"smart-linking-modal-body",children:[(0,i.jsx)(De,{outboundLinks:y,inboundLinks:m,activeLink:k,setSelectedLink:S}),k&&(J(k)?(0,i.jsx)(Ie,{link:k,onNext:A,onPrevious:O,hasNext:m.indexOf(k)0}):(0,i.jsx)(ze,{link:k,hasNext:b().indexOf(k)0,onNext:A,onPrevious:O,onAccept:function(){return Ue(void 0,void 0,void 0,(function(){var e,t;return qe(this,(function(n){switch(n.label){case 0:return k.match?(r(k),[4,(i=k.match.blockId,s=k,Ue(void 0,void 0,void 0,(function(){var e,t;return qe(this,(function(n){switch(n.label){case 0:return(e=document.createElement("a")).href=s.href,e.title=s.title,e.setAttribute("data-smartlink",s.uid),(t=(0,a.select)("core/block-editor").getBlock(i))?(te(t,s,e),s.applied=!0,[4,T(s)]):[2];case 1:return n.sent(),[2]}}))})))]):[2];case 1:return n.sent(),0===w().length?(N(),[2]):(e=y.indexOf(k),y[t=e+1]?S(y[t]):S(y[0]),[2])}var i,s}))}))},onReject:function(){return Ue(void 0,void 0,void 0,(function(){var e,t;return qe(this,(function(n){switch(n.label){case 0:return e=y.indexOf(k),y[t=e+1]?S(y[t]):y[0]?S(y[0]):N(),[4,L(k.uid)];case 1:return n.sent(),[2]}}))}))},onRemove:function(){return Ue(void 0,void 0,void 0,(function(){var e,t,n,r;return qe(this,(function(i){switch(i.label){case 0:return k.match?(e=(0,a.select)("core/block-editor").getBlock(k.match.blockId))?(t=b(),n=t.indexOf(k),r=n-1,[4,E(e,k)]):[3,2]:[2];case 1:if(i.sent(),0===(t=b()).length&&m.length>0)return S(m[0]),[2];if(0===t.length&&0===m.length)return N(),[2];if(t[r])return S(t[r]),[2];S(t[0]),i.label=2;case 2:return[2]}}))}))},onSelectInEditor:function(){if(k.match){var e=(0,a.select)("core/block-editor").getBlock(k.match.blockId);if(e){U.selectBlock(e.clientId);var t=document.querySelector('[data-block="'.concat(e.clientId,'"]'));t&&pe(t,k.uid),N()}}}}))]})}),l&&(0,i.jsxs)(s.Modal,{title:(0,p.__)("Review Smart Links","wp-parsely"),onRequestClose:function(){return C(!1)},className:"wp-parsely-smart-linking-close-dialog",children:[(0,p.__)("Are you sure you want to close? All un-accepted smart links will not be added.","wp-parsely"),(0,i.jsxs)("div",{className:"smart-linking-close-dialog-actions",children:[(0,i.jsx)(s.Button,{variant:"secondary",onClick:function(){return C(!1)},children:(0,p.__)("Go Back","wp-parsely")}),(0,i.jsx)(s.Button,{variant:"primary",onClick:function(){return C(!0)},children:(0,p.__)("Close","wp-parsely")})]})]})]})})),We=function(){return We=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&k("success",/* translators: %d: number of smart links applied */ /* translators: %d: number of smart links applied */ -(0,p.sprintf)((0,p.__)("%s smart links successfully applied.","wp-parsely"),m),{type:"snackbar"}):w(0)}),[_]),(0,u.useEffect)((function(){if(!(Object.keys(I).length>0)){var e={maxLinksPerPost:c.SmartLinking.MaxLinks};ue(e)}}),[ue,c]);var xe=(0,a.useSelect)((function(e){var t=e("core/block-editor"),r=t.getSelectedBlock,i=t.getBlock,s=t.getBlocks,a=e("core/editor"),o=a.getEditedPostContent,l=a.getCurrentPostAttribute;return{allBlocks:s(),selectedBlock:n?i(n):r(),postContent:o(),postPermalink:l("link")}}),[n]),ke=xe.allBlocks,Te=xe.selectedBlock,Le=xe.postContent,Ee=xe.postPermalink,Ne=function(e){return $e(void 0,void 0,void 0,(function(){var t,n,r,i,s;return Ke(this,(function(a){switch(a.label){case 0:t=[],a.label=1;case 1:return a.trys.push([1,4,,9]),[4,pe((n=E||!Te)?ce.All:ce.Selected)];case 2:return a.sent(),o=Ee.replace(/^https?:\/\//i,""),r=["http://"+o,"https://"+o],i=function(e){return e.map((function(e){return e.href}))}(V),r.push.apply(r,i),[4,Se.getInstance().generateSmartLinks(Te&&!n?(0,G.getBlockContent)(Te):Le,R,r)];case 3:return t=a.sent(),[3,9];case 4:if((s=a.sent()).code&&s.code===B.ParselyAborted)throw s.numRetries=3-e,s;return e>0&&s.retryFetch?(console.error(s),[4,fe(!0)]):[3,8];case 5:return a.sent(),[4,he()];case 6:return a.sent(),[4,Ne(e-1)];case 7:return[2,a.sent()];case 8:throw s;case 9:return[2,t]}var o}))}))},Ce=function(){for(var e=[],t=0;t[type="button"]').forEach((function(e){e.setAttribute("disabled","disabled")}))},Re=function(){document.querySelectorAll('.edit-post-header__settings>[type="button"]').forEach((function(e){e.removeAttribute("disabled")})),q.unlockPostSaving("wp-parsely-block-overlay")};return(0,i.jsxs)("div",{className:"wp-parsely-smart-linking",children:[(0,i.jsx)($,{isDetectingEnabled:!L,onLinkRemove:function(e){!function(e){Y(this,void 0,void 0,(function(){var t,n,r;return Q(this,(function(i){switch(i.label){case 0:return[4,oe((0,G.getBlockContent)(e),e.clientId)];case 1:return t=i.sent(),n=t.missingSmartLinks,r=t.didAnyFixes,n.forEach((function(e){(0,a.dispatch)(ve).removeSmartLink(e.uid)})),[2,r]}}))}))}(e.block)}}),(0,i.jsxs)(s.PanelRow,{className:t,children:[(0,i.jsxs)("div",{className:"smart-linking-text",children:[(0,p.__)("Automatically insert links to your most relevant, top performing content.","wp-parsely"),(0,i.jsxs)(s.Button,{href:"https://docs.parse.ly/plugin-content-helper/#h-smart-linking-beta",target:"_blank",variant:"link",children:[(0,p.__)("Learn more about Parse.ly AI","wp-parsely"),(0,i.jsx)(H,{icon:z,size:18,className:"parsely-external-link-icon"})]})]}),C&&(0,i.jsx)(s.Notice,{status:"info",onRemove:function(){return ee(null)},className:"wp-parsely-content-helper-error",children:C.Message()}),_&&m>0&&(0,i.jsx)(s.Notice,{status:"success",onRemove:function(){return x(!1)},className:"wp-parsely-smart-linking-suggested-links",children:(0,p.sprintf)(/* translators: 1 - number of smart links generated */ /* translators: 1 - number of smart links generated */ -(0,p.__)("Successfully added %s smart links.","wp-parsely"),m>0?m:O.length)}),(0,i.jsx)(ye,{disabled:T,selectedBlock:null==Te?void 0:Te.clientId,onSettingChange:function(e,t){var n;g({SmartLinking:We(We({},c.SmartLinking),(n={},n[e]=t,n))}),"MaxLinks"===e&&de(t)}}),(0,i.jsx)("div",{className:"smart-linking-generate",children:(0,i.jsx)(s.Button,{onClick:function(){return $e(void 0,void 0,void 0,(function(){var e,t,n,r,i,s,a,l,c,u;return Ke(this,(function(d){switch(d.label){case 0:return[4,J(!0)];case 1:return d.sent(),[4,we()];case 2:return d.sent(),[4,ee(null)];case 3:return d.sent(),x(!1),v.trackEvent("smart_linking_generate_pressed",{is_full_content:E,selected_block:null!==(l=null==Te?void 0:Te.name)&&void 0!==l?l:"none",context:o}),e=ke.some((function(e){return"core/freeform"===e.name})),"core/freeform"===(null==Te?void 0:Te.name)&&!E||e&&E?(k("error",(0,p.__)("Smart Linking is not supported for the Freeform block.","wp-parsely"),{type:"snackbar"}),J(!1),[2]):[4,Ce(E?"all":null==Te?void 0:Te.clientId)];case 4:d.sent(),t=setTimeout((function(){var e;J(!1),v.trackEvent("smart_linking_generate_timeout",{is_full_content:E,selected_block:null!==(e=null==Te?void 0:Te.name)&&void 0!==e?e:"none",context:o}),Ae(E?"all":null==Te?void 0:Te.clientId)}),18e4),n=M,d.label=5;case 5:return d.trys.push([5,8,10,15]),[4,Ne(3)];case 6:return r=d.sent(),[4,(f=r,$e(void 0,void 0,void 0,(function(){var e;return Ke(this,(function(t){switch(t.label){case 0:return f=f.filter((function(e){return!V.some((function(t){return t.uid===e.uid&&t.applied}))})),e=Ee.replace(/^https?:\/\//,"").replace(/\/+$/,""),f=(f=f.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!V.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)}))})),f=(f=ie(E?ke:[Te],f,{}).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!V.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,te(f)];case 1:return t.sent(),[2]}}))})))];case 7:return d.sent(),be(!0),[3,15];case 8:return i=d.sent(),s=new W(null!==(c=i.message)&&void 0!==c?c:"An unknown error has occurred.",null!==(u=i.code)&&void 0!==u?u:B.UnknownError),a=s.message,i.code&&i.code===B.ParselyAborted&&(a=(0,p.sprintf)(/* translators: %d: number of retry attempts, %s: attempt plural */ /* translators: %d: number of retry attempts, %s: attempt plural */ -(0,p.__)("The Smart Linking process was cancelled after %1$d %2$s.","wp-parsely"),i.numRetries,(0,p._n)("attempt","attempts",i.numRetries,"wp-parsely")),i.message=a),console.error(i),[4,ee(i)];case 9:return d.sent(),k("error",a,{type:"snackbar"}),[3,15];case 10:return[4,J(!1)];case 11:return d.sent(),[4,pe(n)];case 12:return d.sent(),[4,fe(!1)];case 13:return d.sent(),[4,Ae(E?"all":null==Te?void 0:Te.clientId)];case 14:return d.sent(),clearTimeout(t),[7];case 15:return[2]}var f}))}))},variant:"primary",isBusy:T,disabled:T,children:D?(0,p.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,p.__)("Retrying… Attempt %1$d of %2$d","wp-parsely"),F,3):T?(0,p.__)("Generating Smart Links…","wp-parsely"):(0,p.__)("Add Smart Links","wp-parsely")})}),(Z.length>0||U.length>0)&&(0,i.jsx)("div",{className:"smart-linking-manage",children:(0,i.jsx)(s.Button,{onClick:function(){return $e(void 0,void 0,void 0,(function(){var e;return Ke(this,(function(t){switch(t.label){case 0:return[4,le()];case 1:return t.sent(),e=se(),[4,te(e)];case 2:return t.sent(),be(!0),[2]}}))}))},variant:"secondary",disabled:T,children:(0,p.__)("Review Smart Links","wp-parsely")})})]}),L&&(0,i.jsx)(Ze,{isOpen:L,onAppliedLink:function(){w((function(e){return e+1}))},onClose:function(){x(!0),be(!1)}})]})},Xe=function(){return Xe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0)&&(t(),e())}))}))]}))},new((n=void 0)||(n=Promise))((function(i,s){function a(e){try{l(r.next(e))}catch(e){s(e)}}function o(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(a,o)}l((r=r.apply(e,t||[])).next())}));var e,t,n,r}().then((function(){var t=document.querySelector(".wp-block-post-content");pe(t,e)}))}))},lt=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{d:"M7 11.5h10V13H7z"})}),ct=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{d:"M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"})}),ut=function(e){var t=e.title,n=e.icon,r=e.subtitle,a=e.level,o=void 0===a?2:a,l=e.children,c=e.controls,u=e.onClick,d=e.isOpen,f=e.isLoading,h=e.dropdownChildren;return(0,i.jsxs)("div",{className:"performance-stat-panel",children:[(0,i.jsxs)(s.__experimentalHStack,{className:"panel-header level-"+o,children:[(0,i.jsx)(s.__experimentalHeading,{level:o,children:t}),r&&!d&&(0,i.jsx)("span",{className:"panel-subtitle",children:r}),c&&!h&&(0,i.jsx)(s.DropdownMenu,{icon:n,label:(0,p.__)("Settings","wp-parsely"),className:"panel-settings-button",controls:c}),h&&(0,i.jsx)(s.DropdownMenu,{icon:n,label:(0,p.__)("Settings","wp-parsely"),className:"panel-settings-button",children:h}),n&&!h&&!c&&(0,i.jsx)(s.Button,{icon:n,className:"panel-settings-button",isPressed:d,onClick:u})]}),(0,i.jsx)("div",{className:"panel-body",children:f?(0,i.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,i.jsx)(s.Spinner,{})}):l})]})};function pt(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(),a="",o=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/o&&(u=i>10?1:2),u=parseFloat(i.toFixed(2))===parseFloat(i.toFixed(0))?0:u,s=i.toFixed(u),a=l}o=c})),s+n+a}var dt=function(e){var n=e.data,r=e.isLoading,a=(0,u.useState)(t.Views),o=a[0],l=a[1],c=(0,u.useState)(!1),d=c[0],f=c[1];r||delete n.referrers.types.totals;var h=function(e){switch(e){case"social":return(0,p.__)("Social","wp-parsely");case"search":return(0,p.__)("Search","wp-parsely");case"other":return(0,p.__)("Other","wp-parsely");case"internal":return(0,p.__)("Internal","wp-parsely");case"direct":return(0,p.__)("Direct","wp-parsely")}return e},v=(0,p.sprintf)((0,p.__)("By %s","wp-parsely"),N(o)); -/* translators: %s: metric description */return(0,i.jsxs)(ut,{title:(0,p.__)("Categories","wp-parsely"),level:3,subtitle:v,isOpen:d,onClick:function(){return f(!d)},children:[d&&(0,i.jsx)("div",{className:"panel-settings",children:(0,i.jsx)(s.SelectControl,{value:o,prefix:(0,p.__)("By: ","wp-parsely"),onChange:function(e){L(e,t)&&l(e)},children:Object.values(t).map((function(e){return(0,i.jsxs)("option",{value:e,disabled:"avg_engaged"===e,children:[N(e),"avg_engaged"===e&&(0,p.__)(" (coming soon)","wp-parsely")]},e)}))})}),r?(0,i.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,i.jsx)(s.Spinner,{})}):(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:"multi-percentage-bar",children:Object.entries(n.referrers.types).map((function(e){var t=e[0],n=e[1],r=(0,p.sprintf)(/* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ /* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ +!function(){"use strict";var e={20:function(e,t,n){var r=n(609),i=Symbol.for("react.element"),s=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,o=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)a.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:o.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({},{_:function(){return Kn}});var e,t,r,i=n(848),s=window.wp.components,a=window.wp.data,o=window.wp.domReady,l=n.n(o),c=window.wp.editPost,u=window.wp.element,p=window.wp.i18n,d=window.wp.primitives,f=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{fillRule:"evenodd",d:"M11.25 5h1.5v15h-1.5V5zM6 10h1.5v10H6V10zm12 4h-1.5v6H18v-6z",clipRule:"evenodd"})}),h=window.wp.plugins,v=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,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function o(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,o[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(),g=(v.trackEvent,function(){return(0,i.jsx)(s.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,i.jsx)(s.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"})})}),y=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,a=void 0===r?"wp-parsely-icon":r;return(0,i.jsxs)(s.SVG,{className:a,height:n,viewBox:"0 0 60 65",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)(s.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,i.jsx)(s.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,i.jsx)(s.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,i.jsx)(s.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"})]})},m=function(){return m=Object.assign||function(e){for(var t,n=1,r=arguments.length;nhere.',"wp-parsely"):s.code===M.ParselySuggestionsApiOpenAiError||s.code===M.ParselySuggestionsApiOpenAiUnavailable?s.message=(0,p.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):s.code===M.HttpRequestFailed&&s.message.includes("cURL error 28")?s.message=(0,p.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):s.code===M.ParselySuggestionsApiSchemaError?s.message=(0,p.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):s.code===M.ParselySuggestionsApiNoData?s.message=(0,p.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):s.code===M.ParselySuggestionsApiOpenAiSchema?s.message=(0,p.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):s.code===M.ParselySuggestionsApiAuthUnavailable&&(s.message=(0,p.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),s}return W(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[M.PluginCredentialsNotSetMessageDetected,M.PluginSettingsSiteIdNotSet,M.PluginSettingsApiSecretNotSet].includes(this.code)?F(e):(this.code===M.FetchError&&(this.hint=this.Hint((0,p.__)("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!==M.ParselyApiForbidden&&this.code!==M.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,p.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===M.HttpRequestFailed&&(this.hint=this.Hint((0,p.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,i.jsx)(D,{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,p.__)("Hint:","wp-parsely")," ").concat(e,"

")},t}(Error),K=function(e){var t=e.isDetectingEnabled,n=e.onLinkChange,r=e.onLinkRemove,i=e.onLinkAdd,s=e.debounceValue,o=void 0===s?500:s,l=(0,a.useSelect)((function(e){return{blocks:(0,e("core/block-editor").getBlocks)()}}),[]).blocks,c=(0,u.useRef)(l),p=(0,u.useRef)(t);return(0,u.useEffect)((function(){var e=(0,O.debounce)((function(){for(var t=[],s=0;s0)return r(e.innerBlocks,t[s].innerBlocks);if(JSON.stringify(e)!==JSON.stringify(t[s])){var a=t[s],o=i.parseFromString(e.attributes.content||"","text/html"),l=i.parseFromString((null==a?void 0:a.attributes.content)||"","text/html"),c=Array.from(o.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:a,addedLinks:p,removedLinks:d,changedLinks:f})}}}))};return r(e,t),n}(l,c.current);a.length>0&&(a.forEach((function(e){e.changedLinks.length>0&&n&&n(e),e.addedLinks.length>0&&i&&i(e),e.removedLinks.length>0&&r&&r(e)})),c.current=l)}),o);return e(t),function(){e.cancel()}}),[l,o,t,i,n,r]),null},Y=function(e){var t=e.value,n=e.onChange,r=e.max,a=e.min,o=e.suffix,l=e.size,c=e.label,u=e.initialPosition,p=e.disabled,d=e.className;return(0,i.jsxs)("div",{className:"parsely-inputrange-control ".concat(d||""),children:[(0,i.jsx)(s.__experimentalHeading,{className:"parsely-inputrange-control__label",level:3,children:c}),(0,i.jsxs)("div",{className:"parsely-inputrange-control__controls",children:[(0,i.jsx)(s.__experimentalNumberControl,{disabled:p,value:t,suffix:(0,i.jsx)(s.__experimentalInputControlSuffixWrapper,{children:o}),size:null!=l?l:"__unstable-large",min:a,max:r,onChange:function(e){var t=parseInt(e,10);isNaN(t)||n(t)}}),(0,i.jsx)(s.RangeControl,{disabled:p,value:t,showTooltip:!1,initialPosition:u,onChange:function(e){n(e)},withInputField:!1,min:a,max:r})]})]})},J=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function a(e){try{l(r.next(e))}catch(e){s(e)}}function o(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(a,o)}l((r=r.apply(e,t||[])).next())}))},Q=function(e,t){var n,r,i,s,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function o(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,o[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]

","\n\x3c!-- /wp:paragraph --\x3e");t&&g((0,H.parse)(n))}),[o]),(0,i.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,i.jsx)(s.KeyboardShortcuts,{shortcuts:{left:l,right:c,up:l,down:c}}),(0,i.jsx)("div",{className:"review-suggestion-post-title",children:null===(t=o.post_data)||void 0===t?void 0:t.title}),(0,i.jsxs)("div",{className:"review-suggestion-preview",children:[!(null===(n=o.post_data)||void 0===n?void 0:n.is_first_paragraph)&&(0,i.jsx)(Re,{topOrBottom:"top"}),(0,i.jsx)(Oe,{block:v[0],link:o,useOriginalBlock:!0}),!(null===(r=o.post_data)||void 0===r?void 0:r.is_last_paragraph)&&(0,i.jsx)(Re,{topOrBottom:"bottom"})]}),(0,i.jsx)(s.__experimentalDivider,{}),(0,i.jsx)(Ie,{link:o}),(0,i.jsxs)("div",{className:"review-controls",children:[(0,i.jsx)(s.Tooltip,{shortcut:"←",text:(0,p.__)("Previous","wp-parsely"),children:(0,i.jsx)(s.Button,{disabled:!d,className:"wp-parsely-review-suggestion-previous",onClick:l,icon:Ee,children:(0,p.__)("Previous","wp-parsely")})}),(0,i.jsx)("div",{className:"reviews-controls-middle",children:(0,i.jsx)(s.Button,{target:"_blank",href:(null===(a=o.post_data)||void 0===a?void 0:a.edit_link)+"&smart-link="+o.uid,variant:"secondary",children:(0,p.__)("Open in the Editor","wp-parsely")})}),(0,i.jsx)(s.Tooltip,{shortcut:"→",text:(0,p.__)("Next","wp-parsely"),children:(0,i.jsxs)(s.Button,{disabled:!f,onClick:c,className:"wp-parsely-review-suggestion-next",children:[(0,p.__)("Next","wp-parsely"),(0,i.jsx)(z,{icon:Ne})]})})]})]})},Me=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,a=void 0===r?"wp-parsely-icon":r;return(0,i.jsxs)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",className:a,width:n,height:n,viewBox:"0 0 24 24",fill:"none",children:[(0,i.jsx)(s.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,i.jsx)(s.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,i.jsx)(s.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"})]})},De=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,d]);var h=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()},v=(0,i.jsxs)("span",{className:"smart-linking-menu-label",children:[(0,p.__)("NEW","wp-parsely"),(0,i.jsx)(Me,{})]}),g=[];n&&n.length>0&&g.push({name:"outbound",title:(0,p.__)("Outbound","wp-parsely")}),r&&r.length>0&&g.push({name:"inbound",title:(0,p.__)("Inbound","wp-parsely")});var y="outbound";return g=g.filter((function(e){return"outbound"===e.name&&r&&0===r.length&&(e.title=(0,p.__)("Outbound Smart Links","wp-parsely"),y="outbound"),"inbound"===e.name&&n&&0===n.length&&(e.title=(0,p.__)("Inbound Smart Links","wp-parsely"),y="inbound"),e})),(0,i.jsxs)("div",{className:"smart-linking-review-sidebar",ref:o,children:[(0,i.jsx)(s.KeyboardShortcuts,{shortcuts:{tab:function(){return h()},"shift+tab":function(){return h()}}}),(0,i.jsx)(s.TabPanel,{className:"smart-linking-review-sidebar-tabs",initialTabName:y,tabs:g,onSelect:function(e){"outbound"===e&&n&&n.length>0&&a(n[0]),"inbound"===e&&r&&r.length>0&&a(r[0])},children:function(e){return(0,i.jsxs)(i.Fragment,{children:["outbound"===e.name&&(0,i.jsx)(i.Fragment,{children:n&&0!==n.length?n.map((function(e,n){return(0,i.jsxs)(s.MenuItem,{ref:function(e){l.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 a(e)},children:[(0,i.jsx)("span",{className:"smart-linking-menu-item",children:e.text}),!e.applied&&v]},e.uid)})):(0,i.jsxs)(i.Fragment,{children:[" ",(0,p.__)("No outbound links found.","wp-parsely")]})}),"inbound"===e.name&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"review-sidebar-tip",children:(0,p.__)("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,i.jsx)(s.MenuItem,{ref:function(e){l.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 a(e)},children:(0,i.jsx)("span",{className:"smart-linking-menu-item",children:null===(o=e.post_data)||void 0===o?void 0:o.title})},e.uid)})):(0,i.jsxs)(i.Fragment,{children:[" ",(0,p.__)("No inbound links found.","wp-parsely")]})]})]})}})]})},Ve=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),Ge=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),He=function(e){var t,n,r,s,o=null===(t=e.link.match)||void 0===t?void 0:t.blockId,l=(0,a.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]),c=l.block,u=l.parents;return c?(0,i.jsxs)("div",{className:"review-suggestions-breadcrumbs",children:[u.map((function(e,t){var n;return(0,i.jsxs)("span",{children:[(0,i.jsx)("span",{className:"breadcrumbs-parent-block",children:null===(n=(0,H.getBlockType)(e.name))||void 0===n?void 0:n.title}),(0,i.jsx)("span",{className:"breadcrumbs-parent-separator",children:" / "})]},t)})),(0,i.jsxs)("span",{className:"breadcrumbs-current-block",children:[(0,i.jsx)("span",{className:"breadcrumbs-current-block-type",children:null===(n=(0,H.getBlockType)(c.name))||void 0===n?void 0:n.title}),(null===(s=null===(r=c.attributes)||void 0===r?void 0:r.metadata)||void 0===s?void 0:s.name)&&(0,i.jsx)("span",{className:"breadcrumbs-current-block-name",children:c.attributes.metadata.name})]})]}):(0,i.jsx)(i.Fragment,{})},ze=function(e){var t,n=e.link,r=(0,u.useState)(n.href),o=r[0],l=r[1],c=(0,u.useState)(null===(t=n.destination)||void 0===t?void 0:t.post_type),d=c[0],f=c[1],h=(0,u.useRef)(null),v=(0,a.useDispatch)(ge).updateSmartLink;return(0,u.useEffect)((function(){n.destination?f(n.destination.post_type):(f((0,p.__)("External","wp-parsely")),Pe.getInstance().getPostTypeByURL(n.href).then((function(e){e&&f(e.post_type),n.destination=e,v(n)})))}),[n,v]),(0,u.useEffect)((function(){var e=function(){if(h.current){var e=h.current.offsetWidth,t=Math.floor(e/8);l(function(e,t){var n=e.replace(/(^\w+:|^)\/\//,"").replace(/^www\./,"");if(!t||n.length<=t)return n;var r=n.split("/")[0],i=n.substring(r.length);t-=r.length;var s=Math.floor((t-3)/2),a=i.substring(0,s),o=i.substring(i.length-s);return"".concat(r).concat(a,"...").concat(o)}(n.href,t))}};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[n]),(0,i.jsx)(s.MenuItem,{ref:h,info:o,iconPosition:"left",icon:Le,shortcut:d,className:"block-editor-link-control__search-item wp-parsely-link-suggestion-link-details",children:n.title})},Ue=function(e){var t=e.link,n=e.onNext,r=e.onPrevious,o=e.onAccept,l=e.onReject,c=e.onRemove,u=e.onSelectInEditor,d=e.hasPrevious,f=e.hasNext;if(t&&void 0!==t.post_data)return(0,i.jsx)(Be,{link:t,onNext:n,onPrevious:r,onAccept:o,onReject:l,onRemove:c,onSelectInEditor:u,hasPrevious:d,hasNext:f});if(!(null==t?void 0:t.match))return(0,i.jsx)(i.Fragment,{children:(0,p.__)("This Smart Link does not have any matches in the current content.","wp-parsely")});var h=t.match.blockId,v=(0,a.select)("core/block-editor").getBlock(h),g=t.applied;return v?(0,i.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,i.jsx)(s.KeyboardShortcuts,{shortcuts:{left:r,right:n,up:r,down:n,a:function(){t&&!t.applied&&o()},r:function(){t&&(t.applied?c():l())}}}),(0,i.jsx)(He,{link:t}),(0,i.jsx)("div",{className:"review-suggestion-preview",children:(0,i.jsx)(Oe,{block:v,link:t})}),(0,i.jsx)(s.__experimentalDivider,{}),(0,i.jsx)(ze,{link:t}),(0,i.jsxs)("div",{className:"review-controls",children:[(0,i.jsx)(s.Tooltip,{shortcut:"←",text:(0,p.__)("Previous","wp-parsely"),children:(0,i.jsx)(s.Button,{disabled:!d,className:"wp-parsely-review-suggestion-previous",onClick:r,icon:Ee,children:(0,p.__)("Previous","wp-parsely")})}),(0,i.jsxs)("div",{className:"reviews-controls-middle",children:[!g&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.Tooltip,{shortcut:"R",text:(0,p.__)("Reject","wp-parsely"),children:(0,i.jsx)(s.Button,{className:"wp-parsely-review-suggestion-reject",icon:Ve,onClick:l,variant:"secondary",children:(0,p.__)("Reject","wp-parsely")})}),(0,i.jsx)(s.Tooltip,{shortcut:"A",text:(0,p.__)("Accept","wp-parsely"),children:(0,i.jsx)(s.Button,{className:"wp-parsely-review-suggestion-accept",icon:Ge,onClick:o,variant:"secondary",children:(0,p.__)("Accept","wp-parsely")})})]}),g&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.Tooltip,{shortcut:"R",text:(0,p.__)("Remove","wp-parsely"),children:(0,i.jsx)(s.Button,{className:"wp-parsely-review-suggestion-reject",icon:Ve,onClick:c,variant:"secondary",children:(0,p.__)("Remove","wp-parsely")})}),(0,i.jsx)(s.Button,{className:"wp-parsely-review-suggestion-accept",onClick:u,variant:"secondary",children:(0,p.__)("Select in Editor","wp-parsely")})]})]}),(0,i.jsx)(s.Tooltip,{shortcut:"→",text:(0,p.__)("Next","wp-parsely"),children:(0,i.jsxs)(s.Button,{disabled:!f,onClick:n,className:"wp-parsely-review-suggestion-next",children:[(0,p.__)("Next","wp-parsely"),(0,i.jsx)(z,{icon:Ne})]})})]})]}):(0,i.jsx)(i.Fragment,{children:(0,p.__)("No block is selected.","wp-parsely")})},qe=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function a(e){try{l(r.next(e))}catch(e){s(e)}}function o(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(a,o)}l((r=r.apply(e,t||[])).next())}))},Ze=function(e,t){var n,r,i,s,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function o(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,o[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&(o=a[0],(l=o.parentNode)&&(c=document.createTextNode(null!==(u=o.textContent)&&void 0!==u?u:""),l.replaceChild(c,o),q.updateBlockAttributes(n,{content:s.innerHTML}))),[4,L(t.uid)]):[2]):[2];case 1:return p.sent(),[2]}}))}))},N=(0,u.useCallback)((function(){h(!1),_().filter((function(e){return!e.applied})).length>0?c(!0):(Z.unlockPostAutosaving("smart-linking-review-modal"),t())}),[_,t]),C=function(e){c(!1),e?(h(!1),j().then((function(){N()}))):h(!0)},A=function(){if(ee(k)){var e=m.indexOf(k);if(!m[t=e+1])return;S(m[t])}else{var t;if(e=y.indexOf(k),!y[t=e+1])return;S(y[t])}},O=function(){if(ee(k)){var e=m.indexOf(k);if(!m[t=e-1])return;S(m[t])}else{var t;if(e=y.indexOf(k),!y[t=e-1])return;S(y[t])}};return(0,u.useEffect)((function(){f?Z.lockPostAutosaving("smart-linking-review-modal"):f&&0===g.length&&N()}),[f,t,g,N]),(0,u.useEffect)((function(){h(n)}),[n]),(0,i.jsxs)(i.Fragment,{children:[f&&(0,i.jsx)(s.Modal,{title:(0,p.__)("Review Smart Links","wp-parsely"),className:"wp-parsely-smart-linking-review-modal",onRequestClose:N,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,children:(0,i.jsxs)("div",{className:"smart-linking-modal-body",children:[(0,i.jsx)(Fe,{outboundLinks:y,inboundLinks:m,activeLink:k,setSelectedLink:S}),k&&(ee(k)?(0,i.jsx)(Be,{link:k,onNext:A,onPrevious:O,hasNext:m.indexOf(k)0}):(0,i.jsx)(Ue,{link:k,hasNext:b().indexOf(k)0,onNext:A,onPrevious:O,onAccept:function(){return qe(void 0,void 0,void 0,(function(){var e,t;return Ze(this,(function(n){switch(n.label){case 0:return k.match?(r(k),[4,(i=k.match.blockId,s=k,qe(void 0,void 0,void 0,(function(){var e,t;return Ze(this,(function(n){switch(n.label){case 0:return(e=document.createElement("a")).href=s.href,e.title=s.title,e.setAttribute("data-smartlink",s.uid),(t=(0,a.select)("core/block-editor").getBlock(i))?(ne(t,s,e),s.applied=!0,[4,T(s)]):[2];case 1:return n.sent(),[2]}}))})))]):[2];case 1:return n.sent(),0===w().length?(N(),[2]):(e=y.indexOf(k),y[t=e+1]?S(y[t]):S(y[0]),[2])}var i,s}))}))},onReject:function(){return qe(void 0,void 0,void 0,(function(){var e,t;return Ze(this,(function(n){switch(n.label){case 0:return e=y.indexOf(k),y[t=e+1]?S(y[t]):y[0]?S(y[0]):N(),[4,L(k.uid)];case 1:return n.sent(),[2]}}))}))},onRemove:function(){return qe(void 0,void 0,void 0,(function(){var e,t,n,r;return Ze(this,(function(i){switch(i.label){case 0:return k.match?(e=(0,a.select)("core/block-editor").getBlock(k.match.blockId))?(t=b(),n=t.indexOf(k),r=n-1,[4,E(e,k)]):[3,2]:[2];case 1:if(i.sent(),0===(t=b()).length&&m.length>0)return S(m[0]),[2];if(0===t.length&&0===m.length)return N(),[2];if(t[r])return S(t[r]),[2];S(t[0]),i.label=2;case 2:return[2]}}))}))},onSelectInEditor:function(){if(k.match){var e=(0,a.select)("core/block-editor").getBlock(k.match.blockId);if(e){q.selectBlock(e.clientId);var t=document.querySelector('[data-block="'.concat(e.clientId,'"]'));t&&de(t,k.uid),N()}}}}))]})}),l&&(0,i.jsxs)(s.Modal,{title:(0,p.__)("Review Smart Links","wp-parsely"),onRequestClose:function(){return C(!1)},className:"wp-parsely-smart-linking-close-dialog",children:[(0,p.__)("Are you sure you want to close? All un-accepted smart links will not be added.","wp-parsely"),(0,i.jsxs)("div",{className:"smart-linking-close-dialog-actions",children:[(0,i.jsx)(s.Button,{variant:"secondary",onClick:function(){return C(!1)},children:(0,p.__)("Go Back","wp-parsely")}),(0,i.jsx)(s.Button,{variant:"primary",onClick:function(){return C(!0)},children:(0,p.__)("Close","wp-parsely")})]})]})]})})),$e=function(){return $e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&S("success",/* translators: %d: number of smart links applied */ /* translators: %d: number of smart links applied */ +(0,p.sprintf)((0,p.__)("%s smart links successfully applied.","wp-parsely"),w),{type:"snackbar"}):b(0)}),[x]),(0,u.useEffect)((function(){if(!(Object.keys(B).length>0)){var e={maxLinksPerPost:d.SmartLinking.MaxLinks};pe(e)}}),[pe,d]);var ke=(0,a.useSelect)((function(e){var t=e("core/block-editor"),r=t.getSelectedBlock,i=t.getBlock,s=t.getBlocks,a=e("core/editor"),o=a.getEditedPostContent,l=a.getCurrentPostAttribute;return{allBlocks:s(),selectedBlock:n?i(n):r(),postContent:o(),postPermalink:l("link")}}),[n]),Se=ke.allBlocks,Le=ke.selectedBlock,Ee=ke.postContent,Ne=ke.postPermalink,Ce=function(e){return Ke(void 0,void 0,void 0,(function(){var t,n,r,i,s;return Ye(this,(function(a){switch(a.label){case 0:t=[],a.label=1;case 1:return a.trys.push([1,4,,9]),[4,de((n=N||!Le)?ue.All:ue.Selected)];case 2:return a.sent(),o=Ne.replace(/^https?:\/\//i,""),r=["http://"+o,"https://"+o],i=function(e){return e.map((function(e){return e.href}))}(G),r.push.apply(r,i),[4,Pe.getInstance().generateSmartLinks(Le&&!n?(0,H.getBlockContent)(Le):Ee,I,r)];case 3:return t=a.sent(),[3,9];case 4:if((s=a.sent()).code&&s.code===M.ParselyAborted)throw s.numRetries=3-e,s;return e>0&&s.retryFetch?(console.error(s),[4,he(!0)]):[3,8];case 5:return a.sent(),[4,ve()];case 6:return a.sent(),[4,Ce(e-1)];case 7:return[2,a.sent()];case 8:throw s;case 9:return[2,t]}var o}))}))},Ae=function(){for(var e=[],t=0;t[type="button"]').forEach((function(e){e.setAttribute("disabled","disabled")}))},Ie=function(){document.querySelectorAll('.edit-post-header__settings>[type="button"]').forEach((function(e){e.removeAttribute("disabled")})),Z.unlockPostSaving("wp-parsely-block-overlay")};return(0,i.jsxs)("div",{className:"wp-parsely-smart-linking",children:[(0,i.jsx)(K,{isDetectingEnabled:!E,onLinkRemove:function(e){!function(e){J(this,void 0,void 0,(function(){var t,n,r;return Q(this,(function(i){switch(i.label){case 0:return[4,le((0,H.getBlockContent)(e),e.clientId)];case 1:return t=i.sent(),n=t.missingSmartLinks,r=t.didAnyFixes,n.forEach((function(e){(0,a.dispatch)(ge).removeSmartLink(e.uid)})),[2,r]}}))}))}(e.block)}}),(0,i.jsxs)(s.PanelRow,{className:t,children:[(0,i.jsxs)("div",{className:"smart-linking-text",children:[(0,p.__)("Automatically insert links to your most relevant, top performing content.","wp-parsely"),(0,i.jsxs)(s.Button,{href:"https://docs.parse.ly/plugin-content-helper/#h-smart-linking-beta",target:"_blank",variant:"link",children:[(0,p.__)("Learn more about Parse.ly AI","wp-parsely"),(0,i.jsx)(z,{icon:U,size:18,className:"parsely-external-link-icon"})]})]}),A&&(0,i.jsx)(s.Notice,{status:"info",onRemove:function(){return te(null)},className:"wp-parsely-content-helper-error",children:A.Message()}),x&&w>0&&(0,i.jsx)(s.Notice,{status:"success",onRemove:function(){return k(!1)},className:"wp-parsely-smart-linking-suggested-links",children:(0,p.sprintf)(/* translators: 1 - number of smart links generated */ /* translators: 1 - number of smart links generated */ +(0,p.__)("Successfully added %s smart links.","wp-parsely"),w>0?w:R.length)}),(0,i.jsx)(me,{disabled:L,selectedBlock:null==Le?void 0:Le.clientId,onSettingChange:function(e,t){var n;y({SmartLinking:$e($e({},d.SmartLinking),(n={},n[e]=t,n))}),"MaxLinks"===e&&fe(t)}}),(0,i.jsx)("div",{className:"smart-linking-generate",children:(0,i.jsx)(s.Button,{onClick:function(){return Ke(void 0,void 0,void 0,(function(){var e,t,n,r,i,s,a,l,c,u;return Ye(this,(function(d){switch(d.label){case 0:return[4,ee(!0)];case 1:return d.sent(),[4,be()];case 2:return d.sent(),[4,te(null)];case 3:return d.sent(),k(!1),v.trackEvent("smart_linking_generate_pressed",{is_full_content:N,selected_block:null!==(l=null==Le?void 0:Le.name)&&void 0!==l?l:"none",context:o}),e=Se.some((function(e){return"core/freeform"===e.name})),"core/freeform"===(null==Le?void 0:Le.name)&&!N||e&&N?(S("error",(0,p.__)("Smart Linking is not supported for the Freeform block.","wp-parsely"),{type:"snackbar"}),ee(!1),[2]):[4,Ae(N?"all":null==Le?void 0:Le.clientId)];case 4:d.sent(),t=setTimeout((function(){var e;ee(!1),v.trackEvent("smart_linking_generate_timeout",{is_full_content:N,selected_block:null!==(e=null==Le?void 0:Le.name)&&void 0!==e?e:"none",context:o}),Oe(N?"all":null==Le?void 0:Le.clientId)}),18e4),n=D,d.label=5;case 5:return d.trys.push([5,8,10,15]),[4,Ce(3)];case 6:return r=d.sent(),[4,(f=r,Ke(void 0,void 0,void 0,(function(){var e;return Ye(this,(function(t){switch(t.label){case 0:return f=f.filter((function(e){return!G.some((function(t){return t.uid===e.uid&&t.applied}))})),e=Ne.replace(/^https?:\/\//,"").replace(/\/+$/,""),f=(f=f.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!G.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)}))})),f=(f=se(N?Se:[Le],f,{}).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!G.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,ne(f)];case 1:return t.sent(),[2]}}))})))];case 7:return d.sent(),_e(!0),[3,15];case 8:return i=d.sent(),s=new $(null!==(c=i.message)&&void 0!==c?c:"An unknown error has occurred.",null!==(u=i.code)&&void 0!==u?u:M.UnknownError),a=s.message,i.code&&i.code===M.ParselyAborted&&(a=(0,p.sprintf)(/* translators: %d: number of retry attempts, %s: attempt plural */ /* translators: %d: number of retry attempts, %s: attempt plural */ +(0,p.__)("The Smart Linking process was cancelled after %1$d %2$s.","wp-parsely"),i.numRetries,(0,p._n)("attempt","attempts",i.numRetries,"wp-parsely")),i.message=a),console.error(i),[4,te(i)];case 9:return d.sent(),S("error",a,{type:"snackbar"}),[3,15];case 10:return[4,ee(!1)];case 11:return d.sent(),[4,de(n)];case 12:return d.sent(),[4,he(!1)];case 13:return d.sent(),[4,Oe(N?"all":null==Le?void 0:Le.clientId)];case 14:return d.sent(),clearTimeout(t),[7];case 15:return[2]}var f}))}))},variant:"primary",isBusy:L,disabled:L,children:F?(0,p.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,p.__)("Retrying… Attempt %1$d of %2$d","wp-parsely"),V,3):L?(0,p.__)("Generating Smart Links…","wp-parsely"):(0,p.__)("Add Smart Links","wp-parsely")})}),(W.length>0||q.length>0)&&(0,i.jsx)("div",{className:"smart-linking-manage",children:(0,i.jsx)(s.Button,{onClick:function(){return Ke(void 0,void 0,void 0,(function(){var e;return Ye(this,(function(t){switch(t.label){case 0:return[4,ce()];case 1:return t.sent(),e=ae(),[4,ne(e)];case 2:return t.sent(),_e(!0),[2]}}))}))},variant:"secondary",disabled:L,children:(0,p.__)("Review Smart Links","wp-parsely")})})]}),E&&(0,i.jsx)(We,{isOpen:E,onAppliedLink:function(){b((function(e){return e+1}))},onClose:function(){k(!0),_e(!1)}})]})},Xe=function(){return Xe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0)&&(t(),e())}))}))]}))},new((n=void 0)||(n=Promise))((function(i,s){function a(e){try{l(r.next(e))}catch(e){s(e)}}function o(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(a,o)}l((r=r.apply(e,t||[])).next())}));var e,t,n,r}().then((function(){var t=document.querySelector(".wp-block-post-content");de(t,e)}))})))},ut=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{d:"M7 11.5h10V13H7z"})}),pt=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{d:"M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"})}),dt=function(e){var t=e.title,n=e.icon,r=e.subtitle,a=e.level,o=void 0===a?2:a,l=e.children,c=e.controls,u=e.onClick,d=e.isOpen,f=e.isLoading,h=e.dropdownChildren;return(0,i.jsxs)("div",{className:"performance-stat-panel",children:[(0,i.jsxs)(s.__experimentalHStack,{className:"panel-header level-"+o,children:[(0,i.jsx)(s.__experimentalHeading,{level:o,children:t}),r&&!d&&(0,i.jsx)("span",{className:"panel-subtitle",children:r}),c&&!h&&(0,i.jsx)(s.DropdownMenu,{icon:n,label:(0,p.__)("Settings","wp-parsely"),className:"panel-settings-button",controls:c}),h&&(0,i.jsx)(s.DropdownMenu,{icon:n,label:(0,p.__)("Settings","wp-parsely"),className:"panel-settings-button",children:h}),n&&!h&&!c&&(0,i.jsx)(s.Button,{icon:n,className:"panel-settings-button",isPressed:d,onClick:u})]}),(0,i.jsx)("div",{className:"panel-body",children:f?(0,i.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,i.jsx)(s.Spinner,{})}):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,s=r.toString(),a="",o=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/o&&(u=i>10?1:2),u=parseFloat(i.toFixed(2))===parseFloat(i.toFixed(0))?0:u,s=i.toFixed(u),a=l}o=c})),s+n+a}var ht=function(e){var n=e.data,r=e.isLoading,a=(0,u.useState)(t.Views),o=a[0],l=a[1],c=(0,u.useState)(!1),d=c[0],f=c[1];r||delete n.referrers.types.totals;var h=function(e){switch(e){case"social":return(0,p.__)("Social","wp-parsely");case"search":return(0,p.__)("Search","wp-parsely");case"other":return(0,p.__)("Other","wp-parsely");case"internal":return(0,p.__)("Internal","wp-parsely");case"direct":return(0,p.__)("Direct","wp-parsely")}return e},v=(0,p.sprintf)((0,p.__)("By %s","wp-parsely"),N(o)); +/* translators: %s: metric description */return(0,i.jsxs)(dt,{title:(0,p.__)("Categories","wp-parsely"),level:3,subtitle:v,isOpen:d,onClick:function(){return f(!d)},children:[d&&(0,i.jsx)("div",{className:"panel-settings",children:(0,i.jsx)(s.SelectControl,{value:o,prefix:(0,p.__)("By: ","wp-parsely"),onChange:function(e){L(e,t)&&l(e)},children:Object.values(t).map((function(e){return(0,i.jsxs)("option",{value:e,disabled:"avg_engaged"===e,children:[N(e),"avg_engaged"===e&&(0,p.__)(" (coming soon)","wp-parsely")]},e)}))})}),r?(0,i.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,i.jsx)(s.Spinner,{})}):(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:"multi-percentage-bar",children:Object.entries(n.referrers.types).map((function(e){var t=e[0],n=e[1],r=(0,p.sprintf)(/* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ /* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ (0,p.__)("%1$s: %2$s%%","wp-parsely"),h(t),n.viewsPercentage);return(0,i.jsx)(s.Tooltip /* translators: %s: percentage value */,{ /* translators: %s: percentage value */ -text:"".concat(h(t)," - ").concat((0,p.sprintf)((0,p.__)("%s%%","wp-parsely"),n.viewsPercentage)),delay:150,children:(0,i.jsx)("div",{"aria-label":r,className:"bar-fill "+t,style:{width:n.viewsPercentage+"%"}})},t)}))}),(0,i.jsx)("div",{className:"percentage-bar-labels",children:Object.entries(n.referrers.types).map((function(e){var t=e[0],n=e[1];return(0,i.jsxs)("div",{className:"single-label "+t,children:[(0,i.jsx)("div",{className:"label-color "+t}),(0,i.jsx)("div",{className:"label-text",children:h(t)}),(0,i.jsx)("div",{className:"label-value",children:pt(n.views)})]},t)}))})]})]})},ft=(0,i.jsx)(d.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsx)(d.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"})}),ht=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),vt=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),gt=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{d:"M11 13h2v-2h-2v2zm-6 0h2v-2H5v2zm12-2v2h2v-2h-2z"})}),yt=function(){return yt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]1?[2,Promise.reject(new W((0,p.sprintf)(/* translators: URL of the published post */ /* translators: URL of the published post */ -(0,p.__)("Multiple results were returned for the post %s by the Parse.ly API.","wp-parsely"),t),B.ParselyApiReturnedTooManyResults))]:[2,n[0]]}}))}))},t.prototype.fetchReferrerDataFromWpEndpoint=function(e,t,n){return Et(this,void 0,void 0,(function(){return Nt(this,(function(r){switch(r.label){case 0:return[4,this.fetch({path:(0,we.addQueryArgs)("/wp-parsely/v1/referrers/post/detail",Lt(Lt({},jt(e)),{itm_source:this.itmSource,total_views:n,url:t}))})];case 1:return[2,r.sent()]}}))}))},t}(be),At=function(){return At=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return n.sent(),[4,t(r-1)];case 2:return n.sent(),[3,4];case 3:d(e),o(!1),n.label=4;case 4:return[2]}}))}))})),[2]}))}))};return o(!0),t(1),function(){d(void 0)}}),[n]),(0,i.jsxs)("div",{className:"wp-parsely-performance-panel",children:[(0,i.jsx)(ut,{title:(0,p.__)("Performance Stats","wp-parsely"),icon:ct,dropdownChildren:function(e){var t=e.onClose;return(0,i.jsx)(Dt,{onClose:t})},children:(0,i.jsx)("div",{className:"panel-settings",children:(0,i.jsx)(s.SelectControl,{size:"__unstable-large",value:m.PerformanceStats.Period,prefix:(0,i.jsx)(s.__experimentalInputControlPrefixWrapper,{children:(0,p.__)("Period: ","wp-parsely")}),onChange:function(t){L(t,e)&&(w({PerformanceStats:At(At({},m.PerformanceStats),{Period:t})}),v.trackEvent("editor_sidebar_performance_period_changed",{period:t}))},children:Object.values(e).map((function(e){return(0,i.jsx)("option",{value:e,children:E(e)},e)}))})})}),c?c.Message():(0,i.jsxs)(i.Fragment,{children:[Mt(m,"overview")&&(0,i.jsx)(St,{data:h,isLoading:a}),Mt(m,"categories")&&(0,i.jsx)(dt,{data:h,isLoading:a}),Mt(m,"referrers")&&(0,i.jsx)(Pt,{data:h,isLoading:a})]}),window.wpParselyPostUrl&&(0,i.jsx)(s.Button,{className:"wp-parsely-view-post",variant:"primary",onClick:function(){v.trackEvent("editor_sidebar_view_post_pressed")},href:window.wpParselyPostUrl,rel:"noopener",target:"_blank",children:(0,p.__)("View this in Parse.ly","wp-parsely")})]})},Vt=function(e){var t=e.period;return(0,i.jsx)(s.Panel,{children:(0,i.jsx)(V,{children:(0,i.jsx)(Ft,{period:t})})})},Gt=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,i.jsx)(s.__experimentalToggleGroupControlOption,{value:r.Tag,label:(0,p.__)("Tag","wp-parsely")}),a.categories.length>=1&&(0,i.jsx)(s.__experimentalToggleGroupControlOption,{value:r.Section,label:(0,p.__)("Section","wp-parsely")}),a.authors.length>=1&&(0,i.jsx)(s.__experimentalToggleGroupControlOption,{value:r.Author,label:(0,p.__)("Author","wp-parsely")})]})})},zt=function(e){var t=e.filter,n=e.label,a=e.postData,o=Gt(e,["filter","label","postData"]);return(0,i.jsx)("div",{className:"related-posts-filter-values",children:(0,i.jsx)(s.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,label:n,onChange:function(e){return o.onFilterValueChange(e)},options:r.Tag===t.type?a.tags.map((function(e){return{value:e,label:e}})):r.Section===t.type?a.categories.map((function(e){return{value:e,label:e}})):r.Author===t.type?a.authors.map((function(e){return{value:e,label:e}})):[],value:t.value})})},Ut=function(e){var t=e.filter,n=e.postData,s=e.label,a=Gt(e,["filter","postData","label"]),o=function(){return n.authors.length>0&&n.categories.length>0||n.authors.length>0&&n.tags.length>0||n.tags.length>0&&n.categories.length>0},l=function(){return r.Tag===t.type&&n.tags.length>1||r.Section===t.type&&n.categories.length>1||r.Author===t.type&&n.authors.length>1};return o()||l()?(0,i.jsxs)("div",{className:"related-posts-filter-settings",children:[o()&&(0,i.jsx)(Ht,{filter:t,label:s,onFilterTypeChange:a.onFilterTypeChange,postData:n}),l()&&(0,i.jsx)(zt,{filter:t,label:o()?void 0:s,onFilterValueChange:a.onFilterValueChange,postData:n})]}):null},qt=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),Zt=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),Wt=function(){return(0,i.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"1",height:"40",viewBox:"0 0 1 40",fill:"none",children:(0,i.jsx)(s.Rect,{width:"1",height:"40",fill:"#cccccc"})})};function $t(e){var t=e.metric,n=e.post,r=e.avgEngagedIcon,s=e.viewsIcon;return"views"===t?(0,i.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,i.jsx)("span",{className:"screen-reader-text",children:(0,p.__)("Number of Views","wp-parsely")}),s,pt(n.views.toString())]}):"avg_engaged"===t?(0,i.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,i.jsx)("span",{className:"screen-reader-text",children:(0,p.__)("Average Time","wp-parsely")}),r,n.avgEngaged]}):(0,i.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}var Kt,Yt=function(e){var t,n,r=e.metric,o=e.post,l=e.postContent,c=(0,a.useDispatch)("core/notices").createNotice,u=l&&(t=l,n=R(o.rawUrl),new RegExp("]*href=[\"'](http://|https://)?.*".concat(n,".*[\"'][^>]*>"),"i").test(t));return(0,i.jsxs)("div",{className:"related-post-single","data-testid":"related-post-single",children:[(0,i.jsx)("div",{className:"related-post-title",children:(0,i.jsxs)("a",{href:o.url,target:"_blank",rel:"noreferrer",children:[(0,i.jsx)("span",{className:"screen-reader-text",children:(0,p.__)("View on website (opens new tab)","wp-parsely")}),o.title]})}),(0,i.jsx)("div",{className:"related-post-actions",children:(0,i.jsxs)("div",{className:"related-post-info",children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:"related-post-metric",children:(0,i.jsx)($t,{metric:r,post:o,viewsIcon:(0,i.jsx)(H,{icon:ft}),avgEngagedIcon:(0,i.jsx)(s.Dashicon,{icon:"clock",size:24})})}),u&&(0,i.jsx)("div",{className:"related-post-linked",children:(0,i.jsx)(s.Tooltip,{text:(0,p.__)("This post is linked in the content","wp-parsely"),children:(0,i.jsx)(H,{icon:qt,size:24})})})]}),(0,i.jsx)(Wt,{}),(0,i.jsxs)("div",{children:[(0,i.jsx)(s.Button,{icon:Zt,iconSize:24,onClick:function(){navigator.clipboard.writeText(o.rawUrl).then((function(){c("success",(0,p.__)("URL copied to clipboard","wp-parsely"),{type:"snackbar"})}))},label:(0,p.__)("Copy URL to clipboard","wp-parsely")}),(0,i.jsx)(s.Button,{icon:(0,i.jsx)(y,{}),iconSize:18,href:o.dashUrl,target:"_blank",label:(0,p.__)("View in Parse.ly","wp-parsely")})]})]})})]})},Qt=window.wp.coreData,Xt=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 __)}}(),Jt=function(){return Jt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]1?[2,Promise.reject(new $((0,p.sprintf)(/* translators: URL of the published post */ /* translators: URL of the published post */ +(0,p.__)("Multiple results were returned for the post %s by the Parse.ly API.","wp-parsely"),t),M.ParselyApiReturnedTooManyResults))]:[2,n[0]]}}))}))},t.prototype.fetchReferrerDataFromWpEndpoint=function(e,t,n){return Ct(this,void 0,void 0,(function(){return At(this,(function(r){switch(r.label){case 0:return[4,this.fetch({path:(0,be.addQueryArgs)("/wp-parsely/v1/referrers/post/detail",Nt(Nt({},Lt(e)),{itm_source:this.itmSource,total_views:n,url:t}))})];case 1:return[2,r.sent()]}}))}))},t}(_e),Rt=function(){return Rt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return n.sent(),[4,t(r-1)];case 2:return n.sent(),[3,4];case 3:d(e),o(!1),n.label=4;case 4:return[2]}}))}))})),[2]}))}))};return o(!0),t(1),function(){d(void 0)}}),[n]),(0,i.jsxs)("div",{className:"wp-parsely-performance-panel",children:[(0,i.jsx)(dt,{title:(0,p.__)("Performance Stats","wp-parsely"),icon:pt,dropdownChildren:function(e){var t=e.onClose;return(0,i.jsx)(Vt,{onClose:t})},children:(0,i.jsx)("div",{className:"panel-settings",children:(0,i.jsx)(s.SelectControl,{size:"__unstable-large",value:m.PerformanceStats.Period,prefix:(0,i.jsx)(s.__experimentalInputControlPrefixWrapper,{children:(0,p.__)("Period: ","wp-parsely")}),onChange:function(t){L(t,e)&&(w({PerformanceStats:Rt(Rt({},m.PerformanceStats),{Period:t})}),v.trackEvent("editor_sidebar_performance_period_changed",{period:t}))},children:Object.values(e).map((function(e){return(0,i.jsx)("option",{value:e,children:E(e)},e)}))})})}),c?c.Message():(0,i.jsxs)(i.Fragment,{children:[Ft(m,"overview")&&(0,i.jsx)(jt,{data:h,isLoading:a}),Ft(m,"categories")&&(0,i.jsx)(ht,{data:h,isLoading:a}),Ft(m,"referrers")&&(0,i.jsx)(Tt,{data:h,isLoading:a})]}),window.wpParselyPostUrl&&(0,i.jsx)(s.Button,{className:"wp-parsely-view-post",variant:"primary",onClick:function(){v.trackEvent("editor_sidebar_view_post_pressed")},href:window.wpParselyPostUrl,rel:"noopener",target:"_blank",children:(0,p.__)("View this in Parse.ly","wp-parsely")})]})},Ht=function(e){var t=e.period;return(0,i.jsx)(s.Panel,{children:(0,i.jsx)(G,{children:(0,i.jsx)(Gt,{period:t})})})},zt=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,i.jsx)(s.__experimentalToggleGroupControlOption,{value:r.Tag,label:(0,p.__)("Tag","wp-parsely")}),a.categories.length>=1&&(0,i.jsx)(s.__experimentalToggleGroupControlOption,{value:r.Section,label:(0,p.__)("Section","wp-parsely")}),a.authors.length>=1&&(0,i.jsx)(s.__experimentalToggleGroupControlOption,{value:r.Author,label:(0,p.__)("Author","wp-parsely")})]})})},qt=function(e){var t=e.filter,n=e.label,a=e.postData,o=zt(e,["filter","label","postData"]);return(0,i.jsx)("div",{className:"related-posts-filter-values",children:(0,i.jsx)(s.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,label:n,onChange:function(e){return o.onFilterValueChange(e)},options:r.Tag===t.type?a.tags.map((function(e){return{value:e,label:e}})):r.Section===t.type?a.categories.map((function(e){return{value:e,label:e}})):r.Author===t.type?a.authors.map((function(e){return{value:e,label:e}})):[],value:t.value})})},Zt=function(e){var t=e.filter,n=e.postData,s=e.label,a=zt(e,["filter","postData","label"]),o=function(){return n.authors.length>0&&n.categories.length>0||n.authors.length>0&&n.tags.length>0||n.tags.length>0&&n.categories.length>0},l=function(){return r.Tag===t.type&&n.tags.length>1||r.Section===t.type&&n.categories.length>1||r.Author===t.type&&n.authors.length>1};return o()||l()?(0,i.jsxs)("div",{className:"related-posts-filter-settings",children:[o()&&(0,i.jsx)(Ut,{filter:t,label:s,onFilterTypeChange:a.onFilterTypeChange,postData:n}),l()&&(0,i.jsx)(qt,{filter:t,label:o()?void 0:s,onFilterValueChange:a.onFilterValueChange,postData:n})]}):null},Wt=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),$t=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),Kt=function(){return(0,i.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"1",height:"40",viewBox:"0 0 1 40",fill:"none",children:(0,i.jsx)(s.Rect,{width:"1",height:"40",fill:"#cccccc"})})};function Yt(e){var t=e.metric,n=e.post,r=e.avgEngagedIcon,s=e.viewsIcon;return"views"===t?(0,i.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,i.jsx)("span",{className:"screen-reader-text",children:(0,p.__)("Number of Views","wp-parsely")}),s,ft(n.views.toString())]}):"avg_engaged"===t?(0,i.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,i.jsx)("span",{className:"screen-reader-text",children:(0,p.__)("Average Time","wp-parsely")}),r,n.avgEngaged]}):(0,i.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}var Jt,Qt=function(e){var t,n,r=e.metric,o=e.post,l=e.postContent,c=(0,a.useDispatch)("core/notices").createNotice,u=l&&(t=l,n=I(o.rawUrl),new RegExp("]*href=[\"'](http://|https://)?.*".concat(n,".*[\"'][^>]*>"),"i").test(t));return(0,i.jsxs)("div",{className:"related-post-single","data-testid":"related-post-single",children:[(0,i.jsx)("div",{className:"related-post-title",children:(0,i.jsxs)("a",{href:o.url,target:"_blank",rel:"noreferrer",children:[(0,i.jsx)("span",{className:"screen-reader-text",children:(0,p.__)("View on website (opens new tab)","wp-parsely")}),o.title]})}),(0,i.jsx)("div",{className:"related-post-actions",children:(0,i.jsxs)("div",{className:"related-post-info",children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:"related-post-metric",children:(0,i.jsx)(Yt,{metric:r,post:o,viewsIcon:(0,i.jsx)(z,{icon:vt}),avgEngagedIcon:(0,i.jsx)(s.Dashicon,{icon:"clock",size:24})})}),u&&(0,i.jsx)("div",{className:"related-post-linked",children:(0,i.jsx)(s.Tooltip,{text:(0,p.__)("This post is linked in the content","wp-parsely"),children:(0,i.jsx)(z,{icon:Wt,size:24})})})]}),(0,i.jsx)(Kt,{}),(0,i.jsxs)("div",{children:[(0,i.jsx)(s.Button,{icon:$t,iconSize:24,onClick:function(){navigator.clipboard.writeText(o.rawUrl).then((function(){c("success",(0,p.__)("URL copied to clipboard","wp-parsely"),{type:"snackbar"})}))},label:(0,p.__)("Copy URL to clipboard","wp-parsely")}),(0,i.jsx)(s.Button,{icon:(0,i.jsx)(y,{}),iconSize:18,href:o.dashUrl,target:"_blank",label:(0,p.__)("View in Parse.ly","wp-parsely")})]})]})})]})},Xt=window.wp.coreData,en=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 __)}}(),tn=function(){return tn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&u.every(Number.isInteger)?null!==(n=o("taxonomy","category",{include:u,context:"view"}))&&void 0!==n?n:void 0:null,tags:a=Array.isArray(p)&&p.length>0&&p.every(Number.isInteger)?null!==(r=o("taxonomy","post_tag",{include:p,context:"view"}))&&void 0!==r?r:void 0:null,isReady:void 0!==i&&void 0!==s&&void 0!==a}}),[]);return{authors:e.authors,categories:e.categories,tags:e.tags,isReady:e.isReady}}(),m=y.authors,w=y.categories,b=y.tags,_=y.isReady;(0,u.useEffect)((function(){if(_){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})):[]};g({authors:e(m),categories:e(w),tags:e(b)})}}),[m,w,b,_]);var x=(0,u.useState)(!0),k=x[0],S=x[1],P=(0,u.useState)(),T=P[0],C=P[1],O=(0,u.useState)(),R=O[0],I=O[1],B=(0,u.useState)([]),M=B[0],D=B[1],F=(0,u.useState)({type:o.RelatedPosts.FilterBy,value:o.RelatedPosts.FilterValue}),V=F[0],G=F[1],H=(0,u.useState)(void 0),z=H[0],U=H[1],q=(0,A.useDebounce)(U,1e3);(0,a.useSelect)((function(e){if("undefined"==typeof jest){var t=e("core/editor").getEditedPostContent;q(t())}else q("Jest test is running")}),[q]);var Z=function(e,t){l({RelatedPosts:rn(rn({},o.RelatedPosts),{FilterBy:e,FilterValue:t})})};return(0,u.useEffect)((function(){var e,t,n=function(e){return sn(void 0,void 0,void 0,(function(){return an(this,(function(t){return nn.getInstance().getRelatedPosts(c,d,V).then((function(e){D(e.posts),I(e.message),S(!1)})).catch((function(t){return sn(void 0,void 0,void 0,(function(){return an(this,(function(r){switch(r.label){case 0:return e>0&&t.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,n(e-1)];case 2:return r.sent(),[3,4];case 3:S(!1),C(t),r.label=4;case 4:return[2]}}))}))})),[2]}))}))},i=r.Author===V.type,s=r.Tag===V.type,a=r.Section===V.type,o=r.Unavailable===V.type,l=0===h.authors.length,u=0===h.tags.length,p=0===h.categories.length,f=i&&!h.authors.includes(V.value),v=s&&!h.tags.includes(V.value),g=a&&!h.categories.includes(V.value);return S(!0),o||s&&u||a&&p||i&&l?Object.values(h).every((function(e){return 0===e.length}))||G((e="",t=r.Unavailable,h.tags.length>=1?(t=r.Tag,e=h.tags[0]):h.categories.length>=1?(t=r.Section,e=h.categories[0]):h.authors.length>=1&&(t=r.Author,e=h.authors[0]),{type:t,value:e})):v?G({type:r.Tag,value:h.tags[0]}):g?G({type:r.Section,value:h.categories[0]}):f?G({type:r.Author,value:h.authors[0]}):n(1),function(){S(!1),D([]),I(""),C(void 0)}}),[c,d,V,h]),0===h.authors.length&&0===h.categories.length&&0===h.tags.length&&_?(0,i.jsx)("div",{className:"wp-parsely-related-posts",children:(0,i.jsx)("div",{className:"related-posts-body",children:(0,p.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,i.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,i.jsx)("div",{className:"related-posts-description",children:(0,p.__)("Find top-performing related posts based on a key metric.","wp-parsely")}),(0,i.jsxs)("div",{className:"related-posts-body",children:[(0,i.jsxs)("div",{className:"related-posts-settings",children:[(0,i.jsx)(s.SelectControl,{size:"__unstable-large",onChange:function(e){var n;L(n=e,t)&&(l({RelatedPosts:rn(rn({},o.RelatedPosts),{Metric:n})}),v.trackEvent("related_posts_metric_changed",{metric:n}))},prefix:(0,i.jsx)(s.__experimentalInputControlPrefixWrapper,{children:(0,p.__)("Metric: ","wp-parsely")}),value:d,children:Object.values(t).map((function(e){return(0,i.jsx)("option",{value:e,children:N(e)},e)}))}),(0,i.jsx)(s.SelectControl,{size:"__unstable-large",value:c,prefix:(0,i.jsxs)(s.__experimentalInputControlPrefixWrapper,{children:[(0,p.__)("Period: ","wp-parsely")," "]}),onChange:function(t){return function(t){L(t,e)&&(l({RelatedPosts:rn(rn({},o.RelatedPosts),{Period:t})}),v.trackEvent("related_posts_period_changed",{period:t}))}(t)},children:Object.values(e).map((function(e){return(0,i.jsx)("option",{value:e,children:E(e)},e)}))})]}),(0,i.jsx)(Ut,{label:(0,p.__)("Filter by","wp-parsely"),filter:V,onFilterTypeChange:function(e){if(L(e,r)){var t="",n=e;r.Tag===n&&(t=h.tags[0]),r.Section===n&&(t=h.categories[0]),r.Author===n&&(t=h.authors[0]),""!==t&&(Z(n,t),G({type:n,value:t}),v.trackEvent("related_posts_filter_type_changed",{filter_type:n}))}},onFilterValueChange:function(e){"string"==typeof e&&(Z(V.type,e),G(rn(rn({},V),{value:e})))},postData:h}),(0,i.jsxs)("div",{className:"related-posts-wrapper",children:[(0,i.jsx)("div",{children:(0,i.jsx)("p",{className:"related-posts-descr","data-testid":"parsely-related-posts-descr",children:r.Tag===V.type?(0,p.sprintf)(/* translators: 1: tag name, 2: period */ /* translators: 1: tag name, 2: period */ +message:(0,p.sprintf)((0,p.__)('by author "%1$s"',"wp-parsely"),n.value)};throw new $((0,p.__)("No valid filter type has been specified.","wp-parsely"),M.CannotFormulateApiQuery)},t}(_e),an=function(){return an=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&u.every(Number.isInteger)?null!==(n=o("taxonomy","category",{include:u,context:"view"}))&&void 0!==n?n:void 0:null,tags:a=Array.isArray(p)&&p.length>0&&p.every(Number.isInteger)?null!==(r=o("taxonomy","post_tag",{include:p,context:"view"}))&&void 0!==r?r:void 0:null,isReady:void 0!==i&&void 0!==s&&void 0!==a}}),[]);return{authors:e.authors,categories:e.categories,tags:e.tags,isReady:e.isReady}}(),m=y.authors,w=y.categories,b=y.tags,_=y.isReady;(0,u.useEffect)((function(){if(_){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})):[]};g({authors:e(m),categories:e(w),tags:e(b)})}}),[m,w,b,_]);var x=(0,u.useState)(!0),k=x[0],S=x[1],P=(0,u.useState)(),T=P[0],C=P[1],A=(0,u.useState)(),R=A[0],I=A[1],B=(0,u.useState)([]),M=B[0],D=B[1],F=(0,u.useState)({type:o.RelatedPosts.FilterBy,value:o.RelatedPosts.FilterValue}),V=F[0],G=F[1],H=(0,u.useState)(void 0),z=H[0],U=H[1],q=(0,O.useDebounce)(U,1e3);(0,a.useSelect)((function(e){if("undefined"==typeof jest){var t=e("core/editor").getEditedPostContent;q(t())}else q("Jest test is running")}),[q]);var Z=function(e,t){l({RelatedPosts:an(an({},o.RelatedPosts),{FilterBy:e,FilterValue:t})})};return(0,u.useEffect)((function(){var e,t,n=function(e){return on(void 0,void 0,void 0,(function(){return ln(this,(function(t){return sn.getInstance().getRelatedPosts(c,d,V).then((function(e){D(e.posts),I(e.message),S(!1)})).catch((function(t){return on(void 0,void 0,void 0,(function(){return ln(this,(function(r){switch(r.label){case 0:return e>0&&t.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,n(e-1)];case 2:return r.sent(),[3,4];case 3:S(!1),C(t),r.label=4;case 4:return[2]}}))}))})),[2]}))}))},i=r.Author===V.type,s=r.Tag===V.type,a=r.Section===V.type,o=r.Unavailable===V.type,l=0===h.authors.length,u=0===h.tags.length,p=0===h.categories.length,f=i&&!h.authors.includes(V.value),v=s&&!h.tags.includes(V.value),g=a&&!h.categories.includes(V.value);return S(!0),o||s&&u||a&&p||i&&l?Object.values(h).every((function(e){return 0===e.length}))||G((e="",t=r.Unavailable,h.tags.length>=1?(t=r.Tag,e=h.tags[0]):h.categories.length>=1?(t=r.Section,e=h.categories[0]):h.authors.length>=1&&(t=r.Author,e=h.authors[0]),{type:t,value:e})):v?G({type:r.Tag,value:h.tags[0]}):g?G({type:r.Section,value:h.categories[0]}):f?G({type:r.Author,value:h.authors[0]}):n(1),function(){S(!1),D([]),I(""),C(void 0)}}),[c,d,V,h]),0===h.authors.length&&0===h.categories.length&&0===h.tags.length&&_?(0,i.jsx)("div",{className:"wp-parsely-related-posts",children:(0,i.jsx)("div",{className:"related-posts-body",children:(0,p.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,i.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,i.jsx)("div",{className:"related-posts-description",children:(0,p.__)("Find top-performing related posts based on a key metric.","wp-parsely")}),(0,i.jsxs)("div",{className:"related-posts-body",children:[(0,i.jsxs)("div",{className:"related-posts-settings",children:[(0,i.jsx)(s.SelectControl,{size:"__unstable-large",onChange:function(e){var n;L(n=e,t)&&(l({RelatedPosts:an(an({},o.RelatedPosts),{Metric:n})}),v.trackEvent("related_posts_metric_changed",{metric:n}))},prefix:(0,i.jsx)(s.__experimentalInputControlPrefixWrapper,{children:(0,p.__)("Metric: ","wp-parsely")}),value:d,children:Object.values(t).map((function(e){return(0,i.jsx)("option",{value:e,children:N(e)},e)}))}),(0,i.jsx)(s.SelectControl,{size:"__unstable-large",value:c,prefix:(0,i.jsxs)(s.__experimentalInputControlPrefixWrapper,{children:[(0,p.__)("Period: ","wp-parsely")," "]}),onChange:function(t){return function(t){L(t,e)&&(l({RelatedPosts:an(an({},o.RelatedPosts),{Period:t})}),v.trackEvent("related_posts_period_changed",{period:t}))}(t)},children:Object.values(e).map((function(e){return(0,i.jsx)("option",{value:e,children:E(e)},e)}))})]}),(0,i.jsx)(Zt,{label:(0,p.__)("Filter by","wp-parsely"),filter:V,onFilterTypeChange:function(e){if(L(e,r)){var t="",n=e;r.Tag===n&&(t=h.tags[0]),r.Section===n&&(t=h.categories[0]),r.Author===n&&(t=h.authors[0]),""!==t&&(Z(n,t),G({type:n,value:t}),v.trackEvent("related_posts_filter_type_changed",{filter_type:n}))}},onFilterValueChange:function(e){"string"==typeof e&&(Z(V.type,e),G(an(an({},V),{value:e})))},postData:h}),(0,i.jsxs)("div",{className:"related-posts-wrapper",children:[(0,i.jsx)("div",{children:(0,i.jsx)("p",{className:"related-posts-descr","data-testid":"parsely-related-posts-descr",children:r.Tag===V.type?(0,p.sprintf)(/* translators: 1: tag name, 2: period */ /* translators: 1: tag name, 2: period */ (0,p.__)("Top related posts with the “%1$s” tag in the %2$s.","wp-parsely"),V.value,E(c,!0)):r.Section===V.type?(0,p.sprintf)(/* translators: 1: section name, 2: period */ /* translators: 1: section name, 2: period */ (0,p.__)("Top related posts in the “%1$s” section in the %2$s.","wp-parsely"),V.value,E(c,!0)):r.Author===V.type?(0,p.sprintf)(/* translators: 1: author name, 2: period */ /* translators: 1: author name, 2: period */ -(0,p.__)("Top related posts by %1$s in the %2$s.","wp-parsely"),V.value,E(c,!0)):null!=R?R:""})}),T&&T.Message(),k&&(0,i.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,p.__)("Loading…","wp-parsely")}),!k&&!T&&0===M.length&&(0,i.jsx)("div",{className:"related-posts-empty","data-testid":"parsely-related-posts-empty",children:(0,p.__)("No related posts found.","wp-parsely")}),!k&&M.length>0&&(0,i.jsx)("div",{className:"related-posts-list",children:M.map((function(e){return(0,i.jsx)(Yt,{metric:d,post:e,postContent:z},e.id)}))})]})]})]})},ln=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})}),cn=function(){return(0,i.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:(0,i.jsx)(s.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"})})},un={journalist:{label:(0,p.__)("Journalist","wp-parsely")},editorialWriter:{label:(0,p.__)("Editorial Writer","wp-parsely")},investigativeReporter:{label:(0,p.__)("Investigative Reporter","wp-parsely")},techAnalyst:{label:(0,p.__)("Tech Analyst","wp-parsely")},businessAnalyst:{label:(0,p.__)("Business Analyst","wp-parsely")},culturalCommentator:{label:(0,p.__)("Cultural Commentator","wp-parsely")},scienceCorrespondent:{label:(0,p.__)("Science Correspondent","wp-parsely")},politicalAnalyst:{label:(0,p.__)("Political Analyst","wp-parsely")},healthWellnessAdvocate:{label:(0,p.__)("Health and Wellness Advocate","wp-parsely")},environmentalJournalist:{label:(0,p.__)("Environmental Journalist","wp-parsely")},custom:{label:(0,p.__)("Custom Persona","wp-parsely"),icon:ln}},pn=Object.keys(un),dn=function(e){return"custom"===e||""===e?un.custom.label:fn(e)?e:un[e].label},fn=function(e){return!pn.includes(e)||"custom"===e},hn=function(e){var t=e.value,n=e.onChange,r=(0,u.useState)(""),a=r[0],o=r[1],l=(0,A.useDebounce)(n,500);return(0,i.jsx)("div",{className:"parsely-persona-selector-custom",children:(0,i.jsx)(s.TextControl,{value:a||t,placeholder:(0,p.__)("Enter a custom persona…","wp-parsely"),onChange:function(e){if(""===e)return n(""),void o("");e.length>32&&(e=e.slice(0,32)),l(e),o(e)}})})},vn=function(e){var t=e.persona,n=e.value,r=void 0===n?(0,p.__)("Select a persona…","wp-parsely"):n,a=e.label,o=void 0===a?(0,p.__)("Persona","wp-parsely"):a,l=e.onChange,c=e.onDropdownChange,u=e.disabled,d=void 0!==u&&u,f=e.allowCustom,h=void 0!==f&&f;return(0,i.jsxs)(s.Disabled,{isDisabled:d,children:[o&&(0,i.jsx)("div",{className:"wp-parsely-dropdown-label",children:o}),(0,i.jsx)(s.DropdownMenu,{label:(0,p.__)("Persona","wp-parsely"),className:"parsely-persona-selector-dropdown"+(d?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"parsely-persona-selector-label",children:fn(t)?un.custom.label:r}),(0,i.jsx)(cn,{})]})},children:function(e){var n=e.onClose;return(0,i.jsx)(s.MenuGroup,{label:(0,p.__)("Persona","wp-parsely"),children:(0,i.jsx)(i.Fragment,{children:pn.map((function(e){if(!h&&"custom"===e)return null;var r=un[e],a=e===t||fn(t)&&"custom"===e;return(0,i.jsxs)(s.MenuItem,{isSelected:a,className:a?"is-selected":"",role:"menuitemradio",onClick:function(){null==c||c(e),l(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-persona-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,i.jsx)(H,{icon:r.icon}),r.label]},e)}))})})}}),h&&fn(t)&&(0,i.jsx)(hn,{onChange:function(e){l(""!==e?e:"custom")},value:"custom"===t?"":t})]})},gn={neutral:{label:(0,p.__)("Neutral","wp-parsely")},formal:{label:(0,p.__)("Formal","wp-parsely")},humorous:{label:(0,p.__)("Humorous","wp-parsely")},confident:{label:(0,p.__)("Confident","wp-parsely")},provocative:{label:(0,p.__)("Provocative","wp-parsely")},serious:{label:(0,p.__)("Serious","wp-parsely")},inspirational:{label:(0,p.__)("Inspirational","wp-parsely")},skeptical:{label:(0,p.__)("Skeptical","wp-parsely")},conversational:{label:(0,p.__)("Conversational","wp-parsely")},analytical:{label:(0,p.__)("Analytical","wp-parsely")},custom:{label:(0,p.__)("Custom Tone","wp-parsely"),icon:ln}},yn=Object.keys(gn),mn=function(e){return"custom"===e||""===e?gn.custom.label:wn(e)?e:gn[e].label},wn=function(e){return!yn.includes(e)||"custom"===e},bn=function(e){var t=e.value,n=e.onChange,r=(0,u.useState)(""),a=r[0],o=r[1],l=(0,A.useDebounce)(n,500);return(0,i.jsx)("div",{className:"parsely-tone-selector-custom",children:(0,i.jsx)(s.TextControl,{value:a||t,placeholder:(0,p.__)("Enter a custom tone","wp-parsely"),onChange:function(e){if(""===e)return n(""),void o("");e.length>32&&(e=e.slice(0,32)),l(e),o(e)}})})},xn=function(e){var t=e.tone,n=e.value,r=void 0===n?(0,p.__)("Select a tone","wp-parsely"):n,a=e.label,o=void 0===a?(0,p.__)("Tone","wp-parsely"):a,l=e.onChange,c=e.onDropdownChange,u=e.disabled,d=void 0!==u&&u,f=e.allowCustom,h=void 0!==f&&f;return(0,i.jsxs)(s.Disabled,{isDisabled:d,children:[(0,i.jsx)("div",{className:"wp-parsely-dropdown-label",children:o}),(0,i.jsx)(s.DropdownMenu,{label:(0,p.__)("Tone","wp-parsely"),className:"parsely-tone-selector-dropdown"+(d?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"parsely-tone-selector-label",children:wn(t)?gn.custom.label:r}),(0,i.jsx)(cn,{})]})},children:function(e){var n=e.onClose;return(0,i.jsx)(s.MenuGroup,{label:(0,p.__)("Select a tone","wp-parsely"),children:(0,i.jsx)(i.Fragment,{children:yn.map((function(e){if(!h&&"custom"===e)return null;var r=gn[e],a=e===t||wn(t)&&"custom"===e;return(0,i.jsxs)(s.MenuItem,{isSelected:a,className:a?"is-selected":"",role:"menuitemradio",onClick:function(){null==c||c(e),l(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-tone-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,i.jsx)(H,{icon:r.icon}),r.label]},e)}))})})}}),h&&wn(t)&&(0,i.jsx)(bn,{onChange:function(e){l(""!==e?e:"custom")},value:"custom"===t?"":t})]})},kn=(0,i.jsx)(d.SVG,{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsx)(d.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"})}),Sn=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),Pn=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),jn=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),Tn=function(){return Tn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?(0,i.jsx)("span",{className:"parsely-write-titles-text",children:(0,u.createInterpolateElement)( +(0,p.__)("Top related posts by %1$s in the %2$s.","wp-parsely"),V.value,E(c,!0)):null!=R?R:""})}),T&&T.Message(),k&&(0,i.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,p.__)("Loading…","wp-parsely")}),!k&&!T&&0===M.length&&(0,i.jsx)("div",{className:"related-posts-empty","data-testid":"parsely-related-posts-empty",children:(0,p.__)("No related posts found.","wp-parsely")}),!k&&M.length>0&&(0,i.jsx)("div",{className:"related-posts-list",children:M.map((function(e){return(0,i.jsx)(Qt,{metric:d,post:e,postContent:z},e.id)}))})]})]})]})},un=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})}),pn=function(){return(0,i.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:(0,i.jsx)(s.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"})})},dn={journalist:{label:(0,p.__)("Journalist","wp-parsely")},editorialWriter:{label:(0,p.__)("Editorial Writer","wp-parsely")},investigativeReporter:{label:(0,p.__)("Investigative Reporter","wp-parsely")},techAnalyst:{label:(0,p.__)("Tech Analyst","wp-parsely")},businessAnalyst:{label:(0,p.__)("Business Analyst","wp-parsely")},culturalCommentator:{label:(0,p.__)("Cultural Commentator","wp-parsely")},scienceCorrespondent:{label:(0,p.__)("Science Correspondent","wp-parsely")},politicalAnalyst:{label:(0,p.__)("Political Analyst","wp-parsely")},healthWellnessAdvocate:{label:(0,p.__)("Health and Wellness Advocate","wp-parsely")},environmentalJournalist:{label:(0,p.__)("Environmental Journalist","wp-parsely")},custom:{label:(0,p.__)("Custom Persona","wp-parsely"),icon:un}},fn=Object.keys(dn),hn=function(e){return"custom"===e||""===e?dn.custom.label:vn(e)?e:dn[e].label},vn=function(e){return!fn.includes(e)||"custom"===e},gn=function(e){var t=e.value,n=e.onChange,r=(0,u.useState)(""),a=r[0],o=r[1],l=(0,O.useDebounce)(n,500);return(0,i.jsx)("div",{className:"parsely-persona-selector-custom",children:(0,i.jsx)(s.TextControl,{value:a||t,placeholder:(0,p.__)("Enter a custom persona…","wp-parsely"),onChange:function(e){if(""===e)return n(""),void o("");e.length>32&&(e=e.slice(0,32)),l(e),o(e)}})})},yn=function(e){var t=e.persona,n=e.value,r=void 0===n?(0,p.__)("Select a persona…","wp-parsely"):n,a=e.label,o=void 0===a?(0,p.__)("Persona","wp-parsely"):a,l=e.onChange,c=e.onDropdownChange,u=e.disabled,d=void 0!==u&&u,f=e.allowCustom,h=void 0!==f&&f;return(0,i.jsxs)(s.Disabled,{isDisabled:d,children:[o&&(0,i.jsx)("div",{className:"wp-parsely-dropdown-label",children:o}),(0,i.jsx)(s.DropdownMenu,{label:(0,p.__)("Persona","wp-parsely"),className:"parsely-persona-selector-dropdown"+(d?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"parsely-persona-selector-label",children:vn(t)?dn.custom.label:r}),(0,i.jsx)(pn,{})]})},children:function(e){var n=e.onClose;return(0,i.jsx)(s.MenuGroup,{label:(0,p.__)("Persona","wp-parsely"),children:(0,i.jsx)(i.Fragment,{children:fn.map((function(e){if(!h&&"custom"===e)return null;var r=dn[e],a=e===t||vn(t)&&"custom"===e;return(0,i.jsxs)(s.MenuItem,{isSelected:a,className:a?"is-selected":"",role:"menuitemradio",onClick:function(){null==c||c(e),l(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-persona-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,i.jsx)(z,{icon:r.icon}),r.label]},e)}))})})}}),h&&vn(t)&&(0,i.jsx)(gn,{onChange:function(e){l(""!==e?e:"custom")},value:"custom"===t?"":t})]})},mn={neutral:{label:(0,p.__)("Neutral","wp-parsely")},formal:{label:(0,p.__)("Formal","wp-parsely")},humorous:{label:(0,p.__)("Humorous","wp-parsely")},confident:{label:(0,p.__)("Confident","wp-parsely")},provocative:{label:(0,p.__)("Provocative","wp-parsely")},serious:{label:(0,p.__)("Serious","wp-parsely")},inspirational:{label:(0,p.__)("Inspirational","wp-parsely")},skeptical:{label:(0,p.__)("Skeptical","wp-parsely")},conversational:{label:(0,p.__)("Conversational","wp-parsely")},analytical:{label:(0,p.__)("Analytical","wp-parsely")},custom:{label:(0,p.__)("Custom Tone","wp-parsely"),icon:un}},wn=Object.keys(mn),bn=function(e){return"custom"===e||""===e?mn.custom.label:xn(e)?e:mn[e].label},xn=function(e){return!wn.includes(e)||"custom"===e},kn=function(e){var t=e.value,n=e.onChange,r=(0,u.useState)(""),a=r[0],o=r[1],l=(0,O.useDebounce)(n,500);return(0,i.jsx)("div",{className:"parsely-tone-selector-custom",children:(0,i.jsx)(s.TextControl,{value:a||t,placeholder:(0,p.__)("Enter a custom tone","wp-parsely"),onChange:function(e){if(""===e)return n(""),void o("");e.length>32&&(e=e.slice(0,32)),l(e),o(e)}})})},Sn=function(e){var t=e.tone,n=e.value,r=void 0===n?(0,p.__)("Select a tone","wp-parsely"):n,a=e.label,o=void 0===a?(0,p.__)("Tone","wp-parsely"):a,l=e.onChange,c=e.onDropdownChange,u=e.disabled,d=void 0!==u&&u,f=e.allowCustom,h=void 0!==f&&f;return(0,i.jsxs)(s.Disabled,{isDisabled:d,children:[(0,i.jsx)("div",{className:"wp-parsely-dropdown-label",children:o}),(0,i.jsx)(s.DropdownMenu,{label:(0,p.__)("Tone","wp-parsely"),className:"parsely-tone-selector-dropdown"+(d?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"parsely-tone-selector-label",children:xn(t)?mn.custom.label:r}),(0,i.jsx)(pn,{})]})},children:function(e){var n=e.onClose;return(0,i.jsx)(s.MenuGroup,{label:(0,p.__)("Select a tone","wp-parsely"),children:(0,i.jsx)(i.Fragment,{children:wn.map((function(e){if(!h&&"custom"===e)return null;var r=mn[e],a=e===t||xn(t)&&"custom"===e;return(0,i.jsxs)(s.MenuItem,{isSelected:a,className:a?"is-selected":"",role:"menuitemradio",onClick:function(){null==c||c(e),l(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-tone-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,i.jsx)(z,{icon:r.icon}),r.label]},e)}))})})}}),h&&xn(t)&&(0,i.jsx)(kn,{onChange:function(e){l(""!==e?e:"custom")},value:"custom"===t?"":t})]})},Pn=(0,i.jsx)(d.SVG,{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsx)(d.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"})}),jn=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),Tn=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),Ln=(0,i.jsx)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(d.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"})}),En=function(){return En=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?(0,i.jsx)("span",{className:"parsely-write-titles-text",children:(0,u.createInterpolateElement)( // translators: %1$s is the tone, %2$s is the persona. // translators: %1$s is the tone, %2$s is the persona. -(0,p.__)("We've generated a few titles based on the content of your post, written as a .","wp-parsely"),{tone:(0,i.jsx)("strong",{children:mn(d)}),persona:(0,i.jsx)("strong",{children:dn(g)})})}):(0,p.__)("Use Parse.ly AI to generate a title for your post.","wp-parsely"),(0,i.jsxs)(s.Button,{href:"https://docs.parse.ly/plugin-content-helper/#h-title-suggestions-beta",target:"_blank",variant:"link",children:[(0,p.__)("Learn more about Parse.ly AI","wp-parsely"),(0,i.jsx)(H,{icon:z,size:18,className:"parsely-external-link-icon"})]})]}),o&&(0,i.jsx)(s.Notice,{className:"wp-parsely-content-helper-error",onRemove:function(){return l(void 0)},status:"info",children:o.Message()}),void 0!==S&&(0,i.jsx)(Rn,{title:S,type:Kt.PostTitle,isOriginal:!0}),00&&(0,i.jsx)(In,{pinnedTitles:_,isOpen:!0}),b.length>0&&(0,i.jsx)(Mn,{suggestions:b,isOpen:!0,isLoading:w})]}),(0,i.jsx)(Bn,{isLoading:w,onPersonaChange:function(e){A("Persona",e),y(e)},onSettingChange:A,onToneChange:function(e){A("Tone",e),f(e)},persona:t.TitleSuggestions.Persona,tone:t.TitleSuggestions.Tone}),(0,i.jsx)("div",{className:"title-suggestions-generate",children:(0,i.jsxs)(s.Button,{variant:"primary",isBusy:w,disabled:w||"custom"===d||"custom"===g,onClick:function(){return Gn(void 0,void 0,void 0,(function(){return Hn(this,(function(e){switch(e.label){case 0:return l(void 0),!1!==w?[3,2]:(v.trackEvent("title_suggestions_generate_pressed",{request_more:b.length>0,total_titles:b.length,total_pinned:b.filter((function(e){return e.isPinned})).length,tone:d,persona:g}),[4,(t=Kt.PostTitle,n=O,r=d,i=g,Gn(void 0,void 0,void 0,(function(){var e,s,a;return Hn(this,(function(o){switch(o.label){case 0:return[4,L(!0)];case 1:o.sent(),e=Fn.getInstance(),o.label=2;case 2:return o.trys.push([2,5,,6]),[4,e.generateTitles(n,3,r,i)];case 3:return s=o.sent(),[4,T(t,s)];case 4:return o.sent(),[3,6];case 5:return a=o.sent(),l(a),T(t,[]),[3,6];case 6:return[4,L(!1)];case 7:return o.sent(),[2]}}))})))]);case 1:e.sent(),e.label=2;case 2:return[2]}var t,n,r,i}))}))},children:[w&&(0,p.__)("Generating Titles…","wp-parsely"),!w&&x.length>0&&(0,p.__)("Generate More","wp-parsely"),!w&&0===x.length&&(0,p.__)("Generate Titles","wp-parsely")]})})]})})},Un=function(){return Un=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,i.jsx)("strong",{children:bn(d)}),persona:(0,i.jsx)("strong",{children:hn(g)})})}):(0,p.__)("Use Parse.ly AI to generate a title for your post.","wp-parsely"),(0,i.jsxs)(s.Button,{href:"https://docs.parse.ly/plugin-content-helper/#h-title-suggestions-beta",target:"_blank",variant:"link",children:[(0,p.__)("Learn more about Parse.ly AI","wp-parsely"),(0,i.jsx)(z,{icon:U,size:18,className:"parsely-external-link-icon"})]})]}),o&&(0,i.jsx)(s.Notice,{className:"wp-parsely-content-helper-error",onRemove:function(){return l(void 0)},status:"info",children:o.Message()}),void 0!==S&&(0,i.jsx)(Bn,{title:S,type:Jt.PostTitle,isOriginal:!0}),00&&(0,i.jsx)(Mn,{pinnedTitles:_,isOpen:!0}),b.length>0&&(0,i.jsx)(Fn,{suggestions:b,isOpen:!0,isLoading:w})]}),(0,i.jsx)(Dn,{isLoading:w,onPersonaChange:function(e){A("Persona",e),y(e)},onSettingChange:A,onToneChange:function(e){A("Tone",e),f(e)},persona:t.TitleSuggestions.Persona,tone:t.TitleSuggestions.Tone}),(0,i.jsx)("div",{className:"title-suggestions-generate",children:(0,i.jsxs)(s.Button,{variant:"primary",isBusy:w,disabled:w||"custom"===d||"custom"===g,onClick:function(){return zn(void 0,void 0,void 0,(function(){return Un(this,(function(e){switch(e.label){case 0:return l(void 0),!1!==w?[3,2]:(v.trackEvent("title_suggestions_generate_pressed",{request_more:b.length>0,total_titles:b.length,total_pinned:b.filter((function(e){return e.isPinned})).length,tone:d,persona:g}),[4,(t=Jt.PostTitle,n=O,r=d,i=g,zn(void 0,void 0,void 0,(function(){var e,s,a;return Un(this,(function(o){switch(o.label){case 0:return[4,L(!0)];case 1:o.sent(),e=Gn.getInstance(),o.label=2;case 2:return o.trys.push([2,5,,6]),[4,e.generateTitles(n,3,r,i)];case 3:return s=o.sent(),[4,T(t,s)];case 4:return o.sent(),[3,6];case 5:return a=o.sent(),l(a),T(t,[]),[3,6];case 6:return[4,L(!1)];case 7:return o.sent(),[2]}}))})))]);case 1:e.sent(),e.label=2;case 2:return[2]}var t,n,r,i}))}))},children:[w&&(0,p.__)("Generating Titles…","wp-parsely"),!w&&x.length>0&&(0,p.__)("Generate More","wp-parsely"),!w&&0===x.length&&(0,p.__)("Generate Titles","wp-parsely")]})})]})})},Zn=function(){return Zn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '5f61f16e91ecbf9ce984'); + array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '4af404737b96aa89a9a6'); diff --git a/build/content-helper/excerpt-generator.js b/build/content-helper/excerpt-generator.js index e858fa1e2..bd1940e38 100644 --- a/build/content-helper/excerpt-generator.js +++ b/build/content-helper/excerpt-generator.js @@ -1,4 +1,4 @@ -!function(){"use strict";var e={20:function(e,t,r){var n=r(609),a=Symbol.for("react.element"),o=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,s=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,r){var n,o={},c=null,p=null;for(n in void 0!==r&&(c=""+r),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(p=t.ref),t)i.call(t,n)&&!l.hasOwnProperty(n)&&(o[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===o[n]&&(o[n]=t[n]);return{$$typeof:a,type:e,key:c,ref:p,props:o,_owner:s.current}}t.Fragment=o,t.jsx=c,t.jsxs=c},848:function(e,t,r){e.exports=r(20)},609:function(e){e.exports=window.React}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e,t,n=window.wp.data,a=window.wp.hooks,o=window.wp.plugins,i=((0,n.dispatch)("core/block-editor"),(0,n.dispatch)("core/editor"),(0,n.dispatch)("core/edit-post")),s=r(848),l=window.wp.components,c=window.wp.editPost,p=window.wp.editor,u=window.wp.element,d=window.wp.i18n,y=window.wp.wordcount,h=window.wp.primitives,f=(0,s.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,s.jsx)(h.Path,{d:"M19.5 4.5h-7V6h4.44l-5.97 5.97 1.06 1.06L18 7.06v4.44h1.5v-7Zm-13 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3H17v3a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h3V5.5h-3Z"})}),w=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 r=this,n=arguments,o=function(t,r){var n;return void 0===r&&(r={}),function(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(i=0)),i;)try{if(r=1,n&&(a=2&s[0]?n.return:s[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,s[1])).done)return a;switch(n=0,a&&(s=[2&s[0],a.value]),s[0]){case 0:case 1:a=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((a=(a=i.trys).length>0&&a[a.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]=1e4&&(clearInterval(o),r("Telemetry library not loaded"))}),100);else r("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,r){var n;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(r=this.prepareProperties(r),null===(n=this._tkq)||void 0===n||n.push(["recordEvent",t,r])):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,r={};return Object.keys(e).forEach((function(n){t.isProprietyValid(n)&&(r[n]=e[n])})),r},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),v=(w.trackEvent,function(e){var t=e.size,r=void 0===t?24:t,n=e.className,a=void 0===n?"wp-parsely-icon":n;return(0,s.jsxs)(l.SVG,{className:a,height:r,viewBox:"0 0 60 65",width:r,xmlns:"http://www.w3.org/2000/svg",children:[(0,s.jsx)(l.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,s.jsx)(l.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,s.jsx)(l.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,s.jsx)(l.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"})]})}),g=window.wp.apiFetch,_=r.n(g),P=window.wp.url,m=function(e){void 0===e&&(e=null);var t="";(null==e?void 0:e.children)&&(t=e.children);var r="content-helper-error-message";return(null==e?void 0:e.className)&&(r+=" "+e.className),(0,s.jsx)("div",{className:r,"data-testid":null==e?void 0:e.testId,dangerouslySetInnerHTML:{__html:t}})},x=(e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)},function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function __(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(__.prototype=r.prototype,new __)});!function(e){e.CannotFormulateApiQuery="ch_cannot_formulate_api_query",e.FetchError="fetch_error",e.HttpRequestFailed="http_request_failed",e.ParselyAborted="ch_parsely_aborted",e[e.ParselyApiForbidden=403]="ParselyApiForbidden",e.ParselyApiResponseContainsError="ch_response_contains_error",e.ParselyApiReturnedNoData="ch_parsely_api_returned_no_data",e.ParselyApiReturnedTooManyResults="ch_parsely_api_returned_too_many_results",e.PluginCredentialsNotSetMessageDetected="parsely_credentials_not_set_message_detected",e.PluginSettingsApiSecretNotSet="parsely_api_secret_not_set",e.PluginSettingsSiteIdNotSet="parsely_site_id_not_set",e.PostIsNotPublished="ch_post_not_published",e.UnknownError="ch_unknown_error",e.ParselySuggestionsApiAuthUnavailable="AUTH_UNAVAILABLE",e.ParselySuggestionsApiNoAuthentication="NO_AUTHENTICATION",e.ParselySuggestionsApiNoAuthorization="NO_AUTHORIZATION",e.ParselySuggestionsApiNoData="NO_DATA",e.ParselySuggestionsApiOpenAiError="OPENAI_ERROR",e.ParselySuggestionsApiOpenAiSchema="OPENAI_SCHEMA",e.ParselySuggestionsApiOpenAiUnavailable="OPENAI_UNAVAILABLE",e.ParselySuggestionsApiSchemaError="SCHEMA_ERROR"}(t||(t={}));var b=function(e){function r(n,a,o){void 0===o&&(o=(0,d.__)("Error: ","wp-parsely"));var i=this;n.startsWith(o)&&(o=""),(i=e.call(this,o+n)||this).hint=null,i.name=i.constructor.name,i.code=a;var s=[t.ParselyApiForbidden,t.ParselyApiResponseContainsError,t.ParselyApiReturnedNoData,t.ParselyApiReturnedTooManyResults,t.PluginCredentialsNotSetMessageDetected,t.PluginSettingsApiSecretNotSet,t.PluginSettingsSiteIdNotSet,t.PostIsNotPublished,t.UnknownError,t.ParselySuggestionsApiAuthUnavailable,t.ParselySuggestionsApiNoAuthentication,t.ParselySuggestionsApiNoAuthorization,t.ParselySuggestionsApiNoData,t.ParselySuggestionsApiSchemaError];return i.retryFetch=!s.includes(i.code),Object.setPrototypeOf(i,r.prototype),i.code===t.ParselySuggestionsApiNoAuthorization?i.message=(0,d.__)('This AI-powered feature is opt-in. To gain access, please submit a request here.',"wp-parsely"):i.code===t.ParselySuggestionsApiOpenAiError||i.code===t.ParselySuggestionsApiOpenAiUnavailable?i.message=(0,d.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):i.code===t.HttpRequestFailed&&i.message.includes("cURL error 28")?i.message=(0,d.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):i.code===t.ParselySuggestionsApiSchemaError?i.message=(0,d.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):i.code===t.ParselySuggestionsApiNoData?i.message=(0,d.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):i.code===t.ParselySuggestionsApiOpenAiSchema?i.message=(0,d.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):i.code===t.ParselySuggestionsApiAuthUnavailable&&(i.message=(0,d.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),i}return x(r,e),r.prototype.Message=function(e){return void 0===e&&(e=null),[t.PluginCredentialsNotSetMessageDetected,t.PluginSettingsSiteIdNotSet,t.PluginSettingsApiSecretNotSet].includes(this.code)?function(e){var t;return void 0===e&&(e=null),(0,s.jsx)(m,{className:null==e?void 0:e.className,testId:"empty-credentials-message",children:null!==(t=window.wpParselyEmptyCredentialsMessage)&&void 0!==t?t:(0,d.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely")})}(e):(this.code===t.FetchError&&(this.hint=this.Hint((0,d.__)("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!==t.ParselyApiForbidden&&this.code!==t.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,d.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===t.HttpRequestFailed&&(this.hint=this.Hint((0,d.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,s.jsx)(m,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

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

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

")},r}(Error),E=function(){function e(){}return e.prototype.generateExcerpt=function(e,r){return n=this,a=void 0,i=function(){var n,a,o;return function(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(i=0)),i;)try{if(r=1,n&&(a=2&s[0]?n.return:s[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,s[1])).done)return a;switch(n=0,a&&(s=[2&s[0],a.value]),s[0]){case 0:case 1:a=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((a=(a=i.trys).length>0&&a[a.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]0&&a[a.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]0?(0,d.sprintf)( +!function(){"use strict";var e={20:function(e,t,r){var n=r(609),a=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,r){var n,s={},c=null,p=null;for(n in void 0!==r&&(c=""+r),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(p=t.ref),t)o.call(t,n)&&!l.hasOwnProperty(n)&&(s[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===s[n]&&(s[n]=t[n]);return{$$typeof:a,type:e,key:c,ref:p,props:s,_owner:i.current}}t.Fragment=s,t.jsx=c,t.jsxs=c},848:function(e,t,r){e.exports=r(20)},609:function(e){e.exports=window.React}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e,t,n=window.wp.data,a=window.wp.hooks,s=window.wp.plugins,o=((0,n.dispatch)("core/block-editor"),(0,n.dispatch)("core/editor"),(0,n.dispatch)("core/edit-post")),i=r(848),l=window.wp.components,c=window.wp.editPost,p=window.wp.editor,u=window.wp.element,d=window.wp.i18n,y=window.wp.wordcount,h=window.wp.primitives,f=(0,i.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(h.Path,{d:"M19.5 4.5h-7V6h4.44l-5.97 5.97 1.06 1.06L18 7.06v4.44h1.5v-7Zm-13 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3H17v3a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h3V5.5h-3Z"})}),w=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 r=this,n=arguments,s=function(t,r){var n;return void 0===r&&(r={}),function(e,t){var r,n,a,s,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(l){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(o=0)),o;)try{if(r=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]=1e4&&(clearInterval(s),r("Telemetry library not loaded"))}),100);else r("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,r){var n;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(r=this.prepareProperties(r),null===(n=this._tkq)||void 0===n||n.push(["recordEvent",t,r])):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,r={};return Object.keys(e).forEach((function(n){t.isProprietyValid(n)&&(r[n]=e[n])})),r},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),v=(w.trackEvent,function(e){var t=e.size,r=void 0===t?24:t,n=e.className,a=void 0===n?"wp-parsely-icon":n;return(0,i.jsxs)(l.SVG,{className:a,height:r,viewBox:"0 0 60 65",width:r,xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)(l.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,i.jsx)(l.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,i.jsx)(l.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,i.jsx)(l.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"})]})}),_=window.wp.apiFetch,g=r.n(_),P=window.wp.url,b=function(e){void 0===e&&(e=null);var t="";(null==e?void 0:e.children)&&(t=e.children);var r="content-helper-error-message";return(null==e?void 0:e.className)&&(r+=" "+e.className),(0,i.jsx)("div",{className:r,"data-testid":null==e?void 0:e.testId,dangerouslySetInnerHTML:{__html:t}})},m=(e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)},function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function __(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(__.prototype=r.prototype,new __)});!function(e){e.AccessToFeatureDisabled="ch_access_to_feature_disabled",e.CannotFormulateApiQuery="ch_cannot_formulate_api_query",e.FetchError="fetch_error",e.HttpRequestFailed="http_request_failed",e.ParselyAborted="ch_parsely_aborted",e[e.ParselyApiForbidden=403]="ParselyApiForbidden",e.ParselyApiResponseContainsError="ch_response_contains_error",e.ParselyApiReturnedNoData="ch_parsely_api_returned_no_data",e.ParselyApiReturnedTooManyResults="ch_parsely_api_returned_too_many_results",e.PluginCredentialsNotSetMessageDetected="parsely_credentials_not_set_message_detected",e.PluginSettingsApiSecretNotSet="parsely_api_secret_not_set",e.PluginSettingsSiteIdNotSet="parsely_site_id_not_set",e.PostIsNotPublished="ch_post_not_published",e.UnknownError="ch_unknown_error",e.ParselySuggestionsApiAuthUnavailable="AUTH_UNAVAILABLE",e.ParselySuggestionsApiNoAuthentication="NO_AUTHENTICATION",e.ParselySuggestionsApiNoAuthorization="NO_AUTHORIZATION",e.ParselySuggestionsApiNoData="NO_DATA",e.ParselySuggestionsApiOpenAiError="OPENAI_ERROR",e.ParselySuggestionsApiOpenAiSchema="OPENAI_SCHEMA",e.ParselySuggestionsApiOpenAiUnavailable="OPENAI_UNAVAILABLE",e.ParselySuggestionsApiSchemaError="SCHEMA_ERROR"}(t||(t={}));var x=function(e){function r(n,a,s){void 0===s&&(s=(0,d.__)("Error: ","wp-parsely"));var o=this;n.startsWith(s)&&(s=""),(o=e.call(this,s+n)||this).hint=null,o.name=o.constructor.name,o.code=a;var i=[t.AccessToFeatureDisabled,t.ParselyApiForbidden,t.ParselyApiResponseContainsError,t.ParselyApiReturnedNoData,t.ParselyApiReturnedTooManyResults,t.PluginCredentialsNotSetMessageDetected,t.PluginSettingsApiSecretNotSet,t.PluginSettingsSiteIdNotSet,t.PostIsNotPublished,t.UnknownError,t.ParselySuggestionsApiAuthUnavailable,t.ParselySuggestionsApiNoAuthentication,t.ParselySuggestionsApiNoAuthorization,t.ParselySuggestionsApiNoData,t.ParselySuggestionsApiSchemaError];return o.retryFetch=!i.includes(o.code),Object.setPrototypeOf(o,r.prototype),o.code===t.AccessToFeatureDisabled?o.message=(0,d.__)("Access to this feature is disabled by the site's administration.","wp-parsely"):o.code===t.ParselySuggestionsApiNoAuthorization?o.message=(0,d.__)('This AI-powered feature is opt-in. To gain access, please submit a request here.',"wp-parsely"):o.code===t.ParselySuggestionsApiOpenAiError||o.code===t.ParselySuggestionsApiOpenAiUnavailable?o.message=(0,d.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):o.code===t.HttpRequestFailed&&o.message.includes("cURL error 28")?o.message=(0,d.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):o.code===t.ParselySuggestionsApiSchemaError?o.message=(0,d.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):o.code===t.ParselySuggestionsApiNoData?o.message=(0,d.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):o.code===t.ParselySuggestionsApiOpenAiSchema?o.message=(0,d.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):o.code===t.ParselySuggestionsApiAuthUnavailable&&(o.message=(0,d.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),o}return m(r,e),r.prototype.Message=function(e){return void 0===e&&(e=null),[t.PluginCredentialsNotSetMessageDetected,t.PluginSettingsSiteIdNotSet,t.PluginSettingsApiSecretNotSet].includes(this.code)?function(e){var t;return void 0===e&&(e=null),(0,i.jsx)(b,{className:null==e?void 0:e.className,testId:"empty-credentials-message",children:null!==(t=window.wpParselyEmptyCredentialsMessage)&&void 0!==t?t:(0,d.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely")})}(e):(this.code===t.FetchError&&(this.hint=this.Hint((0,d.__)("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!==t.ParselyApiForbidden&&this.code!==t.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,d.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===t.HttpRequestFailed&&(this.hint=this.Hint((0,d.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,i.jsx)(b,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

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

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

")},r}(Error),E=function(){function e(){}return e.prototype.generateExcerpt=function(e,r){return n=this,a=void 0,o=function(){var n,a,s;return function(e,t){var r,n,a,s,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(l){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(o=0)),o;)try{if(r=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0?(0,d.sprintf)( // Translators: %1$s the number of words in the excerpt. // Translators: %1$s the number of words in the excerpt. -(0,d._n)("%1$s word","%1$s words",e,"wp-parsely"),e):"")}),[b.currentExcerpt,O]),(0,u.useEffect)((function(){var e=document.querySelector(".editor-post-excerpt textarea");e&&(e.scrollTop=0)}),[b.newExcerptGeneratedCount]),(0,s.jsxs)("div",{className:"editor-post-excerpt",children:[(0,s.jsxs)("div",{style:{position:"relative"},children:[t&&(0,s.jsx)("div",{className:"editor-post-excerpt__loading_animation",children:(0,s.jsx)(k,{})}),(0,s.jsx)(l.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,d.__)("Write an excerpt (optional)","wp-parsely"),className:"editor-post-excerpt__textarea",onChange:function(e){b.isUnderReview||j({excerpt:e}),T(A(A({},b),{currentExcerpt:e})),g(!0)},onKeyUp:function(){var e;if(h)g(!1);else{var t=document.querySelector(".editor-post-excerpt textarea"),r=null!==(e=null==t?void 0:t.textContent)&&void 0!==e?e:"";T(A(A({},b),{currentExcerpt:r}))}},value:t?"":b.isUnderReview?b.currentExcerpt:O,help:P||null})]}),(0,s.jsxs)(l.Button,{href:(0,d.__)("https://wordpress.org/documentation/article/page-post-settings-sidebar/#excerpt","wp-parsely"),target:"_blank",variant:"link",children:[(0,d.__)("Learn more about manual excerpts","wp-parsely"),(0,s.jsx)(l.Icon,{icon:f,size:18,className:"parsely-external-link-icon"})]}),(0,s.jsxs)("div",{className:"wp-parsely-excerpt-generator",children:[(0,s.jsxs)("div",{className:"wp-parsely-excerpt-generator-header",children:[(0,s.jsx)(v,{size:16}),(0,s.jsxs)("div",{className:"wp-parsely-excerpt-generator-header-label",children:[(0,d.__)("Generate With Parse.ly","wp-parsely"),(0,s.jsx)("span",{className:"beta-label",children:(0,d.__)("Beta","wp-parsely")})]})]}),o&&(0,s.jsx)(l.Notice,{className:"wp-parsely-excerpt-generator-error",onRemove:function(){return i(void 0)},status:"info",children:o.Message()}),(0,s.jsx)("div",{className:"wp-parsely-excerpt-generator-controls",children:b.isUnderReview?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(l.Button,{variant:"secondary",onClick:function(){return S(void 0,void 0,void 0,(function(){return N(this,(function(e){switch(e.label){case 0:return[4,j({excerpt:b.currentExcerpt})];case 1:return e.sent(),T(A(A({},b),{isUnderReview:!1})),w.trackEvent("excerpt_generator_accepted"),[2]}}))}))},children:(0,d.__)("Accept","wp-parsely")}),(0,s.jsx)(l.Button,{isDestructive:!0,variant:"secondary",onClick:function(){return S(void 0,void 0,void 0,(function(){return N(this,(function(e){return j({excerpt:b.oldExcerpt}),T(A(A({},b),{currentExcerpt:b.oldExcerpt,isUnderReview:!1})),w.trackEvent("excerpt_generator_discarded"),[2]}))}))},children:(0,d.__)("Discard","wp-parsely")})]}):(0,s.jsxs)(l.Button,{onClick:function(){return S(void 0,void 0,void 0,(function(){var e,t;return N(this,(function(n){switch(n.label){case 0:r(!0),i(void 0),n.label=1;case 1:return n.trys.push([1,3,4,5]),w.trackEvent("excerpt_generator_pressed"),[4,I.generateExcerpt(U,C)];case 2:return e=n.sent(),T({currentExcerpt:e,isUnderReview:!0,newExcerptGeneratedCount:b.newExcerptGeneratedCount+1,oldExcerpt:O}),[3,5];case 3:return t=n.sent(),i(t),[3,5];case 4:return r(!1),[7];case 5:return[2]}}))}))},variant:"primary",isBusy:t,disabled:t,children:[t&&(0,d.__)("Generating Excerpt…","wp-parsely"),!t&&b.newExcerptGeneratedCount>0&&(0,d.__)("Regenerate Excerpt","wp-parsely"),!t&&0===b.newExcerptGeneratedCount&&(0,d.__)("Generate Excerpt","wp-parsely")]})}),(0,s.jsxs)(l.Button,{href:"https://docs.parse.ly/plugin-content-helper/#h-excerpt-generator-beta",target:"_blank",variant:"link",children:[(0,d.__)("Learn more about Parse.ly AI","wp-parsely"),(0,s.jsx)(l.Icon,{icon:f,size:18,className:"parsely-external-link-icon"})]})]})]})},k=function(){return(0,s.jsx)(l.Animate,{type:"loading",children:function(e){var t=e.className;return(0,s.jsx)("span",{className:t,children:(0,d.__)("Generating…","wp-parsely")})}})},j=function(){return(0,s.jsx)(p.PostTypeSupportCheck,{supportKeys:"excerpt",children:(0,s.jsx)(c.PluginDocumentSettingPanel,{name:"parsely-post-excerpt",title:"Excerpt",children:(0,s.jsx)(T,{})})})};(0,a.addFilter)("plugins.registerPlugin","wp-parsely-excerpt-generator",(function(e,t){var r,s,l;return"wp-parsely-block-editor-sidebar"!==t||((null===(r=null===window||void 0===window?void 0:window.Jetpack_Editor_Initial_State)||void 0===r?void 0:r.available_blocks["ai-content-lens"])&&(console.log("Parse.ly: Jetpack AI is enabled and will be disabled."),(0,a.removeFilter)("blocks.registerBlockType","jetpack/ai-content-lens-features")),(0,o.registerPlugin)("wp-parsely-excerpt-generator",{render:j}),(null===(s=(0,n.dispatch)("core/editor"))||void 0===s?void 0:s.removeEditorPanel)?null===(l=(0,n.dispatch)("core/editor"))||void 0===l||l.removeEditorPanel("post-excerpt"):null==i||i.removeEditorPanel("post-excerpt")),e}),1e3)}()}(); \ No newline at end of file +(0,d._n)("%1$s word","%1$s words",e,"wp-parsely"),e):"")}),[x.currentExcerpt,O]),(0,u.useEffect)((function(){var e=document.querySelector(".editor-post-excerpt textarea");e&&(e.scrollTop=0)}),[x.newExcerptGeneratedCount]),(0,i.jsxs)("div",{className:"editor-post-excerpt",children:[(0,i.jsxs)("div",{style:{position:"relative"},children:[t&&(0,i.jsx)("div",{className:"editor-post-excerpt__loading_animation",children:(0,i.jsx)(k,{})}),(0,i.jsx)(l.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,d.__)("Write an excerpt (optional)","wp-parsely"),className:"editor-post-excerpt__textarea",onChange:function(e){x.isUnderReview||j({excerpt:e}),N(A(A({},x),{currentExcerpt:e})),_(!0)},onKeyUp:function(){var e;if(h)_(!1);else{var t=document.querySelector(".editor-post-excerpt textarea"),r=null!==(e=null==t?void 0:t.textContent)&&void 0!==e?e:"";N(A(A({},x),{currentExcerpt:r}))}},value:t?"":x.isUnderReview?x.currentExcerpt:O,help:P||null})]}),(0,i.jsxs)(l.Button,{href:(0,d.__)("https://wordpress.org/documentation/article/page-post-settings-sidebar/#excerpt","wp-parsely"),target:"_blank",variant:"link",children:[(0,d.__)("Learn more about manual excerpts","wp-parsely"),(0,i.jsx)(l.Icon,{icon:f,size:18,className:"parsely-external-link-icon"})]}),(0,i.jsxs)("div",{className:"wp-parsely-excerpt-generator",children:[(0,i.jsxs)("div",{className:"wp-parsely-excerpt-generator-header",children:[(0,i.jsx)(v,{size:16}),(0,i.jsxs)("div",{className:"wp-parsely-excerpt-generator-header-label",children:[(0,d.__)("Generate With Parse.ly","wp-parsely"),(0,i.jsx)("span",{className:"beta-label",children:(0,d.__)("Beta","wp-parsely")})]})]}),s&&(0,i.jsx)(l.Notice,{className:"wp-parsely-excerpt-generator-error",onRemove:function(){return o(void 0)},status:"info",children:s.Message()}),(0,i.jsx)("div",{className:"wp-parsely-excerpt-generator-controls",children:x.isUnderReview?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(l.Button,{variant:"secondary",onClick:function(){return S(void 0,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,j({excerpt:x.currentExcerpt})];case 1:return e.sent(),N(A(A({},x),{isUnderReview:!1})),w.trackEvent("excerpt_generator_accepted"),[2]}}))}))},children:(0,d.__)("Accept","wp-parsely")}),(0,i.jsx)(l.Button,{isDestructive:!0,variant:"secondary",onClick:function(){return S(void 0,void 0,void 0,(function(){return T(this,(function(e){return j({excerpt:x.oldExcerpt}),N(A(A({},x),{currentExcerpt:x.oldExcerpt,isUnderReview:!1})),w.trackEvent("excerpt_generator_discarded"),[2]}))}))},children:(0,d.__)("Discard","wp-parsely")})]}):(0,i.jsxs)(l.Button,{onClick:function(){return S(void 0,void 0,void 0,(function(){var e,t;return T(this,(function(n){switch(n.label){case 0:r(!0),o(void 0),n.label=1;case 1:return n.trys.push([1,3,4,5]),w.trackEvent("excerpt_generator_pressed"),[4,I.generateExcerpt(U,C)];case 2:return e=n.sent(),N({currentExcerpt:e,isUnderReview:!0,newExcerptGeneratedCount:x.newExcerptGeneratedCount+1,oldExcerpt:O}),[3,5];case 3:return t=n.sent(),o(t),[3,5];case 4:return r(!1),[7];case 5:return[2]}}))}))},variant:"primary",isBusy:t,disabled:t,children:[t&&(0,d.__)("Generating Excerpt…","wp-parsely"),!t&&x.newExcerptGeneratedCount>0&&(0,d.__)("Regenerate Excerpt","wp-parsely"),!t&&0===x.newExcerptGeneratedCount&&(0,d.__)("Generate Excerpt","wp-parsely")]})}),(0,i.jsxs)(l.Button,{href:"https://docs.parse.ly/plugin-content-helper/#h-excerpt-generator-beta",target:"_blank",variant:"link",children:[(0,d.__)("Learn more about Parse.ly AI","wp-parsely"),(0,i.jsx)(l.Icon,{icon:f,size:18,className:"parsely-external-link-icon"})]})]})]})},k=function(){return(0,i.jsx)(l.Animate,{type:"loading",children:function(e){var t=e.className;return(0,i.jsx)("span",{className:t,children:(0,d.__)("Generating…","wp-parsely")})}})},j=function(){return(0,i.jsx)(p.PostTypeSupportCheck,{supportKeys:"excerpt",children:(0,i.jsx)(c.PluginDocumentSettingPanel,{name:"parsely-post-excerpt",title:"Excerpt",children:(0,i.jsx)(N,{})})})};(0,a.addFilter)("plugins.registerPlugin","wp-parsely-excerpt-generator",(function(e,t){var r,i,l;return"wp-parsely-block-editor-sidebar"!==t||((null===(r=null===window||void 0===window?void 0:window.Jetpack_Editor_Initial_State)||void 0===r?void 0:r.available_blocks["ai-content-lens"])&&(console.log("Parse.ly: Jetpack AI is enabled and will be disabled."),(0,a.removeFilter)("blocks.registerBlockType","jetpack/ai-content-lens-features")),(0,s.registerPlugin)("wp-parsely-excerpt-generator",{render:j}),(null===(i=(0,n.dispatch)("core/editor"))||void 0===i?void 0:i.removeEditorPanel)?null===(l=(0,n.dispatch)("core/editor"))||void 0===l||l.removeEditorPanel("post-excerpt"):null==o||o.removeEditorPanel("post-excerpt")),e}),1e3)}()}(); \ No newline at end of file diff --git a/src/@types/assets/window.d.ts b/src/@types/assets/window.d.ts index 617e29451..e9044cd4b 100644 --- a/src/@types/assets/window.d.ts +++ b/src/@types/assets/window.d.ts @@ -24,6 +24,7 @@ declare global { }, wpParselyContentHelperSettings: string; + wpParselyContentHelperPermissions: string; wpParselyDisableAutotrack?: boolean; wpParselyEmptyCredentialsMessage: string; wpParselyHooks?: _Hooks; diff --git a/src/Endpoints/content-helper/class-smart-linking-endpoint.php b/src/Endpoints/content-helper/class-smart-linking-endpoint.php index 9a1af3f5b..d52e7e2c0 100644 --- a/src/Endpoints/content-helper/class-smart-linking-endpoint.php +++ b/src/Endpoints/content-helper/class-smart-linking-endpoint.php @@ -10,10 +10,9 @@ namespace Parsely\Endpoints\Content_Helper; -use InvalidArgumentException; use Parsely\Endpoints\Base_Endpoint; use Parsely\Models\Smart_Link; -use Parsely\Parsely; +use Parsely\Permissions; use WP_Post; use WP_REST_Request; use WP_REST_Response; @@ -45,18 +44,19 @@ class Smart_Linking_Endpoint extends Base_Endpoint { * @return bool */ public function is_available_to_current_user( $request = null ): bool { - if ( null === $request ) { - return false; + $post_id = false; + if ( $request instanceof WP_REST_Request ) { + $temp_post_id = $request->get_param( 'post_id' ); + if ( is_numeric( $temp_post_id ) ) { + $post_id = intval( $temp_post_id ); + } } - $post_id = $request->get_param( 'post_id' ); - - if ( null !== $post_id ) { - // Check if the current user has edit capabilities for the post. - $can_edit = current_user_can( 'edit_post', $post_id ); - } else { - $can_edit = current_user_can( 'edit_posts' ); - } + $can_access_pch = Permissions::current_user_can_use_pch_feature( + 'smart_linking', + $this->parsely->get_options()['content_helper'], + $post_id + ); // Check if the current user has the smart linking capability. $has_capability = current_user_can( @@ -66,7 +66,7 @@ public function is_available_to_current_user( $request = null ): bool { ) ); - return $can_edit && $has_capability; + return $can_access_pch && $has_capability; } /** diff --git a/src/Endpoints/content-suggestions/class-suggest-brief-api-proxy.php b/src/Endpoints/content-suggestions/class-suggest-brief-api-proxy.php index a143b92d4..78bb9c327 100644 --- a/src/Endpoints/content-suggestions/class-suggest-brief-api-proxy.php +++ b/src/Endpoints/content-suggestions/class-suggest-brief-api-proxy.php @@ -13,6 +13,7 @@ use Parsely\Endpoints\Base_API_Proxy; use Parsely\Parsely; +use Parsely\Permissions; use Parsely\RemoteAPI\ContentSuggestions\Suggest_Brief_API; use stdClass; use WP_REST_Request; @@ -81,6 +82,11 @@ public function get_items( WP_REST_Request $request ) { return $validation; } + $pch_options = $this->parsely->get_options()['content_helper']; + if ( ! Permissions::current_user_can_use_pch_feature( 'excerpt_suggestions', $pch_options ) ) { + return new WP_Error( 'ch_access_to_feature_disabled', '', array( 'status' => 403 ) ); + } + /** * The post content to be sent to the API. * diff --git a/src/Endpoints/content-suggestions/class-suggest-headline-api-proxy.php b/src/Endpoints/content-suggestions/class-suggest-headline-api-proxy.php index 3d446cf07..49e02a77a 100644 --- a/src/Endpoints/content-suggestions/class-suggest-headline-api-proxy.php +++ b/src/Endpoints/content-suggestions/class-suggest-headline-api-proxy.php @@ -13,6 +13,7 @@ use Parsely\Endpoints\Base_API_Proxy; use Parsely\Parsely; +use Parsely\Permissions; use Parsely\RemoteAPI\ContentSuggestions\Suggest_Headline_API; use stdClass; use WP_REST_Request; @@ -81,6 +82,11 @@ public function get_items( WP_REST_Request $request ) { return $validation; } + $pch_options = $this->parsely->get_options()['content_helper']; + if ( ! Permissions::current_user_can_use_pch_feature( 'title_suggestions', $pch_options ) ) { + return new WP_Error( 'ch_access_to_feature_disabled', '', array( 'status' => 403 ) ); + } + /** * The post content to be sent to the API. * diff --git a/src/Endpoints/content-suggestions/class-suggest-linked-reference-api-proxy.php b/src/Endpoints/content-suggestions/class-suggest-linked-reference-api-proxy.php index 444ee6306..c224155ed 100644 --- a/src/Endpoints/content-suggestions/class-suggest-linked-reference-api-proxy.php +++ b/src/Endpoints/content-suggestions/class-suggest-linked-reference-api-proxy.php @@ -13,6 +13,7 @@ use Parsely\Endpoints\Base_API_Proxy; use Parsely\Parsely; +use Parsely\Permissions; use Parsely\RemoteAPI\ContentSuggestions\Suggest_Linked_Reference_API; use stdClass; use WP_REST_Request; @@ -80,6 +81,11 @@ public function get_items( WP_REST_Request $request ) { return $validation; } + $pch_options = $this->parsely->get_options()['content_helper']; + if ( ! Permissions::current_user_can_use_pch_feature( 'smart_linking', $pch_options ) ) { + return new WP_Error( 'ch_access_to_feature_disabled', '', array( 'status' => 403 ) ); + } + /** * The post content to be sent to the API. * diff --git a/src/UI/class-settings-page.php b/src/UI/class-settings-page.php index 4d47fc57e..38970afb1 100644 --- a/src/UI/class-settings-page.php +++ b/src/UI/class-settings-page.php @@ -79,7 +79,7 @@ * * @phpstan-type Parsely_Settings_Options_Content_Helper_Feature array{ * enabled?: bool, - * allowed_user_roles?: string[], + * allowed_user_roles?: array|array * } * * @phpstan-import-type Parsely_Options from Parsely diff --git a/src/class-parsely.php b/src/class-parsely.php index fc9fec8af..4f60fb7ce 100644 --- a/src/class-parsely.php +++ b/src/class-parsely.php @@ -34,7 +34,7 @@ * track_post_types: string[], * track_page_types: string[], * track_post_types_as?: array, - * full_metadata_in_non_posts: ?bool, + * full_metadata_in_non_posts: bool, * disable_javascript: bool, * disable_amp: bool, * meta_type: string, @@ -95,15 +95,15 @@ class Parsely { 'ai_features_enabled' => true, 'smart_linking' => array( 'enabled' => true, - 'allowed_user_roles' => array(), + 'allowed_user_roles' => array( 'administrator' ), ), 'title_suggestions' => array( 'enabled' => true, - 'allowed_user_roles' => array(), + 'allowed_user_roles' => array( 'administrator' ), ), 'excerpt_suggestions' => array( 'enabled' => true, - 'allowed_user_roles' => array(), + 'allowed_user_roles' => array( 'administrator' ), ), ), 'track_authenticated_users' => false, @@ -433,10 +433,19 @@ public function get_options() { */ $options = get_option( self::OPTIONS_KEY, null ); + // @phpstan-ignore isset.offset, booleanAnd.alwaysFalse if ( is_array( $options ) && ! isset( $options['full_metadata_in_non_posts'] ) ) { + // Existing plugin installation without full metadata option. $this->set_default_full_metadata_in_non_posts(); } + // @phpstan-ignore isset.offset, booleanAnd.alwaysFalse + if ( is_array( $options ) && ! isset( $options['content_helper'] ) ) { + // Existing plugin installation without Content Helper options. + $this->set_default_content_helper_settings_values(); + } + + // New plugin installation that hasn't saved its options yet. if ( ! is_array( $options ) ) { $this->set_default_track_as_values(); $this->set_default_full_metadata_in_non_posts(); @@ -532,6 +541,22 @@ public function set_default_full_metadata_in_non_posts(): void { } } + /** + * Sets the default values for Content Helper options. + * + * Gives PCH access to all users having the edit_posts capability, to keep + * consistent behavior with plugin versions prior to 3.16.0. + * + * @since 3.16.0 + */ + public function set_default_content_helper_settings_values(): void { + $this->option_defaults['content_helper'] = + Permissions::build_pch_permissions_settings_array( + true, + array_keys( Permissions::get_user_roles_with_edit_posts_cap() ) + ); + } + /** * Gets the URL of the plugin's settings page. * diff --git a/src/class-permissions.php b/src/class-permissions.php index de648eca6..82480ea95 100644 --- a/src/class-permissions.php +++ b/src/class-permissions.php @@ -14,6 +14,9 @@ * Class implementing user/role permissions functionality. * * @since 3.16.0 + * + * @phpstan-import-type Parsely_Options_Content_Helper from Parsely + * @phpstan-import-type Parsely_Options_Content_Helper_Feature from Parsely */ class Permissions { /** @@ -39,4 +42,127 @@ public static function get_user_roles_with_edit_posts_cap(): array { return $result; } + + /** + * Returns whether the current user has the permission to access the + * specified Content Helper feature. + * + * @since 3.16.0 + * + * @param string $feature_name The feature's name. + * @param Parsely_Options_Content_Helper $pch_options The Content Helper options. + * @param int|false $post_id The post ID, if the check is for a specific post. + * @return bool Whether the current user can access the specified feature. + */ + public static function current_user_can_use_pch_feature( + string $feature_name, + $pch_options, + $post_id = false + ): bool { + if ( isset( $pch_options[ $feature_name ] ) ) { + /** + * The feature's options. + * + * @var Parsely_Options_Content_Helper_Feature $feature_options + */ + $feature_options = $pch_options[ $feature_name ]; + } else { + return false; + } + + // All AI features are disabled. + if ( true !== $pch_options['ai_features_enabled'] ) { + return false; + } + + // The specific AI feature is disabled. + if ( true !== $feature_options['enabled'] ) { + return false; + } + + // Current user's role is not yet set. + $current_user = wp_get_current_user(); + if ( 0 === count( $current_user->roles ) ) { + return false; + } + + // Check that the user's role has the capability to edit posts. + $current_user_role = $current_user->roles[0]; + $valid_roles = array_keys( self::get_user_roles_with_edit_posts_cap() ); + if ( ! in_array( $current_user_role, $valid_roles, true ) ) { + return false; + } + + // Check that the user's role has access to the specific feature/post. + $allowed_roles = $feature_options['allowed_user_roles']; + if ( in_array( $current_user_role, $allowed_roles, true ) ) { + if ( (int) $post_id > 0 ) { + return current_user_can( 'edit_post', $post_id ); + } + + return true; + } + + return false; + } + + /** + * Returns a JSON-encoded string with the Content Helper permissions for the + * current user. + * + * @since 3.16.0 + * + * @param Parsely_Options_Content_Helper $pch_options The options to check against. + * @return string The JSON-encoded permissions string. + */ + public static function get_pch_permissions_json( $pch_options ): string { + $permissions = array(); + $features = array( + 'SmartLinking' => 'smart_linking', + 'TitleSuggestions' => 'title_suggestions', + ); + + foreach ( $features as $key => $value ) { + $permissions[ $key ] = self::current_user_can_use_pch_feature( + $value, + $pch_options, + get_the_ID() + ); + } + + $result = wp_json_encode( $permissions ); + + return is_string( $result ) ? $result : '{}'; + } + + /** + * Builds and returns a permissions settings array for the Content Helper, + * based on the passed values. + * + * @since 3.16.0 + * + * @param bool $enabled Whether to enable the features. + * @param array $allowed_user_roles The allowed user roles. + * @return Parsely_Options_Content_Helper The resulting permissions settings. + */ + public static function build_pch_permissions_settings_array( + bool $enabled, + array $allowed_user_roles + ) { + return array( + 'ai_features_enabled' => $enabled, + 'smart_linking' => array( + 'enabled' => $enabled, + 'allowed_user_roles' => $allowed_user_roles, + ), + 'title_suggestions' => array( + 'enabled' => $enabled, + 'allowed_user_roles' => $allowed_user_roles, + ), + 'excerpt_suggestions' => array( + 'enabled' => $enabled, + 'allowed_user_roles' => $allowed_user_roles, + ), + ); + } } diff --git a/src/content-helper/common/class-content-helper-feature.php b/src/content-helper/common/class-content-helper-feature.php index dd57a6d48..374f2b281 100644 --- a/src/content-helper/common/class-content-helper-feature.php +++ b/src/content-helper/common/class-content-helper-feature.php @@ -11,6 +11,7 @@ namespace Parsely\Content_Helper; use Parsely\Parsely; +use Parsely\Permissions; use WP_REST_Request; /** @@ -128,6 +129,17 @@ protected function inject_inline_scripts( $are_credentials_set = $this->parsely->site_id_is_set() && $this->parsely->api_secret_is_set(); + // Inject Content Helper permissions. + $permissions_json = Permissions::get_pch_permissions_json( + $this->parsely->get_options()['content_helper'] + ); + wp_add_inline_script( + static::get_script_id(), + "window.wpParselyContentHelperPermissions = '$permissions_json';", + 'before' + ); + + // Inject a message if the required credentials are not set. if ( ! $are_credentials_set ) { $message = $this->get_credentials_not_set_message(); diff --git a/src/content-helper/common/content-helper-error.tsx b/src/content-helper/common/content-helper-error.tsx index 33ef1c4f9..886c6a148 100644 --- a/src/content-helper/common/content-helper-error.tsx +++ b/src/content-helper/common/content-helper-error.tsx @@ -18,6 +18,7 @@ import { * Helper should start with a "ch_" prefix. */ export enum ContentHelperErrorCode { + AccessToFeatureDisabled = 'ch_access_to_feature_disabled', CannotFormulateApiQuery = 'ch_cannot_formulate_api_query', FetchError = 'fetch_error', // apiFetch() failure, possibly caused by ad blocker. HttpRequestFailed = 'http_request_failed', // Parse.ly API is unreachable. @@ -70,6 +71,7 @@ export class ContentHelperError extends Error { // Errors for which we should not retry a fetch operation. const noRetryFetchErrors: Array = [ + ContentHelperErrorCode.AccessToFeatureDisabled, ContentHelperErrorCode.ParselyApiForbidden, ContentHelperErrorCode.ParselyApiResponseContainsError, ContentHelperErrorCode.ParselyApiReturnedNoData, @@ -95,7 +97,12 @@ export class ContentHelperError extends Error { Object.setPrototypeOf( this, ContentHelperError.prototype ); // Errors that need rephrasing. - if ( this.code === ContentHelperErrorCode.ParselySuggestionsApiNoAuthorization ) { + if ( this.code === ContentHelperErrorCode.AccessToFeatureDisabled ) { + this.message = __( + 'Access to this feature is disabled by the site\'s administration.', + 'wp-parsely' + ); + } else if ( this.code === ContentHelperErrorCode.ParselySuggestionsApiNoAuthorization ) { this.message = __( 'This AI-powered feature is opt-in. To gain access, please submit a request ' + 'here.', diff --git a/src/content-helper/common/utils/permissions.ts b/src/content-helper/common/utils/permissions.ts new file mode 100644 index 000000000..541462987 --- /dev/null +++ b/src/content-helper/common/utils/permissions.ts @@ -0,0 +1,35 @@ +/** + * Defines the structure of a Content Helper Permissions object. + * + * @since 3.16.0 + */ +export interface ContentHelperPermissions { + SmartLinking: boolean; + TitleSuggestions: boolean; +} + +/** + * Returns the current user's permissions for the Content Helper. + * + * @since 3.16.0 + * + * @return {ContentHelperPermissions} The current user's permissions. + */ +export function getContentHelperPermissions(): ContentHelperPermissions { + const defaultPermissions: ContentHelperPermissions = { + SmartLinking: false, + TitleSuggestions: false, + }; + + try { + const permissions = JSON.parse( window.wpParselyContentHelperPermissions ); + + if ( 'object' !== typeof permissions || null === permissions ) { + return defaultPermissions; + } + + return permissions; + } catch ( e ) { + return defaultPermissions; + } +} diff --git a/src/content-helper/editor-sidebar/editor-sidebar.tsx b/src/content-helper/editor-sidebar/editor-sidebar.tsx index eba6fd548..944c8b62c 100644 --- a/src/content-helper/editor-sidebar/editor-sidebar.tsx +++ b/src/content-helper/editor-sidebar/editor-sidebar.tsx @@ -30,6 +30,7 @@ import { PostFilterType, isInEnum, } from '../common/utils/constants'; +import { getContentHelperPermissions } from '../common/utils/permissions'; import { DEFAULT_MAX_LINKS, initSmartLinking, @@ -177,6 +178,7 @@ export const getSettingsFromJson = ( settingsJson: string = '' ): SidebarSetting */ const ContentHelperEditorSidebar = (): React.JSX.Element => { const { settings, setSettings } = useSettings(); + const permissions = getContentHelperPermissions(); /** * Track sidebar opening. @@ -244,7 +246,10 @@ const ContentHelperEditorSidebar = (): React.JSX.Element => { { ( tab ) => ( <> { tab.name === 'tools' && ( - + ) } { tab.name === 'performance' && ( register_taxonomy( 'smart_link_destination', __( 'Smart Link Destination', 'wp-parsely' ) ); } + /** + * Returns whether the feature can be enabled for the current user. + * + * @since 3.16.0 + * + * @param bool ...$conditions Conditions that need to be met besides filters + * for the function to return true. + * @return bool Whether the feature can be enabled. + */ + protected function can_enable_feature( bool ...$conditions ): bool { + if ( ! parent::can_enable_feature( ...$conditions ) ) { + return false; + } + + return Permissions::current_user_can_use_pch_feature( + 'smart_linking', + $this->parsely->get_options()['content_helper'], + get_the_ID() + ); + } + /** * Registers the custom post type for the Smart Links. * diff --git a/src/content-helper/editor-sidebar/smart-linking/component.tsx b/src/content-helper/editor-sidebar/smart-linking/component.tsx index 2a84629fa..f262557f1 100644 --- a/src/content-helper/editor-sidebar/smart-linking/component.tsx +++ b/src/content-helper/editor-sidebar/smart-linking/component.tsx @@ -18,6 +18,7 @@ import { Telemetry } from '../../../js/telemetry/telemetry'; import { ContentHelperError, ContentHelperErrorCode } from '../../common/content-helper-error'; import { SidebarSettings, SmartLinkingSettings, useSettings } from '../../common/settings'; import { generateProtocolVariants } from '../../common/utils/functions'; +import { ContentHelperPermissions } from '../../common/utils/permissions'; import { LinkMonitor } from './component-link-monitor'; import { SmartLinkingSettings as SmartLinkingSettingsComponent } from './component-settings'; import { useSaveSmartLinksOnPostSave, useSmartLinksValidation } from './hooks'; @@ -41,6 +42,7 @@ type SmartLinkingPanelProps = { className?: string; selectedBlockClientId?: string; context?: SmartLinkingPanelContext; + permissions: ContentHelperPermissions; } /** @@ -74,6 +76,7 @@ export const SmartLinkingPanel = ( { className, selectedBlockClientId, context = SmartLinkingPanelContext.Unknown, + permissions, }: Readonly ): React.JSX.Element => { const { settings, setSettings } = useSettings(); @@ -195,6 +198,10 @@ export const SmartLinkingPanel = ( { * @since 3.16.0 */ useEffect( () => { + if ( true !== permissions.SmartLinking ) { + return; + } + if ( ready ) { // Return early if the Smart Linking store is already initialized. return; @@ -228,7 +235,14 @@ export const SmartLinkingPanel = ( { setIsReady( true ); } ); } - }, [ addInboundSmartLinks, addSmartLinks, postId, ready, setIsReady ] ); + }, [ + addInboundSmartLinks, + addSmartLinks, + postId, + ready, + setIsReady, + permissions.SmartLinking, + ] ); /** * Handles the ending of the review process. diff --git a/src/content-helper/editor-sidebar/smart-linking/smart-linking.tsx b/src/content-helper/editor-sidebar/smart-linking/smart-linking.tsx index 39ccb77f7..08f4a7d00 100644 --- a/src/content-helper/editor-sidebar/smart-linking/smart-linking.tsx +++ b/src/content-helper/editor-sidebar/smart-linking/smart-linking.tsx @@ -15,6 +15,7 @@ import { Telemetry } from '../../../js/telemetry/telemetry'; import { LeafIcon } from '../../common/icons/leaf-icon'; import { SettingsProvider, SidebarSettings, useSettings } from '../../common/settings'; import { isEditorReady } from '../../common/utils/functions'; +import { getContentHelperPermissions } from '../../common/utils/permissions'; import { VerifyCredentials } from '../../common/verify-credentials'; import { getSettingsFromJson } from '../editor-sidebar'; import { SmartLinkingPanel, SmartLinkingPanelContext } from './component'; @@ -23,6 +24,7 @@ import './smart-linking.scss'; import { selectSmartLink } from './utils'; export const DEFAULT_MAX_LINKS = 10; +const permissions = getContentHelperPermissions(); /** * Higher order component to add the settings provider to the block edit component. @@ -85,6 +87,7 @@ const SmartLinkingInspectorControlPanel = createHigherOrderComponent( ( BlockEdi @@ -112,6 +115,10 @@ const SmartLinkingPanelWithSettingsProvider = compose( * @since 3.14.0 */ export const initSmartLinking = (): void => { + if ( true !== permissions.SmartLinking ) { + return; + } + /** * Add smart linking inspector control panel to paragraph block. */ diff --git a/src/content-helper/editor-sidebar/tabs/sidebar-tools-tab.tsx b/src/content-helper/editor-sidebar/tabs/sidebar-tools-tab.tsx index de16737f6..49fc1d38b 100644 --- a/src/content-helper/editor-sidebar/tabs/sidebar-tools-tab.tsx +++ b/src/content-helper/editor-sidebar/tabs/sidebar-tools-tab.tsx @@ -8,6 +8,7 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import { SidebarSettings, useSettings } from '../../common/settings'; +import { ContentHelperPermissions } from '../../common/utils/permissions'; import { VerifyCredentials } from '../../common/verify-credentials'; import { RelatedPostsPanel } from '../related-posts/component'; import { SmartLinkingPanel, SmartLinkingPanelContext } from '../smart-linking/component'; @@ -20,6 +21,7 @@ import { TitleSuggestionsPanel } from '../title-suggestions/component'; */ type SidebarToolsTabProps = { trackToggle: ( panel: string, next: boolean ) => void + permissions: ContentHelperPermissions; } /** @@ -31,49 +33,54 @@ type SidebarToolsTabProps = { * @param {SidebarToolsTabProps} props The component's props. */ export const SidebarToolsTab = ( - { trackToggle }: Readonly + { trackToggle, permissions }: Readonly ): React.JSX.Element => { const { settings, setSettings } = useSettings(); return ( - { - setSettings( { - TitleSuggestions: { - ...settings.TitleSuggestions, - Open: next, - }, - } ); - trackToggle( 'title_suggestions', next ); - } } - > - - - - + { permissions.TitleSuggestions && + { + setSettings( { + TitleSuggestions: { + ...settings.TitleSuggestions, + Open: next, + }, + } ); + trackToggle( 'title_suggestions', next ); + } } + > + + + + + } - { - setSettings( { - SmartLinking: { - ...settings.SmartLinking, - Open: next, - }, - } ); - trackToggle( 'smart_linking', next ); - } } - > - - - - + { permissions.SmartLinking && + { + setSettings( { + SmartLinking: { + ...settings.SmartLinking, + Open: next, + }, + } ); + trackToggle( 'smart_linking', next ); + } } + > + + + + + } parsely->get_options()['content_helper'], + get_the_ID() + ); + } } diff --git a/tests/Integration/UI/SettingsPageTest.php b/tests/Integration/UI/SettingsPageTest.php index 1df698c01..e0ac1a958 100644 --- a/tests/Integration/UI/SettingsPageTest.php +++ b/tests/Integration/UI/SettingsPageTest.php @@ -21,6 +21,8 @@ * Integration Tests for the plugin's wp-admin Settings page. * * @since 3.1.0 + * + * @phpstan-import-type ParselySettingOptions from Settings_Page */ final class SettingsPageTest extends TestCase { /** @@ -89,7 +91,9 @@ public function test_empty_api_credentials_are_retained_when_validated(): void { $options['apikey'] = 'mydomain.com'; $options['api_secret'] = 'valid_api_secret'; - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $options, $actual ); // Now try to set it back to empty values. @@ -98,7 +102,9 @@ public function test_empty_api_credentials_are_retained_when_validated(): void { $options['apikey'] = ''; $options['api_secret'] = ''; - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $options, $actual ); } @@ -137,7 +143,9 @@ public function test_valid_api_credentials_are_retained_when_validated(): void { $expected = $options; - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); } @@ -179,7 +187,9 @@ public function test_invalid_api_credentials_are_reset_to_their_previous_value_w $options['apikey'] = 'mydomain.com'; $options['api_secret'] = 'invalid_api_secret'; - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); remove_filter( 'pre_http_request', array( $this, 'mock_request_api_credentials_validation_failure' ), 10 ); } @@ -223,7 +233,9 @@ public function test_empty_api_secret_is_retained_when_validated(): void { $expected = $options; - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); remove_filter( 'pre_http_request', array( $this, 'mock_request_api_credentials_validation_failure' ), 10 ); @@ -262,7 +274,9 @@ public function test_valid_metadata_secret_values_are_retained_when_validated(): $options['metadata_secret'] = 'goodlength'; // 10 characters. $expected = $options; - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); } @@ -299,12 +313,16 @@ public function test_invalid_metadata_secret_values_are_emptied_when_validated() $options['metadata_secret'] = 'too_short'; // Less than 10 characters. - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); $options['metadata_secret'] = 'too_lengthy'; // More than 10 characters. - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); } @@ -349,7 +367,9 @@ function () { } ); - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); } @@ -376,7 +396,9 @@ public function test_save_tracking_settings(): void { 'attachment' => 'post', ); - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( array( 'post', 'attachment' ), $actual['track_post_types'] ); self::assertSame( array( 'page' ), $actual['track_page_types'] ); } @@ -407,7 +429,9 @@ public function test_saving_tracking_settings_for_non_existent_post_type_should_ 'non_existent_post_type' => 'post', ); - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); } @@ -430,7 +454,9 @@ public function test_trying_to_save_unset_tracking_settings_should_fail(): void $options = self::$parsely->get_options(); unset( $options['track_post_types_as'] ); - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); } @@ -453,7 +479,9 @@ public function test_trying_to_save_empty_array_tracking_settings_should_fail(): $options = self::$parsely->get_options(); $options['track_post_types_as'] = array(); - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); } @@ -476,7 +504,10 @@ public function test_trying_to_save_non_array_tracking_settings_should_fail(): v $options = self::$parsely->get_options(); $options['track_post_types_as'] = 'string'; - $actual = self::$settings_page->validate_options( $options ); // @phpstan-ignore-line + $actual = self::$settings_page->validate_options( + // @phpstan-ignore argument.type + $this->transform_pch_options_for_validation( $options ) + ); self::assertSame( $expected, $actual ); } @@ -499,7 +530,9 @@ public function test_saving_disable_autotrack_works_default_value(): void { $options = self::$parsely->get_options(); unset( $options['disable_autotrack'] ); - $actual = self::$settings_page->validate_options( $options ); + $actual = self::$settings_page->validate_options( + $this->transform_pch_options_for_validation( $options ) + ); self::assertEquals( $expected, $actual ); } @@ -704,6 +737,23 @@ private function mock_request_api_credentials_validation( string $result_type, a ); } + /** + * Transforms Content Helper options to the format expected by the + * validation function of the Settings_Page class. + * + * @since 3.16.0 + * + * @param ParselySettingOptions $options The options to transform. + * @return ParselySettingOptions The transformed options. + */ + private function transform_pch_options_for_validation( $options ) { + $options['content_helper']['smart_linking']['allowed_user_roles'] = array( 'administrator' => true ); + $options['content_helper']['title_suggestions']['allowed_user_roles'] = array( 'administrator' => true ); + $options['content_helper']['excerpt_suggestions']['allowed_user_roles'] = array( 'administrator' => true ); + + return $options; + } + /** * Provides data for the test_managed_option_title_html_is_correct test. *