From 608004f7feae3b9bf91c763a69a5ac7f6bc20f01 Mon Sep 17 00:00:00 2001 From: David Bowman Date: Mon, 10 Aug 2026 10:55:02 -0600 Subject: [PATCH 1/2] Add site-wide generation defaults for the suggestion features Title Suggestions and Excerpt Suggestions each start from a tone and a persona, and Excerpt Suggestions also from a desired length. Those starting points were hardcoded, so a site had no way to express its own editorial voice. Each feature now exposes its defaults in the Content Intelligence section of the settings page, and the Editor Sidebar settings endpoint resolves its defaults from them. They apply to users who have not yet chosen their own values in the editor. The new Suggestion_Defaults class holds the tones, the personas, the length bounds, and a validator for each setting, so that a missing or invalid stored value falls back to the shipped default. Installations that predate these settings therefore need no migration. The defaults are validated outside the Content Intelligence sanitizer, which coerces every scalar into a boolean and would otherwise discard them. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01MXxy3dkvUCyMxsBQNMJbaq --- src/UI/class-settings-page.php | 153 ++++++++++++++++- src/class-parsely.php | 9 + src/class-permissions.php | 7 + .../common/class-suggestion-defaults.php | 156 ++++++++++++++++++ ...class-endpoint-editor-sidebar-settings.php | 42 ++++- .../EndpointEditorSidebarSettingsTest.php | 92 +++++++++++ 6 files changed, 449 insertions(+), 10 deletions(-) create mode 100644 src/content-helper/common/class-suggestion-defaults.php diff --git a/src/UI/class-settings-page.php b/src/UI/class-settings-page.php index 498b60c3aa..a386105640 100644 --- a/src/UI/class-settings-page.php +++ b/src/UI/class-settings-page.php @@ -11,6 +11,7 @@ namespace Parsely\UI; use Parsely\Content_Helper\Excerpt_Suggestions; +use Parsely\Content_Helper\Suggestion_Defaults; use Parsely\Parsely; use Parsely\Permissions; use Parsely\Utils\Utils; @@ -110,6 +111,19 @@ final class Settings_Page { */ private $managed_options_badge = array(); + /** + * The Content Intelligence features that expose site-wide generation + * defaults in the settings page. + * + * @since 3.24.0 + * + * @var string[] + */ + private const FEATURES_WITH_DEFAULTS = array( + 'title_suggestions', + 'excerpt_suggestions', + ); + /** * The Content Intelligence features that can be configured in the settings * page. @@ -1122,9 +1136,107 @@ public function print_content_helper_ai_feature_section( $args ): void { echo ''; + if ( in_array( $feature_id, self::FEATURES_WITH_DEFAULTS, true ) ) { + $this->print_suggestion_defaults( $args, $options, $feature_id ); + } + $this->print_filter_text( $args ); } + /** + * Prints out a feature's site-wide generation defaults. + * + * These apply to users who have not yet set their own values in the editor. + * The desired length is printed for Excerpt Suggestions only, as Title + * Suggestions has no equivalent setting. + * + * @since 3.24.0 + * + * @param Setting_Arguments $args The arguments for the fieldset. + * @param Parsely_Options $options The plugin's options. + * @param string $feature_id The feature's name. + */ + private function print_suggestion_defaults( $args, $options, string $feature_id ): void { + /** @var array $feature_options */ + $feature_options = $options['content_helper'][ $feature_id ] ?? array(); + $is_managed = key_exists( 'content_helper', $this->parsely->managed_options ); + + echo '
' : '>'; + echo ''; + printf( + /* translators: %s: Feature name */ + esc_html__( '%s Default Settings', 'wp-parsely' ), + esc_html( $args['legend'] ?? __( 'Feature', 'wp-parsely' ) ) + ); + echo ''; + + if ( Excerpt_Suggestions::get_feature_name() === $feature_id ) { + $length_key = $args['option_key'] . '[default_length]'; + printf( + '


' . + '

', + esc_attr( $length_key ), + esc_html__( 'Default length (characters)', 'wp-parsely' ), + esc_attr( $this->get_html_name_attribute( $length_key ) ), + absint( Suggestion_Defaults::get_default_length( $feature_options ) ), + absint( Suggestion_Defaults::MIN_LENGTH ), + absint( Suggestion_Defaults::MAX_LENGTH ) + ); + } + + $this->print_suggestion_defaults_select( + $args['option_key'] . '[default_tone]', + __( 'Default tone', 'wp-parsely' ), + Suggestion_Defaults::get_tones(), + Suggestion_Defaults::get_default_tone( $feature_options ) + ); + + $this->print_suggestion_defaults_select( + $args['option_key'] . '[default_persona]', + __( 'Default persona', 'wp-parsely' ), + Suggestion_Defaults::get_personas(), + Suggestion_Defaults::get_default_persona( $feature_options ) + ); + + echo '
'; + } + + /** + * Prints out a select tag for a feature's default generation setting. + * + * @since 3.24.0 + * + * @param string $option_key The nested option key. + * @param string $label The visible label. + * @param array $choices The choices, as value => label pairs. + * @param string $selected The currently selected value. + */ + private function print_suggestion_defaults_select( + string $option_key, + string $label, + array $choices, + string $selected + ): void { + printf( + '


'; + } + /** * Prints out the select tags * @@ -1558,10 +1670,49 @@ private function validate_content_helper_section( $input ) { // Produce the final array. $options = $this->parsely->get_options()['content_helper']; - $merged = array_merge( $options, $input['content_helper'] ); + + // Validate the generation defaults separately, as the sanitizer above + // coerces every scalar into a boolean. Values that were not submitted + // fall back to the stored ones, and anything invalid falls back to the + // shipped default. + $validated_defaults = array(); + foreach ( self::FEATURES_WITH_DEFAULTS as $feature_id ) { + /** @var array $submitted */ + $submitted = $input['content_helper'][ $feature_id ] ?? array(); + /** @var array $stored */ + $stored = $options[ $feature_id ]; + + $defaults = array( + 'default_tone' => Suggestion_Defaults::get_default_tone( + array( 'default_tone' => $submitted['default_tone'] ?? $stored['default_tone'] ?? null ) + ), + 'default_persona' => Suggestion_Defaults::get_default_persona( + array( 'default_persona' => $submitted['default_persona'] ?? $stored['default_persona'] ?? null ) + ), + ); + + // Only Excerpt Suggestions has a desired length. + if ( Excerpt_Suggestions::get_feature_name() === $feature_id ) { + $length = $submitted['default_length'] ?? $stored['default_length'] ?? null; + $defaults['default_length'] = Suggestion_Defaults::get_default_length( + array( 'default_length' => is_numeric( $length ) ? (int) $length : null ) + ); + } + + $validated_defaults[ $feature_id ] = $defaults; + } + + $merged = array_merge( $options, $input['content_helper'] ); $input['content_helper'] = $sanitize( $merged ); + foreach ( $validated_defaults as $feature_id => $defaults ) { + $input['content_helper'][ $feature_id ] = array_merge( + $input['content_helper'][ $feature_id ], + $defaults + ); + } + return $input; } diff --git a/src/class-parsely.php b/src/class-parsely.php index 8d617b079a..f9f7d75ea4 100644 --- a/src/class-parsely.php +++ b/src/class-parsely.php @@ -10,6 +10,7 @@ namespace Parsely; +use Parsely\Content_Helper\Suggestion_Defaults; use Parsely\REST_API\REST_API_Controller; use Parsely\Services\Content_API\Content_API_Service; use Parsely\Services\Suggestions_API\Suggestions_API_Service; @@ -60,6 +61,9 @@ * @phpstan-type Parsely_Options_Content_Helper_Feature array{ * enabled: bool, * allowed_user_roles: string[], + * default_length?: int, + * default_tone?: string, + * default_persona?: string, * } * * @phpstan-type Parsely_Options_Headline_Testing array{ @@ -136,10 +140,15 @@ class Parsely { 'title_suggestions' => array( 'enabled' => true, 'allowed_user_roles' => array( 'administrator' ), + 'default_tone' => Suggestion_Defaults::DEFAULT_TONE, + 'default_persona' => Suggestion_Defaults::DEFAULT_PERSONA, ), 'excerpt_suggestions' => array( 'enabled' => true, 'allowed_user_roles' => array( 'administrator' ), + 'default_length' => Suggestion_Defaults::DEFAULT_LENGTH, + 'default_tone' => Suggestion_Defaults::DEFAULT_TONE, + 'default_persona' => Suggestion_Defaults::DEFAULT_PERSONA, ), 'traffic_boost' => array( 'enabled' => true, diff --git a/src/class-permissions.php b/src/class-permissions.php index 9fdfb600b9..87b5a34757 100644 --- a/src/class-permissions.php +++ b/src/class-permissions.php @@ -10,6 +10,8 @@ namespace Parsely; +use Parsely\Content_Helper\Suggestion_Defaults; + /** * Class implementing user/role permissions functionality. * @@ -201,10 +203,15 @@ public static function build_pch_permissions_settings_array( 'title_suggestions' => array( 'enabled' => $enabled, 'allowed_user_roles' => $allowed_user_roles, + 'default_tone' => Suggestion_Defaults::DEFAULT_TONE, + 'default_persona' => Suggestion_Defaults::DEFAULT_PERSONA, ), 'excerpt_suggestions' => array( 'enabled' => $enabled, 'allowed_user_roles' => $allowed_user_roles, + 'default_length' => Suggestion_Defaults::DEFAULT_LENGTH, + 'default_tone' => Suggestion_Defaults::DEFAULT_TONE, + 'default_persona' => Suggestion_Defaults::DEFAULT_PERSONA, ), 'traffic_boost' => array( 'enabled' => $enabled, diff --git a/src/content-helper/common/class-suggestion-defaults.php b/src/content-helper/common/class-suggestion-defaults.php new file mode 100644 index 0000000000..5667a05f57 --- /dev/null +++ b/src/content-helper/common/class-suggestion-defaults.php @@ -0,0 +1,156 @@ + The tones, as value => label pairs. + */ + public static function get_tones(): array { + return array( + 'neutral' => __( 'Neutral', 'wp-parsely' ), + 'formal' => __( 'Formal', 'wp-parsely' ), + 'humorous' => __( 'Humorous', 'wp-parsely' ), + 'confident' => __( 'Confident', 'wp-parsely' ), + 'provocative' => __( 'Provocative', 'wp-parsely' ), + 'serious' => __( 'Serious', 'wp-parsely' ), + 'inspirational' => __( 'Inspirational', 'wp-parsely' ), + 'skeptical' => __( 'Skeptical', 'wp-parsely' ), + 'conversational' => __( 'Conversational', 'wp-parsely' ), + 'analytical' => __( 'Analytical', 'wp-parsely' ), + ); + } + + /** + * Returns the predefined personas, keyed by their stored value. + * + * The custom persona is absent, for the same reason as the custom tone. + * + * @since 3.24.0 + * + * @return array The personas, as value => label pairs. + */ + public static function get_personas(): array { + return array( + 'journalist' => __( 'Journalist', 'wp-parsely' ), + 'editorialWriter' => __( 'Editorial Writer', 'wp-parsely' ), + 'investigativeReporter' => __( 'Investigative Reporter', 'wp-parsely' ), + 'techAnalyst' => __( 'Tech Analyst', 'wp-parsely' ), + 'businessAnalyst' => __( 'Business Analyst', 'wp-parsely' ), + 'culturalCommentator' => __( 'Cultural Commentator', 'wp-parsely' ), + 'scienceCorrespondent' => __( 'Science Correspondent', 'wp-parsely' ), + 'politicalAnalyst' => __( 'Political Analyst', 'wp-parsely' ), + 'healthWellnessAdvocate' => __( 'Health and Wellness Advocate', 'wp-parsely' ), + 'environmentalJournalist' => __( 'Environmental Journalist', 'wp-parsely' ), + ); + } + + /** + * Returns a feature's site-wide default excerpt length. + * + * Falls back to the shipped default when the option is missing, which is + * the case for installations that predate these settings, or when it holds + * an out-of-range value. + * + * @since 3.24.0 + * + * @param array $feature_options The feature's options. + * @return int The default length, in characters. + */ + public static function get_default_length( array $feature_options ): int { + $length = $feature_options['default_length'] ?? self::DEFAULT_LENGTH; + + if ( ! is_int( $length ) || + $length < self::MIN_LENGTH || + $length > self::MAX_LENGTH + ) { + return self::DEFAULT_LENGTH; + } + + return $length; + } + + /** + * Returns a feature's site-wide default tone. + * + * @since 3.24.0 + * + * @param array $feature_options The feature's options. + * @return string The default tone. + */ + public static function get_default_tone( array $feature_options ): string { + $tone = $feature_options['default_tone'] ?? self::DEFAULT_TONE; + + if ( ! is_string( $tone ) || ! isset( self::get_tones()[ $tone ] ) ) { + return self::DEFAULT_TONE; + } + + return $tone; + } + + /** + * Returns a feature's site-wide default persona. + * + * @since 3.24.0 + * + * @param array $feature_options The feature's options. + * @return string The default persona. + */ + public static function get_default_persona( array $feature_options ): string { + $persona = $feature_options['default_persona'] ?? self::DEFAULT_PERSONA; + + if ( ! is_string( $persona ) || ! isset( self::get_personas()[ $persona ] ) ) { + return self::DEFAULT_PERSONA; + } + + return $persona; + } +} diff --git a/src/rest-api/settings/class-endpoint-editor-sidebar-settings.php b/src/rest-api/settings/class-endpoint-editor-sidebar-settings.php index 5680725daf..bc75d7a97e 100644 --- a/src/rest-api/settings/class-endpoint-editor-sidebar-settings.php +++ b/src/rest-api/settings/class-endpoint-editor-sidebar-settings.php @@ -10,6 +10,8 @@ namespace Parsely\REST_API\Settings; +use Parsely\Content_Helper\Suggestion_Defaults; + /** * Endpoint for saving and retrieving Content Intelligence Editor Sidebar * settings. @@ -29,9 +31,9 @@ class Endpoint_Editor_Sidebar_Settings extends Base_Settings_Endpoint { * * @var int */ - public const MIN_EXCERPT_LENGTH = 50; - public const MAX_EXCERPT_LENGTH = 300; - public const DEFAULT_EXCERPT_LENGTH = 160; + public const MIN_EXCERPT_LENGTH = Suggestion_Defaults::MIN_LENGTH; + public const MAX_EXCERPT_LENGTH = Suggestion_Defaults::MAX_LENGTH; + public const DEFAULT_EXCERPT_LENGTH = Suggestion_Defaults::DEFAULT_LENGTH; /** * Returns the endpoint's name. @@ -64,10 +66,15 @@ protected function get_meta_key(): string { * @since 3.24.0 Added the ExcerptSuggestions `Length` setting. * @since 3.24.0 Removed the ExcerptSuggestions `Open` setting, as the panel's * collapsed state is now persisted by the block editor itself. + * @since 3.24.0 The ExcerptSuggestions and TitleSuggestions defaults come + * from the site-wide settings of their respective features. * * @return array */ protected function get_subvalues_specs(): array { + $excerpt_options = $this->get_feature_options( 'excerpt_suggestions' ); + $title_options = $this->get_feature_options( 'title_suggestions' ); + return array( 'ExcerptSuggestions' => array( 'values' => array( @@ -76,9 +83,9 @@ protected function get_subvalues_specs(): array { 'Tone' => array(), ), 'default' => array( - 'Length' => self::DEFAULT_EXCERPT_LENGTH, - 'Persona' => 'journalist', - 'Tone' => 'neutral', + 'Length' => Suggestion_Defaults::get_default_length( $excerpt_options ), + 'Persona' => Suggestion_Defaults::get_default_persona( $excerpt_options ), + 'Tone' => Suggestion_Defaults::get_default_tone( $excerpt_options ), ), ), 'InitialTabName' => array( @@ -129,8 +136,8 @@ protected function get_subvalues_specs(): array { ), 'default' => array( 'Open' => false, - 'Persona' => 'journalist', - 'Tone' => 'neutral', + 'Persona' => Suggestion_Defaults::get_default_persona( $title_options ), + 'Tone' => Suggestion_Defaults::get_default_tone( $title_options ), ), ), ); @@ -154,7 +161,9 @@ protected function sanitize_subvalue( string $composite_key, $value ) { $value < self::MIN_EXCERPT_LENGTH || $value > self::MAX_EXCERPT_LENGTH ) { - return self::DEFAULT_EXCERPT_LENGTH; + return Suggestion_Defaults::get_default_length( + $this->get_feature_options( 'excerpt_suggestions' ) + ); } return $value; @@ -162,4 +171,19 @@ protected function sanitize_subvalue( string $composite_key, $value ) { return parent::sanitize_subvalue( $composite_key, $value ); } + + /** + * Returns the site-wide options of a Content Intelligence feature. + * + * @since 3.24.0 + * + * @param string $feature_id The feature's name. + * @return array The feature's options. + */ + private function get_feature_options( string $feature_id ): array { + /** @var array $options */ + $options = $this->parsely->get_options()['content_helper'][ $feature_id ] ?? array(); + + return $options; + } } diff --git a/tests/Integration/RestAPI/Settings/EndpointEditorSidebarSettingsTest.php b/tests/Integration/RestAPI/Settings/EndpointEditorSidebarSettingsTest.php index 87a78cb640..0f16ab9f30 100644 --- a/tests/Integration/RestAPI/Settings/EndpointEditorSidebarSettingsTest.php +++ b/tests/Integration/RestAPI/Settings/EndpointEditorSidebarSettingsTest.php @@ -10,6 +10,7 @@ namespace Parsely\Tests\Integration\RestAPI\Settings; +use Parsely\Content_Helper\Suggestion_Defaults; use Parsely\REST_API\Content_Helper\Content_Helper_Controller; use Parsely\REST_API\Settings\Endpoint_Editor_Sidebar_Settings; @@ -308,6 +309,97 @@ public function test_excerpt_length_is_validated( $length, int $expected ): void self::assertSame( $expected, $value['ExcerptSuggestions']['Length'] ); } + /** + * Verifies that the ExcerptSuggestions defaults come from the site-wide + * settings of the Excerpt Suggestions feature. + * + * @since 3.24.0 + * + * @covers \Parsely\Content_Helper\Suggestion_Defaults::get_default_length + * @covers \Parsely\Content_Helper\Suggestion_Defaults::get_default_persona + * @covers \Parsely\Content_Helper\Suggestion_Defaults::get_default_tone + * @covers \Parsely\REST_API\Settings\Endpoint_Editor_Sidebar_Settings::get_subvalues_specs + * @uses \Parsely\Parsely::get_options + * @uses \Parsely\REST_API\Base_API_Controller::__construct + * @uses \Parsely\REST_API\Base_API_Controller::get_parsely + * @uses \Parsely\REST_API\Base_API_Controller::init + * @uses \Parsely\REST_API\Base_Endpoint::__construct + * @uses \Parsely\REST_API\Base_Endpoint::is_available_to_current_user + * @uses \Parsely\REST_API\Settings\Base_Settings_Endpoint::get_settings + * @uses \Parsely\REST_API\Settings\Base_Settings_Endpoint::register_routes + * @uses \Parsely\REST_API\Settings\Endpoint_Editor_Sidebar_Settings::get_endpoint_name + * @uses \Parsely\REST_API\Settings\Endpoint_Editor_Sidebar_Settings::get_meta_key + * @dataProvider provide_site_default_data + * + * @param array $feature_options The feature's stored options. + * @param array $expected The expected defaults. + */ + public function test_excerpt_defaults_come_from_site_settings( + array $feature_options, + array $expected + ): void { + // Only the feature under test is stored. Parsely::get_options() fills + // in the remaining Content Intelligence features from its defaults. + $options = self::DEFAULT_OPTIONS; + $options['content_helper'] = array( 'excerpt_suggestions' => $feature_options ); + update_option( \Parsely\Parsely::OPTIONS_KEY, $options ); + + $this->set_current_user_to_admin(); + delete_user_meta( + get_current_user_id(), + 'parsely_content_helper_settings_editor_sidebar' + ); + + // The base endpoint snapshots the specs, and therefore the defaults, + // in its constructor. Build the endpoint after the options are stored, + // as a real request would. + $endpoint = new Endpoint_Editor_Sidebar_Settings( $this->api_controller ); + $value = $endpoint->get_settings()->get_data(); + + assert( is_array( $value ) && is_array( $value['ExcerptSuggestions'] ) ); + self::assertSame( $expected, $value['ExcerptSuggestions'] ); + } + + /** + * Provides data for testing the site-wide defaults. + * + * @since 3.24.0 + * + * @return array> The test data. + */ + public function provide_site_default_data(): array { + $shipped = array( + 'Length' => Suggestion_Defaults::DEFAULT_LENGTH, + 'Persona' => Suggestion_Defaults::DEFAULT_PERSONA, + 'Tone' => Suggestion_Defaults::DEFAULT_TONE, + ); + + return array( + 'configured defaults' => array( + array( + 'default_length' => 220, + 'default_tone' => 'analytical', + 'default_persona' => 'techAnalyst', + ), + array( + 'Length' => 220, + 'Persona' => 'techAnalyst', + 'Tone' => 'analytical', + ), + ), + 'missing keys' => array( array(), $shipped ), + 'out-of-range length' => array( array( 'default_length' => 99999 ), $shipped ), + 'non-integer length' => array( array( 'default_length' => 'abc' ), $shipped ), + 'unknown tone and persona' => array( + array( + 'default_tone' => 'bogus', + 'default_persona' => 'bogus', + ), + $shipped, + ), + ); + } + /** * Provides data for testing the excerpt length validation. * From a01e9f664ff69e890ddda5b5ef2b22aec30d6252 Mon Sep 17 00:00:00 2001 From: David Bowman Date: Mon, 10 Aug 2026 10:55:14 -0600 Subject: [PATCH 2/2] Source the tones and personas from PHP The tone and persona lists existed in both PHP and TypeScript, as the settings page is rendered by PHP and cannot read a TypeScript constant. Keeping two copies of the same vocabulary in step is not something the build or the tests would have caught. PHP is now their single source. The Editor Sidebar injects them alongside the values it already passes to the bundle, and the selectors build their maps from that, adding only the custom entry. That entry stays in TypeScript, as it is a UI affordance rather than part of the vocabulary, and it carries an icon that PHP cannot express. Nothing is lost in the move: ToneProp and PersonaProp are declared as `keyof typeof PARSELY_* | string`, which collapses to `string`, so the literal types were never checking anything. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01MXxy3dkvUCyMxsBQNMJbaq --- build/content-helper/editor-sidebar.asset.php | 2 +- build/content-helper/editor-sidebar.js | 26 +++++------ src/@types/assets/window.d.ts | 2 + .../components/persona-selector/component.tsx | 43 ++++--------------- .../components/tone-selector/component.tsx | 43 ++++--------------- src/content-helper/common/utils/vocabulary.ts | 35 +++++++++++++++ .../editor-sidebar/class-editor-sidebar.php | 11 +++++ 7 files changed, 80 insertions(+), 82 deletions(-) create mode 100644 src/content-helper/common/utils/vocabulary.ts diff --git a/build/content-helper/editor-sidebar.asset.php b/build/content-helper/editor-sidebar.asset.php index 97f8acfe5c..091cf1235f 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-notices', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '7619d859e906db1a12b2'); + 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-notices', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '6a0f76ecef09743f788b'); diff --git a/build/content-helper/editor-sidebar.js b/build/content-helper/editor-sidebar.js index 81b4f6a4d2..51ae95ee24 100644 --- a/build/content-helper/editor-sidebar.js +++ b/build/content-helper/editor-sidebar.js @@ -1,20 +1,20 @@ -!function(){"use strict";var e={20:function(e,t,n){var r=n(609),i=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var r,s={},c=null,u=null;for(r in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,r)&&!l.hasOwnProperty(r)&&(s[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===s[r]&&(s[r]=t[r]);return{$$typeof:i,type:e,key:c,ref:u,props:s,_owner:a.current}}t.Fragment=s,t.jsx=c,t.jsxs=c},848:function(e,t,n){e.exports=n(20)},609:function(e){e.exports=window.React}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){n.d({},{w:function(){return Wr},_:function(){return Yr}});var e,t,r,i,s,o,a,l,c,u,p,d,f=n(848),h=window.wp.components,v=window.wp.data,g=window.wp.domReady,y=n.n(g),m=window.wp.element,w=window.wp.i18n,b=window.wp.primitives,_=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",d:"M11.25 5h1.5v15h-1.5V5zM6 10h1.5v10H6V10zm12 4h-1.5v6H18v-6z",clipRule:"evenodd"})}),x=window.wp.plugins;void 0!==window.wp&&(p=null!==(t=null===(e=window.wp.editor)||void 0===e?void 0:e.PluginDocumentSettingPanel)&&void 0!==t?t:null!==(i=null===(r=window.wp.editPost)||void 0===r?void 0:r.PluginDocumentSettingPanel)&&void 0!==i?i:null===(s=window.wp.editSite)||void 0===s?void 0:s.PluginDocumentSettingPanel,d=null!==(a=null===(o=window.wp.editor)||void 0===o?void 0:o.PluginSidebar)&&void 0!==a?a:null!==(c=null===(l=window.wp.editPost)||void 0===l?void 0:l.PluginSidebar)&&void 0!==c?c:null===(u=window.wp.editSite)||void 0===u?void 0:u.PluginSidebar);var k=function(){function e(){this._tkq=[],this.isLoaded=!1,this.isEnabled=!1,"undefined"!=typeof wpParselyTracksTelemetry&&(this.isEnabled=!0,this.loadTrackingLibrary())}return e.getInstance=function(){return window.wpParselyTelemetryInstance||Object.defineProperty(window,"wpParselyTelemetryInstance",{value:new e,writable:!1,configurable:!1,enumerable:!1}),window.wpParselyTelemetryInstance},e.prototype.loadTrackingLibrary=function(){var e=this,t=document.createElement("script");t.async=!0,t.src="//stats.wp.com/w.js",t.onload=function(){e.isLoaded=!0,e._tkq=window._tkq||[]},document.head.appendChild(t)},e.trackEvent=function(t){return n=this,r=arguments,s=function(t,n){var r;return void 0===n&&(n={}),function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]=1e4&&(clearInterval(s),n("Telemetry library not loaded"))}),100);else n("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,n){var r;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(n=this.prepareProperties(n),null===(r=this._tkq)||void 0===r||r.push(["recordEvent",t,n])):console.error("Error tracking event: Invalid event name")):console.error("Error tracking event: Telemetry not loaded")},e.prototype.isTelemetryEnabled=function(){return this.isEnabled},e.prototype.isProprietyValid=function(t){return e.PROPERTY_REGEX.test(t)},e.prototype.isEventNameValid=function(t){return e.EVENT_NAME_REGEX.test(t)},e.prototype.prepareProperties=function(e){return(e=this.sanitizeProperties(e)).parsely_version=wpParselyTracksTelemetry.version,wpParselyTracksTelemetry.user&&(e._ut=wpParselyTracksTelemetry.user.type,e._ui=wpParselyTracksTelemetry.user.id),wpParselyTracksTelemetry.vipgo_env&&(e.vipgo_env=wpParselyTracksTelemetry.vipgo_env),this.sanitizeProperties(e)},e.prototype.sanitizeProperties=function(e){var t=this,n={};return Object.keys(e).forEach((function(r){t.isProprietyValid(r)&&(n[r]=e[r])})),n},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),S=(k.trackEvent,function(){return(0,f.jsx)(h.SVG,{"aria-hidden":"true",version:"1.1",viewBox:"0 0 15 15",width:"15",height:"15",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(h.Path,{d:"M0 14.0025V11.0025L7.5 3.5025L10.5 6.5025L3 14.0025H0ZM12 5.0025L13.56 3.4425C14.15 2.8525 14.15 1.9025 13.56 1.3225L12.68 0.4425C12.09 -0.1475 11.14 -0.1475 10.56 0.4425L9 2.0025L12 5.0025Z"})})}),j=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{className:i,height:n,viewBox:"0 0 60 65",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M23.72,51.53c0-.18,0-.34-.06-.52a13.11,13.11,0,0,0-2.1-5.53A14.74,14.74,0,0,0,19.12,43c-.27-.21-.5-.11-.51.22l-.24,3.42c0,.33-.38.35-.49,0l-1.5-4.8a1.4,1.4,0,0,0-.77-.78,23.91,23.91,0,0,0-3.1-.84c-1.38-.24-3.39-.39-3.39-.39-.34,0-.45.21-.25.49l2.06,3.76c.2.27,0,.54-.29.33l-4.51-3.6a3.68,3.68,0,0,0-2.86-.48c-1,.16-2.44.46-2.44.46a.68.68,0,0,0-.39.25.73.73,0,0,0-.14.45S.41,43,.54,44a3.63,3.63,0,0,0,1.25,2.62L6.48,50c.28.2.09.49-.23.37l-4.18-.94c-.32-.12-.5,0-.4.37,0,0,.69,1.89,1.31,3.16a24,24,0,0,0,1.66,2.74,1.34,1.34,0,0,0,1,.52l5,.13c.33,0,.41.38.1.48L7.51,58c-.31.1-.34.35-.07.55a14.29,14.29,0,0,0,3.05,1.66,13.09,13.09,0,0,0,5.9.5,25.13,25.13,0,0,0,4.34-1,9.55,9.55,0,0,1-.08-1.2,9.32,9.32,0,0,1,3.07-6.91"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M59.7,41.53a.73.73,0,0,0-.14-.45.68.68,0,0,0-.39-.25s-1.43-.3-2.44-.46a3.64,3.64,0,0,0-2.86.48l-4.51,3.6c-.26.21-.49-.06-.29-.33l2.06-3.76c.2-.28.09-.49-.25-.49,0,0-2,.15-3.39.39a23.91,23.91,0,0,0-3.1.84,1.4,1.4,0,0,0-.77.78l-1.5,4.8c-.11.32-.48.3-.49,0l-.24-3.42c0-.33-.24-.43-.51-.22a14.74,14.74,0,0,0-2.44,2.47A13.11,13.11,0,0,0,36.34,51c0,.18,0,.34-.06.52a9.26,9.26,0,0,1,3,8.1,24.1,24.1,0,0,0,4.34,1,13.09,13.09,0,0,0,5.9-.5,14.29,14.29,0,0,0,3.05-1.66c.27-.2.24-.45-.07-.55l-3.22-1.17c-.31-.1-.23-.47.1-.48l5-.13a1.38,1.38,0,0,0,1-.52A24.6,24.6,0,0,0,57,52.92c.61-1.27,1.31-3.16,1.31-3.16.1-.33-.08-.49-.4-.37l-4.18.94c-.32.12-.51-.17-.23-.37l4.69-3.34A3.63,3.63,0,0,0,59.46,44c.13-1,.24-2.47.24-2.47"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M46.5,25.61c0-.53-.35-.72-.8-.43l-4.86,2.66c-.45.28-.56-.27-.23-.69l4.66-6.23a2,2,0,0,0,.28-1.68,36.51,36.51,0,0,0-2.19-4.89,34,34,0,0,0-2.81-3.94c-.33-.41-.74-.35-.91.16l-2.28,5.68c-.16.5-.6.48-.59-.05l.28-8.93a2.54,2.54,0,0,0-.66-1.64S35,4.27,33.88,3.27,30.78.69,30.78.69a1.29,1.29,0,0,0-1.54,0s-1.88,1.49-3.12,2.59-2.48,2.35-2.48,2.35A2.5,2.5,0,0,0,23,7.27l.27,8.93c0,.53-.41.55-.58.05l-2.29-5.69c-.17-.5-.57-.56-.91-.14a35.77,35.77,0,0,0-3,4.2,35.55,35.55,0,0,0-2,4.62,2,2,0,0,0,.27,1.67l4.67,6.24c.33.42.23,1-.22.69l-4.87-2.66c-.45-.29-.82-.1-.82.43a18.6,18.6,0,0,0,.83,5.07,20.16,20.16,0,0,0,5.37,7.77c3.19,3,5.93,7.8,7.45,11.08A9.6,9.6,0,0,1,30,49.09a9.31,9.31,0,0,1,2.86.45c1.52-3.28,4.26-8.11,7.44-11.09a20.46,20.46,0,0,0,5.09-7,19,19,0,0,0,1.11-5.82"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M36.12,58.44A6.12,6.12,0,1,1,30,52.32a6.11,6.11,0,0,1,6.12,6.12"})]})},P=function(){return P=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0?"".concat(i," ").concat(n):n)||this).hint=null,s.name=s.constructor.name,s.code=r;var o=[U.FetchError,U.HttpRequestFailed,U.ParselySuggestionsApiAuthUnavailable,U.ParselySuggestionsApiOpenAiError,U.ParselySuggestionsApiOpenAiSchema,U.ParselySuggestionsApiOpenAiUnavailable,U.ParselySuggestionsApiSchemaError];return s.retryFetch=o.includes(s.code),Object.setPrototypeOf(s,t.prototype),s.CustomizeErrorMessaging(),s}return se(t,e),t.prototype.CustomizeErrorMessaging=function(){this.code===U.AccessToFeatureDisabled?this.message=(0,w.__)("Access to this feature is disabled by the site's administration.","wp-parsely"):this.code===U.ParselySuggestionsApiNoAuthorization?this.message=(0,w.__)('This AI-powered feature is opt-in. To gain access, please submit a request here.',"wp-parsely"):this.code===U.ParselySuggestionsApiOpenAiError||this.code===U.ParselySuggestionsApiOpenAiUnavailable?this.message=(0,w.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):this.code===U.HttpRequestFailed&&this.message.includes("cURL error 28")?this.message=(0,w.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):this.code===U.ParselySuggestionsApiSchemaError||this.code===U.ParselySuggestionsInvalidRequest?this.message=(0,w.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):this.code===U.ParselySuggestionsApiNoData||this.code===U.ParselySuggestionsApiNoDataManualLinking?this.message=(0,w.__)("The Parse.ly API couldn't find any relevant data to fulfill the request.","wp-parsely"):this.code===U.ParselySuggestionsApiOpenAiSchema||this.code===U.ParselySuggestionsApiResponseValidationError?this.message=(0,w.__)("The Parse.ly API returned an incorrect response.","wp-parsely"):this.code===U.ParselySuggestionsApiAuthUnavailable&&(this.message=(0,w.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),this.code===U.FetchError&&(this.hint=this.Hint((0,w.__)("This error can sometimes be caused by ad-blockers or browser tracking protections. Please add this site to any applicable allow lists and try again.","wp-parsely"))),this.code!==U.ParselyApiForbidden&&this.code!==U.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,w.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===U.HttpRequestFailed&&(this.hint=this.Hint((0,w.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely")))},t.prototype.Hint=function(e){return'

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

")},t.prototype.Message=function(e){return void 0===e&&(e=null),[U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsSiteIdNotSet,U.PluginSettingsApiSecretNotSet].includes(this.code)?ie(e):(0,f.jsx)(re,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

").concat(this.hint?this.hint:"")})},t.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,v.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),ae=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",className:i,width:n,height:n,viewBox:"0 0 24 24",fill:"currentColor",children:[(0,f.jsx)(h.Path,{d:"M8.18983 5.90381L8.83642 7.54325L10.4758 8.18983L8.83642 8.8364L8.18983 10.4759L7.54324 8.8364L5.90381 8.18983L7.54324 7.54325L8.18983 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M15.048 5.90381L15.9101 8.08972L18.0961 8.95186L15.9101 9.81397L15.048 11.9999L14.1859 9.81397L12 8.95186L14.1859 8.08972L15.048 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M11.238 10.4761L12.3157 13.2085L15.048 14.2861L12.3157 15.3638L11.238 18.0962L10.1603 15.3638L7.42798 14.2861L10.1603 13.2085L11.238 10.4761Z"})]})},le=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})}),ce=(0,m.forwardRef)((({icon:e,size:t=24,...n},r)=>(0,m.cloneElement)(e,{width:t,height:t,...n,ref:r}))),ue=function(){return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:(0,f.jsx)(h.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M13.5034 7.91642L9 12.0104L4.49662 7.91642L5.25337 7.08398L8.99999 10.49L12.7466 7.08398L13.5034 7.91642Z",fill:"#1E1E1E"})})},pe={journalist:{label:(0,w.__)("Journalist","wp-parsely")},editorialWriter:{label:(0,w.__)("Editorial Writer","wp-parsely")},investigativeReporter:{label:(0,w.__)("Investigative Reporter","wp-parsely")},techAnalyst:{label:(0,w.__)("Tech Analyst","wp-parsely")},businessAnalyst:{label:(0,w.__)("Business Analyst","wp-parsely")},culturalCommentator:{label:(0,w.__)("Cultural Commentator","wp-parsely")},scienceCorrespondent:{label:(0,w.__)("Science Correspondent","wp-parsely")},politicalAnalyst:{label:(0,w.__)("Political Analyst","wp-parsely")},healthWellnessAdvocate:{label:(0,w.__)("Health and Wellness Advocate","wp-parsely")},environmentalJournalist:{label:(0,w.__)("Environmental Journalist","wp-parsely")},custom:{label:(0,w.__)("Custom Persona","wp-parsely"),icon:le}},de=Object.keys(pe),fe=function(e){return"custom"===e||""===e?pe.custom.label:he(e)?e:pe[e].label},he=function(e){return!de.includes(e)||"custom"===e},ve=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],s=r[1],o=(0,ee.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-persona-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom persona…","wp-parsely"),onChange:function(e){if(""===e)return n(""),void s("");e.length>32&&(e=e.slice(0,32)),o(e),s(e)}})})},ge=function(e){var t=e.persona,n=e.value,r=void 0===n?(0,w.__)("Select a persona…","wp-parsely"):n,i=e.label,s=void 0===i?(0,w.__)("Persona","wp-parsely"):i,o=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u,d="parsely-persona-selector-".concat((0,ee.useInstanceId)(ge));return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[s&&(0,f.jsx)("label",{htmlFor:d,className:"wp-parsely-editor-sidebar-label",children:s}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Persona","wp-parsely"),className:"parsely-persona-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{id:d,children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-persona-selector-label",children:he(t)?pe.custom.label:r}),(0,f.jsx)(ue,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Persona","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:de.map((function(e){if(!p&&"custom"===e)return null;var r=pe[e],i=e===t||he(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),o(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-persona-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ce,{icon:r.icon}),r.label]},e)}))})})}}),p&&he(t)&&(0,f.jsx)(ve,{onChange:function(e){o(""!==e?e:"custom")},value:"custom"===t?"":t})]})},ye={neutral:{label:(0,w.__)("Neutral","wp-parsely")},formal:{label:(0,w.__)("Formal","wp-parsely")},humorous:{label:(0,w.__)("Humorous","wp-parsely")},confident:{label:(0,w.__)("Confident","wp-parsely")},provocative:{label:(0,w.__)("Provocative","wp-parsely")},serious:{label:(0,w.__)("Serious","wp-parsely")},inspirational:{label:(0,w.__)("Inspirational","wp-parsely")},skeptical:{label:(0,w.__)("Skeptical","wp-parsely")},conversational:{label:(0,w.__)("Conversational","wp-parsely")},analytical:{label:(0,w.__)("Analytical","wp-parsely")},custom:{label:(0,w.__)("Custom Tone","wp-parsely"),icon:le}},me=Object.keys(ye),we=function(e){return"custom"===e||""===e?ye.custom.label:be(e)?e:ye[e].label},be=function(e){return!me.includes(e)||"custom"===e},_e=function(e){var t=e.value,n=e.onChange,r=(0,m.useState)(""),i=r[0],s=r[1],o=(0,ee.useDebounce)(n,500);return(0,f.jsx)("div",{className:"parsely-tone-selector-custom",children:(0,f.jsx)(h.TextControl,{value:i||t,placeholder:(0,w.__)("Enter a custom tone","wp-parsely"),onChange:function(e){if(""===e)return n(""),void s("");e.length>32&&(e=e.slice(0,32)),o(e),s(e)}})})},xe=function(e){var t=e.tone,n=e.value,r=void 0===n?(0,w.__)("Select a tone","wp-parsely"):n,i=e.label,s=void 0===i?(0,w.__)("Tone","wp-parsely"):i,o=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,p=void 0!==u&&u,d="parsely-tone-selector-".concat((0,ee.useInstanceId)(xe));return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[(0,f.jsx)("label",{htmlFor:d,className:"wp-parsely-editor-sidebar-label",children:s}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Tone","wp-parsely"),className:"parsely-tone-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{id:d,children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-tone-selector-label",children:be(t)?ye.custom.label:r}),(0,f.jsx)(ue,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Select a tone","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:me.map((function(e){if(!p&&"custom"===e)return null;var r=ye[e],i=e===t||be(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),o(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-tone-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ce,{icon:r.icon}),r.label]},e)}))})})}}),p&&be(t)&&(0,f.jsx)(_e,{onChange:function(e){o(""!==e?e:"custom")},value:"custom"===t?"":t})]})},ke=function(e){return Object.entries(e).map((function(e){var t=e[0];return{label:e[1].label,value:t}}))},Se=ke(ye),je=ke(pe),Pe=function(e,t){var n=(0,m.useState)(e),r=n[0],i=n[1],s=(0,m.useRef)(r),o=(0,m.useRef)(t),a=(0,m.useRef)(e);s.current=r,o.current=t;var l=(0,m.useCallback)((function(e){a.current=e,o.current(e)}),[]),c=(0,ee.useDebounce)(l,500);return(0,m.useEffect)((function(){return function(){s.current!==a.current&&l(s.current)}}),[l]),[r,function(e,t){if(void 0===t&&(t=!1),i(e),t)return c.cancel(),void l(e);c(e)}]},Te=function(e){var t=e.customLabel,n=e.disabled,r=e.label,i=e.onChange,s=e.onSelect,o=e.options,a=e.value,l=function(e,t){return K===e||!t.some((function(t){return t.value===e}))}(a,o),c=Pe(a,i)[1],u=(0,m.useState)(l?K:a),p=u[0],d=u[1],v=(0,m.useState)(l&&K!==a?a:""),g=v[0],y=v[1];return(0,f.jsxs)(h.__experimentalVStack,{spacing:2,children:[(0,f.jsx)(h.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:r,value:p,options:o,onChange:function(e){d(e),c(K===e?g||K:e,!0),s(e)},disabled:n}),K===p&&(0,f.jsx)(h.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:t,maxLength:32,value:g,onChange:function(e){y(e),c(""===e?K:e)},disabled:n})]})},Le=function(e){var t=e.isLoading,n=e.length,r=e.onLengthChange,i=e.onPersonaChange,s=e.onToneChange,o=e.persona,a=e.tone,l=Pe(n,r),c=l[0],u=l[1];return(0,f.jsxs)(h.__experimentalVStack,{spacing:4,children:[(0,f.jsx)(h.RangeControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,value:c,onChange:function(e){void 0!==e&&u(e)},label:(0,w.__)("Desired length (characters)","wp-parsely"),min:50,max:300,disabled:t}),(0,f.jsx)(Te,{label:(0,w.__)("Tone","wp-parsely"),customLabel:(0,w.__)("Custom tone","wp-parsely"),value:a,options:Se,onChange:s,onSelect:function(e){k.trackEvent("excerpt_generator_ai_tone_changed",{selectedTone:e})},disabled:t}),(0,f.jsx)(Te,{label:(0,w.__)("Persona","wp-parsely"),customLabel:(0,w.__)("Custom persona","wp-parsely"),value:o,options:je,onChange:i,onSelect:function(e){k.trackEvent("excerpt_generator_ai_persona_changed",{persona:e})},disabled:t})]})},Ee=function(){return Ee=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]=1e4&&(clearInterval(o),n("Telemetry library not loaded"))}),100);else n("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,n){var r;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(n=this.prepareProperties(n),null===(r=this._tkq)||void 0===r||r.push(["recordEvent",t,n])):console.error("Error tracking event: Invalid event name")):console.error("Error tracking event: Telemetry not loaded")},e.prototype.isTelemetryEnabled=function(){return this.isEnabled},e.prototype.isProprietyValid=function(t){return e.PROPERTY_REGEX.test(t)},e.prototype.isEventNameValid=function(t){return e.EVENT_NAME_REGEX.test(t)},e.prototype.prepareProperties=function(e){return(e=this.sanitizeProperties(e)).parsely_version=wpParselyTracksTelemetry.version,wpParselyTracksTelemetry.user&&(e._ut=wpParselyTracksTelemetry.user.type,e._ui=wpParselyTracksTelemetry.user.id),wpParselyTracksTelemetry.vipgo_env&&(e.vipgo_env=wpParselyTracksTelemetry.vipgo_env),this.sanitizeProperties(e)},e.prototype.sanitizeProperties=function(e){var t=this,n={};return Object.keys(e).forEach((function(r){t.isProprietyValid(r)&&(n[r]=e[r])})),n},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),S=(k.trackEvent,function(){return(0,f.jsx)(h.SVG,{"aria-hidden":"true",version:"1.1",viewBox:"0 0 15 15",width:"15",height:"15",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(h.Path,{d:"M0 14.0025V11.0025L7.5 3.5025L10.5 6.5025L3 14.0025H0ZM12 5.0025L13.56 3.4425C14.15 2.8525 14.15 1.9025 13.56 1.3225L12.68 0.4425C12.09 -0.1475 11.14 -0.1475 10.56 0.4425L9 2.0025L12 5.0025Z"})})}),j=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{className:i,height:n,viewBox:"0 0 60 65",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M23.72,51.53c0-.18,0-.34-.06-.52a13.11,13.11,0,0,0-2.1-5.53A14.74,14.74,0,0,0,19.12,43c-.27-.21-.5-.11-.51.22l-.24,3.42c0,.33-.38.35-.49,0l-1.5-4.8a1.4,1.4,0,0,0-.77-.78,23.91,23.91,0,0,0-3.1-.84c-1.38-.24-3.39-.39-3.39-.39-.34,0-.45.21-.25.49l2.06,3.76c.2.27,0,.54-.29.33l-4.51-3.6a3.68,3.68,0,0,0-2.86-.48c-1,.16-2.44.46-2.44.46a.68.68,0,0,0-.39.25.73.73,0,0,0-.14.45S.41,43,.54,44a3.63,3.63,0,0,0,1.25,2.62L6.48,50c.28.2.09.49-.23.37l-4.18-.94c-.32-.12-.5,0-.4.37,0,0,.69,1.89,1.31,3.16a24,24,0,0,0,1.66,2.74,1.34,1.34,0,0,0,1,.52l5,.13c.33,0,.41.38.1.48L7.51,58c-.31.1-.34.35-.07.55a14.29,14.29,0,0,0,3.05,1.66,13.09,13.09,0,0,0,5.9.5,25.13,25.13,0,0,0,4.34-1,9.55,9.55,0,0,1-.08-1.2,9.32,9.32,0,0,1,3.07-6.91"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M59.7,41.53a.73.73,0,0,0-.14-.45.68.68,0,0,0-.39-.25s-1.43-.3-2.44-.46a3.64,3.64,0,0,0-2.86.48l-4.51,3.6c-.26.21-.49-.06-.29-.33l2.06-3.76c.2-.28.09-.49-.25-.49,0,0-2,.15-3.39.39a23.91,23.91,0,0,0-3.1.84,1.4,1.4,0,0,0-.77.78l-1.5,4.8c-.11.32-.48.3-.49,0l-.24-3.42c0-.33-.24-.43-.51-.22a14.74,14.74,0,0,0-2.44,2.47A13.11,13.11,0,0,0,36.34,51c0,.18,0,.34-.06.52a9.26,9.26,0,0,1,3,8.1,24.1,24.1,0,0,0,4.34,1,13.09,13.09,0,0,0,5.9-.5,14.29,14.29,0,0,0,3.05-1.66c.27-.2.24-.45-.07-.55l-3.22-1.17c-.31-.1-.23-.47.1-.48l5-.13a1.38,1.38,0,0,0,1-.52A24.6,24.6,0,0,0,57,52.92c.61-1.27,1.31-3.16,1.31-3.16.1-.33-.08-.49-.4-.37l-4.18.94c-.32.12-.51-.17-.23-.37l4.69-3.34A3.63,3.63,0,0,0,59.46,44c.13-1,.24-2.47.24-2.47"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M46.5,25.61c0-.53-.35-.72-.8-.43l-4.86,2.66c-.45.28-.56-.27-.23-.69l4.66-6.23a2,2,0,0,0,.28-1.68,36.51,36.51,0,0,0-2.19-4.89,34,34,0,0,0-2.81-3.94c-.33-.41-.74-.35-.91.16l-2.28,5.68c-.16.5-.6.48-.59-.05l.28-8.93a2.54,2.54,0,0,0-.66-1.64S35,4.27,33.88,3.27,30.78.69,30.78.69a1.29,1.29,0,0,0-1.54,0s-1.88,1.49-3.12,2.59-2.48,2.35-2.48,2.35A2.5,2.5,0,0,0,23,7.27l.27,8.93c0,.53-.41.55-.58.05l-2.29-5.69c-.17-.5-.57-.56-.91-.14a35.77,35.77,0,0,0-3,4.2,35.55,35.55,0,0,0-2,4.62,2,2,0,0,0,.27,1.67l4.67,6.24c.33.42.23,1-.22.69l-4.87-2.66c-.45-.29-.82-.1-.82.43a18.6,18.6,0,0,0,.83,5.07,20.16,20.16,0,0,0,5.37,7.77c3.19,3,5.93,7.8,7.45,11.08A9.6,9.6,0,0,1,30,49.09a9.31,9.31,0,0,1,2.86.45c1.52-3.28,4.26-8.11,7.44-11.09a20.46,20.46,0,0,0,5.09-7,19,19,0,0,0,1.11-5.82"}),(0,f.jsx)(h.Path,{fill:"#5ba745",d:"M36.12,58.44A6.12,6.12,0,1,1,30,52.32a6.11,6.11,0,0,1,6.12,6.12"})]})},P=function(){return P=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0?"".concat(i," ").concat(n):n)||this).hint=null,o.name=o.constructor.name,o.code=r;var s=[U.FetchError,U.HttpRequestFailed,U.ParselySuggestionsApiAuthUnavailable,U.ParselySuggestionsApiOpenAiError,U.ParselySuggestionsApiOpenAiSchema,U.ParselySuggestionsApiOpenAiUnavailable,U.ParselySuggestionsApiSchemaError];return o.retryFetch=s.includes(o.code),Object.setPrototypeOf(o,t.prototype),o.CustomizeErrorMessaging(),o}return oe(t,e),t.prototype.CustomizeErrorMessaging=function(){this.code===U.AccessToFeatureDisabled?this.message=(0,w.__)("Access to this feature is disabled by the site's administration.","wp-parsely"):this.code===U.ParselySuggestionsApiNoAuthorization?this.message=(0,w.__)('This AI-powered feature is opt-in. To gain access, please submit a request here.',"wp-parsely"):this.code===U.ParselySuggestionsApiOpenAiError||this.code===U.ParselySuggestionsApiOpenAiUnavailable?this.message=(0,w.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):this.code===U.HttpRequestFailed&&this.message.includes("cURL error 28")?this.message=(0,w.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):this.code===U.ParselySuggestionsApiSchemaError||this.code===U.ParselySuggestionsInvalidRequest?this.message=(0,w.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):this.code===U.ParselySuggestionsApiNoData||this.code===U.ParselySuggestionsApiNoDataManualLinking?this.message=(0,w.__)("The Parse.ly API couldn't find any relevant data to fulfill the request.","wp-parsely"):this.code===U.ParselySuggestionsApiOpenAiSchema||this.code===U.ParselySuggestionsApiResponseValidationError?this.message=(0,w.__)("The Parse.ly API returned an incorrect response.","wp-parsely"):this.code===U.ParselySuggestionsApiAuthUnavailable&&(this.message=(0,w.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),this.code===U.FetchError&&(this.hint=this.Hint((0,w.__)("This error can sometimes be caused by ad-blockers or browser tracking protections. Please add this site to any applicable allow lists and try again.","wp-parsely"))),this.code!==U.ParselyApiForbidden&&this.code!==U.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,w.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===U.HttpRequestFailed&&(this.hint=this.Hint((0,w.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely")))},t.prototype.Hint=function(e){return'

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

")},t.prototype.Message=function(e){return void 0===e&&(e=null),[U.PluginCredentialsNotSetMessageDetected,U.PluginSettingsSiteIdNotSet,U.PluginSettingsApiSecretNotSet].includes(this.code)?ie(e):(0,f.jsx)(re,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

").concat(this.hint?this.hint:"")})},t.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,v.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),ae=function(e){var t=e.size,n=void 0===t?24:t,r=e.className,i=void 0===r?"wp-parsely-icon":r;return(0,f.jsxs)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",className:i,width:n,height:n,viewBox:"0 0 24 24",fill:"currentColor",children:[(0,f.jsx)(h.Path,{d:"M8.18983 5.90381L8.83642 7.54325L10.4758 8.18983L8.83642 8.8364L8.18983 10.4759L7.54324 8.8364L5.90381 8.18983L7.54324 7.54325L8.18983 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M15.048 5.90381L15.9101 8.08972L18.0961 8.95186L15.9101 9.81397L15.048 11.9999L14.1859 9.81397L12 8.95186L14.1859 8.08972L15.048 5.90381Z"}),(0,f.jsx)(h.Path,{d:"M11.238 10.4761L12.3157 13.2085L15.048 14.2861L12.3157 15.3638L11.238 18.0962L10.1603 15.3638L7.42798 14.2861L10.1603 13.2085L11.238 10.4761Z"})]})},le=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})}),ce=(0,m.forwardRef)((({icon:e,size:t=24,...n},r)=>(0,m.cloneElement)(e,{width:t,height:t,...n,ref:r}))),ue=function(){return(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:(0,f.jsx)(h.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M13.5034 7.91642L9 12.0104L4.49662 7.91642L5.25337 7.08398L8.99999 10.49L12.7466 7.08398L13.5034 7.91642Z",fill:"#1E1E1E"})})},de=function(e){return e&&"object"==typeof e?Object.fromEntries(Object.entries(e).map((function(e){return[e[0],{label:e[1]}]}))):{}},pe=function(){return pe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n32&&(e=e.slice(0,32)),s(e),o(e)}})})},me=function(e){var t=e.persona,n=e.value,r=void 0===n?(0,w.__)("Select a persona…","wp-parsely"):n,i=e.label,o=void 0===i?(0,w.__)("Persona","wp-parsely"):i,s=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,d=void 0!==u&&u,p="parsely-persona-selector-".concat((0,ee.useInstanceId)(me));return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[o&&(0,f.jsx)("label",{htmlFor:p,className:"wp-parsely-editor-sidebar-label",children:o}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Persona","wp-parsely"),className:"parsely-persona-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{id:p,children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-persona-selector-label",children:ge(t)?fe.custom.label:r}),(0,f.jsx)(ue,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Persona","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:he.map((function(e){if(!d&&"custom"===e)return null;var r=fe[e],i=e===t||ge(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),s(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-persona-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ce,{icon:r.icon}),r.label]},e)}))})})}}),d&&ge(t)&&(0,f.jsx)(ye,{onChange:function(e){s(""!==e?e:"custom")},value:"custom"===t?"":t})]})},we=function(){return we=Object.assign||function(e){for(var t,n=1,r=arguments.length;n32&&(e=e.slice(0,32)),s(e),o(e)}})})},je=function(e){var t=e.tone,n=e.value,r=void 0===n?(0,w.__)("Select a tone","wp-parsely"):n,i=e.label,o=void 0===i?(0,w.__)("Tone","wp-parsely"):i,s=e.onChange,a=e.onDropdownChange,l=e.disabled,c=void 0!==l&&l,u=e.allowCustom,d=void 0!==u&&u,p="parsely-tone-selector-".concat((0,ee.useInstanceId)(je));return(0,f.jsxs)(h.Disabled,{isDisabled:c,children:[(0,f.jsx)("label",{htmlFor:p,className:"wp-parsely-editor-sidebar-label",children:o}),(0,f.jsx)(h.DropdownMenu,{label:(0,w.__)("Tone","wp-parsely"),className:"parsely-tone-selector-dropdown"+(c?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{id:p,children:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"parsely-tone-selector-label",children:ke(t)?be.custom.label:r}),(0,f.jsx)(ue,{})]})},children:function(e){var n=e.onClose;return(0,f.jsx)(h.MenuGroup,{label:(0,w.__)("Select a tone","wp-parsely"),children:(0,f.jsx)(f.Fragment,{children:_e.map((function(e){if(!d&&"custom"===e)return null;var r=be[e],i=e===t||ke(t)&&"custom"===e;return(0,f.jsxs)(h.MenuItem,{isSelected:i,className:i?"is-selected":"",role:"menuitemradio",onClick:function(){null==a||a(e),s(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-tone-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,f.jsx)(ce,{icon:r.icon}),r.label]},e)}))})})}}),d&&ke(t)&&(0,f.jsx)(Se,{onChange:function(e){s(""!==e?e:"custom")},value:"custom"===t?"":t})]})},Pe=function(e){return Object.entries(e).map((function(e){var t=e[0];return{label:e[1].label,value:t}}))},Te=Pe(be),Le=Pe(fe),Ee=function(e,t){var n=(0,m.useState)(e),r=n[0],i=n[1],o=(0,m.useRef)(r),s=(0,m.useRef)(t),a=(0,m.useRef)(e);o.current=r,s.current=t;var l=(0,m.useCallback)((function(e){a.current=e,s.current(e)}),[]),c=(0,ee.useDebounce)(l,500);return(0,m.useEffect)((function(){return function(){o.current!==a.current&&l(o.current)}}),[l]),[r,function(e,t){if(void 0===t&&(t=!1),i(e),t)return c.cancel(),void l(e);c(e)}]},Ne=function(e){var t=e.customLabel,n=e.disabled,r=e.label,i=e.onChange,o=e.onSelect,s=e.options,a=e.value,l=function(e,t){return K===e||!t.some((function(t){return t.value===e}))}(a,s),c=Ee(a,i)[1],u=(0,m.useState)(l?K:a),d=u[0],p=u[1],v=(0,m.useState)(l&&K!==a?a:""),g=v[0],y=v[1];return(0,f.jsxs)(h.__experimentalVStack,{spacing:2,children:[(0,f.jsx)(h.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:r,value:d,options:s,onChange:function(e){p(e),c(K===e?g||K:e,!0),o(e)},disabled:n}),K===d&&(0,f.jsx)(h.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:t,maxLength:32,value:g,onChange:function(e){y(e),c(""===e?K:e)},disabled:n})]})},Ce=function(e){var t=e.isLoading,n=e.length,r=e.onLengthChange,i=e.onPersonaChange,o=e.onToneChange,s=e.persona,a=e.tone,l=Ee(n,r),c=l[0],u=l[1];return(0,f.jsxs)(h.__experimentalVStack,{spacing:4,children:[(0,f.jsx)(h.RangeControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,value:c,onChange:function(e){void 0!==e&&u(e)},label:(0,w.__)("Desired length (characters)","wp-parsely"),min:50,max:300,disabled:t}),(0,f.jsx)(Ne,{label:(0,w.__)("Tone","wp-parsely"),customLabel:(0,w.__)("Custom tone","wp-parsely"),value:a,options:Te,onChange:o,onSelect:function(e){k.trackEvent("excerpt_generator_ai_tone_changed",{selectedTone:e})},disabled:t}),(0,f.jsx)(Ne,{label:(0,w.__)("Persona","wp-parsely"),customLabel:(0,w.__)("Custom persona","wp-parsely"),value:s,options:Le,onChange:i,onSelect:function(e){k.trackEvent("excerpt_generator_ai_persona_changed",{persona:e})},disabled:t})]})},Oe=function(){return Oe=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&&(O=(0,w.__)("Regenerate","wp-parsely")),(0,f.jsxs)(h.__experimentalVStack,{className:"wp-parsely-excerpt-suggestions",spacing:4,children:[i&&(0,f.jsx)(h.Notice,{className:"wp-parsely-content-helper-error",onRemove:function(){return s(void 0)},status:"info",children:i.Message()}),(0,f.jsx)("div",{className:"editor-post-excerpt",children:(0,f.jsx)(h.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,w.__)("Write an excerpt (optional)","wp-parsely"),className:"editor-post-excerpt__textarea",onChange:function(e){return S({excerpt:e})},value:L,help:C||null,disabled:u})}),(0,f.jsx)(h.BaseControl,{__nextHasNoMarginBottom:!0,id:_,help:E?null:(0,w.__)("Add content to generate an excerpt.","wp-parsely"),children:(0,f.jsxs)(h.Flex,{justify:"flex-start",gap:2,wrap:!0,ref:y,children:[(0,f.jsx)(h.Button,{__next40pxDefaultSize:!0,"aria-describedby":E?void 0:"".concat(_,"__help"),variant:"secondary",icon:ae,onClick:function(){return e=void 0,n=void 0,i=function(){var e,n,r,i,o,a;return function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0)return r(e.innerBlocks,t[s].innerBlocks);if(JSON.stringify(e)!==JSON.stringify(t[s])){var o=t[s],a=i.parseFromString(e.attributes.content||"","text/html"),l=i.parseFromString((null==o?void 0:o.attributes.content)||"","text/html"),c=Array.from(a.querySelectorAll("a[data-smartlink]")),u=Array.from(l.querySelectorAll("a[data-smartlink]")),p=c.filter((function(e){return!u.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),d=u.filter((function(e){return!c.some((function(t){return t.dataset.smartlink===e.dataset.smartlink}))})),f=c.filter((function(e){var t=u.find((function(t){return t.dataset.smartlink===e.dataset.smartlink}));return t&&t.outerHTML!==e.outerHTML}));(p.length>0||d.length>0||f.length>0)&&n.push({block:e,prevBlock:o,addedLinks:p,removedLinks:d,changedLinks:f})}}}))};return r(e,t),n}(a,l.current);o.length>0&&(o.forEach((function(e){e.changedLinks.length>0&&n&&n(e),e.addedLinks.length>0&&i&&i(e),e.removedLinks.length>0&&r&&r(e)})),l.current=a)}),o);return e(t),function(){e.cancel()}}),[a,o,t,i,n,r]),null},Je=function(e){var t=e.value,n=e.onChange,r=e.max,i=e.min,s=e.suffix,o=e.size,a=e.label,l=e.initialPosition,c=e.disabled,u=e.className,p="parsely-inputrange-control-".concat((0,ee.useInstanceId)(Je));return(0,f.jsxs)("div",{className:"parsely-inputrange-control ".concat(u||""),children:[(0,f.jsx)("label",{htmlFor:p,className:"wp-parsely-editor-sidebar-label",children:a}),(0,f.jsxs)("div",{className:"parsely-inputrange-control__controls",children:[(0,f.jsx)(h.__experimentalNumberControl,{id:p,disabled:c,value:t,suffix:(0,f.jsx)(h.__experimentalInputControlSuffixWrapper,{children:s}),size:null!=o?o:"__unstable-large",min:i,max:r,onChange:function(e){var t=parseInt(e,10);isNaN(t)||n(t)}}),(0,f.jsx)(h.RangeControl,{disabled:c,value:t,showTooltip:!1,initialPosition:l,onChange:function(e){n(e)},withInputField:!1,min:i,max:r})]})]})},Xe=function(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}l((r=r.apply(e,t||[])).next())}))},Qe=function(e,t){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]

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

","\n\x3c!-- /wp:paragraph --\x3e");t&&p((0,Je.parse)(n))}),[o]),(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:s,right:a,up:s,down:a}}),(0,f.jsx)("div",{className:"review-suggestion-post-title",children:null===(t=o.post_data)||void 0===t?void 0:t.title}),(0,f.jsxs)("div",{className:"review-suggestion-preview",children:[!(null===(n=o.post_data)||void 0===n?void 0:n.is_first_paragraph)&&(0,f.jsx)(Ut,{topOrBottom:"top"}),(0,f.jsx)(zt,{block:d[0],link:o,useOriginalBlock:!0}),!(null===(r=o.post_data)||void 0===r?void 0:r.is_last_paragraph)&&(0,f.jsx)(Ut,{topOrBottom:"bottom"})]}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(qt,{link:o}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:s,icon:Ft,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsx)("div",{className:"reviews-controls-middle",children:(0,f.jsx)(h.Button,{target:"_blank",href:(null===(i=o.post_data)||void 0===i?void 0:i.edit_link)+"&smart-link="+o.uid,variant:"secondary",onClick:function(){k.trackEvent("smart_linking_open_in_editor_pressed",{type:"inbound",uid:o.uid})},children:(0,w.__)("Open in the Editor","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:a,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ce,{icon:Vt})]})})]})]})},Kt=function(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;ii.bottom)&&(n.scrollTop=r.offsetTop-n.offsetTop)}}}}),[t,l]);var u=function(){var e=document.querySelector(".smart-linking-review-sidebar-tabs [data-active-item]"),t=null==e?void 0:e.nextElementSibling;t||(t=document.querySelector('.smart-linking-review-sidebar-tabs [role="tab"]')),t&&t.click()},d=(0,f.jsxs)("span",{className:"smart-linking-menu-label",children:[(0,w.__)("NEW","wp-parsely"),(0,f.jsx)(ae,{})]}),p=[];n&&n.length>0&&p.push({name:"outbound",title:(0,w.__)("Outbound","wp-parsely")}),r&&r.length>0&&p.push({name:"inbound",title:(0,w.__)("Inbound","wp-parsely")});var v="outbound";return p=p.filter((function(e){return"outbound"===e.name&&r&&0===r.length&&(e.title=(0,w.__)("Outbound Smart Links","wp-parsely"),v="outbound"),"inbound"===e.name&&n&&0===n.length&&(e.title=(0,w.__)("Inbound Smart Links","wp-parsely"),v="inbound"),e})),(0,f.jsxs)("div",{className:"smart-linking-review-sidebar",ref:o,children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{tab:function(){return u()},"shift+tab":function(){return u()}}}),(0,f.jsx)(h.TabPanel,{className:"smart-linking-review-sidebar-tabs",initialTabName:v,tabs:p,onSelect:function(e){var t,o;"outbound"===e&&n&&n.length>0&&i(n[0]),"inbound"===e&&r&&r.length>0&&i(r[0]),k.trackEvent("smart_linking_modal_tab_selected",{tab:e,total_inbound:null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0,total_outbound:null!==(o=null==n?void 0:n.length)&&void 0!==o?o:0})},children:function(e){return(0,f.jsxs)(f.Fragment,{children:["outbound"===e.name&&(0,f.jsx)(f.Fragment,{children:n&&0!==n.length?n.map((function(e,n){return(0,f.jsxs)(h.MenuItem,{ref:function(e){s.current[n]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:[(0,f.jsx)("span",{className:"smart-linking-menu-item",children:e.text}),!e.applied&&d]},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No outbound links found.","wp-parsely")]})}),"inbound"===e.name&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{className:"review-sidebar-tip",children:(0,w.__)("This section shows external posts that link back to the current post.","wp-parsely")}),r&&0!==r.length?r.map((function(e,r){var o;return(0,f.jsx)(h.MenuItem,{ref:function(e){s.current[(n?n.length:0)+r]=e},className:(null==t?void 0:t.uid)===e.uid?"is-selected":"",role:"menuitemradio",isSelected:(null==t?void 0:t.uid)===e.uid,onClick:function(){return i(e)},children:(0,f.jsx)("span",{className:"smart-linking-menu-item",children:null===(o=e.post_data)||void 0===o?void 0:o.title})},e.uid)})):(0,f.jsxs)(f.Fragment,{children:[" ",(0,w.__)("No inbound links found.","wp-parsely")]})]})]})}})]})},Yt=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm.5 16c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V7h15v12zM9 10H7v2h2v-2zm0 4H7v2h2v-2zm4-4h-2v2h2v-2zm4 0h-2v2h2v-2zm-4 4h-2v2h2v-2zm4 0h-2v2h2v-2z"})}),$t=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10 4.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm2.25 7.5v-1A2.75 2.75 0 0011 8.25H7A2.75 2.75 0 004.25 11v1h1.5v-1c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v1h1.5zM4 20h9v-1.5H4V20zm16-4H4v-1.5h16V16z",fillRule:"evenodd",clipRule:"evenodd"})}),Jt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m7.3 9.7 1.4 1.4c.2-.2.3-.3.4-.5 0 0 0-.1.1-.1.3-.5.4-1.1.3-1.6L12 7 9 4 7.2 6.5c-.6-.1-1.1 0-1.6.3 0 0-.1 0-.1.1-.3.1-.4.2-.6.4l1.4 1.4L4 11v1h1l2.3-2.3zM4 20h9v-1.5H4V20zm0-5.5V16h16v-1.5H4z"})}),Xt=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M3.99961 13C4.67043 13.3354 4.6703 13.3357 4.67017 13.3359L4.67298 13.3305C4.67621 13.3242 4.68184 13.3135 4.68988 13.2985C4.70595 13.2686 4.7316 13.2218 4.76695 13.1608C4.8377 13.0385 4.94692 12.8592 5.09541 12.6419C5.39312 12.2062 5.84436 11.624 6.45435 11.0431C7.67308 9.88241 9.49719 8.75 11.9996 8.75C14.502 8.75 16.3261 9.88241 17.5449 11.0431C18.1549 11.624 18.6061 12.2062 18.9038 12.6419C19.0523 12.8592 19.1615 13.0385 19.2323 13.1608C19.2676 13.2218 19.2933 13.2686 19.3093 13.2985C19.3174 13.3135 19.323 13.3242 19.3262 13.3305L19.3291 13.3359C19.3289 13.3357 19.3288 13.3354 19.9996 13C20.6704 12.6646 20.6703 12.6643 20.6701 12.664L20.6697 12.6632L20.6688 12.6614L20.6662 12.6563L20.6583 12.6408C20.6517 12.6282 20.6427 12.6108 20.631 12.5892C20.6078 12.5459 20.5744 12.4852 20.5306 12.4096C20.4432 12.2584 20.3141 12.0471 20.1423 11.7956C19.7994 11.2938 19.2819 10.626 18.5794 9.9569C17.1731 8.61759 14.9972 7.25 11.9996 7.25C9.00203 7.25 6.82614 8.61759 5.41987 9.9569C4.71736 10.626 4.19984 11.2938 3.85694 11.7956C3.68511 12.0471 3.55605 12.2584 3.4686 12.4096C3.42484 12.4852 3.39142 12.5459 3.36818 12.5892C3.35656 12.6108 3.34748 12.6282 3.34092 12.6408L3.33297 12.6563L3.33041 12.6614L3.32948 12.6632L3.32911 12.664C3.32894 12.6643 3.32879 12.6646 3.99961 13ZM11.9996 16C13.9326 16 15.4996 14.433 15.4996 12.5C15.4996 10.567 13.9326 9 11.9996 9C10.0666 9 8.49961 10.567 8.49961 12.5C8.49961 14.433 10.0666 16 11.9996 16Z"})}),Qt=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})}),en=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"})}),tn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M16.5 7.5 10 13.9l-2.5-2.4-1 1 3.5 3.6 7.5-7.6z"})}),nn=function(e){var t,n,r=e.post,i=e.imageUrl,o=e.icon,s=void 0===o?Dt:o,a=e.size,l=void 0===a?100:a,c=e.className,u=void 0===c?"":c,d=null!==(t=null==r?void 0:r.thumbnail)&&void 0!==t?t:i,p=null!==(n=null==r?void 0:r.title.rendered)&&void 0!==n?n:"";return(0,f.jsx)("div",{className:"parsely-thumbnail ".concat(u),style:{width:l,height:l},children:d?(0,f.jsx)("img",{src:d,alt:p,width:l,height:l,loading:"lazy","aria-hidden":""===p}):(0,f.jsx)("div",{className:"parsely-thumbnail-icon-container",children:(0,f.jsx)(h.Icon,{icon:s,size:l})})})};function rn(e,t,n){void 0===t&&(t=1),void 0===n&&(n="");var r=parseInt(e.replace(/\D/g,""),10);if(r<1e3)return e;r<1e4&&(t=1);var i=r,o=r.toString(),s="",a=0;return Object.entries({1e3:"k","1,000,000":"M","1,000,000,000":"B","1,000,000,000,000":"T","1,000,000,000,000,000":"Q"}).forEach((function(e){var n=e[0],l=e[1],c=parseInt(n.replace(/\D/g,""),10);if(r>=c){var u=t;(i=r/c)%1>1/a&&(u=i>10?1:2),u=parseFloat(i.toFixed(2))===parseFloat(i.toFixed(0))?0:u,o=i.toFixed(u),s=l}a=c})),o+n+s}var on,sn=function(e){var t,n,r,i,o=null===(t=e.link.match)||void 0===t?void 0:t.blockId,s=(0,v.useSelect)((function(e){var t=e("core/block-editor"),n=t.getBlock,r=t.getBlockParents;return o?{block:n(o),parents:r(o).map((function(e){return n(e)})).filter((function(e){return void 0!==e}))}:{block:void 0,parents:[]}}),[o]),a=s.block,l=s.parents;return a?(0,f.jsxs)("div",{className:"review-suggestions-breadcrumbs",children:[l.map((function(e,t){var n;return(0,f.jsxs)("span",{children:[(0,f.jsx)("span",{className:"breadcrumbs-parent-block",children:null===(n=(0,Je.getBlockType)(e.name))||void 0===n?void 0:n.title}),(0,f.jsx)("span",{className:"breadcrumbs-parent-separator",children:" / "})]},t)})),(0,f.jsxs)("span",{className:"breadcrumbs-current-block",children:[(0,f.jsx)("span",{className:"breadcrumbs-current-block-type",children:null===(n=(0,Je.getBlockType)(a.name))||void 0===n?void 0:n.title}),(null===(i=null===(r=a.attributes)||void 0===r?void 0:r.metadata)||void 0===i?void 0:i.name)&&(0,f.jsx)("span",{className:"breadcrumbs-current-block-name",children:a.attributes.metadata.name})]})]}):(0,f.jsx)(f.Fragment,{})},an=function(e){var t,n,r,i,o,s,a,l,c,u,d,p,v,g,y=e.link,m=null!==(n=null===(t=y.wp_post_meta)||void 0===t?void 0:t.author)&&void 0!==n?n:(0,w.__)("N/A","wp-parsely"),b=null!==(i=null===(r=y.post_stats)||void 0===r?void 0:r.avg_engaged)&&void 0!==i?i:(0,w.__)("N/A","wp-parsely"),_=(null===(o=y.wp_post_meta)||void 0===o?void 0:o.date)?function(e){if(!1===function(e){return!isNaN(+e)&&0!==e.getTime()}(e))return Et;var t=Tt;return e.getUTCFullYear()===(new Date).getUTCFullYear()&&(t=Lt),Intl.DateTimeFormat(document.documentElement.lang||"en",t).format(e)}(new Date(y.wp_post_meta.date)):(0,w.__)("N/A","wp-parsely"),x=null!==(a=null===(s=y.wp_post_meta)||void 0===s?void 0:s.thumbnail)&&void 0!==a&&a,k=null!==(c=null===(l=y.wp_post_meta)||void 0===l?void 0:l.title)&&void 0!==c?c:(0,w.__)("N/A","wp-parsely"),S=null!==(d=null===(u=y.wp_post_meta)||void 0===u?void 0:u.type)&&void 0!==d?d:(0,w.__)("External","wp-parsely"),j=null===(p=y.wp_post_meta)||void 0===p?void 0:p.url,P=(null===(v=y.post_stats)||void 0===v?void 0:v.views)?rn(y.post_stats.views):(0,w.__)("N/A","wp-parsely"),T=(null===(g=y.post_stats)||void 0===g?void 0:g.visitors)?rn(y.post_stats.visitors):(0,w.__)("N/A","wp-parsely");return(0,f.jsxs)("div",{className:"wp-parsely-link-suggestion-link-details",children:[(0,f.jsx)("div",{className:"thumbnail-column",children:x?(0,f.jsx)(nn,{imageUrl:x,size:52}):(0,f.jsx)(nn,{icon:Dt,size:52})}),(0,f.jsxs)("div",{className:"data-column",children:[(0,f.jsxs)("div",{className:"title-row",children:[(0,f.jsx)(h.Tooltip,{text:k,children:(0,f.jsx)("span",{children:k})}),j&&(0,f.jsx)(h.Button,{href:j,target:"_blank",variant:"link",rel:"noopener",children:(0,f.jsx)(ce,{icon:Xe,size:18})})]}),(0,f.jsxs)("div",{className:"data-row",children:[(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ce,{icon:Yt,size:16}),(0,f.jsx)("span",{children:_})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ce,{icon:$t,size:16}),(0,f.jsx)(h.Tooltip,{text:m,children:(0,f.jsx)("span",{children:m})})]}),(0,f.jsxs)("div",{className:"data-point shrinkable",children:[(0,f.jsx)(ce,{icon:Jt,size:16}),(0,f.jsx)(h.Tooltip,{text:S,children:(0,f.jsx)("span",{children:S})})]})]}),y.post_stats&&(0,f.jsxs)("div",{className:"data-row",children:[P&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ce,{icon:Xt,size:16}),(0,f.jsx)("span",{children:P})]}),T&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(ce,{icon:Qt,size:16}),(0,f.jsx)("span",{children:T})]}),b&&(0,f.jsxs)("div",{className:"data-point",children:[(0,f.jsx)(h.Dashicon,{icon:"clock",size:16}),(0,f.jsx)("span",{children:b})]})]})]})]})},ln=function(e){var t=e.link,n=e.onNext,r=e.onPrevious,i=e.onAccept,o=e.onReject,s=e.onRemove,a=e.onSelectInEditor,l=e.hasPrevious,c=e.hasNext;if(t&&void 0!==t.post_data)return(0,f.jsx)(Zt,{link:t,onNext:n,onPrevious:r,onAccept:i,onReject:o,onRemove:s,onSelectInEditor:a,hasPrevious:l,hasNext:c});if(!(null==t?void 0:t.match))return(0,f.jsx)(f.Fragment,{children:(0,w.__)("This Smart Link does not have any matches in the current content.","wp-parsely")});var u=t.match.blockId,d=(0,v.select)("core/block-editor").getBlock(u),p=t.applied;return d?(0,f.jsxs)("div",{className:"smart-linking-review-suggestion",children:[(0,f.jsx)(h.KeyboardShortcuts,{shortcuts:{left:r,right:n,up:r,down:n,a:function(){t&&!t.applied&&i()},r:function(){t&&(t.applied?s():o())}}}),(0,f.jsx)(sn,{link:t}),(0,f.jsx)("div",{className:"review-suggestion-preview",children:(0,f.jsx)(zt,{block:d,link:t})}),(0,f.jsx)(h.__experimentalDivider,{}),(0,f.jsx)(an,{link:t}),(0,f.jsxs)("div",{className:"review-controls",children:[(0,f.jsx)(h.Tooltip,{shortcut:"←",text:(0,w.__)("Previous","wp-parsely"),children:(0,f.jsx)(h.Button,{disabled:!l,className:"wp-parsely-review-suggestion-previous",onClick:r,icon:Ft,children:(0,w.__)("Previous","wp-parsely")})}),(0,f.jsxs)("div",{className:"reviews-controls-middle",children:[!p&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Reject","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:en,onClick:o,variant:"secondary",children:(0,w.__)("Reject","wp-parsely")})}),(0,f.jsx)(h.Tooltip,{shortcut:"A",text:(0,w.__)("Accept","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",icon:tn,onClick:i,variant:"secondary",children:(0,w.__)("Accept","wp-parsely")})})]}),p&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tooltip,{shortcut:"R",text:(0,w.__)("Remove","wp-parsely"),children:(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-reject",icon:en,onClick:s,variant:"secondary",children:(0,w.__)("Remove","wp-parsely")})}),(0,f.jsx)(h.Button,{className:"wp-parsely-review-suggestion-accept",onClick:a,variant:"secondary",children:(0,w.__)("Select in Editor","wp-parsely")})]})]}),(0,f.jsx)(h.Tooltip,{shortcut:"→",text:(0,w.__)("Next","wp-parsely"),children:(0,f.jsxs)(h.Button,{disabled:!c,onClick:n,className:"wp-parsely-review-suggestion-next",children:[(0,w.__)("Next","wp-parsely"),(0,f.jsx)(ce,{icon:Vt})]})})]})]}):(0,f.jsx)(f.Fragment,{children:(0,w.__)("No block is selected.","wp-parsely")})},cn=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))},un=function(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&(a=s[0],(l=a.parentNode)&&(c=document.createTextNode(null!==(u=a.textContent)&&void 0!==u?u:""),l.replaceChild(c,a),$.updateBlockAttributes(n,{content:o.innerHTML}))),[4,E(t.uid)]):[2]):[2];case 1:return d.sent(),[2]}}))}))},C=(0,m.useCallback)((function(){c(!1),_().filter((function(e){return!e.applied})).length>0?s(!0):(J.unlockPostAutosaving("smart-linking-review-modal"),t())}),[_,t]),O=function(e){s(!1),e?(c(!1),T().then((function(){C()}))):c(!0)},A=function(){if(it(S)){var e=g.indexOf(S);if(!g[t=e+1])return;j(g[t])}else{var t;if(e=p.indexOf(S),!p[t=e+1])return;j(p[t])}},I=function(){if(it(S)){var e=g.indexOf(S);if(!g[t=e-1])return;j(g[t])}else{var t;if(e=p.indexOf(S),!p[t=e-1])return;j(p[t])}};return(0,m.useEffect)((function(){l?J.lockPostAutosaving("smart-linking-review-modal"):l&&0===d.length&&C()}),[l,t,d,C]),(0,m.useEffect)((function(){c(n)}),[n]),(0,f.jsxs)(f.Fragment,{children:[l&&(0,f.jsx)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),className:"wp-parsely-smart-linking-review-modal",onRequestClose:C,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,children:(0,f.jsxs)("div",{className:"smart-linking-modal-body",children:[(0,f.jsx)(Wt,{outboundLinks:p,inboundLinks:g,activeLink:S,setSelectedLink:j}),S&&(it(S)?(0,f.jsx)(Zt,{link:S,onNext:A,onPrevious:I,hasNext:g.indexOf(S)0}):(0,f.jsx)(ln,{link:S,hasNext:b().indexOf(S)0,onNext:A,onPrevious:I,onAccept:function(){return cn(void 0,void 0,void 0,(function(){var e,t;return un(this,(function(n){switch(n.label){case 0:return S.match?(r(S),[4,(i=S.match.blockId,o=S,cn(void 0,void 0,void 0,(function(){var e,t;return un(this,(function(n){switch(n.label){case 0:return(e=document.createElement("a")).href=o.href.itm,e.title=o.title,e.setAttribute("data-smartlink",o.uid),(t=(0,v.select)("core/block-editor").getBlock(i))?(at(t,o,e),o.applied=!0,[4,L(o)]):[2];case 1:return n.sent(),[2]}}))})))]):[2];case 1:return n.sent(),k.trackEvent("smart_linking_link_accepted",{link:S.href.raw,title:S.title,text:S.text,uid:S.uid}),0===y().length?(C(),[2]):(e=p.indexOf(S),p[t=e+1]?j(p[t]):j(p[0]),[2])}var i,o}))}))},onReject:function(){return cn(void 0,void 0,void 0,(function(){var e,t;return un(this,(function(n){switch(n.label){case 0:return e=p.indexOf(S),p[t=e+1]?j(p[t]):p[0]?j(p[0]):C(),[4,E(S.uid)];case 1:return n.sent(),k.trackEvent("smart_linking_link_rejected",{link:S.href.raw,title:S.title,text:S.text,uid:S.uid}),[2]}}))}))},onRemove:function(){return cn(void 0,void 0,void 0,(function(){var e,t,n,r;return un(this,(function(i){switch(i.label){case 0:return S.match?(e=(0,v.select)("core/block-editor").getBlock(S.match.blockId))?(t=b(),n=t.indexOf(S),r=n-1,[4,N(e,S)]):[3,2]:[2];case 1:if(i.sent(),k.trackEvent("smart_linking_link_removed",{link:S.href.raw,title:S.title,text:S.text,uid:S.uid}),0===(t=b()).length&&g.length>0)return j(g[0]),[2];if(0===t.length&&0===g.length)return C(),[2];if(t[r])return j(t[r]),[2];j(t[0]),i.label=2;case 2:return[2]}}))}))},onSelectInEditor:function(){if(S.match){var e=(0,v.select)("core/block-editor").getBlock(S.match.blockId);if(e){$.selectBlock(e.clientId);var t=document.querySelector('[data-block="'.concat(e.clientId,'"]'));t&&vt(t,S.uid),k.trackEvent("smart_linking_select_in_editor_pressed",{type:"outbound",uid:S.uid}),C()}}}}))]})}),o&&(0,f.jsxs)(h.Modal,{title:(0,w.__)("Review Smart Links","wp-parsely"),onRequestClose:function(){return O(!1)},className:"wp-parsely-smart-linking-close-dialog",children:[(0,w.__)("Are you sure you want to close? All un-accepted Smart Links will not be added.","wp-parsely"),(0,f.jsxs)("div",{className:"smart-linking-close-dialog-actions",children:[(0,f.jsx)(h.Button,{variant:"secondary",onClick:function(){return O(!1)},children:(0,w.__)("Go Back","wp-parsely")}),(0,f.jsx)(h.Button,{variant:"secondary",isDestructive:!0,onClick:function(){return O(!0)},children:(0,w.__)("Close","wp-parsely")})]})]})]})})),pn=function(){return pn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&S("success",/* translators: %s: number of smart links applied */ /* translators: %s: number of smart links applied */ +(0,w.sprintf)((0,w.__)("%s Smart Links successfully applied.","wp-parsely"),g),{type:"snackbar"}):y(0)}),[_]),(0,m.useEffect)((function(){if(!(Object.keys(R).length>0)){var e={maxLinksPerPost:a.SmartLinking.MaxLinks};Q(e)}}),[Q,a]);var de=(0,v.useSelect)((function(e){var t=e("core/block-editor"),r=t.getSelectedBlock,i=t.getBlock,o=t.getBlocks,s=e("core/editor"),a=s.getEditedPostContent,l=s.getCurrentPostAttribute;return{allBlocks:o(),selectedBlock:n?i(n):r(),postContent:a(),postPermalink:l("link")}}),[n]),pe=de.allBlocks,fe=de.selectedBlock,he=de.postContent,ve=de.postPermalink,ge=function(e){return fn(void 0,void 0,void 0,(function(){var t,n,r,i,o;return hn(this,(function(s){switch(s.label){case 0:t=[],s.label=1;case 1:return s.trys.push([1,4,,9]),[4,te((n=E||!fe)?yt.All:yt.Selected)];case 2:return s.sent(),a=ve.replace(/^https?:\/\//i,""),r=["http://"+a,"https://"+a],i=function(e){return e.map((function(e){return e.href.raw}))}(F),r.push.apply(r,i),[4,Rt.getInstance().generateSmartLinks(fe&&!n?(0,Je.getBlockContent)(fe):he,A,r)];case 3:return t=s.sent(),[3,9];case 4:if((o=s.sent()).code&&o.code===U.ParselyAborted)throw o.numRetries=3-e,o;return e>0&&o.retryFetch?(console.error(o),[4,re(!0)]):[3,8];case 5:return s.sent(),[4,ie()];case 6:return s.sent(),[4,ge(e-1)];case 7:return[2,s.sent()];case 8:throw o;case 9:return[2,t]}var a}))}))},ye=function(){for(var e=[],t=0;t[type="button"]').forEach((function(e){e.setAttribute("disabled","disabled")}))},be=function(){document.querySelectorAll('.edit-post-header__settings>[type="button"]').forEach((function(e){e.removeAttribute("disabled")})),J.unlockPostSaving("wp-parsely-block-overlay")};return(0,f.jsxs)("div",{className:"wp-parsely-smart-linking",children:[(0,f.jsx)(Qe,{isDetectingEnabled:!L,onLinkRemove:function(e){!function(e){tt(this,void 0,void 0,(function(){var t,n,r;return nt(this,(function(i){switch(i.label){case 0:return[4,ft((0,Je.getBlockContent)(e),e.clientId)];case 1:return t=i.sent(),n=t.missingSmartLinks,r=t.didAnyFixes,n.forEach((function(e){(0,v.dispatch)(xt).removeSmartLink(e.uid)})),[2,r]}}))}))}(e.block)}}),(0,f.jsxs)(h.PanelRow,{className:t,children:[(0,f.jsxs)("div",{className:"smart-linking-text",children:[(0,w.__)("Automatically insert links to your most relevant, top performing content.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/smart-linking/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Smart Linking","wp-parsely"),(0,f.jsx)(ce,{icon:Xe,size:18,className:"parsely-external-link-icon"})]})]}),C&&(0,f.jsx)(h.Notice,{status:"info",onRemove:function(){return Z(null)},className:"wp-parsely-content-helper-error",children:C.Message()}),_&&g>0&&(0,f.jsx)(h.Notice,{status:"success",onRemove:function(){return x(!1)},className:"wp-parsely-smart-linking-suggested-links",children:(0,w.sprintf)(/* translators: %s: number of smart links generated */ /* translators: %s: number of smart links generated */ +(0,w.__)("Successfully added %s Smart Links.","wp-parsely"),g>0?g:O.length)}),(0,f.jsx)(jt,{disabled:T,selectedBlock:fe,onSettingChange:function(e,t){var n;d({SmartLinking:pn(pn({},a.SmartLinking),(n={},n[e]=t,n))}),"MaxLinks"===e&&ne(t)}}),(0,f.jsx)("div",{className:"smart-linking-generate",children:(0,f.jsx)(h.Button,{onClick:function(){return fn(void 0,void 0,void 0,(function(){var e,t,n,r,o,s,a,l;return hn(this,(function(c){switch(c.label){case 0:return[4,q(!0)];case 1:return c.sent(),[4,oe()];case 2:return c.sent(),[4,Z(null)];case 3:return c.sent(),x(!1),k.trackEvent("smart_linking_generate_pressed",{is_full_content:E,selected_block:null!==(s=null==fe?void 0:fe.name)&&void 0!==s?s:"none",context:i}),[4,ye(E?"all":null==fe?void 0:fe.clientId)];case 4:c.sent(),e=setTimeout((function(){var e;q(!1),k.trackEvent("smart_linking_generate_timeout",{is_full_content:E,selected_block:null!==(e=null==fe?void 0:fe.name)&&void 0!==e?e:"none",context:i}),me(E?"all":null==fe?void 0:fe.clientId)}),18e4),t=M,c.label=5;case 5:return c.trys.push([5,8,10,15]),[4,ge(3)];case 6:return n=c.sent(),[4,(u=n,fn(void 0,void 0,void 0,(function(){var e;return hn(this,(function(t){switch(t.label){case 0:return u=u.filter((function(e){return!F.some((function(t){return t.uid===e.uid&&t.applied}))})),e=ve.replace(/^https?:\/\//,"").replace(/\/+$/,""),u=(u=u.filter((function(t){return!t.href.raw.includes(e)||(console.warn("PCH Smart Linking: Skipping self-reference link: ".concat(t.href)),!1)}))).filter((function(e){return!F.some((function(t){return t.href===e.href?(console.warn("PCH Smart Linking: Skipping duplicate link: ".concat(e.href)),!0):t.text===e.text&&t.offset!==e.offset&&(console.warn("PCH Smart Linking: Skipping duplicate link text: ".concat(e.text)),!0)}))})),u=(u=ut(E?pe:[fe],u,{}).filter((function(e){return e.match}))).filter((function(e){if(!e.match)return!1;var t=e.match.blockLinkPosition,n=t+e.text.length;return!F.some((function(r){if(!r.match)return!1;if(e.match.blockId!==r.match.blockId)return!1;var i=r.match.blockLinkPosition,o=i+r.text.length;return t>=i&&n<=o}))})),[4,K(u)];case 1:return t.sent(),[2,u]}}))})))];case 7:if(0===c.sent().length)throw new se((0,w.__)("No Smart Links were generated.","wp-parsely"),U.ParselySuggestionsApiNoData,"");return ae(!0),[3,15];case 8:return r=c.sent(),o=new se(null!==(a=r.message)&&void 0!==a?a:"An unknown error has occurred.",null!==(l=r.code)&&void 0!==l?l:U.UnknownError),r.code&&r.code===U.ParselyAborted&&(o.message=(0,w.sprintf)(/* translators: 1: number of retry attempts, 2: attempt plural */ /* translators: 1: number of retry attempts, 2: attempt plural */ +(0,w.__)("The Smart Linking process was cancelled after %1$d %2$s.","wp-parsely"),r.numRetries,(0,w._n)("attempt","attempts",r.numRetries,"wp-parsely"))),console.error(r),[4,Z(o)];case 9:return c.sent(),o.createErrorSnackbar(),[3,15];case 10:return[4,q(!1)];case 11:return c.sent(),[4,te(t)];case 12:return c.sent(),[4,re(!1)];case 13:return c.sent(),[4,me(E?"all":null==fe?void 0:fe.clientId)];case 14:return c.sent(),clearTimeout(e),[7];case 15:return[2]}var u}))}))},variant:"secondary",isBusy:T,disabled:T,children:B?(0,w.sprintf)(/* translators: %1$d: number of retry attempts, %2$d: maximum number of retries */ /* translators: %1$d: number of retry attempts, %2$d: maximum number of retries */ +(0,w.__)("Retrying… Attempt %1$d of %2$d","wp-parsely"),D,3):T?(0,w.__)("Generating Smart Links…","wp-parsely"):(0,w.__)("Add Smart Links","wp-parsely")})}),(H.length>0||V.length>0)&&(0,f.jsx)("div",{className:"smart-linking-manage",children:(0,f.jsx)(h.Button,{onClick:function(){return fn(void 0,void 0,void 0,(function(){var e,t;return hn(this,(function(n){switch(n.label){case 0:return[4,ht()];case 1:return e=n.sent(),t=dt(),[4,K(t)];case 2:return n.sent(),ae(!0),k.trackEvent("smart_linking_review_pressed",{num_smart_links:F.length,has_fixed_links:e,context:i}),[2]}}))}))},variant:"secondary",disabled:T,children:(0,w.__)("Review Smart Links","wp-parsely")})})]}),L&&(0,f.jsx)(dn,{isOpen:L,onAppliedLink:function(){y((function(e){return e+1}))},onClose:function(){x(!0),ae(!1)}})]})},mn=function(){return mn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0)&&(t(),e())}))}))]}))},new((n=void 0)||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}));var e,t,n,r}().then((function(){var t=document.querySelector(".wp-block-post-content");vt(t,e)}))})))},Cn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M7 11.5h10V13H7z"})}),On=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"})}),An=function(e){var t=e.title,n=e.icon,r=e.subtitle,i=e.level,o=void 0===i?2:i,s=e.children,a=e.controls,l=e.onClick,c=e.isOpen,u=e.isLoading,d=e.dropdownChildren;return(0,f.jsxs)("div",{className:"performance-stat-panel",children:[(0,f.jsxs)(h.__experimentalHStack,{className:"panel-header level-"+o,children:[(0,f.jsx)(h.__experimentalHeading,{level:o,children:t}),r&&!c&&(0,f.jsx)("span",{className:"panel-subtitle",children:r}),a&&!d&&(0,f.jsx)(h.DropdownMenu,{icon:n,label:(0,w.__)("Settings","wp-parsely"),className:"panel-settings-button",controls:a}),d&&(0,f.jsx)(h.DropdownMenu,{icon:n,label:(0,w.__)("Settings","wp-parsely"),className:"panel-settings-button",children:d}),n&&!d&&!a&&(0,f.jsx)(h.Button,{icon:n,className:"panel-settings-button",isPressed:c,onClick:l})]}),(0,f.jsx)("div",{className:"panel-body",children:u?(0,f.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,f.jsx)(h.Spinner,{})}):s})]})},In=function(e){var t=e.data,n=e.isLoading,r=(0,m.useState)(M.Views),i=r[0],o=r[1],s=(0,m.useState)(!1),a=s[0],l=s[1];n||delete t.referrers.types.totals;var c=function(e){switch(e){case"social":return(0,w.__)("Social","wp-parsely");case"search":return(0,w.__)("Search","wp-parsely");case"other":return(0,w.__)("Other","wp-parsely");case"internal":return(0,w.__)("Internal","wp-parsely");case"direct":return(0,w.__)("Direct","wp-parsely")}return e},u=(0,w.sprintf)((0,w.__)("By %s","wp-parsely"),H(i)); +/* translators: %s: metric description */return(0,f.jsxs)(An,{title:(0,w.__)("Categories","wp-parsely"),level:3,subtitle:u,isOpen:a,onClick:function(){return l(!a)},children:[a&&(0,f.jsx)("div",{className:"panel-settings",children:(0,f.jsx)(h.SelectControl,{value:i,prefix:(0,w.__)("By:","wp-parsely"),onChange:function(e){F(e,M)&&o(e)},children:Object.values(M).map((function(e){return(0,f.jsxs)("option",{value:e,disabled:"avg_engaged"===e,children:[H(e),"avg_engaged"===e&&" "+(0,w.__)("(coming soon)","wp-parsely")]},e)}))})}),n?(0,f.jsx)("div",{className:"parsely-spinner-wrapper","data-testid":"parsely-spinner-wrapper",children:(0,f.jsx)(h.Spinner,{})}):(0,f.jsxs)("div",{children:[(0,f.jsx)("div",{className:"multi-percentage-bar",children:Object.entries(t.referrers.types).map((function(e){var t=e[0],n=e[1],r=(0,w.sprintf)(/* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ /* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */ (0,w.__)("%1$s: %2$s%%","wp-parsely"),c(t),n.viewsPercentage);return(0,f.jsx)(h.Tooltip /* translators: %s: percentage value */,{ /* translators: %s: percentage value */ -text:"".concat(c(t)," - ").concat((0,w.sprintf)((0,w.__)("%s%%","wp-parsely"),n.viewsPercentage)),delay:150,children:(0,f.jsx)("div",{"aria-label":r,className:"bar-fill "+t,style:{width:n.viewsPercentage+"%"}})},t)}))}),(0,f.jsx)("div",{className:"percentage-bar-labels",children:Object.entries(t.referrers.types).map((function(e){var t=e[0],n=e[1];return(0,f.jsxs)("div",{className:"single-label "+t,children:[(0,f.jsx)("div",{className:"label-color "+t}),(0,f.jsx)("div",{className:"label-text",children:c(t)}),(0,f.jsx)("div",{className:"label-value",children:en(n.views)})]},t)}))})]})]})},On=(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"})}),An=(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"})}),In=function(){return In=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]%s has 0 views, or the Parse.ly API returned no data.","wp-parsely"),r),U.ParselyApiReturnedNoData,""))]):n.length>1?[2,Promise.reject(new oe((0,w.sprintf)(/* translators: %d: URL of the published post */ /* translators: %d: 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 qn(this,void 0,void 0,(function(){return Zn(this,(function(r){switch(r.label){case 0:return[4,this.fetch({path:(0,kt.addQueryArgs)("/wp-parsely/v2/stats/post/".concat(t,"/referrers"),Un(Un({},Tt(e)),{itm_source:this.itmSource,total_views:n}))})];case 1:return[2,r.sent()]}}))}))},t}(Ne),Wn=function(){return Wn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return t.sent(),[4,n(r-1)];case 2:return t.sent(),[3,4];case 3:a(e),i(!1),t.label=4;case 4:return[2]}}))}))})),[2]}))}))};return i(!0),n(1),function(){a(void 0)}}),[t]),(0,f.jsxs)("div",{className:"wp-parsely-performance-panel",children:[(0,f.jsx)(Nn,{title:(0,w.__)("Performance Stats","wp-parsely"),icon:En,dropdownChildren:function(e){var t=e.onClose;return(0,f.jsx)(er,{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:Wn(Wn({},d.PerformanceStats),{Period:e})}),k.trackEvent("editor_sidebar_performance_period_changed",{period:e}))},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})})}),o?o.Message():(0,f.jsxs)(f.Fragment,{children:[Qn(d,"overview")&&(0,f.jsx)(Hn,{data:c,isLoading:r}),Qn(d,"categories")&&(0,f.jsx)(Cn,{data:c,isLoading:r}),Qn(d,"referrers")&&(0,f.jsx)(Gn,{data:c,isLoading:r})]}),window.wpParselyPostUrl&&(0,f.jsx)(h.Button,{className:"wp-parsely-view-post",variant:"secondary",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")})]})},nr=function(e){var t=e.period;return(0,f.jsx)(h.Panel,{children:(0,f.jsx)(Ke,{children:(0,f.jsx)(tr,{period:t})})})},rr=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,B.Author)},options:s,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,B.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(),B.Tag)},value:t.tags,suggestions:n.tags,maxLength:5})]})},ir=(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"})}),sr=(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"})}),or=function(e){var t=e.size,n=void 0===t?40:t,r=e.color,i=void 0===r?"#cccccc":r;return(0,f.jsx)(f.Fragment,{children:(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"3",height:n,viewBox:"0 0 1 ".concat(n),fill:"none",children:(0,f.jsx)(h.Rect,{width:"1",height:n,fill:i})})})};function ar(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,en(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 lr=function(e){var t,n,r=e.metric,i=e.post,s=e.postContent,o=(0,v.useDispatch)("core/notices").createNotice,a=s&&(t=s,n=qe(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)(ar,{metric:r,post:i,viewsIcon:(0,f.jsx)(ce,{icon:Yt}),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)(ce,{icon:ir,size:24})})})]}),(0,f.jsx)(or,{}),(0,f.jsxs)("div",{children:[(0,f.jsx)(h.Button,{icon:sr,iconSize:24,onClick:function(){navigator.clipboard.writeText(i.rawUrl).then((function(){o("success",(0,w.__)("URL copied to clipboard","wp-parsely"),{type:"snackbar"})}))},label:(0,w.__)("Copy URL to clipboard","wp-parsely")}),(0,f.jsx)(h.Button,{icon:(0,f.jsx)(j,{}),iconSize:18,href:i.dashUrl,target:"_blank",label:(0,w.__)("View in Parse.ly","wp-parsely")})]})]})})]})},cr=window.wp.coreData,ur=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 __)}}(),pr=function(){return pr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&f.every(Number.isInteger)?null!==(n=l("taxonomy","category",{include:f,context:"view"}))&&void 0!==n?n:void 0:null,tagRecords:o=Array.isArray(h)&&h.length>0&&h.every(Number.isInteger)?null!==(r=l("taxonomy","post_tag",{include:h,context:"view"}))&&void 0!==r?r:void 0:null,isLoading:u("getEntityRecords",["root","user",{include:[d],context:"view"}])||u("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||u("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}]),hasResolved:(c("getEntityRecords",["root","user",{include:[d],context:"view"}])||null===i)&&(c("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||null===s)&&(c("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}])||null===o)}}),[]);return(0,m.useEffect)((function(){var e=r.authorRecords,t=r.categoryRecords,i=r.tagRecords,s=r.isLoading;r.hasResolved&&!s&&n({authors:e,categories:t,tags:i,isReady:!0})}),[r]),t}(),c=l.authors,u=l.categories,p=l.tags,d=l.isReady,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,v.useSelect)((function(e){var t=e(yr),n=t.isLoading,r=t.getPosts,i=t.getFilters;return{firstRun:(0,t.isFirstRun)(),loading:n(),posts:r(),filters:i()}}),[]),b=y.firstRun,_=y.loading,x=y.posts,S=y.filters,j=(0,v.useDispatch)(yr),P=j.setFirstRun,T=j.setLoading,L=j.setPosts,E=j.setFilters,N=(0,m.useState)(),C=N[0],O=N[1],A=(0,m.useState)(void 0),D=A[0],G=A[1],z=(0,ee.useDebounce)(G,1e3);(0,v.useSelect)((function(e){if("undefined"==typeof jest){var t=e("core/editor").getEditedPostContent;z(t())}else z("Jest test is running")}),[z]);var U=function(e,t,n,r){return br(void 0,void 0,void 0,(function(){return _r(this,(function(i){return T(!0),hr.getInstance().getRelatedPosts(e,t,n).then((function(e){L(e),T(!1)})).catch((function(i){return br(void 0,void 0,void 0,(function(){return _r(this,(function(s){switch(s.label){case 0:return r>0&&i.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return s.sent(),[4,U(e,t,n,r-1)];case 2:return s.sent(),[3,4];case 3:T(!1),O(i),L([]),s.label=4;case 4:return[2]}}))}))})),[2]}))}))};return b&&(U(r,i,S,1),P(!1)),0===o.authors.length&&0===o.categories.length&&0===o.tags.length&&d?(0,f.jsx)("div",{className:"wp-parsely-related-posts",children:(0,f.jsx)("div",{className:"related-posts-body",children:(0,w.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,f.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,f.jsx)("div",{className:"related-posts-description",children:(0,w.__)("Find top-performing related posts.","wp-parsely")}),(0,f.jsxs)("div",{className:"related-posts-body",children:[(0,f.jsxs)("div",{className:"related-posts-settings",children:[(0,f.jsx)(h.SelectControl,{size:"__unstable-large",onChange:function(e){return function(e){if(F(e,M)){var i=e;n({RelatedPosts:wr(wr({},t.RelatedPosts),{Metric:i})}),k.trackEvent("related_posts_metric_changed",{metric:i}),U(r,i,S,1)}}(e)},prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Metric:","wp-parsely")}),value:i,children:Object.values(M).map((function(e){return(0,f.jsx)("option",{value:e,children:H(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){if(F(e,R)){var r=e;n({RelatedPosts:wr(wr({},t.RelatedPosts),{Period:r})}),k.trackEvent("related_posts_period_changed",{period:r}),U(r,i,S,1)}}(e)},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})]}),(0,f.jsx)(rr,{label:(0,w.__)("Filter by","wp-parsely"),filters:S,onFiltersChange:function(e,t){var n,s;if(null==e&&(e=""),B.Tag===t){var o=[];""!==e&&(o=e.split(",").map((function(e){return e.trim()}))),s=wr(wr({},S),{tags:o})}else s=wr(wr({},S),((n={})[t]=e,n));E(s),U(r,i,s,1)},postData:o}),(0,f.jsxs)("div",{className:"related-posts-wrapper",children:[C&&C.Message(),_&&(0,f.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,w.__)("Loading…","wp-parsely")}),!b&&!_&&!C&&0===x.length&&(0,f.jsx)("div",{className:"related-posts-empty",children:(0,w.__)("No related posts found.","wp-parsely")}),!_&&x.length>0&&(0,f.jsx)("div",{className:"related-posts-list",children:x.map((function(e){return(0,f.jsx)(lr,{metric:i,post:e,postContent:D},e.id)}))})]})]})]})},kr=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10.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"})}),jr=(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"})}),Pr=(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"})}),Tr=function(){return Tr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,f.jsx)("span",{className:"parsely-write-titles-text",children:(0,m.createInterpolateElement)( +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:rn(n.views)})]},t)}))})]})]})},Rn=(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"})}),Mn=(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"})}),Bn=function(){return Bn=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 se((0,w.sprintf)(/* translators: %d: URL of the published post */ /* translators: %d: 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 Wn(this,void 0,void 0,(function(){return Yn(this,(function(r){switch(r.label){case 0:return[4,this.fetch({path:(0,Pt.addQueryArgs)("/wp-parsely/v2/stats/post/".concat(t,"/referrers"),Kn(Kn({},Nt(e)),{itm_source:this.itmSource,total_views:n}))})];case 1:return[2,r.sent()]}}))}))},t}(Ae),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&&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)(An,{title:(0,w.__)("Performance Stats","wp-parsely"),icon:On,dropdownChildren:function(e){var t=e.onClose;return(0,f.jsx)(rr,{onClose:t})},children:(0,f.jsx)("div",{className:"panel-settings",children:(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:p.PerformanceStats.Period,prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Period:","wp-parsely")}),onChange:function(e){F(e,R)&&(v({PerformanceStats:Jn(Jn({},p.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:[nr(p,"overview")&&(0,f.jsx)(Un,{data:c,isLoading:r}),nr(p,"categories")&&(0,f.jsx)(In,{data:c,isLoading:r}),nr(p,"referrers")&&(0,f.jsx)(qn,{data:c,isLoading:r})]}),window.wpParselyPostUrl&&(0,f.jsx)(h.Button,{className:"wp-parsely-view-post",variant:"secondary",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")})]})},or=function(e){var t=e.period;return(0,f.jsx)(h.Panel,{children:(0,f.jsx)($e,{children:(0,f.jsx)(ir,{period:t})})})},sr=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,B.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,B.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(),B.Tag)},value:t.tags,suggestions:n.tags,maxLength:5})]})},ar=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"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"})}),lr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"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"})}),cr=function(e){var t=e.size,n=void 0===t?40:t,r=e.color,i=void 0===r?"#cccccc":r;return(0,f.jsx)(f.Fragment,{children:(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"3",height:n,viewBox:"0 0 1 ".concat(n),fill:"none",children:(0,f.jsx)(h.Rect,{width:"1",height:n,fill:i})})})};function ur(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,rn(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 dr=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=We(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)(ur,{metric:r,post:i,viewsIcon:(0,f.jsx)(ce,{icon:Xt}),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)(ce,{icon:ar,size:24})})})]}),(0,f.jsx)(cr,{}),(0,f.jsxs)("div",{children:[(0,f.jsx)(h.Button,{icon:lr,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")})]})]})})]})},pr=window.wp.coreData,fr=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 __)}}(),hr=function(){return hr=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:[p],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:[p],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,d=l.tags,p=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(p){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(d)})}}),[c,u,d,p]);var y=(0,v.useSelect)((function(e){var t=e(br),n=t.isLoading,r=t.getPosts,i=t.getFilters;return{firstRun:(0,t.isFirstRun)(),loading:n(),posts:r(),filters:i()}}),[]),b=y.firstRun,_=y.loading,x=y.posts,S=y.filters,j=(0,v.useDispatch)(br),P=j.setFirstRun,T=j.setLoading,L=j.setPosts,E=j.setFilters,N=(0,m.useState)(),C=N[0],O=N[1],A=(0,m.useState)(void 0),D=A[0],G=A[1],z=(0,ee.useDebounce)(G,1e3);(0,v.useSelect)((function(e){if("undefined"==typeof jest){var t=e("core/editor").getEditedPostContent;z(t())}else z("Jest test is running")}),[z]);var U=function(e,t,n,r){return kr(void 0,void 0,void 0,(function(){return Sr(this,(function(i){return T(!0),yr.getInstance().getRelatedPosts(e,t,n).then((function(e){L(e),T(!1)})).catch((function(i){return kr(void 0,void 0,void 0,(function(){return Sr(this,(function(o){switch(o.label){case 0:return r>0&&i.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return o.sent(),[4,U(e,t,n,r-1)];case 2:return o.sent(),[3,4];case 3:T(!1),O(i),L([]),o.label=4;case 4:return[2]}}))}))})),[2]}))}))};return b&&(U(r,i,S,1),P(!1)),0===s.authors.length&&0===s.categories.length&&0===s.tags.length&&p?(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){return function(e){if(F(e,M)){var i=e;n({RelatedPosts:xr(xr({},t.RelatedPosts),{Metric:i})}),k.trackEvent("related_posts_metric_changed",{metric:i}),U(r,i,S,1)}}(e)},prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Metric:","wp-parsely")}),value:i,children:Object.values(M).map((function(e){return(0,f.jsx)("option",{value:e,children:H(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){if(F(e,R)){var r=e;n({RelatedPosts:xr(xr({},t.RelatedPosts),{Period:r})}),k.trackEvent("related_posts_period_changed",{period:r}),U(r,i,S,1)}}(e)},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})]}),(0,f.jsx)(sr,{label:(0,w.__)("Filter by","wp-parsely"),filters:S,onFiltersChange:function(e,t){var n,o;if(null==e&&(e=""),B.Tag===t){var s=[];""!==e&&(s=e.split(",").map((function(e){return e.trim()}))),o=xr(xr({},S),{tags:s})}else o=xr(xr({},S),((n={})[t]=e,n));E(o),U(r,i,o,1)},postData:s}),(0,f.jsxs)("div",{className:"related-posts-wrapper",children:[C&&C.Message(),_&&(0,f.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,w.__)("Loading…","wp-parsely")}),!b&&!_&&!C&&0===x.length&&(0,f.jsx)("div",{className:"related-posts-empty",children:(0,w.__)("No related posts found.","wp-parsely")}),!_&&x.length>0&&(0,f.jsx)("div",{className:"related-posts-list",children:x.map((function(e){return(0,f.jsx)(dr,{metric:i,post:e,postContent:D},e.id)}))})]})]})]})},Pr=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10.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"})}),Tr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M18.3 11.7c-.6-.6-1.4-.9-2.3-.9H6.7l2.9-3.3-1.1-1-4.5 5L8.5 16l1-1-2.7-2.7H16c.5 0 .9.2 1.3.5 1 1 1 3.4 1 4.5v.3h1.5v-.2c0-1.5 0-4.3-1.5-5.7z"})}),Lr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z"})}),Er=(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"})}),Nr=function(){return Nr=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:we(a)}),persona:(0,f.jsx)("strong",{children:fe(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 Title Suggestions","wp-parsely"),(0,f.jsx)(ce,{icon:Ye,size:18,className:"parsely-external-link-icon"})]})]}),i&&(0,f.jsx)(h.Notice,{className:"wp-parsely-content-helper-error",onRemove:function(){return s(void 0)},status:"info",children:i.Message()}),void 0!==S&&(0,f.jsx)(Ir,{title:S,type:mr.PostTitle,isOriginal:!0}),0<_.length&&(0,f.jsxs)(f.Fragment,{children:[b.length>0&&(0,f.jsx)(Rr,{pinnedTitles:b,isOpen:!0}),y.length>0&&(0,f.jsx)(Br,{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:"secondary",isBusy:g,disabled:g||"custom"===a||"custom"===u,onClick:function(){return Hr(void 0,void 0,void 0,(function(){return Gr(this,(function(e){switch(e.label){case 0:return s(void 0),!1!==g?[3,2]:(k.trackEvent("title_suggestions_generate_pressed",{request_more:y.length>0,total_titles:y.length,total_pinned:y.filter((function(e){return e.isPinned})).length,tone:a,persona:u}),[4,(t=mr.PostTitle,n=O,r=a,i=u,Hr(void 0,void 0,void 0,(function(){var e,o,a;return Gr(this,(function(l){switch(l.label){case 0:return[4,T(!0)];case 1:l.sent(),e=Fr.getInstance(),l.label=2;case 2:return l.trys.push([2,5,,6]),[4,e.generateTitles(n,3,r,i)];case 3:return o=l.sent(),[4,P(t,o)];case 4:return l.sent(),[3,6];case 5:return a=l.sent(),s(a),P(t,[]),[3,6];case 6:return[4,T(!1)];case 7:return l.sent(),[2]}}))})))]);case 1:e.sent(),e.label=2;case 2:return[2]}var t,n,r,i}))}))},children:[g&&(0,w.__)("Generating Titles…","wp-parsely"),!g&&_.length>0&&(0,w.__)("Generate More","wp-parsely"),!g&&0===_.length&&(0,w.__)("Generate Titles","wp-parsely")]})})]})})},Ur=function(){return Ur=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&u&&r.TrafficBoost&&(0,f.jsxs)(h.Button,{className:"boost-engagement",href:qr(window.wpParselyAdminUrl,l),rel:"noopener",target:"_blank",variant:"secondary",children:[(0,w.__)("Boost Engagement","wp-parsely"),(0,f.jsx)(h.Icon,{icon:Ye,size:18,className:"parsely-external-link-icon"})]})]})})},Kr=function(){return Kr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n300)&&(r.ExcerptSuggestions.Length=n.ExcerptSuggestions.Length),"string"!=typeof r.ExcerptSuggestions.Tone&&(r.ExcerptSuggestions.Tone=n.ExcerptSuggestions.Tone),"string"!=typeof r.ExcerptSuggestions.Persona&&(r.ExcerptSuggestions.Persona=n.ExcerptSuggestions.Persona),r},$r=function(){var e=I(),t=e.settings,n=e.setSettings,r=G(),i=(0,v.useSelect)((function(e){var t;return(null===(t=window.wp.editor)||void 0===t?void 0:t.PluginSidebar)?e("core/interface").getActiveComplementaryArea("core"):e("core/interface").getActiveComplementaryArea("core/edit-post")}),[]);(0,m.useEffect)((function(){"wp-parsely-block-editor-sidebar/wp-parsely-content-helper"===i&&k.trackEvent("editor_sidebar_opened")}),[i]);var s=function(e,t){t?k.trackEvent("editor_sidebar_panel_opened",{panel:e}):k.trackEvent("editor_sidebar_panel_closed",{panel:e})};return(0,f.jsx)(d,{icon:(0,f.jsx)(j,{className:"wp-parsely-sidebar-icon"}),name:"wp-parsely-content-helper",className:"wp-parsely-content-helper",title:(0,w.__)("Parse.ly","wp-parsely"),children:(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Yr(),children:(0,f.jsx)(h.Panel,{className:"wp-parsely-sidebar-main-panel",children:(0,f.jsx)(h.TabPanel,{className:"wp-parsely-sidebar-tabs",initialTabName:t.InitialTabName,tabs:[{icon:(0,f.jsx)(S,{}),name:"tools",title:(0,w.__)("Tools","wp-parsely")},{icon:_,name:"performance",title:(0,w.__)("Performance","wp-parsely")}],onSelect:function(e){n(Kr(Kr({},t),{InitialTabName:e})),k.trackEvent("editor_sidebar_tab_selected",{tab:e})},children:function(e){return(0,f.jsxs)(f.Fragment,{children:["tools"===e.name&&(0,f.jsx)(Zr,{permissions:r,trackToggle:s}),"performance"===e.name&&(0,f.jsx)(nr,{period:t.PerformanceStats.Period})]})}})})})})};Ue&&Ue(),(0,x.registerPlugin)(Wr,{icon:j,render:function(){return(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Yr(),children:(0,f.jsx)($r,{})})}}),y()((function(){Tn&&Tn()}))}()}(); \ No newline at end of file +(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:xe(a)}),persona:(0,f.jsx)("strong",{children:ve(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 Title Suggestions","wp-parsely"),(0,f.jsx)(ce,{icon:Xe,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)(Br,{title:S,type:_r.PostTitle,isOriginal:!0}),0<_.length&&(0,f.jsxs)(f.Fragment,{children:[b.length>0&&(0,f.jsx)(Dr,{pinnedTitles:b,isOpen:!0}),y.length>0&&(0,f.jsx)(Vr,{suggestions:y,isOpen:!0,isLoading:g})]}),(0,f.jsx)(Fr,{isLoading:g,onPersonaChange:function(e){C("Persona",e),d(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:"secondary",isBusy:g,disabled:g||"custom"===a||"custom"===u,onClick:function(){return Ur(void 0,void 0,void 0,(function(){return qr(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=_r.PostTitle,n=O,r=a,i=u,Ur(void 0,void 0,void 0,(function(){var e,s,a;return qr(this,(function(l){switch(l.label){case 0:return[4,T(!0)];case 1:l.sent(),e=Gr.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&&_.length>0&&(0,w.__)("Generate More","wp-parsely"),!g&&0===_.length&&(0,w.__)("Generate Titles","wp-parsely")]})})]})})},Kr=function(){return Kr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&u&&r.TrafficBoost&&(0,f.jsxs)(h.Button,{className:"boost-engagement",href:Wr(window.wpParselyAdminUrl,l),rel:"noopener",target:"_blank",variant:"secondary",children:[(0,w.__)("Boost Engagement","wp-parsely"),(0,f.jsx)(h.Icon,{icon:Xe,size:18,className:"parsely-external-link-icon"})]})]})})},$r=function(){return $r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n300)&&(r.ExcerptSuggestions.Length=n.ExcerptSuggestions.Length),"string"!=typeof r.ExcerptSuggestions.Tone&&(r.ExcerptSuggestions.Tone=n.ExcerptSuggestions.Tone),"string"!=typeof r.ExcerptSuggestions.Persona&&(r.ExcerptSuggestions.Persona=n.ExcerptSuggestions.Persona),r},Qr=function(){var e=I(),t=e.settings,n=e.setSettings,r=G(),i=(0,v.useSelect)((function(e){var t;return(null===(t=window.wp.editor)||void 0===t?void 0:t.PluginSidebar)?e("core/interface").getActiveComplementaryArea("core"):e("core/interface").getActiveComplementaryArea("core/edit-post")}),[]);(0,m.useEffect)((function(){"wp-parsely-block-editor-sidebar/wp-parsely-content-helper"===i&&k.trackEvent("editor_sidebar_opened")}),[i]);var o=function(e,t){t?k.trackEvent("editor_sidebar_panel_opened",{panel:e}):k.trackEvent("editor_sidebar_panel_closed",{panel:e})};return(0,f.jsx)(p,{icon:(0,f.jsx)(j,{className:"wp-parsely-sidebar-icon"}),name:"wp-parsely-content-helper",className:"wp-parsely-content-helper",title:(0,w.__)("Parse.ly","wp-parsely"),children:(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Xr(),children:(0,f.jsx)(h.Panel,{className:"wp-parsely-sidebar-main-panel",children:(0,f.jsx)(h.TabPanel,{className:"wp-parsely-sidebar-tabs",initialTabName:t.InitialTabName,tabs:[{icon:(0,f.jsx)(S,{}),name:"tools",title:(0,w.__)("Tools","wp-parsely")},{icon:_,name:"performance",title:(0,w.__)("Performance","wp-parsely")}],onSelect:function(e){n($r($r({},t),{InitialTabName:e})),k.trackEvent("editor_sidebar_tab_selected",{tab:e})},children:function(e){return(0,f.jsxs)(f.Fragment,{children:["tools"===e.name&&(0,f.jsx)(Yr,{permissions:r,trackToggle:o}),"performance"===e.name&&(0,f.jsx)(or,{period:t.PerformanceStats.Period})]})}})})})})};Ke&&Ke(),(0,x.registerPlugin)(Jr,{icon:j,render:function(){return(0,f.jsx)(D,{endpoint:"editor-sidebar",defaultSettings:Xr(),children:(0,f.jsx)(Qr,{})})}}),y()((function(){Nn&&Nn()}))}()}(); \ No newline at end of file diff --git a/src/@types/assets/window.d.ts b/src/@types/assets/window.d.ts index e6cbe6c19a..b3ff74ccfd 100644 --- a/src/@types/assets/window.d.ts +++ b/src/@types/assets/window.d.ts @@ -25,7 +25,9 @@ declare global { wpParselyAdminUrl: string; wpParselyContentHelperPermissions: string; + wpParselyContentHelperPersonas?: Record; wpParselyContentHelperSettings: string; + wpParselyContentHelperTones?: Record; wpParselyDependencies: { [key: string]: string }; wpParselyDisableAutotrack?: boolean; wpParselyEmptyCredentialsMessage: string; diff --git a/src/content-helper/common/components/persona-selector/component.tsx b/src/content-helper/common/components/persona-selector/component.tsx index 55c17fbba2..ba229f793d 100644 --- a/src/content-helper/common/components/persona-selector/component.tsx +++ b/src/content-helper/common/components/persona-selector/component.tsx @@ -17,54 +17,29 @@ import { Icon, pencil } from '@wordpress/icons'; * Internal dependencies */ import { MoreArrow } from '../../icons/more-arrow'; +import { toMetadata, VocabularyEntry } from '../../utils/vocabulary'; /** * Represents a single persona in the PARSELY_PERSONAS list. * * @since 3.14.0 */ -type PersonaMetadata = { - label: string, - icon?: React.JSX.Element, -}; +type PersonaMetadata = VocabularyEntry; /** * List of the available personas. * Each persona has a label and an optional icon. * + * The predefined personas come from PHP, which is their single source, so that + * the plugin's settings page can offer the same choices. The custom persona is + * defined here, as it is a UI affordance rather than part of the vocabulary, + * and carries an icon that PHP cannot express. + * * @since 3.13.0 + * @since 3.24.0 The predefined personas are supplied by PHP. */ export const PARSELY_PERSONAS: Record = { - journalist: { - label: __( 'Journalist', 'wp-parsely' ), - }, - editorialWriter: { - label: __( 'Editorial Writer', 'wp-parsely' ), - }, - investigativeReporter: { - label: __( 'Investigative Reporter', 'wp-parsely' ), - }, - techAnalyst: { - label: __( 'Tech Analyst', 'wp-parsely' ), - }, - businessAnalyst: { - label: __( 'Business Analyst', 'wp-parsely' ), - }, - culturalCommentator: { - label: __( 'Cultural Commentator', 'wp-parsely' ), - }, - scienceCorrespondent: { - label: __( 'Science Correspondent', 'wp-parsely' ), - }, - politicalAnalyst: { - label: __( 'Political Analyst', 'wp-parsely' ), - }, - healthWellnessAdvocate: { - label: __( 'Health and Wellness Advocate', 'wp-parsely' ), - }, - environmentalJournalist: { - label: __( 'Environmental Journalist', 'wp-parsely' ), - }, + ...toMetadata( window.wpParselyContentHelperPersonas ), custom: { label: __( 'Custom Persona', 'wp-parsely' ), icon: pencil, diff --git a/src/content-helper/common/components/tone-selector/component.tsx b/src/content-helper/common/components/tone-selector/component.tsx index 420a006e64..209ea37349 100644 --- a/src/content-helper/common/components/tone-selector/component.tsx +++ b/src/content-helper/common/components/tone-selector/component.tsx @@ -17,54 +17,29 @@ import { Icon, pencil } from '@wordpress/icons'; * Internal dependencies */ import { MoreArrow } from '../../icons/more-arrow'; +import { toMetadata, VocabularyEntry } from '../../utils/vocabulary'; /** * Represents a single tone in the PARSELY_TONES list. * * @since 3.14.0 */ -type ToneMetadata = { - label: string, - icon?: React.JSX.Element, -}; +type ToneMetadata = VocabularyEntry; /** * List of the available tones. * Each tone has a label and an optional icon. * + * The predefined tones come from PHP, which is their single source, so that + * the plugin's settings page can offer the same choices. The custom tone is + * defined here, as it is a UI affordance rather than part of the vocabulary, + * and carries an icon that PHP cannot express. + * * @since 3.13.0 + * @since 3.24.0 The predefined tones are supplied by PHP. */ export const PARSELY_TONES: Record = { - neutral: { - label: __( 'Neutral', 'wp-parsely' ), - }, - formal: { - label: __( 'Formal', 'wp-parsely' ), - }, - humorous: { - label: __( 'Humorous', 'wp-parsely' ), - }, - confident: { - label: __( 'Confident', 'wp-parsely' ), - }, - provocative: { - label: __( 'Provocative', 'wp-parsely' ), - }, - serious: { - label: __( 'Serious', 'wp-parsely' ), - }, - inspirational: { - label: __( 'Inspirational', 'wp-parsely' ), - }, - skeptical: { - label: __( 'Skeptical', 'wp-parsely' ), - }, - conversational: { - label: __( 'Conversational', 'wp-parsely' ), - }, - analytical: { - label: __( 'Analytical', 'wp-parsely' ), - }, + ...toMetadata( window.wpParselyContentHelperTones ), custom: { label: __( 'Custom Tone', 'wp-parsely' ), icon: pencil, diff --git a/src/content-helper/common/utils/vocabulary.ts b/src/content-helper/common/utils/vocabulary.ts new file mode 100644 index 0000000000..8bd9203055 --- /dev/null +++ b/src/content-helper/common/utils/vocabulary.ts @@ -0,0 +1,35 @@ +/** + * A tone or persona entry, as consumed by the selector components. + * + * @since 3.24.0 + */ +export type VocabularyEntry = { + label: string, + icon?: React.JSX.Element, +}; + +/** + * Converts a value => label record injected by PHP into selector metadata. + * + * PHP is the single source of the predefined tones and personas, so that the + * plugin's settings page can offer the same choices as the editor. The record + * is absent on screens that do not inject it, in which case only the custom + * entry defined by the selector remains. + * + * @since 3.24.0 + * + * @param {Record|undefined} labels The injected labels. + * + * @return {Record} The selector metadata. + */ +export const toMetadata = ( + labels: Record | undefined +): Record => { + if ( ! labels || 'object' !== typeof labels ) { + return {}; + } + + return Object.fromEntries( + Object.entries( labels ).map( ( [ value, label ] ) => [ value, { label } ] ) + ); +}; diff --git a/src/content-helper/editor-sidebar/class-editor-sidebar.php b/src/content-helper/editor-sidebar/class-editor-sidebar.php index cda7e06667..0d46b2c453 100644 --- a/src/content-helper/editor-sidebar/class-editor-sidebar.php +++ b/src/content-helper/editor-sidebar/class-editor-sidebar.php @@ -185,6 +185,17 @@ public function run(): void { 'before' ); + // Inject the tones and personas, so that PHP stays their single source + // and the settings page can offer the same choices as the editor. + wp_add_inline_script( + static::get_script_id(), + 'window.wpParselyContentHelperTones = ' . + wp_json_encode( Suggestion_Defaults::get_tones() ) . ';' . + 'window.wpParselyContentHelperPersonas = ' . + wp_json_encode( Suggestion_Defaults::get_personas() ) . ';', + 'before' + ); + $use_category_slugs_in_searches = apply_filters( 'wp_parsely_use_category_slugs_in_searches', false ); wp_add_inline_script( static::get_script_id(),