diff --git a/build/content-helper/editor-sidebar.asset.php b/build/content-helper/editor-sidebar.asset.php index 22a5f56bca..3b41b13d3f 100644 --- a/build/content-helper/editor-sidebar.asset.php +++ b/build/content-helper/editor-sidebar.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => 'cdab4fcca4b787c82aa2'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => 'c3e7dc1ccdd9065ce0db'); diff --git a/build/content-helper/editor-sidebar.js b/build/content-helper/editor-sidebar.js index 88556a5332..f60acfd621 100644 --- a/build/content-helper/editor-sidebar.js +++ b/build/content-helper/editor-sidebar.js @@ -14,7 +14,7 @@ text:"".concat(c(t)," - ").concat((0,w.sprintf)((0,w.__)("%s%%","wp-parsely"),n.viewsPercentage)),delay:150,children:(0,f.jsx)("div",{"aria-label":r,className:"bar-fill "+t,style:{width:n.viewsPercentage+"%"}})},t)}))}),(0,f.jsx)("div",{className:"percentage-bar-labels",children:Object.entries(t.referrers.types).map((function(e){var t=e[0],n=e[1];return(0,f.jsxs)("div",{className:"single-label "+t,children:[(0,f.jsx)("div",{className:"label-color "+t}),(0,f.jsx)("div",{className:"label-text",children:c(t)}),(0,f.jsx)("div",{className:"label-value",children:Ft(n.views)})]},t)}))})]})]})},gn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M12 4V2.2L9 4.8l3 2.5V5.5c3.6 0 6.5 2.9 6.5 6.5 0 2.9-1.9 5.3-4.5 6.2v.2l-.1-.2c-.4.1-.7.2-1.1.2l.2 1.5c.3 0 .6-.1 1-.2 3.5-.9 6-4 6-7.7 0-4.4-3.6-8-8-8zm-7.9 7l1.5.2c.1-1.2.5-2.3 1.2-3.2l-1.1-.9C4.8 8.2 4.3 9.6 4.1 11zm1.5 1.8l-1.5.2c.1.7.3 1.4.5 2 .3.7.6 1.3 1 1.8l1.2-.8c-.3-.5-.6-1-.8-1.5s-.4-1.1-.4-1.7zm1.5 5.5c1.1.9 2.4 1.4 3.8 1.6l.2-1.5c-1.1-.1-2.2-.5-3.1-1.2l-.9 1.1z"})}),yn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M11 13h2v-2h-2v2zm-6 0h2v-2H5v2zm12-2v2h2v-2h-2z"})}),mn=function(){return mn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]%s has 0 views, or the Parse.ly API returned no data.","wp-parsely"),r),U.ParselyApiReturnedNoData,""))]):n.length>1?[2,Promise.reject(new te((0,w.sprintf)(/* translators: URL of the published post */ /* translators: URL of the published post */ -(0,w.__)("Multiple results were returned for the post %d by the Parse.ly API.","wp-parsely"),t),U.ParselyApiReturnedTooManyResults))]:[2,n[0]]}}))}))},t.prototype.fetchReferrerDataFromWpEndpoint=function(e,t,n){return Nn(this,void 0,void 0,(function(){return Cn(this,(function(r){switch(r.label){case 0:return[4,this.fetch({path:(0,we.addQueryArgs)("/wp-parsely/v2/stats/post/".concat(t,"/referrers"),Ln(Ln({},pt(e)),{itm_source:this.itmSource,total_views:n}))})];case 1:return[2,r.sent()]}}))}))},t}(be),On=function(){return On=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return t.sent(),[4,n(r-1)];case 2:return t.sent(),[3,4];case 3:a(e),i(!1),t.label=4;case 4:return[2]}}))}))})),[2]}))}))};return i(!0),n(1),function(){a(void 0)}}),[t]),(0,f.jsxs)("div",{className:"wp-parsely-performance-panel",children:[(0,f.jsx)(hn,{title:(0,w.__)("Performance Stats","wp-parsely"),icon:fn,dropdownChildren:function(e){var t=e.onClose;return(0,f.jsx)(Fn,{onClose:t})},children:(0,f.jsx)("div",{className:"panel-settings",children:(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:d.PerformanceStats.Period,prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Period:","wp-parsely")}),onChange:function(e){F(e,R)&&(v({PerformanceStats:On(On({},d.PerformanceStats),{Period:e})}),k.trackEvent("editor_sidebar_performance_period_changed",{period:e}))},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})})}),s?s.Message():(0,f.jsxs)(f.Fragment,{children:[Dn(d,"overview")&&(0,f.jsx)(Pn,{data:c,isLoading:r}),Dn(d,"categories")&&(0,f.jsx)(vn,{data:c,isLoading:r}),Dn(d,"referrers")&&(0,f.jsx)(Tn,{data:c,isLoading:r})]}),window.wpParselyPostUrl&&(0,f.jsx)(h.Button,{className:"wp-parsely-view-post",variant:"primary",onClick:function(){k.trackEvent("editor_sidebar_view_post_pressed")},href:window.wpParselyPostUrl,rel:"noopener",target:"_blank",children:(0,w.__)("View this in Parse.ly","wp-parsely")})]})},Gn=function(e){var t=e.period;return(0,f.jsx)(h.Panel,{children:(0,f.jsx)(Ie,{children:(0,f.jsx)(Vn,{period:t})})})},Hn=function(e){var t=e.filters,n=e.postData,r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Author","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Author)},options:i,value:t.author}),n.categories.length>=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Section","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Section)},options:o,value:t.section}),n.tags.length>=1&&(0,f.jsx)(h.FormTokenField,{__experimentalShowHowTo:!1,__next40pxDefaultSize:!0,label:"",placeholder:(0,w.__)("Tags","wp-parsely"),onChange:function(e){return r.onFiltersChange(e.toString(),M.Tag)},value:t.tags,suggestions:n.tags,maxLength:5})]})},zn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z"})}),Un=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M5.625 5.5h9.75c.069 0 .125.056.125.125v9.75a.125.125 0 0 1-.125.125h-9.75a.125.125 0 0 1-.125-.125v-9.75c0-.069.056-.125.125-.125ZM4 5.625C4 4.728 4.728 4 5.625 4h9.75C16.273 4 17 4.728 17 5.625v9.75c0 .898-.727 1.625-1.625 1.625h-9.75A1.625 1.625 0 0 1 4 15.375v-9.75Zm14.5 11.656v-9H20v9C20 18.8 18.77 20 17.251 20H6.25v-1.5h11.001c.69 0 1.249-.528 1.249-1.219Z"})}),qn=function(){return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"1",height:"40",viewBox:"0 0 1 40",fill:"none",children:(0,f.jsx)(h.Rect,{width:"1",height:"40",fill:"#cccccc"})})};function Kn(e){var t=e.metric,n=e.post,r=e.avgEngagedIcon,i=e.viewsIcon;return"views"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Number of Views","wp-parsely")}),i,Ft(n.views.toString())]}):"avg_engaged"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Average Time","wp-parsely")}),r,n.avgEngaged]}):(0,f.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}var Zn,Wn=function(e){var t,n,r=e.metric,i=e.post,o=e.postContent,s=(0,v.useDispatch)("core/notices").createNotice,a=o&&(t=o,n=Ae(i.rawUrl),new RegExp("]*href=[\"'](http://|https://)?.*".concat(n,".*[\"'][^>]*>"),"i").test(t));return(0,f.jsxs)("div",{className:"related-post-single","data-testid":"related-post-single",children:[(0,f.jsx)("div",{className:"related-post-title",children:(0,f.jsxs)("a",{href:i.url,target:"_blank",rel:"noreferrer",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("View on website (opens new tab)","wp-parsely")}),i.title]})}),(0,f.jsx)("div",{className:"related-post-actions",children:(0,f.jsxs)("div",{className:"related-post-info",children:[(0,f.jsxs)("div",{children:[(0,f.jsx)("div",{className:"related-post-metric",children:(0,f.jsx)(Kn,{metric:r,post:i,viewsIcon:(0,f.jsx)(ie,{icon:It}),avgEngagedIcon:(0,f.jsx)(h.Dashicon,{icon:"clock",size:24})})}),a&&(0,f.jsx)("div",{className:"related-post-linked",children:(0,f.jsx)(h.Tooltip,{text:(0,w.__)("This post is linked in the content","wp-parsely"),children:(0,f.jsx)(ie,{icon:zn,size:24})})})]}),(0,f.jsx)(qn,{}),(0,f.jsxs)("div",{children:[(0,f.jsx)(h.Button,{icon:Un,iconSize:24,onClick:function(){navigator.clipboard.writeText(i.rawUrl).then((function(){s("success",(0,w.__)("URL copied to clipboard","wp-parsely"),{type:"snackbar"})}))},label:(0,w.__)("Copy URL to clipboard","wp-parsely")}),(0,f.jsx)(h.Button,{icon:(0,f.jsx)(j,{}),iconSize:18,href:i.dashUrl,target:"_blank",label:(0,w.__)("View in Parse.ly","wp-parsely")})]})]})})]})},Yn=window.wp.coreData,$n=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function __(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(__.prototype=n.prototype,new __)}}(),Jn=function(){return Jn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&f.every(Number.isInteger)?null!==(n=l("taxonomy","category",{include:f,context:"view"}))&&void 0!==n?n:void 0:null,tagRecords:s=Array.isArray(h)&&h.length>0&&h.every(Number.isInteger)?null!==(r=l("taxonomy","post_tag",{include:h,context:"view"}))&&void 0!==r?r:void 0:null,isLoading:u("getEntityRecords",["root","user",{include:[d],context:"view"}])||u("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||u("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}]),hasResolved:(c("getEntityRecords",["root","user",{include:[d],context:"view"}])||null===i)&&(c("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||null===o)&&(c("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}])||null===s)}}),[]);return(0,m.useEffect)((function(){var e=r.authorRecords,t=r.categoryRecords,i=r.tagRecords,o=r.isLoading;r.hasResolved&&!o&&n({authors:e,categories:t,tags:i,isReady:!0})}),[r]),t}(),c=l.authors,u=l.categories,p=l.tags,d=l.isReady;(0,m.useEffect)((function(){if(d){var e=function(e){return function(e){return!(!Array.isArray(e)||0===e.length)&&e.every((function(e){return"name"in e&&"id"in e&&"slug"in e&&"description"in e&&"link"in e}))}(e)?e.map((function(e){return e.name})):[]};a({authors:e(c),categories:e(u),tags:e(p)})}}),[c,u,p,d]);var g=(0,m.useState)(!0),y=g[0],b=g[1],x=(0,m.useState)(),_=x[0],S=x[1],j=(0,m.useState)([]),P=j[0],T=j[1],E=(0,m.useState)({author:"",section:"",tags:[]}),L=E[0],N=E[1],C=(0,m.useState)(void 0),A=C[0],O=C[1],D=(0,ne.useDebounce)(O,1e3);return(0,v.useSelect)((function(e){if("undefined"==typeof jest){var t=e("core/editor").getEditedPostContent;D(t())}else D("Jest test is running")}),[D]),(0,m.useEffect)((function(){var e=function(t){return nr(void 0,void 0,void 0,(function(){return rr(this,(function(n){return er.getInstance().getRelatedPosts(r,i,L).then((function(e){T(e),b(!1)})).catch((function(n){return nr(void 0,void 0,void 0,(function(){return rr(this,(function(r){switch(r.label){case 0:return t>0&&n.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,e(t-1)];case 2:return r.sent(),[3,4];case 3:b(!1),S(n),r.label=4;case 4:return[2]}}))}))})),[2]}))}))};return b(!0),e(1),function(){b(!1),T([]),S(void 0)}}),[r,i,L,s]),0===s.authors.length&&0===s.categories.length&&0===s.tags.length&&d?(0,f.jsx)("div",{className:"wp-parsely-related-posts",children:(0,f.jsx)("div",{className:"related-posts-body",children:(0,w.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,f.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,f.jsx)("div",{className:"related-posts-description",children:(0,w.__)("Find top-performing related posts.","wp-parsely")}),(0,f.jsxs)("div",{className:"related-posts-body",children:[(0,f.jsxs)("div",{className:"related-posts-settings",children:[(0,f.jsx)(h.SelectControl,{size:"__unstable-large",onChange:function(e){var r;F(r=e,B)&&(n({RelatedPosts:tr(tr({},t.RelatedPosts),{Metric:r})}),k.trackEvent("related_posts_metric_changed",{metric:r}))},prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Metric:","wp-parsely")}),value:i,children:Object.values(B).map((function(e){return(0,f.jsx)("option",{value:e,children:G(e)},e)}))}),(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:r,prefix:(0,f.jsxs)(h.__experimentalInputControlPrefixWrapper,{children:[(0,w.__)("Period:","wp-parsely")," "]}),onChange:function(e){return function(e){F(e,R)&&(n({RelatedPosts:tr(tr({},t.RelatedPosts),{Period:e})}),k.trackEvent("related_posts_period_changed",{period:e}))}(e)},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})]}),(0,f.jsx)(Hn,{label:(0,w.__)("Filter by","wp-parsely"),filters:L,onFiltersChange:function(e,t){var n;if(null==e&&(e=""),M.Tag===t){var r=[];""!==e&&(r=e.split(",").map((function(e){return e.trim()}))),N(tr(tr({},L),{tags:r}))}else N(tr(tr({},L),((n={})[t]=e,n)))},postData:s}),(0,f.jsxs)("div",{className:"related-posts-wrapper",children:[_&&_.Message(),y&&(0,f.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,w.__)("Loading…","wp-parsely")}),!y&&!_&&0===P.length&&(0,f.jsx)("div",{className:"related-posts-empty",children:(0,w.__)("No related posts found.","wp-parsely")}),!y&&P.length>0&&(0,f.jsx)("div",{className:"related-posts-list",children:P.map((function(e){return(0,f.jsx)(Wn,{metric:i,post:e,postContent:A},e.id)}))})]})]})]})},or=(0,f.jsx)(b.SVG,{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10.97 10.159a3.382 3.382 0 0 0-2.857.955l1.724 1.723-2.836 2.913L7 17h1.25l2.913-2.837 1.723 1.723a3.38 3.38 0 0 0 .606-.825c.33-.63.446-1.343.35-2.032L17 10.695 13.305 7l-2.334 3.159Z"})}),sr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M18.3 11.7c-.6-.6-1.4-.9-2.3-.9H6.7l2.9-3.3-1.1-1-4.5 5L8.5 16l1-1-2.7-2.7H16c.5 0 .9.2 1.3.5 1 1 1 3.4 1 4.5v.3h1.5v-.2c0-1.5 0-4.3-1.5-5.7z"})}),ar=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z"})}),lr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m21.5 9.1-6.6-6.6-4.2 5.6c-1.2-.1-2.4.1-3.6.7-.1 0-.1.1-.2.1-.5.3-.9.6-1.2.9l3.7 3.7-5.7 5.7v1.1h1.1l5.7-5.7 3.7 3.7c.4-.4.7-.8.9-1.2.1-.1.1-.2.2-.3.6-1.1.8-2.4.6-3.6l5.6-4.1zm-7.3 3.5.1.9c.1.9 0 1.8-.4 2.6l-6-6c.8-.4 1.7-.5 2.6-.4l.9.1L15 4.9 19.1 9l-4.9 3.6z"})}),cr=function(){return cr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,f.jsx)("span",{className:"parsely-write-titles-text",children:(0,m.createInterpolateElement)( +(0,w.__)("Multiple results were returned for the post %d by the Parse.ly API.","wp-parsely"),t),U.ParselyApiReturnedTooManyResults))]:[2,n[0]]}}))}))},t.prototype.fetchReferrerDataFromWpEndpoint=function(e,t,n){return Nn(this,void 0,void 0,(function(){return Cn(this,(function(r){switch(r.label){case 0:return[4,this.fetch({path:(0,we.addQueryArgs)("/wp-parsely/v2/stats/post/".concat(t,"/referrers"),Ln(Ln({},pt(e)),{itm_source:this.itmSource,total_views:n}))})];case 1:return[2,r.sent()]}}))}))},t}(be),On=function(){return On=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return t.sent(),[4,n(r-1)];case 2:return t.sent(),[3,4];case 3:a(e),i(!1),t.label=4;case 4:return[2]}}))}))})),[2]}))}))};return i(!0),n(1),function(){a(void 0)}}),[t]),(0,f.jsxs)("div",{className:"wp-parsely-performance-panel",children:[(0,f.jsx)(hn,{title:(0,w.__)("Performance Stats","wp-parsely"),icon:fn,dropdownChildren:function(e){var t=e.onClose;return(0,f.jsx)(Fn,{onClose:t})},children:(0,f.jsx)("div",{className:"panel-settings",children:(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:d.PerformanceStats.Period,prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Period:","wp-parsely")}),onChange:function(e){F(e,R)&&(v({PerformanceStats:On(On({},d.PerformanceStats),{Period:e})}),k.trackEvent("editor_sidebar_performance_period_changed",{period:e}))},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})})}),s?s.Message():(0,f.jsxs)(f.Fragment,{children:[Dn(d,"overview")&&(0,f.jsx)(Pn,{data:c,isLoading:r}),Dn(d,"categories")&&(0,f.jsx)(vn,{data:c,isLoading:r}),Dn(d,"referrers")&&(0,f.jsx)(Tn,{data:c,isLoading:r})]}),window.wpParselyPostUrl&&(0,f.jsx)(h.Button,{className:"wp-parsely-view-post",variant:"primary",onClick:function(){k.trackEvent("editor_sidebar_view_post_pressed")},href:window.wpParselyPostUrl,rel:"noopener",target:"_blank",children:(0,w.__)("View this in Parse.ly","wp-parsely")})]})},Gn=function(e){var t=e.period;return(0,f.jsx)(h.Panel,{children:(0,f.jsx)(Ie,{children:(0,f.jsx)(Vn,{period:t})})})},Hn=function(e){var t=e.filters,n=e.postData,r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Author","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Author)},options:o,value:t.author}),n.categories.length>=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Section","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Section)},options:i,value:t.section}),n.tags.length>=1&&(0,f.jsx)(h.FormTokenField,{__experimentalShowHowTo:!1,__next40pxDefaultSize:!0,label:"",placeholder:(0,w.__)("Tags","wp-parsely"),onChange:function(e){return r.onFiltersChange(e.toString(),M.Tag)},value:t.tags,suggestions:n.tags,maxLength:5})]})},zn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z"})}),Un=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M5.625 5.5h9.75c.069 0 .125.056.125.125v9.75a.125.125 0 0 1-.125.125h-9.75a.125.125 0 0 1-.125-.125v-9.75c0-.069.056-.125.125-.125ZM4 5.625C4 4.728 4.728 4 5.625 4h9.75C16.273 4 17 4.728 17 5.625v9.75c0 .898-.727 1.625-1.625 1.625h-9.75A1.625 1.625 0 0 1 4 15.375v-9.75Zm14.5 11.656v-9H20v9C20 18.8 18.77 20 17.251 20H6.25v-1.5h11.001c.69 0 1.249-.528 1.249-1.219Z"})}),qn=function(){return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"1",height:"40",viewBox:"0 0 1 40",fill:"none",children:(0,f.jsx)(h.Rect,{width:"1",height:"40",fill:"#cccccc"})})};function Kn(e){var t=e.metric,n=e.post,r=e.avgEngagedIcon,i=e.viewsIcon;return"views"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Number of Views","wp-parsely")}),i,Ft(n.views.toString())]}):"avg_engaged"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Average Time","wp-parsely")}),r,n.avgEngaged]}):(0,f.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}var Zn,Wn=function(e){var t,n,r=e.metric,i=e.post,o=e.postContent,s=(0,v.useDispatch)("core/notices").createNotice,a=o&&(t=o,n=Ae(i.rawUrl),new RegExp("]*href=[\"'](http://|https://)?.*".concat(n,".*[\"'][^>]*>"),"i").test(t));return(0,f.jsxs)("div",{className:"related-post-single","data-testid":"related-post-single",children:[(0,f.jsx)("div",{className:"related-post-title",children:(0,f.jsxs)("a",{href:i.url,target:"_blank",rel:"noreferrer",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("View on website (opens new tab)","wp-parsely")}),i.title]})}),(0,f.jsx)("div",{className:"related-post-actions",children:(0,f.jsxs)("div",{className:"related-post-info",children:[(0,f.jsxs)("div",{children:[(0,f.jsx)("div",{className:"related-post-metric",children:(0,f.jsx)(Kn,{metric:r,post:i,viewsIcon:(0,f.jsx)(ie,{icon:It}),avgEngagedIcon:(0,f.jsx)(h.Dashicon,{icon:"clock",size:24})})}),a&&(0,f.jsx)("div",{className:"related-post-linked",children:(0,f.jsx)(h.Tooltip,{text:(0,w.__)("This post is linked in the content","wp-parsely"),children:(0,f.jsx)(ie,{icon:zn,size:24})})})]}),(0,f.jsx)(qn,{}),(0,f.jsxs)("div",{children:[(0,f.jsx)(h.Button,{icon:Un,iconSize:24,onClick:function(){navigator.clipboard.writeText(i.rawUrl).then((function(){s("success",(0,w.__)("URL copied to clipboard","wp-parsely"),{type:"snackbar"})}))},label:(0,w.__)("Copy URL to clipboard","wp-parsely")}),(0,f.jsx)(h.Button,{icon:(0,f.jsx)(j,{}),iconSize:18,href:i.dashUrl,target:"_blank",label:(0,w.__)("View in Parse.ly","wp-parsely")})]})]})})]})},Yn=window.wp.coreData,$n=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function __(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(__.prototype=n.prototype,new __)}}(),Jn=function(){return Jn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&f.every(Number.isInteger)?null!==(n=l("taxonomy","category",{include:f,context:"view"}))&&void 0!==n?n:void 0:null,tagRecords:s=Array.isArray(h)&&h.length>0&&h.every(Number.isInteger)?null!==(r=l("taxonomy","post_tag",{include:h,context:"view"}))&&void 0!==r?r:void 0:null,isLoading:u("getEntityRecords",["root","user",{include:[d],context:"view"}])||u("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||u("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}]),hasResolved:(c("getEntityRecords",["root","user",{include:[d],context:"view"}])||null===i)&&(c("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||null===o)&&(c("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}])||null===s)}}),[]);return(0,m.useEffect)((function(){var e=r.authorRecords,t=r.categoryRecords,i=r.tagRecords,o=r.isLoading;r.hasResolved&&!o&&n({authors:e,categories:t,tags:i,isReady:!0})}),[r]),t}(),c=l.authors,u=l.categories,p=l.tags,d=l.isReady,g=function(e){return!(!Array.isArray(e)||0===e.length)&&e.every((function(e){return"name"in e&&"id"in e&&"slug"in e&&"description"in e&&"link"in e}))};(0,m.useEffect)((function(){if(d){var e,t=function(e){return g(e)?e.map((function(e){return e.name})):[]};a({authors:t(c),categories:(e=u,g(e)?e.map((function(e){return{name:e.name,slug:e.slug}})):[]),tags:t(p)})}}),[c,u,p,d]);var y=(0,m.useState)(!0),b=y[0],x=y[1],_=(0,m.useState)(),S=_[0],j=_[1],P=(0,m.useState)([]),T=P[0],E=P[1],L=(0,m.useState)({author:"",section:"",tags:[]}),N=L[0],C=L[1],A=(0,m.useState)(void 0),O=A[0],D=A[1],H=(0,ne.useDebounce)(D,1e3);return(0,v.useSelect)((function(e){if("undefined"==typeof jest){var t=e("core/editor").getEditedPostContent;H(t())}else H("Jest test is running")}),[H]),(0,m.useEffect)((function(){var e=function(t){return nr(void 0,void 0,void 0,(function(){return rr(this,(function(n){return er.getInstance().getRelatedPosts(r,i,N).then((function(e){E(e),x(!1)})).catch((function(n){return nr(void 0,void 0,void 0,(function(){return rr(this,(function(r){switch(r.label){case 0:return t>0&&n.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,e(t-1)];case 2:return r.sent(),[3,4];case 3:x(!1),j(n),r.label=4;case 4:return[2]}}))}))})),[2]}))}))};return x(!0),e(1),function(){x(!1),E([]),j(void 0)}}),[r,i,N,s]),0===s.authors.length&&0===s.categories.length&&0===s.tags.length&&d?(0,f.jsx)("div",{className:"wp-parsely-related-posts",children:(0,f.jsx)("div",{className:"related-posts-body",children:(0,w.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,f.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,f.jsx)("div",{className:"related-posts-description",children:(0,w.__)("Find top-performing related posts.","wp-parsely")}),(0,f.jsxs)("div",{className:"related-posts-body",children:[(0,f.jsxs)("div",{className:"related-posts-settings",children:[(0,f.jsx)(h.SelectControl,{size:"__unstable-large",onChange:function(e){var r;F(r=e,B)&&(n({RelatedPosts:tr(tr({},t.RelatedPosts),{Metric:r})}),k.trackEvent("related_posts_metric_changed",{metric:r}))},prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Metric:","wp-parsely")}),value:i,children:Object.values(B).map((function(e){return(0,f.jsx)("option",{value:e,children:G(e)},e)}))}),(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:r,prefix:(0,f.jsxs)(h.__experimentalInputControlPrefixWrapper,{children:[(0,w.__)("Period:","wp-parsely")," "]}),onChange:function(e){return function(e){F(e,R)&&(n({RelatedPosts:tr(tr({},t.RelatedPosts),{Period:e})}),k.trackEvent("related_posts_period_changed",{period:e}))}(e)},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})]}),(0,f.jsx)(Hn,{label:(0,w.__)("Filter by","wp-parsely"),filters:N,onFiltersChange:function(e,t){var n;if(null==e&&(e=""),M.Tag===t){var r=[];""!==e&&(r=e.split(",").map((function(e){return e.trim()}))),C(tr(tr({},N),{tags:r}))}else C(tr(tr({},N),((n={})[t]=e,n)))},postData:s}),(0,f.jsxs)("div",{className:"related-posts-wrapper",children:[S&&S.Message(),b&&(0,f.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,w.__)("Loading…","wp-parsely")}),!b&&!S&&0===T.length&&(0,f.jsx)("div",{className:"related-posts-empty",children:(0,w.__)("No related posts found.","wp-parsely")}),!b&&T.length>0&&(0,f.jsx)("div",{className:"related-posts-list",children:T.map((function(e){return(0,f.jsx)(Wn,{metric:i,post:e,postContent:O},e.id)}))})]})]})]})},or=(0,f.jsx)(b.SVG,{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10.97 10.159a3.382 3.382 0 0 0-2.857.955l1.724 1.723-2.836 2.913L7 17h1.25l2.913-2.837 1.723 1.723a3.38 3.38 0 0 0 .606-.825c.33-.63.446-1.343.35-2.032L17 10.695 13.305 7l-2.334 3.159Z"})}),sr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M18.3 11.7c-.6-.6-1.4-.9-2.3-.9H6.7l2.9-3.3-1.1-1-4.5 5L8.5 16l1-1-2.7-2.7H16c.5 0 .9.2 1.3.5 1 1 1 3.4 1 4.5v.3h1.5v-.2c0-1.5 0-4.3-1.5-5.7z"})}),ar=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z"})}),lr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m21.5 9.1-6.6-6.6-4.2 5.6c-1.2-.1-2.4.1-3.6.7-.1 0-.1.1-.2.1-.5.3-.9.6-1.2.9l3.7 3.7-5.7 5.7v1.1h1.1l5.7-5.7 3.7 3.7c.4-.4.7-.8.9-1.2.1-.1.1-.2.2-.3.6-1.1.8-2.4.6-3.6l5.6-4.1zm-7.3 3.5.1.9c.1.9 0 1.8-.4 2.6l-6-6c.8-.4 1.7-.5 2.6-.4l.9.1L15 4.9 19.1 9l-4.9 3.6z"})}),cr=function(){return cr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,f.jsx)("span",{className:"parsely-write-titles-text",children:(0,m.createInterpolateElement)( // translators: %1$s is the tone, %2$s is the persona. // translators: %1$s is the tone, %2$s is the persona. (0,w.__)("We've generated a few titles based on the content of your post, written as a .","wp-parsely"),{tone:(0,f.jsx)("strong",{children:he(a)}),persona:(0,f.jsx)("strong",{children:le(u)})})}):(0,w.__)("Use Parse.ly AI to generate a title for your post.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/title-suggestions/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Parse.ly AI","wp-parsely"),(0,f.jsx)(ie,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),i&&(0,f.jsx)(h.Notice,{className:"wp-parsely-content-helper-error",onRemove:function(){return o(void 0)},status:"info",children:i.Message()}),void 0!==S&&(0,f.jsx)(gr,{title:S,type:Zn.PostTitle,isOriginal:!0}),00&&(0,f.jsx)(yr,{pinnedTitles:b,isOpen:!0}),y.length>0&&(0,f.jsx)(wr,{suggestions:y,isOpen:!0,isLoading:g})]}),(0,f.jsx)(mr,{isLoading:g,onPersonaChange:function(e){C("Persona",e),p(e)},onSettingChange:C,onToneChange:function(e){C("Tone",e),l(e)},persona:t.TitleSuggestions.Persona,tone:t.TitleSuggestions.Tone}),(0,f.jsx)("div",{className:"title-suggestions-generate",children:(0,f.jsxs)(h.Button,{variant:"primary",isBusy:g,disabled:g||"custom"===a||"custom"===u,onClick:function(){return kr(void 0,void 0,void 0,(function(){return Sr(this,(function(e){switch(e.label){case 0:return o(void 0),!1!==g?[3,2]:(k.trackEvent("title_suggestions_generate_pressed",{request_more:y.length>0,total_titles:y.length,total_pinned:y.filter((function(e){return e.isPinned})).length,tone:a,persona:u}),[4,(t=Zn.PostTitle,n=A,r=a,i=u,kr(void 0,void 0,void 0,(function(){var e,s,a;return Sr(this,(function(l){switch(l.label){case 0:return[4,T(!0)];case 1:l.sent(),e=xr.getInstance(),l.label=2;case 2:return l.trys.push([2,5,,6]),[4,e.generateTitles(n,3,r,i)];case 3:return s=l.sent(),[4,P(t,s)];case 4:return l.sent(),[3,6];case 5:return a=l.sent(),o(a),P(t,[]),[3,6];case 6:return[4,T(!1)];case 7:return l.sent(),[2]}}))})))]);case 1:e.sent(),e.label=2;case 2:return[2]}var t,n,r,i}))}))},children:[g&&(0,w.__)("Generating Titles…","wp-parsely"),!g&&x.length>0&&(0,w.__)("Generate More","wp-parsely"),!g&&0===x.length&&(0,w.__)("Generate Titles","wp-parsely")]})})]})})},Pr=function(){return Pr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n ( { - value: section, label: section, - } ) ); + let categoryOptions: { value: string, label: string }[] = []; + + if ( true !== window.wpParselyUseCategorySlugsInSearches ) { + // Default behavior: Use section names to search. + categoryOptions = postData.categories.map( ( category: SidebarPostDataCategory ) => ( { + value: category.name, label: category.name, + } ) ); + } else { + // Overridden behavior: Use section slugs to search. + categoryOptions = postData.categories.map( ( category: SidebarPostDataCategory ) => ( { + value: category.slug, label: category.name, + } ) ); + } return (
@@ -74,7 +84,7 @@ export const RelatedPostsFilterSettings = ( { onChange={ ( selection ) => props.onFiltersChange( selection, PostFilterType.Section ) } - options={ sectionOptions } + options={ categoryOptions } value={ filters.section } /> ) } diff --git a/src/content-helper/editor-sidebar/related-posts/component.tsx b/src/content-helper/editor-sidebar/related-posts/component.tsx index 3a29a54501..21f1c81417 100644 --- a/src/content-helper/editor-sidebar/related-posts/component.tsx +++ b/src/content-helper/editor-sidebar/related-posts/component.tsx @@ -27,7 +27,7 @@ import { isInEnum, } from '../../common/utils/constants'; import { PostData } from '../../common/utils/post'; -import { SidebarPostData } from '../editor-sidebar'; +import { SidebarPostData, SidebarPostDataCategory } from '../editor-sidebar'; import { RelatedPostsFilterSettings } from './component-filter-settings'; import { RelatedPostItem } from './component-item'; import { usePostData } from './hooks'; @@ -111,11 +111,30 @@ export const RelatedPostsPanel = (): React.JSX.Element => { return array.map( ( item ) => item.name ); }; + /** + * Returns the name and slug properties present in the passed value, or + * an empty array if any errors occur. + * + * @since 3.18.0 + * + * @param {unknown} value The value to be processed. + * + * @return {SidebarPostDataCategory[]} The categories data extracted from the value. + */ + const extractCategoriesDataAsArray = ( value: unknown ): SidebarPostDataCategory[] => { + if ( ! isArrayOfUsersOrTaxonomies( value ) ) { + return []; + } + + const array = value as SidebarPostDataCategory[]; + return array.map( ( item ) => ( { name: item.name, slug: item.slug } ) ); + }; + setPostData( { // Pass the data through validation, as `usePostData()` could return // unexpected results. authors: extractNamesAsArray( authors ), - categories: extractNamesAsArray( categories ), + categories: extractCategoriesDataAsArray( categories ), tags: extractNamesAsArray( tags ), } ); }, [ authors, categories, tags, isPostDataReady ] );