From b96d3d9766e90b98c2ccfecf0f8b6a3e70db9c97 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Fri, 10 Nov 2023 19:02:29 -0600 Subject: [PATCH 1/3] WIP: issue-39 From 80f638265c217dbc5d2f0ab16b50b497c38a83c1 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Mon, 13 Nov 2023 10:04:00 -0600 Subject: [PATCH 2/3] update post display options --- blocks/post/edit.tsx | 182 ++++++++++++++++++++++++++----------------- 1 file changed, 112 insertions(+), 70 deletions(-) diff --git a/blocks/post/edit.tsx b/blocks/post/edit.tsx index b39ab0e3..846b677e 100644 --- a/blocks/post/edit.tsx +++ b/blocks/post/edit.tsx @@ -3,7 +3,7 @@ * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/ */ -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import { ImagePicker, PostPicker } from '@alleyinteractive/block-editor-tools'; import { useSelect } from '@wordpress/data'; import { @@ -14,6 +14,9 @@ import { Spinner, TextControl, } from '@wordpress/components'; +import { arrayMoveImmutable } from 'array-move'; + +import SortableList, { SortableItem, SortableKnob } from 'react-easy-sort'; /** * React hook that is used to mark the block wrapper element. @@ -92,6 +95,47 @@ export default function Edit({ }); }; + const isShown = (item: string) => { + switch (item) { + case 'image': + return showImage; + case 'title': + return true; + case 'byline': + return showByline; + case 'excerpt': + return showExcerpt; + case 'content': + return showContent; + case 'cta': + return showCta; + default: + return false; + } + }; + + const toggleShown = (item: string) => { + switch (item) { + case 'image': + setAttributes({ showImage: !showImage }); + break; + case 'byline': + setAttributes({ showByline: !showByline }); + break; + case 'excerpt': + setAttributes({ showExcerpt: !showExcerpt }); + break; + case 'content': + setAttributes({ showContent: !showContent }); + break; + case 'cta': + setAttributes({ showCta: !showCta }); + break; + default: + break; + } + }; + const removeLinks = (html: string) => ( html ? html.replace(/]*?>(.*?)<\/a>/gi, '$1') : '' ); @@ -130,6 +174,15 @@ export default function Edit({ const titleClass = smallerFont ? 'post__title--small' : ''; + const onSortEnd = (oldIndex: number, newIndex: number) => { + const newOrder = arrayMoveImmutable( + [...order as string[]], // eslint-disable-line camelcase + oldIndex, + newIndex, + ); + setAttributes({ order: newOrder }); + }; + return (
{postId && !record ? ( @@ -225,59 +278,62 @@ export default function Edit({ return ''; } })} - - {/* @ts-ignore */} - + ) : ( +
+ {/* @ts-ignore */} + handleSelect(0)} + params={{ after: cutoff.toISOString(), per_page: 20 }} + title={__('Please select a post', 'wp-newsletter-builder')} + value={postId} + // @ts-ignore + searchRender={PostPickerResult} + /> +
+ )} + + {/* @ts-ignore */} + + + - {/* @ts-ignore */} - - {/* @ts-ignore */} - setAttributes({ showImage: value })} - /> - - {/* @ts-ignore */} - - {/* @ts-ignore */} - setAttributes({ showByline: value })} - /> - - {/* @ts-ignore */} - - {/* @ts-ignore */} - setAttributes({ showExcerpt: value })} - /> - - {/* @ts-ignore */} - - {/* @ts-ignore */} - setAttributes({ showContent: value })} - /> - - {/* @ts-ignore */} - - {/* @ts-ignore */} - setAttributes({ showCta: value })} - /> - - - {/* @ts-ignore */} + {order.map((item) => ( + +
+ + + :: + + + {item === 'title' ? ( +

{__('Title', 'wp-newsletter-builder')}

+ ) : ( + toggleShown(item)} + /> + )} +
+
+ ))} + + +
+ {postId ? ( + <> -
- - ) : ( -
- {/* @ts-ignore */} - handleSelect(0)} - params={{ after: cutoff.toISOString(), per_page: 20 }} - title={__('Please select a post', 'wp-newsletter-builder')} - value={postId} - // @ts-ignore - searchRender={PostPickerResult} - /> -
- )} + + ) : null} +
); } From 9c7b9bc53ca9c17b0e4a7d7f8919a81fb6225f54 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Mon, 13 Nov 2023 12:29:07 -0600 Subject: [PATCH 3/3] version info --- CHANGELOG.md | 4 ++++ plugin.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 714492c6..d24bba5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `Newsletter Builder` will be documented in this file. +## 0.3.4 - 2023-11-13 + +- Allow editing of post block attributes with no block selected. Allow order attribute to be edited. + ## 0.3.3 - 2023-11-10 - Add URL override attribute and slotfill to post block diff --git a/plugin.php b/plugin.php index d153ac92..8c6b5ec5 100644 --- a/plugin.php +++ b/plugin.php @@ -3,7 +3,7 @@ * Plugin Name: Newsletter Builder * Plugin URI: https://github.com/alleyinteractive/wp-newsletter-builder * Description: Interface to manage email newsletters - * Version: 0.3.3 + * Version: 0.3.4 * Author: Alley Interactive * Author URI: https://github.com/alleyinteractive/wp-newsletter-builder * Requires at least: 5.9