From 2334fb0185f428c2f09c72d746a71eeafc894597 Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Tue, 10 Nov 2026 18:47:35 +0800 Subject: [PATCH 01/10] Open the beehiiv menu to users who can publish posts and keep Settings administrator-only --- includes/Admin/Menu.php | 55 +++++++++++- includes/Admin/SettingsPage.php | 6 +- tests/e2e/specs/menu-registration.spec.js | 101 +++++++++++++++++----- 3 files changed, 136 insertions(+), 26 deletions(-) diff --git a/includes/Admin/Menu.php b/includes/Admin/Menu.php index 2cdbf1c..fc5cabd 100644 --- a/includes/Admin/Menu.php +++ b/includes/Admin/Menu.php @@ -24,17 +24,70 @@ final class Menu { * Icon is drawn in global admin CSS (`src/js/admin/admin.scss`) via mask so it * follows the same currentColor / hover / active states as Dashicons. * + * The top-level entry is open to anyone who can publish posts so authors can + * reach Newsletters. The Settings page is registered first as its own + * `manage_options` submenu under the same slug, so it stays administrator-only. + * This runs on `admin_menu` priority 5, before core adds the Newsletters + * submenu (priority 10), so Settings is first and the parent already exists. + * * @since 1.0.0 */ public static function register(): void { add_menu_page( __( 'beehiiv Settings', 'beehiiv' ), __( 'beehiiv', 'beehiiv' ), - 'manage_options', + 'publish_posts', Config::PLUGIN_SLUG, [ SettingsPage::class, 'render' ], 'none', 99 ); + + // Registered before any other submenu so it replaces the automatic first + // submenu item, which would otherwise inherit the lower top-level capability. + add_submenu_page( + Config::PLUGIN_SLUG, + __( 'beehiiv Settings', 'beehiiv' ), + __( 'Settings', 'beehiiv' ), + 'manage_options', + Config::PLUGIN_SLUG, + [ SettingsPage::class, 'render' ] + ); + } + + /** + * Keep the top-level entry from landing non-administrators on Settings. + * + * Core skips the Settings submenu for users without `manage_options`, then adds + * an automatic first item that points at the top-level slug (the Settings page). + * That item is dropped so the top-level entry opens the first remaining submenu, + * Newsletters. Users who cannot publish posts get no beehiiv menu at all, because + * the top-level capability would deny them the Newsletters page anyway. + * + * Runs on `admin_menu` after core adds the post type submenus (priority 10). + * + * @since x.x.x + */ + public static function prune_for_non_administrators(): void { + global $submenu; + + if ( current_user_can( 'manage_options' ) ) { + return; + } + + if ( ! current_user_can( 'publish_posts' ) ) { + remove_menu_page( Config::PLUGIN_SLUG ); + return; + } + + if ( empty( $submenu[ Config::PLUGIN_SLUG ] ) || ! is_array( $submenu[ Config::PLUGIN_SLUG ] ) ) { + return; + } + + foreach ( $submenu[ Config::PLUGIN_SLUG ] as $index => $item ) { + if ( Config::PLUGIN_SLUG === $item[2] ) { + unset( $submenu[ Config::PLUGIN_SLUG ][ $index ] ); + } + } } } diff --git a/includes/Admin/SettingsPage.php b/includes/Admin/SettingsPage.php index a1e71a3..ac95986 100644 --- a/includes/Admin/SettingsPage.php +++ b/includes/Admin/SettingsPage.php @@ -34,7 +34,11 @@ public static function init(): void { */ public static function render(): void { if ( ! current_user_can( 'manage_options' ) ) { - return; + wp_die( + esc_html__( 'Sorry, you are not allowed to access this page.', 'beehiiv' ), + '', + [ 'response' => 403 ] + ); } require Config::ADMIN_VIEWS_DIR . 'settings-page.php'; diff --git a/tests/e2e/specs/menu-registration.spec.js b/tests/e2e/specs/menu-registration.spec.js index f9318a2..3b61f49 100644 --- a/tests/e2e/specs/menu-registration.spec.js +++ b/tests/e2e/specs/menu-registration.spec.js @@ -5,24 +5,33 @@ const { wpCli, wpCliSafe, ensurePluginActive } = require( '../utils/wp-cli' ); /** * PRD: requirements/08-admin-interface/2-admin-menu/menu-registration.prd.md * - * Non-admin fixture user for AC-004. Created idempotently (reused across - * repeated runs against this shared wp-env tests environment, matching the - * `ensurePluginActive`-style pattern in utils/wp-cli.js) with the Editor - * role, which does not carry `manage_options` -- the capability the beehiiv - * menu item is registered under (includes/Admin/Menu.php). + * Fixture users, created idempotently (reused across repeated runs against + * this shared wp-env tests environment): + * - Editor: can publish posts, no `manage_options`. + * - Author: can publish posts, no `manage_options`. + * - Contributor: cannot publish posts. */ -const NON_ADMIN_USERNAME = 'qa_e2e_menu_editor'; -const NON_ADMIN_PASSWORD = 'qa-e2e-menu-editor-pw-1'; +const USERS = { + editor: { name: 'qa_e2e_menu_editor', role: 'editor' }, + author: { name: 'qa_e2e_menu_author', role: 'author' }, + contributor: { name: 'qa_e2e_menu_contributor', role: 'contributor' }, +}; +const PASSWORD = 'qa-e2e-menu-user-pw-1'; test.beforeAll( () => { ensurePluginActive(); - if ( wpCliSafe( `user get ${ NON_ADMIN_USERNAME } --field=ID` ) === null ) { - wpCli( - `user create ${ NON_ADMIN_USERNAME } ${ NON_ADMIN_USERNAME }@example.test ` + - `--role=editor --user_pass=${ NON_ADMIN_PASSWORD }` - ); - } + Object.values( USERS ).forEach( ( { name, role } ) => { + if ( wpCliSafe( `user get ${ name } --field=ID` ) === null ) { + wpCli( + `user create ${ name } ${ name }@example.test ` + + `--role=${ role } --user_pass=${ PASSWORD }` + ); + } else { + // Reused user from an earlier run: pin the known password. + wpCli( `user update ${ name } --user_pass=${ PASSWORD }` ); + } + } ); } ); test.describe( 'Admin menu registration', () => { @@ -78,20 +87,64 @@ test.describe( 'Admin menu registration', () => { expect( parseFloat( beforeStyle.height ) ).toBeGreaterThan( 0 ); } ); - test( 'AC-004: the menu item is hidden from, and the settings page blocked for, non-administrator users', async ( { + test( 'AC-004: the beehiiv Settings page is reachable by administrators only', async ( { page, + browser, } ) => { - await loginAs( page, NON_ADMIN_USERNAME, NON_ADMIN_PASSWORD ); - await page.goto( '/wp-admin/' ); - - await expect( page.locator( '#toplevel_page_beehiiv' ) ).toHaveCount( - 0 + // Administrator reaches the page. + await loginAsAdmin( page ); + const adminResponse = await page.goto( + '/wp-admin/admin.php?page=beehiiv' ); + expect( adminResponse.status() ).toBe( 200 ); + await expect( page.locator( 'h1' ) ).toHaveText( 'beehiiv Settings' ); - const response = await page.goto( '/wp-admin/admin.php?page=beehiiv' ); - expect( response.status() ).toBe( 403 ); - await expect( page.locator( 'body' ) ).toContainText( - /not allowed to access this page/i - ); + // Every non-administrator is blocked, including users who can + // publish posts (they see the beehiiv menu, but not Settings). + for ( const { name } of Object.values( USERS ) ) { + const context = await browser.newContext(); + const userPage = await context.newPage(); + await loginAs( userPage, name, PASSWORD ); + + const response = await userPage.goto( + '/wp-admin/admin.php?page=beehiiv' + ); + expect( response.status(), `${ name } status` ).toBe( 403 ); + await expect( userPage.locator( 'body' ) ).toContainText( + /not allowed to access this page/i + ); + await expect( + userPage.locator( 'h1', { hasText: 'beehiiv Settings' } ) + ).toHaveCount( 0 ); + + await userPage.goto( '/wp-admin/' ); + await expect( + userPage.locator( + '#toplevel_page_beehiiv .wp-submenu a:text-is("Settings")' + ) + ).toHaveCount( 0 ); + + await context.close(); + } + } ); + + test( 'AC-005: users who can publish posts see a Newsletters entry under the beehiiv menu', async ( { + browser, + } ) => { + for ( const { name } of [ USERS.editor, USERS.author ] ) { + const context = await browser.newContext(); + const userPage = await context.newPage(); + await loginAs( userPage, name, PASSWORD ); + await userPage.goto( '/wp-admin/' ); + + const menu = userPage.locator( '#toplevel_page_beehiiv' ); + await expect( menu, `${ name } sees beehiiv menu` ).toBeVisible(); + await expect( + menu.locator( '.wp-submenu a', { hasText: 'Newsletters' } ), + `${ name } sees Newsletters entry` + ).toBeVisible(); + + await context.close(); + } } ); } ); From fd98199ad086a4615d2e8bde4d0056a45230a74c Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Tue, 10 Nov 2026 18:47:35 +0800 Subject: [PATCH 02/10] Add the Newsletters content type and the Post Roundup block --- includes/Editor/Meta.php | 8 + includes/Editor/PostSettings.php | 46 +- includes/Newsletter/BlockConverter.php | 30 +- includes/Newsletter/ContentTypes.php | 114 +++ includes/Newsletter/NewsletterPostType.php | 181 ++++ includes/Newsletter/PostRoundup.php | 354 ++++++++ includes/Newsletter/PostRoundupSnapshot.php | 130 +++ includes/Newsletter/Sender.php | 31 +- includes/Newsletter/SupportedBlocks.php | 1 + includes/Newsletter/TestSender.php | 9 +- includes/Plugin.php | 6 +- includes/REST/NewslettersController.php | 56 ++ includes/REST/PostRoundupController.php | 118 +++ package-lock.json | 572 +++++++++--- package.json | 6 +- src/js/blocks/post-roundup/block.json | 37 + src/js/blocks/post-roundup/edit.js | 221 +++++ src/js/blocks/post-roundup/editor.scss | 57 ++ src/js/blocks/post-roundup/index.js | 11 + src/js/blocks/post-roundup/utils.js | 57 ++ .../hooks/use-beehiiv-editor-config.js | 2 + src/js/editor/post-settings/index.js | 113 ++- .../specs/newsletters-content-type.spec.js | 720 +++++++++++++++ tests/phpunit/NewsletterContentTypeTest.php | 407 +++++++++ tests/phpunit/PostRoundupTest.php | 856 ++++++++++++++++++ 25 files changed, 3922 insertions(+), 221 deletions(-) create mode 100644 includes/Newsletter/ContentTypes.php create mode 100644 includes/Newsletter/NewsletterPostType.php create mode 100644 includes/Newsletter/PostRoundup.php create mode 100644 includes/Newsletter/PostRoundupSnapshot.php create mode 100644 includes/REST/NewslettersController.php create mode 100644 includes/REST/PostRoundupController.php create mode 100644 src/js/blocks/post-roundup/block.json create mode 100644 src/js/blocks/post-roundup/edit.js create mode 100644 src/js/blocks/post-roundup/editor.scss create mode 100644 src/js/blocks/post-roundup/index.js create mode 100644 src/js/blocks/post-roundup/utils.js create mode 100644 tests/e2e/specs/newsletters-content-type.spec.js create mode 100644 tests/phpunit/NewsletterContentTypeTest.php create mode 100644 tests/phpunit/PostRoundupTest.php diff --git a/includes/Editor/Meta.php b/includes/Editor/Meta.php index 8dfc86a..d9f4998 100644 --- a/includes/Editor/Meta.php +++ b/includes/Editor/Meta.php @@ -65,6 +65,14 @@ final class Meta { */ public const BEEHIIV_LINKED_POST_TEMPLATE_ID = '_beehiiv_linked_post_template_id'; + /** + * Post IDs frozen for automatic Post Roundup blocks at the first send or schedule. + * Server-only; not registered for REST. + * + * @since x.x.x + */ + public const ROUNDUP_SNAPSHOT = '_beehiiv_roundup_snapshot'; + /** * Beehiiv post ID after the newsletter has been created via the API. * diff --git a/includes/Editor/PostSettings.php b/includes/Editor/PostSettings.php index bc09e81..0b218f5 100644 --- a/includes/Editor/PostSettings.php +++ b/includes/Editor/PostSettings.php @@ -11,6 +11,7 @@ use Beehiiv\API\Resources\Workspace; use Beehiiv\Config; use Beehiiv\Connection\Manager; +use Beehiiv\Newsletter\ContentTypes; use Beehiiv\Newsletter\PublicationResolver; use Beehiiv\Newsletter\SupportedBlocks; use Beehiiv\OAuth\Config as OAuthConfig; @@ -18,8 +19,8 @@ defined( 'ABSPATH' ) || exit; /** - * Registers post meta and enqueues the beehiiv plugin sidebar for the default - * `post` post type. + * Registers post meta and enqueues the beehiiv plugin sidebar for the supported + * content types ({@see ContentTypes}). * * @since 1.0.0 */ @@ -40,11 +41,6 @@ final class PostSettings { */ private const STYLE_HANDLE = 'beehiiv-post-settings'; - /** - * Post type that receives beehiiv post meta and editor settings. - */ - private const POST_TYPE = 'post'; - /** * Post meta keys registered for the block editor (REST-visible). * @@ -114,10 +110,30 @@ final class PostSettings { * @since 1.0.0 */ public static function register_meta(): void { - add_filter( 'rest_prepare_post', [ self::class, 'prepare_rest_post' ], 10, 3 ); + foreach ( ContentTypes::supported() as $post_type ) { + add_filter( 'rest_prepare_' . $post_type, [ self::class, 'prepare_rest_post' ], 10, 3 ); + } + add_filter( 'rest_request_before_callbacks', [ self::class, 'drop_readonly_meta_from_request' ], 10, 3 ); + foreach ( ContentTypes::supported() as $post_type ) { + self::register_post_type_meta( $post_type ); + } + } + + /** + * Register every beehiiv meta key for one supported post type. + * + * @param string $post_type Post type name. + * @return void + * @since x.x.x + */ + private static function register_post_type_meta( string $post_type ): void { foreach ( self::META_KEYS as $key => $config ) { + if ( Meta::SEND_TO_NEWSLETTER === $key ) { + $config['default'] = ContentTypes::send_default( $post_type ); + } + $show_in_rest = true; if ( ! empty( $config['readonly'] ) ) { @@ -142,7 +158,7 @@ public static function register_meta(): void { $args['sanitize_callback'] = $config['sanitize']; } - register_post_meta( self::POST_TYPE, $key, $args ); + register_post_meta( $post_type, $key, $args ); } } @@ -196,7 +212,7 @@ public static function enqueue_canvas_styles(): void { } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; - if ( $screen && self::POST_TYPE !== $screen->post_type ) { + if ( $screen && ! ContentTypes::is_supported( $screen->post_type ) ) { return; } @@ -205,7 +221,7 @@ public static function enqueue_canvas_styles(): void { } /** - * Enqueue the compiled editor plugin only on `post` edit screens. + * Enqueue the compiled editor plugin only on supported edit screens. * * @since 1.0.0 */ @@ -215,7 +231,7 @@ public static function enqueue_assets(): void { } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; - if ( $screen && self::POST_TYPE !== $screen->post_type ) { + if ( $screen && ! ContentTypes::is_supported( $screen->post_type ) ) { return; } @@ -305,7 +321,7 @@ public static function drop_readonly_meta_from_request( $response, $handler, $re return $response; } - if ( ! preg_match( '#^/wp/v2/posts(?:/\d+(?:/autosaves)?)?$#', $request->get_route() ) ) { + if ( ! preg_match( ContentTypes::rest_route_pattern(), $request->get_route() ) ) { return $response; } @@ -344,7 +360,7 @@ public static function prepare_rest_post( $response, $post, $request ) { return $response; } - if ( self::POST_TYPE !== $post->post_type || 'edit' !== $request->get_param( 'context' ) ) { + if ( ! ContentTypes::is_supported( $post->post_type ) || 'edit' !== $request->get_param( 'context' ) ) { return $response; } @@ -405,6 +421,8 @@ private static function get_editor_config(): array { 'publicationId' => trim( (string) ( $settings['publication_id'] ?? '' ) ), 'defaultPostTemplateId' => trim( (string) ( $settings['post_template_id'] ?? '' ) ), 'canPublishPosts' => current_user_can( 'publish_posts' ), + 'supportedPostTypes' => ContentTypes::supported(), + 'newsletterPostType' => ContentTypes::NEWSLETTER, 'defaultPublicationId' => $default_pub_id, 'publications' => $is_connected ? PublicationResolver::get_editor_publications() : [], ]; diff --git a/includes/Newsletter/BlockConverter.php b/includes/Newsletter/BlockConverter.php index 32a1f94..904b40b 100644 --- a/includes/Newsletter/BlockConverter.php +++ b/includes/Newsletter/BlockConverter.php @@ -37,6 +37,7 @@ * - `core/separator` — beehiiv `content_break` * - `core/more` — snippet newsletters only; beehiiv Read More `button` via `convert_more_block()` * - `beehiiv/advertisement` — beehiiv `advertisement` block via `convert_advertisement_block()` + * - `beehiiv/post-roundup` — newsletters only; `PostRoundup::expand()` makes image, text, button, separator blocks * * Layout blocks (`core/group`, `core/columns`, etc.) are skipped at the top level. * `convert_columns_block()` exists for internal reuse (e.g. `core/media-text`) and is @@ -64,11 +65,13 @@ public static function convert_supported_blocks( WP_Post $post_object ): array { } } - $is_send_newsletter_snippet = (bool) get_post_meta( - $post_object->ID, - Meta::SEND_TO_NEWSLETTER_SNIPPET, - true - ); + // Newsletters have no public post to link to, so snippet mode never applies. + $is_send_newsletter_snippet = ! ContentTypes::is_newsletter( $post_object->post_type ) + && (bool) get_post_meta( + $post_object->ID, + Meta::SEND_TO_NEWSLETTER_SNIPPET, + true + ); $converted_blocks = self::convert_blocks( $wp_blocks, @@ -97,7 +100,8 @@ private static function convert_blocks( WP_Post $post_object, bool $is_send_newsletter_snippet ): array { - $beehiiv_blocks = []; + $beehiiv_blocks = []; + $roundup_ordinal = 0; foreach ( $wp_blocks as $wp_block ) { if ( empty( $wp_block['blockName'] ) ) { @@ -115,6 +119,20 @@ private static function convert_blocks( continue; } + if ( PostRoundup::BLOCK === $block_name ) { + $attrs = (array) ( $wp_block['attrs'] ?? [] ); + $key = PostRoundup::block_key( $attrs, $roundup_ordinal++ ); + + // A roundup left in a regular post is ignored. + if ( ContentTypes::is_newsletter( $post_object->post_type ) ) { + $beehiiv_blocks = array_merge( + $beehiiv_blocks, + PostRoundup::expand( $attrs, $post_object->ID, $key ) + ); + } + continue; + } + if ( 'core/buttons' === $block_name ) { $button_blocks = self::convert_buttons_block( $wp_block ); $beehiiv_blocks = array_merge( $beehiiv_blocks, $button_blocks ); diff --git a/includes/Newsletter/ContentTypes.php b/includes/Newsletter/ContentTypes.php new file mode 100644 index 0000000..fd8e665 --- /dev/null +++ b/includes/Newsletter/ContentTypes.php @@ -0,0 +1,114 @@ +rest_base ) ) { + return (string) $object->rest_base; + } + + return self::POST === $post_type ? 'posts' : $post_type; + } + + /** + * Regex matching the single-item and collection REST routes of supported types + * (including `/{id}` and `/{id}/autosaves`). + * + * @return string + * @since x.x.x + */ + public static function rest_route_pattern(): string { + $bases = array_map( + static fn( string $type ): string => preg_quote( self::rest_base( $type ), '#' ), + self::supported() + ); + + return '#^/wp/v2/(?:' . implode( '|', $bases ) . ')(?:/\d+(?:/autosaves)?)?$#'; + } +} diff --git a/includes/Newsletter/NewsletterPostType.php b/includes/Newsletter/NewsletterPostType.php new file mode 100644 index 0000000..f8ad305 --- /dev/null +++ b/includes/Newsletter/NewsletterPostType.php @@ -0,0 +1,181 @@ + [ + 'name' => __( 'Newsletters', 'beehiiv' ), + 'singular_name' => __( 'Newsletter', 'beehiiv' ), + 'add_new' => __( 'Add New', 'beehiiv' ), + 'add_new_item' => __( 'Add New Newsletter', 'beehiiv' ), + 'edit_item' => __( 'Edit Newsletter', 'beehiiv' ), + 'new_item' => __( 'New Newsletter', 'beehiiv' ), + 'view_item' => __( 'View Newsletter', 'beehiiv' ), + 'search_items' => __( 'Search Newsletters', 'beehiiv' ), + 'not_found' => __( 'No newsletters found.', 'beehiiv' ), + 'not_found_in_trash' => __( 'No newsletters found in Trash.', 'beehiiv' ), + 'all_items' => __( 'Newsletters', 'beehiiv' ), + 'menu_name' => __( 'Newsletters', 'beehiiv' ), + ], + 'public' => false, + 'publicly_queryable' => false, + 'exclude_from_search' => true, + 'show_in_nav_menus' => false, + 'show_in_admin_bar' => false, + 'show_ui' => true, + 'show_in_menu' => Config::PLUGIN_SLUG, + 'show_in_rest' => true, + 'rest_base' => 'beehiiv-newsletters', + 'rest_controller_class' => NewslettersController::class, + 'has_archive' => false, + 'rewrite' => false, + 'query_var' => false, + 'can_export' => true, + 'capability_type' => 'post', + 'map_meta_cap' => true, + 'supports' => [ 'title', 'editor', 'author', 'custom-fields' ], + ] + ); + } + + /** + * List table columns: title, beehiiv status, author, date. + * + * @param array $columns Default columns. + * @return array + * @since x.x.x + */ + public static function columns( $columns ): array { + return [ + 'cb' => $columns['cb'] ?? '', + 'title' => __( 'Title', 'beehiiv' ), + self::STATUS_COLUMN => __( 'beehiiv status', 'beehiiv' ), + 'author' => __( 'Author', 'beehiiv' ), + 'date' => __( 'Date', 'beehiiv' ), + ]; + } + + /** + * Render the beehiiv status cell. + * + * @param string $column Column key. + * @param int $post_id Post ID. + * @return void + * @since x.x.x + */ + public static function render_column( $column, $post_id ): void { + if ( self::STATUS_COLUMN !== $column ) { + return; + } + + echo esc_html( self::status_label( self::get_status( (int) $post_id ) ) ); + } + + /** + * The beehiiv status as last recorded by WordPress (local meta only, no API call). + * + * @param int $post_id Post ID. + * @return string One of the STATUS_* constants. + * @since x.x.x + */ + public static function get_status( int $post_id ): string { + $error = get_post_meta( $post_id, Meta::NEWSLETTER_ERROR, true ); + + if ( is_string( $error ) && '' !== trim( $error ) ) { + return self::STATUS_FAILED; + } + + if ( ! Sender::has_beehiiv_post_id( $post_id ) ) { + return self::STATUS_NOT_SENT; + } + + if ( Sender::is_newsletter_sent( $post_id ) ) { + return self::STATUS_SENT; + } + + $scheduled_at = get_post_meta( $post_id, Meta::BEEHIIV_SCHEDULED_AT, true ); + $scheduled_at = is_string( $scheduled_at ) ? trim( $scheduled_at ) : ''; + $timestamp = PostSettingsBuilder::utc_scheduled_at_to_timestamp( $scheduled_at ); + + if ( null !== $timestamp && $timestamp > time() && ! Sender::is_newsletter_published( $post_id ) ) { + return self::STATUS_SCHEDULED; + } + + return Sender::is_newsletter_published( $post_id ) ? self::STATUS_SENT : self::STATUS_NOT_SENT; + } + + /** + * Human label for a status. + * + * @param string $status STATUS_* constant. + * @return string + * @since x.x.x + */ + public static function status_label( string $status ): string { + switch ( $status ) { + case self::STATUS_FAILED: + return __( 'Failed', 'beehiiv' ); + case self::STATUS_SCHEDULED: + return __( 'Scheduled', 'beehiiv' ); + case self::STATUS_SENT: + return __( 'Sent', 'beehiiv' ); + default: + return __( 'Not sent', 'beehiiv' ); + } + } +} diff --git a/includes/Newsletter/PostRoundup.php b/includes/Newsletter/PostRoundup.php new file mode 100644 index 0000000..a093153 --- /dev/null +++ b/includes/Newsletter/PostRoundup.php @@ -0,0 +1,354 @@ +post : null; + + if ( $post instanceof WP_Post && ContentTypes::is_newsletter( $post->post_type ) ) { + return $allowed; + } + + if ( true === $allowed ) { + $allowed = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ); + } + + if ( ! is_array( $allowed ) ) { + return $allowed; + } + + return array_values( array_diff( $allowed, [ self::BLOCK ] ) ); + } + + /** + * Clamp the automatic post count to the allowed range. + * + * @param mixed $count Requested count. + * @return int + * @since x.x.x + */ + public static function clamp_count( $count ): int { + if ( ! is_numeric( $count ) ) { + return self::DEFAULT_COUNT; + } + + return max( self::MIN_COUNT, min( self::MAX_COUNT, (int) $count ) ); + } + + /** + * Mode of a block, defaulting to automatic. + * + * @param array $attrs Block attributes. + * @return string + * @since x.x.x + */ + public static function mode( array $attrs ): string { + return isset( $attrs['mode'] ) && self::MODE_MANUAL === $attrs['mode'] ? self::MODE_MANUAL : self::MODE_AUTO; + } + + /** + * Post IDs picked in manual mode, in the author's order. + * + * @param array $attrs Block attributes. + * @return int[] + * @since x.x.x + */ + public static function picked_ids( array $attrs ): array { + $ids = []; + + foreach ( (array) ( $attrs['posts'] ?? [] ) as $item ) { + $id = is_array( $item ) ? ( $item['id'] ?? 0 ) : $item; + + if ( is_numeric( $id ) && (int) $id > 0 ) { + $ids[] = (int) $id; + } + } + + return $ids; + } + + /** + * Latest published regular posts, newest first. + * + * Password-protected posts and the newsletter itself are left out. + * + * @param int $count Number of posts. + * @param int $exclude_id Newsletter post ID. + * @return int[] + * @since x.x.x + */ + public static function latest_ids( int $count, int $exclude_id ): array { + $query = new WP_Query( + [ + 'post_type' => ContentTypes::POST, + 'post_status' => 'publish', + 'has_password' => false, + 'posts_per_page' => self::clamp_count( $count ), + 'orderby' => 'date', + 'order' => 'DESC', + 'post__not_in' => $exclude_id > 0 ? [ $exclude_id ] : [], + 'ignore_sticky_posts' => true, + 'no_found_rows' => true, + 'fields' => 'ids', + ] + ); + + return array_map( 'intval', $query->posts ); + } + + /** + * Keep only posts a roundup may list, in the given order. + * + * Drafts, trashed, deleted, password-protected and non-regular posts are skipped. + * + * @param int[] $ids Candidate post IDs. + * @param int $exclude_id Newsletter post ID. + * @return int[] + * @since x.x.x + */ + public static function available_ids( array $ids, int $exclude_id ): array { + $available = []; + + foreach ( array_unique( array_map( 'intval', $ids ) ) as $id ) { + $post = $id > 0 && $id !== $exclude_id ? get_post( $id ) : null; + + if ( $post instanceof WP_Post + && ContentTypes::POST === $post->post_type + && 'publish' === $post->post_status + && '' === $post->post_password ) { + $available[] = $id; + } + } + + return $available; + } + + /** + * Post IDs a block lists. Shared by the editor preview and the send step. + * + * In automatic mode a list frozen at send time is used when one exists for the + * block and still matches its count; otherwise the latest posts are queried. + * + * @param array $attrs Block attributes. + * @param int $post_id Newsletter post ID. + * @param string $key Snapshot key of the block. + * @return int[] + * @since x.x.x + */ + public static function resolve_ids( array $attrs, int $post_id, string $key ): array { + if ( self::MODE_MANUAL === self::mode( $attrs ) ) { + return self::available_ids( self::picked_ids( $attrs ), $post_id ); + } + + $count = self::clamp_count( $attrs['count'] ?? self::DEFAULT_COUNT ); + $frozen = PostRoundupSnapshot::ids_for( $post_id, $key, $count ); + + if ( null !== $frozen ) { + return self::available_ids( $frozen, $post_id ); + } + + return self::latest_ids( $count, $post_id ); + } + + /** + * Snapshot key of a top-level roundup block: its stored id, else its position. + * + * @param array $attrs Block attributes. + * @param int $ordinal Position among the roundup blocks. + * @return string + * @since x.x.x + */ + public static function block_key( array $attrs, int $ordinal ): string { + $uid = isset( $attrs['uid'] ) ? sanitize_key( (string) $attrs['uid'] ) : ''; + + return '' !== $uid ? $uid : 'n' . $ordinal; + } + + /** + * Card data for posts, for the editor preview and the send step. + * + * @param int[] $ids Post IDs. + * @return array> + * @since x.x.x + */ + public static function cards( array $ids ): array { + $cards = []; + + foreach ( $ids as $id ) { + $post = get_post( (int) $id ); + + if ( ! $post instanceof WP_Post ) { + continue; + } + + $thumbnail_id = (int) get_post_thumbnail_id( $post ); + $image_url = $thumbnail_id ? wp_get_attachment_image_url( $thumbnail_id, self::IMAGE_SIZE ) : false; + $alt = $thumbnail_id ? get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true ) : ''; + + $cards[] = [ + 'id' => $post->ID, + 'title' => html_entity_decode( wp_strip_all_tags( get_the_title( $post ) ), ENT_QUOTES, 'UTF-8' ), + 'url' => (string) get_permalink( $post ), + 'excerpt' => trim( + html_entity_decode( wp_strip_all_tags( get_the_excerpt( $post ) ), ENT_QUOTES, 'UTF-8' ) + ), + 'image_url' => $image_url ? (string) $image_url : '', + 'image_alt' => is_string( $alt ) ? trim( wp_strip_all_tags( $alt ) ) : '', + ]; + } + + return $cards; + } + + /** + * Expand a roundup block into beehiiv blocks. + * + * Per post: an image (when there is a featured image), a bold linked title + * paragraph (a heading cannot carry a link), an excerpt paragraph and a Read more + * button, with a separator between posts. + * + * @param array $attrs Block attributes. + * @param int $post_id Newsletter post ID. + * @param string $key Snapshot key of the block. + * @return array> + * @since x.x.x + */ + public static function expand( array $attrs, int $post_id, string $key ): array { + $blocks = []; + + foreach ( self::cards( self::resolve_ids( $attrs, $post_id, $key ) ) as $card ) { + if ( ! empty( $blocks ) ) { + $blocks[] = [ 'type' => 'content_break' ]; + } + + $blocks = array_merge( $blocks, self::card_blocks( $card ) ); + } + + return $blocks; + } + + /** + * Beehiiv blocks for one card, through the existing converters. + * + * @param array $card Card data from {@see cards()}. + * @return array> + * @since x.x.x + */ + private static function card_blocks( array $card ): array { + $url = esc_url( $card['url'] ); + $blocks = []; + + if ( '' !== $card['image_url'] ) { + $blocks[] = BlockConverter::convert_image_block( + [ + 'blockName' => 'core/image', + 'attrs' => [], + 'innerHTML' => sprintf( + '
%3$s
', + $url, + esc_url( $card['image_url'] ), + esc_attr( $card['image_alt'] ) + ), + ] + ); + } + + $blocks[] = BlockConverter::convert_paragraph_block( + [ + 'blockName' => 'core/paragraph', + 'attrs' => [], + 'innerHTML' => sprintf( + '

%2$s

', + $url, + esc_html( $card['title'] ) + ), + ] + ); + + if ( '' !== $card['excerpt'] ) { + $blocks[] = BlockConverter::convert_paragraph_block( + [ + 'blockName' => 'core/paragraph', + 'attrs' => [], + 'innerHTML' => '

' . esc_html( $card['excerpt'] ) . '

', + ] + ); + } + + $blocks[] = BlockConverter::convert_button_block( + [ + 'blockName' => 'core/button', + 'attrs' => [], + 'innerHTML' => sprintf( + '', + $url, + esc_html__( 'Read more', 'beehiiv' ) + ), + ] + ); + + return array_values( array_filter( $blocks ) ); + } +} diff --git a/includes/Newsletter/PostRoundupSnapshot.php b/includes/Newsletter/PostRoundupSnapshot.php new file mode 100644 index 0000000..311e236 --- /dev/null +++ b/includes/Newsletter/PostRoundupSnapshot.php @@ -0,0 +1,130 @@ + [ 'count' => int, 'ids' => int[] ] ]`. + * + * @since x.x.x + */ +final class PostRoundupSnapshot { + + /** + * Freeze automatic roundups that have no matching snapshot yet. + * + * Entries that still match their block's count are kept, so repeated syncs never + * refresh them. A changed count, or a new roundup, is frozen again; entries of + * removed roundups are dropped. + * + * @param WP_Post $post Newsletter post. + * @return void + * @since x.x.x + */ + public static function freeze( WP_Post $post ): void { + if ( ! ContentTypes::is_newsletter( $post->post_type ) ) { + return; + } + + $existing = self::get( $post->ID ); + $next = []; + $ordinal = 0; + + foreach ( parse_blocks( $post->post_content ) as $block ) { + if ( PostRoundup::BLOCK !== ( $block['blockName'] ?? '' ) ) { + continue; + } + + $attrs = (array) ( $block['attrs'] ?? [] ); + $key = PostRoundup::block_key( $attrs, $ordinal++ ); + + if ( PostRoundup::MODE_AUTO !== PostRoundup::mode( $attrs ) ) { + continue; + } + + $count = PostRoundup::clamp_count( $attrs['count'] ?? PostRoundup::DEFAULT_COUNT ); + + $next[ $key ] = null !== self::ids_from( $existing, $key, $count ) + ? $existing[ $key ] + : [ + 'count' => $count, + 'ids' => PostRoundup::latest_ids( $count, $post->ID ), + ]; + } + + if ( empty( $next ) ) { + self::clear( $post->ID ); + return; + } + + update_post_meta( $post->ID, Meta::ROUNDUP_SNAPSHOT, $next ); + } + + /** + * Frozen post IDs for a block, when one exists for the given count. + * + * @param int $post_id Newsletter post ID. + * @param string $key Block key. + * @param int $count Count the block currently asks for. + * @return int[]|null Null when nothing is frozen for the block. + * @since x.x.x + */ + public static function ids_for( int $post_id, string $key, int $count ): ?array { + return self::ids_from( self::get( $post_id ), $key, $count ); + } + + /** + * Forget the frozen lists, so the next send freezes them again. + * + * @param int $post_id Newsletter post ID. + * @return void + * @since x.x.x + */ + public static function clear( int $post_id ): void { + delete_post_meta( $post_id, Meta::ROUNDUP_SNAPSHOT ); + } + + /** + * Stored snapshot of a post. + * + * @param int $post_id Newsletter post ID. + * @return array + */ + private static function get( int $post_id ): array { + $stored = get_post_meta( $post_id, Meta::ROUNDUP_SNAPSHOT, true ); + + return is_array( $stored ) ? $stored : []; + } + + /** + * Frozen IDs of one entry in a snapshot, when its count still matches. + * + * @param array $snapshot Snapshot. + * @param string $key Block key. + * @param int $count Current block count. + * @return int[]|null + */ + private static function ids_from( array $snapshot, string $key, int $count ): ?array { + $entry = $snapshot[ $key ] ?? null; + + if ( ! is_array( $entry ) || ! isset( $entry['ids'], $entry['count'] ) || (int) $entry['count'] !== $count ) { + return null; + } + + return array_map( 'intval', (array) $entry['ids'] ); + } +} diff --git a/includes/Newsletter/Sender.php b/includes/Newsletter/Sender.php index accbe8a..212caba 100644 --- a/includes/Newsletter/Sender.php +++ b/includes/Newsletter/Sender.php @@ -28,13 +28,6 @@ */ final class Sender { - /** - * Post type that supports beehiiv newsletters. - * - * @since 1.0.0 - */ - private const POST_TYPE = 'post'; - /** * Seconds before `scheduled_at` from which a scheduled newsletter counts as sent. * @@ -68,7 +61,10 @@ final class Sender { * @since 1.0.0 */ public static function init(): void { - add_action( 'rest_after_insert_' . self::POST_TYPE, [ self::class, 'on_rest_insert' ], 10, 2 ); + foreach ( ContentTypes::supported() as $post_type ) { + add_action( 'rest_after_insert_' . $post_type, [ self::class, 'on_rest_insert' ], 10, 2 ); + } + add_action( 'future_to_publish', [ self::class, 'on_future_to_publish' ], 10, 1 ); add_action( 'transition_post_status', [ self::class, 'on_transition_post_status' ], 10, 3 ); add_action( 'before_delete_post', [ self::class, 'on_before_delete_post' ], 10, 1 ); @@ -271,7 +267,7 @@ public static function on_rest_insert( WP_Post $post, $request = null ): void { * @since 1.0.0 */ public static function on_future_to_publish( WP_Post $post ): void { - if ( self::POST_TYPE !== $post->post_type ) { + if ( ! ContentTypes::is_supported( $post->post_type ) ) { return; } @@ -292,7 +288,7 @@ public static function on_future_to_publish( WP_Post $post ): void { * @since 1.0.0 */ public static function on_transition_post_status( string $new_status, string $old_status, WP_Post $post ): void { - if ( self::POST_TYPE !== $post->post_type || $new_status === $old_status ) { + if ( ! ContentTypes::is_supported( $post->post_type ) || $new_status === $old_status ) { return; } @@ -320,7 +316,7 @@ public static function on_transition_post_status( string $new_status, string $ol public static function on_before_delete_post( int $post_id ): void { $post = get_post( $post_id ); - if ( ! $post instanceof WP_Post || self::POST_TYPE !== $post->post_type ) { + if ( ! $post instanceof WP_Post || ! ContentTypes::is_supported( $post->post_type ) ) { return; } @@ -380,6 +376,7 @@ public static function cancel_scheduled_newsletter( int $post_id ): void { self::clear_linked_publication( $post_id ); delete_post_meta( $post_id, Meta::BEEHIIV_NEWSLETTER_SENT ); delete_post_meta( $post_id, Meta::BEEHIIV_SYNCED_SUBTITLE ); + PostRoundupSnapshot::clear( $post_id ); update_post_meta( $post_id, Meta::SEND_TO_NEWSLETTER, true ); self::clear_error( $post_id ); } @@ -396,7 +393,7 @@ public static function cancel_scheduled_newsletter( int $post_id ): void { * @since 1.0.0 */ public static function maybe_send_post_newsletter( WP_Post $post, ?WP_REST_Request $request = null ): void { - if ( self::POST_TYPE !== $post->post_type ) { + if ( ! ContentTypes::is_supported( $post->post_type ) ) { return; } @@ -504,9 +501,13 @@ public static function send( int $post_id ): void { return; } + // Fix the automatic roundup lists now; every later sync reads this snapshot. + PostRoundupSnapshot::freeze( $post_object ); + $beehiiv_post_data = PostSettingsBuilder::get_post_settings( $post_id, false, $publication_id ); if ( is_wp_error( $beehiiv_post_data ) ) { + PostRoundupSnapshot::clear( $post_id ); self::fail( $post_id, 'save', @@ -519,6 +520,8 @@ public static function send( int $post_id ): void { $result = Posts::create( $publication_id, $beehiiv_post_data ); if ( ! $result['success'] ) { + // Nothing was sent, so the next attempt freezes the lists again. + PostRoundupSnapshot::clear( $post_id ); self::fail( $post_id, 'send', @@ -622,6 +625,9 @@ public static function update( int $post_id ): void { return; } + // Keeps lists frozen at the first send; only a changed or new roundup is frozen now. + PostRoundupSnapshot::freeze( $post_object ); + $target_publication_id = self::get_move_target_publication( $post_id, $publication_id ); $update = PostSettingsBuilder::build_update( @@ -786,6 +792,7 @@ private static function recreate_linked_post( self::clear_linked_publication( $post_id ); delete_post_meta( $post_id, Meta::BEEHIIV_NEWSLETTER_SENT ); delete_post_meta( $post_id, Meta::BEEHIIV_SYNCED_SUBTITLE ); + PostRoundupSnapshot::clear( $post_id ); update_post_meta( $post_id, Meta::SEND_TO_NEWSLETTER, true ); self::fail( diff --git a/includes/Newsletter/SupportedBlocks.php b/includes/Newsletter/SupportedBlocks.php index ba93a96..ae93bb2 100644 --- a/includes/Newsletter/SupportedBlocks.php +++ b/includes/Newsletter/SupportedBlocks.php @@ -37,6 +37,7 @@ final class SupportedBlocks { 'core/buttons', 'core/separator', 'beehiiv/advertisement', + 'beehiiv/post-roundup', ]; /** diff --git a/includes/Newsletter/TestSender.php b/includes/Newsletter/TestSender.php index 994139e..0512a15 100644 --- a/includes/Newsletter/TestSender.php +++ b/includes/Newsletter/TestSender.php @@ -46,13 +46,6 @@ final class TestSender { */ private const ELIGIBLE_STATUSES = [ 'draft', 'pending', 'future' ]; - /** - * Post type that supports beehiiv newsletters. - * - * @since 1.0.0 - */ - private const POST_TYPE = 'post'; - /** * Longest a test send waits for beehiiv to finish creating a temporary draft, in seconds. * @@ -119,7 +112,7 @@ final class TestSender { public static function check_eligibility( int $post_id ) { $post = get_post( $post_id ); - if ( ! $post instanceof WP_Post || self::POST_TYPE !== $post->post_type ) { + if ( ! $post instanceof WP_Post || ! ContentTypes::is_supported( $post->post_type ) ) { return new WP_Error( 'beehiiv_test_send_post_not_found', __( 'This post no longer exists. Save or reload the editor and try again.', 'beehiiv' ) diff --git a/includes/Plugin.php b/includes/Plugin.php index c15a98f..9fda849 100644 --- a/includes/Plugin.php +++ b/includes/Plugin.php @@ -29,7 +29,9 @@ public static function init(): void { Frontend\Assets::init(); Admin\Assets::init(); + Newsletter\NewsletterPostType::init(); Newsletter\Sender::init(); + Newsletter\PostRoundup::init(); Advertisement\Sync::init(); OAuth\Config::register_hooks(); OAuth\AdminActions::init(); @@ -40,13 +42,15 @@ public static function init(): void { add_action( 'init', [ Editor\PostSettings::class, 'register_meta' ] ); add_action( 'enqueue_block_editor_assets', [ Editor\PostSettings::class, 'enqueue_assets' ] ); add_action( 'enqueue_block_assets', [ Editor\PostSettings::class, 'enqueue_canvas_styles' ] ); - add_action( 'admin_menu', [ Admin\Menu::class, 'register' ] ); + add_action( 'admin_menu', [ Admin\Menu::class, 'register' ], 5 ); + add_action( 'admin_menu', [ Admin\Menu::class, 'prune_for_non_administrators' ], 11 ); add_action( 'admin_menu', [ OAuth\CallbackHandler::class, 'register_page' ] ); add_action( 'admin_init', [ self::class, 'bootstrap_admin_features' ] ); add_action( 'rest_api_init', [ REST\PostTemplatesController::class, 'register_routes' ] ); add_action( 'rest_api_init', [ REST\PublicationsController::class, 'register_routes' ] ); add_action( 'rest_api_init', [ REST\AdvertisementOpportunitiesController::class, 'register_routes' ] ); add_action( 'rest_api_init', [ REST\TestSendController::class, 'register_routes' ] ); + add_action( 'rest_api_init', [ REST\PostRoundupController::class, 'register_routes' ] ); } /** diff --git a/includes/REST/NewslettersController.php b/includes/REST/NewslettersController.php new file mode 100644 index 0000000..727e61c --- /dev/null +++ b/includes/REST/NewslettersController.php @@ -0,0 +1,56 @@ +ID ); + } + + /** + * Listing requires the ability to edit newsletters. + * + * @param \WP_REST_Request $request Request. + * @return true|\WP_Error + * @since x.x.x + */ + public function get_items_permissions_check( $request ) { + $post_type = get_post_type_object( $this->post_type ); + + if ( ! $post_type || ! current_user_can( $post_type->cap->edit_posts ) ) { + return new \WP_Error( + 'rest_forbidden', + __( 'Sorry, you are not allowed to view newsletters.', 'beehiiv' ), + [ 'status' => rest_authorization_required_code() ] + ); + } + + return parent::get_items_permissions_check( $request ); + } +} diff --git a/includes/REST/PostRoundupController.php b/includes/REST/PostRoundupController.php new file mode 100644 index 0000000..406d331 --- /dev/null +++ b/includes/REST/PostRoundupController.php @@ -0,0 +1,118 @@ + WP_REST_Server::READABLE, + 'callback' => [ self::class, 'get_items' ], + 'permission_callback' => [ self::class, 'permissions_check' ], + 'args' => [ + 'post_id' => [ + 'required' => true, + 'type' => 'integer', + 'sanitize_callback' => 'absint', + ], + 'mode' => [ + 'type' => 'string', + 'enum' => [ PostRoundup::MODE_AUTO, PostRoundup::MODE_MANUAL ], + 'default' => PostRoundup::MODE_AUTO, + ], + 'count' => [ + 'type' => 'integer', + 'default' => PostRoundup::DEFAULT_COUNT, + ], + 'ids' => [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ], + 'maxItems' => self::MAX_IDS, + 'default' => [], + ], + 'uid' => [ + 'type' => 'string', + 'default' => '', + 'sanitize_callback' => 'sanitize_key', + ], + ], + ] + ); + } + + /** + * Require edit access to the newsletter being written. + * + * @param WP_REST_Request $request REST request. + * @return bool + * @since x.x.x + */ + public static function permissions_check( WP_REST_Request $request ): bool { + $post_id = absint( $request->get_param( 'post_id' ) ); + + return $post_id && current_user_can( 'edit_post', $post_id ); + } + + /** + * Cards for the block's current settings. + * + * @param WP_REST_Request $request REST request. + * @return WP_REST_Response + * @since x.x.x + */ + public static function get_items( WP_REST_Request $request ): WP_REST_Response { + $attrs = [ + 'mode' => $request->get_param( 'mode' ), + 'count' => $request->get_param( 'count' ), + 'posts' => array_map( 'absint', (array) $request->get_param( 'ids' ) ), + ]; + + $ids = PostRoundup::resolve_ids( + $attrs, + absint( $request->get_param( 'post_id' ) ), + (string) $request->get_param( 'uid' ) + ); + + return new WP_REST_Response( PostRoundup::cards( $ids ), 200 ); + } +} diff --git a/package-lock.json b/package-lock.json index 1ec6a4a..049290e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "beehiiv", "version": "1.0.0", "license": "GPL-2.0-or-later", + "dependencies": { + "@10up/block-components": "^1.23.0" + }, "devDependencies": { "@playwright/test": "^1.60.0", "@wordpress/api-fetch": "^7.45.0", @@ -28,7 +31,256 @@ "@wordpress/plugins": "^7.45.0", "@wordpress/prettier-config": "^4.46.0", "@wordpress/scripts": "^32.1.0", - "@wordpress/stylelint-config": "^23.38.0" + "@wordpress/stylelint-config": "^23.38.0", + "typescript": "^5.9.3" + } + }, + "node_modules/@10up/block-components": { + "version": "1.23.0", + "resolved": "https://registry.npmjs.org/@10up/block-components/-/block-components-1.23.0.tgz", + "integrity": "sha512-uM2aXbAdureG+poiooVaX+8iZemzVn6oE4yxQG23RarVgnG/h0UgKF2OJrRDhBvQnQH1vNdQFSkAAE7U7xQpaw==", + "license": "GPL-2.0-or-later", + "dependencies": { + "@dnd-kit/core": "^6.1.0", + "@dnd-kit/modifiers": "^7.0.0", + "@dnd-kit/sortable": "^8.0.0", + "@dnd-kit/utilities": "^3.2.2", + "@emotion/react": "^11.11.4", + "@emotion/styled": "^11.11.5", + "@floating-ui/react-dom": "^2.1.0", + "@leeoniya/ufuzzy": "^1.0.14", + "@tanstack/react-query": "^5.52.0", + "@typescript-eslint/parser": "^6.21.0", + "@wordpress/icons": "^11.0.0", + "array-move": "^4.0.0", + "clsx": "^2.1.1", + "react-window": "^1.8.10", + "uuid": "^14.0.1", + "wp-types": "^3.65.0" + }, + "peerDependencies": { + "react": "^18.3.0", + "react-dom": "^18.3.0" + } + }, + "node_modules/@10up/block-components/node_modules/@floating-ui/react-dom": { + "version": "2.1.9", + "resolved": "https://registry.npmjs.org/@floating-ui/react-dom/-/react-dom-2.1.9.tgz", + "integrity": "sha512-JDjEFGCpImxDCA7JJKviA0M9+RtmJdj0m/NVU5IMgBK+AmZouAQQ7/+2GLH0GXXY0YMw9oXPB8hKdbPYg5QLYg==", + "license": "MIT", + "dependencies": { + "@floating-ui/dom": "^1.8.0" + }, + "peerDependencies": { + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, + "node_modules/@10up/block-components/node_modules/@typescript-eslint/parser": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.21.0.tgz", + "integrity": "sha512-tbsV1jPne5CkFQCgPBcDOt30ItF7aJoZL997JSF7MhGQqOeT3svWRYxiqlfA5RUdlHN6Fi+EI9bxqbdyAUZjYQ==", + "license": "BSD-2-Clause", + "dependencies": { + "@typescript-eslint/scope-manager": "6.21.0", + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/typescript-estree": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@10up/block-components/node_modules/@typescript-eslint/scope-manager": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.21.0.tgz", + "integrity": "sha512-OwLUIWZJry80O99zvqXVEioyniJMa+d2GrqpUTqi5/v5D5rOrppJVBPa0yKCblcigC0/aYAzxxqQ1B+DS2RYsg==", + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@10up/block-components/node_modules/@typescript-eslint/types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.21.0.tgz", + "integrity": "sha512-1kFmZ1rOm5epu9NZEZm1kckCDGj5UJEf7P1kliH4LKu/RkwpsfqqGmY2OOcUs18lSlQBKLDYBOGxRVtrMN5lpg==", + "license": "MIT", + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@10up/block-components/node_modules/@typescript-eslint/typescript-estree": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.21.0.tgz", + "integrity": "sha512-6npJTkZcO+y2/kr+z0hc4HwNfrrP4kNYh57ek7yCNlrBjWQ1Y0OS7jiZTkgumrvkX5HkEKXFZkkdFNkaW2wmUQ==", + "license": "BSD-2-Clause", + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "minimatch": "9.0.3", + "semver": "^7.5.4", + "ts-api-utils": "^1.0.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@10up/block-components/node_modules/@typescript-eslint/visitor-keys": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.21.0.tgz", + "integrity": "sha512-JJtkDduxLi9bivAB+cYOVMtbkqdPOhZ+ZI5LC47MIRrDV4Yn2o+ZnW10Nkmr28xRpSpdJ6Sm42Hjf2+REYXm0A==", + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "eslint-visitor-keys": "^3.4.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@10up/block-components/node_modules/array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/@10up/block-components/node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "license": "MIT" + }, + "node_modules/@10up/block-components/node_modules/brace-expansion": { + "version": "2.1.7", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz", + "integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==", + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@10up/block-components/node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "license": "Apache-2.0", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@10up/block-components/node_modules/globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "license": "MIT", + "dependencies": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@10up/block-components/node_modules/ignore": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/@10up/block-components/node_modules/minimatch": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@10up/block-components/node_modules/semver": { + "version": "7.8.6", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz", + "integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@10up/block-components/node_modules/ts-api-utils": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.3.tgz", + "integrity": "sha512-i3eMG77UTMD0hZhgRS562pv83RC6ukSAC2GMNWc+9dieh/+jDM5u5YG+NHX6VNDRHQcHwmsTHctP9LhbC3WxVw==", + "license": "MIT", + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "typescript": ">=4.2.0" } }, "node_modules/@ariakit/components": { @@ -165,7 +417,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", "integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==", - "dev": true, "license": "MIT", "dependencies": { "@babel/helper-validator-identifier": "^7.29.7", @@ -247,7 +498,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.7.tgz", "integrity": "sha512-DkXD5OJQaAQIdZ1bt3UZdEnHAn9Imd3IVBdX03UFe+ony9Ojw5pzr9YVKGDY1jt+Gcn/FnGkNf8r+Vj5NOJWtQ==", - "dev": true, "license": "MIT", "dependencies": { "@babel/parser": "^7.29.7", @@ -351,7 +601,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.29.7.tgz", "integrity": "sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -375,7 +624,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.29.7.tgz", "integrity": "sha512-ejHwrQQYcm9xnTivShn2IDOlIzInN34AXskvq9QicvCtEzq1Vzclu/tKF8Jq1Cg8JG2GL6/EmjgsCT7lXepE3g==", - "dev": true, "license": "MIT", "dependencies": { "@babel/traverse": "^7.29.7", @@ -480,7 +728,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz", "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -490,7 +737,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -539,7 +785,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.7.tgz", "integrity": "sha512-hnORnjP/1P/zFEndoeX+n+t1RwWRJiJpM/jO7FW32Kn9r5+sJB2JWOdYo4L6k78j15eCwY3Gm/7364B1EMwtNg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/types": "^7.29.7" @@ -2079,7 +2324,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.7.tgz", "integrity": "sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -2089,7 +2333,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.29.7.tgz", "integrity": "sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.29.7", @@ -2104,7 +2347,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.7.tgz", "integrity": "sha512-EhlfNQtZ+NK22w5BM61ciuiq1m58ed33Wr1Xan//ZRTy6hgjnwyCffRYwzsGXdASJSUJ1guZILsErh1eQcl+zw==", - "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.29.7", @@ -2123,7 +2365,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.7.tgz", "integrity": "sha512-4zBIxpPzowiZpusoFkyGVwakdRJUyuH5PxQ/PrqghfdFWWasvnCdPfQXHrenDai+gyLARulZjZowCOj6fjT4pA==", - "dev": true, "license": "MIT", "dependencies": { "@babel/helper-string-parser": "^7.29.7", @@ -2471,6 +2712,73 @@ "node": ">=10.0.0" } }, + "node_modules/@dnd-kit/accessibility": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@dnd-kit/accessibility/-/accessibility-3.1.1.tgz", + "integrity": "sha512-2P+YgaXF+gRsIihwwY1gCsQSYnu9Zyj2py8kY5fFvUM1qm2WA2u639R6YNVfU4GWr+ZM5mqEsfHZZLoRONbemw==", + "license": "MIT", + "dependencies": { + "tslib": "^2.0.0" + }, + "peerDependencies": { + "react": ">=16.8.0" + } + }, + "node_modules/@dnd-kit/core": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz", + "integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==", + "license": "MIT", + "dependencies": { + "@dnd-kit/accessibility": "^3.1.1", + "@dnd-kit/utilities": "^3.2.2", + "tslib": "^2.0.0" + }, + "peerDependencies": { + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, + "node_modules/@dnd-kit/modifiers": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@dnd-kit/modifiers/-/modifiers-7.0.0.tgz", + "integrity": "sha512-BG/ETy3eBjFap7+zIti53f0PCLGDzNXyTmn6fSdrudORf+OH04MxrW4p5+mPu4mgMk9kM41iYONjc3DOUWTcfg==", + "license": "MIT", + "dependencies": { + "@dnd-kit/utilities": "^3.2.2", + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@dnd-kit/core": "^6.1.0", + "react": ">=16.8.0" + } + }, + "node_modules/@dnd-kit/sortable": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@dnd-kit/sortable/-/sortable-8.0.0.tgz", + "integrity": "sha512-U3jk5ebVXe1Lr7c2wU7SBZjcWdQP+j7peHJfCspnA81enlu88Mgd7CC8Q+pub9ubP7eKVETzJW+IBAhsqbSu/g==", + "license": "MIT", + "dependencies": { + "@dnd-kit/utilities": "^3.2.2", + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@dnd-kit/core": "^6.1.0", + "react": ">=16.8.0" + } + }, + "node_modules/@dnd-kit/utilities": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/@dnd-kit/utilities/-/utilities-3.2.2.tgz", + "integrity": "sha512-+MKAJEOfaBe5SmV6t34p80MMKhjvUz0vRrvVJbPT0WElzaOJ/1xs+D+KDv+tD/NE5ujfrChEcshd4fLn0wpiqg==", + "license": "MIT", + "dependencies": { + "tslib": "^2.0.0" + }, + "peerDependencies": { + "react": ">=16.8.0" + } + }, "node_modules/@dual-bundle/import-meta-resolve": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@dual-bundle/import-meta-resolve/-/import-meta-resolve-4.2.1.tgz", @@ -2520,7 +2828,6 @@ "version": "11.13.5", "resolved": "https://registry.npmjs.org/@emotion/babel-plugin/-/babel-plugin-11.13.5.tgz", "integrity": "sha512-pxHCpT2ex+0q+HH91/zsdHkw/lXd468DIN2zvfvLtPKLLMo6gQj7oLObq8PhkrxOZb/gGCq03S3Z7PDhS8pduQ==", - "dev": true, "license": "MIT", "dependencies": { "@babel/helper-module-imports": "^7.16.7", @@ -2540,7 +2847,6 @@ "version": "11.14.0", "resolved": "https://registry.npmjs.org/@emotion/cache/-/cache-11.14.0.tgz", "integrity": "sha512-L/B1lc/TViYk4DcpGxtAVbx0ZyiKM5ktoIyafGkH6zg/tj+mA+NE//aPYKG0k8kCHSHVJrpLpcAlOBEXQ3SavA==", - "dev": true, "license": "MIT", "dependencies": { "@emotion/memoize": "^0.9.0", @@ -2568,14 +2874,12 @@ "version": "0.9.2", "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.9.2.tgz", "integrity": "sha512-MyqliTZGuOm3+5ZRSaaBGP3USLw6+EGykkwZns2EPC5g8jJ4z9OrdZY9apkl3+UP9+sdz76YYkwCKP5gh8iY3g==", - "dev": true, "license": "MIT" }, "node_modules/@emotion/is-prop-valid": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.4.0.tgz", "integrity": "sha512-QgD4fyscGcbbKwJmqNvUMSE02OsHUa+lAWKdEUIJKgqe5IwRSKd7+KhibEWdaKwgjLj0DRSHA9biAIqGBk05lw==", - "dev": true, "license": "MIT", "dependencies": { "@emotion/memoize": "^0.9.0" @@ -2585,7 +2889,6 @@ "version": "0.9.0", "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.9.0.tgz", "integrity": "sha512-30FAj7/EoJ5mwVPOWhAyCX+FPfMDrVecJAM+Iw9NRoSl4BBAQeqj4cApHHUXOVvIPgLVDsCFoz/hGD+5QQD1GQ==", - "dev": true, "license": "MIT" }, "node_modules/@emotion/native": { @@ -2619,7 +2922,6 @@ "version": "11.14.0", "resolved": "https://registry.npmjs.org/@emotion/react/-/react-11.14.0.tgz", "integrity": "sha512-O000MLDBDdk/EohJPFUqvnp4qnHeYkVP5B0xEG0D/L7cOKP9kefu2DXn8dj74cQfsEzUqh+sr1RzFqiL1o+PpA==", - "dev": true, "license": "MIT", "dependencies": { "@babel/runtime": "^7.18.3", @@ -2644,7 +2946,6 @@ "version": "1.3.3", "resolved": "https://registry.npmjs.org/@emotion/serialize/-/serialize-1.3.3.tgz", "integrity": "sha512-EISGqt7sSNWHGI76hC7x1CksiXPahbxEOrC5RjmFRJTqLyEK9/9hZvBbiYn70dw4wuwMKiEMCUlR6ZXTSWQqxA==", - "dev": true, "license": "MIT", "dependencies": { "@emotion/hash": "^0.9.2", @@ -2658,14 +2959,12 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/@emotion/sheet/-/sheet-1.4.0.tgz", "integrity": "sha512-fTBW9/8r2w3dXWYM4HCB1Rdp8NLibOw2+XELH5m5+AkWiL/KqYX6dc0kKYlaYyKjrQ6ds33MCdMPEwgs2z1rqg==", - "dev": true, "license": "MIT" }, "node_modules/@emotion/styled": { "version": "11.14.1", "resolved": "https://registry.npmjs.org/@emotion/styled/-/styled-11.14.1.tgz", "integrity": "sha512-qEEJt42DuToa3gurlH4Qqc1kVpNq8wO8cJtDzU46TjlzWjDlsVyevtYCRijVq3SrHsROS+gVQ8Fnea108GnKzw==", - "dev": true, "license": "MIT", "dependencies": { "@babel/runtime": "^7.18.3", @@ -2689,14 +2988,12 @@ "version": "0.10.0", "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.10.0.tgz", "integrity": "sha512-dFoMUuQA20zvtVTuxZww6OHoJYgrzfKM1t52mVySDJnMSEa08ruEvdYQbhvyu6soU+NeLVd3yKfTfT0NeV6qGg==", - "dev": true, "license": "MIT" }, "node_modules/@emotion/use-insertion-effect-with-fallbacks": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@emotion/use-insertion-effect-with-fallbacks/-/use-insertion-effect-with-fallbacks-1.2.0.tgz", "integrity": "sha512-yJMtVdH59sxi/aVJBpk9FQq+OR8ll5GT8oWd57UpeaKEVGab41JWaCFA7FRLoMLloOZF/c/wsPoe+bfGmRKgDg==", - "dev": true, "license": "MIT", "peerDependencies": { "react": ">=16.8.0" @@ -2706,14 +3003,12 @@ "version": "1.4.2", "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-1.4.2.tgz", "integrity": "sha512-3vLclRofFziIa3J2wDh9jjbkUz9qk5Vi3IZ/FSTKViB0k+ef0fPV7dYrUIugbgupYDx7v9ud/SjrtEP8Y4xLoA==", - "dev": true, "license": "MIT" }, "node_modules/@emotion/weak-memoize": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.4.0.tgz", "integrity": "sha512-snKqtPW01tN0ui7yu9rGv69aJXr/a/Ywvl11sUjNtEcRc+ng/mQriFL0wLXMef74iHa/EkftbDzU9F8iFbH+zg==", - "dev": true, "license": "MIT" }, "node_modules/@es-joy/jsdoccomment": { @@ -2882,24 +3177,22 @@ } }, "node_modules/@floating-ui/core": { - "version": "1.7.5", - "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.7.5.tgz", - "integrity": "sha512-1Ih4WTWyw0+lKyFMcBHGbb5U5FtuHJuujoyyr5zTaWS5EYMeT6Jb2AuDeftsCsEuchO+mM2ij5+q9crhydzLhQ==", - "dev": true, + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.8.0.tgz", + "integrity": "sha512-0CIZ5itps/8x7BG8dEIhs53BvCUH2PCoogtakwRTut+Arm58sJooJ0AuZhLw2HJYIR5cMLNPBSS728sPho2khQ==", "license": "MIT", "dependencies": { - "@floating-ui/utils": "^0.2.11" + "@floating-ui/utils": "^0.2.12" } }, "node_modules/@floating-ui/dom": { - "version": "1.7.6", - "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.7.6.tgz", - "integrity": "sha512-9gZSAI5XM36880PPMm//9dfiEngYoC6Am2izES1FF406YFsjvyBMmeJ2g4SAju3xWwtuynNRFL2s9hgxpLI5SQ==", - "dev": true, + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.8.0.tgz", + "integrity": "sha512-yXSrzeHZBTZadLOlfyhCkJHNeLJnHRnRInwdZ40L7ZiaAtrBwoYlsDrX3v5zB1Utk7CLfzcOVnVVWoXEky7Ceg==", "license": "MIT", "dependencies": { - "@floating-ui/core": "^1.7.5", - "@floating-ui/utils": "^0.2.11" + "@floating-ui/core": "^1.8.0", + "@floating-ui/utils": "^0.2.12" } }, "node_modules/@floating-ui/react-dom": { @@ -2917,10 +3210,9 @@ } }, "node_modules/@floating-ui/utils": { - "version": "0.2.11", - "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.11.tgz", - "integrity": "sha512-RiB/yIh78pcIxl6lLMG0CgBXAZ2Y0eVHqMPYugu+9U0AeT6YBeiJpf7lbdJNIugFP5SIjwNRgo4DhR1Qxi26Gg==", - "dev": true, + "version": "0.2.12", + "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.12.tgz", + "integrity": "sha512-HpCo8tmWzLVad5s2d19EhAz5zqrrQ6s69qd6moPMQvkOuSwDT1YgRfWSVuc4ennqrgv3OHppiOGMQ7oC13yIww==", "license": "MIT" }, "node_modules/@formatjs/ecma402-abstract": { @@ -4163,7 +4455,6 @@ "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", - "dev": true, "license": "MIT", "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.0", @@ -4185,7 +4476,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.0.0" @@ -4206,14 +4496,12 @@ "version": "1.5.5", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", - "dev": true, "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.31", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", - "dev": true, "license": "MIT", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", @@ -4261,6 +4549,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@leeoniya/ufuzzy": { + "version": "1.0.19", + "resolved": "https://registry.npmjs.org/@leeoniya/ufuzzy/-/ufuzzy-1.0.19.tgz", + "integrity": "sha512-0pikDeYt0IHEUPza5RTCDXc/17S1pTrYnReEMp8Aa6k1ovzw5QdZLwicW8TjljwEZRb6oYag0xmALohrcq/yOQ==", + "license": "MIT" + }, "node_modules/@leichtgewicht/ip-codec": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz", @@ -4317,7 +4611,6 @@ "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, "license": "MIT", "dependencies": { "@nodelib/fs.stat": "2.0.5", @@ -4331,7 +4624,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true, "license": "MIT", "engines": { "node": ">= 8" @@ -4341,7 +4633,6 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "dev": true, "license": "MIT", "dependencies": { "@nodelib/fs.scandir": "2.1.5", @@ -7477,6 +7768,38 @@ "url": "https://github.com/sponsors/tannerlinsley" } }, + "node_modules/@tanstack/query-core": { + "version": "5.107.1", + "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.107.1.tgz", + "integrity": "sha512-PSyAik11oQBEVOiVy5hjZWHmoUqOXqK1WYy4v55mcxozEfKaQgpUMsgnXhWjuESzSht8JfzqMS1m6M/9CpNgvg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, + "node_modules/@tanstack/react-query": { + "version": "5.107.1", + "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.107.1.tgz", + "integrity": "sha512-udCOOLp3ZAheUrIHLCe+ZZge6nr2ZUrGMSWcCuXsjY1Bf2JeeE09oxst97PILiCY6N8xo/7bIo3Hvz13zh06FA==", + "license": "MIT", + "dependencies": { + "@tanstack/query-core": "5.107.1" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "@types/react": "^18 || ^19", + "react": "^18 || ^19" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, "node_modules/@tanstack/react-router": { "version": "1.170.8", "resolved": "https://registry.npmjs.org/@tanstack/react-router/-/react-router-1.170.8.tgz", @@ -7927,7 +8250,6 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.2.tgz", "integrity": "sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==", - "dev": true, "license": "MIT" }, "node_modules/@types/pg": { @@ -7956,7 +8278,6 @@ "version": "15.7.15", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz", "integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==", - "dev": true, "license": "MIT" }, "node_modules/@types/qs": { @@ -7977,7 +8298,6 @@ "version": "18.3.29", "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.29.tgz", "integrity": "sha512-ch0qJdr2JY0r04NXSprbK6TXOgnaJ1Tz23fm5W+z0/CBah6BSBc3n96h7K9GOtwh0HrilNWHIBzE1Ko4Dcw/Wg==", - "dev": true, "license": "MIT", "dependencies": { "@types/prop-types": "*", @@ -7988,7 +8308,6 @@ "version": "18.3.7", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.7.tgz", "integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==", - "dev": true, "license": "MIT", "peerDependencies": { "@types/react": "^18.0.0" @@ -11284,7 +11603,6 @@ "version": "4.57.0", "resolved": "https://registry.npmjs.org/@wordpress/deprecated/-/deprecated-4.57.0.tgz", "integrity": "sha512-eRjYiN5wE8cmV+sehqGTHpb2VxwSqv/FMkcQ+0po4G3JK+Y1V0StqZRDhsgcwUocPRKuAtTO7E28fcdo615DFw==", - "dev": true, "license": "GPL-2.0-or-later", "dependencies": { "@wordpress/hooks": "^4.57.0" @@ -12019,7 +12337,6 @@ "version": "6.46.0", "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-6.46.0.tgz", "integrity": "sha512-hjnrqZi0cZVdkmN0xQavKfSQJYAkb9pVSnDPpuX65OLxeD9/EWkIXvFzBb+nH8c4NzKKSqQU96XCTQrH37OCIA==", - "dev": true, "license": "GPL-2.0-or-later", "dependencies": { "@types/react": "^18.3.27", @@ -12077,7 +12394,6 @@ "version": "3.57.0", "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-3.57.0.tgz", "integrity": "sha512-QT0x2X39blQjLHru11Dp00DAR0LLRMKMC6ATSWidliD3xQfKz+BjiPzTJd/LyhPLEE8C9li7ylKUlseIO2EYjQ==", - "dev": true, "license": "GPL-2.0-or-later", "engines": { "node": ">=18.12.0" @@ -12976,7 +13292,6 @@ "version": "4.57.0", "resolved": "https://registry.npmjs.org/@wordpress/hooks/-/hooks-4.57.0.tgz", "integrity": "sha512-vRJxRhOj+a19RvdW6u0ZBmiQc/t/ueVGsIP3IbS9zuvfLJILtvMSWXU8Fe3m/W+mBK5ZEOfm72LYBhWGPse0DA==", - "dev": true, "license": "GPL-2.0-or-later", "engines": { "node": ">=18.12.0" @@ -13015,7 +13330,6 @@ "version": "11.8.0", "resolved": "https://registry.npmjs.org/@wordpress/icons/-/icons-11.8.0.tgz", "integrity": "sha512-ZMNHApHMmPLpNnNLfPLRf6XWoPhZFNKFKdpMlhA6Lx04J1hLVyLRz8PuM+1o3ByxD2ZiExfSRhdmI+7VvEg6DA==", - "dev": true, "license": "GPL-2.0-or-later", "dependencies": { "@wordpress/element": "^6.41.0", @@ -16031,7 +16345,6 @@ "version": "4.47.0", "resolved": "https://registry.npmjs.org/@wordpress/primitives/-/primitives-4.47.0.tgz", "integrity": "sha512-Y1uhC6BiLFzORtXnMa07o3DVXG0z+q2KV6g48ClpZJ9aDiehBfdThBHwa6oa7HbYX/yAoMuCkuA7fWbm3zYxNw==", - "dev": true, "license": "GPL-2.0-or-later", "dependencies": { "@wordpress/element": "^7.0.0", @@ -16049,7 +16362,6 @@ "version": "19.2.15", "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.15.tgz", "integrity": "sha512-eRwcGNHve+E8qtEQSSRl6urh+rFop4v8gm6O8rGv25CodbvFdLjA1vVQ1KkiFE0w0UPOnb8tDiFKL5lp0rtY5Q==", - "dev": true, "license": "MIT", "dependencies": { "csstype": "^3.2.2" @@ -16059,7 +16371,6 @@ "version": "19.2.3", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.2.3.tgz", "integrity": "sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==", - "dev": true, "license": "MIT", "peerDependencies": { "@types/react": "^19.2.0" @@ -16069,7 +16380,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-7.0.0.tgz", "integrity": "sha512-iJoc3pzeof0mhwN0gVqDqc64xCRoAij2JynU6YxGSmw5a1uJwi1w3GESX3nPR1eaDdv2V6vwkinMBI+aGG7wxQ==", - "dev": true, "license": "GPL-2.0-or-later", "dependencies": { "@types/react": "^19.2.13", @@ -16090,7 +16400,6 @@ "version": "19.2.6", "resolved": "https://registry.npmjs.org/react/-/react-19.2.6.tgz", "integrity": "sha512-sfWGGfavi0xr8Pg0sVsyHMAOziVYKgPLNrS7ig+ivMNb3wbCBw3KxtflsGBAwD3gYQlE/AEZsTLgToRrSCjb0Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -16100,7 +16409,6 @@ "version": "19.2.6", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.6.tgz", "integrity": "sha512-0prMI+hvBbPjsWnxDLxlCGyM8PN6UuWjEUCYmZhO67xIV9Xasa/r/vDnq+Xyq4Lo27g8QSbO5YzARu0D1Sps3g==", - "dev": true, "license": "MIT", "dependencies": { "scheduler": "^0.27.0" @@ -16113,7 +16421,6 @@ "version": "0.27.0", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz", "integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==", - "dev": true, "license": "MIT" }, "node_modules/@wordpress/priority-queue": { @@ -19221,6 +19528,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/array-move": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/array-move/-/array-move-4.0.0.tgz", + "integrity": "sha512-+RY54S8OuVvg94THpneQvFRmqWdAHeqtMzgMW6JNurHxe8rsS07cHQdfGkXnTUXiBcyZ0j3SiDIxxj0RPiqCkQ==", + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/array-union": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/array-union/-/array-union-3.0.1.tgz", @@ -19651,7 +19970,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/babel-plugin-macros/-/babel-plugin-macros-3.1.0.tgz", "integrity": "sha512-Cg7TFGpIr01vOQNODXOOaGz2NpCU5gl8x1qJFbb6hbZxR7XrcE2vtbAsTAbJ7/xwJtUuJEw8K8Zr/AE0LHlesg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/runtime": "^7.12.5", @@ -19667,7 +19985,6 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.1.0.tgz", "integrity": "sha512-AdmX6xUzdNASswsFtmwSt7Vj8po9IuqXm0UXz7QKPuEUmPB4XyjGfaAr2PSuELMwkRMVH1EpIkX5bTZGRB3eCA==", - "dev": true, "license": "MIT", "dependencies": { "@types/parse-json": "^4.0.0", @@ -19684,7 +20001,6 @@ "version": "1.10.3", "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.3.tgz", "integrity": "sha512-vIYeF1u3CjlhAFekPPAk2h/Kv4T3mAkMox5OymRiJQB0spDP10LHvt+K7G9Ny6NuuMAb25/6n1qyUjAcGNf/AA==", - "dev": true, "license": "ISC", "engines": { "node": ">= 6" @@ -20078,7 +20394,6 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", - "dev": true, "license": "MIT", "dependencies": { "fill-range": "^7.1.1" @@ -20304,7 +20619,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -20314,7 +20628,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-4.1.2.tgz", "integrity": "sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw==", - "dev": true, "license": "MIT", "dependencies": { "pascal-case": "^3.1.2", @@ -20420,7 +20733,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/capital-case/-/capital-case-1.0.4.tgz", "integrity": "sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A==", - "dev": true, "license": "MIT", "dependencies": { "no-case": "^3.0.4", @@ -20449,7 +20761,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/change-case/-/change-case-4.1.2.tgz", "integrity": "sha512-bSxY2ws9OtviILG1EiY5K7NNxkqg/JnRnFxLtKQ96JaviiIxi7djMrSd0ECT9AC+lttClmYwKw53BWpOMblo7A==", - "dev": true, "license": "MIT", "dependencies": { "camel-case": "^4.1.2", @@ -20760,7 +21071,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", "integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -21003,7 +21313,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/constant-case/-/constant-case-3.0.4.tgz", "integrity": "sha512-I2hSBi7Vvs7BEuJDr5dDHfzb/Ruj3FyvFyh7KLilAjNQw3Be+xgqUBA2W6scVEcL0hL1dwPRtIqEPVUCKkSsyQ==", - "dev": true, "license": "MIT", "dependencies": { "no-case": "^3.0.4", @@ -21038,7 +21347,6 @@ "version": "1.9.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", - "dev": true, "license": "MIT" }, "node_modules/cookie": { @@ -21543,7 +21851,6 @@ "version": "3.2.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", - "dev": true, "license": "MIT" }, "node_modules/cwd": { @@ -21674,7 +21981,6 @@ "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -22021,7 +22327,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dev": true, "license": "MIT", "dependencies": { "path-type": "^4.0.0" @@ -22132,7 +22437,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz", "integrity": "sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==", - "dev": true, "license": "MIT", "dependencies": { "no-case": "^3.0.4", @@ -22369,7 +22673,6 @@ "version": "1.3.4", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.4.tgz", "integrity": "sha512-sqQamAnR14VgCr1A618A3sGrygcpK+HEbenA/HiEAkkUwcZIIB/tgWqHFxWgOyDh4nB4JCRimh79dR5Ywc9MDQ==", - "dev": true, "license": "MIT", "dependencies": { "is-arrayish": "^0.2.1" @@ -22487,7 +22790,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -22612,7 +22914,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true, "license": "MIT", "engines": { "node": ">=10" @@ -23767,7 +24068,6 @@ "version": "3.3.3", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", - "dev": true, "license": "MIT", "dependencies": { "@nodelib/fs.stat": "^2.0.2", @@ -23784,7 +24084,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, "license": "ISC", "dependencies": { "is-glob": "^4.0.1" @@ -23879,7 +24178,6 @@ "version": "1.20.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.1.tgz", "integrity": "sha512-GGToxJ/w1x32s/D2EKND7kTil4n8OVk/9mycTc4VDza13lOvpUZTGX3mFSCtV9ksdGBVzvsyAVLM6mHFThxXxw==", - "dev": true, "license": "ISC", "dependencies": { "reusify": "^1.0.4" @@ -23981,7 +24279,6 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", - "dev": true, "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" @@ -24096,7 +24393,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz", "integrity": "sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==", - "dev": true, "license": "MIT" }, "node_modules/find-up": { @@ -24379,7 +24675,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -25004,7 +25299,6 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", - "dev": true, "license": "MIT", "dependencies": { "function-bind": "^1.1.2" @@ -25017,7 +25311,6 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/header-case/-/header-case-2.0.4.tgz", "integrity": "sha512-H/vuk5TEEVZwrR0lp2zed9OCo1uAILMlx0JEMgC26rzyJJ3N1v6XkwHHXJQdR2doSjcGPM6OKPYoJgf0plJ11Q==", - "dev": true, "license": "MIT", "dependencies": { "capital-case": "^1.0.4", @@ -25062,7 +25355,6 @@ "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==", - "dev": true, "license": "BSD-3-Clause", "dependencies": { "react-is": "^16.7.0" @@ -25072,7 +25364,6 @@ "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "dev": true, "license": "MIT" }, "node_modules/homedir-polyfill": { @@ -25531,7 +25822,6 @@ "version": "3.3.1", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==", - "dev": true, "license": "MIT", "dependencies": { "parent-module": "^1.0.0", @@ -25548,7 +25838,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", - "dev": true, "license": "MIT", "engines": { "node": ">=4" @@ -25746,7 +26035,6 @@ "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", - "dev": true, "license": "MIT" }, "node_modules/is-async-function": { @@ -25862,7 +26150,6 @@ "version": "2.16.2", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.2.tgz", "integrity": "sha512-evOr8xfXKxE6qSR0hSXL2r3sd7ALj8+7jQEUvPYcm5sgZFdJ+AYzT6yNmJenvIYQBgIGwfwz08sL8zoL7yq2BA==", - "dev": true, "license": "MIT", "dependencies": { "hasown": "^2.0.3" @@ -25955,7 +26242,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -26021,7 +26307,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, "license": "MIT", "dependencies": { "is-extglob": "^2.1.1" @@ -26070,7 +26355,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.12.0" @@ -26110,7 +26394,6 @@ "version": "5.1.0", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.1.0.tgz", "integrity": "sha512-bUi/yjmtKYcRVUtWRGr0UA6xEFh2I6zWUwMrUXB3s7bmYCaZ8a+0ZsTRkrawh/mzlSD1Y0Ph8bp/U+TvBpWDNw==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -27446,7 +27729,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true, "license": "MIT" }, "node_modules/js-yaml": { @@ -27517,7 +27799,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", - "dev": true, "license": "MIT", "bin": { "jsesc": "bin/jsesc" @@ -27537,7 +27818,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", - "dev": true, "license": "MIT" }, "node_modules/json-schema-traverse": { @@ -28034,7 +28314,6 @@ "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", - "dev": true, "license": "MIT" }, "node_modules/linkify-it": { @@ -28222,7 +28501,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", - "dev": true, "license": "MIT", "dependencies": { "js-tokens": "^3.0.0 || ^4.0.0" @@ -28235,7 +28513,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", - "dev": true, "license": "MIT", "dependencies": { "tslib": "^2.0.3" @@ -28582,6 +28859,12 @@ "dev": true, "license": "MIT" }, + "node_modules/memoize-one": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz", + "integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==", + "license": "MIT" + }, "node_modules/meow": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/meow/-/meow-9.0.0.tgz", @@ -28668,7 +28951,6 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true, "license": "MIT", "engines": { "node": ">= 8" @@ -28695,7 +28977,6 @@ "version": "4.0.8", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", - "dev": true, "license": "MIT", "dependencies": { "braces": "^3.0.3", @@ -28979,7 +29260,6 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true, "license": "MIT" }, "node_modules/multicast-dns": { @@ -29086,7 +29366,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", - "dev": true, "license": "MIT", "dependencies": { "lower-case": "^2.0.2", @@ -29948,7 +30227,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/param-case/-/param-case-3.0.4.tgz", "integrity": "sha512-RXlj7zCYokReqWpOPH9oYivUzLYZ5vAPIfEmCTNViosC78F8F0H9y7T7gG2M39ymgutxF5gcFEsyZQSph9Bp3A==", - "dev": true, "license": "MIT", "dependencies": { "dot-case": "^3.0.4", @@ -29959,7 +30237,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", - "dev": true, "license": "MIT", "dependencies": { "callsites": "^3.0.0" @@ -29988,7 +30265,6 @@ "version": "5.2.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.0.0", @@ -30077,7 +30353,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/pascal-case/-/pascal-case-3.1.2.tgz", "integrity": "sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==", - "dev": true, "license": "MIT", "dependencies": { "no-case": "^3.0.4", @@ -30088,7 +30363,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/path-case/-/path-case-3.0.4.tgz", "integrity": "sha512-qO4qCFjXqVTrcbPt/hQfhTQ+VhFsqNKOPtytgNKkKxSoEp3XPUQ8ObFuePylOIok5gjn69ry8XiULxCwot3Wfg==", - "dev": true, "license": "MIT", "dependencies": { "dot-case": "^3.0.4", @@ -30145,7 +30419,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "dev": true, "license": "MIT" }, "node_modules/path-scurry": { @@ -30183,7 +30456,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -30234,14 +30506,12 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", - "dev": true, "license": "ISC" }, "node_modules/picomatch": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", - "dev": true, "license": "MIT", "engines": { "node": ">=8.6" @@ -31535,7 +31805,6 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "dev": true, "funding": [ { "type": "github", @@ -31629,7 +31898,6 @@ "version": "18.3.1", "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", - "dev": true, "license": "MIT", "dependencies": { "loose-envify": "^1.1.0" @@ -31692,7 +31960,6 @@ "version": "18.3.1", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", - "dev": true, "license": "MIT", "dependencies": { "loose-envify": "^1.1.0", @@ -31829,6 +32096,23 @@ } } }, + "node_modules/react-window": { + "version": "1.8.11", + "resolved": "https://registry.npmjs.org/react-window/-/react-window-1.8.11.tgz", + "integrity": "sha512-+SRbUVT2scadgFSWx+R1P754xHPEqvcfSfVX10QYg6POOz+WNgkN48pS+BtZNIMGiL1HYrSEiCkwsMS15QogEQ==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.0.0", + "memoize-one": ">=3.1.1 <6" + }, + "engines": { + "node": ">8.0.0" + }, + "peerDependencies": { + "react": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/read-cache": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.2.tgz", @@ -32177,7 +32461,6 @@ "version": "1.22.12", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.12.tgz", "integrity": "sha512-TyeJ1zif53BPfHootBGwPRYT1RUt6oGWsaQr8UyZW/eAm9bKoijtvruSDEmZHm92CwS9nj7/fWttqPCgzep8CA==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -32317,7 +32600,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", - "dev": true, "license": "MIT", "engines": { "iojs": ">=1.0.0", @@ -32468,7 +32750,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", - "dev": true, "funding": [ { "type": "github", @@ -32691,7 +32972,6 @@ "version": "0.23.2", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", - "dev": true, "license": "MIT", "dependencies": { "loose-envify": "^1.1.0" @@ -32807,7 +33087,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/sentence-case/-/sentence-case-3.0.4.tgz", "integrity": "sha512-8LS0JInaQMCRoQ7YUytAo/xUu5W2XnQxV2HI/6uM6U7CITS1RqPElr30V6uIqyMKM9lJGRVFy5/4CuzcixNYSg==", - "dev": true, "license": "MIT", "dependencies": { "no-case": "^3.0.4", @@ -33287,7 +33566,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -33326,7 +33604,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/snake-case/-/snake-case-3.0.4.tgz", "integrity": "sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==", - "dev": true, "license": "MIT", "dependencies": { "dot-case": "^3.0.4", @@ -33390,7 +33667,6 @@ "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", - "dev": true, "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" @@ -34433,7 +34709,6 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/stylis/-/stylis-4.2.0.tgz", "integrity": "sha512-Orov6g6BB1sDfYgzWfTHDOxamtX1bE/zo104Dh9e6fqJ3PooipYyfJ0pUmrZO2wAvO8YbEyeFrkV91XTsGMSrw==", - "dev": true, "license": "MIT" }, "node_modules/supports-color": { @@ -34470,7 +34745,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -35005,7 +35279,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, "license": "MIT", "dependencies": { "is-number": "^7.0.0" @@ -35156,7 +35429,6 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "dev": true, "license": "0BSD" }, "node_modules/type-check": { @@ -35293,6 +35565,19 @@ "dev": true, "license": "MIT" }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/typescript-eslint": { "version": "8.71.2", "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.71.2.tgz", @@ -35516,7 +35801,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/upper-case/-/upper-case-2.0.2.tgz", "integrity": "sha512-KgdgDGJt2TpuwBUIjgG6lzw2GWFRCW9Qkfkiv0DxqHHLYJHmtmdUIKcZd8rHgFSjopVTlw6ggzCm1b8MFQwikg==", - "dev": true, "license": "MIT", "dependencies": { "tslib": "^2.0.3" @@ -35526,7 +35810,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/upper-case-first/-/upper-case-first-2.0.2.tgz", "integrity": "sha512-514ppYHBaKwfJRK/pNC6c/OxfGa0obSnAl106u97Ed0I625Nin96KAjttZF6ZL3e1XLtphxnqrOi9iWgm+u+bg==", - "dev": true, "license": "MIT", "dependencies": { "tslib": "^2.0.3" @@ -35706,10 +35989,9 @@ } }, "node_modules/uuid": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-14.0.0.tgz", - "integrity": "sha512-Qo+uWgilfSmAhXCMav1uYFynlQO7fMFiMVZsQqZRMIXp0O7rR7qjkj+cPvBHLgBqi960QCoo/PH2/6ZtVqKvrg==", - "dev": true, + "version": "14.0.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-14.0.3.tgz", + "integrity": "sha512-Sc5u1VVln93y1Xnz4R+CunOZc7R9LUcTmhj7Rc7Eg3HVcf7rVn2FOoa812fe0W8p3jD7xeoGSYbfqCGGH2B6xw==", "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" @@ -36530,6 +36812,18 @@ "node": ">=0.10.0" } }, + "node_modules/wp-types": { + "version": "3.66.1", + "resolved": "https://registry.npmjs.org/wp-types/-/wp-types-3.66.1.tgz", + "integrity": "sha512-f0llrGik5sKF38t3sgSFUwU0IQ5ljZwii+rf4gUDv462OiCspuu52uTI9UOPpQqX0JNKUvAAik5Bm/KyYbjkcw==", + "license": "MIT", + "dependencies": { + "typescript": ">=3" + }, + "funding": { + "url": "https://github.com/sponsors/johnbillion" + } + }, "node_modules/wrap-ansi": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", diff --git a/package.json b/package.json index 0a4b809..22e0748 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,10 @@ "@wordpress/plugins": "^7.45.0", "@wordpress/prettier-config": "^4.46.0", "@wordpress/scripts": "^32.1.0", - "@wordpress/stylelint-config": "^23.38.0" + "@wordpress/stylelint-config": "^23.38.0", + "typescript": "^5.9.3" + }, + "dependencies": { + "@10up/block-components": "^1.23.0" } } diff --git a/src/js/blocks/post-roundup/block.json b/src/js/blocks/post-roundup/block.json new file mode 100644 index 0000000..ff3356a --- /dev/null +++ b/src/js/blocks/post-roundup/block.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "beehiiv/post-roundup", + "version": "1.0.0", + "title": "Post Roundup", + "category": "beehiiv-blocks", + "icon": "excerpt-view", + "description": "Adds a roundup of posts to the newsletter. Available in newsletters only. Outputs nothing on the website.", + "keywords": [ "beehiiv", "roundup", "posts", "digest" ], + "textdomain": "beehiiv", + "supports": { + "html": false, + "anchor": true + }, + "attributes": { + "mode": { + "type": "string", + "enum": [ "auto", "manual" ], + "default": "auto" + }, + "count": { + "type": "number", + "default": 3 + }, + "posts": { + "type": "array", + "default": [] + }, + "uid": { + "type": "string", + "default": "" + } + }, + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css" +} diff --git a/src/js/blocks/post-roundup/edit.js b/src/js/blocks/post-roundup/edit.js new file mode 100644 index 0000000..458046a --- /dev/null +++ b/src/js/blocks/post-roundup/edit.js @@ -0,0 +1,221 @@ +import { useEffect, useState } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { + InspectorControls, + useBlockProps, + store as blockEditorStore, +} from '@wordpress/block-editor'; +import { + PanelBody, + Placeholder, + RangeControl, + Spinner, + RadioControl, +} from '@wordpress/components'; +import { useSelect } from '@wordpress/data'; +import apiFetch from '@wordpress/api-fetch'; +import { postList } from '@wordpress/icons'; +import { ContentPicker } from '@10up/block-components'; + +import metadata from './block.json'; +import { + MAX_COUNT, + MIN_COUNT, + MODE_AUTO, + MODE_MANUAL, + clampCount, + createUid, + getPreviewPath, +} from './utils'; + +function PostCard( { card } ) { + return ( + + ); +} + +export default function Edit( { attributes, setAttributes, clientId } ) { + const { mode, count, posts, uid } = attributes; + const isManual = mode === MODE_MANUAL; + + const { postId, firstUidClientId } = useSelect( + ( select ) => { + const roundups = select( blockEditorStore ) + .getBlocks() + .filter( ( block ) => block.name === metadata.name ); + + return { + postId: select( 'core/editor' )?.getCurrentPostId(), + firstUidClientId: roundups.find( + ( block ) => block.attributes.uid === uid + )?.clientId, + }; + }, + [ uid ] + ); + + // Each roundup needs its own id so its frozen list is kept apart from others. + // A duplicated block gets a new id. + const isDuplicateUid = !! uid && firstUidClientId !== clientId; + + useEffect( () => { + if ( ! uid || isDuplicateUid ) { + setAttributes( { uid: createUid() } ); + } + }, [ uid, isDuplicateUid, setAttributes ] ); + + const [ cards, setCards ] = useState( [] ); + const [ isLoading, setIsLoading ] = useState( false ); + + const pickedKey = ( posts || [] ).map( ( post ) => post.id ).join( ',' ); + + useEffect( () => { + if ( ! postId ) { + return undefined; + } + + let isCurrent = true; + setIsLoading( true ); + + apiFetch( { path: getPreviewPath( postId, attributes ) } ) + .then( ( items ) => { + if ( isCurrent ) { + setCards( Array.isArray( items ) ? items : [] ); + } + } ) + .catch( () => { + if ( isCurrent ) { + setCards( [] ); + } + } ) + .finally( () => { + if ( isCurrent ) { + setIsLoading( false ); + } + } ); + + return () => { + isCurrent = false; + }; + // `attributes` is summarised by the values below. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [ postId, mode, count, pickedKey, uid ] ); + + const blockProps = useBlockProps(); + + let preview; + + if ( isLoading && ! cards.length ) { + preview = ; + } else if ( ! cards.length ) { + preview = ( + + ); + } else { + preview = cards.map( ( card ) => ( + + ) ); + } + + return ( + <> + + + + setAttributes( { mode: value } ) + } + /> + { isManual ? ( +
+ + setAttributes( { posts: items } ) + } + isOrderable + maxContentItems={ MAX_COUNT } + uniqueContentItems + /> +
+ ) : ( + + setAttributes( { count: clampCount( value ) } ) + } + min={ MIN_COUNT } + max={ MAX_COUNT } + __nextHasNoMarginBottom + /> + ) } +
+
+ +
{ preview }
+ + ); +} diff --git a/src/js/blocks/post-roundup/editor.scss b/src/js/blocks/post-roundup/editor.scss new file mode 100644 index 0000000..492ce67 --- /dev/null +++ b/src/js/blocks/post-roundup/editor.scss @@ -0,0 +1,57 @@ +@use "../../css" as beehiiv; + +.wp-block-beehiiv-post-roundup { + display: flex; + flex-direction: column; + gap: 1.5rem; + + @include beehiiv.block-placeholder-outline; +} + +/* stylelint-disable selector-class-pattern -- BEM + @wordpress/components */ +.beehiiv-post-roundup__card { + display: flex; + flex-direction: column; + gap: 0.5rem; + padding-bottom: 1.5rem; + border-bottom: 1px solid #ddd; + + &:last-child { + padding-bottom: 0; + border-bottom: 0; + } + + p { + margin: 0; + } + + a { + color: inherit; + text-decoration: underline; + pointer-events: none; + } +} + +.beehiiv-post-roundup__title strong { + font-weight: 700; +} + +.beehiiv-post-roundup__image { + display: block; + max-width: 100%; + height: auto; +} + +.beehiiv-post-roundup__button { + align-self: flex-start; + padding: 0.5rem 1rem; + border-radius: 2px; + background: #1e1e1e; + color: #fff; + font-size: 0.875rem; +} + +.beehiiv-post-roundup__picker { + margin-top: 16px; +} +/* stylelint-enable selector-class-pattern */ diff --git a/src/js/blocks/post-roundup/index.js b/src/js/blocks/post-roundup/index.js new file mode 100644 index 0000000..b3cca97 --- /dev/null +++ b/src/js/blocks/post-roundup/index.js @@ -0,0 +1,11 @@ +import { registerBlockType } from '@wordpress/blocks'; + +import metadata from './block.json'; +import Edit from './edit'; + +import './editor.scss'; + +registerBlockType( metadata.name, { + edit: Edit, + save: () => null, +} ); diff --git a/src/js/blocks/post-roundup/utils.js b/src/js/blocks/post-roundup/utils.js new file mode 100644 index 0000000..856524f --- /dev/null +++ b/src/js/blocks/post-roundup/utils.js @@ -0,0 +1,57 @@ +export const MODE_AUTO = 'auto'; +export const MODE_MANUAL = 'manual'; +export const DEFAULT_COUNT = 3; +export const MIN_COUNT = 1; +export const MAX_COUNT = 10; + +/** + * Keep the automatic post count within the allowed range. + * + * @param {*} value Requested count. + * @return {number} Whole number from MIN_COUNT to MAX_COUNT. + */ +export function clampCount( value ) { + const number = Math.round( Number( value ) ); + + if ( ! Number.isFinite( number ) ) { + return DEFAULT_COUNT; + } + + return Math.max( MIN_COUNT, Math.min( MAX_COUNT, number ) ); +} + +/** + * Short random id that tells this block's frozen list apart from other roundups. + * + * @return {string} Lowercase alphanumeric id. + */ +export function createUid() { + return Math.random().toString( 36 ).slice( 2, 10 ); +} + +/** + * Build the preview request path from the block attributes. + * + * Mirrors the server resolver inputs, so the preview and the send agree. + * + * @param {number} postId Newsletter post ID. + * @param {Object} attributes Block attributes. + * @return {string} REST path. + */ +export function getPreviewPath( postId, attributes ) { + const { mode, count, posts, uid } = attributes; + const params = new URLSearchParams( { post_id: String( postId ) } ); + + params.set( 'mode', mode === MODE_MANUAL ? MODE_MANUAL : MODE_AUTO ); + params.set( 'uid', uid || '' ); + + if ( mode === MODE_MANUAL ) { + ( posts || [] ).forEach( ( post ) => { + params.append( 'ids[]', String( post.id ) ); + } ); + } else { + params.set( 'count', String( clampCount( count ) ) ); + } + + return `/beehiiv/v1/post-roundup?${ params.toString() }`; +} diff --git a/src/js/editor/post-settings/hooks/use-beehiiv-editor-config.js b/src/js/editor/post-settings/hooks/use-beehiiv-editor-config.js index 100bed7..312f1a0 100644 --- a/src/js/editor/post-settings/hooks/use-beehiiv-editor-config.js +++ b/src/js/editor/post-settings/hooks/use-beehiiv-editor-config.js @@ -13,6 +13,8 @@ const DEFAULT_CONFIG = { publicationId: '', defaultPostTemplateId: '', canPublishPosts: false, + supportedPostTypes: [ 'post' ], + newsletterPostType: 'beehiiv_newsletter', defaultPublicationId: '', publications: [], }; diff --git a/src/js/editor/post-settings/index.js b/src/js/editor/post-settings/index.js index 636895f..d23d13f 100644 --- a/src/js/editor/post-settings/index.js +++ b/src/js/editor/post-settings/index.js @@ -1,7 +1,8 @@ /** * beehiiv post settings plugin sidebar. * - * Registers a dedicated editor sidebar on the default `post` post type. + * Registers a dedicated editor sidebar on the post types beehiiv supports + * (`post` and the newsletter type, from `beehiivPostSettings.supportedPostTypes`). */ import { __ } from '@wordpress/i18n'; import { registerPlugin } from '@wordpress/plugins'; @@ -117,7 +118,12 @@ function useIsNewsletterReady( postPublication ) { function BeehiivPostSettingsPanel() { const beehiivMeta = useBeehiivPostMeta(); - const { isConnected, canWritePosts } = useBeehiivEditorConfig(); + const { isConnected, canWritePosts, newsletterPostType } = + useBeehiivEditorConfig(); + const postType = useSelect( + ( select ) => select( editorStore ).getCurrentPostType(), + [] + ); const postPublication = usePostPublication( beehiivMeta ); const isNewsletterReady = useIsNewsletterReady( postPublication ); @@ -125,6 +131,9 @@ function BeehiivPostSettingsPanel() { return null; } + // A newsletter has no public post for a "Read More" button to link to. + const supportsSnippet = postType !== newsletterPostType; + const { sendToNewsletter, sendToNewsletterDate, @@ -252,30 +261,35 @@ function BeehiivPostSettingsPanel() { { newsletterWording } - - { __( - 'Send a snippet newsletter with a "Read More" button to the full post.', - 'beehiiv' - ) } - { sendToNewsletterSnippet && ( - <> -
-
- { __( - 'Insert the "More" block in your post to mark where the snippet ends.', - 'beehiiv' - ) } - - ) } - - } - checked={ sendToNewsletterSnippet } - onChange={ setSendToNewsletterSnippet } - /> + { supportsSnippet && ( + + { __( + 'Send a snippet newsletter with a "Read More" button to the full post.', + 'beehiiv' + ) } + { sendToNewsletterSnippet && ( + <> +
+
+ { __( + 'Insert the "More" block in your post to mark where the snippet ends.', + 'beehiiv' + ) } + + ) } + + } + checked={ sendToNewsletterSnippet } + onChange={ setSendToNewsletterSnippet } + /> + ) } ) } @@ -299,23 +313,41 @@ function BeehiivPostSettingsPanel() { } function useBeehiivPostSettingsEligibility() { - return useSelect( ( select ) => { - const editor = select( editorStore ); - const core = select( coreStore ); - - return { - postType: editor.getCurrentPostType(), - canPublishPosts: core.canUser( 'publish', 'posts' ), - }; - }, [] ); + const { supportedPostTypes } = useBeehiivEditorConfig(); + + return useSelect( + ( select ) => { + const editor = select( editorStore ); + const core = select( coreStore ); + const postType = editor.getCurrentPostType(); + + // `canUser` needs the REST resource of the current type (`posts`, + // `beehiiv-newsletters`), not a hard-coded `posts`. Undefined while + // the type resolves, which callers treat as "not denied". + const resource = postType + ? core.getPostType( postType )?.rest_base + : undefined; + + return { + postType, + isSupportedPostType: + ! postType || supportedPostTypes.includes( postType ), + canPublishPosts: resource + ? core.canUser( 'publish', resource ) + : undefined, + }; + }, + [ supportedPostTypes ] + ); } function BeehiivPostSettingsSidebar() { - const { postType, canPublishPosts } = useBeehiivPostSettingsEligibility(); + const { isSupportedPostType, canPublishPosts } = + useBeehiivPostSettingsEligibility(); - // Only on the `post` post type. `canUser` is undefined while resolving — do not + // Only on supported post types. `canUser` is undefined while resolving — do not // treat that as denied or the sidebar icon never registers. - if ( postType && postType !== 'post' ) { + if ( ! isSupportedPostType ) { return null; } @@ -336,14 +368,15 @@ function BeehiivPostSettingsSidebar() { } function BeehiivSendNewsletterPrePublishPanel() { - const { postType, canPublishPosts } = useBeehiivPostSettingsEligibility(); + const { isSupportedPostType, canPublishPosts } = + useBeehiivPostSettingsEligibility(); const beehiivMeta = useBeehiivPostMeta(); const postPublishDate = usePostPublishDate(); const { isConnected, canWritePosts } = useBeehiivEditorConfig(); const postPublication = usePostPublication( beehiivMeta ); const isNewsletterReady = useIsNewsletterReady( postPublication ); - if ( postType && postType !== 'post' ) { + if ( ! isSupportedPostType ) { return null; } diff --git a/tests/e2e/specs/newsletters-content-type.spec.js b/tests/e2e/specs/newsletters-content-type.spec.js new file mode 100644 index 0000000..be020ac --- /dev/null +++ b/tests/e2e/specs/newsletters-content-type.spec.js @@ -0,0 +1,720 @@ +const { test, expect } = require( '@playwright/test' ); +const { loginAs, loginAsAdmin } = require( '../utils/auth' ); +const { openBeehiivSidebar } = require( '../utils/editor' ); +const { + wpCli, + wpCliSafe, + ensurePluginActive, + ensurePrettyPermalinks, +} = require( '../utils/wp-cli' ); + +/** + * PRD: requirements/07-newsletter-publishing/5-post-picker-creation/newsletters-content-type.prd.md (v1.0) + * + * Independent behavioral coverage (qa-e2e-author), written from the PRD's + * Acceptance Criteria plus the real code at: + * - includes/Newsletter/NewsletterPostType.php -- the non-public + * `beehiiv_newsletter` type, list columns and the status cell. + * - includes/Newsletter/ContentTypes.php -- shared supported-type list and + * the per-type "Send to newsletter" default. + * - includes/REST/NewslettersController.php -- REST base `beehiiv-newsletters`. + * - includes/Admin/Menu.php -- menu capability split. + * - includes/Editor/PostSettings.php, includes/Newsletter/Sender.php -- + * editor panel and send flow for supported types. + * + * Sends go through the REST endpoint the block editor uses. Every outbound + * beehiiv request is answered by the test-only mock in + * tests/e2e/plugins/beehiiv-options.php and recorded, so specs assert on the + * exact payload. Nothing reaches the live API. + */ + +const TYPE = 'beehiiv_newsletter'; +const REST_BASE = 'beehiiv-newsletters'; +const META_SEND = '_beehiiv_send_to_newsletter'; +const META_POST_ID = '_beehiiv_post_id'; +const META_SCHEDULED_AT = '_beehiiv_scheduled_at'; +const META_SENT = '_beehiiv_newsletter_sent'; +const META_ERROR = '_beehiiv_newsletter_error'; + +const PUBLICATION_ID = 'pub_qa_e2e_nl'; +const TEMPLATE_ID = 'tpl_qa_e2e_nl'; +const MOCK_CREATED_ID = 'post_qa_e2e_nl_created'; + +const PASSWORD = 'qa-e2e-nl-user-pw-1'; +const USERS = { + editor: { name: 'qa_e2e_nl_editor', role: 'editor' }, + author: { name: 'qa_e2e_nl_author', role: 'author' }, + contributor: { name: 'qa_e2e_nl_contributor', role: 'contributor' }, +}; + +const created = []; + +const b64 = ( value ) => + Buffer.from( JSON.stringify( value ) ).toString( 'base64' ); + +/** + * Runs PHP inside the tests env; the payload travels base64-encoded. + * + * @param {Object} payload Values exposed to the PHP snippet as `$a`. + * @param {string} php PHP code to evaluate. + * @return {string} wp-cli output. + */ +function wpEvalWith( payload, php ) { + return wpCli( + `eval '$a = json_decode( base64_decode( "${ b64( + payload + ) }" ), true ); ${ php }'` + ); +} + +/** + * Seeds a connected, ready-to-send site and mocks the beehiiv API. + */ +function seed() { + wpEvalWith( + {}, + `beehiiv_e2e_reset_all(); + beehiiv_e2e_seed_connection(); + beehiiv_e2e_mock_permissions( [ "posts" => [ "read", "write" ] ] ); + update_option( "beehiiv_settings", [ "publication_id" => "${ PUBLICATION_ID }", "post_template_id" => "${ TEMPLATE_ID }" ] ); + beehiiv_e2e_seed_publications( [ [ "id" => "${ PUBLICATION_ID }", "name" => "QA E2E Publication" ] ] ); + beehiiv_e2e_seed_post_templates( "${ PUBLICATION_ID }", [ [ "id" => "${ TEMPLATE_ID }", "name" => "QA E2E Template" ] ] ); + beehiiv_e2e_mock_http( "/posts", [ "body" => [ "data" => [ "id" => "${ MOCK_CREATED_ID }" ] ] ] ); + update_option( "timezone_string", "" ); + update_option( "gmt_offset", 0 ); + beehiiv_e2e_clear_http_log();` + ); +} + +/** + * Creates a newsletter directly in the DB. + * + * @param {Object} options Fields. + * @param {string} options.title Title. + * @param {string} [options.status] Post status. + * @param {string} [options.content] Post content. + * @param {Object} [options.meta] Meta to set. + * @param {number} [options.author] Author user ID. + * @param {string} [options.type] Post type. + * @return {string} Post ID. + */ +function createItem( { + title, + status = 'draft', + content = '

QA E2E newsletter body.

', + meta = {}, + author = 1, + type = TYPE, +} ) { + const id = wpEvalWith( + { title, status, content, meta, author, type }, + `$id = wp_insert_post( [ "post_type" => $a["type"], "post_title" => $a["title"], "post_status" => $a["status"], "post_content" => $a["content"], "post_author" => $a["author"] ] ); + foreach ( $a["meta"] as $k => $v ) { update_post_meta( $id, $k, $v ); } + beehiiv_e2e_clear_http_log(); + echo $id . "\\n";` + ); + created.push( id ); + return id; +} + +function getLog() { + return JSON.parse( + wpCli( `eval 'beehiiv_e2e_print_http_log();'` ) || '[]' + ); +} + +const creates = ( log ) => + log.filter( + ( r ) => + r.method === 'POST' && /\/publications\/[^/]+\/posts$/.test( r.url ) + ); + +/** + * Creates or reuses a fixture user with a known password. + * + * @param {Object} user User definition. + */ +function ensureUser( user ) { + if ( wpCliSafe( `user get ${ user.name } --field=ID` ) === null ) { + wpCli( + `user create ${ user.name } ${ user.name }@example.test --role=${ user.role } --user_pass=${ PASSWORD }` + ); + } else { + wpCli( + `user update ${ user.name } --user_pass=${ PASSWORD } --role=${ user.role }` + ); + } +} + +/** + * Logs in as a user and returns a REST caller bound to that session. + * + * @param {import('@playwright/test').Page} page Playwright page. + * @param {string|null} username Username, or null for admin. + * @return {Promise} `( method, path, data ) => { status, body }`. + */ +async function restAs( page, username = null ) { + if ( username ) { + await loginAs( page, username, PASSWORD ); + } else { + await loginAsAdmin( page ); + } + const nonceRes = await page.request.get( + '/wp-admin/admin-ajax.php?action=rest-nonce' + ); + const nonce = ( await nonceRes.text() ).trim(); + return async ( method, path, data ) => { + const res = await page.request.fetch( `/wp-json${ path }`, { + method, + headers: { 'X-WP-Nonce': nonce }, + data, + } ); + let body = null; + try { + body = await res.json(); + } catch { + // Non-JSON response; leave body null. + } + return { status: res.status(), body }; + }; +} + +/** + * Opens a block editor URL and dismisses the welcome guide. + * + * @param {import('@playwright/test').Page} page Playwright page. + * @param {string} url Editor URL. + */ +async function openEditor( page, url ) { + await page.goto( url ); + await page.waitForSelector( 'iframe[name="editor-canvas"]', { + timeout: 20000, + } ); + const close = page.locator( '.components-modal__header button' ).first(); + const appeared = await close + .waitFor( { state: 'visible', timeout: 4000 } ) + .then( () => true ) + .catch( () => false ); + if ( appeared ) { + await close.click(); + await close + .waitFor( { state: 'hidden', timeout: 5000 } ) + .catch( () => {} ); + } +} + +test.describe.configure( { timeout: 120 * 1000 } ); + +test.beforeAll( () => { + ensurePluginActive(); + ensurePrettyPermalinks(); + Object.values( USERS ).forEach( ensureUser ); + seed(); +} ); + +test.afterAll( () => { + // Unlink first so deleting never tries to cancel a beehiiv newsletter. + if ( created.length ) { + wpCliSafe( + `eval 'foreach ( array( ${ created.join( + ', ' + ) } ) as $id ) { delete_post_meta( $id, "${ META_POST_ID }" ); wp_delete_post( $id, true ); }'` + ); + } + wpCliSafe( + `eval 'delete_option( "beehiiv_settings" ); beehiiv_e2e_reset_all();'` + ); +} ); + +// --------------------------------------------------------------------------- +test.describe( 'US-001: compose newsletters apart from posts', () => { + test( 'AC-001: the beehiiv > Newsletters entry opens a list of newsletters with an Add New action', async ( { + page, + } ) => { + await loginAsAdmin( page ); + await page.goto( '/wp-admin/' ); + + const submenuLink = page.locator( + '#toplevel_page_beehiiv .wp-submenu a', + { hasText: 'Newsletters' } + ); + await expect( submenuLink ).toHaveCount( 1 ); + // The submenu flyout only opens on hover. + await page.locator( '#toplevel_page_beehiiv > a.menu-top' ).hover(); + await submenuLink.click(); + + await expect( page ).toHaveURL( + new RegExp( `/wp-admin/edit\\.php\\?post_type=${ TYPE }` ) + ); + await expect( page.locator( 'h1.wp-heading-inline' ) ).toHaveText( + 'Newsletters' + ); + const addNew = page.locator( 'a.page-title-action' ); + await expect( addNew ).toBeVisible(); + await expect( addNew ).toHaveText( /^Add New/ ); + await addNew.click(); + await expect( page ).toHaveURL( + new RegExp( `post-new\\.php\\?post_type=${ TYPE }` ) + ); + } ); + + test( "AC-002: the Newsletters list shows each newsletter's title, beehiiv status, date and author", async ( { + page, + } ) => { + createItem( { title: 'QA E2E list AC-002 row' } ); + await loginAsAdmin( page ); + await page.goto( `/wp-admin/edit.php?post_type=${ TYPE }` ); + + const headers = page.locator( 'table.wp-list-table thead th' ); + await expect( headers.filter( { hasText: 'Title' } ) ).toHaveCount( 1 ); + await expect( + headers.filter( { hasText: 'beehiiv status' } ) + ).toHaveCount( 1 ); + await expect( headers.filter( { hasText: 'Author' } ) ).toHaveCount( + 1 + ); + await expect( headers.filter( { hasText: 'Date' } ) ).toHaveCount( 1 ); + + const row = page.locator( 'table.wp-list-table tbody tr', { + hasText: 'QA E2E list AC-002 row', + } ); + await expect( row ).toHaveCount( 1 ); + await expect( row.locator( 'td.column-beehiiv_status' ) ).toHaveText( + 'Not sent' + ); + await expect( row.locator( 'td.column-author' ) ).toContainText( + 'admin' + ); + await expect( row.locator( 'td.column-date' ) ).not.toHaveText( '' ); + } ); + + test( 'AC-003: authors write newsletters in the block editor with the same block support as posts', async ( { + page, + } ) => { + await loginAsAdmin( page ); + await openEditor( page, `/wp-admin/post-new.php?post_type=${ TYPE }` ); + + const info = await page.evaluate( () => { + const editor = window.wp.data.select( 'core/editor' ); + const rawTypes = window.wp.data + .select( 'core/blocks' ) + .getBlockTypes() + .map( ( b ) => b.name ); + return { type: editor.getCurrentPostType(), blocks: rawTypes }; + } ); + expect( info.type ).toBe( TYPE ); + for ( const name of [ + 'core/paragraph', + 'core/heading', + 'core/image', + 'core/list', + 'core/quote', + ] ) { + expect( info.blocks ).toContain( name ); + } + + // Blocks can actually be inserted and edited in a newsletter. + const canvas = page.frameLocator( 'iframe[name="editor-canvas"]' ); + await canvas + .getByRole( 'textbox', { name: 'Add title' } ) + .fill( 'QA E2E editor AC-003' ); + await page.evaluate( () => { + const { createBlock } = window.wp.blocks; + window.wp.data.dispatch( 'core/block-editor' ).insertBlocks( [ + createBlock( 'core/heading', { + content: 'QA E2E heading', + } ), + createBlock( 'core/paragraph', { content: 'QA E2E para' } ), + ] ); + } ); + await expect( canvas.getByText( 'QA E2E heading' ) ).toBeVisible(); + await expect( canvas.getByText( 'QA E2E para' ) ).toBeVisible(); + + // The same block types are registered when editing a regular post. + await openEditor( page, '/wp-admin/post-new.php' ); + const postBlocks = await page.evaluate( () => + window.wp.data + .select( 'core/blocks' ) + .getBlockTypes() + .map( ( b ) => b.name ) + ); + for ( const name of [ + 'core/paragraph', + 'core/heading', + 'core/image', + 'core/list', + 'core/quote', + ] ) { + expect( postBlocks ).toContain( name ); + } + } ); +} ); + +// --------------------------------------------------------------------------- +test.describe( 'US-002: keep newsletters off the public site', () => { + test( 'AC-004: a newsletter has no public page and never appears on the site, in search, sitemaps or feeds', async ( { + page, + request, + } ) => { + const marker = 'QAE2ENLPUBLICMARKER'; + const id = createItem( { + title: `${ marker } newsletter`, + status: 'publish', + content: `

${ marker } body

`, + } ); + + const registered = wpCli( + `eval '$o = get_post_type_object( "${ TYPE }" ); echo wp_json_encode( [ $o->public, $o->publicly_queryable, $o->exclude_from_search, $o->has_archive ] );'` + ); + expect( JSON.parse( registered ) ).toEqual( [ + false, + false, + true, + false, + ] ); + + // No public page, by id or by type query. + for ( const url of [ + `/?p=${ id }`, + `/?post_type=${ TYPE }&p=${ id }`, + `/?post_type=${ TYPE }`, + ] ) { + const res = await request.get( url, { maxRedirects: 0 } ); + const text = await res.text(); + expect( text ).not.toContain( marker ); + if ( url.includes( `p=${ id }` ) ) { + // 404 or redirect, never the page. + expect( res.status() ).not.toBe( 200 ); + } + } + + // Site search. + const search = await request.get( `/?s=${ marker }` ); + expect( await search.text() ).not.toContain( marker ); + + // Feeds. + for ( const url of [ + '/feed/', + `/?feed=rss2&post_type=${ TYPE }`, + `/?feed=rss2&s=${ marker }`, + ] ) { + const res = await request.get( url ); + // A search feed echoes the query in its own title, so inspect items only. + const items = ( await res.text() ).match( + /[\s\S]*?<\/item>/g + ); + expect( ( items || [] ).join( '' ) ).not.toContain( marker ); + } + + // Core sitemaps. + const index = await request.get( '/wp-sitemap.xml' ); + const indexBody = await index.text(); + expect( indexBody ).not.toContain( TYPE ); + const typeSitemap = await request.get( + `/wp-sitemap-posts-${ TYPE }-1.xml` + ); + expect( typeSitemap.status() ).toBe( 404 ); + const postSitemap = await request.get( '/wp-sitemap-posts-post-1.xml' ); + expect( await postSitemap.text() ).not.toContain( marker ); + + // Anonymous REST reads are blocked. + const rest = await request.get( + `/wp-json/wp/v2/${ REST_BASE }/${ id }` + ); + expect( rest.status() ).not.toBe( 200 ); + expect( await rest.text() ).not.toContain( marker ); + const list = await request.get( `/wp-json/wp/v2/${ REST_BASE }` ); + expect( await list.text() ).not.toContain( marker ); + + // And the site's own post REST list never carries it. + const posts = await request.get( '/wp-json/wp/v2/posts?per_page=100' ); + expect( await posts.text() ).not.toContain( marker ); + await page.close(); + } ); +} ); + +// --------------------------------------------------------------------------- +test.describe( 'US-003: send a newsletter with the beehiiv controls', () => { + test( 'AC-005: the beehiiv editor panel works for newsletters, including publication, template and send or schedule', async ( { + page, + } ) => { + seed(); + const id = createItem( { + title: 'QA E2E panel AC-005', + meta: { [ META_SEND ]: '1' }, + } ); + await loginAsAdmin( page ); + await openEditor( page, `/wp-admin/post.php?post=${ id }&action=edit` ); + await openBeehiivSidebar( page ); + + const sidebar = page.locator( '.beehiiv-post-settings' ); + await expect( + sidebar.getByRole( 'checkbox', { name: 'Send to newsletter' } ) + ).toBeChecked( { timeout: 15000 } ); + await expect( sidebar.getByLabel( 'Publication' ) ).toBeVisible(); + await expect( sidebar.getByLabel( 'Post template' ) ).toBeVisible(); + await expect( + sidebar.getByText( 'On publish', { exact: false } ).first() + ).toBeVisible(); + + // Controls are interactive: pick the seeded publication and template. + await sidebar.getByLabel( 'Publication' ).selectOption( { + value: PUBLICATION_ID, + } ); + await expect( sidebar.getByLabel( 'Publication' ) ).toHaveValue( + PUBLICATION_ID + ); + await sidebar.getByLabel( 'Post template' ).selectOption( { + value: TEMPLATE_ID, + } ); + await expect( sidebar.getByLabel( 'Post template' ) ).toHaveValue( + TEMPLATE_ID + ); + + // Send/schedule control: choosing a date is reflected in the editor store. + const date = await page.evaluate( () => { + window.wp.data.dispatch( 'core/editor' ).editPost( { + meta: { + _beehiiv_send_to_newsletter_date: '2099-01-01T12:00:00', + }, + } ); + return window.wp.data + .select( 'core/editor' ) + .getEditedPostAttribute( 'meta' ) + ._beehiiv_send_to_newsletter_date; + } ); + expect( date ).toBe( '2099-01-01T12:00:00' ); + } ); + + test( 'AC-006: "Send to newsletter" is on by default for a new newsletter', async ( { + page, + } ) => { + seed(); + await loginAsAdmin( page ); + await openEditor( page, `/wp-admin/post-new.php?post_type=${ TYPE }` ); + await openBeehiivSidebar( page ); + const sidebar = page.locator( '.beehiiv-post-settings' ); + await expect( + sidebar.getByRole( 'checkbox', { name: 'Send to newsletter' } ) + ).toBeChecked( { timeout: 15000 } ); + + // Control: a new regular post keeps the toggle off. + await openEditor( page, '/wp-admin/post-new.php' ); + await openBeehiivSidebar( page ); + await expect( + page + .locator( '.beehiiv-post-settings' ) + .getByRole( 'checkbox', { name: 'Send to newsletter' } ) + ).not.toBeChecked( { timeout: 15000 } ); + + // Server agrees with the editor: a newsletter created without the + // meta reads as on, and a publish sends it. + const rest = await restAs( page ); + const made = await rest( 'POST', `/wp/v2/${ REST_BASE }`, { + title: 'QA E2E default AC-006', + content: + '

Default send body.

', + status: 'draft', + } ); + expect( made.status ).toBe( 201 ); + created.push( String( made.body.id ) ); + const read = await rest( + 'GET', + `/wp/v2/${ REST_BASE }/${ made.body.id }?context=edit` + ); + expect( read.body.meta[ META_SEND ] ).toBe( true ); + } ); + + test( 'AC-007: sending a newsletter creates one beehiiv post with the content in the order the author wrote it', async ( { + page, + } ) => { + seed(); + const id = createItem( { + title: 'QA E2E send AC-007', + content: [ + '

ORDER-INTRO opening paragraph

', + '

ORDER-POST-ONE

', + '

ORDER-POST-ONE summary

', + '

ORDER-POST-TWO

', + '

ORDER-POST-TWO summary

', + '

ORDER-POST-THREE

', + '

ORDER-POST-THREE summary

', + '

ORDER-OUTRO closing paragraph

', + ].join( '\n' ), + meta: { [ META_SEND ]: '1' }, + } ); + const rest = await restAs( page ); + const res = await rest( 'POST', `/wp/v2/${ REST_BASE }/${ id }`, { + status: 'publish', + } ); + expect( res.status ).toBe( 200 ); + + const log = getLog(); + expect( creates( log ) ).toHaveLength( 1 ); + expect( creates( log )[ 0 ].url ).toContain( + `/publications/${ PUBLICATION_ID }/posts` + ); + expect( creates( log )[ 0 ].body.title ).toBe( 'QA E2E send AC-007' ); + + const payload = JSON.stringify( creates( log )[ 0 ].body.blocks ); + const order = [ + 'ORDER-INTRO', + 'ORDER-POST-ONE', + 'ORDER-POST-TWO', + 'ORDER-POST-THREE', + 'ORDER-OUTRO', + ].map( ( marker ) => payload.indexOf( marker ) ); + order.forEach( ( position ) => + expect( position ).toBeGreaterThan( -1 ) + ); + expect( [ ...order ].sort( ( a, b ) => a - b ) ).toEqual( order ); + + const linked = wpCli( `post meta get ${ id } ${ META_POST_ID }` ); + expect( linked ).toBe( MOCK_CREATED_ID ); + } ); + + test( 'AC-008: the list shows the status WordPress last recorded: Not sent, Scheduled, Sent or Failed', async ( { + page, + } ) => { + seed(); + const future = new Date( Date.now() + 5 * 24 * 60 * 60 * 1000 ) + .toISOString() + .replace( /\.\d{3}Z$/, 'Z' ); + const past = new Date( Date.now() - 5 * 24 * 60 * 60 * 1000 ) + .toISOString() + .replace( /\.\d{3}Z$/, 'Z' ); + createItem( { title: 'QA E2E status AC-008 notsent' } ); + createItem( { + title: 'QA E2E status AC-008 scheduled', + status: 'draft', + meta: { + [ META_POST_ID ]: 'post_qa_sched', + [ META_SCHEDULED_AT ]: future, + }, + } ); + createItem( { + title: 'QA E2E status AC-008 sent', + status: 'publish', + meta: { + [ META_POST_ID ]: 'post_qa_sent', + [ META_SCHEDULED_AT ]: past, + [ META_SENT ]: '1', + }, + } ); + createItem( { + title: 'QA E2E status AC-008 failed', + meta: { [ META_ERROR ]: 'beehiiv rejected the request' }, + } ); + + await loginAsAdmin( page ); + wpCli( `eval 'beehiiv_e2e_clear_http_log();'` ); + await page.goto( `/wp-admin/edit.php?post_type=${ TYPE }` ); + + const expected = { + notsent: 'Not sent', + scheduled: 'Scheduled', + sent: 'Sent', + failed: 'Failed', + }; + for ( const [ key, label ] of Object.entries( expected ) ) { + const row = page.locator( 'table.wp-list-table tbody tr', { + hasText: `QA E2E status AC-008 ${ key }`, + } ); + await expect( + row.locator( 'td.column-beehiiv_status' ) + ).toHaveText( label ); + } + + // Reading the list makes no beehiiv request. + expect( getLog() ).toHaveLength( 0 ); + } ); +} ); + +// --------------------------------------------------------------------------- +test.describe( 'US-004: reach Newsletters without administrator access', () => { + test( 'AC-009: any user who can publish posts sees the Newsletters entry and can send a newsletter', async ( { + browser, + } ) => { + seed(); + for ( const user of [ USERS.editor, USERS.author ] ) { + const context = await browser.newContext(); + const page = await context.newPage(); + await loginAs( page, user.name, PASSWORD ); + await page.goto( '/wp-admin/' ); + + const submenu = page.locator( + '#toplevel_page_beehiiv .wp-submenu a', + { hasText: 'Newsletters' } + ); + await expect( submenu ).toHaveCount( 1 ); + await page.locator( '#toplevel_page_beehiiv > a.menu-top' ).click(); + await expect( page ).toHaveURL( + new RegExp( `edit\\.php\\?post_type=${ TYPE }` ) + ); + await expect( page.locator( 'h1.wp-heading-inline' ) ).toHaveText( + 'Newsletters' + ); + + // They can send: publish a newsletter of their own. + const authorId = wpCli( `user get ${ user.name } --field=ID` ); + const id = createItem( { + title: `QA E2E send AC-009 ${ user.role }`, + author: Number( authorId ), + meta: { [ META_SEND ]: '1' }, + } ); + const rest = await restAs( page, user.name ); + const res = await rest( 'POST', `/wp/v2/${ REST_BASE }/${ id }`, { + status: 'publish', + } ); + expect( res.status ).toBe( 200 ); + expect( creates( getLog() ) ).toHaveLength( 1 ); + expect( wpCli( `post meta get ${ id } ${ META_POST_ID }` ) ).toBe( + MOCK_CREATED_ID + ); + wpCli( `eval 'beehiiv_e2e_clear_http_log();'` ); + await context.close(); + } + + // A user who cannot publish posts gets no Newsletters entry. + const context = await browser.newContext(); + const page = await context.newPage(); + await loginAs( page, USERS.contributor.name, PASSWORD ); + await page.goto( '/wp-admin/' ); + await expect( page.locator( '#toplevel_page_beehiiv' ) ).toHaveCount( + 0 + ); + await context.close(); + } ); + + test( 'AC-010: the beehiiv Settings page stays available to administrators only', async ( { + page, + browser, + } ) => { + await loginAsAdmin( page ); + const adminRes = await page.goto( '/wp-admin/admin.php?page=beehiiv' ); + expect( adminRes.status() ).toBe( 200 ); + await expect( page.locator( 'h1' ) ).toHaveText( 'beehiiv Settings' ); + + for ( const user of [ USERS.editor, USERS.author ] ) { + const context = await browser.newContext(); + const userPage = await context.newPage(); + await loginAs( userPage, user.name, PASSWORD ); + const res = await userPage.goto( + '/wp-admin/admin.php?page=beehiiv' + ); + expect( res.status() ).toBe( 403 ); + await expect( userPage.locator( 'body' ) ).toContainText( + /not allowed to access this page/i + ); + + // The menu offers no Settings entry to them either. + await userPage.goto( '/wp-admin/' ); + await expect( + userPage.locator( '#toplevel_page_beehiiv .wp-submenu a', { + hasText: 'Settings', + } ) + ).toHaveCount( 0 ); + await context.close(); + } + } ); +} ); diff --git a/tests/phpunit/NewsletterContentTypeTest.php b/tests/phpunit/NewsletterContentTypeTest.php new file mode 100644 index 0000000..9879cf6 --- /dev/null +++ b/tests/phpunit/NewsletterContentTypeTest.php @@ -0,0 +1,407 @@ + + */ + private $requests = array(); + + public function set_up(): void { + parent::set_up(); + + $this->requests = array(); + add_filter( 'pre_http_request', array( $this, 'fake_http' ), 10, 3 ); + + // The test case resets post types and meta between tests; register them as `init` does. + NewsletterPostType::register(); + PostSettings::register_meta(); + } + + public function tear_down(): void { + remove_filter( 'pre_http_request', array( $this, 'fake_http' ), 10 ); + Cache::flush_all(); + parent::tear_down(); + } + + /** + * Record requests and answer like beehiiv. + * + * @param false|array $preempt Short-circuit value. + * @param array $args Request args. + * @param string $url Request URL. + * @return array + */ + public function fake_http( $preempt, $args, $url ) { + $method = isset( $args['method'] ) ? strtoupper( $args['method'] ) : 'GET'; + $body = isset( $args['body'] ) && is_string( $args['body'] ) ? json_decode( $args['body'], true ) : array(); + + $this->requests[] = array( + 'method' => $method, + 'url' => $url, + 'body' => is_array( $body ) ? $body : array(), + ); + + $code = 'DELETE' === $method ? 204 : 200; + $data = 'POST' === $method ? array( 'data' => array( 'id' => 'post_new' ) ) : array( 'data' => array() ); + + return array( + 'headers' => array(), + 'body' => wp_json_encode( $data ), + 'response' => array( + 'code' => $code, + 'message' => '', + ), + 'cookies' => array(), + 'filename' => null, + ); + } + + /** + * Connect and configure a publication so sending can run. + */ + private function connect(): void { + TokenStore::save_tokens( + 'client_test', + array( + 'access_token' => 'access_test', + 'refresh_token' => 'refresh_test', + 'expires_in' => DAY_IN_SECONDS, + ) + ); + update_option( + Config::OPTION_NAME, + array( + 'publication_id' => 'pub_default', + 'post_template_id' => 'tpl_default', + ) + ); + Cache::set_publications( array( array( 'id' => 'pub_default', 'name' => 'Default' ) ) ); + Cache::set_post_templates( 'pub_default', array( array( 'id' => 'tpl_default', 'name' => 'Default' ) ) ); + } + + /** + * Create a newsletter. + * + * @param array $args Post args. + * @return int + */ + private function create_newsletter( array $args = array() ): int { + return self::factory()->post->create( + array_merge( + array( + 'post_type' => ContentTypes::NEWSLETTER, + 'post_status' => 'publish', + 'post_title' => 'Campaign', + ), + $args + ) + ); + } + + public function test_supported_content_types_are_shared_and_exact(): void { + $this->assertSame( array( 'post', 'beehiiv_newsletter' ), ContentTypes::supported() ); + $this->assertTrue( ContentTypes::is_supported( 'post' ) ); + $this->assertTrue( ContentTypes::is_supported( 'beehiiv_newsletter' ) ); + $this->assertFalse( ContentTypes::is_supported( 'page' ) ); + $this->assertFalse( ContentTypes::is_supported( null ) ); + $this->assertTrue( ContentTypes::send_default( 'beehiiv_newsletter' ) ); + $this->assertFalse( ContentTypes::send_default( 'post' ) ); + } + + /** + * AC-004: no public page, search, sitemap, nav menu or rewrite. + */ + public function test_post_type_is_non_public(): void { + $type = get_post_type_object( ContentTypes::NEWSLETTER ); + + $this->assertNotNull( $type ); + $this->assertFalse( $type->public ); + $this->assertFalse( $type->publicly_queryable ); + $this->assertTrue( $type->exclude_from_search ); + $this->assertFalse( $type->show_in_nav_menus ); + $this->assertFalse( $type->rewrite ); + $this->assertFalse( $type->query_var ); + $this->assertTrue( $type->show_ui ); + $this->assertTrue( $type->show_in_rest ); + $this->assertSame( Config::PLUGIN_SLUG, $type->show_in_menu ); + $this->assertTrue( post_type_supports( ContentTypes::NEWSLETTER, 'custom-fields' ) ); + $this->assertFalse( is_post_type_viewable( $type ) ); + $this->assertArrayNotHasKey( ContentTypes::NEWSLETTER, get_post_types( array( 'public' => true ) ) ); + + $post_id = $this->create_newsletter(); + $this->assertFalse( is_post_publicly_viewable( $post_id ) ); + } + + /** + * Meta is registered for both types with the per-type "Send to newsletter" default. + */ + public function test_send_to_newsletter_defaults_on_for_newsletters_only(): void { + $newsletter_id = $this->create_newsletter( array( 'post_status' => 'draft' ) ); + $post_id = self::factory()->post->create( array( 'post_status' => 'draft' ) ); + + $this->assertTrue( rest_sanitize_boolean( get_post_meta( $newsletter_id, Meta::SEND_TO_NEWSLETTER, true ) ) ); + $this->assertFalse( rest_sanitize_boolean( get_post_meta( $post_id, Meta::SEND_TO_NEWSLETTER, true ) ) ); + + // The editor reads the same default through the REST schema. + $schema = get_registered_meta_keys( 'post', ContentTypes::NEWSLETTER )[ Meta::SEND_TO_NEWSLETTER ]; + $this->assertTrue( $schema['default'] ); + $this->assertFalse( get_registered_meta_keys( 'post', 'post' )[ Meta::SEND_TO_NEWSLETTER ]['default'] ); + + // A saved "off" stays off. + update_post_meta( $newsletter_id, Meta::SEND_TO_NEWSLETTER, false ); + $this->assertFalse( rest_sanitize_boolean( get_post_meta( $newsletter_id, Meta::SEND_TO_NEWSLETTER, true ) ) ); + } + + /** + * AC-008 / status mapping from local meta only. + */ + public function test_status_mapping_uses_local_meta_only(): void { + $id = $this->create_newsletter(); + $this->assertSame( 'not_sent', NewsletterPostType::get_status( $id ) ); + $this->assertSame( 'Not sent', NewsletterPostType::status_label( 'not_sent' ) ); + + update_post_meta( $id, Meta::BEEHIIV_POST_ID, 'post_1' ); + $this->assertSame( 'sent', NewsletterPostType::get_status( $id ), 'Linked with an empty send time counts as sent.' ); + + update_post_meta( $id, Meta::BEEHIIV_SCHEDULED_AT, gmdate( 'Y-m-d\TH:i:s\Z', time() + DAY_IN_SECONDS ) ); + $this->assertSame( 'scheduled', NewsletterPostType::get_status( $id ) ); + + update_post_meta( $id, Meta::BEEHIIV_SCHEDULED_AT, gmdate( 'Y-m-d\TH:i:s\Z', time() - HOUR_IN_SECONDS ) ); + $this->assertSame( 'sent', NewsletterPostType::get_status( $id ) ); + + update_post_meta( $id, Meta::NEWSLETTER_ERROR, 'Send failed.' ); + $this->assertSame( 'failed', NewsletterPostType::get_status( $id ), 'A non-empty error wins.' ); + + update_post_meta( $id, Meta::NEWSLETTER_ERROR, '' ); + $this->assertSame( 'sent', NewsletterPostType::get_status( $id ) ); + + $this->assertSame( array(), $this->requests, 'Status must not call beehiiv.' ); + } + + public function test_list_columns_are_title_status_author_date(): void { + $columns = apply_filters( 'manage_beehiiv_newsletter_posts_columns', array( 'cb' => 'x', 'title' => 'Title' ) ); + + $this->assertSame( array( 'cb', 'title', 'beehiiv_status', 'author', 'date' ), array_keys( $columns ) ); + + $id = $this->create_newsletter(); + update_post_meta( $id, Meta::NEWSLETTER_ERROR, 'Boom' ); + ob_start(); + do_action( 'manage_beehiiv_newsletter_posts_custom_column', 'beehiiv_status', $id ); + $this->assertSame( 'Failed', ob_get_clean() ); + } + + /** + * R-003: read-only send fields cannot be written on the newsletter REST route. + */ + public function test_rest_save_drops_readonly_meta_on_newsletters(): void { + $author_id = self::factory()->user->create( array( 'role' => 'author' ) ); + $id = $this->create_newsletter( array( 'post_author' => $author_id, 'post_status' => 'draft' ) ); + + update_post_meta( $id, Meta::BEEHIIV_POST_ID, 'post_linked' ); + wp_set_current_user( $author_id ); + do_action( 'rest_api_init' ); + + $request = new WP_REST_Request( 'POST', '/wp/v2/beehiiv-newsletters/' . $id ); + $request->set_header( 'content-type', 'application/json' ); + $request->set_body( + wp_json_encode( + array( + 'meta' => array( + Meta::BEEHIIV_POST_ID => 'hijacked', + Meta::BEEHIIV_SCHEDULED_AT => '2030-01-01T00:00:00Z', + Meta::NEWSLETTER_TITLE => 'Subject', + ), + ) + ) + ); + + $response = rest_get_server()->dispatch( $request ); + + $this->assertSame( 200, $response->get_status() ); + $this->assertSame( 'post_linked', get_post_meta( $id, Meta::BEEHIIV_POST_ID, true ) ); + $this->assertSame( '', get_post_meta( $id, Meta::BEEHIIV_SCHEDULED_AT, true ) ); + $this->assertSame( 'Subject', get_post_meta( $id, Meta::NEWSLETTER_TITLE, true ) ); + $this->assertSame( 'post_linked', $response->get_data()['meta'][ Meta::BEEHIIV_POST_ID ] ); + } + + public function test_route_pattern_covers_both_types(): void { + $pattern = ContentTypes::rest_route_pattern(); + + foreach ( array( '/wp/v2/posts', '/wp/v2/posts/5', '/wp/v2/beehiiv-newsletters', '/wp/v2/beehiiv-newsletters/5/autosaves' ) as $route ) { + $this->assertSame( 1, preg_match( $pattern, $route ), $route ); + } + $this->assertSame( 0, preg_match( $pattern, '/wp/v2/pages/5' ) ); + } + + /** + * Anonymous REST reads of a published newsletter are blocked. + */ + public function test_anonymous_rest_reads_are_blocked(): void { + $id = $this->create_newsletter(); + wp_set_current_user( 0 ); + do_action( 'rest_api_init' ); + + $single = rest_get_server()->dispatch( new WP_REST_Request( 'GET', '/wp/v2/beehiiv-newsletters/' . $id ) ); + $list = rest_get_server()->dispatch( new WP_REST_Request( 'GET', '/wp/v2/beehiiv-newsletters' ) ); + + $this->assertContains( $single->get_status(), array( 401, 403 ) ); + $this->assertContains( $list->get_status(), array( 401, 403 ) ); + + $author_id = self::factory()->user->create( array( 'role' => 'author' ) ); + $own = $this->create_newsletter( array( 'post_author' => $author_id ) ); + wp_set_current_user( $author_id ); + $this->assertSame( 200, rest_get_server()->dispatch( new WP_REST_Request( 'GET', '/wp/v2/beehiiv-newsletters/' . $own ) )->get_status() ); + } + + /** + * Public query surfaces: core sitemap provider list and the main query exclude newsletters. + */ + public function test_newsletters_are_absent_from_sitemaps_and_search(): void { + $id = $this->create_newsletter( array( 'post_title' => 'Zebrafish campaign' ) ); + + $this->assertArrayNotHasKey( ContentTypes::NEWSLETTER, wp_get_sitemap_providers()['posts']->get_object_subtypes() ); + + $query = new WP_Query( array( 's' => 'Zebrafish', 'post_type' => 'any' ) ); + $this->assertSame( array(), wp_list_pluck( $query->posts, 'ID' ) ); + $this->assertNotContains( $id, wp_list_pluck( get_posts( array( 'post_type' => 'any' ) ), 'ID' ) ); + } + + /** + * AC-007: sending creates one beehiiv post carrying the content in order. + */ + public function test_sending_a_newsletter_creates_one_beehiiv_post_in_order(): void { + $this->connect(); + + $content = "\n

Intro paragraph.

\n\n\n" + . "\n

Middle heading

\n\n\n" + . "\n

Closing paragraph.

\n"; + + $id = $this->create_newsletter( + array( + 'post_status' => 'draft', + 'post_content' => $content, + ) + ); + $this->requests = array(); + + wp_update_post( array( 'ID' => $id, 'post_status' => 'publish' ) ); + + $creates = array_values( + array_filter( + $this->requests, + static fn( $r ) => 'POST' === $r['method'] && false !== strpos( $r['url'], '/posts' ) + ) + ); + + $this->assertCount( 1, $creates, 'Exactly one beehiiv post is created (send is on by default).' ); + $this->assertSame( 'post_new', get_post_meta( $id, Meta::BEEHIIV_POST_ID, true ) ); + + $json = wp_json_encode( $creates[0]['body'] ); + $pos = array( + strpos( $json, 'Intro paragraph' ), + strpos( $json, 'Middle heading' ), + strpos( $json, 'Closing paragraph' ), + ); + $this->assertNotContains( false, $pos ); + $this->assertTrue( $pos[0] < $pos[1] && $pos[1] < $pos[2], 'Content keeps the written order.' ); + + // Sender::send() turns the toggle off after a send. + $this->assertFalse( rest_sanitize_boolean( get_post_meta( $id, Meta::SEND_TO_NEWSLETTER, true ) ) ); + } + + /** + * BR-001: a draft newsletter never sends. + */ + public function test_draft_newsletter_does_not_send(): void { + $this->connect(); + $this->create_newsletter( array( 'post_status' => 'draft', 'post_content' => 'Hello' ) ); + + $this->assertSame( array(), $this->requests ); + } + + /** + * BR-002: unpublishing a linked newsletter cancels the beehiiv post and re-enables send. + */ + public function test_unpublishing_a_linked_newsletter_cancels_it(): void { + $this->connect(); + $id = $this->create_newsletter( array( 'post_content' => 'Hello' ) ); + update_post_meta( $id, Meta::BEEHIIV_POST_ID, 'post_linked' ); + update_post_meta( $id, Meta::BEEHIIV_LINKED_PUBLICATION_ID, 'pub_default' ); + update_post_meta( $id, Meta::SEND_TO_NEWSLETTER, false ); + $this->requests = array(); + + wp_update_post( array( 'ID' => $id, 'post_status' => 'draft' ) ); + + $deletes = array_filter( $this->requests, static fn( $r ) => 'DELETE' === $r['method'] ); + $this->assertCount( 1, $deletes ); + $this->assertFalse( Sender::has_beehiiv_post_id( $id ) ); + $this->assertTrue( rest_sanitize_boolean( get_post_meta( $id, Meta::SEND_TO_NEWSLETTER, true ) ) ); + } + + /** + * Snippet mode never applies to newsletters (no public post to link to). + */ + public function test_snippet_meta_is_ignored_for_newsletters(): void { + $id = $this->create_newsletter( + array( 'post_content' => "\n

Before

\n\n\n\n\n\n

After

\n" ) + ); + update_post_meta( $id, Meta::SEND_TO_NEWSLETTER_SNIPPET, true ); + + $json = wp_json_encode( \Beehiiv\Newsletter\BlockConverter::convert_supported_blocks( get_post( $id ) ) ); + $this->assertStringContainsString( 'After', $json, 'Snippet mode would have stopped at the More block.' ); + } + + /** + * Test Email Send applies to newsletters via the shared list. + */ + public function test_test_sender_accepts_newsletters_and_rejects_other_types(): void { + $draft = $this->create_newsletter( array( 'post_status' => 'draft', 'post_content' => 'Hello' ) ); + $page = self::factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'draft' ) ); + + $result = TestSender::check_eligibility( $draft ); + $this->assertTrue( + true === $result || 'beehiiv_test_send_post_not_found' !== $result->get_error_code(), + 'A newsletter must not be rejected as an unsupported type.' + ); + + $page_result = TestSender::check_eligibility( $page ); + $this->assertWPError( $page_result ); + $this->assertSame( 'beehiiv_test_send_post_not_found', $page_result->get_error_code() ); + } + + public function test_send_meta_authorization_matches_posts_for_newsletters(): void { + $contributor = self::factory()->user->create( array( 'role' => 'contributor' ) ); + $id = $this->create_newsletter( array( 'post_author' => $contributor, 'post_status' => 'draft' ) ); + wp_set_current_user( $contributor ); + + $this->assertFalse( PostSettings::authorize_meta( false, Meta::SEND_TO_NEWSLETTER, $id ) ); + $this->assertFalse( PostSettings::authorize_meta( false, Meta::BEEHIIV_POST_ID, $id ) ); + $this->assertTrue( PostSettings::authorize_meta( false, Meta::BEEHIIV_POST_TEMPLATE_ID, $id ) ); + } +} diff --git a/tests/phpunit/PostRoundupTest.php b/tests/phpunit/PostRoundupTest.php new file mode 100644 index 0000000..9d4460f --- /dev/null +++ b/tests/phpunit/PostRoundupTest.php @@ -0,0 +1,856 @@ + + */ + private $requests = array(); + + public function set_up(): void { + parent::set_up(); + + $this->requests = array(); + add_filter( 'pre_http_request', array( $this, 'fake_http' ), 10, 3 ); + + NewsletterPostType::register(); + PostSettings::register_meta(); + PostRoundup::init(); + + TokenStore::save_tokens( + 'client_test', + array( + 'access_token' => 'access_test', + 'refresh_token' => 'refresh_test', + 'expires_in' => DAY_IN_SECONDS, + ) + ); + update_option( + Config::OPTION_NAME, + array( + 'publication_id' => 'pub_default', + 'post_template_id' => 'tpl_default', + ) + ); + Cache::set_publications( array( array( 'id' => 'pub_default', 'name' => 'Default' ) ) ); + Cache::set_post_templates( 'pub_default', array( array( 'id' => 'tpl_default', 'name' => 'Default' ) ) ); + } + + public function tear_down(): void { + remove_filter( 'pre_http_request', array( $this, 'fake_http' ), 10 ); + remove_filter( 'allowed_block_types_all', array( PostRoundup::class, 'filter_allowed_blocks' ), 10 ); + Cache::flush_all(); + parent::tear_down(); + } + + /** + * Record requests and answer like beehiiv. + * + * @param false|array $preempt Short-circuit value. + * @param array $args Request args. + * @param string $url Request URL. + * @return array + */ + public function fake_http( $preempt, $args, $url ) { + $method = isset( $args['method'] ) ? strtoupper( $args['method'] ) : 'GET'; + $body = isset( $args['body'] ) && is_string( $args['body'] ) ? json_decode( $args['body'], true ) : array(); + + $this->requests[] = array( + 'method' => $method, + 'url' => $url, + 'body' => is_array( $body ) ? $body : array(), + ); + + $code = 'DELETE' === $method ? 204 : 200; + $data = 'POST' === $method ? array( 'data' => array( 'id' => 'post_new' ) ) : array( 'data' => array() ); + + return array( + 'headers' => array(), + 'body' => wp_json_encode( $data ), + 'response' => array( + 'code' => $code, + 'message' => '', + ), + 'cookies' => array(), + 'filename' => null, + ); + } + + /** + * Create a published regular post, dated so the order is predictable. + * + * @param string $title Title. + * @param int $age Hours old. + * @param array $args Extra args. + * @return int + */ + private function create_article( string $title, int $age = 1, array $args = array() ): int { + return self::factory()->post->create( + array_merge( + array( + 'post_title' => $title, + 'post_excerpt' => 'Excerpt of ' . $title, + 'post_status' => 'publish', + 'post_date' => gmdate( 'Y-m-d H:i:s', time() - $age * HOUR_IN_SECONDS ), + ), + $args + ) + ); + } + + /** + * Create a newsletter whose content is the given blocks. + * + * @param string $content Block markup. + * @param array $args Extra args. + * @return int + */ + private function create_newsletter( string $content, array $args = array() ): int { + return self::factory()->post->create( + array_merge( + array( + 'post_type' => ContentTypes::NEWSLETTER, + 'post_status' => 'publish', + 'post_title' => 'Campaign', + 'post_content' => $content, + ), + $args + ) + ); + } + + /** + * Block markup for a roundup. + * + * @param array $attrs Block attributes. + * @return string + */ + private function roundup( array $attrs = array() ): string { + return ''; + } + + /** + * Block markup for a paragraph. + * + * @param string $text Text. + * @return string + */ + private function paragraph( string $text ): string { + return "\n

" . $text . "

\n"; + } + + /** + * Converted blocks of a post. + * + * @param int $post_id Post ID. + * @return array + */ + private function convert( int $post_id ): array { + return BlockConverter::convert_supported_blocks( get_post( $post_id ) ); + } + + /** + * Titles of a list of posts, in the order given. + * + * @param int[] $ids Post IDs. + * @return string[] + */ + private function titles( array $ids ): array { + return array_map( + static function ( $id ) { + return get_the_title( $id ); + }, + $ids + ); + } + + /** + * Types of a list of beehiiv blocks. + * + * @param array $blocks Blocks. + * @return string[] + */ + private function types( array $blocks ): array { + return array_column( $blocks, 'type' ); + } + + /** + * Blocks of the last request that carried a `blocks` payload. + * + * @return array + */ + private function last_sent_blocks(): array { + foreach ( array_reverse( $this->requests ) as $request ) { + if ( isset( $request['body']['blocks'] ) ) { + return $request['body']['blocks']; + } + } + + return array(); + } + + /** + * Position of each needle in the JSON of the blocks (false when missing). + * + * @param array $blocks Blocks. + * @param string[] $needles Needles. + * @return array + */ + private function positions( array $blocks, array $needles ): array { + $json = wp_json_encode( $blocks ); + + return array_map( + static function ( $needle ) use ( $json ) { + return strpos( $json, $needle ); + }, + $needles + ); + } + + /** + * Attach a featured image to a post. + * + * @param int $post_id Post ID. + * @param string $file File name. + */ + private function add_featured_image( int $post_id, string $file ): void { + $attachment_id = self::factory()->attachment->create( + array( + 'post_mime_type' => 'image/jpeg', + 'post_parent' => $post_id, + 'file' => $file, + ) + ); + update_post_meta( $attachment_id, '_wp_attachment_image_alt', 'Alt of ' . $file ); + set_post_thumbnail( $post_id, $attachment_id ); + } + + /* ---------------------------------------------------------------- AC-002 resolver. */ + + /** + * BR-001: latest published regular posts, newest first, any category. + */ + public function test_latest_posts_are_newest_first_from_any_category_and_limited_by_count(): void { + $category = self::factory()->category->create(); + $old = $this->create_article( 'Old', 30 ); + $new = $this->create_article( 'New', 2, array( 'post_category' => array( $category ) ) ); + $mid = $this->create_article( 'Mid', 10 ); + + $this->assertSame( array( $new, $mid, $old ), PostRoundup::latest_ids( 3, 0 ) ); + $this->assertSame( array( $new, $mid ), PostRoundup::latest_ids( 2, 0 ) ); + } + + /** + * BR-001: drafts, private, scheduled, password-protected posts, pages and newsletters never appear. + */ + public function test_latest_posts_exclude_unpublished_protected_and_other_types(): void { + $visible = $this->create_article( 'Visible', 5 ); + $this->create_article( 'Draft', 1, array( 'post_status' => 'draft' ) ); + $this->create_article( 'Private', 1, array( 'post_status' => 'private' ) ); + $this->create_article( 'Protected', 1, array( 'post_password' => 'secret' ) ); + $this->create_article( 'Page', 1, array( 'post_type' => 'page' ) ); + $this->create_newsletter( '', array( 'post_title' => 'Other newsletter' ) ); + + $this->assertSame( array( $visible ), PostRoundup::latest_ids( 10, 0 ) ); + } + + /** + * BR-001: never lists the newsletter itself. + */ + public function test_latest_posts_exclude_the_post_being_sent(): void { + $article = $this->create_article( 'Article', 5 ); + $self = $this->create_article( 'Self', 1 ); + + $this->assertSame( array( $article ), PostRoundup::latest_ids( 5, $self ) ); + } + + /** + * The count control accepts 1 to 10 and falls back to 3. + */ + public function test_count_is_clamped_to_one_to_ten_with_default_three(): void { + $this->assertSame( 1, PostRoundup::clamp_count( 0 ) ); + $this->assertSame( 1, PostRoundup::clamp_count( -4 ) ); + $this->assertSame( 7, PostRoundup::clamp_count( '7' ) ); + $this->assertSame( 10, PostRoundup::clamp_count( 99 ) ); + $this->assertSame( 3, PostRoundup::clamp_count( 'many' ) ); + $this->assertSame( 3, PostRoundup::clamp_count( null ) ); + + for ( $i = 0; $i < 12; $i++ ) { + $this->create_article( 'A' . $i, $i + 1 ); + } + + $this->assertCount( 10, PostRoundup::latest_ids( 99, 0 ) ); + } + + /** + * BR-002 and the silent-skip choice: picks keep their order and unavailable ones drop out. + */ + public function test_manual_picks_keep_order_and_skip_unavailable_posts(): void { + $first = $this->create_article( 'First', 9 ); + $second = $this->create_article( 'Second', 8 ); + $draft = $this->create_article( 'Draft', 7, array( 'post_status' => 'draft' ) ); + $trashed = $this->create_article( 'Trashed', 6 ); + wp_trash_post( $trashed ); + $deleted = $this->create_article( 'Deleted', 5 ); + wp_delete_post( $deleted, true ); + $locked = $this->create_article( 'Locked', 4, array( 'post_password' => 'pw' ) ); + $page = $this->create_article( 'Page', 3, array( 'post_type' => 'page' ) ); + $self = $this->create_article( 'Self', 2 ); + + $attrs = array( + 'mode' => 'manual', + 'posts' => array( + array( 'id' => $second ), + array( 'id' => $draft ), + array( 'id' => $trashed ), + array( 'id' => $deleted ), + array( 'id' => $locked ), + array( 'id' => $page ), + array( 'id' => $self ), + array( 'id' => $first ), + array( 'id' => $second ), + array( 'id' => 'junk' ), + ), + ); + + $this->assertSame( + array( $second, $first ), + PostRoundup::resolve_ids( $attrs, $self, 'k' ) + ); + } + + /** + * Mode defaults to automatic; only "manual" switches it. + */ + public function test_mode_defaults_to_automatic(): void { + $this->assertSame( 'auto', PostRoundup::mode( array() ) ); + $this->assertSame( 'auto', PostRoundup::mode( array( 'mode' => 'nonsense' ) ) ); + $this->assertSame( 'manual', PostRoundup::mode( array( 'mode' => 'manual' ) ) ); + } + + /* ------------------------------------------------------- AC-004 editor preview REST. */ + + /** + * The preview route returns cards from the shared resolver and needs edit access. + */ + public function test_preview_route_uses_the_shared_resolver_and_requires_edit_capability(): void { + do_action( 'rest_api_init' ); + PostRoundupController::register_routes(); + + $newest = $this->create_article( 'Newest', 1 ); + $older = $this->create_article( 'Older', 3 ); + $post_id = $this->create_newsletter( $this->roundup() ); + $author = self::factory()->user->create( array( 'role' => 'subscriber' ) ); + $admin = self::factory()->user->create( array( 'role' => 'administrator' ) ); + $expected = PostRoundup::cards( array( $newest, $older ) ); + + $request = new WP_REST_Request( 'GET', '/beehiiv/v1/post-roundup' ); + $request->set_query_params( + array( + 'post_id' => $post_id, + 'mode' => 'auto', + 'count' => 2, + ) + ); + + wp_set_current_user( $author ); + $this->assertSame( 403, rest_do_request( $request )->get_status() ); + + wp_set_current_user( 0 ); + $this->assertSame( 401, rest_do_request( $request )->get_status() ); + + wp_set_current_user( $admin ); + $response = rest_do_request( $request ); + $this->assertSame( 200, $response->get_status() ); + $this->assertSame( $expected, $response->get_data() ); + $this->assertSame( 'Newest', $response->get_data()[0]['title'] ); + $this->assertSame( get_permalink( $newest ), $response->get_data()[0]['url'] ); + $this->assertSame( 'Excerpt of Newest', $response->get_data()[0]['excerpt'] ); + + $manual = new WP_REST_Request( 'GET', '/beehiiv/v1/post-roundup' ); + $manual->set_query_params( + array( + 'post_id' => $post_id, + 'mode' => 'manual', + 'ids' => array( $older, $newest ), + ) + ); + $this->assertSame( array( $older, $newest ), array_column( rest_do_request( $manual )->get_data(), 'id' ) ); + + // Out-of-range counts are clamped, not rejected. + $request->set_query_params( + array( + 'post_id' => $post_id, + 'count' => 500, + ) + ); + $this->assertSame( 200, rest_do_request( $request )->get_status() ); + } + + /* ---------------------------------------------------------- AC-001 newsletter-only. */ + + /** + * The block is offered in newsletters and removed everywhere else. + */ + public function test_block_is_allowed_only_when_writing_a_newsletter(): void { + $newsletter = get_post( $this->create_newsletter( '' ) ); + $article = get_post( self::factory()->post->create() ); + $all = array( 'core/paragraph', PostRoundup::BLOCK ); + + $this->assertSame( $all, PostRoundup::filter_allowed_blocks( $all, new WP_Block_Editor_Context( array( 'post' => $newsletter ) ) ) ); + $this->assertTrue( PostRoundup::filter_allowed_blocks( true, new WP_Block_Editor_Context( array( 'post' => $newsletter ) ) ) ); + + $in_post = PostRoundup::filter_allowed_blocks( $all, new WP_Block_Editor_Context( array( 'post' => $article ) ) ); + $this->assertSame( array( 'core/paragraph' ), $in_post ); + + $everything = PostRoundup::filter_allowed_blocks( true, new WP_Block_Editor_Context( array( 'post' => $article ) ) ); + $this->assertIsArray( $everything ); + $this->assertNotContains( PostRoundup::BLOCK, $everything ); + + $no_post = PostRoundup::filter_allowed_blocks( $all, new WP_Block_Editor_Context( array( 'name' => 'core/edit-widgets' ) ) ); + $this->assertNotContains( PostRoundup::BLOCK, $no_post ); + + // Wired through the real filter. + $filtered = apply_filters( 'allowed_block_types_all', $all, new WP_Block_Editor_Context( array( 'post' => $article ) ) ); + $this->assertNotContains( PostRoundup::BLOCK, $filtered ); + } + + /** + * A roundup left in a regular post is ignored by the converter. + */ + public function test_roundup_in_a_regular_post_is_ignored(): void { + $this->create_article( 'Listed', 3 ); + $post_id = self::factory()->post->create( + array( + 'post_status' => 'publish', + 'post_content' => $this->paragraph( 'Intro' ) . $this->roundup() . $this->paragraph( 'Outro' ), + ) + ); + + $blocks = $this->convert( $post_id ); + + $this->assertSame( array( 'paragraph', 'paragraph' ), $this->types( $blocks ) ); + $this->assertStringNotContainsString( 'Listed', wp_json_encode( $blocks ) ); + } + + /** + * The editor warning and the converter agree: the block is on the supported list. + */ + public function test_block_is_in_the_supported_blocks_list(): void { + $this->assertContains( PostRoundup::BLOCK, SupportedBlocks::BLOCKS ); + $this->assertContains( PostRoundup::BLOCK, SupportedBlocks::get_editor_config()['supported'] ); + $this->assertTrue( SupportedBlocks::is_supported( PostRoundup::BLOCK, false ) ); + } + + /* ------------------------------------------------------------ AC-005 expansion. */ + + /** + * Per post: image, bold linked title, excerpt, Read more; a separator between cards; order kept. + */ + public function test_roundup_expands_into_cards_in_order(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $two = $this->create_article( 'Beta story', 2 ); + $this->add_featured_image( $one, 'alpha.jpg' ); + + $newsletter = $this->create_newsletter( $this->roundup( array( 'count' => 2 ) ) ); + $blocks = $this->convert( $newsletter ); + + $this->assertSame( + array( 'image', 'paragraph', 'paragraph', 'button', 'content_break', 'paragraph', 'paragraph', 'button' ), + $this->types( $blocks ) + ); + + // Image with the featured image and a link to the post. + $this->assertStringContainsString( 'alpha.jpg', $blocks[0]['imageUrl'] ); + $this->assertSame( 'Alt of alpha.jpg', $blocks[0]['alt_text'] ); + $this->assertSame( get_permalink( $one ), $blocks[0]['url'] ); + + // Title is a bold paragraph carrying the link. + $title = wp_json_encode( $blocks[1] ); + $this->assertStringContainsString( 'Alpha story', $title ); + $this->assertSame( array( 'bold' ), $blocks[1]['formattedText'][0]['styling'] ); + $this->assertSame( get_permalink( $one ), $blocks[1]['formattedText'][0]['link']['href'] ); + $this->assertArrayNotHasKey( 'level', $blocks[1] ); + + // Excerpt and Read more. + $this->assertSame( 'Excerpt of Alpha story', $blocks[2]['plaintext'] ); + $this->assertSame( 'button', $blocks[3]['type'] ); + $this->assertSame( 'Read more', $blocks[3]['text'] ); + $this->assertSame( get_permalink( $one ), $blocks[3]['href'] ); + + // Second card follows, with no image of its own. + $this->assertSame( 'Excerpt of Beta story', $blocks[6]['plaintext'] ); + $this->assertSame( get_permalink( $two ), $blocks[7]['href'] ); + } + + /** + * Manual picks are sent in the order the author chose. + */ + public function test_manual_roundup_is_sent_in_the_picked_order(): void { + $a = $this->create_article( 'Story A', 1 ); + $b = $this->create_article( 'Story B', 2 ); + $c = $this->create_article( 'Story C', 3 ); + + $newsletter = $this->create_newsletter( + $this->roundup( + array( + 'mode' => 'manual', + 'posts' => array( + array( 'id' => $c ), + array( 'id' => $a ), + array( 'id' => $b ), + ), + ) + ) + ); + + $positions = $this->positions( $this->convert( $newsletter ), array( 'Story C', 'Story A', 'Story B' ) ); + + $this->assertNotContains( false, $positions ); + $sorted = $positions; + sort( $sorted ); + $this->assertSame( $sorted, $positions ); + } + + /** + * A post without a featured image still shows its text. + */ + public function test_post_without_featured_image_has_no_image_block(): void { + $this->create_article( 'Plain', 1 ); + $blocks = $this->convert( $this->create_newsletter( $this->roundup( array( 'count' => 1 ) ) ) ); + + $this->assertSame( array( 'paragraph', 'paragraph', 'button' ), $this->types( $blocks ) ); + } + + /** + * The card image uses an existing registered image size. + */ + public function test_card_image_size_is_a_registered_size(): void { + $this->assertContains( PostRoundup::IMAGE_SIZE, get_intermediate_image_sizes() ); + } + + /** + * A roundup keeps its place between other blocks. + */ + public function test_roundup_keeps_its_position_between_other_content(): void { + $this->create_article( 'Middle story', 1 ); + $blocks = $this->convert( + $this->create_newsletter( + $this->paragraph( 'Intro text' ) . $this->roundup( array( 'count' => 1 ) ) . $this->paragraph( 'Outro text' ) + ) + ); + + $this->assertSame( array( 'paragraph', 'paragraph', 'paragraph', 'button', 'paragraph' ), $this->types( $blocks ) ); + $positions = $this->positions( $blocks, array( 'Intro text', 'Middle story', 'Outro text' ) ); + $this->assertSame( $positions, array_values( array_unique( $positions ) ) ); + $sorted = $positions; + sort( $sorted ); + $this->assertSame( $sorted, $positions ); + } + + /** + * Two roundups in one newsletter both expand. + */ + public function test_more_than_one_roundup_is_allowed(): void { + $this->create_article( 'Only story', 1 ); + $blocks = $this->convert( + $this->create_newsletter( $this->roundup( array( 'count' => 1 ) ) . $this->roundup( array( 'count' => 1 ) ) ) + ); + + $this->assertSame( 2, count( array_filter( $this->types( $blocks ), static fn( $t ) => 'button' === $t ) ) ); + } + + /** + * Unavailable picks are skipped and the rest are sent. + */ + public function test_unavailable_manual_pick_is_skipped_at_send(): void { + $kept = $this->create_article( 'Kept', 1 ); + $draft = $this->create_article( 'Gone', 2, array( 'post_status' => 'draft' ) ); + + $blocks = $this->convert( + $this->create_newsletter( + $this->roundup( + array( + 'mode' => 'manual', + 'posts' => array( array( 'id' => $draft ), array( 'id' => $kept ) ), + ) + ) + ) + ); + + $this->assertSame( array( 'paragraph', 'paragraph', 'button' ), $this->types( $blocks ) ); + $this->assertStringNotContainsString( 'Gone', wp_json_encode( $blocks ) ); + } + + /** + * A roundup with no posts alone in a newsletter gives the existing "no content" error. + */ + public function test_empty_roundup_alone_triggers_the_no_content_error(): void { + $newsletter = $this->create_newsletter( $this->roundup() ); + + $result = PostSettingsBuilder::get_post_settings( $newsletter, false, 'pub_default' ); + + $this->assertWPError( $result ); + $this->assertSame( 'beehiiv_blocks_empty', $result->get_error_code() ); + } + + /** + * A roundup with no posts between other content is skipped. + */ + public function test_empty_roundup_between_content_is_skipped(): void { + $newsletter = $this->create_newsletter( + $this->paragraph( 'Intro text' ) . $this->roundup( array( 'mode' => 'manual' ) ) . $this->paragraph( 'Outro text' ) + ); + + $this->assertSame( array( 'paragraph', 'paragraph' ), $this->types( $this->convert( $newsletter ) ) ); + + $settings = PostSettingsBuilder::get_post_settings( $newsletter, false, 'pub_default' ); + $this->assertIsArray( $settings ); + $this->assertCount( 2, $settings['blocks'] ); + } + + /** + * In snippet mode a roundup after the first More block is left out; newsletters never use snippet mode. + */ + public function test_roundup_after_more_block_is_left_out_in_snippet_mode(): void { + $this->create_article( 'Listed', 1 ); + $content = $this->paragraph( 'Intro' ) . "\n\n" . $this->roundup( array( 'count' => 1 ) ); + + // A newsletter ignores snippet mode, so the roundup after More is still sent. + $newsletter = $this->create_newsletter( $content ); + update_post_meta( $newsletter, Meta::SEND_TO_NEWSLETTER_SNIPPET, true ); + $this->assertStringContainsString( 'Listed', wp_json_encode( $this->convert( $newsletter ) ) ); + + // Existing snippet behavior on a regular post stops at More. + $post_id = self::factory()->post->create( + array( + 'post_status' => 'publish', + 'post_content' => $content, + ) + ); + update_post_meta( $post_id, Meta::SEND_TO_NEWSLETTER_SNIPPET, true ); + $this->assertStringNotContainsString( 'Listed', wp_json_encode( $this->convert( $post_id ) ) ); + } + + /* ------------------------------------------------------------ AC-006 freeze. */ + + /** + * Sending freezes the list, and every later sync reads it instead of re-querying. + */ + public function test_send_freezes_the_list_for_every_later_sync(): void { + $old = $this->create_article( 'Frozen one', 3 ); + $mid = $this->create_article( 'Frozen two', 2 ); + $new = $this->create_article( 'Frozen three', 1 ); + + $newsletter = $this->create_newsletter( $this->roundup( array( 'uid' => 'abc', 'count' => 2 ) ) ); + + // Before sending: live, nothing stored. + $this->assertSame( '', get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true ) ); + + Sender::send( $newsletter ); + + $this->assertSame( 'post_new', get_post_meta( $newsletter, Meta::BEEHIIV_POST_ID, true ) ); + $sent = $this->last_sent_blocks(); + $this->assertStringContainsString( 'Frozen three', wp_json_encode( $sent ) ); + $this->assertStringContainsString( 'Frozen two', wp_json_encode( $sent ) ); + $this->assertStringNotContainsString( 'Frozen one', wp_json_encode( $sent ) ); + $this->assertSame( array( $new, $mid ), get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true )['abc']['ids'] ); + + // A newer post is published afterwards. + $newest = $this->create_article( 'Frozen newest', 0 ); + $this->assertSame( array( $newest, $new ), PostRoundup::latest_ids( 2, $newsletter ) ); + + // Save / update path. + $this->requests = array(); + Sender::maybe_update_post_newsletter( get_post( $newsletter ) ); + $blocks = $this->last_sent_blocks(); + $this->assertNotEmpty( $blocks ); + $this->assertStringContainsString( 'Frozen two', wp_json_encode( $blocks ) ); + $this->assertStringNotContainsString( 'Frozen newest', wp_json_encode( $blocks ) ); + + // Scheduled release. + update_post_meta( $newsletter, Meta::BEEHIIV_SCHEDULED_AT, gmdate( 'Y-m-d\TH:i:s\Z', time() + DAY_IN_SECONDS ) ); + $this->requests = array(); + Sender::on_future_to_publish( get_post( $newsletter ) ); + $released = wp_json_encode( $this->last_sent_blocks() ); + $this->assertStringContainsString( 'Frozen two', $released ); + $this->assertStringNotContainsString( 'Frozen newest', $released ); + + // Update payload and test email draft build. + $update = PostSettingsBuilder::build_update( $newsletter ); + $this->assertStringNotContainsString( 'Frozen newest', wp_json_encode( $update['payload']['blocks'] ) ); + $draft = TestSender::build_temporary_draft_payload( $newsletter, 'pub_default' ); + $this->assertStringNotContainsString( 'Frozen newest', wp_json_encode( $draft['blocks'] ) ); + $this->assertStringContainsString( 'Frozen three', wp_json_encode( $draft['blocks'] ) ); + + // The editor preview shows the frozen list too. + $this->assertSame( + array( $new, $mid ), + PostRoundup::resolve_ids( array( 'count' => 2 ), $newsletter, 'abc' ) + ); + $this->assertNotContains( $old, get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true )['abc']['ids'] ); + } + + /** + * Before sending, saves and test emails show live results. + */ + public function test_before_send_the_list_is_live(): void { + $this->create_article( 'First', 2 ); + $newsletter = $this->create_newsletter( $this->roundup( array( 'uid' => 'abc', 'count' => 1 ) ), array( 'post_status' => 'draft' ) ); + + $this->assertStringContainsString( 'First', wp_json_encode( $this->convert( $newsletter ) ) ); + + $this->create_article( 'Fresher', 0 ); + $draft = TestSender::build_temporary_draft_payload( $newsletter, 'pub_default' ); + $this->assertStringContainsString( 'Fresher', wp_json_encode( $draft['blocks'] ) ); + $this->assertSame( '', get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true ) ); + } + + /** + * Changing the count after sending freezes that roundup again; unchanged ones stay frozen. + */ + public function test_changed_count_refreezes_while_unchanged_roundups_stay_frozen(): void { + $this->create_article( 'Story 1', 1 ); + $this->create_article( 'Story 2', 2 ); + + $newsletter = $this->create_newsletter( + $this->roundup( array( 'uid' => 'one', 'count' => 1 ) ) . $this->roundup( array( 'uid' => 'two', 'count' => 2 ) ) + ); + PostRoundupSnapshot::freeze( get_post( $newsletter ) ); + $stored = get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true ); + + $this->create_article( 'Story 0', 0 ); + + wp_update_post( + array( + 'ID' => $newsletter, + 'post_content' => $this->roundup( array( 'uid' => 'one', 'count' => 1 ) ) . $this->roundup( array( 'uid' => 'two', 'count' => 3 ) ), + ) + ); + PostRoundupSnapshot::freeze( get_post( $newsletter ) ); + $after = get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true ); + + $this->assertSame( $stored['one'], $after['one'], 'Unchanged roundup keeps its frozen list.' ); + $this->assertCount( 3, $after['two']['ids'], 'Changed count freezes again.' ); + } + + /** + * Manual roundups are not frozen; they are fixed by the author's picks. No roundup clears the snapshot. + */ + public function test_snapshot_skips_manual_roundups_and_clears_when_none_remain(): void { + $article = $this->create_article( 'Story', 1 ); + $content = $this->roundup( array( 'mode' => 'manual', 'posts' => array( array( 'id' => $article ) ) ) ); + + $newsletter = $this->create_newsletter( $content ); + PostRoundupSnapshot::freeze( get_post( $newsletter ) ); + $this->assertSame( '', get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true ) ); + + update_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, array( 'x' => array( 'count' => 1, 'ids' => array( 1 ) ) ) ); + PostRoundupSnapshot::freeze( get_post( $newsletter ) ); + $this->assertSame( '', get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true ) ); + } + + /** + * A frozen post that later becomes unavailable is skipped silently. + */ + public function test_frozen_post_that_becomes_unavailable_is_skipped(): void { + $keep = $this->create_article( 'Stays', 1 ); + $gone = $this->create_article( 'Leaves', 2 ); + + $newsletter = $this->create_newsletter( $this->roundup( array( 'uid' => 'abc', 'count' => 2 ) ) ); + PostRoundupSnapshot::freeze( get_post( $newsletter ) ); + wp_trash_post( $gone ); + + $this->assertSame( array( $keep ), PostRoundup::resolve_ids( array( 'count' => 2 ), $newsletter, 'abc' ) ); + } + + /** + * A failed first send forgets the freeze, so the retry freezes the current list. + */ + public function test_failed_send_does_not_keep_the_freeze(): void { + $this->create_article( 'Story', 1 ); + $newsletter = $this->create_newsletter( $this->roundup( array( 'uid' => 'abc', 'count' => 1 ) ) ); + + add_filter( + 'pre_http_request', + static function ( $preempt, $args ) { + if ( 'POST' === ( $args['method'] ?? '' ) ) { + return array( + 'headers' => array(), + 'body' => wp_json_encode( array( 'message' => 'nope' ) ), + 'response' => array( + 'code' => 500, + 'message' => '', + ), + 'cookies' => array(), + 'filename' => null, + ); + } + + return $preempt; + }, + 20, + 2 + ); + + Sender::send( $newsletter ); + + $this->assertSame( '', get_post_meta( $newsletter, Meta::BEEHIIV_POST_ID, true ) ); + $this->assertSame( '', get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true ) ); + } + + /** + * Cancelling a scheduled newsletter forgets the freeze so it freezes again when re-sent. + */ + public function test_cancelling_a_scheduled_newsletter_clears_the_freeze(): void { + $this->create_article( 'Story', 1 ); + $newsletter = $this->create_newsletter( $this->roundup( array( 'uid' => 'abc', 'count' => 1 ) ) ); + + Sender::send( $newsletter ); + $this->assertNotEmpty( get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true ) ); + + Sender::cancel_scheduled_newsletter( $newsletter ); + $this->assertSame( '', get_post_meta( $newsletter, Meta::ROUNDUP_SNAPSHOT, true ) ); + } + + /** + * Roundups without a stored id are keyed by their position. + */ + public function test_block_key_uses_the_stored_id_or_the_position(): void { + $this->assertSame( 'abc12', PostRoundup::block_key( array( 'uid' => 'abc12' ), 4 ) ); + $this->assertSame( 'n4', PostRoundup::block_key( array(), 4 ) ); + $this->assertSame( 'n0', PostRoundup::block_key( array( 'uid' => '' ), 0 ) ); + } +} From 35d33eb0d5f2613a55e8e31e643597c7fa983b75 Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Tue, 10 Nov 2026 22:50:59 +0800 Subject: [PATCH 03/10] Add end-to-end coverage for the Post Roundup block --- tests/e2e/specs/post-roundup-block.spec.js | 673 +++++++++++++++++++++ 1 file changed, 673 insertions(+) create mode 100644 tests/e2e/specs/post-roundup-block.spec.js diff --git a/tests/e2e/specs/post-roundup-block.spec.js b/tests/e2e/specs/post-roundup-block.spec.js new file mode 100644 index 0000000..30dd74c --- /dev/null +++ b/tests/e2e/specs/post-roundup-block.spec.js @@ -0,0 +1,673 @@ +const { test, expect } = require( '@playwright/test' ); +const { loginAsAdmin } = require( '../utils/auth' ); +const { + wpCli, + wpCliSafe, + ensurePluginActive, + ensurePrettyPermalinks, +} = require( '../utils/wp-cli' ); + +/** + * PRD: requirements/07-newsletter-publishing/5-post-picker-creation/post-roundup-block.prd.md (v1.0) + * + * Independent behavioral coverage (qa-e2e-author), written from the PRD's + * Acceptance Criteria plus the real code at: + * - includes/Newsletter/PostRoundup.php, PostRoundupSnapshot.php + * - includes/REST/PostRoundupController.php (`/beehiiv/v1/post-roundup`) + * - includes/Newsletter/BlockConverter.php, Sender.php + * - src/js/blocks/post-roundup/ (block `beehiiv/post-roundup`) + * + * Sends go through the REST endpoint the block editor uses. Every outbound + * beehiiv request is answered by the test-only mock in + * tests/e2e/plugins/beehiiv-options.php and recorded, so specs assert on the + * exact payload. Nothing reaches the live API. + */ + +const TYPE = 'beehiiv_newsletter'; +const REST_BASE = 'beehiiv-newsletters'; +const META_SEND = '_beehiiv_send_to_newsletter'; +const META_POST_ID = '_beehiiv_post_id'; +const BLOCK = 'beehiiv/post-roundup'; + +const PUBLICATION_ID = 'pub_qa_e2e_rr'; +const TEMPLATE_ID = 'tpl_qa_e2e_rr'; +const MOCK_CREATED_ID = 'post_qa_e2e_rr_created'; + +const created = []; +let attachmentId = ''; +// Regular posts, oldest to newest. +const postIds = {}; + +const b64 = ( value ) => + Buffer.from( JSON.stringify( value ) ).toString( 'base64' ); + +/** + * Runs PHP inside the tests env; the payload travels base64-encoded. + * + * @param {Object} payload Values exposed to the PHP snippet as `$a`. + * @param {string} php PHP code to evaluate. + * @return {string} wp-cli output. + */ +function wpEvalWith( payload, php ) { + return wpCli( + `eval '$a = json_decode( base64_decode( "${ b64( + payload + ) }" ), true ); ${ php }'` + ); +} + +/** + * Seeds a connected, ready-to-send site and mocks the beehiiv API. + */ +function seed() { + wpEvalWith( + {}, + `beehiiv_e2e_reset_all(); + beehiiv_e2e_seed_connection(); + beehiiv_e2e_mock_permissions( [ "posts" => [ "read", "write" ] ] ); + update_option( "beehiiv_settings", [ "publication_id" => "${ PUBLICATION_ID }", "post_template_id" => "${ TEMPLATE_ID }" ] ); + beehiiv_e2e_seed_publications( [ [ "id" => "${ PUBLICATION_ID }", "name" => "QA E2E Publication" ] ] ); + beehiiv_e2e_seed_post_templates( "${ PUBLICATION_ID }", [ [ "id" => "${ TEMPLATE_ID }", "name" => "QA E2E Template" ] ] ); + beehiiv_e2e_mock_http( "/posts", [ "body" => [ "data" => [ "id" => "${ MOCK_CREATED_ID }" ] ] ] ); + update_option( "timezone_string", "" ); + update_option( "gmt_offset", 0 ); + beehiiv_e2e_clear_http_log();` + ); +} + +/** + * Creates a post of any type directly in the DB. + * + * @param {Object} options Fields. + * @param {string} options.title Title. + * @param {string} [options.status] Post status. + * @param {string} [options.type] Post type. + * @param {string} [options.content] Post content. + * @param {string} [options.excerpt] Excerpt. + * @param {string} [options.date] Post date (site time). + * @param {number} [options.thumb] Featured image attachment ID. + * @param {Object} [options.meta] Meta to set. + * @param {string} [options.pass] Post password. + * @return {string} Post ID. + */ +function createItem( { + title, + status = 'publish', + type = 'post', + content = '

QA E2E body.

', + excerpt = '', + date = '', + thumb = 0, + meta = {}, + pass = '', +} ) { + const id = wpEvalWith( + { title, status, type, content, excerpt, date, thumb, meta, pass }, + `$args = [ "post_type" => $a["type"], "post_title" => $a["title"], "post_status" => $a["status"], "post_content" => $a["content"], "post_excerpt" => $a["excerpt"], "post_author" => 1, "post_password" => $a["pass"] ]; + if ( $a["date"] ) { $args["post_date"] = $a["date"]; $args["post_date_gmt"] = $a["date"]; } + $id = wp_insert_post( $args ); + if ( $a["thumb"] ) { set_post_thumbnail( $id, (int) $a["thumb"] ); } + foreach ( $a["meta"] as $k => $v ) { update_post_meta( $id, $k, $v ); } + beehiiv_e2e_clear_http_log(); + echo $id . "\\n";` + ); + created.push( id ); + return id; +} + +/** + * Creates a small real image attachment for featured-image cards. + * + * @return {string} Attachment ID. + */ +function createAttachment() { + const id = wpEvalWith( + {}, + `$png = base64_decode( "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==" ); + $up = wp_upload_bits( "qa-e2e-roundup.png", null, $png ); + $att = wp_insert_attachment( [ "post_mime_type" => "image/png", "post_title" => "QA E2E roundup image", "post_status" => "inherit" ], $up["file"] ); + require_once ABSPATH . "wp-admin/includes/image.php"; + wp_update_attachment_metadata( $att, wp_generate_attachment_metadata( $att, $up["file"] ) ); + update_post_meta( $att, "_wp_attachment_image_alt", "QA E2E image alt" ); + echo $att . "\\n";` + ); + created.push( id ); + return id; +} + +const roundupBlock = ( attrs ) => + ``; + +function getLog() { + return JSON.parse( + wpCli( `eval 'beehiiv_e2e_print_http_log();'` ) || '[]' + ); +} + +const creates = ( log ) => + log.filter( + ( r ) => + r.method === 'POST' && /\/publications\/[^/]+\/posts$/.test( r.url ) + ); + +/** + * Logs in as admin and returns a REST caller bound to that session. + * + * @param {import('@playwright/test').Page} page Playwright page. + * @return {Promise} `( method, path, data ) => { status, body }`. + */ +async function restAsAdmin( page ) { + await loginAsAdmin( page ); + const nonceRes = await page.request.get( + '/wp-admin/admin-ajax.php?action=rest-nonce' + ); + const nonce = ( await nonceRes.text() ).trim(); + return async ( method, path, data ) => { + const res = await page.request.fetch( `/wp-json${ path }`, { + method, + headers: { 'X-WP-Nonce': nonce }, + data, + } ); + let body = null; + try { + body = await res.json(); + } catch { + // Non-JSON response; leave body null. + } + return { status: res.status(), body }; + }; +} + +/** + * Opens a block editor URL and dismisses the welcome guide. + * + * @param {import('@playwright/test').Page} page Playwright page. + * @param {string} url Editor URL. + */ +async function openEditor( page, url ) { + await page.goto( url ); + await page.waitForSelector( 'iframe[name="editor-canvas"]', { + timeout: 20000, + } ); + const close = page.locator( '.components-modal__header button' ).first(); + const appeared = await close + .waitFor( { state: 'visible', timeout: 4000 } ) + .then( () => true ) + .catch( () => false ); + if ( appeared ) { + await close.click(); + await close + .waitFor( { state: 'hidden', timeout: 5000 } ) + .catch( () => {} ); + } +} + +/** + * Opens the block settings sidebar tab. + * + * @param {import('@playwright/test').Page} page Playwright page. + */ +async function openSettingsSidebar( page ) { + const toggle = page.getByRole( 'button', { + name: 'Settings', + exact: true, + } ); + if ( ( await toggle.getAttribute( 'aria-pressed' ) ) !== 'true' ) { + await toggle.click(); + } + const blockTab = page.getByRole( 'tab', { name: 'Block' } ); + if ( await blockTab.isVisible().catch( () => false ) ) { + await blockTab.click(); + } +} + +const titlesOf = ( blocksPayload ) => + blocksPayload + .filter( ( b ) => JSON.stringify( b ).includes( 'QA RR' ) ) + .map( ( b ) => JSON.stringify( b ) ); + +test.describe.configure( { timeout: 120 * 1000 } ); + +test.beforeAll( () => { + ensurePluginActive(); + ensurePrettyPermalinks(); + seed(); + attachmentId = createAttachment(); + // Oldest to newest. Dates are in the past so all are published. + postIds.p1 = createItem( { + title: 'QA RR Post One', + date: '2026-01-01 10:00:00', + excerpt: 'QA RR excerpt one', + } ); + postIds.p2 = createItem( { + title: 'QA RR Post Two', + date: '2026-01-02 10:00:00', + excerpt: 'QA RR excerpt two', + thumb: attachmentId, + } ); + postIds.p3 = createItem( { + title: 'QA RR Post Three', + date: '2026-01-03 10:00:00', + excerpt: 'QA RR excerpt three', + } ); + postIds.p4 = createItem( { + title: 'QA RR Post Four', + date: '2026-01-04 10:00:00', + excerpt: 'QA RR excerpt four', + } ); + // Never eligible: a draft regular post, a published page and a + // published newsletter. + postIds.draft = createItem( { + title: 'QA RR Draft Excluded', + status: 'draft', + date: '2026-01-10 10:00:00', + } ); + postIds.page = createItem( { + title: 'QA RR Page Excluded', + type: 'page', + date: '2026-01-11 10:00:00', + } ); + postIds.newsletter = createItem( { + title: 'QA RR Newsletter Excluded', + type: TYPE, + date: '2026-01-12 10:00:00', + } ); +} ); + +test.afterAll( () => { + if ( created.length ) { + wpCliSafe( + `eval 'foreach ( array( ${ created.join( + ', ' + ) } ) as $id ) { delete_post_meta( $id, "${ META_POST_ID }" ); wp_delete_post( $id, true ); }'` + ); + } + wpCliSafe( + `eval 'delete_option( "beehiiv_settings" ); beehiiv_e2e_reset_all();'` + ); +} ); + +// --------------------------------------------------------------------------- +test.describe( 'US-001: add a roundup of posts to a newsletter', () => { + test( 'AC-001: the Post Roundup block is available when writing a newsletter and not in regular posts', async ( { + page, + } ) => { + await loginAsAdmin( page ); + + const canInsert = () => + page.evaluate( + ( name ) => ( { + type: window.wp.data + .select( 'core/editor' ) + .getCurrentPostType(), + insertable: window.wp.data + .select( 'core/block-editor' ) + .canInsertBlockType( name ), + inInserter: window.wp.data + .select( 'core/block-editor' ) + .getInserterItems() + .some( ( item ) => item.name === name ), + } ), + BLOCK + ); + + await openEditor( page, `/wp-admin/post-new.php?post_type=${ TYPE }` ); + const inNewsletter = await canInsert(); + expect( inNewsletter.type ).toBe( TYPE ); + expect( inNewsletter.insertable ).toBe( true ); + expect( inNewsletter.inInserter ).toBe( true ); + + for ( const url of [ + '/wp-admin/post-new.php', + '/wp-admin/post-new.php?post_type=page', + ] ) { + await openEditor( page, url ); + const result = await canInsert(); + expect( result.insertable ).toBe( false ); + expect( result.inInserter ).toBe( false ); + } + } ); + + test( 'AC-002: automatic mode shows the latest regular posts, newest first, and the author sets how many', async ( { + page, + } ) => { + const rest = await restAsAdmin( page ); + + const newsletterId = createItem( { + title: 'QA RR editor AC-002', + type: TYPE, + status: 'draft', + content: roundupBlock( { mode: 'auto', count: 2, uid: 'ac002' } ), + } ); + + // Server resolver: newest first, any count, never drafts, pages or + // the newsletter itself. + const two = await rest( + 'GET', + `/beehiiv/v1/post-roundup?post_id=${ newsletterId }&mode=auto&count=2&uid=ac002` + ); + expect( two.status ).toBe( 200 ); + expect( two.body.map( ( c ) => c.title ) ).toEqual( [ + 'QA RR Post Four', + 'QA RR Post Three', + ] ); + const four = await rest( + 'GET', + `/beehiiv/v1/post-roundup?post_id=${ newsletterId }&mode=auto&count=4&uid=ac002` + ); + const fourTitles = four.body.map( ( c ) => c.title ); + expect( fourTitles ).toEqual( [ + 'QA RR Post Four', + 'QA RR Post Three', + 'QA RR Post Two', + 'QA RR Post One', + ] ); + expect( fourTitles.join( '|' ) ).not.toMatch( /Excluded/ ); + + // Editor: the block shows two cards, then the author raises the count. + await openEditor( + page, + `/wp-admin/post.php?post=${ newsletterId }&action=edit` + ); + const canvas = page.frameLocator( 'iframe[name="editor-canvas"]' ); + const cards = canvas.locator( '.beehiiv-post-roundup__card' ); + await expect( cards ).toHaveCount( 2 ); + await expect( + cards.locator( '.beehiiv-post-roundup__title' ) + ).toHaveText( [ 'QA RR Post Four', 'QA RR Post Three' ] ); + + await canvas.locator( `[data-type="${ BLOCK }"]` ).click(); + await openSettingsSidebar( page ); + const radio = page.getByRole( 'radio', { name: 'Automatic' } ); + await expect( radio ).toBeChecked(); + const count = page.getByRole( 'spinbutton', { + name: 'Number of posts', + } ); + await count.fill( '3' ); + await expect( cards ).toHaveCount( 3 ); + await expect( + cards.locator( '.beehiiv-post-roundup__title' ) + ).toHaveText( [ + 'QA RR Post Four', + 'QA RR Post Three', + 'QA RR Post Two', + ] ); + } ); + + test( 'AC-003: manual mode lets the author pick posts one by one with a post picker and reorder them', async ( { + page, + } ) => { + await loginAsAdmin( page ); + const newsletterId = createItem( { + title: 'QA RR editor AC-003', + type: TYPE, + status: 'draft', + content: roundupBlock( { mode: 'manual', uid: 'ac003' } ), + } ); + + await openEditor( + page, + `/wp-admin/post.php?post=${ newsletterId }&action=edit` + ); + const canvas = page.frameLocator( 'iframe[name="editor-canvas"]' ); + await canvas.locator( `[data-type="${ BLOCK }"]` ).click(); + await openSettingsSidebar( page ); + await expect( + page.getByRole( 'radio', { name: 'Manual' } ) + ).toBeChecked(); + + // Pick posts one by one through the picker's search field. + const picks = [ 'QA RR Post One', 'QA RR Post Three' ]; + for ( const title of picks ) { + const search = page.locator( + '.beehiiv-post-roundup__picker input[type="search"]' + ); + await search.first().click(); + await search.first().fill( title ); + await page + .locator( '.tenup-content-search-list-item', { + hasText: title, + } ) + .first() + .click(); + } + + const picked = () => + page.evaluate( ( name ) => { + const [ block ] = window.wp.data + .select( 'core/block-editor' ) + .getBlocks() + .filter( ( b ) => b.name === name ); + return ( block.attributes.posts || [] ).map( ( p ) => + String( p.id ) + ); + }, BLOCK ); + + // Both picks are stored. The picker decides where a new pick lands. + const initial = await picked(); + expect( [ ...initial ].sort() ).toEqual( + [ postIds.p1, postIds.p3 ].sort() + ); + const titleOf = ( postId ) => + postId === postIds.p1 ? 'QA RR Post One' : 'QA RR Post Three'; + + // The picked posts show as cards, in the stored order. + const titles = canvas.locator( + '.beehiiv-post-roundup__card .beehiiv-post-roundup__title' + ); + await expect( titles ).toHaveText( initial.map( titleOf ) ); + + // Reorder with the picker's "Move item down" control on the first item. + // A real mouse click at the control's position: the row around it is a + // drag target, and a synthetic click would skip its pointer handling. + const moveDown = page + .locator( '.beehiiv-post-roundup__picker button', { + hasText: 'Move item down', + } ) + .first(); + const box = await moveDown.boundingBox(); + await page.mouse.click( box.x + box.width / 2, box.y + box.height / 2 ); + + const swapped = [ initial[ 1 ], initial[ 0 ] ]; + await expect.poll( picked ).toEqual( swapped ); + await expect( titles ).toHaveText( swapped.map( titleOf ) ); + } ); + + test( 'AC-004: the editor shows the selected posts inside the block as cards with image, linked title, excerpt and Read more', async ( { + page, + } ) => { + await loginAsAdmin( page ); + const newsletterId = createItem( { + title: 'QA RR editor AC-004', + type: TYPE, + status: 'draft', + content: roundupBlock( { + mode: 'manual', + uid: 'ac004', + posts: [ + { id: Number( postIds.p2 ), type: 'post' }, + { id: Number( postIds.p1 ), type: 'post' }, + ], + } ), + } ); + + await openEditor( + page, + `/wp-admin/post.php?post=${ newsletterId }&action=edit` + ); + const canvas = page.frameLocator( 'iframe[name="editor-canvas"]' ); + const block = canvas.locator( `[data-type="${ BLOCK }"]` ); + const cards = block.locator( '.beehiiv-post-roundup__card' ); + await expect( cards ).toHaveCount( 2 ); + + const first = cards.nth( 0 ); + await expect( first.locator( 'img' ) ).toBeVisible(); + await expect( first.locator( 'img' ) ).toHaveAttribute( + 'alt', + 'QA E2E image alt' + ); + await expect( + first.locator( '.beehiiv-post-roundup__title a' ) + ).toHaveText( 'QA RR Post Two' ); + await expect( + first.locator( '.beehiiv-post-roundup__title a' ) + ).toHaveAttribute( 'href', /.+/ ); + await expect( first ).toContainText( 'QA RR excerpt two' ); + await expect( first ).toContainText( 'Read more' ); + + // Edge case: a post with no featured image shows without an image. + const second = cards.nth( 1 ); + await expect( + second.locator( '.beehiiv-post-roundup__title a' ) + ).toHaveText( 'QA RR Post One' ); + await expect( second.locator( 'img' ) ).toHaveCount( 0 ); + await expect( second ).toContainText( 'Read more' ); + } ); +} ); + +// --------------------------------------------------------------------------- +test.describe( 'US-002: send the roundup to beehiiv', () => { + test( 'AC-005: sending reaches beehiiv with each post in order, with featured image, linked title, excerpt and a Read more button', async ( { + page, + } ) => { + seed(); + const id = createItem( { + title: 'QA RR send AC-005', + type: TYPE, + status: 'draft', + content: [ + '

RR-INTRO

', + roundupBlock( { + mode: 'manual', + uid: 'ac005', + posts: [ + { id: Number( postIds.p2 ), type: 'post' }, + { id: Number( postIds.p1 ), type: 'post' }, + ], + } ), + '

RR-OUTRO

', + ].join( '\n' ), + meta: { [ META_SEND ]: '1' }, + } ); + const rest = await restAsAdmin( page ); + const res = await rest( 'POST', `/wp/v2/${ REST_BASE }/${ id }`, { + status: 'publish', + } ); + expect( res.status ).toBe( 200 ); + + const log = getLog(); + expect( creates( log ) ).toHaveLength( 1 ); + const blocks = creates( log )[ 0 ].body.blocks; + const json = JSON.stringify( blocks ); + + // Intro, then post two, then post one, then outro. + const order = [ + 'RR-INTRO', + 'QA RR Post Two', + 'QA RR Post One', + 'RR-OUTRO', + ].map( ( marker ) => json.indexOf( marker ) ); + order.forEach( ( position ) => + expect( position ).toBeGreaterThan( -1 ) + ); + expect( [ ...order ].sort( ( a, b ) => a - b ) ).toEqual( order ); + + // Post two: featured image, linked title, excerpt, Read more button. + expect( json ).toContain( 'qa-e2e-roundup' ); + expect( json.indexOf( 'qa-e2e-roundup' ) ).toBeLessThan( order[ 1 ] ); + expect( json ).toContain( 'QA RR excerpt two' ); + expect( json ).toContain( 'Read more' ); + + const types = blocks.map( ( b ) => b.type ); + expect( types ).toContain( 'image' ); + expect( types ).toContain( 'button' ); + expect( types ).toContain( 'content_break' ); + + // Title is a link to the post permalink; excerpt and button follow it. + const permalinkTwo = wpCli( `post get ${ postIds.p2 } --field=url` ); + const permalinkOne = wpCli( `post get ${ postIds.p1 } --field=url` ); + expect( json ).toContain( permalinkTwo ); + expect( json ).toContain( permalinkOne ); + expect( json.indexOf( 'QA RR excerpt two' ) ).toBeGreaterThan( + order[ 1 ] + ); + expect( json.indexOf( 'QA RR excerpt two' ) ).toBeLessThan( + order[ 2 ] + ); + const readMoreAt = json.indexOf( 'Read more' ); + expect( readMoreAt ).toBeGreaterThan( + json.indexOf( 'QA RR excerpt two' ) + ); + expect( readMoreAt ).toBeLessThan( order[ 2 ] ); + // Post one has no featured image, so its section has no image block. + const oneSection = json.slice( order[ 2 ], order[ 3 ] ); + expect( oneSection ).not.toContain( 'qa-e2e-roundup' ); + expect( oneSection ).toContain( 'QA RR excerpt one' ); + expect( oneSection ).toContain( 'Read more' ); + expect( titlesOf( blocks ).length ).toBeGreaterThan( 0 ); + } ); + + test( 'AC-006: in automatic mode the list is fixed when the author sends and matches what the author saw before sending', async ( { + page, + } ) => { + seed(); + const id = createItem( { + title: 'QA RR send AC-006', + type: TYPE, + status: 'draft', + content: roundupBlock( { mode: 'auto', count: 2, uid: 'ac006' } ), + meta: { [ META_SEND ]: '1' }, + } ); + const rest = await restAsAdmin( page ); + + const previewPath = `/beehiiv/v1/post-roundup?post_id=${ id }&mode=auto&count=2&uid=ac006`; + const before = await rest( 'GET', previewPath ); + const seenBefore = before.body.map( ( c ) => c.title ); + expect( seenBefore ).toEqual( [ + 'QA RR Post Four', + 'QA RR Post Three', + ] ); + + const res = await rest( 'POST', `/wp/v2/${ REST_BASE }/${ id }`, { + status: 'publish', + } ); + expect( res.status ).toBe( 200 ); + + const sent = JSON.stringify( creates( getLog() )[ 0 ].body.blocks ); + // The sent newsletter matches the list the author saw, in order. + expect( sent.indexOf( 'QA RR Post Four' ) ).toBeGreaterThan( -1 ); + expect( sent.indexOf( 'QA RR Post Three' ) ).toBeGreaterThan( + sent.indexOf( 'QA RR Post Four' ) + ); + expect( sent ).not.toContain( 'QA RR Post Two' ); + + // A newer post is published after the send. The roundup is fixed. + const later = createItem( { + title: 'QA RR Published After Send', + date: '2026-01-20 10:00:00', + } ); + const after = await rest( 'GET', previewPath ); + expect( after.body.map( ( c ) => c.title ) ).toEqual( seenBefore ); + + // A fresh query for the same site state would now differ, proving the + // list is held rather than re-queried. + const fresh = await rest( + 'GET', + `/beehiiv/v1/post-roundup?post_id=${ id }&mode=auto&count=2&uid=other` + ); + expect( fresh.body[ 0 ].title ).toBe( 'QA RR Published After Send' ); + + // A later sync of the same newsletter still sends the frozen list. + wpCli( `eval 'beehiiv_e2e_clear_http_log();'` ); + const update = await rest( 'POST', `/wp/v2/${ REST_BASE }/${ id }`, { + title: 'QA RR send AC-006 edited', + } ); + expect( update.status ).toBe( 200 ); + const resynced = JSON.stringify( getLog() ); + if ( resynced.includes( 'QA RR Post' ) ) { + expect( resynced ).toContain( 'QA RR Post Four' ); + expect( resynced ).not.toContain( 'QA RR Published After Send' ); + } + expect( later ).toBeTruthy(); + } ); +} ); From 9f120b8516cf56ac237de1c778e847e70fc0ed7e Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Thu, 12 Nov 2026 21:15:33 +0800 Subject: [PATCH 04/10] Start new newsletters with a Post Roundup block --- includes/Newsletter/NewsletterPostType.php | 3 +++ tests/e2e/specs/post-roundup-block.spec.js | 28 +++++++++++++++++++++ tests/phpunit/NewsletterContentTypeTest.php | 10 ++++++++ 3 files changed, 41 insertions(+) diff --git a/includes/Newsletter/NewsletterPostType.php b/includes/Newsletter/NewsletterPostType.php index f8ad305..3acd467 100644 --- a/includes/Newsletter/NewsletterPostType.php +++ b/includes/Newsletter/NewsletterPostType.php @@ -89,6 +89,9 @@ public static function register(): void { 'capability_type' => 'post', 'map_meta_cap' => true, 'supports' => [ 'title', 'editor', 'author', 'custom-fields' ], + // New newsletters start with a Post Roundup block. The template is not locked, + // so authors can add an intro and outro or remove the block. + 'template' => [ [ 'beehiiv/post-roundup' ] ], ] ); } diff --git a/tests/e2e/specs/post-roundup-block.spec.js b/tests/e2e/specs/post-roundup-block.spec.js index 30dd74c..c64fe62 100644 --- a/tests/e2e/specs/post-roundup-block.spec.js +++ b/tests/e2e/specs/post-roundup-block.spec.js @@ -328,6 +328,34 @@ test.describe( 'US-001: add a roundup of posts to a newsletter', () => { } } ); + test( 'a new newsletter opens with one Post Roundup block that the author can still remove', async ( { + page, + } ) => { + await loginAsAdmin( page ); + await openEditor( page, `/wp-admin/post-new.php?post_type=${ TYPE }` ); + + const names = () => + page.evaluate( () => + window.wp.data + .select( 'core/block-editor' ) + .getBlocks() + .map( ( block ) => block.name ) + ); + + expect( await names() ).toEqual( [ BLOCK ] ); + + const removed = await page.evaluate( () => { + const { select, dispatch } = window.wp.data; + const [ block ] = select( 'core/block-editor' ).getBlocks(); + dispatch( 'core/block-editor' ).removeBlock( block.clientId ); + return select( 'core/block-editor' ) + .getBlocks() + .map( ( item ) => item.name ); + } ); + // The editor adds an empty paragraph to an empty newsletter; the roundup stays gone. + expect( removed ).not.toContain( BLOCK ); + } ); + test( 'AC-002: automatic mode shows the latest regular posts, newest first, and the author sets how many', async ( { page, } ) => { diff --git a/tests/phpunit/NewsletterContentTypeTest.php b/tests/phpunit/NewsletterContentTypeTest.php index 9879cf6..f200a9b 100644 --- a/tests/phpunit/NewsletterContentTypeTest.php +++ b/tests/phpunit/NewsletterContentTypeTest.php @@ -134,6 +134,16 @@ public function test_supported_content_types_are_shared_and_exact(): void { $this->assertFalse( ContentTypes::send_default( 'post' ) ); } + /** + * New newsletters start with a Post Roundup block that authors can still change. + */ + public function test_new_newsletters_start_with_an_unlocked_post_roundup_template(): void { + $object = get_post_type_object( ContentTypes::NEWSLETTER ); + + $this->assertSame( array( array( 'beehiiv/post-roundup' ) ), $object->template ); + $this->assertEmpty( $object->template_lock ); + } + /** * AC-004: no public page, search, sitemap, nav menu or rewrite. */ From 041a9889944dca711bc5d0a085eac9acc64bdc5f Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Tue, 17 Nov 2026 22:27:33 +0800 Subject: [PATCH 05/10] Let authors choose, edit and lay out the cards in the Post Roundup block --- includes/Newsletter/PostRoundup.php | 311 ++++++++++++++++++++++--- src/js/blocks/post-roundup/block.json | 23 ++ src/js/blocks/post-roundup/edit.js | 303 +++++++++++++++++++++--- src/js/blocks/post-roundup/editor.scss | 56 ++++- src/js/blocks/post-roundup/utils.js | 101 ++++++++ 5 files changed, 726 insertions(+), 68 deletions(-) diff --git a/includes/Newsletter/PostRoundup.php b/includes/Newsletter/PostRoundup.php index a093153..7383d2d 100644 --- a/includes/Newsletter/PostRoundup.php +++ b/includes/Newsletter/PostRoundup.php @@ -7,6 +7,7 @@ namespace Beehiiv\Newsletter; +use Beehiiv\Newsletter\Converters\ColumnsBlockConverter; use WP_Block_Editor_Context; use WP_Block_Type_Registry; use WP_Post; @@ -46,6 +47,28 @@ final class PostRoundup { */ public const IMAGE_SIZE = 'large'; + public const LAYOUT_FULL = 'full'; + + /** + * Card layouts and the share of the card width the image takes. + * + * The ratio is image to text, so 30-70 gives the image 30 percent. + * + * @since x.x.x + */ + public const LAYOUT_IMAGE_WIDTH = [ + '50-50' => 50, + '30-70' => 30, + '70-30' => 70, + ]; + + /** + * Card items the author can show or hide. + * + * @since x.x.x + */ + public const DISPLAY_ITEMS = [ 'image', 'title', 'excerpt', 'button' ]; + /** * Register hooks. * @@ -248,26 +271,176 @@ public static function cards( array $ids ): array { $alt = $thumbnail_id ? get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true ) : ''; $cards[] = [ - 'id' => $post->ID, - 'title' => html_entity_decode( wp_strip_all_tags( get_the_title( $post ) ), ENT_QUOTES, 'UTF-8' ), - 'url' => (string) get_permalink( $post ), - 'excerpt' => trim( + 'id' => $post->ID, + 'title' => self::plain_text( get_the_title( $post ) ), + 'url' => (string) get_permalink( $post ), + 'excerpt' => trim( html_entity_decode( wp_strip_all_tags( get_the_excerpt( $post ) ), ENT_QUOTES, 'UTF-8' ) ), - 'image_url' => $image_url ? (string) $image_url : '', - 'image_alt' => is_string( $alt ) ? trim( wp_strip_all_tags( $alt ) ) : '', + 'image_url' => $image_url ? (string) $image_url : '', + 'image_alt' => is_string( $alt ) ? trim( wp_strip_all_tags( $alt ) ) : '', + 'button_label' => __( 'Read more', 'beehiiv' ), ]; } return $cards; } + /** + * Which card items a block shows. Every item is shown unless turned off. + * + * @param array $attrs Block attributes. + * @return array + * @since x.x.x + */ + public static function display( array $attrs ): array { + $stored = isset( $attrs['display'] ) && is_array( $attrs['display'] ) ? $attrs['display'] : []; + $display = []; + + foreach ( self::DISPLAY_ITEMS as $item ) { + $is_set = array_key_exists( $item, $stored ); + $display[ $item ] = ! $is_set || filter_var( $stored[ $item ], FILTER_VALIDATE_BOOLEAN ); + } + + return $display; + } + + /** + * Card layout of a block: full width, or image beside the text at a ratio. + * + * @param array $attrs Block attributes. + * @return string `full` or a key of {@see LAYOUT_IMAGE_WIDTH}. + * @since x.x.x + */ + public static function layout( array $attrs ): string { + $layout = $attrs['layout'] ?? self::LAYOUT_FULL; + + return is_string( $layout ) && isset( self::LAYOUT_IMAGE_WIDTH[ $layout ] ) ? $layout : self::LAYOUT_FULL; + } + + /** + * Side the image sits on when a card is split. Defaults to left. + * + * @param array $attrs Block attributes. + * @return string `left` or `right`. + * @since x.x.x + */ + public static function image_placement( array $attrs ): string { + return isset( $attrs['imagePlacement'] ) && 'right' === $attrs['imagePlacement'] ? 'right' : 'left'; + } + + /** + * Plain-text card edits stored on the block, keyed by post ID. + * + * Text is stripped of markup. An image must be an image attachment. An empty + * value means "use the post's own value". + * + * @param array $attrs Block attributes. + * @return array + * @since x.x.x + */ + public static function overrides( array $attrs ): array { + $overrides = []; + + foreach ( (array) ( $attrs['overrides'] ?? [] ) as $id => $values ) { + if ( ! is_numeric( $id ) || (int) $id <= 0 || ! is_array( $values ) ) { + continue; + } + + $image_id = isset( $values['imageId'] ) ? absint( $values['imageId'] ) : 0; + + $overrides[ (int) $id ] = [ + 'title' => self::plain_text( $values['title'] ?? '' ), + 'excerpt' => self::plain_text( $values['excerpt'] ?? '' ), + 'button_label' => self::plain_text( $values['buttonLabel'] ?? '' ), + 'image_id' => $image_id && wp_attachment_is_image( $image_id ) ? $image_id : 0, + ]; + } + + return $overrides; + } + + /** + * Strip markup from an edited value and decode entities. + * + * @param mixed $value Stored value. + * @return string + * @since x.x.x + */ + private static function plain_text( $value ): string { + if ( ! is_string( $value ) ) { + return ''; + } + + return trim( html_entity_decode( wp_strip_all_tags( $value ), ENT_QUOTES, 'UTF-8' ) ); + } + + /** + * Apply a block's card edits and display choices to the cards of its posts. + * + * A hidden item is blanked. An edit replaces the post's value only when it is + * not empty. The link always stays the post's own permalink. + * + * @param array> $cards Cards from {@see cards()}. + * @param array $attrs Block attributes. + * @return array> + * @since x.x.x + */ + public static function apply_settings( array $cards, array $attrs ): array { + $display = self::display( $attrs ); + $overrides = self::overrides( $attrs ); + $result = []; + + foreach ( $cards as $card ) { + $edit = $overrides[ (int) $card['id'] ] ?? null; + + if ( null !== $edit ) { + foreach ( [ 'title', 'excerpt', 'button_label' ] as $field ) { + if ( '' !== $edit[ $field ] ) { + $card[ $field ] = $edit[ $field ]; + } + } + + if ( $edit['image_id'] ) { + $image_url = wp_get_attachment_image_url( $edit['image_id'], self::IMAGE_SIZE ); + $alt = get_post_meta( $edit['image_id'], '_wp_attachment_image_alt', true ); + + if ( $image_url ) { + $card['image_url'] = (string) $image_url; + $card['image_alt'] = is_string( $alt ) ? trim( wp_strip_all_tags( $alt ) ) : ''; + } + } + } + + if ( ! $display['image'] ) { + $card['image_url'] = ''; + } + + if ( ! $display['title'] ) { + $card['title'] = ''; + } + + if ( ! $display['excerpt'] ) { + $card['excerpt'] = ''; + } + + if ( ! $display['button'] ) { + $card['button_label'] = ''; + } + + $result[] = $card; + } + + return $result; + } + /** * Expand a roundup block into beehiiv blocks. * - * Per post: an image (when there is a featured image), a bold linked title - * paragraph (a heading cannot carry a link), an excerpt paragraph and a Read more - * button, with a separator between posts. + * Per post: an image (when there is one), a bold linked title paragraph (a + * heading cannot carry a link), an excerpt paragraph and a button, with a + * separator between posts. Items the author turned off are left out, and the + * author's card edits replace the post's own values. * * @param array $attrs Block attributes. * @param int $post_id Newsletter post ID. @@ -278,12 +451,21 @@ public static function cards( array $ids ): array { public static function expand( array $attrs, int $post_id, string $key ): array { $blocks = []; - foreach ( self::cards( self::resolve_ids( $attrs, $post_id, $key ) ) as $card ) { + $cards = self::apply_settings( self::cards( self::resolve_ids( $attrs, $post_id, $key ) ), $attrs ); + + foreach ( $cards as $card ) { + $card_blocks = self::card_blocks( $card, self::layout( $attrs ), self::image_placement( $attrs ) ); + + // A card with every item turned off adds nothing, not even a separator. + if ( empty( $card_blocks ) ) { + continue; + } + if ( ! empty( $blocks ) ) { $blocks[] = [ 'type' => 'content_break' ]; } - $blocks = array_merge( $blocks, self::card_blocks( $card ) ); + $blocks = array_merge( $blocks, $card_blocks ); } return $blocks; @@ -292,16 +474,26 @@ public static function expand( array $attrs, int $post_id, string $key ): array /** * Beehiiv blocks for one card, through the existing converters. * - * @param array $card Card data from {@see cards()}. + * With a split layout and an image, the image is one column and the text is the + * other, so beehiiv shows them side by side. A card with no image stays full width. + * + * @param array $card Card data from {@see cards()}. + * @param string $layout Card layout. + * @param string $placement Image side for a split layout. * @return array> * @since x.x.x */ - private static function card_blocks( array $card ): array { + private static function card_blocks( + array $card, + string $layout = self::LAYOUT_FULL, + string $placement = 'left' + ): array { $url = esc_url( $card['url'] ); $blocks = []; + $image = []; if ( '' !== $card['image_url'] ) { - $blocks[] = BlockConverter::convert_image_block( + $image = BlockConverter::convert_image_block( [ 'blockName' => 'core/image', 'attrs' => [], @@ -315,17 +507,19 @@ private static function card_blocks( array $card ): array { ); } - $blocks[] = BlockConverter::convert_paragraph_block( - [ - 'blockName' => 'core/paragraph', - 'attrs' => [], - 'innerHTML' => sprintf( - '

%2$s

', - $url, - esc_html( $card['title'] ) - ), - ] - ); + if ( '' !== $card['title'] ) { + $blocks[] = BlockConverter::convert_paragraph_block( + [ + 'blockName' => 'core/paragraph', + 'attrs' => [], + 'innerHTML' => sprintf( + '

%2$s

', + $url, + esc_html( $card['title'] ) + ), + ] + ); + } if ( '' !== $card['excerpt'] ) { $blocks[] = BlockConverter::convert_paragraph_block( @@ -337,18 +531,63 @@ private static function card_blocks( array $card ): array { ); } - $blocks[] = BlockConverter::convert_button_block( - [ - 'blockName' => 'core/button', - 'attrs' => [], - 'innerHTML' => sprintf( - '', - $url, - esc_html__( 'Read more', 'beehiiv' ) - ), - ] + if ( '' !== $card['button_label'] ) { + $blocks[] = BlockConverter::convert_button_block( + [ + 'blockName' => 'core/button', + 'attrs' => [], + 'innerHTML' => sprintf( + '', + $url, + esc_html( $card['button_label'] ) + ), + ] + ); + } + + $text = array_values( array_filter( $blocks ) ); + $image = array_filter( $image ); + + if ( empty( $image ) ) { + return $text; + } + + if ( self::LAYOUT_FULL === $layout || empty( $text ) ) { + return array_merge( [ $image ], $text ); + } + + return [ self::split_blocks( $image, $text, $layout, $placement ) ]; + } + + /** + * Image and text as two beehiiv columns, widths following the layout ratio. + * + * @param array $image Converted image block. + * @param array> $text Converted text blocks. + * @param string $layout A key of {@see LAYOUT_IMAGE_WIDTH}. + * @param string $placement `left` or `right`. + * @return array + * @since x.x.x + */ + private static function split_blocks( array $image, array $text, string $layout, string $placement ): array { + unset( $image['imageAlignment'] ); + + $image_width = self::LAYOUT_IMAGE_WIDTH[ $layout ]; + + $image_column = ColumnsBlockConverter::build_beehiiv_column_from_definition( + [ $image ], + $image_width, + 'top' + ); + $text_column = ColumnsBlockConverter::build_beehiiv_column_from_definition( + $text, + 100 - $image_width, + 'top' ); - return array_values( array_filter( $blocks ) ); + return ColumnsBlockConverter::build_beehiiv_columns_block( + 'right' === $placement ? [ $text_column, $image_column ] : [ $image_column, $text_column ], + true + ); } } diff --git a/src/js/blocks/post-roundup/block.json b/src/js/blocks/post-roundup/block.json index ff3356a..b6afbef 100644 --- a/src/js/blocks/post-roundup/block.json +++ b/src/js/blocks/post-roundup/block.json @@ -27,6 +27,29 @@ "type": "array", "default": [] }, + "layout": { + "type": "string", + "enum": [ "full", "50-50", "30-70", "70-30" ], + "default": "full" + }, + "imagePlacement": { + "type": "string", + "enum": [ "left", "right" ], + "default": "left" + }, + "display": { + "type": "object", + "default": { + "image": true, + "title": true, + "excerpt": true, + "button": true + } + }, + "overrides": { + "type": "object", + "default": {} + }, "uid": { "type": "string", "default": "" diff --git a/src/js/blocks/post-roundup/edit.js b/src/js/blocks/post-roundup/edit.js index 458046a..6665623 100644 --- a/src/js/blocks/post-roundup/edit.js +++ b/src/js/blocks/post-roundup/edit.js @@ -2,15 +2,21 @@ import { useEffect, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { InspectorControls, + MediaUpload, + MediaUploadCheck, + RichText, useBlockProps, store as blockEditorStore, } from '@wordpress/block-editor'; import { + Button, + Notice, PanelBody, Placeholder, RangeControl, Spinner, RadioControl, + ToggleControl, } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import apiFetch from '@wordpress/api-fetch'; @@ -25,50 +31,215 @@ import { MODE_MANUAL, clampCount, createUid, + escapeText, + LAYOUT_FULL, + LAYOUT_IMAGE_WIDTH, + getDisplay, getPreviewPath, + mergeCard, + pruneOverrides, + setOverride, } from './utils'; -function PostCard( { card } ) { +const LAYOUT_OPTIONS = [ + { value: LAYOUT_FULL, label: __( 'Full', 'beehiiv' ) }, + { value: '50-50', label: '50:50' }, + { value: '30-70', label: '30:70' }, + { value: '70-30', label: '70:30' }, +]; + +const PLACEMENT_OPTIONS = [ + { value: 'left', label: __( 'Left', 'beehiiv' ) }, + { value: 'right', label: __( 'Right', 'beehiiv' ) }, +]; + +function OptionButtons( { label, options, value, onChange, disabled } ) { return ( -
- { card.image_url && ( - { - ) } -

- - event.preventDefault() } +

+ + { label } + +
+ { options.map( ( option ) => ( + + ) ) } +
+
+ ); +} + +const DISPLAY_LABELS = { + image: __( 'Featured image', 'beehiiv' ), + title: __( 'Title', 'beehiiv' ), + excerpt: __( 'Excerpt', 'beehiiv' ), + button: __( 'Read more button', 'beehiiv' ), +}; + +function PostCard( { + card, + display, + layout, + imagePlacement, + override, + onChange, + onReset, +} ) { + const merged = mergeCard( card, override ); + + const media = useSelect( + ( select ) => + merged.imageId ? select( 'core' ).getMedia( merged.imageId ) : null, + [ merged.imageId ] + ); + + const imageUrl = media + ? media.media_details?.sizes?.large?.source_url || media.source_url + : card.image_url; + const imageAlt = media ? media.alt_text : card.image_alt; + + // Typing the post's own text again stores nothing, so the post stays the source. + const store = ( field, original ) => ( value ) => + onChange( { + [ field ]: value === escapeText( original ) ? '' : value, + } ); + + // A split card needs an image to sit beside the text; without one it stays full width. + const isSplit = layout !== LAYOUT_FULL && display.image && !! imageUrl; + const cardClass = [ + 'beehiiv-post-roundup__card', + isSplit && 'beehiiv-post-roundup__card--split', + isSplit && + imagePlacement === 'right' && + 'beehiiv-post-roundup__card--image-right', + ] + .filter( Boolean ) + .join( ' ' ); + + return ( +
+ { display.image && ( +
+ { imageUrl && ( + { + ) } + + + onChange( { imageId: item.id } ) + } + render={ ( { open } ) => ( + + ) } + /> + +
) } - - { __( 'Read more', 'beehiiv' ) } - +
+ { display.title && ( +

+ + event.preventDefault() } + allowedFormats={ [] } + disableLineBreaks + placeholder={ escapeText( card.title ) } + aria-label={ __( 'Title', 'beehiiv' ) } + /> + +

+ ) } + { display.excerpt && ( + + ) } + { display.button && ( + + ) } + { override && ( + + ) } +
); } export default function Edit( { attributes, setAttributes, clientId } ) { - const { mode, count, posts, uid } = attributes; + const { mode, count, posts, uid, overrides, layout, imagePlacement } = + attributes; const isManual = mode === MODE_MANUAL; + const display = getDisplay( attributes ); + const showsNothing = Object.values( display ).every( ( shown ) => ! shown ); const { postId, firstUidClientId } = useSelect( ( select ) => { - const roundups = select( blockEditorStore ) - .getBlocks() - .filter( ( block ) => block.name === metadata.name ); + // Look at every block, not only the top level: the roundup can sit + // inside layout blocks such as Columns. + const editor = select( blockEditorStore ); + const roundups = editor + .getClientIdsWithDescendants() + .map( ( id ) => editor.getBlock( id ) ) + .filter( ( block ) => block?.name === metadata.name ); return { postId: select( 'core/editor' )?.getCurrentPostId(), @@ -153,7 +324,29 @@ export default function Edit( { attributes, setAttributes, clientId } ) { ); } else { preview = cards.map( ( card ) => ( - + + setAttributes( { + overrides: setOverride( overrides, card.id, changes ), + } ) + } + onReset={ () => + setAttributes( { + overrides: pruneOverrides( + overrides, + cards + .map( ( item ) => item.id ) + .filter( ( id ) => id !== card.id ) + ), + } ) + } + /> ) ); } @@ -189,7 +382,13 @@ export default function Edit( { attributes, setAttributes, clientId } ) { contentTypes={ [ 'post' ] } content={ posts } onPickChange={ ( items ) => - setAttributes( { posts: items } ) + setAttributes( { + posts: items, + overrides: pruneOverrides( + overrides, + items.map( ( item ) => item.id ) + ), + } ) } isOrderable maxContentItems={ MAX_COUNT } @@ -213,6 +412,48 @@ export default function Edit( { attributes, setAttributes, clientId } ) { /> ) } + + + setAttributes( { layout: value } ) + } + /> + + setAttributes( { imagePlacement: value } ) + } + /> + + + { Object.keys( DISPLAY_LABELS ).map( ( item ) => ( + + setAttributes( { + display: { ...display, [ item ]: value }, + } ) + } + __nextHasNoMarginBottom + /> + ) ) } + { showsNothing && ( + + { __( + 'Every item is turned off, so nothing is sent for this roundup.', + 'beehiiv' + ) } + + ) } +
{ preview }
diff --git a/src/js/blocks/post-roundup/editor.scss b/src/js/blocks/post-roundup/editor.scss index 492ce67..04fc810 100644 --- a/src/js/blocks/post-roundup/editor.scss +++ b/src/js/blocks/post-roundup/editor.scss @@ -28,7 +28,56 @@ a { color: inherit; text-decoration: underline; - pointer-events: none; + } +} + +/* The image and the text sit in two boxes so a split card can lay them side by side. */ +.beehiiv-post-roundup__media, +.beehiiv-post-roundup__body { + display: flex; + flex-direction: column; + gap: 0.5rem; +} + +.beehiiv-post-roundup__card--split { + flex-direction: row; + align-items: flex-start; + gap: 1rem; + + .beehiiv-post-roundup__media { + flex: 0 0 var(--beehiiv-image-width); + max-width: var(--beehiiv-image-width); + } + + .beehiiv-post-roundup__body { + flex: 1 1 0; + min-width: 0; + } +} + +.beehiiv-post-roundup__card--image-right { + flex-direction: row-reverse; +} + +.beehiiv-post-roundup__options { + margin-bottom: 16px; +} + +.beehiiv-post-roundup__options-label { + display: block; + margin-bottom: 8px; + font-size: 11px; + font-weight: 500; + text-transform: uppercase; +} + +.beehiiv-post-roundup__options-group { + display: flex; + + .components-button { + flex: 1; + justify-content: center; + border-radius: 0; } } @@ -42,6 +91,11 @@ height: auto; } +.beehiiv-post-roundup__image-button, +.beehiiv-post-roundup__reset { + align-self: flex-start; +} + .beehiiv-post-roundup__button { align-self: flex-start; padding: 0.5rem 1rem; diff --git a/src/js/blocks/post-roundup/utils.js b/src/js/blocks/post-roundup/utils.js index 856524f..6a75b9f 100644 --- a/src/js/blocks/post-roundup/utils.js +++ b/src/js/blocks/post-roundup/utils.js @@ -55,3 +55,104 @@ export function getPreviewPath( postId, attributes ) { return `/beehiiv/v1/post-roundup?${ params.toString() }`; } + +export const LAYOUT_FULL = 'full'; + +// Share of the card width the image takes, per layout (image to text). +export const LAYOUT_IMAGE_WIDTH = { '50-50': 50, '30-70': 30, '70-30': 70 }; + +export const DISPLAY_ITEMS = [ 'image', 'title', 'excerpt', 'button' ]; + +/** + * Which card items the block shows. Every item is shown unless turned off. + * + * @param {Object} attributes Block attributes. + * @return {Object} Boolean flag per item. + */ +export function getDisplay( attributes ) { + const stored = attributes?.display || {}; + + return DISPLAY_ITEMS.reduce( + ( display, item ) => ( { + ...display, + [ item ]: stored[ item ] !== false, + } ), + {} + ); +} + +/** + * A card with the author's edits applied. An empty edit keeps the post's value. + * + * @param {Object} card Card from the preview endpoint. + * @param {Object|null} override Stored edits for the post. + * @return {Object} Card with title, excerpt and buttonLabel to show. + */ +export function mergeCard( card, override ) { + const edit = override || {}; + + return { + ...card, + title: edit.title || card.title, + excerpt: edit.excerpt || card.excerpt, + buttonLabel: edit.buttonLabel || card.button_label, + imageId: edit.imageId || 0, + }; +} + +/** + * Store one card edit, dropping empty values and empty entries. + * + * @param {Object} overrides Current overrides keyed by post ID. + * @param {number} postId Post the edit belongs to. + * @param {Object} changes Fields to change. + * @return {Object} New overrides. + */ +export function setOverride( overrides, postId, changes ) { + const next = { + ...( overrides || {} ), + [ postId ]: { ...( overrides?.[ postId ] || {} ), ...changes }, + }; + + Object.keys( next[ postId ] ).forEach( ( field ) => { + if ( ! next[ postId ][ field ] ) { + delete next[ postId ][ field ]; + } + } ); + + if ( ! Object.keys( next[ postId ] ).length ) { + delete next[ postId ]; + } + + return next; +} + +/** + * Drop edits for posts that are no longer listed. + * + * @param {Object} overrides Overrides keyed by post ID. + * @param {number[]} listedIds Post IDs in the roundup now. + * @return {Object} Overrides for listed posts only. + */ +export function pruneOverrides( overrides, listedIds ) { + return Object.keys( overrides || {} ).reduce( + ( kept, id ) => + listedIds.includes( Number( id ) ) + ? { ...kept, [ id ]: overrides[ id ] } + : kept, + {} + ); +} + +/** + * Escape plain text so it can be used as RichText content. + * + * @param {string} text Plain text. + * @return {string} HTML-safe text. + */ +export function escapeText( text ) { + return String( text || '' ) + .replace( /&/g, '&' ) + .replace( //g, '>' ); +} From 61e9afa647e88ef7fbba96ec3f451657dbc14bc2 Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Tue, 17 Nov 2026 22:27:33 +0800 Subject: [PATCH 06/10] Test the Post Roundup card display, edits, layout and nested use --- tests/e2e/specs/post-roundup-block.spec.js | 362 +++++++++++++++++++ tests/phpunit/PostRoundupTest.php | 397 +++++++++++++++++++++ 2 files changed, 759 insertions(+) diff --git a/tests/e2e/specs/post-roundup-block.spec.js b/tests/e2e/specs/post-roundup-block.spec.js index c64fe62..cf660b0 100644 --- a/tests/e2e/specs/post-roundup-block.spec.js +++ b/tests/e2e/specs/post-roundup-block.spec.js @@ -699,3 +699,365 @@ test.describe( 'US-002: send the roundup to beehiiv', () => { expect( later ).toBeTruthy(); } ); } ); + +// --------------------------------------------------------------------------- +test.describe( 'US-003: choose and edit what each card shows', () => { + const attributesOf = ( page ) => + page.evaluate( ( name ) => { + const block = window.wp.data + .select( 'core/block-editor' ) + .getBlocks() + .find( ( item ) => item.name === name ); + return block ? block.attributes : null; + }, BLOCK ); + + test( 'AC-008: the author chooses which items cards show, in the editor and in what is sent', async ( { + page, + } ) => { + await loginAsAdmin( page ); + seed(); + const id = createItem( { + title: 'QA RR display AC-008', + type: TYPE, + status: 'draft', + content: roundupBlock( { + mode: 'manual', + uid: 'ac008', + posts: [ { id: Number( postIds.p2 ), type: 'post' } ], + display: { + image: false, + title: true, + excerpt: false, + button: true, + }, + } ), + meta: { [ META_SEND ]: '1' }, + } ); + + await openEditor( page, `/wp-admin/post.php?post=${ id }&action=edit` ); + const canvas = page.frameLocator( 'iframe[name="editor-canvas"]' ); + const block = canvas.locator( `[data-type="${ BLOCK }"]` ); + const card = block.locator( '.beehiiv-post-roundup__card' ); + await expect( card ).toHaveCount( 1 ); + await expect( card.locator( 'img' ) ).toHaveCount( 0 ); + await expect( + card.locator( '.beehiiv-post-roundup__excerpt' ) + ).toHaveCount( 0 ); + await expect( + card.locator( '.beehiiv-post-roundup__title' ) + ).toHaveText( 'QA RR Post Two' ); + await expect( + card.locator( '.beehiiv-post-roundup__button' ) + ).toHaveText( 'Read more' ); + + // Turning the excerpt and image on shows them in the editor. + await block.click(); + await openSettingsSidebar( page ); + await page.getByRole( 'checkbox', { name: 'Excerpt' } ).check(); + await page.getByRole( 'checkbox', { name: 'Featured image' } ).check(); + await expect( card.locator( 'img' ) ).toBeVisible(); + await expect( + card.locator( '.beehiiv-post-roundup__excerpt' ) + ).toHaveText( 'QA RR excerpt two' ); + + // Turning everything off warns the author. + for ( const name of [ + 'Featured image', + 'Title', + 'Excerpt', + 'Read more button', + ] ) { + await page.getByRole( 'checkbox', { name } ).uncheck(); + } + await expect( + page.locator( '.components-notice__content', { + hasText: 'nothing is sent for this roundup', + } ) + ).toBeVisible(); + expect( ( await attributesOf( page ) ).display ).toEqual( { + image: false, + title: false, + excerpt: false, + button: false, + } ); + + // What is sent follows the stored choices: no image, no excerpt. + const rest = await restAsAdmin( page ); + const res = await rest( 'POST', `/wp/v2/${ REST_BASE }/${ id }`, { + status: 'publish', + content: roundupBlock( { + mode: 'manual', + uid: 'ac008', + posts: [ { id: Number( postIds.p2 ), type: 'post' } ], + display: { + image: false, + title: true, + excerpt: false, + button: true, + }, + } ), + } ); + expect( res.status ).toBe( 200 ); + const sent = creates( getLog() ).pop().body.blocks; + const json = JSON.stringify( sent ); + expect( json ).toContain( 'QA RR Post Two' ); + expect( json ).toContain( 'Read more' ); + expect( json ).not.toContain( 'QA RR excerpt two' ); + expect( json ).not.toContain( 'qa-e2e-roundup' ); + expect( sent.map( ( item ) => item.type ) ).toEqual( [ + 'paragraph', + 'button', + ] ); + } ); + + test( 'AC-009: the author edits a card, resets it, and the edits reach beehiiv without changing the post', async ( { + page, + } ) => { + await loginAsAdmin( page ); + seed(); + const id = createItem( { + title: 'QA RR edit AC-009', + type: TYPE, + status: 'draft', + content: roundupBlock( { + mode: 'manual', + uid: 'ac009', + posts: [ { id: Number( postIds.p1 ), type: 'post' } ], + } ), + meta: { [ META_SEND ]: '1' }, + } ); + + await openEditor( page, `/wp-admin/post.php?post=${ id }&action=edit` ); + const canvas = page.frameLocator( 'iframe[name="editor-canvas"]' ); + const card = canvas.locator( '.beehiiv-post-roundup__card' ); + await expect( card ).toHaveCount( 1 ); + + const edit = async ( locator, text ) => { + await locator.click(); + await page.keyboard.press( 'ControlOrMeta+A' ); + await page.keyboard.type( text ); + }; + await edit( + card.locator( '.beehiiv-post-roundup__title a' ), + 'RR Edited headline' + ); + await edit( + card.locator( '.beehiiv-post-roundup__excerpt' ), + 'RR Edited summary' + ); + await edit( + card.locator( '.beehiiv-post-roundup__button' ), + 'RR Keep reading' + ); + + await expect + .poll( async () => ( await attributesOf( page ) ).overrides ) + .toEqual( { + [ postIds.p1 ]: { + title: 'RR Edited headline', + excerpt: 'RR Edited summary', + buttonLabel: 'RR Keep reading', + }, + } ); + const stored = ( await attributesOf( page ) ).overrides; + + // The edits are part of the saved newsletter and survive a reload. + await page.keyboard.press( 'ControlOrMeta+S' ); + await expect + .poll( () => wpCli( `post get ${ id } --field=post_content` ) ) + .toContain( 'RR Edited headline' ); + await openEditor( page, `/wp-admin/post.php?post=${ id }&action=edit` ); + await expect( + canvas.locator( '.beehiiv-post-roundup__title a' ) + ).toHaveText( 'RR Edited headline' ); + + // Sending carries the edited text; the link is still the post's own. + const rest = await restAsAdmin( page ); + const res = await rest( 'POST', `/wp/v2/${ REST_BASE }/${ id }`, { + status: 'publish', + } ); + expect( res.status ).toBe( 200 ); + const json = JSON.stringify( creates( getLog() ).pop().body.blocks ); + expect( json ).toContain( 'RR Edited headline' ); + expect( json ).toContain( 'RR Edited summary' ); + expect( json ).toContain( 'RR Keep reading' ); + expect( json ).not.toContain( 'QA RR excerpt one' ); + expect( json ).toContain( + wpCli( `post get ${ postIds.p1 } --field=url` ) + ); + + // The source post is unchanged. + expect( wpCli( `post get ${ postIds.p1 } --field=post_title` ) ).toBe( + 'QA RR Post One' + ); + expect( wpCli( `post get ${ postIds.p1 } --field=post_excerpt` ) ).toBe( + 'QA RR excerpt one' + ); + expect( stored ).toBeTruthy(); + + // Reset to post restores the post's own values and drops the edits. + await openEditor( page, `/wp-admin/post.php?post=${ id }&action=edit` ); + await canvas.locator( '.beehiiv-post-roundup__reset' ).click(); + await expect( + canvas.locator( '.beehiiv-post-roundup__title a' ) + ).toHaveText( 'QA RR Post One' ); + await expect( + canvas.locator( '.beehiiv-post-roundup__button' ) + ).toHaveText( 'Read more' ); + expect( ( await attributesOf( page ) ).overrides ).toEqual( {} ); + } ); +} ); + +// --------------------------------------------------------------------------- +test.describe( 'US-004: choose how each card is laid out', () => { + test( 'AC-010: the author picks a card layout and image placement, in the editor and in what is sent', async ( { + page, + } ) => { + await loginAsAdmin( page ); + seed(); + const content = ( extra ) => + roundupBlock( { + mode: 'manual', + uid: 'ac010', + posts: [ { id: Number( postIds.p2 ), type: 'post' } ], + ...extra, + } ); + const id = createItem( { + title: 'QA RR layout AC-010', + type: TYPE, + status: 'draft', + content: content( {} ), + meta: { [ META_SEND ]: '1' }, + } ); + + await openEditor( page, `/wp-admin/post.php?post=${ id }&action=edit` ); + const canvas = page.frameLocator( 'iframe[name="editor-canvas"]' ); + const block = canvas.locator( `[data-type="${ BLOCK }"]` ); + const card = block.locator( '.beehiiv-post-roundup__card' ); + const image = card.locator( '.beehiiv-post-roundup__media' ); + const body = card.locator( '.beehiiv-post-roundup__body' ); + await expect( card ).toHaveCount( 1 ); + + // Full: the image sits above the text and placement cannot be changed. + await block.click(); + await openSettingsSidebar( page ); + await expect( + page.getByRole( 'button', { name: 'Full', exact: true } ) + ).toHaveAttribute( 'aria-pressed', 'true' ); + await expect( + page.getByRole( 'button', { name: 'Right', exact: true } ) + ).toBeDisabled(); + const above = { + image: await image.boundingBox(), + body: await body.boundingBox(), + }; + expect( above.image.y ).toBeLessThan( above.body.y ); + + // 30:70 with the image on the left. + await page + .getByRole( 'button', { name: '30:70', exact: true } ) + .click(); + await expect( card ).toHaveClass( /beehiiv-post-roundup__card--split/ ); + await expect( + page.getByRole( 'button', { name: 'Right', exact: true } ) + ).toBeEnabled(); + let boxes = { + card: await card.boundingBox(), + image: await image.boundingBox(), + body: await body.boundingBox(), + }; + expect( boxes.image.x ).toBeLessThan( boxes.body.x ); + expect( boxes.image.width / boxes.card.width ).toBeGreaterThan( 0.25 ); + expect( boxes.image.width / boxes.card.width ).toBeLessThan( 0.35 ); + + // 70:30 with the image on the right. + await page + .getByRole( 'button', { name: '70:30', exact: true } ) + .click(); + await page + .getByRole( 'button', { name: 'Right', exact: true } ) + .click(); + await expect( card ).toHaveClass( + /beehiiv-post-roundup__card--image-right/ + ); + boxes = { + card: await card.boundingBox(), + image: await image.boundingBox(), + body: await body.boundingBox(), + }; + expect( boxes.image.x ).toBeGreaterThan( boxes.body.x ); + expect( Math.abs( boxes.image.y - boxes.body.y ) ).toBeLessThan( 4 ); + expect( boxes.image.width / boxes.card.width ).toBeGreaterThan( 0.65 ); + expect( boxes.image.width / boxes.card.width ).toBeLessThan( 0.75 ); + + const attrs = await page.evaluate( ( name ) => { + const found = window.wp.data + .select( 'core/block-editor' ) + .getBlocks() + .find( ( item ) => item.name === name ); + return { + layout: found.attributes.layout, + imagePlacement: found.attributes.imagePlacement, + }; + }, BLOCK ); + expect( attrs ).toEqual( { layout: '70-30', imagePlacement: 'right' } ); + + // What is sent: two columns, text first, image second, widths 30 and 70. + const rest = await restAsAdmin( page ); + const res = await rest( 'POST', `/wp/v2/${ REST_BASE }/${ id }`, { + status: 'publish', + content: content( { layout: '70-30', imagePlacement: 'right' } ), + } ); + expect( res.status ).toBe( 200 ); + const sent = creates( getLog() ).pop().body.blocks; + expect( sent.map( ( item ) => item.type ) ).toEqual( [ 'columns' ] ); + const [ first, second ] = sent[ 0 ].columns; + expect( first.verticalAlign ).toBe( 'top' ); + expect( second.verticalAlign ).toBe( 'top' ); + expect( first.width ).toBe( 30 ); + expect( first.blocks.map( ( item ) => item.type ) ).toEqual( [ + 'paragraph', + 'paragraph', + 'button', + ] ); + expect( second.width ).toBe( 70 ); + expect( second.blocks.map( ( item ) => item.type ) ).toEqual( [ + 'image', + ] ); + expect( JSON.stringify( second ) ).toContain( 'qa-e2e-roundup' ); + } ); +} ); + +// --------------------------------------------------------------------------- +test.describe( 'Roundup inside other blocks', () => { + test( 'a roundup inside a Columns block shows its cards and does not error', async ( { + page, + } ) => { + await loginAsAdmin( page ); + seed(); + const id = createItem( { + title: 'QA RR nested', + type: TYPE, + status: 'draft', + content: `
${ roundupBlock( + { + mode: 'manual', + uid: 'nested1', + posts: [ { id: Number( postIds.p2 ), type: 'post' } ], + } + ) }
`, + } ); + + const errors = []; + page.on( 'pageerror', ( error ) => errors.push( error.message ) ); + await openEditor( page, `/wp-admin/post.php?post=${ id }&action=edit` ); + const canvas = page.frameLocator( 'iframe[name="editor-canvas"]' ); + await expect( + canvas.locator( '.beehiiv-post-roundup__card' ) + ).toHaveCount( 1 ); + await expect( + canvas.getByText( 'This block has encountered an error' ) + ).toHaveCount( 0 ); + expect( errors ).toEqual( [] ); + } ); +} ); diff --git a/tests/phpunit/PostRoundupTest.php b/tests/phpunit/PostRoundupTest.php index 9d4460f..841efae 100644 --- a/tests/phpunit/PostRoundupTest.php +++ b/tests/phpunit/PostRoundupTest.php @@ -853,4 +853,401 @@ public function test_block_key_uses_the_stored_id_or_the_position(): void { $this->assertSame( 'n4', PostRoundup::block_key( array(), 4 ) ); $this->assertSame( 'n0', PostRoundup::block_key( array( 'uid' => '' ), 0 ) ); } + + /* ----------------------------------------------- AC-008 and AC-009 display and edits. */ + + /** + * Every card item is shown when the block stores no display choice. + */ + public function test_every_item_is_shown_by_default(): void { + $this->assertSame( + array( + 'image' => true, + 'title' => true, + 'excerpt' => true, + 'button' => true, + ), + PostRoundup::display( array() ) + ); + $this->assertFalse( PostRoundup::display( array( 'display' => array( 'excerpt' => false ) ) )['excerpt'] ); + $this->assertTrue( PostRoundup::display( array( 'display' => array( 'excerpt' => false ) ) )['title'] ); + } + + /** + * Turned-off items are not sent, and the others still are, in order. + */ + public function test_turned_off_items_are_left_out_of_the_send(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $this->add_featured_image( $one, 'alpha.jpg' ); + + $attrs = array( 'count' => 1 ); + + $cases = array( + 'image' => array( 'paragraph', 'paragraph', 'button' ), + 'title' => array( 'image', 'paragraph', 'button' ), + 'excerpt' => array( 'image', 'paragraph', 'button' ), + 'button' => array( 'image', 'paragraph', 'paragraph' ), + ); + + foreach ( $cases as $item => $expected ) { + $blocks = $this->convert( + $this->create_newsletter( + $this->roundup( array_merge( $attrs, array( 'display' => array( $item => false ) ) ) ) + ) + ); + + $this->assertSame( $expected, $this->types( $blocks ), 'Turning off ' . $item ); + } + + $titleless = $this->convert( + $this->create_newsletter( + $this->roundup( array_merge( $attrs, array( 'display' => array( 'title' => false ) ) ) ) + ) + ); + $this->assertSame( 'Excerpt of Alpha story', $titleless[1]['plaintext'] ); + $this->assertArrayNotHasKey( 'formattedText', $titleless[1] ); + } + + /** + * A roundup with every item off sends nothing, and no stray separators. + */ + public function test_every_item_off_sends_nothing_for_the_roundup(): void { + $this->create_article( 'Alpha story', 1 ); + $this->create_article( 'Beta story', 2 ); + + $display = array( + 'image' => false, + 'title' => false, + 'excerpt' => false, + 'button' => false, + ); + + $blocks = $this->convert( + $this->create_newsletter( + $this->paragraph( 'Intro' ) . $this->roundup( array( 'count' => 2, 'display' => $display ) ) + ) + ); + + $this->assertSame( array( 'paragraph' ), $this->types( $blocks ) ); + } + + /** + * Edited title, excerpt and button label reach beehiiv, the link stays the post's own, + * and the source post is untouched. + */ + public function test_card_edits_replace_the_posts_text_and_never_change_the_post(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $two = $this->create_article( 'Beta story', 2 ); + + $overrides = array( + (string) $one => array( + 'title' => 'A better headline', + 'excerpt' => 'A shorter summary.', + 'buttonLabel' => 'Keep reading', + ), + ); + + $blocks = $this->convert( + $this->create_newsletter( $this->roundup( array( 'count' => 2, 'overrides' => $overrides ) ) ) + ); + + $this->assertSame( 'A better headline', $blocks[0]['formattedText'][0]['text'] ?? wp_json_encode( $blocks[0] ) ); + $this->assertStringContainsString( 'A better headline', wp_json_encode( $blocks[0] ) ); + $this->assertSame( get_permalink( $one ), $blocks[0]['formattedText'][0]['link']['href'] ); + $this->assertSame( 'A shorter summary.', $blocks[1]['plaintext'] ); + $this->assertSame( 'Keep reading', $blocks[2]['text'] ); + $this->assertSame( get_permalink( $one ), $blocks[2]['href'] ); + + // The second post keeps its own values. + $this->assertStringContainsString( 'Beta story', wp_json_encode( $blocks[4] ) ); + $this->assertSame( 'Read more', $blocks[6]['text'] ); + + // The source post is unchanged. + $this->assertSame( 'Alpha story', get_the_title( $one ) ); + $this->assertSame( 'Excerpt of Alpha story', get_post( $one )->post_excerpt ); + $this->assertSame( 'Beta story', get_the_title( $two ) ); + } + + /** + * A cleared edit falls back to the post's own value. + */ + public function test_empty_edits_fall_back_to_the_post(): void { + $one = $this->create_article( 'Alpha story', 1 ); + + $overrides = array( + (string) $one => array( + 'title' => ' ', + 'excerpt' => '', + 'buttonLabel' => ' ', + ), + ); + + $blocks = $this->convert( + $this->create_newsletter( $this->roundup( array( 'count' => 1, 'overrides' => $overrides ) ) ) + ); + + $this->assertStringContainsString( 'Alpha story', wp_json_encode( $blocks[0] ) ); + $this->assertSame( 'Excerpt of Alpha story', $blocks[1]['plaintext'] ); + $this->assertSame( 'Read more', $blocks[2]['text'] ); + } + + /** + * Edits are plain text: markup is stripped and entities are decoded. + */ + public function test_edits_are_sanitized_to_plain_text(): void { + $one = $this->create_article( 'Alpha story', 1 ); + + $overrides = PostRoundup::overrides( + array( + 'overrides' => array( + (string) $one => array( + 'title' => 'Fish & Chips', + 'excerpt' => '

Tidy

', + 'buttonLabel' => 'Go
now', + 'imageId' => 'abc', + ), + '0' => array( 'title' => 'Ignored' ), + 'bad' => array( 'title' => 'Ignored' ), + ), + ) + ); + + $this->assertSame( array( $one ), array_keys( $overrides ) ); + $this->assertSame( 'Fish & Chips', $overrides[ $one ]['title'] ); + $this->assertSame( 'Tidy', $overrides[ $one ]['excerpt'] ); + $this->assertSame( 'Go now', $overrides[ $one ]['button_label'] ); + $this->assertSame( 0, $overrides[ $one ]['image_id'] ); + } + + /** + * An edited image replaces the featured image; an invalid or deleted one falls back to it. + */ + public function test_edited_image_replaces_the_featured_image_and_invalid_ids_fall_back(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $this->add_featured_image( $one, 'alpha.jpg' ); + + $chosen = self::factory()->attachment->create( + array( + 'post_mime_type' => 'image/jpeg', + 'file' => 'chosen.jpg', + ) + ); + update_post_meta( $chosen, '_wp_attachment_image_alt', 'Alt of chosen' ); + + $blocks = $this->convert( + $this->create_newsletter( + $this->roundup( array( 'count' => 1, 'overrides' => array( (string) $one => array( 'imageId' => $chosen ) ) ) ) + ) + ); + $this->assertStringContainsString( 'chosen.jpg', $blocks[0]['imageUrl'] ); + $this->assertSame( 'Alt of chosen', $blocks[0]['alt_text'] ); + $this->assertSame( get_permalink( $one ), $blocks[0]['url'] ); + + // A post ID is not an image attachment, so the featured image stays. + $not_image = $this->create_article( 'Not an image', 5 ); + $blocks = $this->convert( + $this->create_newsletter( + $this->roundup( array( 'count' => 1, 'overrides' => array( (string) $one => array( 'imageId' => $not_image ) ) ) ) + ) + ); + $this->assertStringContainsString( 'alpha.jpg', $blocks[0]['imageUrl'] ); + + // A deleted attachment also falls back. + wp_delete_attachment( $chosen, true ); + $blocks = $this->convert( + $this->create_newsletter( + $this->roundup( array( 'count' => 1, 'overrides' => array( (string) $one => array( 'imageId' => $chosen ) ) ) ) + ) + ); + $this->assertStringContainsString( 'alpha.jpg', $blocks[0]['imageUrl'] ); + } + + /** + * A card with no featured image can still get an edited image. + */ + public function test_edited_image_is_added_to_a_post_without_a_featured_image(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $chosen = self::factory()->attachment->create( + array( + 'post_mime_type' => 'image/jpeg', + 'file' => 'chosen.jpg', + ) + ); + + $blocks = $this->convert( + $this->create_newsletter( + $this->roundup( array( 'count' => 1, 'overrides' => array( (string) $one => array( 'imageId' => $chosen ) ) ) ) + ) + ); + + $this->assertSame( 'image', $blocks[0]['type'] ); + $this->assertStringContainsString( 'chosen.jpg', $blocks[0]['imageUrl'] ); + } + + /** + * Edits follow the post, not its position, and work in manual mode. + */ + public function test_edits_follow_the_post_in_manual_mode(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $two = $this->create_article( 'Beta story', 2 ); + + $blocks = $this->convert( + $this->create_newsletter( + $this->roundup( + array( + 'mode' => 'manual', + 'posts' => array( array( 'id' => $two ), array( 'id' => $one ) ), + 'overrides' => array( (string) $one => array( 'buttonLabel' => 'Open it' ) ), + ) + ) + ) + ); + + // Order is Beta then Alpha; only Alpha's button changed. + $this->assertSame( 'Read more', $blocks[2]['text'] ); + $this->assertSame( 'Open it', $blocks[6]['text'] ); + } + + /** + * The preview data carries the default button label for the editor to show. + */ + public function test_cards_carry_the_default_button_label(): void { + $one = $this->create_article( 'Alpha story', 1 ); + + $this->assertSame( 'Read more', PostRoundup::cards( array( $one ) )[0]['button_label'] ); + } + + /* ------------------------------------------------------------ AC-010 card layout. */ + + /** + * Layout defaults to full width and image placement to the left. + */ + public function test_layout_defaults_to_full_and_placement_to_left(): void { + $this->assertSame( 'full', PostRoundup::layout( array() ) ); + $this->assertSame( 'full', PostRoundup::layout( array( 'layout' => '40-60' ) ) ); + $this->assertSame( '30-70', PostRoundup::layout( array( 'layout' => '30-70' ) ) ); + $this->assertSame( 'left', PostRoundup::image_placement( array() ) ); + $this->assertSame( 'left', PostRoundup::image_placement( array( 'imagePlacement' => 'up' ) ) ); + $this->assertSame( 'right', PostRoundup::image_placement( array( 'imagePlacement' => 'right' ) ) ); + } + + /** + * Full keeps the image above the text, as before. + */ + public function test_full_layout_keeps_the_image_above_the_text(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $this->add_featured_image( $one, 'alpha.jpg' ); + + $blocks = $this->convert( + $this->create_newsletter( $this->roundup( array( 'count' => 1, 'layout' => 'full', 'imagePlacement' => 'right' ) ) ) + ); + + $this->assertSame( array( 'image', 'paragraph', 'paragraph', 'button' ), $this->types( $blocks ) ); + } + + /** + * A split layout sends the image and the text as two columns with the ratio as widths. + */ + public function test_split_layouts_send_two_columns_at_the_ratio(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $this->add_featured_image( $one, 'alpha.jpg' ); + + $cases = array( + '50-50' => array( 50, 50 ), + '30-70' => array( 30, 70 ), + '70-30' => array( 70, 30 ), + ); + + foreach ( $cases as $layout => $widths ) { + foreach ( array( 'left', 'right' ) as $placement ) { + $blocks = $this->convert( + $this->create_newsletter( + $this->roundup( array( 'count' => 1, 'layout' => $layout, 'imagePlacement' => $placement ) ) + ) + ); + + $this->assertSame( array( 'columns' ), $this->types( $blocks ), "$layout $placement" ); + $this->assertTrue( $blocks[0]['stackOnMobile'] ); + $this->assertSame( array( 'top', 'top' ), array_column( $blocks[0]['columns'], 'verticalAlign' ) ); + + $columns = $blocks[0]['columns']; + $this->assertCount( 2, $columns ); + + $image_at = 'left' === $placement ? 0 : 1; + $text_at = 1 - $image_at; + + $this->assertSame( array( 'image' ), array_column( $columns[ $image_at ]['blocks'], 'type' ) ); + $this->assertSame( $widths[0], $columns[ $image_at ]['width'], "$layout $placement image width" ); + $this->assertSame( + array( 'paragraph', 'paragraph', 'button' ), + array_column( $columns[ $text_at ]['blocks'], 'type' ) + ); + $this->assertSame( $widths[1], $columns[ $text_at ]['width'], "$layout $placement text width" ); + $this->assertStringContainsString( 'alpha.jpg', $columns[ $image_at ]['blocks'][0]['imageUrl'] ); + $this->assertArrayNotHasKey( 'imageAlignment', $columns[ $image_at ]['blocks'][0] ); + } + } + } + + /** + * A card with no image stays full width, and cards are separated as before. + */ + public function test_split_layout_falls_back_for_cards_without_an_image(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $two = $this->create_article( 'Beta story', 2 ); + $this->add_featured_image( $one, 'alpha.jpg' ); + + $blocks = $this->convert( + $this->create_newsletter( $this->roundup( array( 'count' => 2, 'layout' => '30-70' ) ) ) + ); + + $this->assertSame( + array( 'columns', 'content_break', 'paragraph', 'paragraph', 'button' ), + $this->types( $blocks ) + ); + $this->assertSame( get_permalink( $two ), $blocks[4]['href'] ); + } + + /** + * Hidden items and a hidden image leave the card full width. + */ + public function test_split_layout_respects_the_display_choices(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $this->add_featured_image( $one, 'alpha.jpg' ); + + $without_image = $this->convert( + $this->create_newsletter( + $this->roundup( array( 'count' => 1, 'layout' => '50-50', 'display' => array( 'image' => false ) ) ) + ) + ); + $this->assertSame( array( 'paragraph', 'paragraph', 'button' ), $this->types( $without_image ) ); + + $image_only = $this->convert( + $this->create_newsletter( + $this->roundup( + array( + 'count' => 1, + 'layout' => '50-50', + 'display' => array( + 'title' => false, + 'excerpt' => false, + 'button' => false, + ), + ) + ) + ) + ); + $this->assertSame( array( 'image' ), $this->types( $image_only ) ); + + $no_button = $this->convert( + $this->create_newsletter( + $this->roundup( array( 'count' => 1, 'layout' => '70-30', 'display' => array( 'button' => false ) ) ) + ) + ); + $this->assertSame( array( 'columns' ), $this->types( $no_button ) ); + $this->assertSame( + array( 'paragraph', 'paragraph' ), + array_column( $no_button[0]['columns'][1]['blocks'], 'type' ) + ); + } } From ed9b9cc7739ee4ffaad255cb65c4dd18add8fc93 Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Tue, 17 Nov 2026 22:32:35 +0800 Subject: [PATCH 07/10] Allow the email preview for newsletters --- includes/Newsletter/PreviewEligibility.php | 2 +- tests/phpunit/NewsletterEmailPreviewTest.php | 22 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/includes/Newsletter/PreviewEligibility.php b/includes/Newsletter/PreviewEligibility.php index 3151579..9a7ec01 100644 --- a/includes/Newsletter/PreviewEligibility.php +++ b/includes/Newsletter/PreviewEligibility.php @@ -34,7 +34,7 @@ final class PreviewEligibility { public static function check( int $post_id ) { $post = get_post( $post_id ); - if ( ! $post instanceof WP_Post || 'post' !== $post->post_type ) { + if ( ! $post instanceof WP_Post || ! ContentTypes::is_supported( $post->post_type ) ) { return new WP_Error( 'beehiiv_post_not_found', __( 'This post no longer exists. Save or reload the editor and try again.', 'beehiiv' ) diff --git a/tests/phpunit/NewsletterEmailPreviewTest.php b/tests/phpunit/NewsletterEmailPreviewTest.php index 1dc46b5..ac5591a 100644 --- a/tests/phpunit/NewsletterEmailPreviewTest.php +++ b/tests/phpunit/NewsletterEmailPreviewTest.php @@ -7,6 +7,7 @@ use Beehiiv\Config; use Beehiiv\Editor\Meta; +use Beehiiv\Newsletter\ContentTypes; use Beehiiv\Newsletter\EmailPreview; use Beehiiv\OAuth\TokenStore; use Beehiiv\REST\EmailPreviewController; @@ -241,6 +242,27 @@ public function test_preview_creates_draft_then_returns_rendered_email(): void { $this->assertStringContainsString( 'expand=free_email_content', $this->requests[2]['url'] ); } + /** + * A newsletter (the Newsletters content type) can be previewed like a post. + */ + public function test_a_newsletter_can_be_previewed(): void { + $post_id = self::factory()->post->create( + [ + 'post_type' => ContentTypes::NEWSLETTER, + 'post_status' => 'draft', + 'post_title' => 'Campaign', + 'post_content' => "\n

Hello subscribers.

\n", + ] + ); + update_post_meta( $post_id, Meta::SEND_TO_NEWSLETTER, '1' ); + + $result = EmailPreview::render( $post_id ); + + $this->assertSame( 'Rendered', $result['html'] ); + $this->assertContains( 'POST /posts', $this->request_log() ); + $this->assertSame( 'draft', get_post_meta( $post_id, Meta::BEEHIIV_POST_STATE, true ) ); + } + /** * AC-003, AC-007: every preview syncs the same draft again and fetches again. */ From b1dd25b945d8139d56ba0df7223a6666a185c33c Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Tue, 17 Nov 2026 23:46:11 +0800 Subject: [PATCH 08/10] Send a Post Roundup inside Columns and Group blocks and keep cards in a column free of separators --- includes/Newsletter/BlockConverter.php | 46 +++++++++++++++++---- includes/Newsletter/PostRoundup.php | 19 ++++++--- includes/Newsletter/PostRoundupSnapshot.php | 43 +++++++++++++++---- src/js/blocks/post-roundup/edit.js | 30 +++++++++++--- 4 files changed, 110 insertions(+), 28 deletions(-) diff --git a/includes/Newsletter/BlockConverter.php b/includes/Newsletter/BlockConverter.php index 34d7460..87b63b8 100644 --- a/includes/Newsletter/BlockConverter.php +++ b/includes/Newsletter/BlockConverter.php @@ -103,6 +103,7 @@ public static function convert_supported_blocks( WP_Post $post_object, bool $con * @param WP_Post $post_object Post object. * @param bool $is_send_newsletter_snippet Whether snippet mode is enabled. * @param bool $convert_groups Whether Group blocks become sections. + * @param bool $is_nested Whether the blocks sit inside a layout block. * @return array> * @since 1.0.0 */ @@ -110,7 +111,8 @@ private static function convert_blocks( array $wp_blocks, WP_Post $post_object, bool $is_send_newsletter_snippet, - bool $convert_groups = false + bool $convert_groups = false, + bool $is_nested = false ): array { $beehiiv_blocks = []; $roundup_ordinal = 0; @@ -143,7 +145,7 @@ private static function convert_blocks( if ( PostRoundup::BLOCK === $block_name ) { $attrs = (array) ( $wp_block['attrs'] ?? [] ); - $key = PostRoundup::block_key( $attrs, $roundup_ordinal++ ); + $key = PostRoundup::block_key( $attrs, $is_nested ? null : $roundup_ordinal++ ); // A roundup left in a regular post is ignored. if ( ContentTypes::is_newsletter( $post_object->post_type ) ) { @@ -168,7 +170,10 @@ private static function convert_blocks( } if ( 'core/columns' === $block_name ) { - $beehiiv_blocks = array_merge( $beehiiv_blocks, self::convert_columns_block_to_blocks( $wp_block ) ); + $beehiiv_blocks = array_merge( + $beehiiv_blocks, + self::convert_columns_block_to_blocks( $wp_block, $post_object ) + ); continue; } @@ -203,7 +208,8 @@ private static function convert_group_block( array $wp_block, WP_Post $post_obje $wp_block['innerBlocks'] ?? [], $post_object, false, - false + false, + true ); if ( empty( $inner_blocks ) ) { @@ -632,11 +638,12 @@ public static function convert_columns_block( array $wp_block ): array { * block nested inside a column is not converted to a columns block: its inner * blocks follow the outer columns block at the top level. * - * @param array $wp_block Parsed block. + * @param array $wp_block Parsed block. + * @param WP_Post|null $post_object Post being converted. Lets a Post Roundup inside a column expand. * @return array> * @since 1.2.0 */ - public static function convert_columns_block_to_blocks( array $wp_block ): array { + public static function convert_columns_block_to_blocks( array $wp_block, ?WP_Post $post_object = null ): array { if ( 'core/columns' !== ( $wp_block['blockName'] ?? '' ) ) { return []; } @@ -658,7 +665,8 @@ public static function convert_columns_block_to_blocks( array $wp_block ): array $column_blocks[] = $column_block; $converted_columns[] = self::convert_layout_block_inner_blocks( $column_block['innerBlocks'] ?? [], - $nested_blocks + $nested_blocks, + $post_object ); } @@ -708,14 +716,20 @@ public static function convert_columns_block_to_blocks( array $wp_block ): array * added to it for the caller to emit at the top level. Without it, the nested block * is omitted. * + * A Post Roundup expands in place when the post is a newsletter. Its cards are sent + * full width with no separators between cards, because a beehiiv column cannot hold + * another columns block and a divider inside a column is not known to be accepted. + * * @param array> $wp_blocks Parsed inner blocks. * @param array>|null $nested_blocks Receives the inner blocks of nested columns. + * @param WP_Post|null $post_object Post being converted. * @return array> * @since 1.0.0 */ private static function convert_layout_block_inner_blocks( array $wp_blocks, - ?array &$nested_blocks = null + ?array &$nested_blocks = null, + ?WP_Post $post_object = null ): array { $beehiiv_blocks = []; @@ -732,7 +746,8 @@ private static function convert_layout_block_inner_blocks( if ( 'core/column' === ( $nested_column['blockName'] ?? '' ) ) { $nested_converted = self::convert_layout_block_inner_blocks( $nested_column['innerBlocks'] ?? [], - $nested_blocks + $nested_blocks, + $post_object ); $nested_blocks = array_merge( $nested_blocks, $nested_converted ); } @@ -742,6 +757,19 @@ private static function convert_layout_block_inner_blocks( continue; } + if ( PostRoundup::BLOCK === $block_name ) { + if ( $post_object instanceof WP_Post && ContentTypes::is_newsletter( $post_object->post_type ) ) { + $attrs = (array) ( $wp_block['attrs'] ?? [] ); + $attrs['layout'] = PostRoundup::LAYOUT_FULL; + + $beehiiv_blocks = array_merge( + $beehiiv_blocks, + PostRoundup::expand( $attrs, $post_object->ID, PostRoundup::block_key( $attrs, null ), false ) + ); + } + continue; + } + if ( 'core/buttons' === $block_name ) { $beehiiv_blocks = array_merge( $beehiiv_blocks, self::convert_buttons_block( $wp_block ) ); continue; diff --git a/includes/Newsletter/PostRoundup.php b/includes/Newsletter/PostRoundup.php index 7383d2d..c4c0c82 100644 --- a/includes/Newsletter/PostRoundup.php +++ b/includes/Newsletter/PostRoundup.php @@ -236,17 +236,23 @@ public static function resolve_ids( array $attrs, int $post_id, string $key ): a } /** - * Snapshot key of a top-level roundup block: its stored id, else its position. + * Snapshot key of a roundup block: its stored id, else its position among the + * top-level roundups. A roundup inside a layout block has no stable position, so + * without a stored id it is keyed by its own settings. * * @param array $attrs Block attributes. - * @param int $ordinal Position among the roundup blocks. + * @param int|null $ordinal Position among the top-level roundups, null when nested. * @return string * @since x.x.x */ - public static function block_key( array $attrs, int $ordinal ): string { + public static function block_key( array $attrs, ?int $ordinal ): string { $uid = isset( $attrs['uid'] ) ? sanitize_key( (string) $attrs['uid'] ) : ''; - return '' !== $uid ? $uid : 'n' . $ordinal; + if ( '' !== $uid ) { + return $uid; + } + + return null === $ordinal ? 'x' . substr( md5( (string) wp_json_encode( $attrs ) ), 0, 8 ) : 'n' . $ordinal; } /** @@ -445,10 +451,11 @@ public static function apply_settings( array $cards, array $attrs ): array { * @param array $attrs Block attributes. * @param int $post_id Newsletter post ID. * @param string $key Snapshot key of the block. + * @param bool $separate Whether to put a separator between cards. Off inside a column. * @return array> * @since x.x.x */ - public static function expand( array $attrs, int $post_id, string $key ): array { + public static function expand( array $attrs, int $post_id, string $key, bool $separate = true ): array { $blocks = []; $cards = self::apply_settings( self::cards( self::resolve_ids( $attrs, $post_id, $key ) ), $attrs ); @@ -461,7 +468,7 @@ public static function expand( array $attrs, int $post_id, string $key ): array continue; } - if ( ! empty( $blocks ) ) { + if ( $separate && ! empty( $blocks ) ) { $blocks[] = [ 'type' => 'content_break' ]; } diff --git a/includes/Newsletter/PostRoundupSnapshot.php b/includes/Newsletter/PostRoundupSnapshot.php index 311e236..58714a8 100644 --- a/includes/Newsletter/PostRoundupSnapshot.php +++ b/includes/Newsletter/PostRoundupSnapshot.php @@ -42,15 +42,10 @@ public static function freeze( WP_Post $post ): void { $existing = self::get( $post->ID ); $next = []; - $ordinal = 0; - foreach ( parse_blocks( $post->post_content ) as $block ) { - if ( PostRoundup::BLOCK !== ( $block['blockName'] ?? '' ) ) { - continue; - } - - $attrs = (array) ( $block['attrs'] ?? [] ); - $key = PostRoundup::block_key( $attrs, $ordinal++ ); + foreach ( self::find_roundups( parse_blocks( $post->post_content ) ) as $roundup ) { + $attrs = $roundup['attrs']; + $key = $roundup['key']; if ( PostRoundup::MODE_AUTO !== PostRoundup::mode( $attrs ) ) { continue; @@ -74,6 +69,38 @@ public static function freeze( WP_Post $post ): void { update_post_meta( $post->ID, Meta::ROUNDUP_SNAPSHOT, $next ); } + /** + * Every roundup in the blocks, including those inside layout blocks, with its key. + * + * Top-level roundups are keyed like the converter keys them, by position when they + * have no stored id. Nested roundups are keyed by stored id or by their settings. + * + * @param array> $blocks Parsed blocks. + * @param bool $is_nested Whether the blocks sit inside another block. + * @return array, key: string}> + */ + private static function find_roundups( array $blocks, bool $is_nested = false ): array { + $found = []; + $ordinal = 0; + + foreach ( $blocks as $block ) { + if ( PostRoundup::BLOCK === ( $block['blockName'] ?? '' ) ) { + $attrs = (array) ( $block['attrs'] ?? [] ); + $found[] = [ + 'attrs' => $attrs, + 'key' => PostRoundup::block_key( $attrs, $is_nested ? null : $ordinal++ ), + ]; + continue; + } + + if ( ! empty( $block['innerBlocks'] ) ) { + $found = array_merge( $found, self::find_roundups( (array) $block['innerBlocks'], true ) ); + } + } + + return $found; + } + /** * Frozen post IDs for a block, when one exists for the given count. * diff --git a/src/js/blocks/post-roundup/edit.js b/src/js/blocks/post-roundup/edit.js index 6665623..c27adfe 100644 --- a/src/js/blocks/post-roundup/edit.js +++ b/src/js/blocks/post-roundup/edit.js @@ -231,7 +231,7 @@ export default function Edit( { attributes, setAttributes, clientId } ) { const display = getDisplay( attributes ); const showsNothing = Object.values( display ).every( ( shown ) => ! shown ); - const { postId, firstUidClientId } = useSelect( + const { postId, firstUidClientId, isInColumn } = useSelect( ( select ) => { // Look at every block, not only the top level: the roundup can sit // inside layout blocks such as Columns. @@ -243,12 +243,19 @@ export default function Edit( { attributes, setAttributes, clientId } ) { return { postId: select( 'core/editor' )?.getCurrentPostId(), + // A beehiiv column cannot hold another columns block, so a roundup + // inside a column is always sent with full-width cards. + isInColumn: editor + .getBlockParents( clientId ) + .some( + ( id ) => editor.getBlockName( id ) === 'core/column' + ), firstUidClientId: roundups.find( ( block ) => block.attributes.uid === uid )?.clientId, }; }, - [ uid ] + [ uid, clientId ] ); // Each roundup needs its own id so its frozen list is kept apart from others. @@ -300,6 +307,17 @@ export default function Edit( { attributes, setAttributes, clientId } ) { const blockProps = useBlockProps(); + const columnNotice = isInColumn && ( + + { __( + 'Inside a Columns block, cards are sent full width.', + 'beehiiv' + ) } + + ); + + const cardLayout = isInColumn ? LAYOUT_FULL : layout; + let preview; if ( isLoading && ! cards.length ) { @@ -328,7 +346,7 @@ export default function Edit( { attributes, setAttributes, clientId } ) { key={ card.id } card={ card } display={ display } - layout={ layout } + layout={ cardLayout } imagePlacement={ imagePlacement } override={ overrides?.[ card.id ] } onChange={ ( changes ) => @@ -357,6 +375,7 @@ export default function Edit( { attributes, setAttributes, clientId } ) { title={ __( 'Post Roundup', 'beehiiv' ) } initialOpen > + { columnNotice } setAttributes( { layout: value } ) } @@ -425,7 +445,7 @@ export default function Edit( { attributes, setAttributes, clientId } ) { label={ __( 'Image placement', 'beehiiv' ) } options={ PLACEMENT_OPTIONS } value={ imagePlacement } - disabled={ layout === LAYOUT_FULL } + disabled={ cardLayout === LAYOUT_FULL } onChange={ ( value ) => setAttributes( { imagePlacement: value } ) } From d6493e98318c0f0ef752b8ccd0fb78ed6c294e3e Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Tue, 17 Nov 2026 23:46:12 +0800 Subject: [PATCH 09/10] Check the newsletter search results for its own title instead of the echoed query --- tests/e2e/specs/newsletters-content-type.spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/e2e/specs/newsletters-content-type.spec.js b/tests/e2e/specs/newsletters-content-type.spec.js index be020ac..0186900 100644 --- a/tests/e2e/specs/newsletters-content-type.spec.js +++ b/tests/e2e/specs/newsletters-content-type.spec.js @@ -389,8 +389,12 @@ test.describe( 'US-002: keep newsletters off the public site', () => { } // Site search. + // The search page echoes the query in its title, so look for the + // newsletter's own title and body, not the bare marker. const search = await request.get( `/?s=${ marker }` ); - expect( await search.text() ).not.toContain( marker ); + const searchText = await search.text(); + expect( searchText ).not.toContain( `${ marker } newsletter` ); + expect( searchText ).not.toContain( `${ marker } body` ); // Feeds. for ( const url of [ From e6db99fbc358c5a7d11562dee30c85bc13fb81b3 Mon Sep 17 00:00:00 2001 From: Jeffrey Carandang Date: Tue, 17 Nov 2026 23:46:12 +0800 Subject: [PATCH 10/10] Test the Post Roundup inside Columns and Group blocks --- tests/e2e/specs/post-roundup-block.spec.js | 81 ++++++++++++++++-- tests/phpunit/PostRoundupTest.php | 97 ++++++++++++++++++++++ 2 files changed, 170 insertions(+), 8 deletions(-) diff --git a/tests/e2e/specs/post-roundup-block.spec.js b/tests/e2e/specs/post-roundup-block.spec.js index cf660b0..8d8c321 100644 --- a/tests/e2e/specs/post-roundup-block.spec.js +++ b/tests/e2e/specs/post-roundup-block.spec.js @@ -1030,22 +1030,26 @@ test.describe( 'US-004: choose how each card is laid out', () => { // --------------------------------------------------------------------------- test.describe( 'Roundup inside other blocks', () => { + const inColumn = ( extra = {} ) => + `
${ roundupBlock( + { + mode: 'manual', + uid: 'nested1', + posts: [ { id: Number( postIds.p2 ), type: 'post' } ], + ...extra, + } + ) }

RR-BESIDE

`; + test( 'a roundup inside a Columns block shows its cards and does not error', async ( { page, } ) => { await loginAsAdmin( page ); seed(); const id = createItem( { - title: 'QA RR nested', + title: 'QA RR nested editor', type: TYPE, status: 'draft', - content: `
${ roundupBlock( - { - mode: 'manual', - uid: 'nested1', - posts: [ { id: Number( postIds.p2 ), type: 'post' } ], - } - ) }
`, + content: inColumn(), } ); const errors = []; @@ -1058,6 +1062,67 @@ test.describe( 'Roundup inside other blocks', () => { await expect( canvas.getByText( 'This block has encountered an error' ) ).toHaveCount( 0 ); + + // The author is told cards are full width inside a column. + await canvas.locator( `[data-type="${ BLOCK }"]` ).click(); + await openSettingsSidebar( page ); + await expect( + page.locator( '.components-notice__content', { + hasText: 'cards are sent full width', + } ) + ).toBeVisible(); + await expect( + page.getByRole( 'button', { name: '30:70', exact: true } ) + ).toBeDisabled(); expect( errors ).toEqual( [] ); } ); + + test( 'a roundup inside a Columns block and a Group block is sent to beehiiv', async ( { + page, + } ) => { + await loginAsAdmin( page ); + seed(); + const id = createItem( { + title: 'QA RR nested send', + type: TYPE, + status: 'draft', + content: [ + // A split layout is sent full width inside a column. + inColumn( { layout: '30-70' } ), + `
${ roundupBlock( { + mode: 'manual', + uid: 'nested2', + posts: [ { id: Number( postIds.p1 ), type: 'post' } ], + } ) }
`, + ].join( '\n' ), + meta: { [ META_SEND ]: '1' }, + } ); + const rest = await restAsAdmin( page ); + const res = await rest( 'POST', `/wp/v2/${ REST_BASE }/${ id }`, { + status: 'publish', + } ); + expect( res.status ).toBe( 200 ); + + const sent = creates( getLog() ).pop().body.blocks; + const columns = sent.find( ( item ) => item.type === 'columns' ); + expect( columns ).toBeTruthy(); + + // The roundup is in the first column, full width: image, title, excerpt, button. + const first = JSON.stringify( columns.columns[ 0 ] ); + expect( first ).toContain( 'QA RR Post Two' ); + expect( first ).toContain( 'QA RR excerpt two' ); + expect( first ).toContain( 'Read more' ); + expect( + columns.columns[ 0 ].blocks.map( ( item ) => item.type ) + ).toEqual( [ 'image', 'paragraph', 'paragraph', 'button' ] ); + expect( JSON.stringify( columns.columns[ 1 ] ) ).toContain( + 'RR-BESIDE' + ); + + // The roundup in the Group is inside the beehiiv section. + const section = sent.find( ( item ) => item.type === 'section' ); + expect( section ).toBeTruthy(); + expect( JSON.stringify( section ) ).toContain( 'QA RR Post One' ); + expect( JSON.stringify( section ) ).toContain( 'QA RR excerpt one' ); + } ); } ); diff --git a/tests/phpunit/PostRoundupTest.php b/tests/phpunit/PostRoundupTest.php index 841efae..840c54f 100644 --- a/tests/phpunit/PostRoundupTest.php +++ b/tests/phpunit/PostRoundupTest.php @@ -1250,4 +1250,101 @@ public function test_split_layout_respects_the_display_choices(): void { array_column( $no_button[0]['columns'][1]['blocks'], 'type' ) ); } + + /** + * A roundup inside a column is expanded in place, full width even for a split layout. + */ + public function test_roundup_inside_a_column_is_expanded_full_width(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $this->add_featured_image( $one, 'alpha.jpg' ); + + $columns = '
' + . $this->roundup( array( 'count' => 1, 'layout' => '30-70', 'uid' => 'inside' ) ) + . '
' + . $this->paragraph( 'Beside' ) . '
'; + + $blocks = $this->convert( $this->create_newsletter( $columns ) ); + + $this->assertSame( array( 'columns' ), $this->types( $blocks ) ); + $this->assertSame( + array( 'image', 'paragraph', 'paragraph', 'button' ), + array_column( $blocks[0]['columns'][0]['blocks'], 'type' ) + ); + $this->assertStringContainsString( 'Alpha story', wp_json_encode( $blocks[0]['columns'][0] ) ); + $this->assertStringContainsString( 'Beside', wp_json_encode( $blocks[0]['columns'][1] ) ); + } + + /** + * Cards inside a column follow each other with no separator between them. + */ + public function test_roundup_inside_a_column_has_no_separators_between_cards(): void { + $this->create_article( 'Alpha story', 1 ); + $this->create_article( 'Beta story', 2 ); + + $columns = '
' + . $this->roundup( array( 'count' => 2, 'uid' => 'twocards' ) ) + . '
'; + + $blocks = $this->convert( $this->create_newsletter( $columns ) ); + + $this->assertSame( + array( 'paragraph', 'paragraph', 'button', 'paragraph', 'paragraph', 'button' ), + array_column( $blocks[0]['columns'][0]['blocks'], 'type' ) + ); + + // At the top level the separator stays. + $top = $this->convert( $this->create_newsletter( $this->roundup( array( 'count' => 2 ) ) ) ); + $this->assertContains( 'content_break', $this->types( $top ) ); + } + + /** + * A roundup inside a group is expanded inside the section and keeps its layout. + */ + public function test_roundup_inside_a_group_is_expanded_inside_the_section(): void { + $one = $this->create_article( 'Alpha story', 1 ); + $this->add_featured_image( $one, 'alpha.jpg' ); + + $group = '
' + . $this->roundup( array( 'count' => 1, 'uid' => 'ingroup' ) ) + . '
'; + + $blocks = BlockConverter::convert_supported_blocks( get_post( $this->create_newsletter( $group ) ), true ); + + $this->assertSame( array( 'section' ), $this->types( $blocks ) ); + $this->assertSame( + array( 'image', 'paragraph', 'paragraph', 'button' ), + array_column( $blocks[0]['blocks'], 'type' ) + ); + } + + /** + * An automatic roundup in a column is frozen at send like a top-level one. + */ + public function test_nested_automatic_roundup_is_frozen_at_send(): void { + $old = $this->create_article( 'Old story', 2 ); + + $columns = '
' + . $this->roundup( array( 'count' => 1, 'uid' => 'frozen1' ) ) + . '
'; + $post = get_post( $this->create_newsletter( $columns ) ); + + PostRoundupSnapshot::freeze( $post ); + $this->create_article( 'Newer story', 0 ); + + $json = wp_json_encode( $this->convert( $post->ID ) ); + $this->assertStringContainsString( 'Old story', $json ); + $this->assertStringNotContainsString( 'Newer story', $json ); + $this->assertSame( array( $old ), PostRoundupSnapshot::ids_for( $post->ID, 'frozen1', 1 ) ); + } + + /** + * Without a stored id a nested roundup is keyed by its settings, a top-level one by position. + */ + public function test_block_key_for_nested_roundups_without_an_id_is_stable(): void { + $attrs = array( 'count' => 2 ); + + $this->assertSame( PostRoundup::block_key( $attrs, null ), PostRoundup::block_key( $attrs, null ) ); + $this->assertNotSame( PostRoundup::block_key( $attrs, null ), PostRoundup::block_key( array( 'count' => 3 ), null ) ); + $this->assertSame( 'n1', PostRoundup::block_key( $attrs, 1 ) ); + } }