From 0a7f241d6229f467e5483db645832bfe5e050320 Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Fri, 5 Jul 2024 16:13:56 +0100 Subject: [PATCH] Fix issue when generating excerpt for empty content (#2609) --- .../content-helper/dashboard-widget.asset.php | 2 +- build/content-helper/dashboard-widget.js | 2 +- build/content-helper/editor-sidebar.asset.php | 2 +- build/content-helper/editor-sidebar.js | 2 +- .../excerpt-generator.asset.php | 2 +- build/content-helper/excerpt-generator.js | 4 +- src/content-helper/common/base-provider.tsx | 8 ++- .../components/excerpt-panel.tsx | 19 +++-- .../excerpt-generator/provider.ts | 70 +++++++++---------- 9 files changed, 62 insertions(+), 49 deletions(-) diff --git a/build/content-helper/dashboard-widget.asset.php b/build/content-helper/dashboard-widget.asset.php index 200309a54..e9331a046 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' => '90d10f8d4634a269395a'); + array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'a741adf6df6b723b2f3d'); diff --git a/build/content-helper/dashboard-widget.js b/build/content-helper/dashboard-widget.js index aed781aad..50392fc4b 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.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,f.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),O=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 N=function(e,t){d.trackEvent("dash_widget_filter_changed",W({filter:e},t))},j=(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}),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}),N("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:[j,g.Message(),S>1&&C]});var k=(0,a.jsx)("div",{className:"parsely-spinner-wrapper",children:(0,a.jsx)(p.Spinner,{})});return(0,a.jsxs)(a.Fragment,{children:[j,u?k:(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.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,f.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),O=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,l;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 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 k=(0,a.jsx)("div",{className:"parsely-spinner-wrapper",children:(0,a.jsx)(p.Spinner,{})});return(0,a.jsxs)(a.Fragment,{children:[N,u?k:(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 ef0e02951..0f2c9aef6 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' => '189b30aafaa619830baf'); + 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' => '629f8616ef4e8194995e'); diff --git a/build/content-helper/editor-sidebar.js b/build/content-helper/editor-sidebar.js index cc4f03390..e0cd1a51c 100644 --- a/build/content-helper/editor-sidebar.js +++ b/build/content-helper/editor-sidebar.js @@ -1,4 +1,4 @@ -!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.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,a.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},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&&y((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:g[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",onClick:function(){v.trackEvent("smart_linking_open_in_editor_pressed",{type:"inbound",uid:o.uid})},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()},g=(0,i.jsxs)("span",{className:"smart-linking-menu-label",children:[(0,p.__)("NEW","wp-parsely"),(0,i.jsx)(Me,{})]}),y=[];n&&n.length>0&&y.push({name:"outbound",title:(0,p.__)("Outbound","wp-parsely")}),r&&r.length>0&&y.push({name:"inbound",title:(0,p.__)("Inbound","wp-parsely")});var m="outbound";return y=y.filter((function(e){return"outbound"===e.name&&r&&0===r.length&&(e.title=(0,p.__)("Outbound Smart Links","wp-parsely"),m="outbound"),"inbound"===e.name&&n&&0===n.length&&(e.title=(0,p.__)("Inbound Smart Links","wp-parsely"),m="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:m,tabs:y,onSelect:function(e){var t,i;"outbound"===e&&n&&n.length>0&&a(n[0]),"inbound"===e&&r&&r.length>0&&a(r[0]),v.trackEvent("smart_linking_modal_tab_selected",{tab:e,total_inbound:null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0,total_outbound:null!==(i=null==n?void 0:n.length)&&void 0!==i?i: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&&g]},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,E(t.uid)]):[2]):[2];case 1:return p.sent(),[2]}}))}))},C=(0,u.useCallback)((function(){h(!1),x().filter((function(e){return!e.applied})).length>0?c(!0):(Z.unlockPostAutosaving("smart-linking-review-modal"),t())}),[x,t]),A=function(e){c(!1),e?(h(!1),T().then((function(){C()}))):h(!0)},O=function(){if(ee(S)){var e=w.indexOf(S);if(!w[t=e+1])return;P(w[t])}else{var t;if(e=m.indexOf(S),!m[t=e+1])return;P(m[t])}},R=function(){if(ee(S)){var e=w.indexOf(S);if(!w[t=e-1])return;P(w[t])}else{var t;if(e=m.indexOf(S),!m[t=e-1])return;P(m[t])}};return(0,u.useEffect)((function(){f?Z.lockPostAutosaving("smart-linking-review-modal"):f&&0===y.length&&C()}),[f,t,y,C]),(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:C,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,children:(0,i.jsxs)("div",{className:"smart-linking-modal-body",children:[(0,i.jsx)(Fe,{outboundLinks:m,inboundLinks:w,activeLink:S,setSelectedLink:P}),S&&(ee(S)?(0,i.jsx)(Be,{link:S,onNext:O,onPrevious:R,hasNext:w.indexOf(S)0}):(0,i.jsx)(Ue,{link:S,hasNext:_().indexOf(S)<_().length-1,hasPrevious:_().indexOf(S)>0,onNext:O,onPrevious:R,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 S.match?(r(S),[4,(i=S.match.blockId,s=S,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,L(s)]):[2];case 1:return n.sent(),[2]}}))})))]):[2];case 1:return n.sent(),v.trackEvent("smart_linking_link_accepted",{link:S.href,title:S.title,text:S.text,uid:S.uid}),0===b().length?(C(),[2]):(e=m.indexOf(S),m[t=e+1]?P(m[t]):P(m[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=m.indexOf(S),m[t=e+1]?P(m[t]):m[0]?P(m[0]):C(),[4,E(S.uid)];case 1:return n.sent(),v.trackEvent("smart_linking_link_rejected",{link:S.href,title:S.title,text:S.text,uid:S.uid}),[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 S.match?(e=(0,a.select)("core/block-editor").getBlock(S.match.blockId))?(t=_(),n=t.indexOf(S),r=n-1,[4,N(e,S)]):[3,2]:[2];case 1:if(i.sent(),v.trackEvent("smart_linking_link_removed",{link:S.href,title:S.title,text:S.text,uid:S.uid}),0===(t=_()).length&&w.length>0)return P(w[0]),[2];if(0===t.length&&0===w.length)return C(),[2];if(t[r])return P(t[r]),[2];P(t[0]),i.label=2;case 2:return[2]}}))}))},onSelectInEditor:function(){if(S.match){var e=(0,a.select)("core/block-editor").getBlock(S.match.blockId);if(e){q.selectBlock(e.clientId);var t=document.querySelector('[data-block="'.concat(e.clientId,'"]'));t&&de(t,S.uid),v.trackEvent("smart_linking_select_in_editor_pressed",{type:"outbound",uid:S.uid}),C()}}}}))]})}),l&&(0,i.jsxs)(s.Modal,{title:(0,p.__)("Review Smart Links","wp-parsely"),onRequestClose:function(){return A(!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 A(!1)},children:(0,p.__)("Go Back","wp-parsely")}),(0,i.jsx)(s.Button,{variant:"primary",onClick:function(){return A(!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 */ +!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.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,a.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},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&&y((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:g[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",onClick:function(){v.trackEvent("smart_linking_open_in_editor_pressed",{type:"inbound",uid:o.uid})},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()},g=(0,i.jsxs)("span",{className:"smart-linking-menu-label",children:[(0,p.__)("NEW","wp-parsely"),(0,i.jsx)(Me,{})]}),y=[];n&&n.length>0&&y.push({name:"outbound",title:(0,p.__)("Outbound","wp-parsely")}),r&&r.length>0&&y.push({name:"inbound",title:(0,p.__)("Inbound","wp-parsely")});var m="outbound";return y=y.filter((function(e){return"outbound"===e.name&&r&&0===r.length&&(e.title=(0,p.__)("Outbound Smart Links","wp-parsely"),m="outbound"),"inbound"===e.name&&n&&0===n.length&&(e.title=(0,p.__)("Inbound Smart Links","wp-parsely"),m="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:m,tabs:y,onSelect:function(e){var t,i;"outbound"===e&&n&&n.length>0&&a(n[0]),"inbound"===e&&r&&r.length>0&&a(r[0]),v.trackEvent("smart_linking_modal_tab_selected",{tab:e,total_inbound:null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0,total_outbound:null!==(i=null==n?void 0:n.length)&&void 0!==i?i: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&&g]},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,E(t.uid)]):[2]):[2];case 1:return p.sent(),[2]}}))}))},C=(0,u.useCallback)((function(){h(!1),x().filter((function(e){return!e.applied})).length>0?c(!0):(Z.unlockPostAutosaving("smart-linking-review-modal"),t())}),[x,t]),A=function(e){c(!1),e?(h(!1),T().then((function(){C()}))):h(!0)},O=function(){if(ee(S)){var e=w.indexOf(S);if(!w[t=e+1])return;P(w[t])}else{var t;if(e=m.indexOf(S),!m[t=e+1])return;P(m[t])}},R=function(){if(ee(S)){var e=w.indexOf(S);if(!w[t=e-1])return;P(w[t])}else{var t;if(e=m.indexOf(S),!m[t=e-1])return;P(m[t])}};return(0,u.useEffect)((function(){f?Z.lockPostAutosaving("smart-linking-review-modal"):f&&0===y.length&&C()}),[f,t,y,C]),(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:C,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,children:(0,i.jsxs)("div",{className:"smart-linking-modal-body",children:[(0,i.jsx)(Fe,{outboundLinks:m,inboundLinks:w,activeLink:S,setSelectedLink:P}),S&&(ee(S)?(0,i.jsx)(Be,{link:S,onNext:O,onPrevious:R,hasNext:w.indexOf(S)0}):(0,i.jsx)(Ue,{link:S,hasNext:_().indexOf(S)<_().length-1,hasPrevious:_().indexOf(S)>0,onNext:O,onPrevious:R,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 S.match?(r(S),[4,(i=S.match.blockId,s=S,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,L(s)]):[2];case 1:return n.sent(),[2]}}))})))]):[2];case 1:return n.sent(),v.trackEvent("smart_linking_link_accepted",{link:S.href,title:S.title,text:S.text,uid:S.uid}),0===b().length?(C(),[2]):(e=m.indexOf(S),m[t=e+1]?P(m[t]):P(m[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=m.indexOf(S),m[t=e+1]?P(m[t]):m[0]?P(m[0]):C(),[4,E(S.uid)];case 1:return n.sent(),v.trackEvent("smart_linking_link_rejected",{link:S.href,title:S.title,text:S.text,uid:S.uid}),[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 S.match?(e=(0,a.select)("core/block-editor").getBlock(S.match.blockId))?(t=_(),n=t.indexOf(S),r=n-1,[4,N(e,S)]):[3,2]:[2];case 1:if(i.sent(),v.trackEvent("smart_linking_link_removed",{link:S.href,title:S.title,text:S.text,uid:S.uid}),0===(t=_()).length&&w.length>0)return P(w[0]),[2];if(0===t.length&&0===w.length)return C(),[2];if(t[r])return P(t[r]),[2];P(t[0]),i.label=2;case 2:return[2]}}))}))},onSelectInEditor:function(){if(S.match){var e=(0,a.select)("core/block-editor").getBlock(S.match.blockId);if(e){q.selectBlock(e.clientId);var t=document.querySelector('[data-block="'.concat(e.clientId,'"]'));t&&de(t,S.uid),v.trackEvent("smart_linking_select_in_editor_pressed",{type:"outbound",uid:S.uid}),C()}}}}))]})}),l&&(0,i.jsxs)(s.Modal,{title:(0,p.__)("Review Smart Links","wp-parsely"),onRequestClose:function(){return A(!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 A(!1)},children:(0,p.__)("Go Back","wp-parsely")}),(0,i.jsx)(s.Button,{variant:"primary",onClick:function(){return A(!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;return Ye(this,(function(u){switch(u.label){case 0:return[4,ee(!0)];case 1:return u.sent(),[4,be()];case 2:return u.sent(),[4,te(null)];case 3:return u.sent(),k(!1),v.trackEvent("smart_linking_generate_pressed",{is_full_content:N,selected_block:null!==(a=null==Le?void 0:Le.name)&&void 0!==a?a:"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:u.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,u.label=5;case 5:return u.trys.push([5,8,10,15]),[4,Ce(3)];case 6:return r=u.sent(),[4,(d=r,Ke(void 0,void 0,void 0,(function(){var e;return Ye(this,(function(t){switch(t.label){case 0:return d=d.filter((function(e){return!G.some((function(t){return t.uid===e.uid&&t.applied}))})),e=Ne.replace(/^https?:\/\//,"").replace(/\/+$/,""),d=(d=d.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)}))})),d=(d=se(N?Se:[Le],d,{}).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(d)];case 1:return t.sent(),[2]}}))})))];case 7:return u.sent(),_e(!0),[3,15];case 8:return i=u.sent(),s=new $(null!==(l=i.message)&&void 0!==l?l:"An unknown error has occurred.",null!==(c=i.code)&&void 0!==c?c:M.UnknownError),i.code&&i.code===M.ParselyAborted&&(s.message=(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"))),console.error(i),[4,te(s)];case 9:return u.sent(),s.createErrorSnackbar(),[3,15];case 10:return[4,ee(!1)];case 11:return u.sent(),[4,de(n)];case 12:return u.sent(),[4,he(!1)];case 13:return u.sent(),[4,Oe(N?"all":null==Le?void 0:Le.clientId)];case 14:return u.sent(),clearTimeout(t),[7];case 15:return[2]}var d}))}))},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 */ diff --git a/build/content-helper/excerpt-generator.asset.php b/build/content-helper/excerpt-generator.asset.php index 93d8ef14c..8e4b311df 100644 --- a/build/content-helper/excerpt-generator.asset.php +++ b/build/content-helper/excerpt-generator.asset.php @@ -1 +1 @@ - 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' => '24552cd6b0e986d2d486'); + 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' => '020225d87d32e61d3c23'); diff --git a/build/content-helper/excerpt-generator.js b/build/content-helper/excerpt-generator.js index 4fe7c8ef2..bc058a476 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"),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.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,n.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},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)( +!function(){"use strict";var e={20:function(e,t,r){var n=r(609),o=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=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,a={},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)s.call(t,n)&&!l.hasOwnProperty(n)&&(a[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===a[n]&&(a[n]=t[n]);return{$$typeof:o,type:e,key:c,ref:u,props:a,_owner:i.current}}t.Fragment=a,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 o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,r),a.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,o=window.wp.hooks,a=window.wp.plugins,s=((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,u=window.wp.editor,p=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,a=function(t,r){var n;return void 0===r&&(r={}),function(e,t){var r,n,o,a,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(l){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=1e4&&(clearInterval(a),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){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}})}),g=(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 _=function(e){function r(n,o,a){void 0===a&&(a=(0,d.__)("Error: ","wp-parsely"));var s=this;n.startsWith(a)&&(a=""),(s=e.call(this,a+n)||this).hint=null,s.name=s.constructor.name,s.code=o;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 s.retryFetch=!i.includes(s.code),Object.setPrototypeOf(s,r.prototype),s.code===t.AccessToFeatureDisabled?s.message=(0,d.__)("Access to this feature is disabled by the site's administration.","wp-parsely"):s.code===t.ParselySuggestionsApiNoAuthorization?s.message=(0,d.__)('This AI-powered feature is opt-in. To gain access, please submit a request here.',"wp-parsely"):s.code===t.ParselySuggestionsApiOpenAiError||s.code===t.ParselySuggestionsApiOpenAiUnavailable?s.message=(0,d.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):s.code===t.HttpRequestFailed&&s.message.includes("cURL error 28")?s.message=(0,d.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):s.code===t.ParselySuggestionsApiSchemaError?s.message=(0,d.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):s.code===t.ParselySuggestionsApiNoData?s.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"):s.code===t.ParselySuggestionsApiOpenAiSchema?s.message=(0,d.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):s.code===t.ParselySuggestionsApiAuthUnavailable&&(s.message=(0,d.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),s}return g(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)(v,{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)(v,{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.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,n.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},r}(Error),b=function(e){var t=e.size,r=void 0===t?24:t,n=e.className,o=void 0===n?"wp-parsely-icon":n;return(0,i.jsxs)(l.SVG,{className:o,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"})]})},m=window.wp.url,P=window.wp.apiFetch,x=r.n(P),E=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,r){return n=this,o=void 0,s=function(){var n,o,a,s,i,l;return function(e,t){var r,n,o,a,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(l){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[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):"")}),[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 +(0,d._n)("%1$s word","%1$s words",e,"wp-parsely"),e):"")}),[A.currentExcerpt,R]),(0,p.useEffect)((function(){var e=document.querySelector(".editor-post-excerpt textarea");e&&(e.scrollTop=0)}),[A.newExcerptGeneratedCount]),(0,i.jsxs)("div",{className:"editor-post-excerpt",children:[(0,i.jsxs)("div",{style:{position:"relative"},children:[r&&(0,i.jsx)("div",{className:"editor-post-excerpt__loading_animation",children:(0,i.jsx)(C,{})}),(0,i.jsx)(l.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,d.__)("Write an excerpt (optional)","wp-parsely"),className:"editor-post-excerpt__textarea",onChange:function(e){A.isUnderReview||I({excerpt:e}),j(k(k({},A),{currentExcerpt:e})),g(!0)},onKeyUp:function(){var e;if(v)g(!1);else{var t=document.querySelector(".editor-post-excerpt textarea"),r=null!==(e=null==t?void 0:t.textContent)&&void 0!==e?e:"";j(k(k({},A),{currentExcerpt:r}))}},value:r?"":A.isUnderReview?A.currentExcerpt:R,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)(b,{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 c(void 0)},status:"info",children:s.Message()}),(0,i.jsx)("div",{className:"wp-parsely-excerpt-generator-controls",children:A.isUnderReview?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(l.Button,{variant:"secondary",onClick:function(){return T(void 0,void 0,void 0,(function(){return N(this,(function(e){switch(e.label){case 0:return[4,I({excerpt:A.currentExcerpt})];case 1:return e.sent(),j(k(k({},A),{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 T(void 0,void 0,void 0,(function(){return N(this,(function(e){return I({excerpt:A.oldExcerpt}),j(k(k({},A),{currentExcerpt:A.oldExcerpt,isUnderReview:!1})),w.trackEvent("excerpt_generator_discarded"),[2]}))}))},children:(0,d.__)("Discard","wp-parsely")})]}):(0,i.jsxs)(l.Button,{onClick:function(){return T(void 0,void 0,void 0,(function(){var e,r;return N(this,(function(n){switch(n.label){case 0:o(!0),c(void 0),n.label=1;case 1:return n.trys.push([1,3,4,5]),w.trackEvent("excerpt_generator_pressed"),[4,S.getInstance().generateExcerpt(F,U)];case 2:return e=n.sent(),j({currentExcerpt:e,isUnderReview:!0,newExcerptGeneratedCount:A.newExcerptGeneratedCount+1,oldExcerpt:R}),[3,5];case 3:return(r=n.sent())instanceof _?c(r):(c(new _((0,d.__)("An unknown error occurred.","wp-parsely"),t.UnknownError)),console.error(r)),[3,5];case 4:return o(!1),[7];case 5:return[2]}}))}))},variant:"primary",isBusy:r,disabled:r||!U,children:[r&&(0,d.__)("Generating Excerpt…","wp-parsely"),!r&&A.newExcerptGeneratedCount>0&&(0,d.__)("Regenerate Excerpt","wp-parsely"),!r&&0===A.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"})]})]})]})},C=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")})}})},I=function(){return(0,i.jsx)(u.PostTypeSupportCheck,{supportKeys:"excerpt",children:(0,i.jsx)(c.PluginDocumentSettingPanel,{name:"parsely-post-excerpt",title:"Excerpt",children:(0,i.jsx)(j,{})})})};(0,o.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,o.removeFilter)("blocks.registerBlockType","jetpack/ai-content-lens-features")),(0,a.registerPlugin)("wp-parsely-excerpt-generator",{render:I}),(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==s||s.removeEditorPanel("post-excerpt")),e}),1e3)}()}(); \ No newline at end of file diff --git a/src/content-helper/common/base-provider.tsx b/src/content-helper/common/base-provider.tsx index 77c5ffab7..4018b7c9e 100644 --- a/src/content-helper/common/base-provider.tsx +++ b/src/content-helper/common/base-provider.tsx @@ -171,7 +171,13 @@ export abstract class BaseProvider { ); } - return Promise.reject( new ContentHelperError( wpError.message, wpError.code ) ); + let errorMessage = wpError.message; + // The error message might be an object with multiple messages. + if ( typeof wpError.message === 'object' && wpError.message[ 0 ].msg ) { + errorMessage = wpError.message[ 0 ].msg; + } + + return Promise.reject( new ContentHelperError( errorMessage, wpError.code ) ); } finally { // Clean-up the AbortController after a successful request. this.abortControllers.delete( abortId ); diff --git a/src/content-helper/excerpt-generator/components/excerpt-panel.tsx b/src/content-helper/excerpt-generator/components/excerpt-panel.tsx index d21b5e843..ee73d398f 100644 --- a/src/content-helper/excerpt-generator/components/excerpt-panel.tsx +++ b/src/content-helper/excerpt-generator/components/excerpt-panel.tsx @@ -21,7 +21,7 @@ import { count } from '@wordpress/wordcount'; import { external } from '@wordpress/icons'; import { GutenbergFunction } from '../../../@types/gutenberg/types'; import { Telemetry } from '../../../js/telemetry/telemetry'; -import { ContentHelperError } from '../../common/content-helper-error'; +import { ContentHelperError, ContentHelperErrorCode } from '../../common/content-helper-error'; import { LeafIcon } from '../../common/icons/leaf-icon'; import { ExcerptGeneratorProvider } from '../provider'; @@ -55,7 +55,6 @@ const PostExcerptGenerator = () => { } ); const { editPost } = useDispatch( editorStore ); - const excerptGeneratorProvider = new ExcerptGeneratorProvider(); // Get the current excerpt, post content, and post title. const { excerpt, postContent, postTitle } = useSelect( ( select ) => { @@ -124,15 +123,23 @@ const PostExcerptGenerator = () => { try { Telemetry.trackEvent( 'excerpt_generator_pressed' ); - const requestedExcerpt = await excerptGeneratorProvider.generateExcerpt( postTitle, postContent ); + const requestedExcerpt = await ExcerptGeneratorProvider.getInstance().generateExcerpt( + postTitle, + postContent + ); setExcerptData( { currentExcerpt: requestedExcerpt, isUnderReview: true, newExcerptGeneratedCount: excerptData.newExcerptGeneratedCount + 1, oldExcerpt: excerpt, } ); - } catch ( err: any ) { // eslint-disable-line @typescript-eslint/no-explicit-any - setError( err ); + } catch ( err: unknown ) { + if ( err instanceof ContentHelperError ) { + setError( err ); + } else { + setError( new ContentHelperError( __( 'An unknown error occurred.', 'wp-parsely' ), ContentHelperErrorCode.UnknownError ) ); + console.error( err ); // eslint-disable-line no-console + } } finally { setLoading( false ); } @@ -265,7 +272,7 @@ const PostExcerptGenerator = () => { onClick={ generateExcerpt } variant="primary" isBusy={ isLoading } - disabled={ isLoading } + disabled={ isLoading || ! postContent } > { isLoading && __( 'Generating Excerpt…', 'wp-parsely' ) } { ! isLoading && excerptData.newExcerptGeneratedCount > 0 && diff --git a/src/content-helper/excerpt-generator/provider.ts b/src/content-helper/excerpt-generator/provider.ts index 75b4e39ab..6fb4dcaf0 100644 --- a/src/content-helper/excerpt-generator/provider.ts +++ b/src/content-helper/excerpt-generator/provider.ts @@ -1,31 +1,41 @@ /** * WordPress dependencies */ -import apiFetch from '@wordpress/api-fetch'; import { addQueryArgs } from '@wordpress/url'; /** * Internal dependencies */ -import { ContentHelperError, ContentHelperErrorCode } from '../common/content-helper-error'; - -/** - * Specifies the form of the response returned by the - * `/content-suggestions/suggest-brief` WordPress REST API endpoint. - * - * @since 3.13.0 - */ -interface ExcerptGeneratorApiResponse { - error?: Error; - data: string; -} +import { BaseProvider } from '../common/base-provider'; /** * Provides the generate excerpt functionality to be used in other components. * * @since 3.13.0 */ -export class ExcerptGeneratorProvider { +export class ExcerptGeneratorProvider extends BaseProvider { + /** + * The singleton instance of the ExcerptGeneratorProvider. + * + * @since 3.16.0 + */ + private static instance: ExcerptGeneratorProvider; + + /** + * Returns the singleton instance of the TitleSuggestionsProvider. + * + * @since 3.16.0 + * + * @return {ExcerptGeneratorProvider} The singleton instance. + */ + public static getInstance(): ExcerptGeneratorProvider { + if ( ! this.instance ) { + this.instance = new ExcerptGeneratorProvider(); + } + + return this.instance; + } + /** * Generates an excerpt for a given post. * @@ -35,28 +45,18 @@ export class ExcerptGeneratorProvider { * @return {Promise} The generated excerpt. */ public async generateExcerpt( title: string, content: string ): Promise { - let response; - try { - response = await apiFetch( { - method: 'POST', - path: addQueryArgs( '/wp-parsely/v1/content-suggestions/suggest-brief', { - title, - } ), - data: { - content, - }, - } ); - } catch ( wpError: any ) { // eslint-disable-line @typescript-eslint/no-explicit-any - return Promise.reject( new ContentHelperError( wpError.message, wpError.code ) ); - } - - if ( response?.error ) { - return Promise.reject( new ContentHelperError( - response.error.message, - ContentHelperErrorCode.ParselyApiResponseContainsError - ) ); + if ( '' === title ) { + title = 'Untitled'; } - return response?.data ?? ''; + return await this.fetch( { + method: 'POST', + path: addQueryArgs( '/wp-parsely/v1/content-suggestions/suggest-brief', { + title, + } ), + data: { + content, + }, + } ); } }