From 9c7a6bb6a40b1554c8b243535ed08ddee14f4970 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 7 Mar 2023 15:14:36 -0500 Subject: [PATCH 001/123] add coauthors and coauthor-display-name blocks --- blocks/coauthor-display-name/build/block.json | 20 ++++ .../build/index.asset.php | 1 + blocks/coauthor-display-name/build/index.js | 1 + .../class-cap-block-coauthor-display-name.php | 40 +++++++ blocks/coauthor-display-name/package.json | 5 + blocks/coauthor-display-name/src/block.json | 18 +++ blocks/coauthor-display-name/src/edit.js | 24 ++++ blocks/coauthor-display-name/src/index.js | 24 ++++ blocks/coauthors/build/block.json | 18 +++ blocks/coauthors/build/index.asset.php | 1 + blocks/coauthors/build/index.js | 1 + .../coauthors/class-cap-block-coauthors.php | 109 ++++++++++++++++++ blocks/coauthors/package.json | 5 + blocks/coauthors/src/block.json | 16 +++ blocks/coauthors/src/edit.js | 100 ++++++++++++++++ blocks/coauthors/src/index.js | 30 +++++ ...emoized-coauthor-template-block-preview.js | 41 +++++++ blocks/coauthors/src/save.js | 22 ++++ 18 files changed, 476 insertions(+) create mode 100644 blocks/coauthor-display-name/build/block.json create mode 100644 blocks/coauthor-display-name/build/index.asset.php create mode 100644 blocks/coauthor-display-name/build/index.js create mode 100644 blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php create mode 100644 blocks/coauthor-display-name/package.json create mode 100644 blocks/coauthor-display-name/src/block.json create mode 100644 blocks/coauthor-display-name/src/edit.js create mode 100644 blocks/coauthor-display-name/src/index.js create mode 100644 blocks/coauthors/build/block.json create mode 100644 blocks/coauthors/build/index.asset.php create mode 100644 blocks/coauthors/build/index.js create mode 100644 blocks/coauthors/class-cap-block-coauthors.php create mode 100644 blocks/coauthors/package.json create mode 100644 blocks/coauthors/src/block.json create mode 100644 blocks/coauthors/src/edit.js create mode 100644 blocks/coauthors/src/index.js create mode 100644 blocks/coauthors/src/modules/memoized-coauthor-template-block-preview.js create mode 100644 blocks/coauthors/src/save.js diff --git a/blocks/coauthor-display-name/build/block.json b/blocks/coauthor-display-name/build/block.json new file mode 100644 index 00000000..b99ebc49 --- /dev/null +++ b/blocks/coauthor-display-name/build/block.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "cap/coauthor-display-name", + "version": "0.1.0", + "title": "Co-Author Display Name", + "category": "widgets", + "icon": "smiley", + "description": "Display a co-author's preferred name.", + "supports": { + "html": false + }, + "usesContext": [ + "displayName" + ], + "textdomain": "co-authors-plus", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css" +} \ No newline at end of file diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php new file mode 100644 index 00000000..44e74ebf --- /dev/null +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-element'), 'version' => '38aff22fcae65c52b6fb'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js new file mode 100644 index 00000000..edc18fe2 --- /dev/null +++ b/blocks/coauthor-display-name/build/index.js @@ -0,0 +1 @@ +!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,o=window.wp.blockEditor,n=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(n.u2,{edit:function(e){let{context:n}=e;const{displayName:c}=n;return(0,t.createElement)("p",(0,o.useBlockProps)(),c)}})}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php new file mode 100644 index 00000000..e6e4e67e --- /dev/null +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -0,0 +1,40 @@ + array( __CLASS__, 'render_block' ), + ) + ); + } + /** + * Render Block + * + * @param array $attributes + * @param string $content + * @param WP_Block $block + * @return string + */ + public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + return array_key_exists( 'displayName', $block->context ) ? $block->context['displayName'] : ''; + } +} diff --git a/blocks/coauthor-display-name/package.json b/blocks/coauthor-display-name/package.json new file mode 100644 index 00000000..b6abf47a --- /dev/null +++ b/blocks/coauthor-display-name/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "build": "../../node_modules/.bin/wp-scripts build" + } +} diff --git a/blocks/coauthor-display-name/src/block.json b/blocks/coauthor-display-name/src/block.json new file mode 100644 index 00000000..4eb92c75 --- /dev/null +++ b/blocks/coauthor-display-name/src/block.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "cap/coauthor-display-name", + "version": "0.1.0", + "title": "Co-Author Display Name", + "category": "widgets", + "icon": "smiley", + "description": "Display a co-author's preferred name.", + "supports": { + "html": false + }, + "usesContext": [ "displayName" ], + "textdomain": "co-authors-plus", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css" +} \ No newline at end of file diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js new file mode 100644 index 00000000..ecd13e61 --- /dev/null +++ b/blocks/coauthor-display-name/src/edit.js @@ -0,0 +1,24 @@ +/** + * React hook that is used to mark the block wrapper element. + * It provides all the necessary props like the class name. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops + */ +import { useBlockProps } from '@wordpress/block-editor'; + +/** + * The edit function describes the structure of your block in the context of the + * editor. This represents what the editor will render when the block is used. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit + * + * @return {WPElement} Element to render. + */ +export default function Edit( { context } ) { + const { displayName } = context; + return ( +

+ { displayName } +

+ ); +} diff --git a/blocks/coauthor-display-name/src/index.js b/blocks/coauthor-display-name/src/index.js new file mode 100644 index 00000000..252c391e --- /dev/null +++ b/blocks/coauthor-display-name/src/index.js @@ -0,0 +1,24 @@ +/** + * Registers a new block provided a unique name and an object defining its behavior. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +import { registerBlockType } from '@wordpress/blocks'; + +/** + * Internal dependencies + */ +import Edit from './edit'; +import metadata from './block.json'; + +/** + * Every block starts by registering a new block type definition. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +registerBlockType( metadata.name, { + /** + * @see ./edit.js + */ + edit: Edit +} ); diff --git a/blocks/coauthors/build/block.json b/blocks/coauthors/build/block.json new file mode 100644 index 00000000..2f9c2a4c --- /dev/null +++ b/blocks/coauthors/build/block.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "cap/coauthors", + "version": "0.1.0", + "title": "Co-Authors", + "category": "widgets", + "icon": "smiley", + "description": "Display the co-authors for a post.", + "supports": { + "html": false + }, + "usesContext": [ + "postId" + ], + "textdomain": "co-authors-plus", + "editorScript": "file:./index.js" +} \ No newline at end of file diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php new file mode 100644 index 00000000..2509fc94 --- /dev/null +++ b/blocks/coauthors/build/index.asset.php @@ -0,0 +1 @@ + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element'), 'version' => 'cdf92359799aa426a7f3'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js new file mode 100644 index 00000000..cf25b0cb --- /dev/null +++ b/blocks/coauthors/build/index.js @@ -0,0 +1 @@ +!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t=window.wp.blocks,n=window.wp.element,o=window.wp.blockEditor,r=window.wp.apiFetch,c=e.n(r),a=window.wp.data;function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t{a(r)},u={display:c?"none":void 0};return(0,n.createElement)("div",l({},s,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:u}))}));function i(){return(0,n.createElement)("div",(0,o.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}var u=JSON.parse('{"u2":"cap/coauthors"}');(0,t.registerBlockType)(u.u2,{edit:function(e){let{clientId:t,context:r}=e;const{postId:l}=r,[u,d]=(0,n.useState)([]),[p,b]=(0,n.useState)(),m=(0,a.useDispatch)("core/notices");function v(e){"AbortError"!==e.name&&m.createErrorNotice(e.message,{isDismissible:!0})}(0,n.useEffect)((()=>{const e=new AbortController;return c()({path:`/coauthors/v1/authors/${l}`,signal:e.signal}).then(d).catch(v),()=>{e.abort()}}),[l]);const w=(0,a.useSelect)((e=>e(o.store).getBlocks(t)));return(0,n.createElement)("div",(0,o.useBlockProps)(),u&&u.map((e=>{var t;let{id:r,displayName:c}=e;const a=r===(p||(null===(t=u[0])||void 0===t?void 0:t.id));return(0,n.createElement)(o.BlockContextProvider,{key:r,value:{coAuthorId:r,displayName:c}},a?(0,n.createElement)(i,null):null,(0,n.createElement)(s,{blocks:w,blockContextId:r,setActiveBlockContextId:b,isHidden:a}))})))},save:function(){return(0,n.createElement)(o.InnerBlocks.Content,null)}})}(); \ No newline at end of file diff --git a/blocks/coauthors/class-cap-block-coauthors.php b/blocks/coauthors/class-cap-block-coauthors.php new file mode 100644 index 00000000..4bb04a30 --- /dev/null +++ b/blocks/coauthors/class-cap-block-coauthors.php @@ -0,0 +1,109 @@ + array( __CLASS__, 'render_block' ), + ) + ); + } + /** + * Render Block + * + * @param array $attributes + * @param string $content + * @param WP_Block $block + * @return string + */ + public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + $post_id = array_key_exists( 'postId', $block->context ) ? absint( $block->context['postId'] ) : 0; + + if ( 0 === $post_id ) { + return ''; + } + + $authors = get_coauthors( $post_id ); + + if ( ! is_array( $authors ) || empty( $authors ) ) { + return ''; + } + + $author_blocks = array_map( + self::get_block_wrapper_function('div', 'class="wp-block-cap-coauthor"'), + array_map( + self::get_template_render_function( + self::get_block_as_template( $block ) + ), + $authors + ) + ); + + return self::get_block_wrapper_function('div', get_block_wrapper_attributes())(implode("\n", $author_blocks)); + } + + /** + * Get Block Wrapper Function + * + * @param string $element_name + * @param string $attributes + * @return callable + */ + private static function get_block_wrapper_function( string $element_name, string $attributes ) : callable { + return function( string $content ) use ( $element_name, $attributes ) : string { + return "<{$element_name} {$attributes}>{$content}"; + }; + } + + /** + * Get Template Render Function + * + * @param array $block_template + * @return callable + */ + private static function get_template_render_function( array $block_template ) : callable { + return function( stdClass|WP_User $author ) use ( $block_template ) : string { + return ( + new WP_Block( + $block_template, + array( + 'displayName' => $author->display_name, + ) + ) + )->render( array( 'dynamic' => false ) ); + }; + } + + /** + * Get Block as Template + * + * @param WP_Block $block + * @return array + */ + private static function get_block_as_template( WP_Block $block ) : array { + return array_merge( + $block->parsed_block, + array( + 'blockName' => 'core/null' + ) + ); + } +} diff --git a/blocks/coauthors/package.json b/blocks/coauthors/package.json new file mode 100644 index 00000000..b6abf47a --- /dev/null +++ b/blocks/coauthors/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "build": "../../node_modules/.bin/wp-scripts build" + } +} diff --git a/blocks/coauthors/src/block.json b/blocks/coauthors/src/block.json new file mode 100644 index 00000000..dcd72f08 --- /dev/null +++ b/blocks/coauthors/src/block.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "cap/coauthors", + "version": "0.1.0", + "title": "Co-Authors", + "category": "widgets", + "icon": "smiley", + "description": "Display the co-authors for a post.", + "supports": { + "html": false + }, + "usesContext": [ "postId" ], + "textdomain": "co-authors-plus", + "editorScript": "file:./index.js" +} diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js new file mode 100644 index 00000000..b38f0ccf --- /dev/null +++ b/blocks/coauthors/src/edit.js @@ -0,0 +1,100 @@ +/** + * React hook that is used to mark the block wrapper element. + * It provides all the necessary props like the class name. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops + */ +import { + BlockContextProvider, + useBlockProps, + useInnerBlocksProps, + store as blockEditorStore, +} from '@wordpress/block-editor'; + +import apiFetch from '@wordpress/api-fetch'; +import { useSelect, useDispatch } from '@wordpress/data'; +import { useState, useEffect } from '@wordpress/element'; +import MemoizedCoAuthorTemplateBlockPreview from './modules/memoized-coauthor-template-block-preview'; + +/** + * CoAuthor Template Inner Blocks + */ +function CoAuthorTemplateInnerBlocks () { + return
; +} + +/** + * The edit function describes the structure of your block in the context of the + * editor. This represents what the editor will render when the block is used. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit + * + * @return {WPElement} Element to render. + */ +export default function Edit( { clientId, context } ) { + + const { postId } = context; + const [ coAuthors, setCoAuthors ] = useState([]); + const [ activeBlockContextId, setActiveBlockContextId ] = useState(); + const noticesDispatch = useDispatch('core/notices'); + + useEffect(()=>{ + const controller = new AbortController(); + + apiFetch( { + path: `/coauthors/v1/authors/${postId}`, + signal: controller.signal + } ) + .then( setCoAuthors ) + .catch( handleError ) + + return () => { + controller.abort(); + } + },[postId]); + + /** + * Handle Error + * + * @param {Error} + */ + function handleError( error ) { + if ( 'AbortError' === error.name ) { + return; + } + noticesDispatch.createErrorNotice( error.message, { isDismissible: true } ); + } + + const blocks = useSelect( (select) => { + return select( blockEditorStore ).getBlocks( clientId ); + }); + + return ( +
+ { + coAuthors && + coAuthors.map( ( { id, displayName } ) => { + const isHidden = id === ( activeBlockContextId || coAuthors[0]?.id ); + return ( + + { isHidden ? () : null } + + + ) + } + ) + } +
+ ); +} diff --git a/blocks/coauthors/src/index.js b/blocks/coauthors/src/index.js new file mode 100644 index 00000000..a719f8dc --- /dev/null +++ b/blocks/coauthors/src/index.js @@ -0,0 +1,30 @@ +/** + * Registers a new block provided a unique name and an object defining its behavior. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +import { registerBlockType } from '@wordpress/blocks'; + +/** + * Internal dependencies + */ +import Edit from './edit'; +import save from './save'; +import metadata from './block.json'; + +/** + * Every block starts by registering a new block type definition. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +registerBlockType( metadata.name, { + /** + * @see ./edit.js + */ + edit: Edit, + + /** + * @see ./save.js + */ + save, +} ); diff --git a/blocks/coauthors/src/modules/memoized-coauthor-template-block-preview.js b/blocks/coauthors/src/modules/memoized-coauthor-template-block-preview.js new file mode 100644 index 00000000..a61c84a9 --- /dev/null +++ b/blocks/coauthors/src/modules/memoized-coauthor-template-block-preview.js @@ -0,0 +1,41 @@ +import { memo } from '@wordpress/element'; +import { __experimentalUseBlockPreview as useBlockPreview } from '@wordpress/block-editor'; + +/** + * CoAuthor Template Block Preview + */ +function CoAuthorTemplateBlockPreview({ + blocks, + blockContextId, + isHidden, + setActiveBlockContextId, +}) { + + const blockPreviewProps = useBlockPreview( { + blocks, + props: { + className: 'wp-block-cap-coauthor', + }, + } ); + + const handleOnClick = () => { + setActiveBlockContextId( blockContextId ); + }; + + const style = { + display: isHidden ? 'none' : undefined, + }; + + return ( +
+ ); +} + +export default memo( CoAuthorTemplateBlockPreview ); diff --git a/blocks/coauthors/src/save.js b/blocks/coauthors/src/save.js new file mode 100644 index 00000000..6745b81e --- /dev/null +++ b/blocks/coauthors/src/save.js @@ -0,0 +1,22 @@ +/** + * React hook that is used to mark the block wrapper element. + * It provides all the necessary props like the class name. + * + * @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps + */ +import { InnerBlocks } from '@wordpress/block-editor'; + +/** + * The save function defines the way in which the different attributes should + * be combined into the final markup, which is then serialized by the block + * editor into `post_content`. + * + * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save + * + * @return {WPElement} Element to render. + */ +export default function save() { + return ( + + ); +} From 2efcc43bd9006bec77460539038712ff393e856f Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 7 Mar 2023 15:15:08 -0500 Subject: [PATCH 002/123] instantiate block classes --- co-authors-plus.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index a6719e93..ba7fdce7 100755 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -34,6 +34,9 @@ require_once __DIR__ . '/php/class-coauthors-plus.php'; require_once __DIR__ . '/php/class-coauthors-iterator.php'; +require_once dirname( __FILE__ ) . '/blocks/coauthors/class-cap-block-coauthors.php'; +require_once dirname( __FILE__ ) . '/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php'; + if ( defined( 'WP_CLI' ) && WP_CLI ) { require_once __DIR__ . '/php/class-wp-cli.php'; } @@ -42,6 +45,9 @@ $coauthors_plus = new CoAuthors_Plus(); $coauthors_endpoint = new CoAuthors\API\Endpoints( $coauthors_plus ); +new CAP_Block_CoAuthors(); +new CAP_Block_CoAuthor_Display_Name(); + if ( ! function_exists( 'wp_notify_postauthor' ) ) : /** * Notify a co-author of a comment/trackback/pingback to one of their posts. From a2fb1c0341e79674cec84c5183990b0eed5fa8e9 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 7 Mar 2023 15:24:24 -0500 Subject: [PATCH 003/123] wrap display name in something, start with p --- .../class-cap-block-coauthor-display-name.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index e6e4e67e..41e35509 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -35,6 +35,10 @@ public static function register_block() : void { * @return string */ public static function render_block( array $attributes, string $content, WP_Block $block ) : string { - return array_key_exists( 'displayName', $block->context ) ? $block->context['displayName'] : ''; + $display_name = array_key_exists( 'displayName', $block->context ) ? $block->context['displayName'] : ''; + if ( '' === $display_name ) { + return ''; + } + return "

{$display_name}

"; } } From 15cc2d265afd0d1b57f395be36b9ef842ce28d6c Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 17 Jul 2023 19:53:12 -0400 Subject: [PATCH 004/123] wip: support separators; inline and block layouts --- blocks/coauthor-display-name/build/block.json | 30 +++- .../class-cap-block-coauthor-display-name.php | 3 +- blocks/coauthor-display-name/src/block.json | 28 +++- blocks/coauthors/build/block.json | 46 +++++- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- blocks/coauthors/build/style-index.css | 1 + .../coauthors/class-cap-block-coauthors.php | 142 +++++++++++++++++- blocks/coauthors/src/block.json | 46 +++++- blocks/coauthors/src/edit.js | 139 ++++++++++++++--- blocks/coauthors/src/index.js | 5 + blocks/coauthors/src/style.css | 4 + 12 files changed, 407 insertions(+), 41 deletions(-) create mode 100644 blocks/coauthors/build/style-index.css create mode 100644 blocks/coauthors/src/style.css diff --git a/blocks/coauthor-display-name/build/block.json b/blocks/coauthor-display-name/build/block.json index b99ebc49..7095d386 100644 --- a/blocks/coauthor-display-name/build/block.json +++ b/blocks/coauthor-display-name/build/block.json @@ -7,8 +7,36 @@ "category": "widgets", "icon": "smiley", "description": "Display a co-author's preferred name.", + "parent": [ + "cap/coauthors" + ], "supports": { - "html": false + "html": false, + "color": { + "link": true, + "text": true, + "background": true, + "__experimentalDefaultControls": {} + }, + "typography": { + "fontSize": true, + "lineHeight": true, + "__experimentalFontFamily": true, + "__experimentalTextDecoration": true, + "__experimentalFontStyle": true, + "__experimentalFontWeight": true, + "__experimentalLetterSpacing": true, + "__experimentalTextTransform": true, + "__experimentalDefaultControls": {} + }, + "spacing": { + "margin": true, + "padding": true, + "__experimentalDefaultControls": { + "margin": false, + "padding": false + } + } }, "usesContext": [ "displayName" diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index 41e35509..d926d4eb 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -39,6 +39,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc if ( '' === $display_name ) { return ''; } - return "

{$display_name}

"; + $attributes = get_block_wrapper_attributes(); + return "

{$display_name}

"; } } diff --git a/blocks/coauthor-display-name/src/block.json b/blocks/coauthor-display-name/src/block.json index 4eb92c75..4e79e7c5 100644 --- a/blocks/coauthor-display-name/src/block.json +++ b/blocks/coauthor-display-name/src/block.json @@ -7,8 +7,34 @@ "category": "widgets", "icon": "smiley", "description": "Display a co-author's preferred name.", + "parent": ["cap/coauthors"], "supports": { - "html": false + "html": false, + "color": { + "link": true, + "text": true, + "background": true, + "__experimentalDefaultControls": {} + }, + "typography": { + "fontSize": true, + "lineHeight": true, + "__experimentalFontFamily": true, + "__experimentalTextDecoration": true, + "__experimentalFontStyle": true, + "__experimentalFontWeight": true, + "__experimentalLetterSpacing": true, + "__experimentalTextTransform": true, + "__experimentalDefaultControls": {} + }, + "spacing": { + "margin": true, + "padding": true, + "__experimentalDefaultControls": { + "margin": false, + "padding": false + } + } }, "usesContext": [ "displayName" ], "textdomain": "co-authors-plus", diff --git a/blocks/coauthors/build/block.json b/blocks/coauthors/build/block.json index 2f9c2a4c..b34e183c 100644 --- a/blocks/coauthors/build/block.json +++ b/blocks/coauthors/build/block.json @@ -8,11 +8,53 @@ "icon": "smiley", "description": "Display the co-authors for a post.", "supports": { - "html": false + "html": false, + "color": { + "link": true, + "text": true, + "background": true, + "__experimentalDefaultControls": {} + }, + "typography": { + "fontSize": true, + "lineHeight": true, + "__experimentalFontFamily": true, + "__experimentalTextDecoration": true, + "__experimentalFontStyle": true, + "__experimentalFontWeight": true, + "__experimentalLetterSpacing": true, + "__experimentalTextTransform": true, + "__experimentalDefaultControls": {} + }, + "spacing": { + "margin": true, + "padding": true, + "__experimentalDefaultControls": { + "margin": false, + "padding": false + } + } + }, + "attributes": { + "separator": { + "type": "string", + "default": ", " + }, + "lastSeparator": { + "type": "string", + "default": " and " + }, + "layout": { + "type": "object", + "default": { + "type": "inline" + } + } }, "usesContext": [ "postId" ], "textdomain": "co-authors-plus", - "editorScript": "file:./index.js" + "editorScript": "file:./index.js", + "style": "file:./style-index.css" } \ No newline at end of file diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 2509fc94..ae57a480 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element'), 'version' => 'cdf92359799aa426a7f3'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'a55e3a79e1895257e98a'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index cf25b0cb..88eb6df7 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t=window.wp.blocks,n=window.wp.element,o=window.wp.blockEditor,r=window.wp.apiFetch,c=e.n(r),a=window.wp.data;function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t{a(r)},u={display:c?"none":void 0};return(0,n.createElement)("div",l({},s,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:u}))}));function i(){return(0,n.createElement)("div",(0,o.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}var u=JSON.parse('{"u2":"cap/coauthors"}');(0,t.registerBlockType)(u.u2,{edit:function(e){let{clientId:t,context:r}=e;const{postId:l}=r,[u,d]=(0,n.useState)([]),[p,b]=(0,n.useState)(),m=(0,a.useDispatch)("core/notices");function v(e){"AbortError"!==e.name&&m.createErrorNotice(e.message,{isDismissible:!0})}(0,n.useEffect)((()=>{const e=new AbortController;return c()({path:`/coauthors/v1/authors/${l}`,signal:e.signal}).then(d).catch(v),()=>{e.abort()}}),[l]);const w=(0,a.useSelect)((e=>e(o.store).getBlocks(t)));return(0,n.createElement)("div",(0,o.useBlockProps)(),u&&u.map((e=>{var t;let{id:r,displayName:c}=e;const a=r===(p||(null===(t=u[0])||void 0===t?void 0:t.id));return(0,n.createElement)(o.BlockContextProvider,{key:r,value:{coAuthorId:r,displayName:c}},a?(0,n.createElement)(i,null):null,(0,n.createElement)(s,{blocks:w,blockContextId:r,setActiveBlockContextId:b,isHidden:a}))})))},save:function(){return(0,n.createElement)(o.InnerBlocks.Content,null)}})}(); \ No newline at end of file +!function(){var e,t={911:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,c=window.wp.apiFetch,i=n.n(c),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,v=(0,o.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,o.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,o.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),f=n(779),h=n.n(f);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",m({},c,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function b(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}var y=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(y.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:c}=e;const{postId:p}=c,[f,m]=(0,o.useState)([{id:0,displayName:"CoAuthor Display Name"}]),[y,g]=(0,o.useState)(),k=(0,s.useDispatch)("core/notices"),{separator:E,lastSeparator:C,layout:x}=t;function _(e){"AbortError"!==e.name&&k.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!p)return;const e=new AbortController;return i()({path:`/coauthors/v1/authors/${p}`,signal:e.signal}).then(m).catch(_),()=>{e.abort()}}),[p]);const O=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),S=e=>{n({layout:{...x,...e}})},B=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>S({type:"inline"}),isActive:"inline"===x.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>S({type:"block"}),isActive:"block"===x.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:B})),(0,o.createElement)("div",(0,a.useBlockProps)({className:h()([`is-layout-cap-${x.type}`])}),f&&f.map((e=>{var t;let{id:n,displayName:r}=e;const l=n===(y||(null===(t=f[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,displayName:r}},l?(0,o.createElement)(b,null):null,(0,o.createElement)(w,{blocks:O,blockContextId:n,setActiveBlockContextId:g,isHidden:l}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===x.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===r.length-1?`${C}`:`${E}`),t)))),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===x.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[i])}))?n.splice(i--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],c=n[1],i=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in c)r.o(c,o)&&(r.m[o]=c[o]);if(i)var u=i(r)}for(t&&t(n);s*{display:inline} diff --git a/blocks/coauthors/class-cap-block-coauthors.php b/blocks/coauthors/class-cap-block-coauthors.php index 4bb04a30..e058bba4 100644 --- a/blocks/coauthors/class-cap-block-coauthors.php +++ b/blocks/coauthors/class-cap-block-coauthors.php @@ -15,6 +15,7 @@ class CAP_Block_CoAuthors { public function __construct() { add_action( 'init', array( __CLASS__, 'register_block' ) ); } + /** * Register Block */ @@ -26,6 +27,7 @@ public static function register_block() : void { ) ); } + /** * Render Block * @@ -47,17 +49,143 @@ public static function render_block( array $attributes, string $content, WP_Bloc return ''; } - $author_blocks = array_map( - self::get_block_wrapper_function('div', 'class="wp-block-cap-coauthor"'), + $blocks = self::render_coauthor_blocks_with_template( + self::get_block_as_template( $block ), + $authors + ); + + $separators = self::get_separators( + count( $blocks ), + $attributes + ); + + $inner_content = self::merge_blocks_with_separators( + $blocks, + $separators + ); + + return self::get_block_wrapper_function( + 'div', + get_block_wrapper_attributes( + array( + 'class' => "is-layout-cap-{$attributes['layout']['type']}" + ) + ) + )( $inner_content ); + } + + /** + * Get Composed Map Function + * Use array reduce so an unknown array of functions can be used as single array_map callback + * + * @param array $fns + * @return callable + */ + public static function get_composed_map_function( ...$fns ) : callable { + return function ( $value ) use ( $fns ) { + return array_reduce( + $fns, + fn( $v, callable $f ) => $f($v), + $value + ); + }; + } + + /** + * Render CoAuthor Blocks with Template + * + * @param array $template + * @param array $authors + * @return array + */ + public static function render_coauthor_blocks_with_template( array $template, array $authors ) : array { + return array_map( + self::get_composed_map_function( + self::get_template_render_function( $template ), + 'trim', + self::get_block_wrapper_function('div', 'class="wp-block-cap-coauthor"') + ), + $authors + ); + } + + /** + * Merge Blocks with Separators + * + * @param array $blocks + * @param array $separators + * @return string + */ + private static function merge_blocks_with_separators( array $blocks, array $separators ) : string { + return implode( array_map( - self::get_template_render_function( - self::get_block_as_template( $block ) - ), - $authors + fn(...$args) : string => implode($args), + $blocks, + $separators ) ); + } + + /** + * Get Separators + * + * @param int $count + * @param array $attributes + */ + private static function get_separators( int $count, array $attributes ) : array { + if ( 1 === $count ) { + return array(); + } + + if ( 'inline' !== $attributes['layout']['type'] ) { + return array(); + } + + $separator = self::get_separator( $attributes ); + $last_separator = self::get_last_separator( $attributes, $separator ); + $separators = array_fill( 0, $count - 1, $separator ); + + if ( ! empty( $separators ) ) { + array_splice( $separators, -1, 1, $last_separator ); + } + + return $separators; + } + + /** + * Get Separator + * + * @param array $attributes + * @return string $separator + */ + private static function get_separator( array $attributes ) : string { + $separator = esc_html( + $attributes['separator'] ?? '' + ); + + if ( '' === $separator ) { + return $separator; + } + + return "{$separator}"; + } + + /** + * Get Last Separator + * + * @param array $attributes + * @param string $default + */ + private static function get_last_separator( array $attributes, string $default ) : string { + $last_separator = esc_html( + $attributes['lastSeparator'] ?? '' + ); + + if ( '' === $last_separator ) { + return $default; + } - return self::get_block_wrapper_function('div', get_block_wrapper_attributes())(implode("\n", $author_blocks)); + return "{$last_separator}"; } /** diff --git a/blocks/coauthors/src/block.json b/blocks/coauthors/src/block.json index dcd72f08..52019b8b 100644 --- a/blocks/coauthors/src/block.json +++ b/blocks/coauthors/src/block.json @@ -8,9 +8,51 @@ "icon": "smiley", "description": "Display the co-authors for a post.", "supports": { - "html": false + "html": false, + "color": { + "link": true, + "text": true, + "background": true, + "__experimentalDefaultControls": {} + }, + "typography": { + "fontSize": true, + "lineHeight": true, + "__experimentalFontFamily": true, + "__experimentalTextDecoration": true, + "__experimentalFontStyle": true, + "__experimentalFontWeight": true, + "__experimentalLetterSpacing": true, + "__experimentalTextTransform": true, + "__experimentalDefaultControls": {} + }, + "spacing": { + "margin": true, + "padding": true, + "__experimentalDefaultControls": { + "margin": false, + "padding": false + } + } + }, + "attributes": { + "separator": { + "type": "string", + "default": ", " + }, + "lastSeparator": { + "type": "string", + "default": " and " + }, + "layout": { + "type": "object", + "default": { + "type": "inline" + } + } }, "usesContext": [ "postId" ], "textdomain": "co-authors-plus", - "editorScript": "file:./index.js" + "editorScript": "file:./index.js", + "style": "file:./style-index.css" } diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js index b38f0ccf..d14f318f 100644 --- a/blocks/coauthors/src/edit.js +++ b/blocks/coauthors/src/edit.js @@ -5,15 +5,22 @@ * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ import { + BlockControls, BlockContextProvider, useBlockProps, useInnerBlocksProps, store as blockEditorStore, + InspectorControls } from '@wordpress/block-editor'; - +import { TextControl, ToolbarGroup, PanelBody } from '@wordpress/components'; import apiFetch from '@wordpress/api-fetch'; import { useSelect, useDispatch } from '@wordpress/data'; import { useState, useEffect } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { list, grid } from '@wordpress/icons'; + +import classnames from 'classnames'; + import MemoizedCoAuthorTemplateBlockPreview from './modules/memoized-coauthor-template-block-preview'; /** @@ -34,14 +41,24 @@ function CoAuthorTemplateInnerBlocks () { * * @return {WPElement} Element to render. */ -export default function Edit( { clientId, context } ) { +export default function Edit( { attributes, setAttributes, clientId, context } ) { const { postId } = context; - const [ coAuthors, setCoAuthors ] = useState([]); + /* Default state for full site editing */ + const [ coAuthors, setCoAuthors ] = useState([{ + id: 0, + displayName: 'CoAuthor Display Name' + }]); const [ activeBlockContextId, setActiveBlockContextId ] = useState(); const noticesDispatch = useDispatch('core/notices'); + const { separator, lastSeparator, layout } = attributes; + useEffect(()=>{ + if ( ! postId ) { + return; + } + const controller = new AbortController(); apiFetch( { @@ -72,29 +89,101 @@ export default function Edit( { clientId, context } ) { return select( blockEditorStore ).getBlocks( clientId ); }); + const setLayout = ( nextLayout ) => { + setAttributes( { + layout: { ...layout, ...nextLayout }, + } ); + } + + const layoutControls = [ + { + icon: list, + title: __( 'Inline' ), + onClick: () => setLayout( { type: 'inline' } ), + isActive: layout.type === 'inline', + }, + { + icon: grid, + title: __( 'Block' ), + onClick: () => + setLayout( { type: 'block' } ), + isActive: layout.type === 'block', + }, + ]; + return ( -
- { - coAuthors && - coAuthors.map( ( { id, displayName } ) => { - const isHidden = id === ( activeBlockContextId || coAuthors[0]?.id ); - return ( - - { isHidden ? () : null } - - - ) + <> + + + +
+ { + coAuthors && + coAuthors + .map( ( { id, displayName } ) => { + const isHidden = id === ( activeBlockContextId || coAuthors[0]?.id ); + return ( + + { isHidden ? () : null } + + + ); + }) + .reduce( ( previous, current, index, all ) => ( + <> + { previous } + { + 'inline' === layout.type && + ( + + { ( lastSeparator && index === (all.length - 1) ) ? `${lastSeparator}` : `${separator}` } + + ) + } + { current } + + )) } - ) - } -
+
+ + + + { + 'inline' === layout.type && + ( + <> + { + setAttributes( { separator: nextValue } ); + } } + help={ __( 'Enter character(s) used to separate authors.' ) } + /> + { + setAttributes( { lastSeparator: nextValue } ); + } } + help={ __( 'Enter character(s) used to distinguish the last author.' ) } + /> + + ) + } + + + + ); } diff --git a/blocks/coauthors/src/index.js b/blocks/coauthors/src/index.js index a719f8dc..d6bfa3a1 100644 --- a/blocks/coauthors/src/index.js +++ b/blocks/coauthors/src/index.js @@ -12,6 +12,11 @@ import Edit from './edit'; import save from './save'; import metadata from './block.json'; +/** + * Style shared between editor and content + */ +import './style.css'; + /** * Every block starts by registering a new block type definition. * diff --git a/blocks/coauthors/src/style.css b/blocks/coauthors/src/style.css new file mode 100644 index 00000000..f963ab8a --- /dev/null +++ b/blocks/coauthors/src/style.css @@ -0,0 +1,4 @@ +.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor, +.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor > * { + display: inline; +} From 2c1524c091debb68f7ab33d5a2ddbff57ccc7d8a Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 18 Jul 2023 11:06:35 -0400 Subject: [PATCH 005/123] add prefix and suffix, storage in json is ugly --- blocks/coauthors/build/block.json | 8 ++ blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- .../coauthors/class-cap-block-coauthors.php | 82 +++++++++++++++++-- blocks/coauthors/src/block.json | 8 ++ blocks/coauthors/src/edit.js | 53 ++++++++++-- 6 files changed, 139 insertions(+), 16 deletions(-) diff --git a/blocks/coauthors/build/block.json b/blocks/coauthors/build/block.json index b34e183c..ed809b06 100644 --- a/blocks/coauthors/build/block.json +++ b/blocks/coauthors/build/block.json @@ -49,6 +49,14 @@ "default": { "type": "inline" } + }, + "prefix": { + "type": "string", + "default": "By" + }, + "suffix": { + "type": "string", + "default": "" } }, "usesContext": [ diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index ae57a480..2808f921 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'a55e3a79e1895257e98a'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'a2fa5ae83821a16029d9'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index 88eb6df7..b43ab463 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,c=window.wp.apiFetch,i=n.n(c),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,v=(0,o.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,o.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,o.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),f=n(779),h=n.n(f);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",m({},c,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function b(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}var y=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(y.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:c}=e;const{postId:p}=c,[f,m]=(0,o.useState)([{id:0,displayName:"CoAuthor Display Name"}]),[y,g]=(0,o.useState)(),k=(0,s.useDispatch)("core/notices"),{separator:E,lastSeparator:C,layout:x}=t;function _(e){"AbortError"!==e.name&&k.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!p)return;const e=new AbortController;return i()({path:`/coauthors/v1/authors/${p}`,signal:e.signal}).then(m).catch(_),()=>{e.abort()}}),[p]);const O=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),S=e=>{n({layout:{...x,...e}})},B=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>S({type:"inline"}),isActive:"inline"===x.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>S({type:"block"}),isActive:"block"===x.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:B})),(0,o.createElement)("div",(0,a.useBlockProps)({className:h()([`is-layout-cap-${x.type}`])}),f&&f.map((e=>{var t;let{id:n,displayName:r}=e;const l=n===(y||(null===(t=f[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,displayName:r}},l?(0,o.createElement)(b,null):null,(0,o.createElement)(w,{blocks:O,blockContextId:n,setActiveBlockContextId:g,isHidden:l}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===x.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===r.length-1?`${C}`:`${E}`),t)))),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===x.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[i])}))?n.splice(i--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],c=n[1],i=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in c)r.o(c,o)&&(r.m[o]=c[o]);if(i)var u=i(r)}for(t&&t(n);s{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",v({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function b(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/image","core/italic","core/link","core/strikethrough","core/text-color"];var g=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(g.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:i,isSelected:p}=e;const{postId:h}=i,[v,g]=(0,o.useState)([{id:0,displayName:"CoAuthor Display Name"}]),[k,x]=(0,o.useState)(),_=(0,s.useDispatch)("core/notices"),{separator:E,lastSeparator:C,layout:O,prefix:S,suffix:B}=t;function N(e){"AbortError"!==e.name&&_.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!h)return;const e=new AbortController;return c()({path:`/coauthors/v1/authors/${h}`,signal:e.signal}).then(g).catch(N),()=>{e.abort()}}),[h]);const P=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),A=e=>{n({layout:{...O,...e}})},I=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>A({type:"inline"}),isActive:"inline"===O.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>A({type:"block"}),isActive:"block"===O.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:I})),(0,o.createElement)("div",(0,a.useBlockProps)({className:m()([`is-layout-cap-${O.type}`])}),v&&"inline"===O.type&&(p||S)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:S,onChange:e=>n({prefix:e}),tagName:"span"}),v&&v.map((e=>{var t;let{id:n,displayName:r}=e;const l=n===(k||(null===(t=v[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,displayName:r}},l?(0,o.createElement)(b,null):null,(0,o.createElement)(w,{blocks:P,blockContextId:n,setActiveBlockContextId:x,isHidden:l}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===O.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===r.length-1?`${C}`:`${E}`),t))),v&&"inline"===O.type&&(p||B)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:B,onChange:e=>n({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===O.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);s true, + 'i' => true, + 'strong' => true, + 'b' => true, + 'mark' => array( + 'class' => true, + 'style' => true + ), + 's' => true, + ); + } + /** * Render CoAuthor Blocks with Template * @@ -114,15 +180,13 @@ public static function render_coauthor_blocks_with_template( array $template, ar * * @param array $blocks * @param array $separators - * @return string + * @return array */ - private static function merge_blocks_with_separators( array $blocks, array $separators ) : string { - return implode( - array_map( - fn(...$args) : string => implode($args), - $blocks, - $separators - ) + private static function merge_blocks_with_separators( array $blocks, array $separators ) : array { + return array_map( + fn(...$args) : string => implode($args), + $blocks, + $separators ); } diff --git a/blocks/coauthors/src/block.json b/blocks/coauthors/src/block.json index 52019b8b..2f68fcc2 100644 --- a/blocks/coauthors/src/block.json +++ b/blocks/coauthors/src/block.json @@ -49,6 +49,14 @@ "default": { "type": "inline" } + }, + "prefix": { + "type": "string", + "default": "By " + }, + "suffix": { + "type": "string", + "default": "" } }, "usesContext": [ "postId" ], diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js index d14f318f..b342d893 100644 --- a/blocks/coauthors/src/edit.js +++ b/blocks/coauthors/src/edit.js @@ -10,7 +10,8 @@ import { useBlockProps, useInnerBlocksProps, store as blockEditorStore, - InspectorControls + InspectorControls, + RichText } from '@wordpress/block-editor'; import { TextControl, ToolbarGroup, PanelBody } from '@wordpress/components'; import apiFetch from '@wordpress/api-fetch'; @@ -33,6 +34,12 @@ function CoAuthorTemplateInnerBlocks () { ) } />; } +const ALLOWED_FORMATS = [ + 'core/bold', + 'core/italic', + 'core/text-color', +]; + /** * The edit function describes the structure of your block in the context of the * editor. This represents what the editor will render when the block is used. @@ -41,7 +48,7 @@ function CoAuthorTemplateInnerBlocks () { * * @return {WPElement} Element to render. */ -export default function Edit( { attributes, setAttributes, clientId, context } ) { +export default function Edit( { attributes, setAttributes, clientId, context, isSelected } ) { const { postId } = context; /* Default state for full site editing */ @@ -52,7 +59,7 @@ export default function Edit( { attributes, setAttributes, clientId, context } ) const [ activeBlockContextId, setActiveBlockContextId ] = useState(); const noticesDispatch = useDispatch('core/notices'); - const { separator, lastSeparator, layout } = attributes; + const { separator, lastSeparator, layout, prefix, suffix } = attributes; useEffect(()=>{ if ( ! postId ) { @@ -117,6 +124,25 @@ export default function Edit( { attributes, setAttributes, clientId, context } )
+ { + coAuthors && + 'inline' === layout.type && + ( isSelected || prefix ) && + ( + + setAttributes( { prefix: value } ) + } + tagName="span" + /> + ) + } { coAuthors && coAuthors @@ -152,8 +178,26 @@ export default function Edit( { attributes, setAttributes, clientId, context } ) )) } + { + coAuthors && + 'inline' === layout.type && + ( isSelected || suffix ) && + ( + + setAttributes( { suffix: value } ) + } + tagName="span" + /> + ) + }
- { @@ -183,7 +227,6 @@ export default function Edit( { attributes, setAttributes, clientId, context } ) } - ); } From 57cd9157d20c3ec07618c5aff97bba8c05481afb Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 18 Jul 2023 11:22:35 -0400 Subject: [PATCH 006/123] wp_kses removes style attribute, removing for now --- blocks/coauthors/build/block.json | 2 +- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- .../coauthors/class-cap-block-coauthors.php | 27 +++---------------- 4 files changed, 6 insertions(+), 27 deletions(-) diff --git a/blocks/coauthors/build/block.json b/blocks/coauthors/build/block.json index ed809b06..17dc97ee 100644 --- a/blocks/coauthors/build/block.json +++ b/blocks/coauthors/build/block.json @@ -52,7 +52,7 @@ }, "prefix": { "type": "string", - "default": "By" + "default": "By " }, "suffix": { "type": "string", diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 2808f921..6d318a68 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'a2fa5ae83821a16029d9'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '6f8480a6269d8c7ef807'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index b43ab463..296aef45 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,f=(0,o.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,o.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,o.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),h=n(779),m=n.n(h);function v(){return v=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",v({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function b(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/image","core/italic","core/link","core/strikethrough","core/text-color"];var g=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(g.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:i,isSelected:p}=e;const{postId:h}=i,[v,g]=(0,o.useState)([{id:0,displayName:"CoAuthor Display Name"}]),[k,x]=(0,o.useState)(),_=(0,s.useDispatch)("core/notices"),{separator:E,lastSeparator:C,layout:O,prefix:S,suffix:B}=t;function N(e){"AbortError"!==e.name&&_.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!h)return;const e=new AbortController;return c()({path:`/coauthors/v1/authors/${h}`,signal:e.signal}).then(g).catch(N),()=>{e.abort()}}),[h]);const P=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),A=e=>{n({layout:{...O,...e}})},I=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>A({type:"inline"}),isActive:"inline"===O.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>A({type:"block"}),isActive:"block"===O.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:I})),(0,o.createElement)("div",(0,a.useBlockProps)({className:m()([`is-layout-cap-${O.type}`])}),v&&"inline"===O.type&&(p||S)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:S,onChange:e=>n({prefix:e}),tagName:"span"}),v&&v.map((e=>{var t;let{id:n,displayName:r}=e;const l=n===(k||(null===(t=v[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,displayName:r}},l?(0,o.createElement)(b,null):null,(0,o.createElement)(w,{blocks:P,blockContextId:n,setActiveBlockContextId:x,isHidden:l}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===O.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===r.length-1?`${C}`:`${E}`),t))),v&&"inline"===O.type&&(p||B)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:B,onChange:e=>n({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===O.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);s{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",h({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function b(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var g=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(g.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:i,isSelected:p}=e;const{postId:m}=i,[h,g]=(0,o.useState)([{id:0,displayName:"CoAuthor Display Name"}]),[k,x]=(0,o.useState)(),_=(0,s.useDispatch)("core/notices"),{separator:E,lastSeparator:C,layout:O,prefix:S,suffix:B}=t;function N(e){"AbortError"!==e.name&&_.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!m)return;const e=new AbortController;return c()({path:`/coauthors/v1/authors/${m}`,signal:e.signal}).then(g).catch(N),()=>{e.abort()}}),[m]);const P=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),A=e=>{n({layout:{...O,...e}})},I=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>A({type:"inline"}),isActive:"inline"===O.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>A({type:"block"}),isActive:"block"===O.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:I})),(0,o.createElement)("div",(0,a.useBlockProps)({className:v()([`is-layout-cap-${O.type}`])}),h&&"inline"===O.type&&(p||S)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:S,onChange:e=>n({prefix:e}),tagName:"span"}),h&&h.map((e=>{var t;let{id:n,displayName:r}=e;const l=n===(k||(null===(t=h[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,displayName:r}},l?(0,o.createElement)(b,null):null,(0,o.createElement)(w,{blocks:P,blockContextId:n,setActiveBlockContextId:x,isHidden:l}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===O.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===r.length-1?`${C}`:`${E}`),t))),h&&"inline"===O.type&&(p||B)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:B,onChange:e=>n({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===O.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);s true, - 'i' => true, - 'strong' => true, - 'b' => true, - 'mark' => array( - 'class' => true, - 'style' => true - ), - 's' => true, - ); + )( $suffix ); } /** From 03d45bf7ad614f54883658851f76ae0325f189f3 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 18 Jul 2023 16:32:35 -0400 Subject: [PATCH 007/123] wip adding block specifc api routes --- blocks/coauthor-display-name/build/block.json | 2 +- .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- .../class-cap-block-coauthor-display-name.php | 2 +- blocks/coauthor-display-name/src/block.json | 2 +- blocks/coauthor-display-name/src/edit.js | 4 +- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- .../coauthors/class-cap-block-coauthors.php | 2 +- blocks/coauthors/src/edit.js | 6 +- co-authors-plus.php | 4 + .../class-coauthor-blocks-controller.php | 157 ++++++++++++++++++ 12 files changed, 174 insertions(+), 13 deletions(-) create mode 100644 php/api/endpoints/class-coauthor-blocks-controller.php diff --git a/blocks/coauthor-display-name/build/block.json b/blocks/coauthor-display-name/build/block.json index 7095d386..6454722b 100644 --- a/blocks/coauthor-display-name/build/block.json +++ b/blocks/coauthor-display-name/build/block.json @@ -39,7 +39,7 @@ } }, "usesContext": [ - "displayName" + "display_name" ], "textdomain": "co-authors-plus", "editorScript": "file:./index.js", diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index 44e74ebf..95753db8 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-element'), 'version' => '38aff22fcae65c52b6fb'); + array('wp-block-editor', 'wp-blocks', 'wp-element'), 'version' => '52fa7a87b1bca10e1f81'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index edc18fe2..05e9fab7 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,o=window.wp.blockEditor,n=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(n.u2,{edit:function(e){let{context:n}=e;const{displayName:c}=n;return(0,t.createElement)("p",(0,o.useBlockProps)(),c)}})}(); \ No newline at end of file +!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,o=window.wp.blockEditor,n=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(n.u2,{edit:function(e){let{context:n}=e;const{display_name:c}=n;return(0,t.createElement)("p",(0,o.useBlockProps)(),c)}})}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index d926d4eb..8298c63c 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -35,7 +35,7 @@ public static function register_block() : void { * @return string */ public static function render_block( array $attributes, string $content, WP_Block $block ) : string { - $display_name = array_key_exists( 'displayName', $block->context ) ? $block->context['displayName'] : ''; + $display_name = array_key_exists( 'display_name', $block->context ) ? $block->context['display_name'] : ''; if ( '' === $display_name ) { return ''; } diff --git a/blocks/coauthor-display-name/src/block.json b/blocks/coauthor-display-name/src/block.json index 4e79e7c5..68cdca2d 100644 --- a/blocks/coauthor-display-name/src/block.json +++ b/blocks/coauthor-display-name/src/block.json @@ -36,7 +36,7 @@ } } }, - "usesContext": [ "displayName" ], + "usesContext": [ "display_name" ], "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "editorStyle": "file:./index.css", diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index ecd13e61..e669d554 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -15,10 +15,10 @@ import { useBlockProps } from '@wordpress/block-editor'; * @return {WPElement} Element to render. */ export default function Edit( { context } ) { - const { displayName } = context; + const { display_name } = context; return (

- { displayName } + { display_name }

); } diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 6d318a68..693d8625 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '6f8480a6269d8c7ef807'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '083155470dfd5f9c76d2'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index 296aef45..ca9839ca 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,f=(0,o.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,o.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,o.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),m=n(779),v=n.n(m);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",h({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function b(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var g=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(g.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:i,isSelected:p}=e;const{postId:m}=i,[h,g]=(0,o.useState)([{id:0,displayName:"CoAuthor Display Name"}]),[k,x]=(0,o.useState)(),_=(0,s.useDispatch)("core/notices"),{separator:E,lastSeparator:C,layout:O,prefix:S,suffix:B}=t;function N(e){"AbortError"!==e.name&&_.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!m)return;const e=new AbortController;return c()({path:`/coauthors/v1/authors/${m}`,signal:e.signal}).then(g).catch(N),()=>{e.abort()}}),[m]);const P=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),A=e=>{n({layout:{...O,...e}})},I=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>A({type:"inline"}),isActive:"inline"===O.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>A({type:"block"}),isActive:"block"===O.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:I})),(0,o.createElement)("div",(0,a.useBlockProps)({className:v()([`is-layout-cap-${O.type}`])}),h&&"inline"===O.type&&(p||S)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:S,onChange:e=>n({prefix:e}),tagName:"span"}),h&&h.map((e=>{var t;let{id:n,displayName:r}=e;const l=n===(k||(null===(t=h[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,displayName:r}},l?(0,o.createElement)(b,null):null,(0,o.createElement)(w,{blocks:P,blockContextId:n,setActiveBlockContextId:x,isHidden:l}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===O.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===r.length-1?`${C}`:`${E}`),t))),h&&"inline"===O.type&&(p||B)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:B,onChange:e=>n({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===O.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);s{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",h({},c,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function b(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var g=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(g.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:o,context:c,isSelected:p}=e;const{postId:m}=c,[h,g]=(0,r.useState)([{id:0,displayName:"CoAuthor Display Name"}]),[k,x]=(0,r.useState)(),_=(0,s.useDispatch)("core/notices"),{separator:E,lastSeparator:C,layout:O,prefix:S,suffix:B}=t;function P(e){"AbortError"!==e.name&&_.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!m)return;const e=new AbortController;return i()({path:`/coauthor-blocks/v1/coauthors/${m}/`,signal:e.signal}).then(g).catch(P),()=>{e.abort()}}),[m]);const A=(0,s.useSelect)((e=>e(a.store).getBlocks(o))),I=e=>{n({layout:{...O,...e}})},N=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>I({type:"inline"}),isActive:"inline"===O.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>I({type:"block"}),isActive:"block"===O.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:N})),(0,r.createElement)("div",(0,a.useBlockProps)({className:v()([`is-layout-cap-${O.type}`])}),h&&"inline"===O.type&&(p||S)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:S,onChange:e=>n({prefix:e}),tagName:"span"}),h&&h.map((e=>{var t;let{id:n,display_name:o}=e;const l=n===(k||(null===(t=h[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,display_name:o}},l?(0,r.createElement)(b,null):null,(0,r.createElement)(w,{blocks:A,blockContextId:n,setActiveBlockContextId:x,isHidden:l}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===O.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===o.length-1?`${C}`:`${E}`),t))),h&&"inline"===O.type&&(p||B)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:B,onChange:e=>n({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===O.type&&(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,r.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[i])}))?n.splice(i--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],c=n[1],i=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in c)o.o(c,r)&&(o.m[r]=c[r]);if(i)var u=i(o)}for(t&&t(n);s $author->display_name, + 'display_name' => $author->display_name, ) ) )->render( array( 'dynamic' => false ) ); diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js index b342d893..2936f612 100644 --- a/blocks/coauthors/src/edit.js +++ b/blocks/coauthors/src/edit.js @@ -69,7 +69,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is const controller = new AbortController(); apiFetch( { - path: `/coauthors/v1/authors/${postId}`, + path: `/coauthor-blocks/v1/coauthors/${postId}/`, signal: controller.signal } ) .then( setCoAuthors ) @@ -146,12 +146,12 @@ export default function Edit( { attributes, setAttributes, clientId, context, is { coAuthors && coAuthors - .map( ( { id, displayName } ) => { + .map( ( { id, display_name } ) => { const isHidden = id === ( activeBlockContextId || coAuthors[0]?.id ); return ( { isHidden ? () : null } coauthors_plus = $coauthors_plus; + + add_action( 'rest_api_init', array( $this, 'register_routes' ) ); + } + + /** + * Register Rest Route + */ + public function register_routes() : void { + register_rest_route( + 'coauthor-blocks/v1', + '/coauthors/(?P[\d]+)', + array( + 'args' => array( + 'id' => array( + 'description' => __( 'Unique identifier for a post.' ), + 'type' => 'integer', + 'validate_callback' => 'is_int' + ), + ), + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permission_check' ), + ) + ) + ); + } + + /** + * Get Items + * + * @param WP_REST_Request $request + * @return WP_REST_Response|WP_Error + */ + public function get_items( $request ) : WP_REST_Response|WP_Error { + + $coauthors = get_coauthors( $request->get_param( 'post_id' ) ); + + if ( ! is_array( $coauthors ) ) { + return new WP_Error( + 'rest_unusable_data', + __('Sorry, an unusable response was produced.'), + array( 'status' => 406 ) + ); + } + + return rest_ensure_response( + array_map( + function( stdClass|WP_User $author ) use ( $request ) : array { + return $this->prepare_response_for_collection( + $this->prepare_item_for_response( $author, $request ) + ); + }, + $coauthors + ) + ); + } + + /** + * Get Items Permission Check + * + * @param WP_REST_Request $request + * @return bool|WP_Error + */ + public function get_items_permission_check( WP_REST_Request $request ) : bool|WP_Error { + + $post_id = $request->get_param( 'post_id' ); + + if ( current_user_can( 'edit_post', $post_id ) ) { + return true; + } + + if ( is_coauthor_for_post( get_current_user(), $post_id ) ) { + return true; + } + + return new WP_Error( + 'rest_cannot_view', + __( 'Sorry, you are not allowed to view coauthors of this post.' ), + array( 'status' => rest_authorization_required_code() ) + ); + } + + /** + * Prepare Item For Response + * + * @param stdClass|WP_User $author + * @param WP_REST_Request $request + * @return WP_REST_Response|WP_Error + */ + public function prepare_item_for_response( $author, $request ) : WP_REST_Response|WP_Error { + + $disallowed = array( + 'ID', + 'linked_account', + 'user_email', + 'user_login' + ); + + $data = array_diff_key( + (array) $author, + array_flip( $disallowed ) + ); + + $data['id'] = $author->ID; + $data['link'] = get_author_posts_url( $author->ID, $author->user_nicename ); + + $response = rest_ensure_response( $data ); + + /** + * Filters the post data for a REST API response. + * + * + * @param WP_REST_Response $response The response object. + * @param stdClass|WP_User $author + * @param WP_REST_Request $request Request object. + */ + return apply_filters( "rest_prepare_coauthor_block", $response, $author, $request ); + } +} From 752c06eb92e92e86f3da64b3a0447e053b771ae0 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 19 Jul 2023 11:45:19 -0400 Subject: [PATCH 008/123] add api route for single coauthor by name --- co-authors-plus.php | 12 ++- .../class-coauthor-blocks-controller.php | 99 ++++++++++++++++++- 2 files changed, 105 insertions(+), 6 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 555f8e91..3a77878b 100755 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -47,7 +47,7 @@ $coauthors_plus = new CoAuthors_Plus(); $coauthors_endpoint = new CoAuthors\API\Endpoints( $coauthors_plus ); -new CoAuthors\API\Endpoints\CoAuthor_Blocks_Controller( $coauthors_plus ); + new CAP_Block_CoAuthors(); new CAP_Block_CoAuthor_Display_Name(); @@ -217,3 +217,13 @@ function cap_get_coauthor_terms_for_post( $post_id ) { global $coauthors_plus; return $coauthors_plus->get_coauthor_terms_for_post( $post_id ); } + +/** + * Register CoAuthor Blocks REST API Routes + */ +function cap_register_coauthor_blocks_rest_api_routes() : void { + global $coauthors_plus; + $controller = new CoAuthors\API\Endpoints\CoAuthor_Blocks_Controller( $coauthors_plus ); + $controller->register_routes(); +} +add_action( 'rest_api_init', 'cap_register_coauthor_blocks_rest_api_routes' ); diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index a22f65df..06c03bf7 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -35,12 +35,10 @@ class CoAuthor_Blocks_Controller extends WP_REST_Controller { */ public function __construct( CoAuthors_Plus $coauthors_plus ) { $this->coauthors_plus = $coauthors_plus; - - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); } /** - * Register Rest Route + * Register Rest Routes */ public function register_routes() : void { register_rest_route( @@ -51,7 +49,7 @@ public function register_routes() : void { 'id' => array( 'description' => __( 'Unique identifier for a post.' ), 'type' => 'integer', - 'validate_callback' => 'is_int' + 'validate_callback' => fn( $post_id ) => is_int( $post_id ) ), ), array( @@ -61,6 +59,68 @@ public function register_routes() : void { ) ) ); + + register_rest_route( + 'coauthor-blocks/v1', + '/coauthor/(?P[\d\w-]+)', + array( + 'args' => array( + 'user_nicename' => array( + 'description' => __( 'Nicename / slug for coauthor.' ), + 'type' => 'string', + 'validate_callback' => fn( $slug ) => is_string( $slug ), + 'sanitize_callback' => fn( $slug ) => sanitize_title( $slug ) + ), + ), + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => array( $this, 'get_item_permission_check' ), + ) + ) + ); + } + + /** + * Get Item + * + * + * @param WP_REST_Request $request + * @return WP_REST_Response|WP_Error + */ + public function get_item( $request ) : WP_REST_Response|WP_Error { + + $coauthor = $this->coauthors_plus->get_coauthor_by( + 'user_nicename', + $request->get_param( 'user_nicename' ) + ); + + if ( ! is_object( $coauthor ) ) { + return new WP_Error( + 'rest_not_found', + __('Sorry, we could not find that coauthor.'), + array( 'status' => 404 ) + ); + } + + if ( ! self::is_coauthor( $coauthor ) ) { + return new WP_Error( + 'rest_unusable_data', + __('Sorry, an unusable response was produced.'), + array( 'status' => 406 ) + ); + } + + return self::prepare_item_for_response( $coauthor, $request ); + } + + /** + * Is Valid CoAuthor + * + * @param WP_User|stdClass $coauthor + */ + public static function is_coauthor( WP_User|stdClass $coauthor ) : bool { + return is_a( $coauthor, 'WP_User' ) || ( property_exists( $coauthor, 'type' ) && 'guest-author' === $coauthor->type ); } /** @@ -93,6 +153,25 @@ function( stdClass|WP_User $author ) use ( $request ) : array { ); } + /** + * Get Item Permission Check + * + * @param WP_REST_Request $request + * @return bool|WP_Error + */ + public function get_item_permission_check( WP_REST_Request $request ) : bool|WP_Error { + + if ( current_user_can( 'edit_posts' ) ) { + return true; + } + + return new WP_Error( + 'rest_cannot_view', + __( 'Sorry, you are not allowed to view coauthors.' ), + array( 'status' => rest_authorization_required_code() ) + ); + } + /** * Get Items Permission Check * @@ -127,11 +206,21 @@ public function get_items_permission_check( WP_REST_Request $request ) : bool|WP */ public function prepare_item_for_response( $author, $request ) : WP_REST_Response|WP_Error { + if ( is_a( $author, 'WP_User' ) ) { + $author = $author->data; + } + $disallowed = array( 'ID', 'linked_account', 'user_email', - 'user_login' + 'user_login', + 'user_pass', + 'user_registered', + 'user_activation_key', + 'user_url', + 'user_status', + 'type' ); $data = array_diff_key( From b90c30e1ac259b8d51cc58ee7a9e3b61e4554e25 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 20 Jul 2023 10:45:06 -0400 Subject: [PATCH 009/123] add link toggle to display name block --- blocks/coauthor-display-name/build/block.json | 14 +++++- .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- blocks/coauthor-display-name/src/block.json | 16 ++++++- blocks/coauthor-display-name/src/edit.js | 45 +++++++++++++++++-- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- blocks/coauthors/src/edit.js | 12 ++--- 8 files changed, 81 insertions(+), 14 deletions(-) diff --git a/blocks/coauthor-display-name/build/block.json b/blocks/coauthor-display-name/build/block.json index 6454722b..f01c98c7 100644 --- a/blocks/coauthor-display-name/build/block.json +++ b/blocks/coauthor-display-name/build/block.json @@ -39,8 +39,20 @@ } }, "usesContext": [ - "display_name" + "display_name", + "link" ], + "attributes": { + "isLink": { + "type": "boolean", + "default": false + }, + "rel": { + "type": "string", + "attribute": "rel", + "default": "author" + } + }, "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "editorStyle": "file:./index.css", diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index 95753db8..a737be5a 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-element'), 'version' => '52fa7a87b1bca10e1f81'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '9b74bc40849f9ddb1ba8'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index 05e9fab7..70633afc 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,o=window.wp.blockEditor,n=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(n.u2,{edit:function(e){let{context:n}=e;const{display_name:c}=n;return(0,t.createElement)("p",(0,o.useBlockProps)(),c)}})}(); \ No newline at end of file +!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,n=window.wp.blockEditor,l=window.wp.components,o=window.wp.i18n,r=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(r.u2,{edit:function(e){let{context:r,attributes:a,setAttributes:i}=e;const{display_name:c,link:s}=r,{isLink:m,rel:p}=a;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("p",(0,n.useBlockProps)(),m?(0,t.createElement)("a",{href:s,target:linkTarget,rel:p,onClick:e=>e.preventDefault()},c):c),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(l.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make title a link"),onChange:()=>i({isLink:!m}),checked:m}),m&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:p,onChange:e=>i({rel:e})})))))}})}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/src/block.json b/blocks/coauthor-display-name/src/block.json index 68cdca2d..4acc124b 100644 --- a/blocks/coauthor-display-name/src/block.json +++ b/blocks/coauthor-display-name/src/block.json @@ -36,7 +36,21 @@ } } }, - "usesContext": [ "display_name" ], + "usesContext": [ + "display_name", + "link" + ], + "attributes": { + "isLink": { + "type": "boolean", + "default": false + }, + "rel": { + "type": "string", + "attribute": "rel", + "default": "author" + } + }, "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "editorStyle": "file:./index.css", diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index e669d554..cb2ed50f 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -5,6 +5,9 @@ * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ import { useBlockProps } from '@wordpress/block-editor'; +import { InspectorControls } from '@wordpress/block-editor'; +import { TextControl, PanelBody, ToggleControl } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; /** * The edit function describes the structure of your block in the context of the @@ -14,11 +17,47 @@ import { useBlockProps } from '@wordpress/block-editor'; * * @return {WPElement} Element to render. */ -export default function Edit( { context } ) { - const { display_name } = context; +export default function Edit( { context, attributes, setAttributes } ) { + const { display_name, link } = context; + const { isLink, rel } = attributes; return ( + <>

- { display_name } + { + isLink ? ( + event.preventDefault() } + > + { display_name } + + ) : display_name + }

+ + + setAttributes( { isLink: ! isLink } ) } + checked={ isLink } + /> + { isLink && ( + <> + + setAttributes( { rel: newRel } ) + } + /> + + ) } + + + ); } diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 693d8625..3d79c963 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '083155470dfd5f9c76d2'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'd41603de0318ef9844cb'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index ca9839ca..3ecae070 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,c=window.wp.apiFetch,i=n.n(c),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,f=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),m=n(779),v=n.n(m);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",h({},c,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function b(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var g=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(g.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:o,context:c,isSelected:p}=e;const{postId:m}=c,[h,g]=(0,r.useState)([{id:0,displayName:"CoAuthor Display Name"}]),[k,x]=(0,r.useState)(),_=(0,s.useDispatch)("core/notices"),{separator:E,lastSeparator:C,layout:O,prefix:S,suffix:B}=t;function P(e){"AbortError"!==e.name&&_.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!m)return;const e=new AbortController;return i()({path:`/coauthor-blocks/v1/coauthors/${m}/`,signal:e.signal}).then(g).catch(P),()=>{e.abort()}}),[m]);const A=(0,s.useSelect)((e=>e(a.store).getBlocks(o))),I=e=>{n({layout:{...O,...e}})},N=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>I({type:"inline"}),isActive:"inline"===O.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>I({type:"block"}),isActive:"block"===O.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:N})),(0,r.createElement)("div",(0,a.useBlockProps)({className:v()([`is-layout-cap-${O.type}`])}),h&&"inline"===O.type&&(p||S)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:S,onChange:e=>n({prefix:e}),tagName:"span"}),h&&h.map((e=>{var t;let{id:n,display_name:o}=e;const l=n===(k||(null===(t=h[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,display_name:o}},l?(0,r.createElement)(b,null):null,(0,r.createElement)(w,{blocks:A,blockContextId:n,setActiveBlockContextId:x,isHidden:l}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===O.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===o.length-1?`${C}`:`${E}`),t))),h&&"inline"===O.type&&(p||B)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:B,onChange:e=>n({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===O.type&&(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,r.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[i])}))?n.splice(i--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],c=n[1],i=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in c)o.o(c,r)&&(o.m[r]=c[r]);if(i)var u=i(o)}for(t&&t(n);s{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",h({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function b(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var k=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(k.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:o,context:i,isSelected:p}=e;const{separator:m,lastSeparator:h,layout:k,prefix:g,suffix:_}=t,{postId:x}=i,[E,C]=(0,r.useState)([{id:0,display_name:"CoAuthor Display Name",link:""}]),[O,S]=(0,r.useState)(),B=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&B.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!x)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${x}/`,signal:e.signal}).then(C).catch(P),()=>{e.abort()}}),[x]);const A=(0,s.useSelect)((e=>e(a.store).getBlocks(o))),I=e=>{n({layout:{...k,...e}})},N=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>I({type:"inline"}),isActive:"inline"===k.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>I({type:"block"}),isActive:"block"===k.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:N})),(0,r.createElement)("div",(0,a.useBlockProps)({className:v()([`is-layout-cap-${k.type}`])}),E&&"inline"===k.type&&(p||g)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:g,onChange:e=>n({prefix:e}),tagName:"span"}),E&&E.map((e=>{var t;let{id:n,display_name:o,link:l}=e;const i=n===(O||(null===(t=E[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,display_name:o,link:l}},i?(0,r.createElement)(b,null):null,(0,r.createElement)(w,{blocks:A,blockContextId:n,setActiveBlockContextId:S,isHidden:i}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===k.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},h&&n===o.length-1?`${h}`:`${m}`),t))),E&&"inline"===k.type&&(p||_)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>n({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===k.type&&(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:m||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:h||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,r.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s{ if ( ! postId ) { return; @@ -146,12 +148,12 @@ export default function Edit( { attributes, setAttributes, clientId, context, is { coAuthors && coAuthors - .map( ( { id, display_name } ) => { + .map( ( { id, display_name, link } ) => { const isHidden = id === ( activeBlockContextId || coAuthors[0]?.id ); return ( { isHidden ? () : null } Date: Thu, 20 Jul 2023 10:45:19 -0400 Subject: [PATCH 010/123] provide link in context from coauthors block --- blocks/coauthors/class-cap-block-coauthors.php | 1 + 1 file changed, 1 insertion(+) diff --git a/blocks/coauthors/class-cap-block-coauthors.php b/blocks/coauthors/class-cap-block-coauthors.php index 8a7f5e58..7bbfd962 100644 --- a/blocks/coauthors/class-cap-block-coauthors.php +++ b/blocks/coauthors/class-cap-block-coauthors.php @@ -257,6 +257,7 @@ private static function get_template_render_function( array $block_template ) : $block_template, array( 'display_name' => $author->display_name, + 'link' => get_author_posts_url( $author->ID, $author->user_nicename ) ) ) )->render( array( 'dynamic' => false ) ); From e9d4109b8ec8c25f4103537bf2f8960b5e8f2c7e Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 20 Jul 2023 10:45:47 -0400 Subject: [PATCH 011/123] output link in display name block render callback --- .../class-cap-block-coauthor-display-name.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index 8298c63c..505d0662 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -35,11 +35,29 @@ public static function register_block() : void { * @return string */ public static function render_block( array $attributes, string $content, WP_Block $block ) : string { - $display_name = array_key_exists( 'display_name', $block->context ) ? $block->context['display_name'] : ''; + + $display_name = $block->context['display_name'] ?? ''; + if ( '' === $display_name ) { return ''; } - $attributes = get_block_wrapper_attributes(); - return "

{$display_name}

"; + + $link = $block->context['link'] ?? ''; + $is_link = $attributes['isLink'] ?? false; + $rel = $attributes['rel'] ?? ''; + + if ( $is_link && '' !== $link ) { + $inner_content = sprintf( + '%s', + $rel, + $link, + sprintf( __( 'Posts by %s', 'co-authors-plus' ), $display_name ), + $display_name + ); + } else { + $inner_content = $display_name; + } + + return sprintf( '

%s

', get_block_wrapper_attributes(), $inner_content ); } } From df51b94c3a7693b24e992127c109badd3332a669 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 20 Jul 2023 12:08:07 -0400 Subject: [PATCH 012/123] missed one link target --- blocks/coauthor-display-name/build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- blocks/coauthor-display-name/src/edit.js | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index a737be5a..7afa5b5d 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '9b74bc40849f9ddb1ba8'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'c69cb3db7db5d297203c'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index 70633afc..4748b8df 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,n=window.wp.blockEditor,l=window.wp.components,o=window.wp.i18n,r=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(r.u2,{edit:function(e){let{context:r,attributes:a,setAttributes:i}=e;const{display_name:c,link:s}=r,{isLink:m,rel:p}=a;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("p",(0,n.useBlockProps)(),m?(0,t.createElement)("a",{href:s,target:linkTarget,rel:p,onClick:e=>e.preventDefault()},c):c),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(l.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make title a link"),onChange:()=>i({isLink:!m}),checked:m}),m&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:p,onChange:e=>i({rel:e})})))))}})}(); \ No newline at end of file +!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,n=window.wp.blockEditor,l=window.wp.components,o=window.wp.i18n,r=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(r.u2,{edit:function(e){let{context:r,attributes:a,setAttributes:i}=e;const{display_name:c,link:s}=r,{isLink:m,rel:p}=a;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("p",(0,n.useBlockProps)(),m?(0,t.createElement)("a",{href:s,rel:p,onClick:e=>e.preventDefault()},c):c),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(l.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make title a link"),onChange:()=>i({isLink:!m}),checked:m}),m&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:p,onChange:e=>i({rel:e})})))))}})}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index cb2ed50f..3cb3e413 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -27,7 +27,6 @@ export default function Edit( { context, attributes, setAttributes } ) { isLink ? ( event.preventDefault() } > From dff5263fbc0a54ccc25bd7647c7de928ebfeb3d4 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 26 Jul 2023 12:53:02 -0400 Subject: [PATCH 013/123] ignore node_modules. wherever they are From 5e4999ba32f3056e73dec36bd42b0d9a8870278e Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 27 Jul 2023 14:41:00 -0400 Subject: [PATCH 014/123] add avatar_urls to api response --- php/api/endpoints/class-coauthor-blocks-controller.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index 06c03bf7..ec6913ae 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -228,8 +228,9 @@ public function prepare_item_for_response( $author, $request ) : WP_REST_Respons array_flip( $disallowed ) ); - $data['id'] = $author->ID; - $data['link'] = get_author_posts_url( $author->ID, $author->user_nicename ); + $data['id'] = $author->ID; + $data['link'] = get_author_posts_url( $author->ID, $author->user_nicename ); + $data['avatar_urls'] = rest_get_avatar_urls( $author->ID ); $response = rest_ensure_response( $data ); From 26fa69d8e46d6a51da2af7935dfb6207912d2766 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 28 Jul 2023 13:17:49 -0400 Subject: [PATCH 015/123] tabs fix --- blocks/coauthor-display-name/src/edit.js | 44 ++++++++++++------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index 3cb3e413..fa8a06b7 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -36,27 +36,27 @@ export default function Edit( { context, attributes, setAttributes } ) { }

- - setAttributes( { isLink: ! isLink } ) } - checked={ isLink } - /> - { isLink && ( - <> - - setAttributes( { rel: newRel } ) - } - /> - - ) } - - - + + setAttributes( { isLink: ! isLink } ) } + checked={ isLink } + /> + { isLink && ( + <> + + setAttributes( { rel: newRel } ) + } + /> + + ) } + + + ); } From c14d406882acaa13248b819af4febb02270e6416 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 28 Jul 2023 13:18:21 -0400 Subject: [PATCH 016/123] add avatar block --- blocks/coauthor-avatar/build/block.json | 31 ++++++ blocks/coauthor-avatar/build/index.asset.php | 1 + blocks/coauthor-avatar/build/index.js | 1 + blocks/coauthor-avatar/build/style-index.css | 1 + .../class-cap-block-coauthor-avatar.php | 102 ++++++++++++++++++ blocks/coauthor-avatar/package.json | 5 + blocks/coauthor-avatar/src/block.json | 32 ++++++ blocks/coauthor-avatar/src/edit.js | 69 ++++++++++++ blocks/coauthor-avatar/src/index.js | 29 +++++ blocks/coauthor-avatar/src/style.css | 3 + 10 files changed, 274 insertions(+) create mode 100644 blocks/coauthor-avatar/build/block.json create mode 100644 blocks/coauthor-avatar/build/index.asset.php create mode 100644 blocks/coauthor-avatar/build/index.js create mode 100644 blocks/coauthor-avatar/build/style-index.css create mode 100644 blocks/coauthor-avatar/class-cap-block-coauthor-avatar.php create mode 100644 blocks/coauthor-avatar/package.json create mode 100644 blocks/coauthor-avatar/src/block.json create mode 100644 blocks/coauthor-avatar/src/edit.js create mode 100644 blocks/coauthor-avatar/src/index.js create mode 100644 blocks/coauthor-avatar/src/style.css diff --git a/blocks/coauthor-avatar/build/block.json b/blocks/coauthor-avatar/build/block.json new file mode 100644 index 00000000..da4f0872 --- /dev/null +++ b/blocks/coauthor-avatar/build/block.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "cap/coauthor-avatar", + "version": "0.1.0", + "title": "Co-Author Avatar", + "category": "widgets", + "icon": "smiley", + "description": "Display a co-author's avatar", + "supports": { + "html": false + }, + "usesContext": [ + "avatar_urls", + "link" + ], + "attributes": { + "size": { + "type": "number", + "default": 24 + }, + "isLink": { + "type": "boolean", + "default": false + } + }, + "textdomain": "coauthor-avatar", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css" +} \ No newline at end of file diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php new file mode 100644 index 00000000..cf369fe7 --- /dev/null +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'bff2582553524a68157f'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js new file mode 100644 index 00000000..d2e7b8ee --- /dev/null +++ b/blocks/coauthor-avatar/build/index.js @@ -0,0 +1 @@ +!function(){"use strict";var e,t={363:function(){var e=window.wp.blocks,t=window.wp.element,n=window.wp.i18n,r=window.wp.blockEditor,o=window.wp.components,a=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(a.u2,{edit:function(e){let{context:a,attributes:i,setAttributes:l}=e;const{avatar_urls:c,link:u}=a,{isLink:s,size:f}=i;if(!c)return null;const p=Object.keys(c).map((e=>({value:e,label:`${e} x ${e}`}))),v=(0,t.createElement)("img",{width:f,height:f,src:`${c[f]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,r.useBlockProps)(),s?(0,t.createElement)("a",{href:u,onClick:e=>e.preventDefault()},v):v),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,n.__)("Avatar Settings")},(0,t.createElement)(o.ToggleControl,{label:(0,n.__)("Make avatar a link to author archive."),onChange:()=>l({isLink:!s}),checked:s}),(0,t.createElement)(o.SelectControl,{label:(0,n.__)("Avatar size"),value:f,options:p,onChange:e=>{l({size:Number(e)})}}))))}})}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=function(t,n,o,a){if(!n){var i=1/0;for(s=0;s=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(l=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[n,o,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,i=n[0],l=n[1],c=n[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(o in l)r.o(l,o)&&(r.m[o]=l[o]);if(c)var s=c(r)}for(t&&t(n);u array( __CLASS__, 'render_block' ), + ) + ); + register_block_style( + 'cap/coauthor-avatar', + array( + 'name' => 'rounded', + 'label' => __('Rounded'), + 'inline_style' => '.wp-block-cap-coauthor-avatar.is-style-rounded img { border-radius: 50% }', + ) + ); + } + /** + * Render Block + * + * @param array $attributes + * @param string $content + * @param WP_Block $block + * @return string + */ + public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + + $avatar_urls = $block->context['avatar_urls'] ?? array(); + + if ( empty( $avatar_urls ) ) { + return ''; + } + + $link = $block->context['link'] ?? ''; + $is_link = $attributes['isLink'] ?? false; + $size = $attributes['size'] ?? 24; + $srcset = array_map( + fn( $url, $size ) => "{$url} {$size}w", + array_values( $avatar_urls ), + array_keys( $avatar_urls ) + ); + + $image = sprintf( + '', + $avatar_urls[$size], + $size, + $size, + "{$size}px", + implode( ', ', $srcset) + ); + + $inner_content = $is_link ? self::add_link( $link, $image ) : $image; + + return self::get_block_wrapper_function( + 'div', + get_block_wrapper_attributes() + )( $inner_content ); + } + + /** + * Add Link + * + * @param string $link + * @param string $content + * @return string + */ + public static function add_link( string $link, string $content ) : string { + return sprintf('
%s', $link, $content); + } + + /** + * Get Block Wrapper Function + * + * @param string $element_name + * @param string $attributes + * @return callable + */ + private static function get_block_wrapper_function( string $element_name, string $attributes ) : callable { + return function( string $content ) use ( $element_name, $attributes ) : string { + return "<{$element_name} {$attributes}>{$content}"; + }; + } +} diff --git a/blocks/coauthor-avatar/package.json b/blocks/coauthor-avatar/package.json new file mode 100644 index 00000000..b6abf47a --- /dev/null +++ b/blocks/coauthor-avatar/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "build": "../../node_modules/.bin/wp-scripts build" + } +} diff --git a/blocks/coauthor-avatar/src/block.json b/blocks/coauthor-avatar/src/block.json new file mode 100644 index 00000000..6e14f59f --- /dev/null +++ b/blocks/coauthor-avatar/src/block.json @@ -0,0 +1,32 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "cap/coauthor-avatar", + "version": "0.1.0", + "title": "Co-Author Avatar", + "category": "widgets", + "icon": "smiley", + "description": "Display a co-author's avatar", + "supports": { + "html": false + }, + "usesContext": [ + "avatar_urls", + "link" + ], + "attributes": { + "size" : { + "type": "number", + "default": 24 + }, + "isLink": { + "type": "boolean", + "default": false + } + }, + "textdomain": "coauthor-avatar", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css" + +} \ No newline at end of file diff --git a/blocks/coauthor-avatar/src/edit.js b/blocks/coauthor-avatar/src/edit.js new file mode 100644 index 00000000..ac002087 --- /dev/null +++ b/blocks/coauthor-avatar/src/edit.js @@ -0,0 +1,69 @@ +import { __ } from '@wordpress/i18n'; +import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; +import { SelectControl, PanelBody, ToggleControl } from '@wordpress/components'; + +/** + * The edit function describes the structure of your block in the context of the + * editor. This represents what the editor will render when the block is used. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit + * + * @return {WPElement} Element to render. + */ +export default function Edit( { context, attributes, setAttributes } ) { + + const { avatar_urls, link } = context; + const { isLink, size } = attributes; + + if ( ! avatar_urls ) { + return null; + } + + const sizes = Object.keys( avatar_urls ).map( (size) => { + return { + value: size, + label: `${ size } x ${ size }` + }; + }); + + // what to do if existing size is not in sizes array? + + const image = ; + + return ( + <> +
+ {( + isLink ? ( + e.preventDefault())}> + {image} + + ) : ( + image + ) + )} +
+ + + setAttributes( { isLink: ! isLink } ) } + checked={ isLink } + /> + { + setAttributes( { + size: Number( nextSize ), + } ); + } } + /> + + + + ); +} diff --git a/blocks/coauthor-avatar/src/index.js b/blocks/coauthor-avatar/src/index.js new file mode 100644 index 00000000..37757e6a --- /dev/null +++ b/blocks/coauthor-avatar/src/index.js @@ -0,0 +1,29 @@ +/** + * Registers a new block provided a unique name and an object defining its behavior. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +import { registerBlockType } from '@wordpress/blocks'; + +/** + * Internal dependencies + */ +import Edit from './edit'; +import metadata from './block.json'; + +/** + * Style shared between editor and content + */ +import './style.css'; + +/** + * Every block starts by registering a new block type definition. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +registerBlockType( metadata.name, { + /** + * @see ./edit.js + */ + edit: Edit +} ); diff --git a/blocks/coauthor-avatar/src/style.css b/blocks/coauthor-avatar/src/style.css new file mode 100644 index 00000000..26b74781 --- /dev/null +++ b/blocks/coauthor-avatar/src/style.css @@ -0,0 +1,3 @@ +.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-avatar :where(img) { + vertical-align: middle; +} \ No newline at end of file From 353b87ac05ad70d407ee8d8b2d5727f60b151c44 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 28 Jul 2023 13:18:31 -0400 Subject: [PATCH 017/123] add avatar block to main plugin file --- co-authors-plus.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 3a77878b..209a7dcd 100755 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -35,6 +35,7 @@ require_once __DIR__ . '/php/class-coauthors-iterator.php'; require_once dirname( __FILE__ ) . '/blocks/coauthors/class-cap-block-coauthors.php'; +require_once dirname( __FILE__ ) . '/blocks/coauthor-avatar/class-cap-block-coauthor-avatar.php'; require_once dirname( __FILE__ ) . '/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php'; require_once dirname( __FILE__ ) . '/php/api/endpoints/class-coauthor-blocks-controller.php'; @@ -47,9 +48,8 @@ $coauthors_plus = new CoAuthors_Plus(); $coauthors_endpoint = new CoAuthors\API\Endpoints( $coauthors_plus ); - - new CAP_Block_CoAuthors(); +new CAP_Block_CoAuthor_Avatar(); new CAP_Block_CoAuthor_Display_Name(); if ( ! function_exists( 'wp_notify_postauthor' ) ) : From 0d9abee3ca940e53ba762ab1bede738696bce206 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 28 Jul 2023 13:18:52 -0400 Subject: [PATCH 018/123] provide avatar_urls context --- blocks/coauthors/class-cap-block-coauthors.php | 3 ++- blocks/coauthors/src/edit.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/blocks/coauthors/class-cap-block-coauthors.php b/blocks/coauthors/class-cap-block-coauthors.php index 7bbfd962..9d917a9b 100644 --- a/blocks/coauthors/class-cap-block-coauthors.php +++ b/blocks/coauthors/class-cap-block-coauthors.php @@ -257,7 +257,8 @@ private static function get_template_render_function( array $block_template ) : $block_template, array( 'display_name' => $author->display_name, - 'link' => get_author_posts_url( $author->ID, $author->user_nicename ) + 'link' => get_author_posts_url( $author->ID, $author->user_nicename ), + 'avatar_urls' => rest_get_avatar_urls( $author->ID ), ) ) )->render( array( 'dynamic' => false ) ); diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js index 4771a540..03206c80 100644 --- a/blocks/coauthors/src/edit.js +++ b/blocks/coauthors/src/edit.js @@ -148,12 +148,12 @@ export default function Edit( { attributes, setAttributes, clientId, context, is { coAuthors && coAuthors - .map( ( { id, display_name, link } ) => { + .map( ( { id, display_name, link, avatar_urls } ) => { const isHidden = id === ( activeBlockContextId || coAuthors[0]?.id ); return ( { isHidden ? () : null } Date: Fri, 28 Jul 2023 13:19:18 -0400 Subject: [PATCH 019/123] more general css for inline style --- blocks/coauthors/src/style.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blocks/coauthors/src/style.css b/blocks/coauthors/src/style.css index f963ab8a..7b7e0810 100644 --- a/blocks/coauthors/src/style.css +++ b/blocks/coauthors/src/style.css @@ -1,4 +1,3 @@ -.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor, -.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor > * { +.wp-block-cap-coauthors.is-layout-cap-inline :where(*) { display: inline; } From fc40fb78b53a1de12c5a391334fe3e29a1da09d2 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 28 Jul 2023 13:19:31 -0400 Subject: [PATCH 020/123] build coauthors block --- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- blocks/coauthors/build/style-index.css | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 3d79c963..22a1a475 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'd41603de0318ef9844cb'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '5a2c562ff5dd8aa1dcad'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index 3ecae070..2a459c0b 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,f=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),m=n(779),v=n.n(m);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",h({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function b(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var k=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(k.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:o,context:i,isSelected:p}=e;const{separator:m,lastSeparator:h,layout:k,prefix:g,suffix:_}=t,{postId:x}=i,[E,C]=(0,r.useState)([{id:0,display_name:"CoAuthor Display Name",link:""}]),[O,S]=(0,r.useState)(),B=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&B.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!x)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${x}/`,signal:e.signal}).then(C).catch(P),()=>{e.abort()}}),[x]);const A=(0,s.useSelect)((e=>e(a.store).getBlocks(o))),I=e=>{n({layout:{...k,...e}})},N=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>I({type:"inline"}),isActive:"inline"===k.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>I({type:"block"}),isActive:"block"===k.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:N})),(0,r.createElement)("div",(0,a.useBlockProps)({className:v()([`is-layout-cap-${k.type}`])}),E&&"inline"===k.type&&(p||g)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:g,onChange:e=>n({prefix:e}),tagName:"span"}),E&&E.map((e=>{var t;let{id:n,display_name:o,link:l}=e;const i=n===(O||(null===(t=E[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,display_name:o,link:l}},i?(0,r.createElement)(b,null):null,(0,r.createElement)(w,{blocks:A,blockContextId:n,setActiveBlockContextId:S,isHidden:i}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===k.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},h&&n===o.length-1?`${h}`:`${m}`),t))),E&&"inline"===k.type&&(p||_)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>n({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===k.type&&(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:m||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:h||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,r.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",h({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function b(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var k=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(k.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:i,isSelected:p}=e;const{separator:v,lastSeparator:h,layout:k,prefix:_,suffix:g}=t,{postId:x}=i,[E,C]=(0,o.useState)([{id:0,display_name:"CoAuthor Display Name",link:""}]),[O,S]=(0,o.useState)(),B=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&B.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!x)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${x}/`,signal:e.signal}).then(C).catch(P),()=>{e.abort()}}),[x]);const A=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),I=e=>{n({layout:{...k,...e}})},N=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>I({type:"inline"}),isActive:"inline"===k.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>I({type:"block"}),isActive:"block"===k.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:N})),(0,o.createElement)("div",(0,a.useBlockProps)({className:m()([`is-layout-cap-${k.type}`])}),E&&"inline"===k.type&&(p||_)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:_,onChange:e=>n({prefix:e}),tagName:"span"}),E&&E.map((e=>{var t;let{id:n,display_name:r,link:l,avatar_urls:i}=e;const c=n===(O||(null===(t=E[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,display_name:r,link:l,avatar_urls:i}},c?(0,o.createElement)(b,null):null,(0,o.createElement)(w,{blocks:A,blockContextId:n,setActiveBlockContextId:S,isHidden:c}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===k.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},h&&n===r.length-1?`${h}`:`${v}`),t))),E&&"inline"===k.type&&(p||g)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:g,onChange:e=>n({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===k.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:v||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:h||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);s*{display:inline} +.wp-block-cap-coauthors.is-layout-cap-inline :where(*){display:inline} From dba39d497c41ecf8b09e28746ecb3720f3e1048e Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 31 Jul 2023 13:32:13 -0400 Subject: [PATCH 021/123] reduce whitespace to match JSX in editor --- blocks/coauthors/class-cap-block-coauthors.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/blocks/coauthors/class-cap-block-coauthors.php b/blocks/coauthors/class-cap-block-coauthors.php index 9d917a9b..25cba5ee 100644 --- a/blocks/coauthors/class-cap-block-coauthors.php +++ b/blocks/coauthors/class-cap-block-coauthors.php @@ -147,6 +147,9 @@ public static function render_coauthor_blocks_with_template( array $template, ar return array_map( self::get_composed_map_function( self::get_template_render_function( $template ), + // To match JSX from edition, remove line-breaks between blocks. + fn( $content ) => str_replace("\n", '', $content ), + // To match JSX from edition, trim whitespace around blocks. 'trim', self::get_block_wrapper_function('div', 'class="wp-block-cap-coauthor"') ), From eea9905ab7b2dd51e02321a147428618ac9fdd3c Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 1 Aug 2023 13:19:10 -0400 Subject: [PATCH 022/123] wip fse --- blocks/blocks.php | 8 +++ blocks/coauthor-avatar/build/block.json | 3 +- blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- .../class-cap-block-coauthor-avatar.php | 42 ++++++++++++++- blocks/coauthor-avatar/src/block.json | 3 +- blocks/coauthor-avatar/src/edit.js | 54 +++++++++++++++++-- blocks/coauthor-display-name/build/block.json | 10 ++-- .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- .../class-cap-block-coauthor-display-name.php | 43 ++++++++++++++- blocks/coauthor-display-name/src/block.json | 8 ++- blocks/coauthor-display-name/src/edit.js | 48 +++++++++++++++-- co-authors-plus.php | 10 ++-- .../class-coauthor-blocks-controller.php | 3 +- 15 files changed, 199 insertions(+), 41 deletions(-) create mode 100644 blocks/blocks.php diff --git a/blocks/blocks.php b/blocks/blocks.php new file mode 100644 index 00000000..fb9797f2 --- /dev/null +++ b/blocks/blocks.php @@ -0,0 +1,8 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'bff2582553524a68157f'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '2e1b0f04af558b46a4e8'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index d2e7b8ee..34adb171 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={363:function(){var e=window.wp.blocks,t=window.wp.element,n=window.wp.i18n,r=window.wp.blockEditor,o=window.wp.components,a=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(a.u2,{edit:function(e){let{context:a,attributes:i,setAttributes:l}=e;const{avatar_urls:c,link:u}=a,{isLink:s,size:f}=i;if(!c)return null;const p=Object.keys(c).map((e=>({value:e,label:`${e} x ${e}`}))),v=(0,t.createElement)("img",{width:f,height:f,src:`${c[f]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,r.useBlockProps)(),s?(0,t.createElement)("a",{href:u,onClick:e=>e.preventDefault()},v):v),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,n.__)("Avatar Settings")},(0,t.createElement)(o.ToggleControl,{label:(0,n.__)("Make avatar a link to author archive."),onChange:()=>l({isLink:!s}),checked:s}),(0,t.createElement)(o.SelectControl,{label:(0,n.__)("Avatar size"),value:f,options:p,onChange:e=>{l({size:Number(e)})}}))))}})}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=function(t,n,o,a){if(!n){var i=1/0;for(s=0;s=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(l=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[n,o,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,i=n[0],l=n[1],c=n[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(o in l)r.o(l,o)&&(r.m[o]=l[o]);if(c)var s=c(r)}for(t&&t(n);u{if(!c)return;const e=new AbortController;return apiFetch({path:`/coauthor-blocks/v1/coauthor/${c}`,signal:e.signal}).then(v).catch(D),()=>{e.abort()}}),[c]);const{avatar_urls:g,link:m,display_name:d}=f;if(!g||0===g.length)return null;const p=Object.keys(g).map((e=>({value:e,label:`${e} x ${e}`}))),E=(0,t.createElement)("img",{width:u,height:u,src:`${g[u]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,n.useBlockProps)(),h?(0,t.createElement)("a",{href:m,onClick:e=>e.preventDefault()},E):E),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,r.__)("Avatar Settings")},(0,t.createElement)(i.ToggleControl,{label:(0,r.__)("Make avatar a link to author archive."),onChange:()=>s({isLink:!h}),checked:h}),(0,t.createElement)(i.SelectControl,{label:(0,r.__)("Avatar size"),value:u,options:p,onChange:e=>{s({size:Number(e)})}}))))}})}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.m=t,e=[],n.O=function(t,r,i,a){if(!r){var o=1/0;for(h=0;h=a)&&Object.keys(n.O).every((function(e){return n.O[e](r[s])}))?r.splice(s--,1):(l=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[r,i,a]},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,r){var i,a,o=r[0],l=r[1],s=r[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(i in l)n.o(l,i)&&(n.m[i]=l[i]);if(s)var h=s(n)}for(t&&t(r);ccontext['avatar_urls'] ?? array(); + $author_name = $block->context['author_name'] ?? ''; + + if ( '' === $author_name ) { + return ''; + } + + $author = rest_get_server()->dispatch( + WP_REST_Request::from_url( + home_url( "/wp-json/coauthor-blocks/v1/coauthor/{$author_name}" ) + ) + )->get_data(); + + $avatar_urls = $author['avatar_urls'] ?? array(); if ( empty( $avatar_urls ) ) { return ''; } - $link = $block->context['link'] ?? ''; + $link = $author['link'] ?? ''; $is_link = $attributes['isLink'] ?? false; $size = $attributes['size'] ?? 24; $srcset = array_map( @@ -99,4 +111,30 @@ private static function get_block_wrapper_function( string $element_name, string return "<{$element_name} {$attributes}>{$content}"; }; } + /** + * Provide Author Archive Context + * + * @param array $context, + * @param array $parsed_block + * @param null|WP_Block $parent_block + * @return array + */ + public static function provide_author_archive_context( array $context, array $parsed_block, ?WP_Block $parent_block ) : array { + if ( ! is_author() ) { + return $context; + } + + if ( null === $parsed_block['blockName'] ) { + return $context; + } + + // author if you do an individual piece of a coauthor outside of a coauthor template. + if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( null === $parent_block || 'core/null' !== $parent_block->name ?? '' ) ) { + return array( + 'author_name' => get_query_var( 'author_name' ) + ); + } + + return $context; + } } diff --git a/blocks/coauthor-avatar/src/block.json b/blocks/coauthor-avatar/src/block.json index 6e14f59f..69821ed3 100644 --- a/blocks/coauthor-avatar/src/block.json +++ b/blocks/coauthor-avatar/src/block.json @@ -11,8 +11,7 @@ "html": false }, "usesContext": [ - "avatar_urls", - "link" + "author_name" ], "attributes": { "size" : { diff --git a/blocks/coauthor-avatar/src/edit.js b/blocks/coauthor-avatar/src/edit.js index ac002087..03c813b3 100644 --- a/blocks/coauthor-avatar/src/edit.js +++ b/blocks/coauthor-avatar/src/edit.js @@ -1,6 +1,8 @@ import { __ } from '@wordpress/i18n'; import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; import { SelectControl, PanelBody, ToggleControl } from '@wordpress/components'; +import { useEffect, useState } from '@wordpress/element'; +import { useDispatch } from '@wordpress/data'; /** * The edit function describes the structure of your block in the context of the @@ -12,10 +14,54 @@ import { SelectControl, PanelBody, ToggleControl } from '@wordpress/components'; */ export default function Edit( { context, attributes, setAttributes } ) { - const { avatar_urls, link } = context; + const { author_name } = context; const { isLink, size } = attributes; + const [ author, setAuthor ] = useState({ + link: '#', + display_name: 'CoAuthor Name', + // how to get defaults?? + avatar_urls: { + 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', + 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', + 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' + } + }); + const noticesDispatch = useDispatch('core/notices'); + + useEffect(() => { + if ( ! author_name ) { + return; + } + + const controller = new AbortController(); + + apiFetch( { + path: `/coauthor-blocks/v1/coauthor/${author_name}`, + signal: controller.signal + } ) + .then( setAuthor ) + .catch( handleError ) + + return () => { + controller.abort(); + } + }, [author_name]); + + /** + * Handle Error + * + * @param {Error} + */ + function handleError( error ) { + if ( 'AbortError' === error.name ) { + return; + } + noticesDispatch.createErrorNotice( error.message, { isDismissible: true } ); + } + + const { avatar_urls, link, display_name } = author; - if ( ! avatar_urls ) { + if ( ! avatar_urls || 0 === avatar_urls.length ) { return null; } @@ -46,19 +92,17 @@ export default function Edit( { context, attributes, setAttributes } ) { setAttributes( { isLink: ! isLink } ) } checked={ isLink } /> { setAttributes( { - size: Number( nextSize ), + size: Number( nextSize ) } ); } } /> diff --git a/blocks/coauthor-display-name/build/block.json b/blocks/coauthor-display-name/build/block.json index f01c98c7..87c55a31 100644 --- a/blocks/coauthor-display-name/build/block.json +++ b/blocks/coauthor-display-name/build/block.json @@ -3,13 +3,10 @@ "apiVersion": 2, "name": "cap/coauthor-display-name", "version": "0.1.0", - "title": "Co-Author Display Name", + "title": "Co-Author Name", "category": "widgets", "icon": "smiley", - "description": "Display a co-author's preferred name.", - "parent": [ - "cap/coauthors" - ], + "description": "Display a co-author's name.", "supports": { "html": false, "color": { @@ -39,8 +36,7 @@ } }, "usesContext": [ - "display_name", - "link" + "author_name" ], "attributes": { "isLink": { diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index 7afa5b5d..5133f2b8 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'c69cb3db7db5d297203c'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'b55411c118bbf4ad1581'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index 4748b8df..c9533b9c 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,n=window.wp.blockEditor,l=window.wp.components,o=window.wp.i18n,r=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(r.u2,{edit:function(e){let{context:r,attributes:a,setAttributes:i}=e;const{display_name:c,link:s}=r,{isLink:m,rel:p}=a;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("p",(0,n.useBlockProps)(),m?(0,t.createElement)("a",{href:s,rel:p,onClick:e=>e.preventDefault()},c):c),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(l.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make title a link"),onChange:()=>i({isLink:!m}),checked:m}),m&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:p,onChange:e=>i({rel:e})})))))}})}(); \ No newline at end of file +!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,n=window.wp.blockEditor,o=window.wp.components,r=window.wp.data,a=window.wp.i18n,l=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(l.u2,{edit:function(e){let{context:l,attributes:i,setAttributes:c}=e;const{author_name:s}=l,{isLink:u,rel:m}=i,[p,w]=(0,t.useState)({link:"#",display_name:"CoAuthor Name"}),h=(0,r.useDispatch)("core/notices");function d(e){"AbortError"!==e.name&&h.createErrorNotice(e.message,{isDismissible:!0})}(0,t.useEffect)((()=>{if(!s)return;const e=new AbortController;return apiFetch({path:`/coauthor-blocks/v1/coauthor/${s}`,signal:e.signal}).then(w).catch(d),()=>{e.abort()}}),[s]);const{link:k,display_name:g}=p;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("p",(0,n.useBlockProps)(),u?(0,t.createElement)("a",{href:k,rel:m,onClick:e=>e.preventDefault()},g):g),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,a.__)("Settings")},(0,t.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Make coauthor name a link"),onChange:()=>c({isLink:!u}),checked:u}),u&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(o.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:m,onChange:e=>c({rel:e})})))))}})}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index 505d0662..0af17d0c 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -14,6 +14,7 @@ class CAP_Block_CoAuthor_Display_Name { */ public function __construct() { add_action( 'init', array( __CLASS__, 'register_block' ) ); + add_action( 'render_block_context', array( __CLASS__, 'provide_author_archive_context' ), 10, 3 ); } /** * Register Block @@ -36,13 +37,25 @@ public static function register_block() : void { */ public static function render_block( array $attributes, string $content, WP_Block $block ) : string { - $display_name = $block->context['display_name'] ?? ''; + $author_name = $block->context['author_name'] ?? ''; + + if ( '' === $author_name ) { + return ''; + } + + $author = rest_get_server()->dispatch( + WP_REST_Request::from_url( + home_url( "/wp-json/coauthor-blocks/v1/coauthor/{$author_name}" ) + ) + )->get_data(); + + $display_name = $author['display_name'] ?? ''; if ( '' === $display_name ) { return ''; } - $link = $block->context['link'] ?? ''; + $link = $author['link'] ?? ''; $is_link = $attributes['isLink'] ?? false; $rel = $attributes['rel'] ?? ''; @@ -60,4 +73,30 @@ public static function render_block( array $attributes, string $content, WP_Bloc return sprintf( '

%s

', get_block_wrapper_attributes(), $inner_content ); } + /** + * Provide Author Archive Context + * + * @param array $context, + * @param array $parsed_block + * @param null|WP_Block $parent_block + * @return array + */ + public static function provide_author_archive_context( array $context, array $parsed_block, ?WP_Block $parent_block ) : array { + if ( ! is_author() ) { + return $context; + } + + if ( null === $parsed_block['blockName'] ) { + return $context; + } + + // author if you do an individual piece of a coauthor outside of a coauthor template. + if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( null === $parent_block || 'core/null' !== $parent_block->name ?? '' ) ) { + return array( + 'author_name' => get_query_var( 'author_name' ) + ); + } + + return $context; + } } diff --git a/blocks/coauthor-display-name/src/block.json b/blocks/coauthor-display-name/src/block.json index 4acc124b..7458c3cb 100644 --- a/blocks/coauthor-display-name/src/block.json +++ b/blocks/coauthor-display-name/src/block.json @@ -3,11 +3,10 @@ "apiVersion": 2, "name": "cap/coauthor-display-name", "version": "0.1.0", - "title": "Co-Author Display Name", + "title": "Co-Author Name", "category": "widgets", "icon": "smiley", - "description": "Display a co-author's preferred name.", - "parent": ["cap/coauthors"], + "description": "Display a co-author's name.", "supports": { "html": false, "color": { @@ -37,8 +36,7 @@ } }, "usesContext": [ - "display_name", - "link" + "author_name" ], "attributes": { "isLink": { diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index fa8a06b7..8f394a8d 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -4,9 +4,10 @@ * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ -import { useBlockProps } from '@wordpress/block-editor'; -import { InspectorControls } from '@wordpress/block-editor'; +import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; import { TextControl, PanelBody, ToggleControl } from '@wordpress/components'; +import { useEffect, useState } from '@wordpress/element'; +import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; /** @@ -18,8 +19,47 @@ import { __ } from '@wordpress/i18n'; * @return {WPElement} Element to render. */ export default function Edit( { context, attributes, setAttributes } ) { - const { display_name, link } = context; + const { author_name } = context; const { isLink, rel } = attributes; + const [ author, setAuthor ] = useState({ + link: '#', + display_name: 'CoAuthor Name' + }); + const noticesDispatch = useDispatch('core/notices'); + + useEffect(() => { + if ( ! author_name ) { + return; + } + + const controller = new AbortController(); + + apiFetch( { + path: `/coauthor-blocks/v1/coauthor/${author_name}`, + signal: controller.signal + } ) + .then( setAuthor ) + .catch( handleError ) + + return () => { + controller.abort(); + } + }, [author_name]); + + /** + * Handle Error + * + * @param {Error} + */ + function handleError( error ) { + if ( 'AbortError' === error.name ) { + return; + } + noticesDispatch.createErrorNotice( error.message, { isDismissible: true } ); + } + + const { link, display_name } = author; + return ( <>

@@ -39,7 +79,7 @@ export default function Edit( { context, attributes, setAttributes } ) { setAttributes( { isLink: ! isLink } ) } checked={ isLink } /> diff --git a/co-authors-plus.php b/co-authors-plus.php index 209a7dcd..a36c1f3e 100755 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -34,10 +34,10 @@ require_once __DIR__ . '/php/class-coauthors-plus.php'; require_once __DIR__ . '/php/class-coauthors-iterator.php'; -require_once dirname( __FILE__ ) . '/blocks/coauthors/class-cap-block-coauthors.php'; -require_once dirname( __FILE__ ) . '/blocks/coauthor-avatar/class-cap-block-coauthor-avatar.php'; -require_once dirname( __FILE__ ) . '/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php'; +// Blocks +require_once dirname( __FILE__ ) . '/blocks/blocks.php'; +// REST APIs for Blocks require_once dirname( __FILE__ ) . '/php/api/endpoints/class-coauthor-blocks-controller.php'; if ( defined( 'WP_CLI' ) && WP_CLI ) { @@ -48,10 +48,6 @@ $coauthors_plus = new CoAuthors_Plus(); $coauthors_endpoint = new CoAuthors\API\Endpoints( $coauthors_plus ); -new CAP_Block_CoAuthors(); -new CAP_Block_CoAuthor_Avatar(); -new CAP_Block_CoAuthor_Display_Name(); - if ( ! function_exists( 'wp_notify_postauthor' ) ) : /** * Notify a co-author of a comment/trackback/pingback to one of their posts. diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index ec6913ae..ccd6a7c0 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -75,7 +75,8 @@ public function register_routes() : void { array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permission_check' ), + // 'permission_callback' => array( $this, 'get_item_permission_check' ), + 'permission_callback' => '__return_true' ) ) ); From 2b73d4b0e57f148e5581201beead16c1b7477385 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 1 Aug 2023 15:21:06 -0400 Subject: [PATCH 023/123] more FSE support through dummy data and context --- blocks/coauthor-avatar/build/block.json | 2 +- blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- .../class-cap-block-coauthor-avatar.php | 23 +++++----- blocks/coauthor-avatar/src/block.json | 2 +- blocks/coauthor-avatar/src/edit.js | 43 +++--------------- blocks/coauthor-display-name/build/block.json | 2 +- .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- .../class-cap-block-coauthor-display-name.php | 23 +++++----- blocks/coauthor-display-name/src/block.json | 2 +- blocks/coauthor-display-name/src/edit.js | 44 ++++--------------- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- .../coauthors/class-cap-block-coauthors.php | 28 +++++++++--- blocks/coauthors/src/edit.js | 28 +++++++----- 16 files changed, 89 insertions(+), 120 deletions(-) diff --git a/blocks/coauthor-avatar/build/block.json b/blocks/coauthor-avatar/build/block.json index c24c1f1d..6a981c3e 100644 --- a/blocks/coauthor-avatar/build/block.json +++ b/blocks/coauthor-avatar/build/block.json @@ -11,7 +11,7 @@ "html": false }, "usesContext": [ - "author_name" + "cap/author" ], "attributes": { "size": { diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index 8e6fa966..934e890a 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '2e1b0f04af558b46a4e8'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a5214c7c6f74fdbb694f'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index 34adb171..93151d48 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={631:function(){var e=window.wp.blocks,t=window.wp.element,r=window.wp.i18n,n=window.wp.blockEditor,i=window.wp.components,a=window.wp.data,o=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(o.u2,{edit:function(e){let{context:o,attributes:l,setAttributes:s}=e;const{author_name:c}=o,{isLink:h,size:u}=l,[f,v]=(0,t.useState)({link:"#",display_name:"CoAuthor Name",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}),w=(0,a.useDispatch)("core/notices");function D(e){"AbortError"!==e.name&&w.createErrorNotice(e.message,{isDismissible:!0})}(0,t.useEffect)((()=>{if(!c)return;const e=new AbortController;return apiFetch({path:`/coauthor-blocks/v1/coauthor/${c}`,signal:e.signal}).then(v).catch(D),()=>{e.abort()}}),[c]);const{avatar_urls:g,link:m,display_name:d}=f;if(!g||0===g.length)return null;const p=Object.keys(g).map((e=>({value:e,label:`${e} x ${e}`}))),E=(0,t.createElement)("img",{width:u,height:u,src:`${g[u]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,n.useBlockProps)(),h?(0,t.createElement)("a",{href:m,onClick:e=>e.preventDefault()},E):E),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,r.__)("Avatar Settings")},(0,t.createElement)(i.ToggleControl,{label:(0,r.__)("Make avatar a link to author archive."),onChange:()=>s({isLink:!h}),checked:h}),(0,t.createElement)(i.SelectControl,{label:(0,r.__)("Avatar size"),value:u,options:p,onChange:e=>{s({size:Number(e)})}}))))}})}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.m=t,e=[],n.O=function(t,r,i,a){if(!r){var o=1/0;for(h=0;h=a)&&Object.keys(n.O).every((function(e){return n.O[e](r[s])}))?r.splice(s--,1):(l=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[r,i,a]},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,r){var i,a,o=r[0],l=r[1],s=r[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(i in l)n.o(l,i)&&(n.m[i]=l[i]);if(s)var h=s(n)}for(t&&t(r);c({value:e,label:`${e} x ${e}`}))),d=(0,t.createElement)("img",{width:h,height:h,src:`${v[h]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,r.useBlockProps)(),c?(0,t.createElement)("a",{href:w,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,n.__)("Avatar Settings")},(0,t.createElement)(i.ToggleControl,{label:(0,n.__)("Make avatar a link to author archive."),onChange:()=>o({isLink:!c}),checked:c}),(0,t.createElement)(i.SelectControl,{label:(0,n.__)("Avatar size"),value:h,options:g,onChange:e=>{o({size:Number(e)})}}))))}})}},n={};function r(e){var i=n[e];if(void 0!==i)return i.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=function(t,n,i,a){if(!n){var l=1/0;for(h=0;h=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(o=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[n,i,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var i,a,l=n[0],o=n[1],s=n[2],c=0;if(l.some((function(t){return 0!==e[t]}))){for(i in o)r.o(o,i)&&(r.m[i]=o[i]);if(s)var h=s(r)}for(t&&t(n);ccontext['author_name'] ?? ''; + $author = $block->context['cap/author'] ?? array(); - if ( '' === $author_name ) { + if ( empty( $author ) ) { return ''; } - $author = rest_get_server()->dispatch( - WP_REST_Request::from_url( - home_url( "/wp-json/coauthor-blocks/v1/coauthor/{$author_name}" ) - ) - )->get_data(); - $avatar_urls = $author['avatar_urls'] ?? array(); if ( empty( $avatar_urls ) ) { @@ -129,9 +123,18 @@ public static function provide_author_archive_context( array $context, array $pa } // author if you do an individual piece of a coauthor outside of a coauthor template. - if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( null === $parent_block || 'core/null' !== $parent_block->name ?? '' ) ) { + if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( ! array_key_exists( 'cap/author', $context ) || empty( $context['cap/author'] ) ) ) { return array( - 'author_name' => get_query_var( 'author_name' ) + 'cap/author' => rest_get_server()->dispatch( + WP_REST_Request::from_url( + home_url( + sprintf( + '/wp-json/coauthor-blocks/v1/coauthor/%s', + get_query_var( 'author_name' ) + ) + ) + ) + )->get_data() ); } diff --git a/blocks/coauthor-avatar/src/block.json b/blocks/coauthor-avatar/src/block.json index 69821ed3..8d692513 100644 --- a/blocks/coauthor-avatar/src/block.json +++ b/blocks/coauthor-avatar/src/block.json @@ -11,7 +11,7 @@ "html": false }, "usesContext": [ - "author_name" + "cap/author" ], "attributes": { "size" : { diff --git a/blocks/coauthor-avatar/src/edit.js b/blocks/coauthor-avatar/src/edit.js index 03c813b3..7f540ee0 100644 --- a/blocks/coauthor-avatar/src/edit.js +++ b/blocks/coauthor-avatar/src/edit.js @@ -14,52 +14,19 @@ import { useDispatch } from '@wordpress/data'; */ export default function Edit( { context, attributes, setAttributes } ) { - const { author_name } = context; const { isLink, size } = attributes; - const [ author, setAuthor ] = useState({ + const author = context['cap/author'] || { + id: 0, + display_name: 'FirstName LastName', link: '#', - display_name: 'CoAuthor Name', - // how to get defaults?? avatar_urls: { 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' } - }); - const noticesDispatch = useDispatch('core/notices'); - - useEffect(() => { - if ( ! author_name ) { - return; - } - - const controller = new AbortController(); - - apiFetch( { - path: `/coauthor-blocks/v1/coauthor/${author_name}`, - signal: controller.signal - } ) - .then( setAuthor ) - .catch( handleError ) - - return () => { - controller.abort(); - } - }, [author_name]); - - /** - * Handle Error - * - * @param {Error} - */ - function handleError( error ) { - if ( 'AbortError' === error.name ) { - return; - } - noticesDispatch.createErrorNotice( error.message, { isDismissible: true } ); - } + }; - const { avatar_urls, link, display_name } = author; + const { avatar_urls, link } = author; if ( ! avatar_urls || 0 === avatar_urls.length ) { return null; diff --git a/blocks/coauthor-display-name/build/block.json b/blocks/coauthor-display-name/build/block.json index 87c55a31..fc95a073 100644 --- a/blocks/coauthor-display-name/build/block.json +++ b/blocks/coauthor-display-name/build/block.json @@ -36,7 +36,7 @@ } }, "usesContext": [ - "author_name" + "cap/author" ], "attributes": { "isLink": { diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index 5133f2b8..0da4c1f9 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'b55411c118bbf4ad1581'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a2460e19116ea13eed8a'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index c9533b9c..5b60ce82 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,n=window.wp.blockEditor,o=window.wp.components,r=window.wp.data,a=window.wp.i18n,l=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(l.u2,{edit:function(e){let{context:l,attributes:i,setAttributes:c}=e;const{author_name:s}=l,{isLink:u,rel:m}=i,[p,w]=(0,t.useState)({link:"#",display_name:"CoAuthor Name"}),h=(0,r.useDispatch)("core/notices");function d(e){"AbortError"!==e.name&&h.createErrorNotice(e.message,{isDismissible:!0})}(0,t.useEffect)((()=>{if(!s)return;const e=new AbortController;return apiFetch({path:`/coauthor-blocks/v1/coauthor/${s}`,signal:e.signal}).then(w).catch(d),()=>{e.abort()}}),[s]);const{link:k,display_name:g}=p;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("p",(0,n.useBlockProps)(),u?(0,t.createElement)("a",{href:k,rel:m,onClick:e=>e.preventDefault()},g):g),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,a.__)("Settings")},(0,t.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Make coauthor name a link"),onChange:()=>c({isLink:!u}),checked:u}),u&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(o.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:m,onChange:e=>c({rel:e})})))))}})}(); \ No newline at end of file +!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,n=window.wp.blockEditor,a=window.wp.components,i=(window.wp.data,window.wp.i18n),l=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(l.u2,{edit:function(e){let{context:l,attributes:r,setAttributes:o}=e;const s=l["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},{isLink:D,rel:w}=r,[c,m]=(0,t.useState)(s),{link:g,display_name:h}=c;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("p",(0,n.useBlockProps)(),D?(0,t.createElement)("a",{href:g,rel:w,onClick:e=>e.preventDefault()},h):h),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,i.__)("Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Make coauthor name a link"),onChange:()=>o({isLink:!D}),checked:D}),D&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Link rel"),value:w,onChange:e=>o({rel:e})})))))}})}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index 0af17d0c..ccc7c8b4 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -37,18 +37,12 @@ public static function register_block() : void { */ public static function render_block( array $attributes, string $content, WP_Block $block ) : string { - $author_name = $block->context['author_name'] ?? ''; + $author = $block->context['cap/author'] ?? array(); - if ( '' === $author_name ) { + if ( empty( $author ) ) { return ''; } - $author = rest_get_server()->dispatch( - WP_REST_Request::from_url( - home_url( "/wp-json/coauthor-blocks/v1/coauthor/{$author_name}" ) - ) - )->get_data(); - $display_name = $author['display_name'] ?? ''; if ( '' === $display_name ) { @@ -91,9 +85,18 @@ public static function provide_author_archive_context( array $context, array $pa } // author if you do an individual piece of a coauthor outside of a coauthor template. - if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( null === $parent_block || 'core/null' !== $parent_block->name ?? '' ) ) { + if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( ! array_key_exists( 'cap/author', $context ) || empty( $context['cap/author'] ) ) ) { return array( - 'author_name' => get_query_var( 'author_name' ) + 'cap/author' => rest_get_server()->dispatch( + WP_REST_Request::from_url( + home_url( + sprintf( + '/wp-json/coauthor-blocks/v1/coauthor/%s', + get_query_var( 'author_name' ) + ) + ) + ) + )->get_data() ); } diff --git a/blocks/coauthor-display-name/src/block.json b/blocks/coauthor-display-name/src/block.json index 7458c3cb..d159579c 100644 --- a/blocks/coauthor-display-name/src/block.json +++ b/blocks/coauthor-display-name/src/block.json @@ -36,7 +36,7 @@ } }, "usesContext": [ - "author_name" + "cap/author" ], "attributes": { "isLink": { diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index 8f394a8d..fa35840c 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -19,44 +19,18 @@ import { __ } from '@wordpress/i18n'; * @return {WPElement} Element to render. */ export default function Edit( { context, attributes, setAttributes } ) { - const { author_name } = context; + const { isLink, rel } = attributes; - const [ author, setAuthor ] = useState({ + const author = context['cap/author'] || { + id: 0, + display_name: 'FirstName LastName', link: '#', - display_name: 'CoAuthor Name' - }); - const noticesDispatch = useDispatch('core/notices'); - - useEffect(() => { - if ( ! author_name ) { - return; - } - - const controller = new AbortController(); - - apiFetch( { - path: `/coauthor-blocks/v1/coauthor/${author_name}`, - signal: controller.signal - } ) - .then( setAuthor ) - .catch( handleError ) - - return () => { - controller.abort(); - } - }, [author_name]); - - /** - * Handle Error - * - * @param {Error} - */ - function handleError( error ) { - if ( 'AbortError' === error.name ) { - return; + avatar_urls: { + 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', + 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', + 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' } - noticesDispatch.createErrorNotice( error.message, { isDismissible: true } ); - } + }; const { link, display_name } = author; diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 22a1a475..67fb5a09 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '5a2c562ff5dd8aa1dcad'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'a6d3f0c9d17f103b2d77'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index 2a459c0b..c51ee3bc 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,f=(0,o.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,o.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,o.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),v=n(779),m=n.n(v);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",h({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function b(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var k=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(k.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:i,isSelected:p}=e;const{separator:v,lastSeparator:h,layout:k,prefix:_,suffix:g}=t,{postId:x}=i,[E,C]=(0,o.useState)([{id:0,display_name:"CoAuthor Display Name",link:""}]),[O,S]=(0,o.useState)(),B=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&B.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!x)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${x}/`,signal:e.signal}).then(C).catch(P),()=>{e.abort()}}),[x]);const A=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),I=e=>{n({layout:{...k,...e}})},N=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>I({type:"inline"}),isActive:"inline"===k.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>I({type:"block"}),isActive:"block"===k.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:N})),(0,o.createElement)("div",(0,a.useBlockProps)({className:m()([`is-layout-cap-${k.type}`])}),E&&"inline"===k.type&&(p||_)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:_,onChange:e=>n({prefix:e}),tagName:"span"}),E&&E.map((e=>{var t;let{id:n,display_name:r,link:l,avatar_urls:i}=e;const c=n===(O||(null===(t=E[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:n,value:{coAuthorId:n,display_name:r,link:l,avatar_urls:i}},c?(0,o.createElement)(b,null):null,(0,o.createElement)(w,{blocks:A,blockContextId:n,setActiveBlockContextId:S,isHidden:c}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===k.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},h&&n===r.length-1?`${h}`:`${v}`),t))),E&&"inline"===k.type&&(p||g)&&(0,o.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:g,onChange:e=>n({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===k.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:v||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:h||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);s{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function g(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var E=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(E.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:i,isSelected:p}=e;const{separator:d,lastSeparator:m,layout:E,prefix:b,suffix:y}=t,{postId:C}=i,[D,k]=(0,o.useState)([{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[_,F]=(0,o.useState)(),O=(0,s.useDispatch)("core/notices");function S(e){"AbortError"!==e.name&&O.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!C)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${C}/`,signal:e.signal}).then(k).catch(S),()=>{e.abort()}}),[C]);const B=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),A=e=>{n({layout:{...E,...e}})},P=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>A({type:"inline"}),isActive:"inline"===E.type},{icon:h,title:(0,u.__)("Block"),onClick:()=>A({type:"block"}),isActive:"block"===E.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:P})),(0,o.createElement)("div",(0,a.useBlockProps)({className:v()([`is-layout-cap-${E.type}`])}),D&&"inline"===E.type&&(p||b)&&(0,o.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:b,onChange:e=>n({prefix:e}),tagName:"span"}),D&&D.map((e=>{var t;const n=e.id===(_||(null===(t=D[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,o.createElement)(g,null):null,(0,o.createElement)(w,{blocks:B,blockContextId:e.id,setActiveBlockContextId:F,isHidden:n}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===E.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},m&&n===r.length-1?`${m}`:`${d}`),t))),D&&"inline"===E.type&&(p||y)&&(0,o.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:y,onChange:e=>n({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===E.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:d||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:m||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);sdispatch( + WP_REST_Request::from_url( + home_url( + sprintf( + '/wp-json/coauthor-blocks/v1/coauthor/%s', + $author->user_nicename + ) + ) + ) + )->get_data(); + }, + get_coauthors( $post_id ) + ); if ( ! is_array( $authors ) || empty( $authors ) ) { return ''; @@ -254,17 +268,19 @@ private static function get_block_wrapper_function( string $element_name, string * @return callable */ private static function get_template_render_function( array $block_template ) : callable { - return function( stdClass|WP_User $author ) use ( $block_template ) : string { + return function( array $author ) use ( $block_template ) : string { return ( new WP_Block( $block_template, array( - 'display_name' => $author->display_name, - 'link' => get_author_posts_url( $author->ID, $author->user_nicename ), - 'avatar_urls' => rest_get_avatar_urls( $author->ID ), + 'cap/author' => $author, ) ) - )->render( array( 'dynamic' => false ) ); + )->render( + array( + 'dynamic' => false, + ) + ); }; } diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js index 03206c80..26a71c57 100644 --- a/blocks/coauthors/src/edit.js +++ b/blocks/coauthors/src/edit.js @@ -54,12 +54,18 @@ export default function Edit( { attributes, setAttributes, clientId, context, is const { postId } = context; /* Default state for full site editing */ - const [ coAuthors, setCoAuthors ] = useState([{ - id: 0, - display_name: 'CoAuthor Display Name', - link: '' - }]); - + const [ coAuthors, setCoAuthors ] = useState([ + { + id: 0, + display_name: 'FirstName LastName', + link: '#', + avatar_urls: { + 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', + 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', + 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' + } + } + ]); const [ activeBlockContextId, setActiveBlockContextId ] = useState(); const noticesDispatch = useDispatch('core/notices'); @@ -148,17 +154,17 @@ export default function Edit( { attributes, setAttributes, clientId, context, is { coAuthors && coAuthors - .map( ( { id, display_name, link, avatar_urls } ) => { - const isHidden = id === ( activeBlockContextId || coAuthors[0]?.id ); + .map( ( author ) => { + const isHidden = author.id === ( activeBlockContextId || coAuthors[0]?.id ); return ( { isHidden ? () : null } From 4a7550d48bfa0d0952d34043827d9a0e631b7387 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 1 Aug 2023 15:22:55 -0400 Subject: [PATCH 024/123] undo dev permissions change --- php/api/endpoints/class-coauthor-blocks-controller.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index ccd6a7c0..ec6913ae 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -75,8 +75,7 @@ public function register_routes() : void { array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), - // 'permission_callback' => array( $this, 'get_item_permission_check' ), - 'permission_callback' => '__return_true' + 'permission_callback' => array( $this, 'get_item_permission_check' ), ) ) ); From 8cb50ad72bfbc2391b0d29bb873c6928a7c2dd60 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 2 Aug 2023 12:05:30 -0400 Subject: [PATCH 025/123] support vertical spacing, blockgap --- blocks/coauthors/build/block.json | 6 +- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- blocks/coauthors/build/style-index.css | 2 +- .../coauthors/class-cap-block-coauthors.php | 101 +++++++++++++++++- blocks/coauthors/src/block.json | 4 +- blocks/coauthors/src/edit.js | 59 +++++----- blocks/coauthors/src/style.css | 5 + 8 files changed, 145 insertions(+), 36 deletions(-) diff --git a/blocks/coauthors/build/block.json b/blocks/coauthors/build/block.json index 17dc97ee..461da882 100644 --- a/blocks/coauthors/build/block.json +++ b/blocks/coauthors/build/block.json @@ -29,9 +29,13 @@ "spacing": { "margin": true, "padding": true, + "blockGap": [ + "vertical" + ], "__experimentalDefaultControls": { "margin": false, - "padding": false + "padding": false, + "blockGap": false } } }, diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 67fb5a09..df302f72 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'a6d3f0c9d17f103b2d77'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2513e86d26fbc6c4ed0e'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index c51ee3bc..49e71616 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,f=(0,o.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,o.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),h=(0,o.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),d=n(779),v=n.n(d);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function g(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var E=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(E.u2,{edit:function(e){let{attributes:t,setAttributes:n,clientId:r,context:i,isSelected:p}=e;const{separator:d,lastSeparator:m,layout:E,prefix:b,suffix:y}=t,{postId:C}=i,[D,k]=(0,o.useState)([{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[_,F]=(0,o.useState)(),O=(0,s.useDispatch)("core/notices");function S(e){"AbortError"!==e.name&&O.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!C)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${C}/`,signal:e.signal}).then(k).catch(S),()=>{e.abort()}}),[C]);const B=(0,s.useSelect)((e=>e(a.store).getBlocks(r))),A=e=>{n({layout:{...E,...e}})},P=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>A({type:"inline"}),isActive:"inline"===E.type},{icon:h,title:(0,u.__)("Block"),onClick:()=>A({type:"block"}),isActive:"block"===E.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:P})),(0,o.createElement)("div",(0,a.useBlockProps)({className:v()([`is-layout-cap-${E.type}`])}),D&&"inline"===E.type&&(p||b)&&(0,o.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:b,onChange:e=>n({prefix:e}),tagName:"span"}),D&&D.map((e=>{var t;const n=e.id===(_||(null===(t=D[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,o.createElement)(g,null):null,(0,o.createElement)(w,{blocks:B,blockContextId:e.id,setActiveBlockContextId:F,isHidden:n}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===E.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},m&&n===r.length-1?`${m}`:`${d}`),t))),D&&"inline"===E.type&&(p||y)&&(0,o.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:y,onChange:e=>n({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},"inline"===E.type&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:d||"",onChange:e=>{n({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:m||"",onChange:e=>{n({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")})))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);s{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function g(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var E=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(E.u2,{edit:function(e){var t,n;let{attributes:r,setAttributes:i,clientId:p,context:v,isSelected:m}=e;const{separator:E,lastSeparator:b,layout:y,prefix:C,suffix:D}=r,{postId:k}=v,[_,F]=(0,o.useState)([{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[S,O]=(0,o.useState)(),B=(0,s.useDispatch)("core/notices");function A(e){"AbortError"!==e.name&&B.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!k)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${k}/`,signal:e.signal}).then(F).catch(A),()=>{e.abort()}}),[k]);const P=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...y,...e}})},N=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===y.type},{icon:h,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===y.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:N})),(0,o.createElement)("div",(0,a.useBlockProps)({className:d()([`is-layout-cap-${y.type}`]),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==r||null===(t=r.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),_&&"inline"===y.type&&(m||C)&&(0,o.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:C,onChange:e=>i({prefix:e}),tagName:"span"}),_&&_.map((e=>{var t;const n=e.id===(S||(null===(t=_[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,o.createElement)(g,null):null,(0,o.createElement)(w,{blocks:P,blockContextId:e.id,setActiveBlockContextId:O,isHidden:n}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===y.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},b&&n===r.length-1?`${b}`:`${E}`),t))),_&&"inline"===y.type&&(m||D)&&(0,o.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:D,onChange:e=>i({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,"inline"===y.type&&(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:b||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);scontext ) ? absint( $block->context['postId'] ) : 0; if ( 0 === $post_id ) { @@ -91,11 +92,19 @@ function( stdClass|WP_User $author ) : array { $inner_content = implode( $blocks_with_separators ); + if ( 'block' === $attributes['layout']['type'] && $attributes['style']['spacing']['blockGap'] ?? false ) { + $gap_value = self::get_gap_css_value( self::get_normalized_gap_value( $attributes['style']['spacing']['blockGap'])); + $style = "gap: {$gap_value};"; + } else { + $style = null; + } + return self::get_block_wrapper_function( 'div', get_block_wrapper_attributes( array( - 'class' => "is-layout-cap-{$attributes['layout']['type']}" + 'class' => "is-layout-cap-{$attributes['layout']['type']}", + 'style' => $style ) ) )( $inner_content ); @@ -298,4 +307,94 @@ private static function get_block_as_template( WP_Block $block ) : array { ) ); } + + public static function has_gap_attribute( array $attributes ) : bool { + return ($attributes['style']['spacing']['blockGap'] ?? false) ? true : false; + } + + public static function get_gap_css_value( array $gaps ) : string { + return $gaps['row'] === $gaps['column'] ? $gaps['row'] : "{$gaps['row']} {$gaps['column']}"; + } + + public static function get_normalized_gap_value( string|array $gap ) : array { + + if ( is_array( $gap ) ) { + $gap = array_merge( + array( + 'top' => '0', + 'left' => '0' + ), + $gap + ); + } + + return array( + 'row' => self::get_preset_css_value( is_string( $gap ) ? $gap : $gap['top'] ), + 'column' => self::get_preset_css_value( is_string( $gap ) ? $gap : $gap['left'] ), + ); + } + + + + + public static function get_preset_css_value( string $value ) : string { + if ( 'var:' !== substr( $value, 0, 4 ) ) { + return $value; + } + return sprintf( + 'var(--wp--%s)', + str_replace( '|', '--', substr( $value, 4 ) ) + ); + } + + /** + * Get Block Gap from Block Style Attribute + * Reduce block gap settings into custom proprties we can use in our CSS. + * + * @param array style + * @return string + */ + public static function get_block_gap_from_block_style_attribute( array $style ) : string { + + if ( ! array_key_exists( 'spacing', $style ) ) { + return ''; + } + + $block_gap = $style['spacing']['blockGap'] ?? ''; + + if ( empty( $block_gap ) ) { + return ''; + } + + if ( ! is_array( $block_gap ) ) { + $block_gap = array( + 'top' => $block_gap, + 'left' => $block_gap + ); + } + + $directions = array( + 'top' => 'row', + 'left' => 'column' + ); + + $declarations = array_map( + function( string $gap, $key ) use ( $directions ) : string { + + if ( 'var:preset|spacing|' === substr( $gap, 0, 19 ) ) { + $slug = str_replace( '|', '-', substr( $gap, 19 ) ); + $value = "var(--wp--preset--spacing--{$slug})"; + } else { + $value = $gap; + } + + return "{$directions[$key]}-gap:{$value}"; + }, + $block_gap, + array_keys( $block_gap ) + ); + + return implode( ';', $declarations ); + } + } diff --git a/blocks/coauthors/src/block.json b/blocks/coauthors/src/block.json index 2f68fcc2..f5db2dc8 100644 --- a/blocks/coauthors/src/block.json +++ b/blocks/coauthors/src/block.json @@ -29,9 +29,11 @@ "spacing": { "margin": true, "padding": true, + "blockGap": ["vertical"], "__experimentalDefaultControls": { "margin": false, - "padding": false + "padding": false, + "blockGap": false } } }, diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js index 26a71c57..fbdeb567 100644 --- a/blocks/coauthors/src/edit.js +++ b/blocks/coauthors/src/edit.js @@ -11,7 +11,8 @@ import { useInnerBlocksProps, store as blockEditorStore, InspectorControls, - RichText + RichText, + __experimentalGetGapCSSValue } from '@wordpress/block-editor'; import { TextControl, ToolbarGroup, PanelBody } from '@wordpress/components'; import apiFetch from '@wordpress/api-fetch'; @@ -131,7 +132,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is -

+
{ coAuthors && 'inline' === layout.type && @@ -159,7 +160,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is return ( { isHidden ? () : null } - - { - 'inline' === layout.type && - ( - <> - { - setAttributes( { separator: nextValue } ); - } } - help={ __( 'Enter character(s) used to separate authors.' ) } - /> - { - setAttributes( { lastSeparator: nextValue } ); - } } - help={ __( 'Enter character(s) used to distinguish the last author.' ) } - /> - - ) - } - + { + 'inline' === layout.type && + ( + + { + setAttributes( { separator: nextValue } ); + } } + help={ __( 'Enter character(s) used to separate authors.' ) } + /> + { + setAttributes( { lastSeparator: nextValue } ); + } } + help={ __( 'Enter character(s) used to distinguish the last author.' ) } + /> + + ) + } ); diff --git a/blocks/coauthors/src/style.css b/blocks/coauthors/src/style.css index 7b7e0810..ce404765 100644 --- a/blocks/coauthors/src/style.css +++ b/blocks/coauthors/src/style.css @@ -1,3 +1,8 @@ .wp-block-cap-coauthors.is-layout-cap-inline :where(*) { display: inline; } + +.wp-block-cap-coauthors.is-layout-cap-block { + display: flex; + flex-direction: column; +} From d35ecd23ffc070e71b4d157a98d29f70320ebb86 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 2 Aug 2023 13:50:38 -0400 Subject: [PATCH 026/123] better match for client-side gap calculation --- .../coauthors/class-cap-block-coauthors.php | 84 +++++-------------- 1 file changed, 22 insertions(+), 62 deletions(-) diff --git a/blocks/coauthors/class-cap-block-coauthors.php b/blocks/coauthors/class-cap-block-coauthors.php index 41d26c26..36ebc29d 100644 --- a/blocks/coauthors/class-cap-block-coauthors.php +++ b/blocks/coauthors/class-cap-block-coauthors.php @@ -93,8 +93,10 @@ function( stdClass|WP_User $author ) : array { $inner_content = implode( $blocks_with_separators ); if ( 'block' === $attributes['layout']['type'] && $attributes['style']['spacing']['blockGap'] ?? false ) { - $gap_value = self::get_gap_css_value( self::get_normalized_gap_value( $attributes['style']['spacing']['blockGap'])); - $style = "gap: {$gap_value};"; + $gap_value = self::get_gap_css_value( + self::get_normalized_gap_value($attributes['style']['spacing']['blockGap']) + ); + $style = "gap:{$gap_value};"; } else { $style = null; } @@ -308,16 +310,23 @@ private static function get_block_as_template( WP_Block $block ) : array { ); } - public static function has_gap_attribute( array $attributes ) : bool { - return ($attributes['style']['spacing']['blockGap'] ?? false) ? true : false; - } - + /** + * Get Gap CSS Value + * + * @param array $gaps + * @return string + */ public static function get_gap_css_value( array $gaps ) : string { return $gaps['row'] === $gaps['column'] ? $gaps['row'] : "{$gaps['row']} {$gaps['column']}"; } + /** + * Get Normalize Gap Value + * + * @param string|array $gap + * @return array + */ public static function get_normalized_gap_value( string|array $gap ) : array { - if ( is_array( $gap ) ) { $gap = array_merge( array( @@ -327,16 +336,18 @@ public static function get_normalized_gap_value( string|array $gap ) : array { $gap ); } - return array( 'row' => self::get_preset_css_value( is_string( $gap ) ? $gap : $gap['top'] ), 'column' => self::get_preset_css_value( is_string( $gap ) ? $gap : $gap['left'] ), ); } - - - + /** + * Get Preset CSS Value + * + * @param string $value + * @return string + */ public static function get_preset_css_value( string $value ) : string { if ( 'var:' !== substr( $value, 0, 4 ) ) { return $value; @@ -346,55 +357,4 @@ public static function get_preset_css_value( string $value ) : string { str_replace( '|', '--', substr( $value, 4 ) ) ); } - - /** - * Get Block Gap from Block Style Attribute - * Reduce block gap settings into custom proprties we can use in our CSS. - * - * @param array style - * @return string - */ - public static function get_block_gap_from_block_style_attribute( array $style ) : string { - - if ( ! array_key_exists( 'spacing', $style ) ) { - return ''; - } - - $block_gap = $style['spacing']['blockGap'] ?? ''; - - if ( empty( $block_gap ) ) { - return ''; - } - - if ( ! is_array( $block_gap ) ) { - $block_gap = array( - 'top' => $block_gap, - 'left' => $block_gap - ); - } - - $directions = array( - 'top' => 'row', - 'left' => 'column' - ); - - $declarations = array_map( - function( string $gap, $key ) use ( $directions ) : string { - - if ( 'var:preset|spacing|' === substr( $gap, 0, 19 ) ) { - $slug = str_replace( '|', '-', substr( $gap, 19 ) ); - $value = "var(--wp--preset--spacing--{$slug})"; - } else { - $value = $gap; - } - - return "{$directions[$key]}-gap:{$value}"; - }, - $block_gap, - array_keys( $block_gap ) - ); - - return implode( ';', $declarations ); - } - } From 1530916c72ef8b9913304d654d425890bba07a5c Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 2 Aug 2023 15:33:29 -0400 Subject: [PATCH 027/123] move gap to block save func, add text alignment --- blocks/coauthors/build/block.json | 3 + blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- .../coauthors/class-cap-block-coauthors.php | 72 +------------------ blocks/coauthors/src/block.json | 3 + blocks/coauthors/src/edit.js | 22 +++++- blocks/coauthors/src/save.js | 32 +++++---- 7 files changed, 50 insertions(+), 86 deletions(-) diff --git a/blocks/coauthors/build/block.json b/blocks/coauthors/build/block.json index 461da882..0a804cb4 100644 --- a/blocks/coauthors/build/block.json +++ b/blocks/coauthors/build/block.json @@ -61,6 +61,9 @@ "suffix": { "type": "string", "default": "" + }, + "textAlign": { + "type": "string" } }, "usesContext": [ diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index df302f72..8cfd9d10 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2513e86d26fbc6c4ed0e'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '4a91361a581126f8f49b'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index 49e71616..de5cd845 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,f=(0,o.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,o.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),h=(0,o.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),v=n(779),d=n.n(v);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:r?"none":void 0};return(0,o.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function g(){return(0,o.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var E=JSON.parse('{"u2":"cap/coauthors"}');(0,r.registerBlockType)(E.u2,{edit:function(e){var t,n;let{attributes:r,setAttributes:i,clientId:p,context:v,isSelected:m}=e;const{separator:E,lastSeparator:b,layout:y,prefix:C,suffix:D}=r,{postId:k}=v,[_,F]=(0,o.useState)([{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[S,O]=(0,o.useState)(),B=(0,s.useDispatch)("core/notices");function A(e){"AbortError"!==e.name&&B.createErrorNotice(e.message,{isDismissible:!0})}(0,o.useEffect)((()=>{if(!k)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${k}/`,signal:e.signal}).then(F).catch(A),()=>{e.abort()}}),[k]);const P=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...y,...e}})},N=[{icon:f,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===y.type},{icon:h,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===y.type}];return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(a.BlockControls,null,(0,o.createElement)(l.ToolbarGroup,{controls:N})),(0,o.createElement)("div",(0,a.useBlockProps)({className:d()([`is-layout-cap-${y.type}`]),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==r||null===(t=r.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),_&&"inline"===y.type&&(m||C)&&(0,o.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:C,onChange:e=>i({prefix:e}),tagName:"span"}),_&&_.map((e=>{var t;const n=e.id===(S||(null===(t=_[0])||void 0===t?void 0:t.id));return(0,o.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,o.createElement)(g,null):null,(0,o.createElement)(w,{blocks:P,blockContextId:e.id,setActiveBlockContextId:O,isHidden:n}))})).reduce(((e,t,n,r)=>(0,o.createElement)(o.Fragment,null,e,"inline"===y.type&&(0,o.createElement)("span",{className:"wp-block-cap-coauthor__separator"},b&&n===r.length-1?`${b}`:`${E}`),t))),_&&"inline"===y.type&&(m||D)&&(0,o.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:D,onChange:e=>i({suffix:e}),tagName:"span"})),(0,o.createElement)(a.InspectorControls,null,"inline"===y.type&&(0,o.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,o.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:b||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(){return(0,o.createElement)(a.InnerBlocks.Content,null)}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(o in i)r.o(i,o)&&(r.m[o]=i[o]);if(c)var u=c(r)}for(t&&t(n);s{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:f,isSelected:m}=e;const{prefix:y,separator:b,lastSeparator:E,suffix:C,layout:D,textAlign:k}=o,{postId:_}=f,[F,S]=(0,r.useState)([{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[B,O]=(0,r.useState)(),A=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&A.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!_)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${_}/`,signal:e.signal}).then(S).catch(P),()=>{e.abort()}}),[_]);const N=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...D,...e}})},I=[{icon:h,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===D.type},{icon:v,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===D.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:I}),(0,r.createElement)(a.AlignmentControl,{value:k,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:d()({[`is-layout-cap-${D.type}`]:D.type,[`has-text-align-${k}`]:k}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),F&&"inline"===D.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),F&&F.map((e=>{var t;const n=e.id===(B||(null===(t=F[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(g,{blocks:N,blockContextId:e.id,setActiveBlockContextId:O,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===D.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},E&&n===o.length-1?`${E}`:`${b}`),t))),F&&"inline"===D.type&&(m||C)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:C,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===D.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:b||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:E||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=d()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s "is-layout-cap-{$attributes['layout']['type']}", - 'style' => $style - ) - ) - )( $inner_content ); + return current( $block->parsed_block['innerContent'] ) . implode( $blocks_with_separators ) . end ($block->parsed_block['innerContent'] ); } /** @@ -305,56 +286,9 @@ private static function get_block_as_template( WP_Block $block ) : array { return array_merge( $block->parsed_block, array( - 'blockName' => 'core/null' + 'innerContent' => array_slice( $block->parsed_block['innerContent'], 1, -1 ), + 'blockName' => 'core/null' ) ); } - - /** - * Get Gap CSS Value - * - * @param array $gaps - * @return string - */ - public static function get_gap_css_value( array $gaps ) : string { - return $gaps['row'] === $gaps['column'] ? $gaps['row'] : "{$gaps['row']} {$gaps['column']}"; - } - - /** - * Get Normalize Gap Value - * - * @param string|array $gap - * @return array - */ - public static function get_normalized_gap_value( string|array $gap ) : array { - if ( is_array( $gap ) ) { - $gap = array_merge( - array( - 'top' => '0', - 'left' => '0' - ), - $gap - ); - } - return array( - 'row' => self::get_preset_css_value( is_string( $gap ) ? $gap : $gap['top'] ), - 'column' => self::get_preset_css_value( is_string( $gap ) ? $gap : $gap['left'] ), - ); - } - - /** - * Get Preset CSS Value - * - * @param string $value - * @return string - */ - public static function get_preset_css_value( string $value ) : string { - if ( 'var:' !== substr( $value, 0, 4 ) ) { - return $value; - } - return sprintf( - 'var(--wp--%s)', - str_replace( '|', '--', substr( $value, 4 ) ) - ); - } } diff --git a/blocks/coauthors/src/block.json b/blocks/coauthors/src/block.json index f5db2dc8..709a5e42 100644 --- a/blocks/coauthors/src/block.json +++ b/blocks/coauthors/src/block.json @@ -59,6 +59,9 @@ "suffix": { "type": "string", "default": "" + }, + "textAlign": { + "type": "string" } }, "usesContext": [ "postId" ], diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js index fbdeb567..92af08aa 100644 --- a/blocks/coauthors/src/edit.js +++ b/blocks/coauthors/src/edit.js @@ -12,7 +12,8 @@ import { store as blockEditorStore, InspectorControls, RichText, - __experimentalGetGapCSSValue + __experimentalGetGapCSSValue, + AlignmentControl } from '@wordpress/block-editor'; import { TextControl, ToolbarGroup, PanelBody } from '@wordpress/components'; import apiFetch from '@wordpress/api-fetch'; @@ -51,7 +52,7 @@ const ALLOWED_FORMATS = [ */ export default function Edit( { attributes, setAttributes, clientId, context, isSelected } ) { - const { separator, lastSeparator, layout, prefix, suffix } = attributes; + const { prefix, separator, lastSeparator, suffix, layout, textAlign } = attributes; const { postId } = context; /* Default state for full site editing */ @@ -131,8 +132,23 @@ export default function Edit( { attributes, setAttributes, clientId, context, is <> + { + setAttributes( { textAlign: nextAlign } ); + } } + /> -
+
{ coAuthors && 'inline' === layout.type && diff --git a/blocks/coauthors/src/save.js b/blocks/coauthors/src/save.js index 6745b81e..0461c4c9 100644 --- a/blocks/coauthors/src/save.js +++ b/blocks/coauthors/src/save.js @@ -1,22 +1,30 @@ /** - * React hook that is used to mark the block wrapper element. - * It provides all the necessary props like the class name. - * - * @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps + * Save */ -import { InnerBlocks } from '@wordpress/block-editor'; +import { useBlockProps, InnerBlocks, __experimentalGetGapCSSValue } from '@wordpress/block-editor'; +import classnames from 'classnames'; /** - * The save function defines the way in which the different attributes should - * be combined into the final markup, which is then serialized by the block - * editor into `post_content`. - * - * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save + * Save * * @return {WPElement} Element to render. */ -export default function save() { +export default function save( { attributes } ) { + + const { layout, textAlign } = attributes; + + const style = { + gap: 'block' === layout.type ? __experimentalGetGapCSSValue( attributes.style?.spacing?.blockGap ) : null + }; + + const className = classnames({ + [`is-layout-cap-${layout.type}`]: layout.type, + [`has-text-align-${ textAlign }`]: textAlign + }); + return ( - +
+ +
); } From 820cf89bce8f1c718b548ade4ec33c8bbe7c58d7 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 3 Aug 2023 10:49:29 -0400 Subject: [PATCH 028/123] default avatars to display block --- blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- blocks/coauthor-avatar/build/style-index.css | 2 +- blocks/coauthor-avatar/src/style.css | 6 +++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index 934e890a..6811c576 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a5214c7c6f74fdbb694f'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'c81272de10aa20374275'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index 93151d48..51a9059c 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={631:function(){var e=window.wp.blocks,t=window.wp.element,n=window.wp.i18n,r=window.wp.blockEditor,i=window.wp.components;window.wp.data;var a=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(a.u2,{edit:function(e){let{context:a,attributes:l,setAttributes:o}=e;const s=a["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},{isLink:c,size:h}=l,[u,f]=(0,t.useState)(s),{avatar_urls:v,link:w,display_name:D}=u;if(!v||0===v.length)return null;const g=Object.keys(v).map((e=>({value:e,label:`${e} x ${e}`}))),d=(0,t.createElement)("img",{width:h,height:h,src:`${v[h]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,r.useBlockProps)(),c?(0,t.createElement)("a",{href:w,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,n.__)("Avatar Settings")},(0,t.createElement)(i.ToggleControl,{label:(0,n.__)("Make avatar a link to author archive."),onChange:()=>o({isLink:!c}),checked:c}),(0,t.createElement)(i.SelectControl,{label:(0,n.__)("Avatar size"),value:h,options:g,onChange:e=>{o({size:Number(e)})}}))))}})}},n={};function r(e){var i=n[e];if(void 0!==i)return i.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=function(t,n,i,a){if(!n){var l=1/0;for(h=0;h=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(o=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[n,i,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var i,a,l=n[0],o=n[1],s=n[2],c=0;if(l.some((function(t){return 0!==e[t]}))){for(i in o)r.o(o,i)&&(r.m[i]=o[i]);if(s)var h=s(r)}for(t&&t(n);c({value:e,label:`${e} x ${e}`}))),w=(0,t.createElement)("img",{width:c,height:c,src:`${u[c]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,r.useBlockProps)(),s?(0,t.createElement)("a",{href:f,onClick:e=>e.preventDefault()},w):w),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,n.__)("Avatar Settings")},(0,t.createElement)(i.ToggleControl,{label:(0,n.__)("Make avatar a link to author archive."),onChange:()=>l({isLink:!s}),checked:s}),(0,t.createElement)(i.SelectControl,{label:(0,n.__)("Avatar size"),value:c,options:v,onChange:e=>{l({size:Number(e)})}}))))}})}},n={};function r(e){var i=n[e];if(void 0!==i)return i.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=function(t,n,i,a){if(!n){var o=1/0;for(h=0;h=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(l=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[n,i,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var i,a,o=n[0],l=n[1],s=n[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(i in l)r.o(l,i)&&(r.m[i]=l[i]);if(s)var h=s(r)}for(t&&t(n);c Date: Thu, 3 Aug 2023 12:14:02 -0400 Subject: [PATCH 029/123] add coauthor description block --- blocks/blocks.php | 2 + blocks/coauthor-description/build/block.json | 44 +++++++++ .../build/index.asset.php | 1 + blocks/coauthor-description/build/index.js | 1 + .../class-cap-block-coauthor-description.php | 97 +++++++++++++++++++ blocks/coauthor-description/package.json | 5 + blocks/coauthor-description/src/block.json | 44 +++++++++ blocks/coauthor-description/src/edit.js | 35 +++++++ blocks/coauthor-description/src/index.js | 24 +++++ blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- blocks/coauthors/src/edit.js | 1 + .../class-coauthor-blocks-controller.php | 6 ++ 13 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 blocks/coauthor-description/build/block.json create mode 100644 blocks/coauthor-description/build/index.asset.php create mode 100644 blocks/coauthor-description/build/index.js create mode 100644 blocks/coauthor-description/class-cap-block-coauthor-description.php create mode 100644 blocks/coauthor-description/package.json create mode 100644 blocks/coauthor-description/src/block.json create mode 100644 blocks/coauthor-description/src/edit.js create mode 100644 blocks/coauthor-description/src/index.js diff --git a/blocks/blocks.php b/blocks/blocks.php index fb9797f2..05857c30 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -1,8 +1,10 @@ array('wp-block-editor', 'wp-blocks', 'wp-element'), 'version' => '1579e243f73c6dc32c2c'); diff --git a/blocks/coauthor-description/build/index.js b/blocks/coauthor-description/build/index.js new file mode 100644 index 00000000..61bd4154 --- /dev/null +++ b/blocks/coauthor-description/build/index.js @@ -0,0 +1 @@ +!function(){"use strict";var t=window.wp.blocks;function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;ePost hoc impie perpetratum quod in aliis quoque iam timebatur, tamquam licentia crudelitati indulta per suspicionum nebulas aestimati quidam.

",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},{description:n}=r;return(0,i.createElement)("div",e({},(0,a.useBlockProps)({className:["is-layout-flow"]}),{dangerouslySetInnerHTML:{__html:n}}))}})}(); \ No newline at end of file diff --git a/blocks/coauthor-description/class-cap-block-coauthor-description.php b/blocks/coauthor-description/class-cap-block-coauthor-description.php new file mode 100644 index 00000000..b6a8cc31 --- /dev/null +++ b/blocks/coauthor-description/class-cap-block-coauthor-description.php @@ -0,0 +1,97 @@ + array( __CLASS__, 'render_block' ), + ) + ); + } + /** + * Render Block + * + * @param array $attributes + * @param string $content + * @param WP_Block $block + * @return string + */ + public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + + $author = $block->context['cap/author'] ?? array(); + + if ( empty( $author ) ) { + return ''; + } + + $description = $author['description'] ?? ''; + + if ( '' === $description ) { + return ''; + } + + return sprintf( + '
%s
', + get_block_wrapper_attributes( + array( + 'class' => 'is-layout-flow' + ) + ), + wp_kses_post( wpautop( wptexturize( $description ) ) ) + ); + } + /** + * Provide Author Archive Context + * + * @param array $context, + * @param array $parsed_block + * @param null|WP_Block $parent_block + * @return array + */ + public static function provide_author_archive_context( array $context, array $parsed_block, ?WP_Block $parent_block ) : array { + if ( ! is_author() ) { + return $context; + } + + if ( null === $parsed_block['blockName'] ) { + return $context; + } + + // author if you do an individual piece of a coauthor outside of a coauthor template. + if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( ! array_key_exists( 'cap/author', $context ) || empty( $context['cap/author'] ) ) ) { + return array( + 'cap/author' => rest_get_server()->dispatch( + WP_REST_Request::from_url( + home_url( + sprintf( + '/wp-json/coauthor-blocks/v1/coauthor/%s', + get_query_var( 'author_name' ) + ) + ) + ) + )->get_data() + ); + } + + return $context; + } +} diff --git a/blocks/coauthor-description/package.json b/blocks/coauthor-description/package.json new file mode 100644 index 00000000..b6abf47a --- /dev/null +++ b/blocks/coauthor-description/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "build": "../../node_modules/.bin/wp-scripts build" + } +} diff --git a/blocks/coauthor-description/src/block.json b/blocks/coauthor-description/src/block.json new file mode 100644 index 00000000..51cab162 --- /dev/null +++ b/blocks/coauthor-description/src/block.json @@ -0,0 +1,44 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "cap/coauthor-description", + "version": "0.1.0", + "title": "Co-Author Description", + "category": "widgets", + "icon": "smiley", + "description": "Display a co-author's description.", + "supports": { + "html": false, + "color": { + "link": true, + "text": true, + "background": true, + "__experimentalDefaultControls": {} + }, + "typography": { + "fontSize": true, + "lineHeight": true, + "__experimentalFontFamily": true, + "__experimentalTextDecoration": true, + "__experimentalFontStyle": true, + "__experimentalFontWeight": true, + "__experimentalLetterSpacing": true, + "__experimentalTextTransform": true, + "__experimentalDefaultControls": {} + }, + "spacing": { + "margin": true, + "padding": true, + "__experimentalDefaultControls": { + "margin": false, + "padding": false + } + } + }, + "usesContext": [ + "cap/author" + ], + "attributes": {}, + "textdomain": "co-authors-plus", + "editorScript": "file:./index.js" +} \ No newline at end of file diff --git a/blocks/coauthor-description/src/edit.js b/blocks/coauthor-description/src/edit.js new file mode 100644 index 00000000..8a331484 --- /dev/null +++ b/blocks/coauthor-description/src/edit.js @@ -0,0 +1,35 @@ +/** + * React hook that is used to mark the block wrapper element. + * It provides all the necessary props like the class name. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops + */ +import { useBlockProps } from '@wordpress/block-editor'; + +/** + * The edit function describes the structure of your block in the context of the + * editor. This represents what the editor will render when the block is used. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit + * + * @return {WPElement} Element to render. + */ +export default function Edit( { context } ) { + const author = context['cap/author'] || { + id: 0, + display_name: 'FirstName LastName', + description: '

Post hoc impie perpetratum quod in aliis quoque iam timebatur, tamquam licentia crudelitati indulta per suspicionum nebulas aestimati quidam.

', + link: '#', + avatar_urls: { + 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', + 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', + 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' + } + }; + + const { description } = author; + + return ( +
+ ); +} diff --git a/blocks/coauthor-description/src/index.js b/blocks/coauthor-description/src/index.js new file mode 100644 index 00000000..252c391e --- /dev/null +++ b/blocks/coauthor-description/src/index.js @@ -0,0 +1,24 @@ +/** + * Registers a new block provided a unique name and an object defining its behavior. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +import { registerBlockType } from '@wordpress/blocks'; + +/** + * Internal dependencies + */ +import Edit from './edit'; +import metadata from './block.json'; + +/** + * Every block starts by registering a new block type definition. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +registerBlockType( metadata.name, { + /** + * @see ./edit.js + */ + edit: Edit +} ); diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 8cfd9d10..7014fcd1 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '4a91361a581126f8f49b'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'f93e8f19cdc1455a5c38'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index de5cd845..bf706bae 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,h=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),v=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),f=n(779),d=n.n(f);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:f,isSelected:m}=e;const{prefix:y,separator:b,lastSeparator:E,suffix:C,layout:D,textAlign:k}=o,{postId:_}=f,[F,S]=(0,r.useState)([{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[B,O]=(0,r.useState)(),A=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&A.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!_)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${_}/`,signal:e.signal}).then(S).catch(P),()=>{e.abort()}}),[_]);const N=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...D,...e}})},I=[{icon:h,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===D.type},{icon:v,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===D.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:I}),(0,r.createElement)(a.AlignmentControl,{value:k,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:d()({[`is-layout-cap-${D.type}`]:D.type,[`has-text-align-${k}`]:k}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),F&&"inline"===D.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),F&&F.map((e=>{var t;const n=e.id===(B||(null===(t=F[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(g,{blocks:N,blockContextId:e.id,setActiveBlockContextId:O,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===D.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},E&&n===o.length-1?`${E}`:`${b}`),t))),F&&"inline"===D.type&&(m||C)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:C,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===D.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:b||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:E||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=d()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:v,isSelected:m}=e;const{prefix:y,separator:b,lastSeparator:E,suffix:C,layout:k,textAlign:D}=o,{postId:_}=v,[F,S]=(0,r.useState)([{id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[A,B]=(0,r.useState)(),O=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&O.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!_)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${_}/`,signal:e.signal}).then(S).catch(P),()=>{e.abort()}}),[_]);const N=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...k,...e}})},I=[{icon:h,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===k.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===k.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:I}),(0,r.createElement)(a.AlignmentControl,{value:D,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:d()({[`is-layout-cap-${k.type}`]:k.type,[`has-text-align-${D}`]:D}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),F&&"inline"===k.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),F&&F.map((e=>{var t;const n=e.id===(A||(null===(t=F[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(g,{blocks:N,blockContextId:e.id,setActiveBlockContextId:B,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===k.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},E&&n===o.length-1?`${E}`:`${b}`),t))),F&&"inline"===k.type&&(m||C)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:C,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===k.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:b||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:E||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=d()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);sPlaceholder description from Co-Authors block.

', link: '#', avatar_urls: { 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index ec6913ae..e74389ff 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -232,6 +232,12 @@ public function prepare_item_for_response( $author, $request ) : WP_REST_Respons $data['link'] = get_author_posts_url( $author->ID, $author->user_nicename ); $data['avatar_urls'] = rest_get_avatar_urls( $author->ID ); + if ( 'wpuser' === $author->type ) { + if ( ! array_key_exists( 'description', $data ) ) { + $data['description'] = wp_kses_post( wpautop( wptexturize( get_user_meta( $author->ID, 'description', true ) ) ) ); + } + } + $response = rest_ensure_response( $data ); /** From 9fd178d4336668341cc22546fa659bba161990b4 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 3 Aug 2023 12:36:41 -0400 Subject: [PATCH 030/123] dont click links in the editor if desc has html --- blocks/coauthor-avatar/src/block.json | 1 - blocks/coauthor-avatar/src/edit.js | 2 -- blocks/coauthor-description/build/block.json | 3 ++- blocks/coauthor-description/build/index.asset.php | 2 +- blocks/coauthor-description/build/index.css | 1 + blocks/coauthor-description/src/block.json | 3 ++- blocks/coauthor-description/src/edit.js | 2 ++ blocks/coauthor-description/src/editor.css | 3 +++ 8 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 blocks/coauthor-description/build/index.css create mode 100644 blocks/coauthor-description/src/editor.css diff --git a/blocks/coauthor-avatar/src/block.json b/blocks/coauthor-avatar/src/block.json index 8d692513..f5010b67 100644 --- a/blocks/coauthor-avatar/src/block.json +++ b/blocks/coauthor-avatar/src/block.json @@ -25,7 +25,6 @@ }, "textdomain": "coauthor-avatar", "editorScript": "file:./index.js", - "editorStyle": "file:./index.css", "style": "file:./style-index.css" } \ No newline at end of file diff --git a/blocks/coauthor-avatar/src/edit.js b/blocks/coauthor-avatar/src/edit.js index 7f540ee0..a3a51459 100644 --- a/blocks/coauthor-avatar/src/edit.js +++ b/blocks/coauthor-avatar/src/edit.js @@ -1,8 +1,6 @@ import { __ } from '@wordpress/i18n'; import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; import { SelectControl, PanelBody, ToggleControl } from '@wordpress/components'; -import { useEffect, useState } from '@wordpress/element'; -import { useDispatch } from '@wordpress/data'; /** * The edit function describes the structure of your block in the context of the diff --git a/blocks/coauthor-description/build/block.json b/blocks/coauthor-description/build/block.json index ffd3589e..6711732a 100644 --- a/blocks/coauthor-description/build/block.json +++ b/blocks/coauthor-description/build/block.json @@ -40,5 +40,6 @@ ], "attributes": {}, "textdomain": "co-authors-plus", - "editorScript": "file:./index.js" + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css" } \ No newline at end of file diff --git a/blocks/coauthor-description/build/index.asset.php b/blocks/coauthor-description/build/index.asset.php index 1d46ca55..e95faf60 100644 --- a/blocks/coauthor-description/build/index.asset.php +++ b/blocks/coauthor-description/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-element'), 'version' => '1579e243f73c6dc32c2c'); + array('wp-block-editor', 'wp-blocks', 'wp-element'), 'version' => '3cb0fbd02f3348cbae82'); diff --git a/blocks/coauthor-description/build/index.css b/blocks/coauthor-description/build/index.css new file mode 100644 index 00000000..4bcbaa2b --- /dev/null +++ b/blocks/coauthor-description/build/index.css @@ -0,0 +1 @@ +.wp-block-cap-coauthor-description a{pointer-events:none} diff --git a/blocks/coauthor-description/src/block.json b/blocks/coauthor-description/src/block.json index 51cab162..d387ecbb 100644 --- a/blocks/coauthor-description/src/block.json +++ b/blocks/coauthor-description/src/block.json @@ -40,5 +40,6 @@ ], "attributes": {}, "textdomain": "co-authors-plus", - "editorScript": "file:./index.js" + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css" } \ No newline at end of file diff --git a/blocks/coauthor-description/src/edit.js b/blocks/coauthor-description/src/edit.js index 8a331484..36131b3f 100644 --- a/blocks/coauthor-description/src/edit.js +++ b/blocks/coauthor-description/src/edit.js @@ -6,6 +6,8 @@ */ import { useBlockProps } from '@wordpress/block-editor'; +import './editor.css'; + /** * The edit function describes the structure of your block in the context of the * editor. This represents what the editor will render when the block is used. diff --git a/blocks/coauthor-description/src/editor.css b/blocks/coauthor-description/src/editor.css new file mode 100644 index 00000000..a984e75e --- /dev/null +++ b/blocks/coauthor-description/src/editor.css @@ -0,0 +1,3 @@ +.wp-block-cap-coauthor-description a { + pointer-events: none; +} From 92fc4b2e87d0caf47a1fb4ae4ef1052b07893d64 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 3 Aug 2023 13:33:31 -0400 Subject: [PATCH 031/123] add text align to display name and description --- blocks/coauthor-description/build/block.json | 6 +++- .../build/index.asset.php | 2 +- blocks/coauthor-description/build/index.js | 2 +- .../class-cap-block-coauthor-description.php | 27 ++++++++++++++-- blocks/coauthor-description/src/block.json | 6 +++- blocks/coauthor-description/src/edit.js | 31 +++++++++++++++++-- blocks/coauthor-display-name/build/block.json | 3 ++ .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- .../class-cap-block-coauthor-display-name.php | 26 +++++++++++++++- blocks/coauthor-display-name/src/block.json | 3 ++ blocks/coauthor-display-name/src/edit.js | 17 +++++++--- 12 files changed, 109 insertions(+), 18 deletions(-) diff --git a/blocks/coauthor-description/build/block.json b/blocks/coauthor-description/build/block.json index 6711732a..aab8a9a5 100644 --- a/blocks/coauthor-description/build/block.json +++ b/blocks/coauthor-description/build/block.json @@ -38,7 +38,11 @@ "usesContext": [ "cap/author" ], - "attributes": {}, + "attributes": { + "textAlign": { + "type": "string" + } + }, "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "editorStyle": "file:./index.css" diff --git a/blocks/coauthor-description/build/index.asset.php b/blocks/coauthor-description/build/index.asset.php index e95faf60..828e1748 100644 --- a/blocks/coauthor-description/build/index.asset.php +++ b/blocks/coauthor-description/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-element'), 'version' => '3cb0fbd02f3348cbae82'); + array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n'), 'version' => 'f43801ee6c0cc938b461'); diff --git a/blocks/coauthor-description/build/index.js b/blocks/coauthor-description/build/index.js index 61bd4154..6f7c69b1 100644 --- a/blocks/coauthor-description/build/index.js +++ b/blocks/coauthor-description/build/index.js @@ -1 +1 @@ -!function(){"use strict";var t=window.wp.blocks;function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;ePost hoc impie perpetratum quod in aliis quoque iam timebatur, tamquam licentia crudelitati indulta per suspicionum nebulas aestimati quidam.

",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},{description:n}=r;return(0,i.createElement)("div",e({},(0,a.useBlockProps)({className:["is-layout-flow"]}),{dangerouslySetInnerHTML:{__html:n}}))}})}(); \ No newline at end of file +!function(){var t={779:function(t,e){var i;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var t=[],e=0;ePost hoc impie perpetratum quod in aliis quoque iam timebatur, tamquam licentia crudelitati indulta per suspicionum nebulas aestimati quidam.

",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},{description:c}=u;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(n.BlockControls,null,(0,r.createElement)(n.AlignmentControl,{value:l,onChange:t=>{s({textAlign:t})}})),(0,r.createElement)("div",e({},(0,n.useBlockProps)({className:a()({[`has-text-align-${l}`]:l,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:c}})))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-description/class-cap-block-coauthor-description.php b/blocks/coauthor-description/class-cap-block-coauthor-description.php index b6a8cc31..3071eadf 100644 --- a/blocks/coauthor-description/class-cap-block-coauthor-description.php +++ b/blocks/coauthor-description/class-cap-block-coauthor-description.php @@ -52,9 +52,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc return sprintf( '
%s
', get_block_wrapper_attributes( - array( - 'class' => 'is-layout-flow' - ) + self::get_custom_block_wrapper_attributes( $attributes ) ), wp_kses_post( wpautop( wptexturize( $description ) ) ) ); @@ -94,4 +92,27 @@ public static function provide_author_archive_context( array $context, array $pa return $context; } + + /** + * Get Custom Block Wrapper Attributes + * + * @param array $attributes + * @return array + */ + public static function get_custom_block_wrapper_attributes( array $attributes ) : array { + + $default = array( + 'class' => 'is-layout-flow', + ); + + $text_align = $attributes['textAlign'] ?? ''; + + if ( empty( $text_align ) ) { + return $default; + } + + return array( + 'class' => $default['class'] . ' ' . esc_attr( "has-text-align-{$text_align}" ) + ); + } } diff --git a/blocks/coauthor-description/src/block.json b/blocks/coauthor-description/src/block.json index d387ecbb..29f38887 100644 --- a/blocks/coauthor-description/src/block.json +++ b/blocks/coauthor-description/src/block.json @@ -38,7 +38,11 @@ "usesContext": [ "cap/author" ], - "attributes": {}, + "attributes": { + "textAlign": { + "type": "string" + } + }, "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "editorStyle": "file:./index.css" diff --git a/blocks/coauthor-description/src/edit.js b/blocks/coauthor-description/src/edit.js index 36131b3f..f0e0b2f7 100644 --- a/blocks/coauthor-description/src/edit.js +++ b/blocks/coauthor-description/src/edit.js @@ -4,7 +4,9 @@ * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ -import { useBlockProps } from '@wordpress/block-editor'; +import { useBlockProps, AlignmentControl, BlockControls } from '@wordpress/block-editor'; +import { __ } from '@wordpress/i18n'; +import classnames from 'classnames'; import './editor.css'; @@ -16,7 +18,10 @@ import './editor.css'; * * @return {WPElement} Element to render. */ -export default function Edit( { context } ) { +export default function Edit( { context, attributes, setAttributes } ) { + + const { textAlign } = attributes; + const author = context['cap/author'] || { id: 0, display_name: 'FirstName LastName', @@ -32,6 +37,26 @@ export default function Edit( { context } ) { const { description } = author; return ( -
+ <> + + { + setAttributes( { textAlign: nextAlign } ); + } } + /> + +
+ ); } diff --git a/blocks/coauthor-display-name/build/block.json b/blocks/coauthor-display-name/build/block.json index fc95a073..bce3ee2d 100644 --- a/blocks/coauthor-display-name/build/block.json +++ b/blocks/coauthor-display-name/build/block.json @@ -47,6 +47,9 @@ "type": "string", "attribute": "rel", "default": "author" + }, + "textAlign": { + "type": "string" } }, "textdomain": "co-authors-plus", diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index 0da4c1f9..51fd181c 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a2460e19116ea13eed8a'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a3fc7095e6db95805807'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index 5b60ce82..501ccc1a 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e=window.wp.blocks,t=window.wp.element,n=window.wp.blockEditor,a=window.wp.components,i=(window.wp.data,window.wp.i18n),l=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(l.u2,{edit:function(e){let{context:l,attributes:r,setAttributes:o}=e;const s=l["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},{isLink:D,rel:w}=r,[c,m]=(0,t.useState)(s),{link:g,display_name:h}=c;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("p",(0,n.useBlockProps)(),D?(0,t.createElement)("a",{href:g,rel:w,onClick:e=>e.preventDefault()},h):h),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,i.__)("Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Make coauthor name a link"),onChange:()=>o({isLink:!D}),checked:D}),D&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Link rel"),value:w,onChange:e=>o({rel:e})})))))}})}(); \ No newline at end of file +!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function i(){for(var e=[],t=0;t{s({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:l()({[`has-text-align-${g}`]:g})}),c?(0,t.createElement)("a",{href:h,rel:u,onClick:e=>e.preventDefault()},p):p),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(i.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>s({isLink:!c}),checked:c}),c&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:u,onChange:e=>s({rel:e})})))))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index ccc7c8b4..1f4bcf79 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -65,7 +65,13 @@ public static function render_block( array $attributes, string $content, WP_Bloc $inner_content = $display_name; } - return sprintf( '

%s

', get_block_wrapper_attributes(), $inner_content ); + return sprintf( + '

%s

', + get_block_wrapper_attributes( + self::get_custom_block_wrapper_attributes( $attributes ) + ), + $inner_content + ); } /** * Provide Author Archive Context @@ -102,4 +108,22 @@ public static function provide_author_archive_context( array $context, array $pa return $context; } + + /** + * Get Custom Block Wrapper Attributes + * + * @param array $attributes + * @return array + */ + public static function get_custom_block_wrapper_attributes( array $attributes ) : array { + + $text_align = $attributes['textAlign'] ?? ''; + + if ( empty( $text_align ) ) { + return array(); + } + return array( + 'class' => esc_attr( "has-text-align-{$text_align}" ) + ); + } } diff --git a/blocks/coauthor-display-name/src/block.json b/blocks/coauthor-display-name/src/block.json index d159579c..1cff4932 100644 --- a/blocks/coauthor-display-name/src/block.json +++ b/blocks/coauthor-display-name/src/block.json @@ -47,6 +47,9 @@ "type": "string", "attribute": "rel", "default": "author" + }, + "textAlign": { + "type": "string" } }, "textdomain": "co-authors-plus", diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index fa35840c..5754004b 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -4,11 +4,10 @@ * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ -import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; +import { useBlockProps, InspectorControls, AlignmentControl, BlockControls } from '@wordpress/block-editor'; import { TextControl, PanelBody, ToggleControl } from '@wordpress/components'; -import { useEffect, useState } from '@wordpress/element'; -import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; +import classnames from 'classnames'; /** * The edit function describes the structure of your block in the context of the @@ -20,7 +19,7 @@ import { __ } from '@wordpress/i18n'; */ export default function Edit( { context, attributes, setAttributes } ) { - const { isLink, rel } = attributes; + const { isLink, rel, textAlign } = attributes; const author = context['cap/author'] || { id: 0, display_name: 'FirstName LastName', @@ -36,7 +35,15 @@ export default function Edit( { context, attributes, setAttributes } ) { return ( <> -

+ + { + setAttributes( { textAlign: nextAlign } ); + } } + /> + +

{ isLink ? ( Date: Thu, 3 Aug 2023 14:15:03 -0400 Subject: [PATCH 032/123] open up permissions for single coauthor --- php/api/endpoints/class-coauthor-blocks-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index e74389ff..badb4004 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -75,7 +75,7 @@ public function register_routes() : void { array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permission_check' ), + 'permission_callback' => '__return_true', ) ) ); From d248c189fe80e7fe52cfe55cf92e733bec49586e Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 3 Aug 2023 14:40:01 -0400 Subject: [PATCH 033/123] typo and whitespace --- blocks/coauthors/class-cap-block-coauthors.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blocks/coauthors/class-cap-block-coauthors.php b/blocks/coauthors/class-cap-block-coauthors.php index b52b5651..337221ca 100644 --- a/blocks/coauthors/class-cap-block-coauthors.php +++ b/blocks/coauthors/class-cap-block-coauthors.php @@ -90,7 +90,7 @@ function( stdClass|WP_User $author ) : array { ); } - return current( $block->parsed_block['innerContent'] ) . implode( $blocks_with_separators ) . end ($block->parsed_block['innerContent'] ); + return current( $block->parsed_block['innerContent'] ) . implode( $blocks_with_separators ) . end( $block->parsed_block['innerContent'] ); } /** @@ -153,9 +153,9 @@ public static function render_coauthor_blocks_with_template( array $template, ar return array_map( self::get_composed_map_function( self::get_template_render_function( $template ), - // To match JSX from edition, remove line-breaks between blocks. + // To match JSX from editor, remove line-breaks between blocks. fn( $content ) => str_replace("\n", '', $content ), - // To match JSX from edition, trim whitespace around blocks. + // To match JSX from editor, trim whitespace around blocks. 'trim', self::get_block_wrapper_function('div', 'class="wp-block-cap-coauthor"') ), From 01815d29434fabe492ca38edc4305ba7f53fcf76 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 9 Aug 2023 11:07:37 -0400 Subject: [PATCH 034/123] add featured media to api responses --- php/api/endpoints/class-coauthor-blocks-controller.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index badb4004..8a5aa541 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -238,6 +238,14 @@ public function prepare_item_for_response( $author, $request ) : WP_REST_Respons } } + if ( 'guest-author' === $author->type ) { + $data['featured_media'] = absint( + get_post_thumbnail_id( $author->ID ) + ); + } else { + $data['featured_media'] = 0; + } + $response = rest_ensure_response( $data ); /** From 3eeedb2810d7fe7a39219d1e24305cdeb4afc3ed Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 9 Aug 2023 11:07:56 -0400 Subject: [PATCH 035/123] add default featured_media --- blocks/coauthors/src/edit.js | 1 + 1 file changed, 1 insertion(+) diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js index b6c6dd58..537529c4 100644 --- a/blocks/coauthors/src/edit.js +++ b/blocks/coauthors/src/edit.js @@ -62,6 +62,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is display_name: 'FirstName LastName', description: '

Placeholder description from Co-Authors block.

', link: '#', + featured_media: 0, avatar_urls: { 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', From 9cf110ed20438d8446cc56c0bb9724292ac04f6d Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 9 Aug 2023 11:08:12 -0400 Subject: [PATCH 036/123] add default featured media --- blocks/coauthor-avatar/src/edit.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blocks/coauthor-avatar/src/edit.js b/blocks/coauthor-avatar/src/edit.js index a3a51459..d90655b5 100644 --- a/blocks/coauthor-avatar/src/edit.js +++ b/blocks/coauthor-avatar/src/edit.js @@ -21,7 +21,8 @@ export default function Edit( { context, attributes, setAttributes } ) { 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' - } + }, + featured_media: 0 }; const { avatar_urls, link } = author; From e85f1c561afa128820569b4e3b670e0769b4dedc Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 9 Aug 2023 11:08:24 -0400 Subject: [PATCH 037/123] build coauthors block --- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 7014fcd1..6bca0952 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'f93e8f19cdc1455a5c38'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2af020dad6fbebd679f5'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index bf706bae..10a583bd 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,h=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),f=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),v=n(779),d=n.n(v);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:v,isSelected:m}=e;const{prefix:y,separator:b,lastSeparator:E,suffix:C,layout:k,textAlign:D}=o,{postId:_}=v,[F,S]=(0,r.useState)([{id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[A,B]=(0,r.useState)(),O=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&O.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!_)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${_}/`,signal:e.signal}).then(S).catch(P),()=>{e.abort()}}),[_]);const N=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...k,...e}})},I=[{icon:h,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===k.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===k.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:I}),(0,r.createElement)(a.AlignmentControl,{value:D,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:d()({[`is-layout-cap-${k.type}`]:k.type,[`has-text-align-${D}`]:D}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),F&&"inline"===k.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),F&&F.map((e=>{var t;const n=e.id===(A||(null===(t=F[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(g,{blocks:N,blockContextId:e.id,setActiveBlockContextId:B,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===k.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},E&&n===o.length-1?`${E}`:`${b}`),t))),F&&"inline"===k.type&&(m||C)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:C,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===k.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:b||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:E||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=d()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:f,isSelected:m}=e;const{prefix:y,separator:b,lastSeparator:E,suffix:C,layout:k,textAlign:D}=o,{postId:_}=f,[F,S]=(0,r.useState)([{id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[A,B]=(0,r.useState)(),O=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&O.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!_)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${_}/`,signal:e.signal}).then(S).catch(P),()=>{e.abort()}}),[_]);const N=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...k,...e}})},I=[{icon:h,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===k.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===k.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:I}),(0,r.createElement)(a.AlignmentControl,{value:D,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:v()({[`is-layout-cap-${k.type}`]:k.type,[`has-text-align-${D}`]:D}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),F&&"inline"===k.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),F&&F.map((e=>{var t;const n=e.id===(A||(null===(t=F[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(g,{blocks:N,blockContextId:e.id,setActiveBlockContextId:B,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===k.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},E&&n===o.length-1?`${E}`:`${b}`),t))),F&&"inline"===k.type&&(m||C)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:C,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===k.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:b||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:E||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=v()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s Date: Wed, 9 Aug 2023 11:08:39 -0400 Subject: [PATCH 038/123] add featured image, sufficient to edit only --- blocks/blocks.php | 2 + .../coauthor-feature-image/build/block.json | 69 +++++ .../build/index.asset.php | 1 + blocks/coauthor-feature-image/build/index.css | 1 + blocks/coauthor-feature-image/build/index.js | 3 + .../build/style-index.css | 1 + .../build/view.asset.php | 1 + blocks/coauthor-feature-image/build/view.js | 1 + ...class-cap-block-coauthor-feature-image.php | 76 ++++++ .../coauthor-feature-image/package-lock.json | 6 + blocks/coauthor-feature-image/package.json | 5 + blocks/coauthor-feature-image/src/block.json | 63 +++++ .../src/dimension-controls.js | 237 ++++++++++++++++++ blocks/coauthor-feature-image/src/edit.js | 110 ++++++++ blocks/coauthor-feature-image/src/editor.scss | 14 ++ blocks/coauthor-feature-image/src/index.js | 39 +++ blocks/coauthor-feature-image/src/save.js | 24 ++ blocks/coauthor-feature-image/src/style.scss | 21 ++ blocks/coauthor-feature-image/src/view.js | 3 + 19 files changed, 677 insertions(+) create mode 100644 blocks/coauthor-feature-image/build/block.json create mode 100644 blocks/coauthor-feature-image/build/index.asset.php create mode 100644 blocks/coauthor-feature-image/build/index.css create mode 100644 blocks/coauthor-feature-image/build/index.js create mode 100644 blocks/coauthor-feature-image/build/style-index.css create mode 100644 blocks/coauthor-feature-image/build/view.asset.php create mode 100644 blocks/coauthor-feature-image/build/view.js create mode 100644 blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php create mode 100644 blocks/coauthor-feature-image/package-lock.json create mode 100644 blocks/coauthor-feature-image/package.json create mode 100644 blocks/coauthor-feature-image/src/block.json create mode 100644 blocks/coauthor-feature-image/src/dimension-controls.js create mode 100644 blocks/coauthor-feature-image/src/edit.js create mode 100644 blocks/coauthor-feature-image/src/editor.scss create mode 100644 blocks/coauthor-feature-image/src/index.js create mode 100644 blocks/coauthor-feature-image/src/save.js create mode 100644 blocks/coauthor-feature-image/src/style.scss create mode 100644 blocks/coauthor-feature-image/src/view.js diff --git a/blocks/blocks.php b/blocks/blocks.php index 05857c30..eb5ee55f 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -3,8 +3,10 @@ require_once dirname( __FILE__ ) . '/coauthor-avatar/class-cap-block-coauthor-avatar.php'; require_once dirname( __FILE__ ) . '/coauthor-description/class-cap-block-coauthor-description.php'; require_once dirname( __FILE__ ) . '/coauthor-display-name/class-cap-block-coauthor-display-name.php'; +require_once dirname( __FILE__ ) . '/coauthor-feature-image/class-cap-block-coauthor-feature-image.php'; new CAP_Block_CoAuthors(); new CAP_Block_CoAuthor_Avatar(); new CAP_Block_CoAuthor_Description(); new CAP_Block_CoAuthor_Display_Name(); +new CAP_Block_CoAuthor_Feature_Image(); diff --git a/blocks/coauthor-feature-image/build/block.json b/blocks/coauthor-feature-image/build/block.json new file mode 100644 index 00000000..863e1fbf --- /dev/null +++ b/blocks/coauthor-feature-image/build/block.json @@ -0,0 +1,69 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "cap/coauthor-feature-image", + "version": "0.1.0", + "title": "Coauthor Feature Image", + "category": "widgets", + "icon": "smiley", + "description": "Feature Image from a Guest Author profile.", + "supports": { + "align": [ + "left", + "right", + "center", + "wide", + "full" + ], + "__experimentalBorder": { + "color": true, + "radius": true, + "width": true, + "__experimentalSelector": "img, .block-editor-media-placeholder, .wp-block-post-featured-image__overlay", + "__experimentalSkipSerialization": true, + "__experimentalDefaultControls": { + "color": true, + "radius": true, + "width": true + } + }, + "spacing": { + "margin": true, + "padding": true + } + }, + "usesContext": [ + "cap/author" + ], + "attributes": { + "isLink": { + "type": "boolean", + "default": false + }, + "rel": { + "type": "string", + "attribute": "rel" + }, + "aspectRatio": { + "type": "string" + }, + "width": { + "type": "string" + }, + "height": { + "type": "string" + }, + "scale": { + "type": "string", + "default": "cover" + }, + "sizeSlug": { + "type": "string" + } + }, + "textdomain": "coauthor-feature-image", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css", + "viewScript": "file:./view.js" +} \ No newline at end of file diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php new file mode 100644 index 00000000..a1079401 --- /dev/null +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '26f13fe5d2cc650f54f6'); diff --git a/blocks/coauthor-feature-image/build/index.css b/blocks/coauthor-feature-image/build/index.css new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/blocks/coauthor-feature-image/build/index.css @@ -0,0 +1 @@ + diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js new file mode 100644 index 00000000..7b47fd2b --- /dev/null +++ b/blocks/coauthor-feature-image/build/index.js @@ -0,0 +1,3 @@ +!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=window.wp.i18n,i=window.wp.blockEditor,r=window.wp.components,s=window.wp.data,u=window.wp.coreData;const c=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.__experimentalToggleGroupControlOption,{value:"cover",label:(0,o._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(r.__experimentalToggleGroupControlOption,{value:"contain",label:(0,o._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(r.__experimentalToggleGroupControlOption,{value:"fill",label:(0,o._x)("Fill","Scale option for Image dimension control")})),p="cover",d={cover:(0,o.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,o.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,o.__)("Image will be stretched and distorted to completely fill the space.")};var m=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:s,scale:u,sizeSlug:m},setAttributes:_,imageSizeOptions:h=[]}=e;const g=(0,r.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||_({[e]:l<0?"0":t})},f=(0,o._x)("Scale","Image scaling options"),b=s||l&&"auto"!==l;return(0,a.createElement)(i.InspectorControls,{group:"dimensions"},(0,a.createElement)(r.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,o.__)("Aspect ratio"),onDeselect:()=>_({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Aspect ratio"),value:l,options:[{label:(0,o.__)("Original"),value:"auto"},{label:(0,o.__)("Square"),value:"1"},{label:(0,o.__)("16:9"),value:"16/9"},{label:(0,o.__)("4:3"),value:"4/3"},{label:(0,o.__)("3:2"),value:"3/2"},{label:(0,o.__)("9:16"),value:"9/16"},{label:(0,o.__)("3:4"),value:"3/4"},{label:(0,o.__)("2:3"),value:"2/3"}],onChange:e=>_({aspectRatio:e})})),(0,a.createElement)(r.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!s,label:(0,o.__)("Height"),onDeselect:()=>_({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(r.__experimentalUnitControl,{label:(0,o.__)("Height"),labelPosition:"top",value:s||"",min:0,onChange:e=>v("height",e),units:g})),(0,a.createElement)(r.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,o.__)("Width"),onDeselect:()=>_({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(r.__experimentalUnitControl,{label:(0,o.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:g})),b&&(0,a.createElement)(r.__experimentalToolsPanelItem,{hasValue:()=>!!u&&u!==p,label:f,onDeselect:()=>_({scale:p}),resetAllFilter:()=>({scale:p}),isShownByDefault:!0,panelId:t},(0,a.createElement)(r.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:u,help:d[u],onChange:e=>_({scale:e}),isBlock:!0},c)),!!h.length&&(0,a.createElement)(r.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,o.__)("Resolution"),onDeselect:()=>_({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Resolution"),value:m||"full",options:h,onChange:e=>_({sizeSlug:e}),help:(0,o.__)("Select the size of the source image.")})))},_=l(779),h=l.n(_),g=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(g.u2,{edit:function(e){let{attributes:t,setAttributes:l,context:n,clientId:c}=e;const{width:p,height:d,aspectRatio:_,sizeSlug:g,scale:v}=t,f=n["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:[],featured_media:0},b=(0,s.useSelect)((e=>{const{getMedia:t}=e(u.store);return 0!==f.featured_media&&t(f.featured_media,{context:"view"})}),[f.featured_media]),w=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(b,g),x=(0,s.useSelect)((e=>e(i.store).getSettings().imageSizes),[]).filter((e=>{var t,l,n;let{slug:a}=e;return null==b||null===(t=b.media_details)||void 0===t||null===(l=t.sizes)||void 0===l||null===(n=l[a])||void 0===n?void 0:n.source_url})).map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),S=(0,i.__experimentalUseBorderProps)(t),y={...S.style,height:_?"100%":d,width:!!_&&"100%",objectFit:!(!d&&!_)&&v};return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(m,{clientId:c,attributes:t,setAttributes:l,imageSizeOptions:x}),(0,a.createElement)("div",(0,i.useBlockProps)({style:{width:p,height:d,aspectRatio:_}}),b?(0,a.createElement)("img",{src:w,alt:b.alt_text?sprintf( +// translators: %s: The image's alt text. +(0,o.__)("Featured image: %s"),b.alt_text):(0,o.__)("Featured image"),style:y}):(0,a.createElement)(r.Placeholder,{className:h()("block-editor-media-placeholder",S.className),withIllustration:!0,style:{height:!!_&&"100%",width:!!_&&"100%",minWidth:"auto",minHeight:"auto",...S.style}})))},save:function(){return(0,a.createElement)("p",i.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[c-1][2]>o;c--)e[c]=e[c-1];e[c]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var c=s(n)}for(t&&t(l);u array(), 'version' => '07f6b9b394c20ddc8229'); diff --git a/blocks/coauthor-feature-image/build/view.js b/blocks/coauthor-feature-image/build/view.js new file mode 100644 index 00000000..ad6e2948 --- /dev/null +++ b/blocks/coauthor-feature-image/build/view.js @@ -0,0 +1 @@ +console.log("Hello World! (from cap-coauthor-feature-image block)"); \ No newline at end of file diff --git a/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php b/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php new file mode 100644 index 00000000..3a607f69 --- /dev/null +++ b/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php @@ -0,0 +1,76 @@ + array( __CLASS__, 'render_block' ), + ) + ); + } + /** + * Render Block + * + * @param array $attributes + * @param string $content + * @param WP_Block $block + * @return string + */ + public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + return $content; + } + /** + * Provide Author Archive Context + * + * @param array $context, + * @param array $parsed_block + * @param null|WP_Block $parent_block + * @return array + */ + public static function provide_author_archive_context( array $context, array $parsed_block, ?WP_Block $parent_block ) : array { + if ( ! is_author() ) { + return $context; + } + + if ( null === $parsed_block['blockName'] ) { + return $context; + } + + // author if you do an individual piece of a coauthor outside of a coauthor template. + if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( ! array_key_exists( 'cap/author', $context ) || empty( $context['cap/author'] ) ) ) { + return array( + 'cap/author' => rest_get_server()->dispatch( + WP_REST_Request::from_url( + home_url( + sprintf( + '/wp-json/coauthor-blocks/v1/coauthor/%s', + get_query_var( 'author_name' ) + ) + ) + ) + )->get_data() + ); + } + + return $context; + } +} diff --git a/blocks/coauthor-feature-image/package-lock.json b/blocks/coauthor-feature-image/package-lock.json new file mode 100644 index 00000000..dd50e04b --- /dev/null +++ b/blocks/coauthor-feature-image/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "coauthor-feature-image", + "lockfileVersion": 2, + "requires": true, + "packages": {} +} diff --git a/blocks/coauthor-feature-image/package.json b/blocks/coauthor-feature-image/package.json new file mode 100644 index 00000000..a0142be4 --- /dev/null +++ b/blocks/coauthor-feature-image/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "build": "../../node_modules/.bin/wp-scripts build" + } +} \ No newline at end of file diff --git a/blocks/coauthor-feature-image/src/block.json b/blocks/coauthor-feature-image/src/block.json new file mode 100644 index 00000000..4400835f --- /dev/null +++ b/blocks/coauthor-feature-image/src/block.json @@ -0,0 +1,63 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "cap/coauthor-feature-image", + "version": "0.1.0", + "title": "Coauthor Feature Image", + "category": "widgets", + "icon": "smiley", + "description": "Feature Image from a Guest Author profile.", + "supports": { + "align": [ "left", "right", "center", "wide", "full" ], + "__experimentalBorder": { + "color": true, + "radius": true, + "width": true, + "__experimentalSelector": "img, .block-editor-media-placeholder, .wp-block-post-featured-image__overlay", + "__experimentalSkipSerialization": true, + "__experimentalDefaultControls": { + "color": true, + "radius": true, + "width": true + } + }, + "spacing": { + "margin": true, + "padding": true + } + }, + "usesContext": [ + "cap/author" + ], + "attributes": { + "isLink": { + "type": "boolean", + "default": false + }, + "rel": { + "type": "string", + "attribute": "rel" + }, + "aspectRatio": { + "type": "string" + }, + "width": { + "type": "string" + }, + "height": { + "type": "string" + }, + "scale": { + "type": "string", + "default": "cover" + }, + "sizeSlug": { + "type": "string" + } + }, + "textdomain": "coauthor-feature-image", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css", + "viewScript": "file:./view.js" +} \ No newline at end of file diff --git a/blocks/coauthor-feature-image/src/dimension-controls.js b/blocks/coauthor-feature-image/src/dimension-controls.js new file mode 100644 index 00000000..5e120492 --- /dev/null +++ b/blocks/coauthor-feature-image/src/dimension-controls.js @@ -0,0 +1,237 @@ +/** + * WordPress dependencies + */ +import { __, _x } from '@wordpress/i18n'; +import { + SelectControl, + __experimentalUnitControl as UnitControl, + __experimentalToggleGroupControl as ToggleGroupControl, + __experimentalToggleGroupControlOption as ToggleGroupControlOption, + __experimentalUseCustomUnits as useCustomUnits, + __experimentalToolsPanelItem as ToolsPanelItem, +} from '@wordpress/components'; +import { InspectorControls, useSetting } from '@wordpress/block-editor'; + +const SCALE_OPTIONS = ( + <> + + + + +); + +const DEFAULT_SCALE = 'cover'; +const DEFAULT_SIZE = 'full'; + +const scaleHelp = { + cover: __( + 'Image is scaled and cropped to fill the entire space without being distorted.' + ), + contain: __( + 'Image is scaled to fill the space without clipping nor distorting.' + ), + fill: __( + 'Image will be stretched and distorted to completely fill the space.' + ), +}; + +const DimensionControls = ( { + clientId, + attributes: { aspectRatio, width, height, scale, sizeSlug }, + setAttributes, + imageSizeOptions = [], +} ) => { + const defaultUnits = [ 'px', '%', 'vw', 'em', 'rem' ]; + const units = useCustomUnits( { + availableUnits: useSetting( 'spacing.units' ) || defaultUnits, + } ); + const onDimensionChange = ( dimension, nextValue ) => { + const parsedValue = parseFloat( nextValue ); + /** + * If we have no value set and we change the unit, + * we don't want to set the attribute, as it would + * end up having the unit as value without any number. + */ + if ( isNaN( parsedValue ) && nextValue ) return; + setAttributes( { + [ dimension ]: parsedValue < 0 ? '0' : nextValue, + } ); + }; + const scaleLabel = _x( 'Scale', 'Image scaling options' ); + + const showScaleControl = + height || ( aspectRatio && aspectRatio !== 'auto' ); + + return ( + + !! aspectRatio } + label={ __( 'Aspect ratio' ) } + onDeselect={ () => setAttributes( { aspectRatio: undefined } ) } + resetAllFilter={ () => ( { + aspectRatio: undefined, + } ) } + isShownByDefault={ true } + panelId={ clientId } + > + + setAttributes( { aspectRatio: nextAspectRatio } ) + } + /> + + !! height } + label={ __( 'Height' ) } + onDeselect={ () => setAttributes( { height: undefined } ) } + resetAllFilter={ () => ( { + height: undefined, + } ) } + isShownByDefault={ true } + panelId={ clientId } + > + + onDimensionChange( 'height', nextHeight ) + } + units={ units } + /> + + !! width } + label={ __( 'Width' ) } + onDeselect={ () => setAttributes( { width: undefined } ) } + resetAllFilter={ () => ( { + width: undefined, + } ) } + isShownByDefault={ true } + panelId={ clientId } + > + + onDimensionChange( 'width', nextWidth ) + } + units={ units } + /> + + { showScaleControl && ( + !! scale && scale !== DEFAULT_SCALE } + label={ scaleLabel } + onDeselect={ () => + setAttributes( { + scale: DEFAULT_SCALE, + } ) + } + resetAllFilter={ () => ( { + scale: DEFAULT_SCALE, + } ) } + isShownByDefault={ true } + panelId={ clientId } + > + + setAttributes( { + scale: value, + } ) + } + isBlock + > + { SCALE_OPTIONS } + + + ) } + { !! imageSizeOptions.length && ( + !! sizeSlug } + label={ __( 'Resolution' ) } + onDeselect={ () => + setAttributes( { sizeSlug: undefined } ) + } + resetAllFilter={ () => ( { + sizeSlug: undefined, + } ) } + isShownByDefault={ false } + panelId={ clientId } + > + + setAttributes( { sizeSlug: nextSizeSlug } ) + } + help={ __( 'Select the size of the source image.' ) } + /> + + ) } + + ); +}; + +export default DimensionControls; diff --git a/blocks/coauthor-feature-image/src/edit.js b/blocks/coauthor-feature-image/src/edit.js new file mode 100644 index 00000000..0f72111c --- /dev/null +++ b/blocks/coauthor-feature-image/src/edit.js @@ -0,0 +1,110 @@ + +import { __ } from '@wordpress/i18n'; +import { useBlockProps, store as blockEditorStore, __experimentalUseBorderProps as useBorderProps } from '@wordpress/block-editor'; +import './editor.scss'; + +import { Placeholder } from '@wordpress/components'; +import { useSelect, useDispatch } from '@wordpress/data'; + +import { useEntityProp, store as coreStore } from '@wordpress/core-data'; + +import DimensionControls from './dimension-controls'; + +import classnames from 'classnames'; + +function getMediaSourceUrlBySizeSlug( media, slug ) { + return ( + media?.media_details?.sizes?.[ slug ]?.source_url || media?.source_url + ); +} + +/** + * Edit + * + * @return {WPElement} Element to render. + */ +export default function Edit( { attributes, setAttributes, context, clientId } ) { + + const { width, height, aspectRatio, sizeSlug, scale } = attributes; + + const author = context['cap/author'] || { + id: 0, + display_name: 'FirstName LastName', + link: '#', + avatar_urls: [], + featured_media: 0 + }; + + const media = useSelect( (select) => { + const { getMedia } = select( coreStore ); + return 0 !== author.featured_media && getMedia( author.featured_media, { context: 'view' } ) + }, [author.featured_media]); + + const mediaUrl = getMediaSourceUrlBySizeSlug( media, sizeSlug ); + + const imageSizes = useSelect( + ( select ) => select( blockEditorStore ).getSettings().imageSizes, + [] + ); + const imageSizeOptions = imageSizes + .filter( ( { slug } ) => { + return media?.media_details?.sizes?.[ slug ]?.source_url; + } ) + .map( ( { name, slug } ) => ( { + value: slug, + label: name, + } ) ); + + const borderProps = useBorderProps( attributes ); + + + const imageStyles = { + ...borderProps.style, + height: aspectRatio ? '100%' : height, + width: !! aspectRatio && '100%', + objectFit: !! ( height || aspectRatio ) && scale, + }; + + return ( + <> + + +
+ { + media ? ( + { + ) : ( + + ) + } +
+ + ); +} diff --git a/blocks/coauthor-feature-image/src/editor.scss b/blocks/coauthor-feature-image/src/editor.scss new file mode 100644 index 00000000..8c20cfa9 --- /dev/null +++ b/blocks/coauthor-feature-image/src/editor.scss @@ -0,0 +1,14 @@ +/** + * The following styles get applied inside the editor only. + * + * Replace them with your own styles or remove the file completely. + */ + +.wp-block-cap-coauthor-feature-image { + // border: 1px dotted #f00; +} + +.wp-block-cap-coauthor-feature-image .components-placeholder { + // min-width: auto; + // min-height: auto; +} diff --git a/blocks/coauthor-feature-image/src/index.js b/blocks/coauthor-feature-image/src/index.js new file mode 100644 index 00000000..ade1e478 --- /dev/null +++ b/blocks/coauthor-feature-image/src/index.js @@ -0,0 +1,39 @@ +/** + * Registers a new block provided a unique name and an object defining its behavior. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +import { registerBlockType } from '@wordpress/blocks'; + +/** + * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. + * All files containing `style` keyword are bundled together. The code used + * gets applied both to the front of your site and to the editor. + * + * @see https://www.npmjs.com/package/@wordpress/scripts#using-css + */ +import './style.scss'; + +/** + * Internal dependencies + */ +import Edit from './edit'; +import save from './save'; +import metadata from './block.json'; + +/** + * Every block starts by registering a new block type definition. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +registerBlockType( metadata.name, { + /** + * @see ./edit.js + */ + edit: Edit, + + /** + * @see ./save.js + */ + save, +} ); diff --git a/blocks/coauthor-feature-image/src/save.js b/blocks/coauthor-feature-image/src/save.js new file mode 100644 index 00000000..350d12a8 --- /dev/null +++ b/blocks/coauthor-feature-image/src/save.js @@ -0,0 +1,24 @@ +/** + * React hook that is used to mark the block wrapper element. + * It provides all the necessary props like the class name. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops + */ +import { useBlockProps } from '@wordpress/block-editor'; + +/** + * The save function defines the way in which the different attributes should + * be combined into the final markup, which is then serialized by the block + * editor into `post_content`. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save + * + * @return {WPElement} Element to render. + */ +export default function save() { + return ( +

+ { 'Coauthor Feature Image – hello from the saved content!' } +

+ ); +} diff --git a/blocks/coauthor-feature-image/src/style.scss b/blocks/coauthor-feature-image/src/style.scss new file mode 100644 index 00000000..3f13ff69 --- /dev/null +++ b/blocks/coauthor-feature-image/src/style.scss @@ -0,0 +1,21 @@ +/** + * The following styles get applied both on the front of your site + * and in the editor. + * + * Replace them with your own styles or remove the file completely. + */ + +.wp-block-cap-coauthor-feature-image { + // background-color: #21759b; + // color: #fff; + // padding: 2px; +} + +.wp-block-cap-coauthor-feature-image :where(img,svg) { + display: block; +} + +.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-feature-image { + display: inline-flex; + vertical-align: middle; +} diff --git a/blocks/coauthor-feature-image/src/view.js b/blocks/coauthor-feature-image/src/view.js new file mode 100644 index 00000000..2c36b119 --- /dev/null +++ b/blocks/coauthor-feature-image/src/view.js @@ -0,0 +1,3 @@ +/* eslint-disable no-console */ +console.log("Hello World! (from cap-coauthor-feature-image block)"); +/* eslint-enable no-console */ From 10bd299a43f37947e05bf348b4341153ef1d9aee Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 9 Aug 2023 13:27:19 -0400 Subject: [PATCH 039/123] render guest author feature image --- ...class-cap-block-coauthor-feature-image.php | 53 +++++++++++++++- blocks/coauthor-feature-image/src/block.json | 12 ++-- blocks/coauthor-feature-image/src/edit.js | 60 +++++++++++-------- blocks/coauthor-feature-image/src/style.scss | 6 +- 4 files changed, 98 insertions(+), 33 deletions(-) diff --git a/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php b/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php index 3a607f69..91140dfd 100644 --- a/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php +++ b/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php @@ -36,7 +36,58 @@ public static function register_block() : void { * @return string */ public static function render_block( array $attributes, string $content, WP_Block $block ) : string { - return $content; + + $author = $block->context['cap/author'] ?? array(); + + if ( empty( $author ) ) { + return ''; + } + + $featured_media_id = absint( $author['featured_media'] ?? 0 ); + + if ( 0 === $featured_media_id ) { + return ''; + } + + $size_slug = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'thumbnail'; + $attr = get_block_core_post_featured_image_border_attributes( $attributes ); + + $extra_styles = ''; + + // Aspect ratio with a height set needs to override the default width/height. + if ( ! empty( $attributes['aspectRatio'] ) ) { + $extra_styles .= 'width:100%;height:100%;'; + } elseif ( ! empty( $attributes['height'] ) ) { + $extra_styles .= "height:{$attributes['height']};"; + } + + if ( ! empty( $attributes['scale'] ) ) { + $extra_styles .= "object-fit:{$attributes['scale']};"; + } + + if ( ! empty( $extra_styles ) ) { + $attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles; + } + + $featured_image = wp_get_attachment_image( $featured_media_id, $size_slug, false, $attr ); + + $aspect_ratio = ! empty( $attributes['aspectRatio'] ) + ? esc_attr( safecss_filter_attr( 'aspect-ratio:' . $attributes['aspectRatio'] ) ) . ';' + : ''; + $width = ! empty( $attributes['width'] ) + ? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';' + : ''; + $height = ! empty( $attributes['height'] ) + ? esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';' + : ''; + + if ( ! $height && ! $width && ! $aspect_ratio ) { + $wrapper_attributes = get_block_wrapper_attributes(); + } else { + $wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $aspect_ratio . $width . $height ) ); + } + + return "
{$featured_image}
"; } /** * Provide Author Archive Context diff --git a/blocks/coauthor-feature-image/src/block.json b/blocks/coauthor-feature-image/src/block.json index 4400835f..46fd35df 100644 --- a/blocks/coauthor-feature-image/src/block.json +++ b/blocks/coauthor-feature-image/src/block.json @@ -16,14 +16,18 @@ "__experimentalSelector": "img, .block-editor-media-placeholder, .wp-block-post-featured-image__overlay", "__experimentalSkipSerialization": true, "__experimentalDefaultControls": { - "color": true, - "radius": true, - "width": true + "color": false, + "radius": false, + "width": false } }, "spacing": { "margin": true, - "padding": true + "padding": true, + "__experimentalDefaultControls": { + "margin": false, + "padding": false + } } }, "usesContext": [ diff --git a/blocks/coauthor-feature-image/src/edit.js b/blocks/coauthor-feature-image/src/edit.js index 0f72111c..13ca91a1 100644 --- a/blocks/coauthor-feature-image/src/edit.js +++ b/blocks/coauthor-feature-image/src/edit.js @@ -1,17 +1,25 @@ +import classnames from 'classnames'; import { __ } from '@wordpress/i18n'; -import { useBlockProps, store as blockEditorStore, __experimentalUseBorderProps as useBorderProps } from '@wordpress/block-editor'; -import './editor.scss'; - +import { + useBlockProps, + store as blockEditorStore, + __experimentalUseBorderProps as useBorderProps +} from '@wordpress/block-editor'; import { Placeholder } from '@wordpress/components'; -import { useSelect, useDispatch } from '@wordpress/data'; +import { useSelect } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; -import { useEntityProp, store as coreStore } from '@wordpress/core-data'; +import './editor.scss'; import DimensionControls from './dimension-controls'; -import classnames from 'classnames'; - +/** + * + * @param {Object|undefined} media + * @param {String|undefined} slug + * @return {String|undefined} + */ function getMediaSourceUrlBySizeSlug( media, slug ) { return ( media?.media_details?.sizes?.[ slug ]?.source_url || media?.source_url @@ -36,28 +44,22 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) }; const media = useSelect( (select) => { - const { getMedia } = select( coreStore ); - return 0 !== author.featured_media && getMedia( author.featured_media, { context: 'view' } ) + return 0 !== author.featured_media && select( coreStore ).getMedia( author.featured_media, { context: 'view' } ) }, [author.featured_media]); const mediaUrl = getMediaSourceUrlBySizeSlug( media, sizeSlug ); - const imageSizes = useSelect( - ( select ) => select( blockEditorStore ).getSettings().imageSizes, + const { imageSizes, imageDimensions } = useSelect( + ( select ) => select( blockEditorStore ).getSettings(), [] ); - const imageSizeOptions = imageSizes - .filter( ( { slug } ) => { - return media?.media_details?.sizes?.[ slug ]?.source_url; - } ) - .map( ( { name, slug } ) => ( { - value: slug, - label: name, - } ) ); + + const imageSizeOptions = imageSizes.map( + ( { name, slug } ) => ( { value: slug, label: name } ) + ); const borderProps = useBorderProps( attributes ); - const imageStyles = { ...borderProps.style, height: aspectRatio ? '100%' : height, @@ -65,6 +67,17 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) objectFit: !! ( height || aspectRatio ) && scale, }; + const widthFromImageDimensions = imageDimensions[sizeSlug]?.width; + const hasWidthOrHeight = width || height; + + const blockProps = useBlockProps( { + style: { + width: hasWidthOrHeight ? width : widthFromImageDimensions, + height, + aspectRatio, + } + } ); + return ( <> - -
+
{ media ? ( ) : ( ) } -
+ ); } diff --git a/blocks/coauthor-feature-image/src/style.scss b/blocks/coauthor-feature-image/src/style.scss index 3f13ff69..ca70475a 100644 --- a/blocks/coauthor-feature-image/src/style.scss +++ b/blocks/coauthor-feature-image/src/style.scss @@ -5,10 +5,8 @@ * Replace them with your own styles or remove the file completely. */ -.wp-block-cap-coauthor-feature-image { - // background-color: #21759b; - // color: #fff; - // padding: 2px; +.wp-block-cap-coauthor-feature-image:where(figure) { + margin-block-end: 0; } .wp-block-cap-coauthor-feature-image :where(img,svg) { From a2b37e80b0f3871524262ae54dd8220d9b846f8d Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 9 Aug 2023 13:27:29 -0400 Subject: [PATCH 040/123] build feature image block --- blocks/coauthor-feature-image/build/block.json | 12 ++++++++---- blocks/coauthor-feature-image/build/index.asset.php | 2 +- blocks/coauthor-feature-image/build/index.js | 4 ++-- blocks/coauthor-feature-image/build/style-index.css | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/blocks/coauthor-feature-image/build/block.json b/blocks/coauthor-feature-image/build/block.json index 863e1fbf..e174fbc8 100644 --- a/blocks/coauthor-feature-image/build/block.json +++ b/blocks/coauthor-feature-image/build/block.json @@ -22,14 +22,18 @@ "__experimentalSelector": "img, .block-editor-media-placeholder, .wp-block-post-featured-image__overlay", "__experimentalSkipSerialization": true, "__experimentalDefaultControls": { - "color": true, - "radius": true, - "width": true + "color": false, + "radius": false, + "width": false } }, "spacing": { "margin": true, - "padding": true + "padding": true, + "__experimentalDefaultControls": { + "margin": false, + "padding": false + } } }, "usesContext": [ diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php index a1079401..8087018f 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '26f13fe5d2cc650f54f6'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '6de75661c5837bb87cb7'); diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js index 7b47fd2b..fca113ba 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-feature-image/build/index.js @@ -1,3 +1,3 @@ -!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=window.wp.i18n,i=window.wp.blockEditor,r=window.wp.components,s=window.wp.data,u=window.wp.coreData;const c=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.__experimentalToggleGroupControlOption,{value:"cover",label:(0,o._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(r.__experimentalToggleGroupControlOption,{value:"contain",label:(0,o._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(r.__experimentalToggleGroupControlOption,{value:"fill",label:(0,o._x)("Fill","Scale option for Image dimension control")})),p="cover",d={cover:(0,o.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,o.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,o.__)("Image will be stretched and distorted to completely fill the space.")};var m=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:s,scale:u,sizeSlug:m},setAttributes:_,imageSizeOptions:h=[]}=e;const g=(0,r.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||_({[e]:l<0?"0":t})},f=(0,o._x)("Scale","Image scaling options"),b=s||l&&"auto"!==l;return(0,a.createElement)(i.InspectorControls,{group:"dimensions"},(0,a.createElement)(r.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,o.__)("Aspect ratio"),onDeselect:()=>_({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Aspect ratio"),value:l,options:[{label:(0,o.__)("Original"),value:"auto"},{label:(0,o.__)("Square"),value:"1"},{label:(0,o.__)("16:9"),value:"16/9"},{label:(0,o.__)("4:3"),value:"4/3"},{label:(0,o.__)("3:2"),value:"3/2"},{label:(0,o.__)("9:16"),value:"9/16"},{label:(0,o.__)("3:4"),value:"3/4"},{label:(0,o.__)("2:3"),value:"2/3"}],onChange:e=>_({aspectRatio:e})})),(0,a.createElement)(r.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!s,label:(0,o.__)("Height"),onDeselect:()=>_({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(r.__experimentalUnitControl,{label:(0,o.__)("Height"),labelPosition:"top",value:s||"",min:0,onChange:e=>v("height",e),units:g})),(0,a.createElement)(r.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,o.__)("Width"),onDeselect:()=>_({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(r.__experimentalUnitControl,{label:(0,o.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:g})),b&&(0,a.createElement)(r.__experimentalToolsPanelItem,{hasValue:()=>!!u&&u!==p,label:f,onDeselect:()=>_({scale:p}),resetAllFilter:()=>({scale:p}),isShownByDefault:!0,panelId:t},(0,a.createElement)(r.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:u,help:d[u],onChange:e=>_({scale:e}),isBlock:!0},c)),!!h.length&&(0,a.createElement)(r.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,o.__)("Resolution"),onDeselect:()=>_({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Resolution"),value:m||"full",options:h,onChange:e=>_({sizeSlug:e}),help:(0,o.__)("Select the size of the source image.")})))},_=l(779),h=l.n(_),g=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(g.u2,{edit:function(e){let{attributes:t,setAttributes:l,context:n,clientId:c}=e;const{width:p,height:d,aspectRatio:_,sizeSlug:g,scale:v}=t,f=n["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:[],featured_media:0},b=(0,s.useSelect)((e=>{const{getMedia:t}=e(u.store);return 0!==f.featured_media&&t(f.featured_media,{context:"view"})}),[f.featured_media]),w=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(b,g),x=(0,s.useSelect)((e=>e(i.store).getSettings().imageSizes),[]).filter((e=>{var t,l,n;let{slug:a}=e;return null==b||null===(t=b.media_details)||void 0===t||null===(l=t.sizes)||void 0===l||null===(n=l[a])||void 0===n?void 0:n.source_url})).map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),S=(0,i.__experimentalUseBorderProps)(t),y={...S.style,height:_?"100%":d,width:!!_&&"100%",objectFit:!(!d&&!_)&&v};return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(m,{clientId:c,attributes:t,setAttributes:l,imageSizeOptions:x}),(0,a.createElement)("div",(0,i.useBlockProps)({style:{width:p,height:d,aspectRatio:_}}),b?(0,a.createElement)("img",{src:w,alt:b.alt_text?sprintf( +!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=l(779),i=l.n(o),r=window.wp.i18n,s=window.wp.blockEditor,u=window.wp.components,c=window.wp.data,p=window.wp.coreData;const m=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),d="cover",_={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var h=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:o,scale:i,sizeSlug:c},setAttributes:p,imageSizeOptions:h=[]}=e;const g=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),b=o||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:o||"",min:0,onChange:e=>v("height",e),units:g})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:g})),b&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==d,label:f,onDeselect:()=>p({scale:d}),resetAllFilter:()=>({scale:d}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:_[i],onChange:e=>p({scale:e}),isBlock:!0},m)),!!h.length&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:h,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))},g=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(g.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:o,clientId:m}=e;const{width:d,height:_,aspectRatio:g,sizeSlug:v,scale:f}=l,b=o["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:[],featured_media:0},w=(0,c.useSelect)((e=>0!==b.featured_media&&e(p.store).getMedia(b.featured_media,{context:"view"})),[b.featured_media]),x=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(w,v),{imageSizes:S,imageDimensions:y}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),E=S.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),I=(0,s.__experimentalUseBorderProps)(l),C={...I.style,height:g?"100%":_,width:!!g&&"100%",objectFit:!(!_&&!g)&&f},O=null===(t=y[v])||void 0===t?void 0:t.width,F=d||_,P=(0,s.useBlockProps)({style:{width:F?d:O,height:_,aspectRatio:g}});return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(h,{clientId:m,attributes:l,setAttributes:n,imageSizeOptions:E}),(0,a.createElement)("figure",P,w?(0,a.createElement)("img",{src:x,alt:w.alt_text?sprintf( // translators: %s: The image's alt text. -(0,o.__)("Featured image: %s"),b.alt_text):(0,o.__)("Featured image"),style:y}):(0,a.createElement)(r.Placeholder,{className:h()("block-editor-media-placeholder",S.className),withIllustration:!0,style:{height:!!_&&"100%",width:!!_&&"100%",minWidth:"auto",minHeight:"auto",...S.style}})))},save:function(){return(0,a.createElement)("p",i.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[c-1][2]>o;c--)e[c]=e[c-1];e[c]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var c=s(n)}for(t&&t(l);u=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[c-1][2]>o;c--)e[c]=e[c-1];e[c]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var c=s(n)}for(t&&t(l);u Date: Wed, 9 Aug 2023 13:57:45 -0400 Subject: [PATCH 041/123] consistent linking to author archive --- blocks/coauthor-avatar/build/block.json | 4 ++- blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- .../class-cap-block-coauthor-avatar.php | 16 ++++++++--- blocks/coauthor-avatar/src/block.json | 3 +++ blocks/coauthor-avatar/src/edit.js | 14 ++++++++-- blocks/coauthor-display-name/build/block.json | 1 - .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- .../class-cap-block-coauthor-display-name.php | 4 +-- blocks/coauthor-display-name/src/block.json | 1 - .../coauthor-feature-image/build/block.json | 3 +-- .../build/index.asset.php | 2 +- blocks/coauthor-feature-image/build/index.js | 4 +-- ...class-cap-block-coauthor-feature-image.php | 22 +++++++++++++++ blocks/coauthor-feature-image/src/block.json | 3 +-- blocks/coauthor-feature-image/src/edit.js | 27 ++++++++++++++++--- 17 files changed, 87 insertions(+), 25 deletions(-) diff --git a/blocks/coauthor-avatar/build/block.json b/blocks/coauthor-avatar/build/block.json index 6a981c3e..9ad46eb8 100644 --- a/blocks/coauthor-avatar/build/block.json +++ b/blocks/coauthor-avatar/build/block.json @@ -21,10 +21,12 @@ "isLink": { "type": "boolean", "default": false + }, + "rel": { + "type": "string" } }, "textdomain": "coauthor-avatar", "editorScript": "file:./index.js", - "editorStyle": "file:./index.css", "style": "file:./style-index.css" } \ No newline at end of file diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index 6811c576..b4e483f9 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'c81272de10aa20374275'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '1752e170c3d26ba5aa1a'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index 51a9059c..00e93a69 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={631:function(){var e=window.wp.blocks,t=window.wp.element,n=window.wp.i18n,r=window.wp.blockEditor,i=window.wp.components;window.wp.data;var a=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(a.u2,{edit:function(e){let{context:a,attributes:o,setAttributes:l}=e;const{isLink:s,size:c}=o,h=a["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},{avatar_urls:u,link:f}=h;if(!u||0===u.length)return null;const v=Object.keys(u).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,t.createElement)("img",{width:c,height:c,src:`${u[c]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,r.useBlockProps)(),s?(0,t.createElement)("a",{href:f,onClick:e=>e.preventDefault()},w):w),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,n.__)("Avatar Settings")},(0,t.createElement)(i.ToggleControl,{label:(0,n.__)("Make avatar a link to author archive."),onChange:()=>l({isLink:!s}),checked:s}),(0,t.createElement)(i.SelectControl,{label:(0,n.__)("Avatar size"),value:c,options:v,onChange:e=>{l({size:Number(e)})}}))))}})}},n={};function r(e){var i=n[e];if(void 0!==i)return i.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=function(t,n,i,a){if(!n){var o=1/0;for(h=0;h=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(l=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[n,i,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var i,a,o=n[0],l=n[1],s=n[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(i in l)r.o(l,i)&&(r.m[i]=l[i]);if(s)var h=s(r)}for(t&&t(n);c({value:e,label:`${e} x ${e}`}))),w=(0,t.createElement)("img",{width:h,height:h,src:`${f[h]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,r.useBlockProps)(),s?(0,t.createElement)("a",{href:v,onClick:e=>e.preventDefault()},w):w),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,n.__)("Avatar Settings")},(0,t.createElement)(i.ToggleControl,{label:(0,n.__)("Make avatar a link to author archive."),onChange:()=>o({isLink:!s}),checked:s}),s&&(0,t.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)("Link rel"),value:c,onChange:e=>o({rel:e})}),(0,t.createElement)(i.SelectControl,{label:(0,n.__)("Avatar size"),value:h,options:g,onChange:e=>{o({size:Number(e)})}}))))}})}},n={};function r(e){var i=n[e];if(void 0!==i)return i.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=function(t,n,i,a){if(!n){var l=1/0;for(h=0;h=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(o=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[n,i,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var i,a,l=n[0],o=n[1],s=n[2],c=0;if(l.some((function(t){return 0!==e[t]}))){for(i in o)r.o(o,i)&&(r.m[i]=o[i]);if(s)var h=s(r)}for(t&&t(n);c "{$url} {$size}w", @@ -74,7 +74,9 @@ public static function render_block( array $attributes, string $content, WP_Bloc implode( ', ', $srcset) ); - $inner_content = $is_link ? self::add_link( $link, $image ) : $image; + $rel = $attributes['rel'] ?? ''; + + $inner_content = $is_link ? self::add_link( $link, $image, $rel ) : $image; return self::get_block_wrapper_function( 'div', @@ -87,10 +89,16 @@ public static function render_block( array $attributes, string $content, WP_Bloc * * @param string $link * @param string $content + * @param null|string $rel * @return string */ - public static function add_link( string $link, string $content ) : string { - return sprintf('
%s', $link, $content); + public static function add_link( string $link, string $content, ?string $rel = '' ) : string { + return sprintf( + '%s', + $link, + $rel, + $content + ); } /** diff --git a/blocks/coauthor-avatar/src/block.json b/blocks/coauthor-avatar/src/block.json index f5010b67..78b846dc 100644 --- a/blocks/coauthor-avatar/src/block.json +++ b/blocks/coauthor-avatar/src/block.json @@ -21,6 +21,9 @@ "isLink": { "type": "boolean", "default": false + }, + "rel": { + "type": "string" } }, "textdomain": "coauthor-avatar", diff --git a/blocks/coauthor-avatar/src/edit.js b/blocks/coauthor-avatar/src/edit.js index d90655b5..f25065a4 100644 --- a/blocks/coauthor-avatar/src/edit.js +++ b/blocks/coauthor-avatar/src/edit.js @@ -1,6 +1,6 @@ import { __ } from '@wordpress/i18n'; import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; -import { SelectControl, PanelBody, ToggleControl } from '@wordpress/components'; +import { SelectControl, PanelBody, ToggleControl, TextControl } from '@wordpress/components'; /** * The edit function describes the structure of your block in the context of the @@ -12,7 +12,7 @@ import { SelectControl, PanelBody, ToggleControl } from '@wordpress/components'; */ export default function Edit( { context, attributes, setAttributes } ) { - const { isLink, size } = attributes; + const { isLink, rel, size } = attributes; const author = context['cap/author'] || { id: 0, display_name: 'FirstName LastName', @@ -62,6 +62,16 @@ export default function Edit( { context, attributes, setAttributes } ) { onChange={ () => setAttributes( { isLink: ! isLink } ) } checked={ isLink } /> + { isLink && ( + + setAttributes( { rel: newRel } ) + } + /> + ) } array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a3fc7095e6db95805807'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '0be45211cc6280cbad12'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index 501ccc1a..18bd619b 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function i(){for(var e=[],t=0;t{s({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:l()({[`has-text-align-${g}`]:g})}),c?(0,t.createElement)("a",{href:h,rel:u,onClick:e=>e.preventDefault()},p):p),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(i.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>s({isLink:!c}),checked:c}),c&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:u,onChange:e=>s({rel:e})})))))}})}()}(); \ No newline at end of file +!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function i(){for(var e=[],t=0;t{s({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:l()({[`has-text-align-${g}`]:g})}),c?(0,t.createElement)("a",{href:h,rel:u,onClick:e=>e.preventDefault()},p):p),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(i.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>s({isLink:!c}),checked:c}),c&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:u,onChange:e=>s({rel:e})})))))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index 1f4bcf79..b5f14420 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -50,10 +50,10 @@ public static function render_block( array $attributes, string $content, WP_Bloc } $link = $author['link'] ?? ''; - $is_link = $attributes['isLink'] ?? false; + $is_link = '' !== $link && $attributes['isLink'] ?? false; $rel = $attributes['rel'] ?? ''; - if ( $is_link && '' !== $link ) { + if ( $is_link ) { $inner_content = sprintf( '%s', $rel, diff --git a/blocks/coauthor-display-name/src/block.json b/blocks/coauthor-display-name/src/block.json index 1cff4932..aec2e661 100644 --- a/blocks/coauthor-display-name/src/block.json +++ b/blocks/coauthor-display-name/src/block.json @@ -45,7 +45,6 @@ }, "rel": { "type": "string", - "attribute": "rel", "default": "author" }, "textAlign": { diff --git a/blocks/coauthor-feature-image/build/block.json b/blocks/coauthor-feature-image/build/block.json index e174fbc8..72737791 100644 --- a/blocks/coauthor-feature-image/build/block.json +++ b/blocks/coauthor-feature-image/build/block.json @@ -45,8 +45,7 @@ "default": false }, "rel": { - "type": "string", - "attribute": "rel" + "type": "string" }, "aspectRatio": { "type": "string" diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php index 8087018f..98d9e0a9 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '6de75661c5837bb87cb7'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '0be34c8631e422938561'); diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js index fca113ba..4fb78861 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-feature-image/build/index.js @@ -1,3 +1,3 @@ -!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=l(779),i=l.n(o),r=window.wp.i18n,s=window.wp.blockEditor,u=window.wp.components,c=window.wp.data,p=window.wp.coreData;const m=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),d="cover",_={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var h=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:o,scale:i,sizeSlug:c},setAttributes:p,imageSizeOptions:h=[]}=e;const g=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),b=o||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:o||"",min:0,onChange:e=>v("height",e),units:g})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:g})),b&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==d,label:f,onDeselect:()=>p({scale:d}),resetAllFilter:()=>({scale:d}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:_[i],onChange:e=>p({scale:e}),isBlock:!0},m)),!!h.length&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:h,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))},g=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(g.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:o,clientId:m}=e;const{width:d,height:_,aspectRatio:g,sizeSlug:v,scale:f}=l,b=o["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:[],featured_media:0},w=(0,c.useSelect)((e=>0!==b.featured_media&&e(p.store).getMedia(b.featured_media,{context:"view"})),[b.featured_media]),x=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(w,v),{imageSizes:S,imageDimensions:y}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),E=S.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),I=(0,s.__experimentalUseBorderProps)(l),C={...I.style,height:g?"100%":_,width:!!g&&"100%",objectFit:!(!_&&!g)&&f},O=null===(t=y[v])||void 0===t?void 0:t.width,F=d||_,P=(0,s.useBlockProps)({style:{width:F?d:O,height:_,aspectRatio:g}});return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(h,{clientId:m,attributes:l,setAttributes:n,imageSizeOptions:E}),(0,a.createElement)("figure",P,w?(0,a.createElement)("img",{src:x,alt:w.alt_text?sprintf( +!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=l(779),i=l.n(o),r=window.wp.i18n,s=window.wp.blockEditor,u=window.wp.components,c=window.wp.data,p=window.wp.coreData;const m=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),_="cover",d={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var g=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:o,scale:i,sizeSlug:c},setAttributes:p,imageSizeOptions:g=[]}=e;const h=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),b=o||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:o||"",min:0,onChange:e=>v("height",e),units:h})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:h})),b&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==_,label:f,onDeselect:()=>p({scale:_}),resetAllFilter:()=>({scale:_}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:d[i],onChange:e=>p({scale:e}),isBlock:!0},m)),!!g.length&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:g,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))},h=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(h.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:o,clientId:m}=e;const{isLink:_,rel:d,width:h,height:v,aspectRatio:f,sizeSlug:b,scale:w}=l,x=o["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:[],featured_media:0},S=(0,c.useSelect)((e=>0!==x.featured_media&&e(p.store).getMedia(x.featured_media,{context:"view"})),[x.featured_media]),E=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(S,b),{imageSizes:y,imageDimensions:C}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=(0,s.__experimentalUseBorderProps)(l),k={...O.style,height:f?"100%":v,width:!!f&&"100%",objectFit:!(!v&&!f)&&w},B=null===(t=C[b])||void 0===t?void 0:t.width,P=h||v,F=(0,s.useBlockProps)({style:{width:P?h:B,height:v,aspectRatio:f}});return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(g,{clientId:m,attributes:l,setAttributes:n,imageSizeOptions:I}),(0,a.createElement)("figure",F,S?(0,a.createElement)("img",{src:E,alt:S.alt_text?sprintf( // translators: %s: The image's alt text. -(0,r.__)("Featured image: %s"),w.alt_text):(0,r.__)("Featured image"),style:C}):(0,a.createElement)(u.Placeholder,{className:i()("block-editor-media-placeholder",I.className),withIllustration:!0,style:{height:!!g&&"100%",width:!!g&&"100%",minWidth:"auto",minHeight:"auto",...I.style}})))},save:function(){return(0,a.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[c-1][2]>o;c--)e[c]=e[c-1];e[c]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var c=s(n)}for(t&&t(l);un({isLink:!_}),checked:_}),_&&(0,a.createElement)(u.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:d,onChange:e=>n({rel:e})}))))},save:function(){return(0,a.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[c-1][2]>o;c--)e[c]=e[c-1];e[c]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var c=s(n)}for(t&&t(l);u{$featured_image}"; } + /** + * Add Link + * + * @param string $link + * @param string $content + * @param null|string $rel + * @return string + */ + public static function add_link( string $link, string $content, ?string $rel = '' ) : string { + return sprintf( + '%s', + $link, + $rel, + $content + ); + } /** * Provide Author Archive Context * diff --git a/blocks/coauthor-feature-image/src/block.json b/blocks/coauthor-feature-image/src/block.json index 46fd35df..a44d2a69 100644 --- a/blocks/coauthor-feature-image/src/block.json +++ b/blocks/coauthor-feature-image/src/block.json @@ -39,8 +39,7 @@ "default": false }, "rel": { - "type": "string", - "attribute": "rel" + "type": "string" }, "aspectRatio": { "type": "string" diff --git a/blocks/coauthor-feature-image/src/edit.js b/blocks/coauthor-feature-image/src/edit.js index 13ca91a1..94953d95 100644 --- a/blocks/coauthor-feature-image/src/edit.js +++ b/blocks/coauthor-feature-image/src/edit.js @@ -4,9 +4,10 @@ import { __ } from '@wordpress/i18n'; import { useBlockProps, store as blockEditorStore, - __experimentalUseBorderProps as useBorderProps + __experimentalUseBorderProps as useBorderProps, + InspectorControls, } from '@wordpress/block-editor'; -import { Placeholder } from '@wordpress/components'; +import { Placeholder, TextControl, PanelBody, ToggleControl } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; @@ -33,7 +34,7 @@ function getMediaSourceUrlBySizeSlug( media, slug ) { */ export default function Edit( { attributes, setAttributes, context, clientId } ) { - const { width, height, aspectRatio, sizeSlug, scale } = attributes; + const { isLink, rel, width, height, aspectRatio, sizeSlug, scale } = attributes; const author = context['cap/author'] || { id: 0, @@ -117,6 +118,26 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) ) } + + + setAttributes( { isLink: ! isLink } ) } + checked={ isLink } + /> + { isLink && ( + + setAttributes( { rel: newRel } ) + } + /> + ) } + + ); } From 027fd828ea916ca35879df7a2aefd32a173c4d86 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 9 Aug 2023 16:15:46 -0400 Subject: [PATCH 042/123] unify placeholders, use border not rounded style --- blocks/coauthor-avatar/build/block.json | 14 ++++- blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- .../class-cap-block-coauthor-avatar.php | 16 +++--- blocks/coauthor-avatar/src/block.json | 14 ++++- blocks/coauthor-avatar/src/edit.js | 52 ++++++++++--------- blocks/coauthor-avatar/src/style.css | 2 +- .../build/index.asset.php | 2 +- blocks/coauthor-description/build/index.js | 2 +- blocks/coauthor-description/src/edit.js | 16 +----- .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- blocks/coauthor-display-name/src/edit.js | 13 +---- .../build/index.asset.php | 2 +- blocks/coauthor-feature-image/build/index.js | 4 +- blocks/coauthor-feature-image/src/block.json | 2 +- blocks/coauthor-feature-image/src/edit.js | 9 +--- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- blocks/coauthors/src/edit.js | 17 ++---- blocks/modules/example-author.js | 12 +++++ 21 files changed, 93 insertions(+), 96 deletions(-) create mode 100644 blocks/modules/example-author.js diff --git a/blocks/coauthor-avatar/build/block.json b/blocks/coauthor-avatar/build/block.json index 9ad46eb8..7989fea0 100644 --- a/blocks/coauthor-avatar/build/block.json +++ b/blocks/coauthor-avatar/build/block.json @@ -8,7 +8,19 @@ "icon": "smiley", "description": "Display a co-author's avatar", "supports": { - "html": false + "html": false, + "__experimentalBorder": { + "color": true, + "radius": true, + "width": true, + "__experimentalSelector": "img, .block-editor-media-placeholder", + "__experimentalSkipSerialization": true, + "__experimentalDefaultControls": { + "color": false, + "radius": false, + "width": false + } + } }, "usesContext": [ "cap/author" diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index b4e483f9..128e751a 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '1752e170c3d26ba5aa1a'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '50343f52f0fcce0364ee'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index 00e93a69..f6c5cc99 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={363:function(){var e=window.wp.blocks,t=window.wp.element,n=window.wp.i18n,r=window.wp.blockEditor,i=window.wp.components,a=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(a.u2,{edit:function(e){let{context:a,attributes:l,setAttributes:o}=e;const{isLink:s,rel:c,size:h}=l,u=a["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"},featured_media:0},{avatar_urls:f,link:v}=u;if(!f||0===f.length)return null;const g=Object.keys(f).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,t.createElement)("img",{width:h,height:h,src:`${f[h]}`});return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,r.useBlockProps)(),s?(0,t.createElement)("a",{href:v,onClick:e=>e.preventDefault()},w):w),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,n.__)("Avatar Settings")},(0,t.createElement)(i.ToggleControl,{label:(0,n.__)("Make avatar a link to author archive."),onChange:()=>o({isLink:!s}),checked:s}),s&&(0,t.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)("Link rel"),value:c,onChange:e=>o({rel:e})}),(0,t.createElement)(i.SelectControl,{label:(0,n.__)("Avatar size"),value:h,options:g,onChange:e=>{o({size:Number(e)})}}))))}})}},n={};function r(e){var i=n[e];if(void 0!==i)return i.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=function(t,n,i,a){if(!n){var l=1/0;for(h=0;h=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(o=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[n,i,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var i,a,l=n[0],o=n[1],s=n[2],c=0;if(l.some((function(t){return 0!==e[t]}))){for(i in o)r.o(o,i)&&(r.m[i]=o[i]);if(s)var h=s(r)}for(t&&t(n);cPlaceholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"",48:"",96:""}},p=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,n.registerBlockType)(p.u2,{edit:function(e){var t;let{context:r,attributes:n,setAttributes:a}=e;const{isLink:p,rel:f,size:d}=n,v=r["cap/author"]||s,{avatar_urls:h}=v;if(!h||0===h.length)return null;const m=Object.keys(h).map((e=>({value:e,label:`${e} x ${e}`}))),g=(0,u.__experimentalUseBorderProps)(n),b=null!==(t=h[d])&&void 0!==t?t:"";return(0,o.createElement)(o.Fragment,null,(0,o.createElement)("div",(0,u.useBlockProps)(),""===b?(0,o.createElement)(c.Placeholder,{className:i()("block-editor-media-placeholder",g.className),withIllustration:!0,style:{height:d,width:d,minWidth:"auto",minHeight:"auto",padding:0,...g.style}}):(0,o.createElement)("img",{style:{...g.style},width:d,height:d,src:`${h[d]}`})),(0,o.createElement)(u.InspectorControls,null,(0,o.createElement)(c.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,o.createElement)(c.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>a({isLink:!p}),checked:p}),p&&(0,o.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:f,onChange:e=>a({rel:e})}),(0,o.createElement)(c.SelectControl,{label:(0,l.__)("Avatar size"),value:d,options:m,onChange:e=>{a({size:Number(e)})}}))))}})},779:function(e,t){var r;!function(){"use strict";var n={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](r[u])}))?r.splice(u--,1):(l=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[r,o,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,r){var o,a,i=r[0],l=r[1],u=r[2],c=0;if(i.some((function(t){return 0!==e[t]}))){for(o in l)n.o(l,o)&&(n.m[o]=l[o]);if(u)var s=u(n)}for(t&&t(r);c array( __CLASS__, 'render_block' ), ) ); - register_block_style( - 'cap/coauthor-avatar', - array( - 'name' => 'rounded', - 'label' => __('Rounded'), - 'inline_style' => '.wp-block-cap-coauthor-avatar.is-style-rounded img { border-radius: 50% }', - ) - ); } /** * Render Block @@ -65,13 +57,17 @@ public static function render_block( array $attributes, string $content, WP_Bloc array_keys( $avatar_urls ) ); + $attr = get_block_core_post_featured_image_border_attributes( $attributes ); + $image = sprintf( - '', + '', $avatar_urls[$size], $size, $size, "{$size}px", - implode( ', ', $srcset) + implode( ', ', $srcset), + $attr['style'] ?? '', + $attr['class'] ?? '' ); $rel = $attributes['rel'] ?? ''; diff --git a/blocks/coauthor-avatar/src/block.json b/blocks/coauthor-avatar/src/block.json index 78b846dc..ce7157fe 100644 --- a/blocks/coauthor-avatar/src/block.json +++ b/blocks/coauthor-avatar/src/block.json @@ -8,7 +8,19 @@ "icon": "smiley", "description": "Display a co-author's avatar", "supports": { - "html": false + "html": false, + "__experimentalBorder": { + "color": true, + "radius": true, + "width": true, + "__experimentalSelector": "img, .block-editor-media-placeholder", + "__experimentalSkipSerialization": true, + "__experimentalDefaultControls": { + "color": false, + "radius": false, + "width": false + } + } }, "usesContext": [ "cap/author" diff --git a/blocks/coauthor-avatar/src/edit.js b/blocks/coauthor-avatar/src/edit.js index f25065a4..8ace0db4 100644 --- a/blocks/coauthor-avatar/src/edit.js +++ b/blocks/coauthor-avatar/src/edit.js @@ -1,6 +1,9 @@ +import classnames from 'classnames'; + import { __ } from '@wordpress/i18n'; -import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; -import { SelectControl, PanelBody, ToggleControl, TextControl } from '@wordpress/components'; +import { useBlockProps, InspectorControls, __experimentalUseBorderProps as useBorderProps } from '@wordpress/block-editor'; +import { Placeholder, SelectControl, PanelBody, ToggleControl, TextControl } from '@wordpress/components'; +import exampleAuthor from '../../modules/example-author'; /** * The edit function describes the structure of your block in the context of the @@ -13,19 +16,8 @@ import { SelectControl, PanelBody, ToggleControl, TextControl } from '@wordpress export default function Edit( { context, attributes, setAttributes } ) { const { isLink, rel, size } = attributes; - const author = context['cap/author'] || { - id: 0, - display_name: 'FirstName LastName', - link: '#', - avatar_urls: { - 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', - 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', - 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' - }, - featured_media: 0 - }; - - const { avatar_urls, link } = author; + const author = context['cap/author'] || exampleAuthor; + const { avatar_urls } = author; if ( ! avatar_urls || 0 === avatar_urls.length ) { return null; @@ -38,22 +30,32 @@ export default function Edit( { context, attributes, setAttributes } ) { }; }); - // what to do if existing size is not in sizes array? - - const image = ; + const borderProps = useBorderProps( attributes ); + const src = avatar_urls[size] ?? ''; + return ( <>
- {( - isLink ? ( - e.preventDefault())}> - {image} - + { + '' === src ? + ( + ) : ( - image + ) - )} + }
diff --git a/blocks/coauthor-avatar/src/style.css b/blocks/coauthor-avatar/src/style.css index f20f86e8..4ac0aa57 100644 --- a/blocks/coauthor-avatar/src/style.css +++ b/blocks/coauthor-avatar/src/style.css @@ -1,4 +1,4 @@ -.wp-block-cap-coauthor-avatar :where(img) { +.wp-block-cap-coauthor-avatar :where(img,svg) { display: block; } diff --git a/blocks/coauthor-description/build/index.asset.php b/blocks/coauthor-description/build/index.asset.php index 828e1748..b7485033 100644 --- a/blocks/coauthor-description/build/index.asset.php +++ b/blocks/coauthor-description/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n'), 'version' => 'f43801ee6c0cc938b461'); + array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n'), 'version' => '31e4e2124cc73f53c0a9'); diff --git a/blocks/coauthor-description/build/index.js b/blocks/coauthor-description/build/index.js index 6f7c69b1..385c1291 100644 --- a/blocks/coauthor-description/build/index.js +++ b/blocks/coauthor-description/build/index.js @@ -1 +1 @@ -!function(){var t={779:function(t,e){var i;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var t=[],e=0;ePost hoc impie perpetratum quod in aliis quoque iam timebatur, tamquam licentia crudelitati indulta per suspicionum nebulas aestimati quidam.

",link:"#",avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},{description:c}=u;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(n.BlockControls,null,(0,r.createElement)(n.AlignmentControl,{value:l,onChange:t=>{s({textAlign:t})}})),(0,r.createElement)("div",e({},(0,n.useBlockProps)({className:a()({[`has-text-align-${l}`]:l,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:c}})))}})}()}(); \ No newline at end of file +!function(){var t={779:function(t,e){var r;!function(){"use strict";var n={}.hasOwnProperty;function i(){for(var t=[],e=0;ePlaceholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},l=JSON.parse('{"u2":"cap/coauthor-description"}');(0,t.registerBlockType)(l.u2,{edit:function(t){let{context:r,attributes:o,setAttributes:l}=t;const{textAlign:c}=o,u=r["cap/author"]||s,{description:f}=u;return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(i.BlockControls,null,(0,n.createElement)(i.AlignmentControl,{value:c,onChange:t=>{l({textAlign:t})}})),(0,n.createElement)("div",e({},(0,i.useBlockProps)({className:a()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f}})))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-description/src/edit.js b/blocks/coauthor-description/src/edit.js index f0e0b2f7..6e2d6ba9 100644 --- a/blocks/coauthor-description/src/edit.js +++ b/blocks/coauthor-description/src/edit.js @@ -7,7 +7,7 @@ import { useBlockProps, AlignmentControl, BlockControls } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; import classnames from 'classnames'; - +import exampleAuthor from '../../modules/example-author'; import './editor.css'; /** @@ -21,19 +21,7 @@ import './editor.css'; export default function Edit( { context, attributes, setAttributes } ) { const { textAlign } = attributes; - - const author = context['cap/author'] || { - id: 0, - display_name: 'FirstName LastName', - description: '

Post hoc impie perpetratum quod in aliis quoque iam timebatur, tamquam licentia crudelitati indulta per suspicionum nebulas aestimati quidam.

', - link: '#', - avatar_urls: { - 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', - 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', - 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' - } - }; - + const author = context['cap/author'] || exampleAuthor; const { description } = author; return ( diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index c3ee7efd..d8b0cb1e 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '0be45211cc6280cbad12'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '4a6ee27d24c59530577e'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index 18bd619b..d4cf7611 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function i(){for(var e=[],t=0;t{s({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:l()({[`has-text-align-${g}`]:g})}),c?(0,t.createElement)("a",{href:h,rel:u,onClick:e=>e.preventDefault()},p):p),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(i.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>s({isLink:!c}),checked:c}),c&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:u,onChange:e=>s({rel:e})})))))}})}()}(); \ No newline at end of file +!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function i(){for(var e=[],t=0;tPlaceholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},c=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(c.u2,{edit:function(e){let{context:n,attributes:a,setAttributes:c}=e;const{isLink:u,rel:f,textAlign:g}=a,p=n["cap/author"]||s,{link:h,display_name:d}=p;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:g,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:l()({[`has-text-align-${g}`]:g})}),u?(0,t.createElement)("a",{href:h,rel:f,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(i.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>c({isLink:!u}),checked:u}),u&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:f,onChange:e=>c({rel:e})})))))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index 5754004b..8ca2562b 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -8,6 +8,7 @@ import { useBlockProps, InspectorControls, AlignmentControl, BlockControls } fro import { TextControl, PanelBody, ToggleControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import classnames from 'classnames'; +import exampleAuthor from '../../modules/example-author'; /** * The edit function describes the structure of your block in the context of the @@ -20,17 +21,7 @@ import classnames from 'classnames'; export default function Edit( { context, attributes, setAttributes } ) { const { isLink, rel, textAlign } = attributes; - const author = context['cap/author'] || { - id: 0, - display_name: 'FirstName LastName', - link: '#', - avatar_urls: { - 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', - 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', - 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' - } - }; - + const author = context['cap/author'] || exampleAuthor; const { link, display_name } = author; return ( diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php index 98d9e0a9..ce95d0ec 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '0be34c8631e422938561'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'cb612ea4f09ae72ae63b'); diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js index 4fb78861..960f99cf 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-feature-image/build/index.js @@ -1,3 +1,3 @@ -!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=l(779),i=l.n(o),r=window.wp.i18n,s=window.wp.blockEditor,u=window.wp.components,c=window.wp.data,p=window.wp.coreData;const m=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),_="cover",d={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var g=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:o,scale:i,sizeSlug:c},setAttributes:p,imageSizeOptions:g=[]}=e;const h=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),b=o||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:o||"",min:0,onChange:e=>v("height",e),units:h})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:h})),b&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==_,label:f,onDeselect:()=>p({scale:_}),resetAllFilter:()=>({scale:_}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:d[i],onChange:e=>p({scale:e}),isBlock:!0},m)),!!g.length&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:g,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))},h=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(h.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:o,clientId:m}=e;const{isLink:_,rel:d,width:h,height:v,aspectRatio:f,sizeSlug:b,scale:w}=l,x=o["cap/author"]||{id:0,display_name:"FirstName LastName",link:"#",avatar_urls:[],featured_media:0},S=(0,c.useSelect)((e=>0!==x.featured_media&&e(p.store).getMedia(x.featured_media,{context:"view"})),[x.featured_media]),E=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(S,b),{imageSizes:y,imageDimensions:C}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=(0,s.__experimentalUseBorderProps)(l),k={...O.style,height:f?"100%":v,width:!!f&&"100%",objectFit:!(!v&&!f)&&w},B=null===(t=C[b])||void 0===t?void 0:t.width,P=h||v,F=(0,s.useBlockProps)({style:{width:P?h:B,height:v,aspectRatio:f}});return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(g,{clientId:m,attributes:l,setAttributes:n,imageSizeOptions:I}),(0,a.createElement)("figure",F,S?(0,a.createElement)("img",{src:E,alt:S.alt_text?sprintf( +!function(){var e,t={969:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,i=l(779),o=l.n(i),r=window.wp.i18n,s=window.wp.blockEditor,c=window.wp.components,u=window.wp.data,m=window.wp.coreData;const d=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),h="cover",p={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var g=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:i,scale:o,sizeSlug:u},setAttributes:m,imageSizeOptions:g=[]}=e;const _=(0,c.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),f=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||m({[e]:l<0?"0":t})},v=(0,r._x)("Scale","Image scaling options"),w=i||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>m({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>m({aspectRatio:e})})),(0,a.createElement)(c.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!i,label:(0,r.__)("Height"),onDeselect:()=>m({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:i||"",min:0,onChange:e=>f("height",e),units:_})),(0,a.createElement)(c.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>m({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>f("width",e),units:_})),w&&(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!o&&o!==h,label:v,onDeselect:()=>m({scale:h}),resetAllFilter:()=>({scale:h}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:v,value:o,help:p[o],onChange:e=>m({scale:e}),isBlock:!0},d)),!!g.length&&(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!u,label:(0,r.__)("Resolution"),onDeselect:()=>m({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(c.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:u||"full",options:g,onChange:e=>m({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))},_={id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},f=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(f.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:i,clientId:d}=e;const{isLink:h,rel:p,width:f,height:v,aspectRatio:w,sizeSlug:x,scale:b}=l,D=i["cap/author"]||_,E=(0,u.useSelect)((e=>0!==D.featured_media&&e(m.store).getMedia(D.featured_media,{context:"view"})),[D.featured_media]),C=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(E,x),{imageSizes:F,imageDimensions:y}=(0,u.useSelect)((e=>e(s.store).getSettings()),[]),S=F.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),I=(0,s.__experimentalUseBorderProps)(l),k={...I.style,height:w?"100%":v,width:!!w&&"100%",objectFit:!(!v&&!w)&&b},O=null===(t=y[x])||void 0===t?void 0:t.width,B=f||v,A=(0,s.useBlockProps)({style:{width:B?f:O,height:v,aspectRatio:w}});return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(g,{clientId:d,attributes:l,setAttributes:n,imageSizeOptions:S}),(0,a.createElement)("figure",A,E?(0,a.createElement)("img",{src:C,alt:E.alt_text?sprintf( // translators: %s: The image's alt text. -(0,r.__)("Featured image: %s"),S.alt_text):(0,r.__)("Featured image"),style:k}):(0,a.createElement)(u.Placeholder,{className:i()("block-editor-media-placeholder",O.className),withIllustration:!0,style:{height:!!f&&"100%",width:!!f&&"100%",minWidth:"auto",minHeight:"auto",...O.style}})),(0,a.createElement)(s.InspectorControls,null,(0,a.createElement)(u.PanelBody,{title:(0,r.__)("Settings")},(0,a.createElement)(u.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make feature image a link to author archive."),onChange:()=>n({isLink:!_}),checked:_}),_&&(0,a.createElement)(u.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:d,onChange:e=>n({rel:e})}))))},save:function(){return(0,a.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[c-1][2]>o;c--)e[c]=e[c-1];e[c]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var c=s(n)}for(t&&t(l);un({isLink:!h}),checked:h}),h&&(0,a.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:p,onChange:e=>n({rel:e})}))))},save:function(){return(0,a.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=i)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[l,a,i]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,i,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var u=s(n)}for(t&&t(l);c { return 0 !== author.featured_media && select( coreStore ).getMedia( author.featured_media, { context: 'view' } ) diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 6bca0952..1bafbb27 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2af020dad6fbebd679f5'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '3494ebb2ec574dd7495c'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index 10a583bd..56ccfbe0 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,h=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),f=n(779),v=n.n(f);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const x=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:f,isSelected:m}=e;const{prefix:y,separator:b,lastSeparator:E,suffix:C,layout:k,textAlign:D}=o,{postId:_}=f,[F,S]=(0,r.useState)([{id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}}]),[A,B]=(0,r.useState)(),O=(0,s.useDispatch)("core/notices");function P(e){"AbortError"!==e.name&&O.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!_)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${_}/`,signal:e.signal}).then(S).catch(P),()=>{e.abort()}}),[_]);const N=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...k,...e}})},I=[{icon:h,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===k.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===k.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:I}),(0,r.createElement)(a.AlignmentControl,{value:D,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:v()({[`is-layout-cap-${k.type}`]:k.type,[`has-text-align-${D}`]:D}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),F&&"inline"===k.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),F&&F.map((e=>{var t;const n=e.id===(A||(null===(t=F[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(g,{blocks:N,blockContextId:e.id,setActiveBlockContextId:B,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===k.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},E&&n===o.length-1?`${E}`:`${b}`),t))),F&&"inline"===k.type&&(m||C)&&(0,r.createElement)(a.RichText,{allowedFormats:x,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:C,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===k.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:b||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:E||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=v()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))})),w={id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}};function x(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var b=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(b.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:f,isSelected:m}=e;const{prefix:b,separator:E,lastSeparator:C,suffix:k,layout:D,textAlign:_}=o,{postId:F}=f,[S,A]=(0,r.useState)([w]),[B,O]=(0,r.useState)(),P=(0,s.useDispatch)("core/notices");function N(e){"AbortError"!==e.name&&P.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!F)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${F}/`,signal:e.signal}).then(A).catch(N),()=>{e.abort()}}),[F]);const z=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),I=e=>{i({layout:{...D,...e}})},V=[{icon:h,title:(0,u.__)("Inline"),onClick:()=>I({type:"inline"}),isActive:"inline"===D.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>I({type:"block"}),isActive:"block"===D.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:V}),(0,r.createElement)(a.AlignmentControl,{value:_,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:v()({[`is-layout-cap-${D.type}`]:D.type,[`has-text-align-${_}`]:_}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),S&&"inline"===D.type&&(m||b)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:b,onChange:e=>i({prefix:e}),tagName:"span"}),S&&S.map((e=>{var t;const n=e.id===(B||(null===(t=S[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(x,null):null,(0,r.createElement)(g,{blocks:z,blockContextId:e.id,setActiveBlockContextId:O,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===D.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===o.length-1?`${C}`:`${E}`),t))),S&&"inline"===D.type&&(m||k)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:k,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===D.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=v()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);sPlaceholder description from Co-Authors block.

', - link: '#', - featured_media: 0, - avatar_urls: { - 24: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E', - 48: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E', - 96: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E' - } - } - ]); + const [ coAuthors, setCoAuthors ] = useState([exampleAuthor]); const [ activeBlockContextId, setActiveBlockContextId ] = useState(); const noticesDispatch = useDispatch('core/notices'); diff --git a/blocks/modules/example-author.js b/blocks/modules/example-author.js new file mode 100644 index 00000000..71233234 --- /dev/null +++ b/blocks/modules/example-author.js @@ -0,0 +1,12 @@ +export default { + id: 0, + display_name: 'FirstName LastName', + description: '

Placeholder description from Co-Authors block.

', + link: '#', + featured_media: 0, + avatar_urls: { + 24: '', + 48: '', + 96: '' + } +}; From 5e6ec6dcc533abc61678de9f87d9c867b364a3ae Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 10 Aug 2023 12:17:52 -0400 Subject: [PATCH 043/123] example author in settings, 1 archive context func --- blocks/blocks.php | 69 +++++++++++++++++++ blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- blocks/coauthor-avatar/build/style-index.css | 2 +- .../class-cap-block-coauthor-avatar.php | 35 ---------- blocks/coauthor-avatar/src/edit.js | 8 +-- .../build/index.asset.php | 2 +- blocks/coauthor-description/build/index.js | 2 +- .../class-cap-block-coauthor-description.php | 37 ---------- blocks/coauthor-description/src/edit.js | 7 +- .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- .../class-cap-block-coauthor-display-name.php | 36 ---------- blocks/coauthor-display-name/src/edit.js | 13 +++- .../coauthor-feature-image/build/block.json | 2 +- .../build/index.asset.php | 2 +- blocks/coauthor-feature-image/build/index.js | 4 +- ...class-cap-block-coauthor-feature-image.php | 36 ---------- blocks/coauthor-feature-image/src/edit.js | 13 ++-- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- blocks/coauthors/src/edit.js | 7 +- blocks/modules/example-author.js | 12 ---- 23 files changed, 108 insertions(+), 191 deletions(-) delete mode 100644 blocks/modules/example-author.js diff --git a/blocks/blocks.php b/blocks/blocks.php index eb5ee55f..f2630c5d 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -10,3 +10,72 @@ new CAP_Block_CoAuthor_Description(); new CAP_Block_CoAuthor_Display_Name(); new CAP_Block_CoAuthor_Feature_Image(); + +add_filter( + 'block_editor_settings_all', + function( array $editor_settings ) : array { + return array_merge( + $editor_settings, + array( + 'cap/author-example' => array( + 'id' => 0, + 'display_name' => 'FirstName LastName', + 'description' => '

Placeholder description from Co-Authors block.

', + 'link' => '#', + 'featured_media' => 0, + 'avatar_urls' => array_map( '__return_empty_string', array_flip( rest_get_avatar_sizes() ) ) + ) + ) + ); + } +); + +/** + * Provide Author Archive Context + * + * @param array $context, + * @param array $parsed_block + * @param null|WP_Block $parent_block + * @return array + */ +function coauthors_blocks_provide_author_archive_context( array $context, array $parsed_block, ?WP_Block $parent_block ) : array { + if ( ! is_author() ) { + return $context; + } + + if ( null === $parsed_block['blockName'] ) { + return $context; + } + + $uses_author_context = apply_filters( + 'coauthor_blocks_block_uses_author_context', + 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ), + $parsed_block['blockName'] + ); + + $has_author_context = array_key_exists( 'cap/author', $context ) && is_array( $context['cap/author'] ); + + if ( ! $uses_author_context || $has_author_context ) { + return $context; + } + + $author = rest_get_server()->dispatch( + WP_REST_Request::from_url( + home_url( + sprintf( + '/wp-json/coauthor-blocks/v1/coauthor/%s', + get_query_var( 'author_name' ) + ) + ) + ) + )->get_data(); + + if ( ! is_array( $author ) || ! array_key_exists( 'id', $author ) ) { + return $context; + } + + return array( + 'cap/author' => $author + ); +} +add_action( 'render_block_context', 'coauthors_blocks_provide_author_archive_context', 10, 3 ); diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index 128e751a..ecb1f08f 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '50343f52f0fcce0364ee'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'cc8de3fa39ea7b6e07e0'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index f6c5cc99..032c5c50 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){var e,t={371:function(e,t,r){"use strict";var n=window.wp.blocks,o=window.wp.element,a=r(779),i=r.n(a),l=window.wp.i18n,u=window.wp.blockEditor,c=window.wp.components,s={id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"",48:"",96:""}},p=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,n.registerBlockType)(p.u2,{edit:function(e){var t;let{context:r,attributes:n,setAttributes:a}=e;const{isLink:p,rel:f,size:d}=n,v=r["cap/author"]||s,{avatar_urls:h}=v;if(!h||0===h.length)return null;const m=Object.keys(h).map((e=>({value:e,label:`${e} x ${e}`}))),g=(0,u.__experimentalUseBorderProps)(n),b=null!==(t=h[d])&&void 0!==t?t:"";return(0,o.createElement)(o.Fragment,null,(0,o.createElement)("div",(0,u.useBlockProps)(),""===b?(0,o.createElement)(c.Placeholder,{className:i()("block-editor-media-placeholder",g.className),withIllustration:!0,style:{height:d,width:d,minWidth:"auto",minHeight:"auto",padding:0,...g.style}}):(0,o.createElement)("img",{style:{...g.style},width:d,height:d,src:`${h[d]}`})),(0,o.createElement)(u.InspectorControls,null,(0,o.createElement)(c.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,o.createElement)(c.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>a({isLink:!p}),checked:p}),p&&(0,o.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:f,onChange:e=>a({rel:e})}),(0,o.createElement)(c.SelectControl,{label:(0,l.__)("Avatar size"),value:d,options:m,onChange:e=>{a({size:Number(e)})}}))))}})},779:function(e,t){var r;!function(){"use strict";var n={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](r[u])}))?r.splice(u--,1):(l=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[r,o,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,r){var o,a,i=r[0],l=r[1],u=r[2],c=0;if(i.some((function(t){return 0!==e[t]}))){for(o in l)n.o(l,o)&&(n.m[o]=l[o]);if(u)var s=u(n)}for(t&&t(r);ce(u.store).getSettings()),[]),h=n["cap/author"]||d["cap/author-example"],{avatar_urls:g}=h;if(!g||0===g.length)return null;const m=Object.keys(g).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,u.__experimentalUseBorderProps)(r),b=null!==(t=g[v])&&void 0!==t?t:"";return(0,o.createElement)(o.Fragment,null,(0,o.createElement)("div",(0,u.useBlockProps)(),""===b?(0,o.createElement)(c.Placeholder,{className:i()("block-editor-media-placeholder",w.className),withIllustration:!0,style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,...w.style}}):(0,o.createElement)("img",{style:{...w.style},width:v,height:v,src:`${g[v]}`})),(0,o.createElement)(u.InspectorControls,null,(0,o.createElement)(c.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,o.createElement)(c.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>a({isLink:!p}),checked:p}),p&&(0,o.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:f,onChange:e=>a({rel:e})}),(0,o.createElement)(c.SelectControl,{label:(0,l.__)("Avatar size"),value:v,options:m,onChange:e=>{a({size:Number(e)})}}))))}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[u])}))?n.splice(u--,1):(l=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,i=n[0],l=n[1],u=n[2],c=0;if(i.some((function(t){return 0!==e[t]}))){for(o in l)r.o(l,o)&&(r.m[o]=l[o]);if(u)var s=u(r)}for(t&&t(n);c{$content}"; }; } - /** - * Provide Author Archive Context - * - * @param array $context, - * @param array $parsed_block - * @param null|WP_Block $parent_block - * @return array - */ - public static function provide_author_archive_context( array $context, array $parsed_block, ?WP_Block $parent_block ) : array { - if ( ! is_author() ) { - return $context; - } - - if ( null === $parsed_block['blockName'] ) { - return $context; - } - - // author if you do an individual piece of a coauthor outside of a coauthor template. - if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( ! array_key_exists( 'cap/author', $context ) || empty( $context['cap/author'] ) ) ) { - return array( - 'cap/author' => rest_get_server()->dispatch( - WP_REST_Request::from_url( - home_url( - sprintf( - '/wp-json/coauthor-blocks/v1/coauthor/%s', - get_query_var( 'author_name' ) - ) - ) - ) - )->get_data() - ); - } - - return $context; - } } diff --git a/blocks/coauthor-avatar/src/edit.js b/blocks/coauthor-avatar/src/edit.js index 8ace0db4..ea5327d4 100644 --- a/blocks/coauthor-avatar/src/edit.js +++ b/blocks/coauthor-avatar/src/edit.js @@ -1,10 +1,9 @@ import classnames from 'classnames'; import { __ } from '@wordpress/i18n'; -import { useBlockProps, InspectorControls, __experimentalUseBorderProps as useBorderProps } from '@wordpress/block-editor'; +import { useBlockProps, InspectorControls, __experimentalUseBorderProps as useBorderProps, store as blockEditorStore } from '@wordpress/block-editor'; import { Placeholder, SelectControl, PanelBody, ToggleControl, TextControl } from '@wordpress/components'; -import exampleAuthor from '../../modules/example-author'; - +import { useSelect } from '@wordpress/data'; /** * The edit function describes the structure of your block in the context of the * editor. This represents what the editor will render when the block is used. @@ -16,7 +15,8 @@ import exampleAuthor from '../../modules/example-author'; export default function Edit( { context, attributes, setAttributes } ) { const { isLink, rel, size } = attributes; - const author = context['cap/author'] || exampleAuthor; + const settings = useSelect( select => select( blockEditorStore ).getSettings(), []); + const author = context['cap/author'] || settings['cap/author-example']; const { avatar_urls } = author; if ( ! avatar_urls || 0 === avatar_urls.length ) { diff --git a/blocks/coauthor-description/build/index.asset.php b/blocks/coauthor-description/build/index.asset.php index b7485033..b2e69cfc 100644 --- a/blocks/coauthor-description/build/index.asset.php +++ b/blocks/coauthor-description/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n'), 'version' => '31e4e2124cc73f53c0a9'); + array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '5142fd32514d4e6fd0f9'); diff --git a/blocks/coauthor-description/build/index.js b/blocks/coauthor-description/build/index.js index 385c1291..dab51ca5 100644 --- a/blocks/coauthor-description/build/index.js +++ b/blocks/coauthor-description/build/index.js @@ -1 +1 @@ -!function(){var t={779:function(t,e){var r;!function(){"use strict";var n={}.hasOwnProperty;function i(){for(var t=[],e=0;ePlaceholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},l=JSON.parse('{"u2":"cap/coauthor-description"}');(0,t.registerBlockType)(l.u2,{edit:function(t){let{context:r,attributes:o,setAttributes:l}=t;const{textAlign:c}=o,u=r["cap/author"]||s,{description:f}=u;return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(i.BlockControls,null,(0,n.createElement)(i.AlignmentControl,{value:c,onChange:t=>{l({textAlign:t})}})),(0,n.createElement)("div",e({},(0,i.useBlockProps)({className:a()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f}})))}})}()}(); \ No newline at end of file +!function(){var t={779:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var t=[],e=0;et(o.store).getSettings()),[]),p=n["cap/author"]||s["cap/author-example"],{description:f}=p;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(o.BlockControls,null,(0,r.createElement)(o.AlignmentControl,{value:c,onChange:t=>{l({textAlign:t})}})),(0,r.createElement)("div",e({},(0,o.useBlockProps)({className:u()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f}})))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-description/class-cap-block-coauthor-description.php b/blocks/coauthor-description/class-cap-block-coauthor-description.php index 3071eadf..604984c3 100644 --- a/blocks/coauthor-description/class-cap-block-coauthor-description.php +++ b/blocks/coauthor-description/class-cap-block-coauthor-description.php @@ -14,7 +14,6 @@ class CAP_Block_CoAuthor_Description { */ public function __construct() { add_action( 'init', array( __CLASS__, 'register_block' ) ); - add_action( 'render_block_context', array( __CLASS__, 'provide_author_archive_context' ), 10, 3 ); } /** * Register Block @@ -57,42 +56,6 @@ public static function render_block( array $attributes, string $content, WP_Bloc wp_kses_post( wpautop( wptexturize( $description ) ) ) ); } - /** - * Provide Author Archive Context - * - * @param array $context, - * @param array $parsed_block - * @param null|WP_Block $parent_block - * @return array - */ - public static function provide_author_archive_context( array $context, array $parsed_block, ?WP_Block $parent_block ) : array { - if ( ! is_author() ) { - return $context; - } - - if ( null === $parsed_block['blockName'] ) { - return $context; - } - - // author if you do an individual piece of a coauthor outside of a coauthor template. - if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( ! array_key_exists( 'cap/author', $context ) || empty( $context['cap/author'] ) ) ) { - return array( - 'cap/author' => rest_get_server()->dispatch( - WP_REST_Request::from_url( - home_url( - sprintf( - '/wp-json/coauthor-blocks/v1/coauthor/%s', - get_query_var( 'author_name' ) - ) - ) - ) - )->get_data() - ); - } - - return $context; - } - /** * Get Custom Block Wrapper Attributes * diff --git a/blocks/coauthor-description/src/edit.js b/blocks/coauthor-description/src/edit.js index 6e2d6ba9..4f014d7b 100644 --- a/blocks/coauthor-description/src/edit.js +++ b/blocks/coauthor-description/src/edit.js @@ -4,10 +4,10 @@ * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ -import { useBlockProps, AlignmentControl, BlockControls } from '@wordpress/block-editor'; +import { useBlockProps, AlignmentControl, BlockControls, store as blockEditorStore } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; +import { useSelect } from '@wordpress/data'; import classnames from 'classnames'; -import exampleAuthor from '../../modules/example-author'; import './editor.css'; /** @@ -21,7 +21,8 @@ import './editor.css'; export default function Edit( { context, attributes, setAttributes } ) { const { textAlign } = attributes; - const author = context['cap/author'] || exampleAuthor; + const settings = useSelect( select => select( blockEditorStore ).getSettings(), []); + const author = context['cap/author'] || settings['cap/author-example']; const { description } = author; return ( diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index d8b0cb1e..f0f5c953 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '4a6ee27d24c59530577e'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'df069a45e247f93fe52e'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index d4cf7611..fb080753 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function i(){for(var e=[],t=0;tPlaceholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},c=JSON.parse('{"u2":"cap/coauthor-display-name"}');(0,e.registerBlockType)(c.u2,{edit:function(e){let{context:n,attributes:a,setAttributes:c}=e;const{isLink:u,rel:f,textAlign:g}=a,p=n["cap/author"]||s,{link:h,display_name:d}=p;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:g,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:l()({[`has-text-align-${g}`]:g})}),u?(0,t.createElement)("a",{href:h,rel:f,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(i.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(i.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>c({isLink:!u}),checked:u}),u&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:f,onChange:e=>c({rel:e})})))))}})}()}(); \ No newline at end of file +!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;te(r.store).getSettings()),[]),m=n["cap/author"]||g["cap/author-example"],{link:d,display_name:w}=m;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:f,onChange:e=>{u({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:c()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:d,rel:p,onClick:e=>e.preventDefault()},w):w),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,a.__)("Settings")},(0,t.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Make coauthor name a link"),onChange:()=>u({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(o.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:p,onChange:e=>u({rel:e})})))))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index b5f14420..0d3062b7 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -14,7 +14,6 @@ class CAP_Block_CoAuthor_Display_Name { */ public function __construct() { add_action( 'init', array( __CLASS__, 'register_block' ) ); - add_action( 'render_block_context', array( __CLASS__, 'provide_author_archive_context' ), 10, 3 ); } /** * Register Block @@ -73,41 +72,6 @@ public static function render_block( array $attributes, string $content, WP_Bloc $inner_content ); } - /** - * Provide Author Archive Context - * - * @param array $context, - * @param array $parsed_block - * @param null|WP_Block $parent_block - * @return array - */ - public static function provide_author_archive_context( array $context, array $parsed_block, ?WP_Block $parent_block ) : array { - if ( ! is_author() ) { - return $context; - } - - if ( null === $parsed_block['blockName'] ) { - return $context; - } - - // author if you do an individual piece of a coauthor outside of a coauthor template. - if ( 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ) && ( ! array_key_exists( 'cap/author', $context ) || empty( $context['cap/author'] ) ) ) { - return array( - 'cap/author' => rest_get_server()->dispatch( - WP_REST_Request::from_url( - home_url( - sprintf( - '/wp-json/coauthor-blocks/v1/coauthor/%s', - get_query_var( 'author_name' ) - ) - ) - ) - )->get_data() - ); - } - - return $context; - } /** * Get Custom Block Wrapper Attributes diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index 8ca2562b..01a4383a 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -4,11 +4,17 @@ * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ -import { useBlockProps, InspectorControls, AlignmentControl, BlockControls } from '@wordpress/block-editor'; +import { + useBlockProps, + InspectorControls, + AlignmentControl, + BlockControls, + store as blockEditorStore +} from '@wordpress/block-editor'; import { TextControl, PanelBody, ToggleControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; +import { useSelect } from '@wordpress/data'; import classnames from 'classnames'; -import exampleAuthor from '../../modules/example-author'; /** * The edit function describes the structure of your block in the context of the @@ -21,7 +27,8 @@ import exampleAuthor from '../../modules/example-author'; export default function Edit( { context, attributes, setAttributes } ) { const { isLink, rel, textAlign } = attributes; - const author = context['cap/author'] || exampleAuthor; + const settings = useSelect( select => select( blockEditorStore ).getSettings(), []); + const author = context['cap/author'] || settings['cap/author-example']; const { link, display_name } = author; return ( diff --git a/blocks/coauthor-feature-image/build/block.json b/blocks/coauthor-feature-image/build/block.json index 72737791..7eb660b7 100644 --- a/blocks/coauthor-feature-image/build/block.json +++ b/blocks/coauthor-feature-image/build/block.json @@ -19,7 +19,7 @@ "color": true, "radius": true, "width": true, - "__experimentalSelector": "img, .block-editor-media-placeholder, .wp-block-post-featured-image__overlay", + "__experimentalSelector": "img, .block-editor-media-placeholder", "__experimentalSkipSerialization": true, "__experimentalDefaultControls": { "color": false, diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php index ce95d0ec..74a39779 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'cb612ea4f09ae72ae63b'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'e22af9ba3598360523fb'); diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js index 960f99cf..de14074f 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-feature-image/build/index.js @@ -1,3 +1,3 @@ -!function(){var e,t={969:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,i=l(779),o=l.n(i),r=window.wp.i18n,s=window.wp.blockEditor,c=window.wp.components,u=window.wp.data,m=window.wp.coreData;const d=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),h="cover",p={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var g=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:i,scale:o,sizeSlug:u},setAttributes:m,imageSizeOptions:g=[]}=e;const _=(0,c.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),f=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||m({[e]:l<0?"0":t})},v=(0,r._x)("Scale","Image scaling options"),w=i||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>m({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>m({aspectRatio:e})})),(0,a.createElement)(c.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!i,label:(0,r.__)("Height"),onDeselect:()=>m({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:i||"",min:0,onChange:e=>f("height",e),units:_})),(0,a.createElement)(c.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>m({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>f("width",e),units:_})),w&&(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!o&&o!==h,label:v,onDeselect:()=>m({scale:h}),resetAllFilter:()=>({scale:h}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:v,value:o,help:p[o],onChange:e=>m({scale:e}),isBlock:!0},d)),!!g.length&&(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!u,label:(0,r.__)("Resolution"),onDeselect:()=>m({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(c.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:u||"full",options:g,onChange:e=>m({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))},_={id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}},f=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(f.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:i,clientId:d}=e;const{isLink:h,rel:p,width:f,height:v,aspectRatio:w,sizeSlug:x,scale:b}=l,D=i["cap/author"]||_,E=(0,u.useSelect)((e=>0!==D.featured_media&&e(m.store).getMedia(D.featured_media,{context:"view"})),[D.featured_media]),C=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(E,x),{imageSizes:F,imageDimensions:y}=(0,u.useSelect)((e=>e(s.store).getSettings()),[]),S=F.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),I=(0,s.__experimentalUseBorderProps)(l),k={...I.style,height:w?"100%":v,width:!!w&&"100%",objectFit:!(!v&&!w)&&b},O=null===(t=y[x])||void 0===t?void 0:t.width,B=f||v,A=(0,s.useBlockProps)({style:{width:B?f:O,height:v,aspectRatio:w}});return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(g,{clientId:d,attributes:l,setAttributes:n,imageSizeOptions:S}),(0,a.createElement)("figure",A,E?(0,a.createElement)("img",{src:C,alt:E.alt_text?sprintf( +!function(){var e,t={249:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=l(779),i=l.n(o),r=window.wp.i18n,s=window.wp.blockEditor,u=window.wp.components,c=window.wp.data,p=window.wp.coreData;const m=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),_="cover",d={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var h=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:o,scale:i,sizeSlug:c},setAttributes:p,imageSizeOptions:h=[]}=e;const g=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),b=o||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:o||"",min:0,onChange:e=>v("height",e),units:g})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:g})),b&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==_,label:f,onDeselect:()=>p({scale:_}),resetAllFilter:()=>({scale:_}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:d[i],onChange:e=>p({scale:e}),isBlock:!0},m)),!!h.length&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:h,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))};(0,window.wp.hooks.applyFilters)("cap.settings.exampleAuthor",{id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"",48:"",96:""}});var g=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(g.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:o,clientId:m}=e;const{isLink:_,rel:d,width:g,height:v,aspectRatio:f,sizeSlug:b,scale:w}=l,{imageSizes:x,imageDimensions:S,...y}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),E=o["cap/author"]||y.co_authors_plus_example_author,C=(0,c.useSelect)((e=>0!==E.featured_media&&e(p.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),I=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(C,b),k=x.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=(0,s.__experimentalUseBorderProps)(l),B={...O.style,height:f?"100%":v,width:!!f&&"100%",objectFit:!(!v&&!f)&&w},P=null===(t=S[b])||void 0===t?void 0:t.width,F=g||v,A=(0,s.useBlockProps)({style:{width:F?g:P,height:v,aspectRatio:f}});return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(h,{clientId:m,attributes:l,setAttributes:n,imageSizeOptions:k}),(0,a.createElement)("figure",A,C?(0,a.createElement)("img",{src:I,alt:C.alt_text?sprintf( // translators: %s: The image's alt text. -(0,r.__)("Featured image: %s"),E.alt_text):(0,r.__)("Featured image"),style:k}):(0,a.createElement)(c.Placeholder,{className:o()("block-editor-media-placeholder",I.className),withIllustration:!0,style:{height:!!w&&"100%",width:!!w&&"100%",minWidth:"auto",minHeight:"auto",...I.style}})),(0,a.createElement)(s.InspectorControls,null,(0,a.createElement)(c.PanelBody,{title:(0,r.__)("Settings")},(0,a.createElement)(c.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make feature image a link to author archive."),onChange:()=>n({isLink:!h}),checked:h}),h&&(0,a.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:p,onChange:e=>n({rel:e})}))))},save:function(){return(0,a.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=i)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[l,a,i]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,i,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var u=s(n)}for(t&&t(l);cn({isLink:!_}),checked:_}),_&&(0,a.createElement)(u.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:d,onChange:e=>n({rel:e})}))))},save:function(){return(0,a.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[c-1][2]>o;c--)e[c]=e[c-1];e[c]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var c=s(n)}for(t&&t(l);u rest_get_server()->dispatch( - WP_REST_Request::from_url( - home_url( - sprintf( - '/wp-json/coauthor-blocks/v1/coauthor/%s', - get_query_var( 'author_name' ) - ) - ) - ) - )->get_data() - ); - } - - return $context; - } } diff --git a/blocks/coauthor-feature-image/src/edit.js b/blocks/coauthor-feature-image/src/edit.js index 116660b7..68db996e 100644 --- a/blocks/coauthor-feature-image/src/edit.js +++ b/blocks/coauthor-feature-image/src/edit.js @@ -14,7 +14,6 @@ import { store as coreStore } from '@wordpress/core-data'; import './editor.scss'; import DimensionControls from './dimension-controls'; -import exampleAuthor from '../../modules/example-author'; /** * @@ -37,7 +36,12 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) const { isLink, rel, width, height, aspectRatio, sizeSlug, scale } = attributes; - const author = context['cap/author'] || exampleAuthor; + const { imageSizes, imageDimensions, ...settings } = useSelect( + ( select ) => select( blockEditorStore ).getSettings(), + [] + ); + + const author = context['cap/author'] || settings['cap/author-example']; const media = useSelect( (select) => { return 0 !== author.featured_media && select( coreStore ).getMedia( author.featured_media, { context: 'view' } ) @@ -45,11 +49,6 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) const mediaUrl = getMediaSourceUrlBySizeSlug( media, sizeSlug ); - const { imageSizes, imageDimensions } = useSelect( - ( select ) => select( blockEditorStore ).getSettings(), - [] - ); - const imageSizeOptions = imageSizes.map( ( { name, slug } ) => ( { value: slug, label: name } ) ); diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index 1bafbb27..babdf068 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '3494ebb2ec574dd7495c'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '7395abd96d84c23f07d2'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index 56ccfbe0..953bf78a 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={125:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,h=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),f=n(779),v=n.n(f);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))})),w={id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%225%22%3E24x24%3C%2Ftext%3E%3C%2Fsvg%3E",48:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2248%22%20height%3D%2248%22%20viewBox%3D%220%200%2048%2048%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2248%22%20height%3D%2248%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2210%22%3E48x48%3C%2Ftext%3E%3C%2Fsvg%3E",96:"data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2296%22%20height%3D%2296%22%20viewBox%3D%220%200%2096%2096%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2296%22%20height%3D%2296%22%20fill%3D%22%23eeeeee%22%3E%3C%2Frect%3E%3Ctext%20fill%3D%22%23111111%22%20font-family%3D%22sans-serif%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20text-anchor%3D%22middle%22%20font-size%3D%2219%22%3E96x96%3C%2Ftext%3E%3C%2Fsvg%3E"}};function x(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var b=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(b.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:f,isSelected:m}=e;const{prefix:b,separator:E,lastSeparator:C,suffix:k,layout:D,textAlign:_}=o,{postId:F}=f,[S,A]=(0,r.useState)([w]),[B,O]=(0,r.useState)(),P=(0,s.useDispatch)("core/notices");function N(e){"AbortError"!==e.name&&P.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!F)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${F}/`,signal:e.signal}).then(A).catch(N),()=>{e.abort()}}),[F]);const z=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),I=e=>{i({layout:{...D,...e}})},V=[{icon:h,title:(0,u.__)("Inline"),onClick:()=>I({type:"inline"}),isActive:"inline"===D.type},{icon:d,title:(0,u.__)("Block"),onClick:()=>I({type:"block"}),isActive:"block"===D.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:V}),(0,r.createElement)(a.AlignmentControl,{value:_,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:v()({[`is-layout-cap-${D.type}`]:D.type,[`has-text-align-${_}`]:_}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),S&&"inline"===D.type&&(m||b)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:b,onChange:e=>i({prefix:e}),tagName:"span"}),S&&S.map((e=>{var t;const n=e.id===(B||(null===(t=S[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(x,null):null,(0,r.createElement)(g,{blocks:z,blockContextId:e.id,setActiveBlockContextId:O,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===D.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},C&&n===o.length-1?`${C}`:`${E}`),t))),S&&"inline"===D.type&&(m||k)&&(0,r.createElement)(a.RichText,{allowedFormats:y,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:k,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===D.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:E||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:C||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=v()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function g(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const w=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:d,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=o,{postId:S}=d,O=(0,s.useSelect)((e=>e(a.store).getSettings()),[]),[B,A]=(0,r.useState)([O["cap/author-example"]]),[P,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(A).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...E,...e}})},G=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:G}),(0,r.createElement)(a.AlignmentControl,{value:C,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:h()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),B&&"inline"===E.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:w,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),B&&B.map((e=>{var t;const n=e.id===(P||(null===(t=B[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},k&&n===o.length-1?`${k}`:`${x}`),t))),B&&"inline"===E.type&&(m||_)&&(0,r.createElement)(a.RichText,{allowedFormats:w,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:x||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:k||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=h()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s select( blockEditorStore ).getSettings(), []); + const [ coAuthors, setCoAuthors ] = useState([ settings['cap/author-example']]); const [ activeBlockContextId, setActiveBlockContextId ] = useState(); const noticesDispatch = useDispatch('core/notices'); diff --git a/blocks/modules/example-author.js b/blocks/modules/example-author.js deleted file mode 100644 index 71233234..00000000 --- a/blocks/modules/example-author.js +++ /dev/null @@ -1,12 +0,0 @@ -export default { - id: 0, - display_name: 'FirstName LastName', - description: '

Placeholder description from Co-Authors block.

', - link: '#', - featured_media: 0, - avatar_urls: { - 24: '', - 48: '', - 96: '' - } -}; From 2ce029c110171ea5f16c2f7e6614dd9e7dee5496 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 11 Aug 2023 10:41:17 -0400 Subject: [PATCH 044/123] start using schema for api responses --- .../class-cap-block-coauthor-description.php | 2 +- .../class-coauthor-blocks-controller.php | 166 ++++++++++++++---- 2 files changed, 136 insertions(+), 32 deletions(-) diff --git a/blocks/coauthor-description/class-cap-block-coauthor-description.php b/blocks/coauthor-description/class-cap-block-coauthor-description.php index 604984c3..e0c7554f 100644 --- a/blocks/coauthor-description/class-cap-block-coauthor-description.php +++ b/blocks/coauthor-description/class-cap-block-coauthor-description.php @@ -42,7 +42,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc return ''; } - $description = $author['description'] ?? ''; + $description = $author['description']['raw'] ?? ''; if ( '' === $description ) { return ''; diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index 8a5aa541..364404cc 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -197,6 +197,105 @@ public function get_items_permission_check( WP_REST_Request $request ) : bool|WP ); } + /** + * Retrieves the CoAuthor schema, conforming to JSON Schema. + * + * @return array Item schema data. + */ + public function get_item_schema() : array { + + if ( $this->schema ) { + return $this->add_additional_fields_schema( $this->schema ); + } + + $schema = array( + '$schema' => 'http://json-schema.org/draft-04/schema#', + 'title' => 'coauthor-block', + 'type' => 'object', + 'properties' => array( + 'id' => array( + 'description' => __( '', 'co-authors-plus' ), + 'type' => 'integer', + 'context' => array( 'view' ), + 'readonly' => true + ), + 'display_name' => array( + 'description' => __( '', 'co-authors-plus' ), + 'type' => 'string', + 'context' => array( 'view' ), + 'readonly' => true + ), + 'description' => array( + 'description' => __( '', 'co-authors-plus' ), + 'type' => 'object', + 'context' => array( 'view' ), + 'readonly' => true, + 'properties' => array( + 'raw' => array( + 'description' => __( '', 'co-authors-plus' ), + 'type' => 'string', + 'context' => array( 'view' ), + 'readonly' => true, + ), + 'rendered' => array( + 'description' => __( '', 'co-authors-plus' ), + 'type' => 'string', + 'context' => array( 'view' ), + 'readonly' => true, + ) + ) + ), + 'user_nicename' => array( + 'description' => __( '', 'co-authors-plus' ), + 'type' => 'string', + 'context' => array( 'view' ), + 'readonly' => true + ), + 'link' => array( + 'description' => __( 'URL of author archive.', 'co-authors-plus' ), + 'type' => 'string', + 'context' => array( 'view' ), + 'readonly' => true + ), + 'avatar_urls' => array( + 'description' => __( '', 'co-authors-plus' ), + 'type' => 'object', + 'context' => array( 'view' ), + 'readonly' => true, + ), + 'featured_media' => array( + 'description' => __( '', 'co-authors-plus' ), + 'type' => 'integer', + 'context' => array( 'view' ), + 'readonly' => true, + ) + ) + ); + + // Take a snapshot of which fields are in the schema pre-filtering. + $schema_fields = array_keys( $schema['properties'] ); + + $schema = apply_filters( 'rest_coauthor-block_item_schema', $schema ); + + // Emit a _doing_it_wrong warning if user tries to add new properties using this filter. + $new_fields = array_diff( array_keys( $schema['properties'] ), $schema_fields ); + if ( count( $new_fields ) > 0 ) { + _doing_it_wrong( + __METHOD__, + sprintf( + /* translators: %s: register_rest_field */ + __( 'Please use %s to add new schema properties.' ), + 'register_rest_field' + ), + '5.4.0' + ); + } + + $this->schema = $schema; + + return $this->add_additional_fields_schema( $this->schema ); + } + /** * Prepare Item For Response * @@ -206,44 +305,49 @@ public function get_items_permission_check( WP_REST_Request $request ) : bool|WP */ public function prepare_item_for_response( $author, $request ) : WP_REST_Response|WP_Error { + $fields = $this->get_fields_for_response( $request ); + if ( is_a( $author, 'WP_User' ) ) { - $author = $author->data; + $author = $author->data; + $author->description = get_user_meta( $author->ID, 'description', true ); } - $disallowed = array( - 'ID', - 'linked_account', - 'user_email', - 'user_login', - 'user_pass', - 'user_registered', - 'user_activation_key', - 'user_url', - 'user_status', - 'type' - ); + $data = array(); - $data = array_diff_key( - (array) $author, - array_flip( $disallowed ) - ); + if ( rest_is_field_included( 'id', $fields ) ) { + $data['id'] = (int) $author->ID; + } - $data['id'] = $author->ID; - $data['link'] = get_author_posts_url( $author->ID, $author->user_nicename ); - $data['avatar_urls'] = rest_get_avatar_urls( $author->ID ); + if ( rest_is_field_included( 'avatar_urls', $fields ) ) { + $data['avatar_urls'] = rest_get_avatar_urls( $author->ID ); + } - if ( 'wpuser' === $author->type ) { - if ( ! array_key_exists( 'description', $data ) ) { - $data['description'] = wp_kses_post( wpautop( wptexturize( get_user_meta( $author->ID, 'description', true ) ) ) ); - } + if ( rest_is_field_included( 'description', $fields ) ) { + $data['description'] = array(); } - if ( 'guest-author' === $author->type ) { - $data['featured_media'] = absint( - get_post_thumbnail_id( $author->ID ) - ); - } else { - $data['featured_media'] = 0; + if ( rest_is_field_included( 'description.raw', $fields ) ) { + $data['description']['raw'] = (string) $author->description; + } + + if ( rest_is_field_included( 'description.rendered', $fields ) ) { + $data['description']['rendered'] = wp_kses_post( wpautop( wptexturize( (string) $author->description ) ) ); + } + + if ( rest_is_field_included( 'display_name', $fields ) ) { + $data['display_name'] = (string) $author->display_name; + } + + if ( rest_is_field_included( 'link', $fields ) ) { + $data['link'] = (string) get_author_posts_url( $author->ID, $author->user_nicename ); + } + + if ( rest_is_field_included( 'featured_media', $fields ) ) { + $data['featured_media'] = (integer) ( 'guest-author' === $author->type ? get_post_thumbnail_id( $author->ID ) : 0 ); + } + + if ( rest_is_field_included( 'user_nicename', $fields ) ) { + $data['user_nicename'] = (string) $author->user_nicename; } $response = rest_ensure_response( $data ); @@ -256,6 +360,6 @@ public function prepare_item_for_response( $author, $request ) : WP_REST_Respons * @param stdClass|WP_User $author * @param WP_REST_Request $request Request object. */ - return apply_filters( "rest_prepare_coauthor_block", $response, $author, $request ); + return apply_filters( 'rest_prepare_coauthor-block', $response, $author, $request ); } } From 984e92c16945c8c3f310e02ff5ebc47593d2b425 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 11 Aug 2023 10:42:03 -0400 Subject: [PATCH 045/123] use custom store instead of block editor settings --- blocks/blocks.php | 57 ++++++++++++------- blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- .../build/index.asset.php | 2 +- blocks/coauthor-description/build/index.js | 2 +- blocks/coauthor-description/src/edit.js | 6 +- .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- blocks/coauthor-display-name/src/edit.js | 4 +- .../build/index.asset.php | 2 +- blocks/coauthor-feature-image/build/index.js | 4 +- blocks/coauthor-feature-image/src/edit.js | 8 ++- blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- blocks/coauthors/src/edit.js | 4 +- blocks/store/build/index.asset.php | 1 + blocks/store/build/index.js | 1 + blocks/store/package.json | 5 ++ blocks/store/src/index.js | 13 +++++ 19 files changed, 81 insertions(+), 40 deletions(-) create mode 100644 blocks/store/build/index.asset.php create mode 100644 blocks/store/build/index.js create mode 100644 blocks/store/package.json create mode 100644 blocks/store/src/index.js diff --git a/blocks/blocks.php b/blocks/blocks.php index f2630c5d..5305fedf 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -11,25 +11,6 @@ new CAP_Block_CoAuthor_Display_Name(); new CAP_Block_CoAuthor_Feature_Image(); -add_filter( - 'block_editor_settings_all', - function( array $editor_settings ) : array { - return array_merge( - $editor_settings, - array( - 'cap/author-example' => array( - 'id' => 0, - 'display_name' => 'FirstName LastName', - 'description' => '

Placeholder description from Co-Authors block.

', - 'link' => '#', - 'featured_media' => 0, - 'avatar_urls' => array_map( '__return_empty_string', array_flip( rest_get_avatar_sizes() ) ) - ) - ) - ); - } -); - /** * Provide Author Archive Context * @@ -79,3 +60,41 @@ function coauthors_blocks_provide_author_archive_context( array $context, array ); } add_action( 'render_block_context', 'coauthors_blocks_provide_author_archive_context', 10, 3 ); + +/** + * Enqueue Store + */ +function coauthors_blocks_enqueue_store() : void { + $asset = require_once dirname( __FILE__ ) . '/store/build/index.asset.php'; + + wp_enqueue_script( + 'coauthors-blocks-store', + plugins_url( '/store/build/index.js', __FILE__ ), + $asset['dependencies'], + $asset['version'] + ); + + $data = apply_filters( + 'coauthor_blocks_store_data', + array( + 'authorPlaceholder' => array( + 'id' => 0, + 'display_name' => 'FirstName LastName', + 'description' => array( + 'raw' => 'Placeholder description from Co-Authors block.', + 'rendered' => '

Placeholder description from Co-Authors block.

' + ), + 'link' => '#', + 'featured_media' => 0, + 'avatar_urls' => array_map( '__return_empty_string', array_flip( rest_get_avatar_sizes() ) ) + ) + ) + ); + + wp_localize_script( + 'coauthors-blocks-store', + 'coAuthorsBlocks', + $data + ); +} +add_action( 'enqueue_block_editor_assets', 'coauthors_blocks_enqueue_store' ); diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index ecb1f08f..e923096f 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'cc8de3fa39ea7b6e07e0'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '31d4185601de4d83966b'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index 032c5c50..a208fb62 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){var e,t={631:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,a=n(779),i=n.n(a),l=window.wp.i18n,u=window.wp.blockEditor,c=window.wp.components,s=window.wp.data,p=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,r.registerBlockType)(p.u2,{edit:function(e){var t;let{context:n,attributes:r,setAttributes:a}=e;const{isLink:p,rel:f,size:v}=r,d=(0,s.useSelect)((e=>e(u.store).getSettings()),[]),h=n["cap/author"]||d["cap/author-example"],{avatar_urls:g}=h;if(!g||0===g.length)return null;const m=Object.keys(g).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,u.__experimentalUseBorderProps)(r),b=null!==(t=g[v])&&void 0!==t?t:"";return(0,o.createElement)(o.Fragment,null,(0,o.createElement)("div",(0,u.useBlockProps)(),""===b?(0,o.createElement)(c.Placeholder,{className:i()("block-editor-media-placeholder",w.className),withIllustration:!0,style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,...w.style}}):(0,o.createElement)("img",{style:{...w.style},width:v,height:v,src:`${g[v]}`})),(0,o.createElement)(u.InspectorControls,null,(0,o.createElement)(c.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,o.createElement)(c.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>a({isLink:!p}),checked:p}),p&&(0,o.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:f,onChange:e=>a({rel:e})}),(0,o.createElement)(c.SelectControl,{label:(0,l.__)("Avatar size"),value:v,options:m,onChange:e=>{a({size:Number(e)})}}))))}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[u])}))?n.splice(u--,1):(l=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,i=n[0],l=n[1],u=n[2],c=0;if(i.some((function(t){return 0!==e[t]}))){for(o in l)r.o(l,o)&&(r.m[o]=l[o]);if(u)var s=u(r)}for(t&&t(n);ce("cap/blocks").getAuthorPlaceholder()),[]),h=n["cap/author"]||d,{avatar_urls:g}=h;if(!g||0===g.length)return null;const m=Object.keys(g).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,u.__experimentalUseBorderProps)(r),b=null!==(t=g[v])&&void 0!==t?t:"";return(0,o.createElement)(o.Fragment,null,(0,o.createElement)("div",(0,u.useBlockProps)(),""===b?(0,o.createElement)(c.Placeholder,{className:i()("block-editor-media-placeholder",w.className),withIllustration:!0,style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,...w.style}}):(0,o.createElement)("img",{style:{...w.style},width:v,height:v,src:`${g[v]}`})),(0,o.createElement)(u.InspectorControls,null,(0,o.createElement)(c.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,o.createElement)(c.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>a({isLink:!p}),checked:p}),p&&(0,o.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:f,onChange:e=>a({rel:e})}),(0,o.createElement)(c.SelectControl,{label:(0,l.__)("Avatar size"),value:v,options:m,onChange:e=>{a({size:Number(e)})}}))))}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[u])}))?n.splice(u--,1):(l=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,i=n[0],l=n[1],u=n[2],c=0;if(i.some((function(t){return 0!==e[t]}))){for(o in l)r.o(l,o)&&(r.m[o]=l[o]);if(u)var s=u(r)}for(t&&t(n);c array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '5142fd32514d4e6fd0f9'); + array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'c349c7f5f5253a0c7e21'); diff --git a/blocks/coauthor-description/build/index.js b/blocks/coauthor-description/build/index.js index dab51ca5..d71cce83 100644 --- a/blocks/coauthor-description/build/index.js +++ b/blocks/coauthor-description/build/index.js @@ -1 +1 @@ -!function(){var t={779:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var t=[],e=0;et(o.store).getSettings()),[]),p=n["cap/author"]||s["cap/author-example"],{description:f}=p;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(o.BlockControls,null,(0,r.createElement)(o.AlignmentControl,{value:c,onChange:t=>{l({textAlign:t})}})),(0,r.createElement)("div",e({},(0,o.useBlockProps)({className:u()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f}})))}})}()}(); \ No newline at end of file +!function(){var t={779:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var t=[],e=0;et("cap/blocks").getAuthorPlaceholder()),[]),p=n["cap/author"]||s,{description:f}=p;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(o.BlockControls,null,(0,r.createElement)(o.AlignmentControl,{value:c,onChange:t=>{l({textAlign:t})}})),(0,r.createElement)("div",e({},(0,o.useBlockProps)({className:u()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f.rendered}})))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-description/src/edit.js b/blocks/coauthor-description/src/edit.js index 4f014d7b..4fc6207c 100644 --- a/blocks/coauthor-description/src/edit.js +++ b/blocks/coauthor-description/src/edit.js @@ -21,8 +21,8 @@ import './editor.css'; export default function Edit( { context, attributes, setAttributes } ) { const { textAlign } = attributes; - const settings = useSelect( select => select( blockEditorStore ).getSettings(), []); - const author = context['cap/author'] || settings['cap/author-example']; + const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); + const author = context['cap/author'] || authorPlaceholder; const { description } = author; return ( @@ -44,7 +44,7 @@ export default function Edit( { context, attributes, setAttributes } ) { }) }) } - dangerouslySetInnerHTML={ { __html: description } } + dangerouslySetInnerHTML={ { __html: description.rendered } } /> ); diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index f0f5c953..c84d6307 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'df069a45e247f93fe52e'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'b0522d9b4feffa65c1b3'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index fb080753..5e87fd92 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;te(r.store).getSettings()),[]),m=n["cap/author"]||g["cap/author-example"],{link:d,display_name:w}=m;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:f,onChange:e=>{u({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:c()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:d,rel:p,onClick:e=>e.preventDefault()},w):w),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,a.__)("Settings")},(0,t.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Make coauthor name a link"),onChange:()=>u({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(o.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:p,onChange:e=>u({rel:e})})))))}})}()}(); \ No newline at end of file +!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),d=n["cap/author"]||g,{link:m,display_name:w}=d;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:f,onChange:e=>{u({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:c()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:m,rel:p,onClick:e=>e.preventDefault()},w):w),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,l.__)("Settings")},(0,t.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make coauthor name a link"),onChange:()=>u({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(o.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:p,onChange:e=>u({rel:e})})))))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index 01a4383a..19c6df7f 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -27,8 +27,8 @@ import classnames from 'classnames'; export default function Edit( { context, attributes, setAttributes } ) { const { isLink, rel, textAlign } = attributes; - const settings = useSelect( select => select( blockEditorStore ).getSettings(), []); - const author = context['cap/author'] || settings['cap/author-example']; + const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); + const author = context['cap/author'] || authorPlaceholder; const { link, display_name } = author; return ( diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php index 74a39779..de6f36b7 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'e22af9ba3598360523fb'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '73797188219d475e8fb0'); diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js index de14074f..62b3b07c 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-feature-image/build/index.js @@ -1,3 +1,3 @@ -!function(){var e,t={249:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=l(779),i=l.n(o),r=window.wp.i18n,s=window.wp.blockEditor,u=window.wp.components,c=window.wp.data,p=window.wp.coreData;const m=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(u.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),_="cover",d={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var h=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:o,scale:i,sizeSlug:c},setAttributes:p,imageSizeOptions:h=[]}=e;const g=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),b=o||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:o||"",min:0,onChange:e=>v("height",e),units:g})),(0,a.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:g})),b&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==_,label:f,onDeselect:()=>p({scale:_}),resetAllFilter:()=>({scale:_}),isShownByDefault:!0,panelId:t},(0,a.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:d[i],onChange:e=>p({scale:e}),isBlock:!0},m)),!!h.length&&(0,a.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:h,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))};(0,window.wp.hooks.applyFilters)("cap.settings.exampleAuthor",{id:0,display_name:"FirstName LastName",description:"

Placeholder description from Co-Authors block.

",link:"#",featured_media:0,avatar_urls:{24:"",48:"",96:""}});var g=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(g.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:o,clientId:m}=e;const{isLink:_,rel:d,width:g,height:v,aspectRatio:f,sizeSlug:b,scale:w}=l,{imageSizes:x,imageDimensions:S,...y}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),E=o["cap/author"]||y.co_authors_plus_example_author,C=(0,c.useSelect)((e=>0!==E.featured_media&&e(p.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),I=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(C,b),k=x.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=(0,s.__experimentalUseBorderProps)(l),B={...O.style,height:f?"100%":v,width:!!f&&"100%",objectFit:!(!v&&!f)&&w},P=null===(t=S[b])||void 0===t?void 0:t.width,F=g||v,A=(0,s.useBlockProps)({style:{width:F?g:P,height:v,aspectRatio:f}});return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(h,{clientId:m,attributes:l,setAttributes:n,imageSizeOptions:k}),(0,a.createElement)("figure",A,C?(0,a.createElement)("img",{src:I,alt:C.alt_text?sprintf( +!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,o=window.wp.element,a=l(779),i=l.n(a),r=window.wp.i18n,s=window.wp.blockEditor,u=window.wp.components,c=window.wp.data,p=window.wp.coreData;const m=(0,o.createElement)(o.Fragment,null,(0,o.createElement)(u.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,o.createElement)(u.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,o.createElement)(u.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),_="cover",d={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var g=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:a,scale:i,sizeSlug:c},setAttributes:p,imageSizeOptions:g=[]}=e;const h=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),b=a||l&&"auto"!==l;return(0,o.createElement)(s.InspectorControls,{group:"dimensions"},(0,o.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,o.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,o.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!a,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,o.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:a||"",min:0,onChange:e=>v("height",e),units:h})),(0,o.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,o.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:h})),b&&(0,o.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==_,label:f,onDeselect:()=>p({scale:_}),resetAllFilter:()=>({scale:_}),isShownByDefault:!0,panelId:t},(0,o.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:d[i],onChange:e=>p({scale:e}),isBlock:!0},m)),!!g.length&&(0,o.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,o.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:g,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))},h=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(h.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:a,clientId:m}=e;const{isLink:_,rel:d,width:h,height:v,aspectRatio:f,sizeSlug:b,scale:w}=l,x=(0,c.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),S=a["cap/author"]||x,{imageSizes:E,imageDimensions:y}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),C=(0,c.useSelect)((e=>0!==S.featured_media&&e(p.store).getMedia(S.featured_media,{context:"view"})),[S.featured_media]),I=function(e,t){var l,n,o;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(o=n[t])||void 0===o?void 0:o.source_url)||(null==e?void 0:e.source_url)}(C,b),O=E.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),k=(0,s.__experimentalUseBorderProps)(l),B={...k.style,height:f?"100%":v,width:!!f&&"100%",objectFit:!(!v&&!f)&&w},P=null===(t=y[b])||void 0===t?void 0:t.width,A=h||v,F=(0,s.useBlockProps)({style:{width:A?h:P,height:v,aspectRatio:f}});return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(g,{clientId:m,attributes:l,setAttributes:n,imageSizeOptions:O}),(0,o.createElement)("figure",F,C?(0,o.createElement)("img",{src:I,alt:C.alt_text?sprintf( // translators: %s: The image's alt text. -(0,r.__)("Featured image: %s"),C.alt_text):(0,r.__)("Featured image"),style:B}):(0,a.createElement)(u.Placeholder,{className:i()("block-editor-media-placeholder",O.className),withIllustration:!0,style:{height:!!f&&"100%",width:!!f&&"100%",minWidth:"auto",minHeight:"auto",...O.style}})),(0,a.createElement)(s.InspectorControls,null,(0,a.createElement)(u.PanelBody,{title:(0,r.__)("Settings")},(0,a.createElement)(u.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make feature image a link to author archive."),onChange:()=>n({isLink:!_}),checked:_}),_&&(0,a.createElement)(u.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:d,onChange:e=>n({rel:e})}))))},save:function(){return(0,a.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[c-1][2]>o;c--)e[c]=e[c-1];e[c]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var c=s(n)}for(t&&t(l);un({isLink:!_}),checked:_}),_&&(0,o.createElement)(u.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:d,onChange:e=>n({rel:e})}))))},save:function(){return(0,o.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,a0&&e[c-1][2]>a;c--)e[c]=e[c-1];e[c]=[l,o,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,a,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(o in r)n.o(r,o)&&(n.m[o]=r[o]);if(s)var c=s(n)}for(t&&t(l);u select( 'cap/blocks' ).getAuthorPlaceholder(), []); + + const author = context['cap/author'] || authorPlaceholder; + + const { imageSizes, imageDimensions } = useSelect( ( select ) => select( blockEditorStore ).getSettings(), [] ); - const author = context['cap/author'] || settings['cap/author-example']; - const media = useSelect( (select) => { return 0 !== author.featured_media && select( coreStore ).getMedia( author.featured_media, { context: 'view' } ) }, [author.featured_media]); diff --git a/blocks/coauthors/build/index.asset.php b/blocks/coauthors/build/index.asset.php index babdf068..6b8a42e0 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/blocks/coauthors/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '7395abd96d84c23f07d2'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '992aad811383c5f0a244'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index 953bf78a..9344efdf 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,v=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),f=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),d=n(779),h=n.n(d);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function g(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const w=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:d,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=o,{postId:S}=d,O=(0,s.useSelect)((e=>e(a.store).getSettings()),[]),[B,A]=(0,r.useState)([O["cap/author-example"]]),[P,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(A).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{i({layout:{...E,...e}})},G=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:G}),(0,r.createElement)(a.AlignmentControl,{value:C,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:h()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),B&&"inline"===E.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:w,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),B&&B.map((e=>{var t;const n=e.id===(P||(null===(t=B[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},k&&n===o.length-1?`${k}`:`${x}`),t))),B&&"inline"===E.type&&(m||_)&&(0,r.createElement)(a.RichText,{allowedFormats:w,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:x||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:k||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:l,textAlign:i}=o,c={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=h()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:c}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,l=n[0],i=n[1],c=n[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s{a(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,l.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const g=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:d,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=o,{postId:S}=d,O=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(l.store).getBlocks(p))),z=e=>{i({layout:{...E,...e}})},G=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.BlockControls,null,(0,r.createElement)(a.ToolbarGroup,{controls:G}),(0,r.createElement)(l.AlignmentControl,{value:C,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,l.useBlockProps)({className:h()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,l.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),A&&"inline"===E.type&&(m||y)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const n=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(l.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},k&&n===o.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(m||_)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(l.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(a.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:x||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:k||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:a,textAlign:i}=o,c={gap:"block"===a.type?(0,l.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=h()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",l.useBlockProps.save({className:s,style:c}),(0,r.createElement)(l.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,r,l]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,l,a=n[0],i=n[1],c=n[2],s=0;if(a.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s select( blockEditorStore ).getSettings(), []); - const [ coAuthors, setCoAuthors ] = useState([ settings['cap/author-example']]); + const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); + const [ coAuthors, setCoAuthors ] = useState([authorPlaceholder]); const [ activeBlockContextId, setActiveBlockContextId ] = useState(); const noticesDispatch = useDispatch('core/notices'); diff --git a/blocks/store/build/index.asset.php b/blocks/store/build/index.asset.php new file mode 100644 index 00000000..ddd6f624 --- /dev/null +++ b/blocks/store/build/index.asset.php @@ -0,0 +1 @@ + array('wp-data', 'wp-hooks'), 'version' => '2f09dca744215aa9be3a'); diff --git a/blocks/store/build/index.js b/blocks/store/build/index.js new file mode 100644 index 00000000..af5501ed --- /dev/null +++ b/blocks/store/build/index.js @@ -0,0 +1 @@ +!function(){"use strict";var e=window.wp.data,o=window.wp.hooks;(0,e.register)((0,e.createReduxStore)("cap/blocks",{reducer:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.coAuthorsBlocks;return e},selectors:{getAuthorPlaceholder:e=>(0,o.applyFilters)("cap.author-placeholder",e.authorPlaceholder)}}))}(); \ No newline at end of file diff --git a/blocks/store/package.json b/blocks/store/package.json new file mode 100644 index 00000000..b6abf47a --- /dev/null +++ b/blocks/store/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "build": "../../node_modules/.bin/wp-scripts build" + } +} diff --git a/blocks/store/src/index.js b/blocks/store/src/index.js new file mode 100644 index 00000000..4231195a --- /dev/null +++ b/blocks/store/src/index.js @@ -0,0 +1,13 @@ +import { createReduxStore, register } from '@wordpress/data'; +import { applyFilters } from '@wordpress/hooks'; + +register( + createReduxStore( 'cap/blocks', { + reducer: ( state = window.coAuthorsBlocks ) => { + return state; + }, + selectors: { + getAuthorPlaceholder: ( state ) => applyFilters( 'cap.author-placeholder', state.authorPlaceholder ), + }, + } ) +); From 09af02064dcad1ead1eeccc8c648ee8b93346d62 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 11 Aug 2023 10:42:23 -0400 Subject: [PATCH 046/123] use author placeholder from custom store --- blocks/coauthor-avatar/src/edit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/coauthor-avatar/src/edit.js b/blocks/coauthor-avatar/src/edit.js index ea5327d4..64e74ab3 100644 --- a/blocks/coauthor-avatar/src/edit.js +++ b/blocks/coauthor-avatar/src/edit.js @@ -15,8 +15,8 @@ import { useSelect } from '@wordpress/data'; export default function Edit( { context, attributes, setAttributes } ) { const { isLink, rel, size } = attributes; - const settings = useSelect( select => select( blockEditorStore ).getSettings(), []); - const author = context['cap/author'] || settings['cap/author-example']; + const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); + const author = context['cap/author'] || authorPlaceholder; const { avatar_urls } = author; if ( ! avatar_urls || 0 === avatar_urls.length ) { From 4e489f1ae39db2dd59f0afe0cb51115e43701ec6 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 11 Aug 2023 10:47:47 -0400 Subject: [PATCH 047/123] add descriptions to schema items --- .../endpoints/class-coauthor-blocks-controller.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index 364404cc..bf6cc546 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -214,19 +214,19 @@ public function get_item_schema() : array { 'type' => 'object', 'properties' => array( 'id' => array( - 'description' => __( '', 'co-authors-plus' ), + 'description' => __( 'Either user id or guest author id.', 'co-authors-plus' ), 'type' => 'integer', 'context' => array( 'view' ), 'readonly' => true ), 'display_name' => array( - 'description' => __( '', 'co-authors-plus' ), + 'description' => __( 'Author name for display.', 'co-authors-plus' ), 'type' => 'string', 'context' => array( 'view' ), 'readonly' => true ), 'description' => array( - 'description' => __( '', 'co-authors-plus' ), + 'description' => __( 'Author description.', 'co-authors-plus' ), 'type' => 'object', 'context' => array( 'view' ), 'readonly' => true, @@ -246,7 +246,7 @@ public function get_item_schema() : array { ) ), 'user_nicename' => array( - 'description' => __( '', 'co-authors-plus' ), + 'description' => __( 'Unique author slug.', 'co-authors-plus' ), 'type' => 'string', 'context' => array( 'view' ), 'readonly' => true @@ -258,13 +258,13 @@ public function get_item_schema() : array { 'readonly' => true ), 'avatar_urls' => array( - 'description' => __( '', 'co-authors-plus' ), + 'description' => __( 'URL for author avatar.', 'co-authors-plus' ), 'type' => 'object', 'context' => array( 'view' ), 'readonly' => true, ), 'featured_media' => array( - 'description' => __( '', 'co-authors-plus' ), + 'description' => __( 'Id of guest author feature image.', 'co-authors-plus' ), 'type' => 'integer', 'context' => array( 'view' ), 'readonly' => true, From 802c7817dec5e8df545197302d72f51cc2ef0a30 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 11 Aug 2023 13:44:24 -0400 Subject: [PATCH 048/123] support spacing in avatar block --- blocks/coauthor-avatar/build/block.json | 8 ++++++++ blocks/coauthor-avatar/src/block.json | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/blocks/coauthor-avatar/build/block.json b/blocks/coauthor-avatar/build/block.json index 7989fea0..3905451d 100644 --- a/blocks/coauthor-avatar/build/block.json +++ b/blocks/coauthor-avatar/build/block.json @@ -20,6 +20,14 @@ "radius": false, "width": false } + }, + "spacing": { + "margin": true, + "padding": true, + "__experimentalDefaultControls": { + "margin": false, + "padding": false + } } }, "usesContext": [ diff --git a/blocks/coauthor-avatar/src/block.json b/blocks/coauthor-avatar/src/block.json index ce7157fe..7ae68982 100644 --- a/blocks/coauthor-avatar/src/block.json +++ b/blocks/coauthor-avatar/src/block.json @@ -20,6 +20,14 @@ "radius": false, "width": false } + }, + "spacing": { + "margin": true, + "padding": true, + "__experimentalDefaultControls": { + "margin": false, + "padding": false + } } }, "usesContext": [ From 4826d388e693544b787869fb4b2c9cb24d4ba171 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 11 Aug 2023 13:45:22 -0400 Subject: [PATCH 049/123] support register_rest_field --- php/api/endpoints/class-coauthor-blocks-controller.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index bf6cc546..8d4b94e1 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -350,6 +350,10 @@ public function prepare_item_for_response( $author, $request ) : WP_REST_Respons $data['user_nicename'] = (string) $author->user_nicename; } + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; + $data = $this->add_additional_fields_to_object( $data, $request ); + $data = $this->filter_response_by_context( $data, $context ); + $response = rest_ensure_response( $data ); /** From 17fcb215c6caa496d4127bd778bd51846c830136 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 11 Aug 2023 14:35:23 -0400 Subject: [PATCH 050/123] =?UTF-8?q?support=20turning=20off=20the=20?= =?UTF-8?q?=E2=80=9Cshow=5Favatars=E2=80=9D=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class-coauthor-blocks-controller.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthor-blocks-controller.php index 8d4b94e1..363bf84c 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthor-blocks-controller.php @@ -257,12 +257,6 @@ public function get_item_schema() : array { 'context' => array( 'view' ), 'readonly' => true ), - 'avatar_urls' => array( - 'description' => __( 'URL for author avatar.', 'co-authors-plus' ), - 'type' => 'object', - 'context' => array( 'view' ), - 'readonly' => true, - ), 'featured_media' => array( 'description' => __( 'Id of guest author feature image.', 'co-authors-plus' ), 'type' => 'integer', @@ -272,6 +266,15 @@ public function get_item_schema() : array { ) ); + if ( get_option( 'show_avatars' ) ) { + $schema['properties']['avatar_urls'] = array( + 'description' => __( 'URL for author avatar.', 'co-authors-plus' ), + 'type' => 'object', + 'context' => array( 'view' ), + 'readonly' => true, + ); + } + // Take a snapshot of which fields are in the schema pre-filtering. $schema_fields = array_keys( $schema['properties'] ); From 2cfe150841ac602c7fbd0d91a52f3c0f88328d60 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 15 Aug 2023 11:03:20 -0400 Subject: [PATCH 051/123] working but slightly bizarre feature image --- .../build/index.asset.php | 2 +- blocks/coauthor-feature-image/build/index.js | 4 +- blocks/coauthor-feature-image/src/edit.js | 175 ++++++++++++------ 3 files changed, 119 insertions(+), 62 deletions(-) diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php index de6f36b7..7feb165f 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '73797188219d475e8fb0'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'cc1a636b8341aedf1be8'); diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js index 62b3b07c..c0ee180f 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-feature-image/build/index.js @@ -1,3 +1,3 @@ -!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,o=window.wp.element,a=l(779),i=l.n(a),r=window.wp.i18n,s=window.wp.blockEditor,u=window.wp.components,c=window.wp.data,p=window.wp.coreData;const m=(0,o.createElement)(o.Fragment,null,(0,o.createElement)(u.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,o.createElement)(u.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,o.createElement)(u.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),_="cover",d={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var g=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:a,scale:i,sizeSlug:c},setAttributes:p,imageSizeOptions:g=[]}=e;const h=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),b=a||l&&"auto"!==l;return(0,o.createElement)(s.InspectorControls,{group:"dimensions"},(0,o.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,o.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,o.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!a,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,o.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:a||"",min:0,onChange:e=>v("height",e),units:h})),(0,o.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,o.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>v("width",e),units:h})),b&&(0,o.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==_,label:f,onDeselect:()=>p({scale:_}),resetAllFilter:()=>({scale:_}),isShownByDefault:!0,panelId:t},(0,o.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:d[i],onChange:e=>p({scale:e}),isBlock:!0},m)),!!g.length&&(0,o.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,o.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:g,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))},h=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(h.u2,{edit:function(e){var t;let{attributes:l,setAttributes:n,context:a,clientId:m}=e;const{isLink:_,rel:d,width:h,height:v,aspectRatio:f,sizeSlug:b,scale:w}=l,x=(0,c.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),S=a["cap/author"]||x,{imageSizes:E,imageDimensions:y}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),C=(0,c.useSelect)((e=>0!==S.featured_media&&e(p.store).getMedia(S.featured_media,{context:"view"})),[S.featured_media]),I=function(e,t){var l,n,o;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(o=n[t])||void 0===o?void 0:o.source_url)||(null==e?void 0:e.source_url)}(C,b),O=E.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),k=(0,s.__experimentalUseBorderProps)(l),B={...k.style,height:f?"100%":v,width:!!f&&"100%",objectFit:!(!v&&!f)&&w},P=null===(t=y[b])||void 0===t?void 0:t.width,A=h||v,F=(0,s.useBlockProps)({style:{width:A?h:P,height:v,aspectRatio:f}});return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(g,{clientId:m,attributes:l,setAttributes:n,imageSizeOptions:O}),(0,o.createElement)("figure",F,C?(0,o.createElement)("img",{src:I,alt:C.alt_text?sprintf( +!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=l(779),i=l.n(o),r=window.wp.i18n,s=window.wp.blockEditor,c=window.wp.components,u=window.wp.data,p=window.wp.coreData;const h=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),d="cover",m={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var g=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:o,scale:i,sizeSlug:u},setAttributes:p,imageSizeOptions:g=[]}=e;const _=(0,c.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),f=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},v=(0,r._x)("Scale","Image scaling options"),b=o||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,a.createElement)(c.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:o||"",min:0,onChange:e=>f("height",e),units:_})),(0,a.createElement)(c.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>f("width",e),units:_})),b&&(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==d,label:v,onDeselect:()=>p({scale:d}),resetAllFilter:()=>({scale:d}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:v,value:i,help:m[i],onChange:e=>p({scale:e}),isBlock:!0},h)),!!g.length&&(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!u,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(c.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:u||"full",options:g,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))};function _(e,t,l){let{width:n,height:a,aspectRatio:o,scale:i,sizeSlug:r}=t;const s={width:n,height:a,objectFit:i};if(n&&a||(n||a)&&o&&"auto"!==o)return{width:"100%",height:"100%",objectFit:i};const c=Object.keys(l),u=l[e||"full"!==r?r:c[Math.max(0,c.length-1)]],p={};!u||n&&a||(!0===u.crop?(p.width=`${u.width}px`,o&&"auto"!==o||(p.aspectRatio=`${u.width}/${u.height}`)):u.width>=u.height&&u.width>0?(p.width=`${u.width}px`,e||(p.aspectRatio="1/1")):u.height>0&&(p.height=`${u.height}px`,e||(p.aspectRatio="1/1"))),p.width&&p.height||!o||"auto"===o||(p.aspectRatio=o);for(const e in p)s[e]||(s[e]=p[e]);return s}var f=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(f.u2,{edit:function(e){let{attributes:t,setAttributes:l,context:n,clientId:o}=e;const h=(0,u.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),d=n["cap/author"]||h,m=(0,s.__experimentalUseBorderProps)(t),f=(0,u.useSelect)((e=>0!==d.featured_media&&e(p.store).getMedia(d.featured_media,{context:"view"})),[d.featured_media]),{isLink:v,rel:b,width:w,height:x,aspectRatio:S,sizeSlug:E,scale:y}=t,C=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(f,E),{imageSizes:I,imageDimensions:O}=(0,u.useSelect)((e=>e(s.store).getSettings()),[]),k=I.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),B=function(e){let{width:t,height:l,aspectRatio:n}=e;return t||l?{width:t,height:l,aspectRatio:n}:{}}(t),P={...m.style,..._(f,t,O)},F={padding:0,minHeight:"100%",minWidth:"100%",...m.style,..._(f,t,O)},R=0!==d.id&&!1===f;return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(g,{clientId:o,attributes:t,setAttributes:l,imageSizeOptions:k}),R?null:(0,a.createElement)("figure",(0,s.useBlockProps)({style:B}),f?(0,a.createElement)("img",{src:C,alt:f.alt_text?sprintf( // translators: %s: The image's alt text. -(0,r.__)("Featured image: %s"),C.alt_text):(0,r.__)("Featured image"),style:B}):(0,o.createElement)(u.Placeholder,{className:i()("block-editor-media-placeholder",k.className),withIllustration:!0,style:{height:!!f&&"100%",width:!!f&&"100%",minWidth:"auto",minHeight:"auto",...k.style}})),(0,o.createElement)(s.InspectorControls,null,(0,o.createElement)(u.PanelBody,{title:(0,r.__)("Settings")},(0,o.createElement)(u.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make feature image a link to author archive."),onChange:()=>n({isLink:!_}),checked:_}),_&&(0,o.createElement)(u.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:d,onChange:e=>n({rel:e})}))))},save:function(){return(0,o.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,a0&&e[c-1][2]>a;c--)e[c]=e[c-1];e[c]=[l,o,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,a,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(o in r)n.o(r,o)&&(n.m[o]=r[o]);if(s)var c=s(n)}for(t&&t(l);ul({isLink:!v}),checked:v}),v&&(0,a.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:b,onChange:e=>l({rel:e})}))))},save:function(){return(0,a.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[u-1][2]>o;u--)e[u]=e[u-1];e[u]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],c=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var u=s(n)}for(t&&t(l);c= size.height) && size.width > 0 ) { + newStyles['width'] = `${size.width}px`; + if ( ! media ) { + newStyles['aspectRatio'] = '1/1'; + } + } else if ( size.height > 0 ) { + newStyles['height'] = `${size.height}px`; + if ( ! media ) { + newStyles['aspectRatio'] = '1/1'; + } + } + } + + if ( ((! newStyles['width'] || ! newStyles['height'])) && ( aspectRatio && 'auto' !== aspectRatio ) ) { + newStyles['aspectRatio'] = aspectRatio; + } + + for ( const key in newStyles ) { + if ( ! styles[key] ) { + styles[key] = newStyles[key]; + } + } + + return styles; +} + +function getContainerStyles( { width, height, aspectRatio } ) { + + if ( ( width || height ) ) { + return { width, height, aspectRatio }; + } + + return {} +} + /** * Edit * @@ -34,46 +92,46 @@ function getMediaSourceUrlBySizeSlug( media, slug ) { */ export default function Edit( { attributes, setAttributes, context, clientId } ) { - const { isLink, rel, width, height, aspectRatio, sizeSlug, scale } = attributes; - const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); - const author = context['cap/author'] || authorPlaceholder; - - const { imageSizes, imageDimensions } = useSelect( - ( select ) => select( blockEditorStore ).getSettings(), - [] - ); - + const borderProps = useBorderProps( attributes ); const media = useSelect( (select) => { return 0 !== author.featured_media && select( coreStore ).getMedia( author.featured_media, { context: 'view' } ) }, [author.featured_media]); + const { isLink, + rel, + width, + height, + aspectRatio, + sizeSlug, // AKA "resolution" + scale // AKA "object-fit" + } = attributes; + const mediaUrl = getMediaSourceUrlBySizeSlug( media, sizeSlug ); - const imageSizeOptions = imageSizes.map( - ( { name, slug } ) => ( { value: slug, label: name } ) - ); - - const borderProps = useBorderProps( attributes ); + const { imageSizes, imageDimensions } = useSelect( select => select( blockEditorStore ).getSettings(), [] ); + + const imageSizeOptions = imageSizes.map( ( { name, slug } ) => ( { value: slug, label: name } ) ); + + const containerStyles = getContainerStyles( attributes ); - const imageStyles = { + const imageEditStyles = { ...borderProps.style, - height: aspectRatio ? '100%' : height, - width: !! aspectRatio && '100%', - objectFit: !! ( height || aspectRatio ) && scale, + ...getPlaceholderStyles( media, attributes, imageDimensions ) }; - const widthFromImageDimensions = imageDimensions[sizeSlug]?.width; - const hasWidthOrHeight = width || height; - - const blockProps = useBlockProps( { - style: { - width: hasWidthOrHeight ? width : widthFromImageDimensions, - height, - aspectRatio, - } - } ); + const placeholderStyles = { + padding: 0, + minHeight: '100%', + minWidth: '100%', + ...borderProps.style, + ...getPlaceholderStyles( media, attributes, imageDimensions ), + }; + + // don't placehold feature images in a loop where there's no image. + // but do placehold them in author archive contexts. + const panic = 0 !== author.id && false === media; return ( <> @@ -83,37 +141,36 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) setAttributes={ setAttributes } imageSizeOptions={ imageSizeOptions } /> -
- { - media ? ( - { - ) : ( - - ) - } -
+ { + panic ? null : ( +
+ { + media ? ( + { + ) : ( + + ) + } +
+ ) + } + Date: Wed, 16 Aug 2023 11:55:11 -0400 Subject: [PATCH 052/123] use custom placeholder, make more like image block --- .../build/index.asset.php | 2 +- blocks/coauthor-feature-image/build/index.js | 4 +- .../build/style-index.css | 2 +- ...class-cap-block-coauthor-feature-image.php | 95 +++++---- blocks/coauthor-feature-image/src/edit.js | 184 ++++++------------ blocks/coauthor-feature-image/src/style.scss | 6 +- blocks/coauthor-feature-image/src/utils.js | 129 ++++++++++++ blocks/components/placeholder-image.jsx | 60 ++++++ 8 files changed, 315 insertions(+), 167 deletions(-) create mode 100644 blocks/coauthor-feature-image/src/utils.js create mode 100644 blocks/components/placeholder-image.jsx diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php index 7feb165f..720bea9d 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'cc1a636b8341aedf1be8'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '2572a193a917764e0740'); diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js index c0ee180f..1b7cc4e9 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-feature-image/build/index.js @@ -1,3 +1 @@ -!function(){var e,t={113:function(e,t,l){"use strict";var n=window.wp.blocks,a=window.wp.element,o=l(779),i=l.n(o),r=window.wp.i18n,s=window.wp.blockEditor,c=window.wp.components,u=window.wp.data,p=window.wp.coreData;const h=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,a.createElement)(c.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),d="cover",m={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var g=e=>{let{clientId:t,attributes:{aspectRatio:l,width:n,height:o,scale:i,sizeSlug:u},setAttributes:p,imageSizeOptions:g=[]}=e;const _=(0,c.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),f=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||p({[e]:l<0?"0":t})},v=(0,r._x)("Scale","Image scaling options"),b=o||l&&"auto"!==l;return(0,a.createElement)(s.InspectorControls,{group:"dimensions"},(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>p({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>p({aspectRatio:e})})),(0,a.createElement)(c.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Height"),onDeselect:()=>p({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:o||"",min:0,onChange:e=>f("height",e),units:_})),(0,a.createElement)(c.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!n,label:(0,r.__)("Width"),onDeselect:()=>p({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:n||"",min:0,onChange:e=>f("width",e),units:_})),b&&(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==d,label:v,onDeselect:()=>p({scale:d}),resetAllFilter:()=>({scale:d}),isShownByDefault:!0,panelId:t},(0,a.createElement)(c.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:v,value:i,help:m[i],onChange:e=>p({scale:e}),isBlock:!0},h)),!!g.length&&(0,a.createElement)(c.__experimentalToolsPanelItem,{hasValue:()=>!!u,label:(0,r.__)("Resolution"),onDeselect:()=>p({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,a.createElement)(c.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:u||"full",options:g,onChange:e=>p({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))};function _(e,t,l){let{width:n,height:a,aspectRatio:o,scale:i,sizeSlug:r}=t;const s={width:n,height:a,objectFit:i};if(n&&a||(n||a)&&o&&"auto"!==o)return{width:"100%",height:"100%",objectFit:i};const c=Object.keys(l),u=l[e||"full"!==r?r:c[Math.max(0,c.length-1)]],p={};!u||n&&a||(!0===u.crop?(p.width=`${u.width}px`,o&&"auto"!==o||(p.aspectRatio=`${u.width}/${u.height}`)):u.width>=u.height&&u.width>0?(p.width=`${u.width}px`,e||(p.aspectRatio="1/1")):u.height>0&&(p.height=`${u.height}px`,e||(p.aspectRatio="1/1"))),p.width&&p.height||!o||"auto"===o||(p.aspectRatio=o);for(const e in p)s[e]||(s[e]=p[e]);return s}var f=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,n.registerBlockType)(f.u2,{edit:function(e){let{attributes:t,setAttributes:l,context:n,clientId:o}=e;const h=(0,u.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),d=n["cap/author"]||h,m=(0,s.__experimentalUseBorderProps)(t),f=(0,u.useSelect)((e=>0!==d.featured_media&&e(p.store).getMedia(d.featured_media,{context:"view"})),[d.featured_media]),{isLink:v,rel:b,width:w,height:x,aspectRatio:S,sizeSlug:E,scale:y}=t,C=function(e,t){var l,n,a;return(null==e||null===(l=e.media_details)||void 0===l||null===(n=l.sizes)||void 0===n||null===(a=n[t])||void 0===a?void 0:a.source_url)||(null==e?void 0:e.source_url)}(f,E),{imageSizes:I,imageDimensions:O}=(0,u.useSelect)((e=>e(s.store).getSettings()),[]),k=I.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),B=function(e){let{width:t,height:l,aspectRatio:n}=e;return t||l?{width:t,height:l,aspectRatio:n}:{}}(t),P={...m.style,..._(f,t,O)},F={padding:0,minHeight:"100%",minWidth:"100%",...m.style,..._(f,t,O)},R=0!==d.id&&!1===f;return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(g,{clientId:o,attributes:t,setAttributes:l,imageSizeOptions:k}),R?null:(0,a.createElement)("figure",(0,s.useBlockProps)({style:B}),f?(0,a.createElement)("img",{src:C,alt:f.alt_text?sprintf( -// translators: %s: The image's alt text. -(0,r.__)("Featured image: %s"),f.alt_text):(0,r.__)("Featured image"),style:P}):(0,a.createElement)(c.Placeholder,{className:i()("block-editor-media-placeholder",m.className),withIllustration:!0,style:F})),(0,a.createElement)(s.InspectorControls,null,(0,a.createElement)(c.PanelBody,{title:(0,r.__)("Settings")},(0,a.createElement)(c.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make feature image a link to author archive."),onChange:()=>l({isLink:!v}),checked:v}),v&&(0,a.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel"),value:b,onChange:e=>l({rel:e})}))))},save:function(){return(0,a.createElement)("p",s.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})},779:function(e,t){var l;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;t=o)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(r=!1,o0&&e[u-1][2]>o;u--)e[u]=e[u-1];e[u]=[l,a,o]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,o,i=l[0],r=l[1],s=l[2],c=0;if(i.some((function(t){return 0!==e[t]}))){for(a in r)n.o(r,a)&&(n.m[a]=r[a]);if(s)var u=s(n)}for(t&&t(l);c{let{clientId:a,attributes:{aspectRatio:o,width:h,height:u,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,n.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),w=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},f=(0,l._x)("Scale","Image scaling options"),v=u||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:a},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:a},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:u||"",min:0,onChange:e=>w("height",e),units:_})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:a},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:h||"",min:0,onChange:e=>w("width",e),units:_})),v&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:f,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:a},(0,t.createElement)(n.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:a},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function u(e){let{dimensions:i,style:n,className:a}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:a,src:o,style:n,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:w,scale:f,sizeSlug:v,width:b}=r,x=(0,a.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),S=c["cap/author"]||x,E=(0,a.useSelect)((e=>0!==S.featured_media&&e(o.store).getMedia(S.featured_media,{context:"view"})),[S.featured_media]),{imageSizes:C,imageDimensions:k}=(0,a.useSelect)((e=>e(i.store).getSettings()),[]),I=C.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),y=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(E,k,v),O=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const n=t[l];if(!0===n.crop||n.width===n.height)return{width:n.width,height:n.height};const a=i.width/i.height;return n.width>n.height?{width:n.width,height:n.width/a}:{width:n.height*a,height:n.height}}(E,k,y),B=E?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,y),N=(0,i.__experimentalUseBorderProps)(r),A=0!==S.id&&!1===E;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(h,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:I}),A?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),E?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:N.className,src:g(E,y),style:{width:!b&&p?"auto":b,height:!p&&b?"auto":p,aspectRatio:d,objectFit:f,...N.style},width:O.width,height:O.height}):(0,t.createElement)(u,{className:N.className,dimensions:B,style:{width:!b&&p?"auto":b,height:!p&&b?"auto":p,aspectRatio:d,objectFit:f,...N.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:(0,l.__)("Settings")},(0,t.createElement)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(n.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:w,onChange:e=>s({rel:e})}))))},save:function(){return(0,t.createElement)("p",i.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})}},l={};function i(e){var n=l[e];if(void 0!==n)return n.exports;var a=l[e]={exports:{}};return t[e](a,a.exports,i),a.exports}i.m=t,e=[],i.O=function(t,l,n,a){if(!l){var o=1/0;for(h=0;h=a)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[l,n,a]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var n,a,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(n in r)i.o(r,n)&&(i.m[n]=r[n]);if(s)var h=s(i)}for(t&&t(l);c '', + 'height' => '', + 'sizeSlug' => 'thumbnail', + 'scale' => '', + 'aspectRatio' => '', + 'isLink' => false, + 'rel' => '' + ), + $attributes + ); - if ( ! empty( $extra_styles ) ) { - $attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles; + if ( empty( $attributes['width'] ) && ! empty( $attributes['height'] ) ) { + $attributes['width'] = 'auto'; } - $link = $author['link'] ?? ''; - $is_link = '' !== $link && $attributes['isLink'] ?? false; - $rel = $attributes['rel'] ?? ''; + $style_attribute_map = array( + array( + 'prop' => 'width', + 'attr' => 'width' + ), + array( + 'prop' => 'height', + 'attr' => 'height' + ), + array( + 'prop' => 'object-fit', + 'attr' => 'scale' + ), + array( + 'prop' => 'aspect-ratio', + 'attr' => 'aspectRatio' + ) + ); - $featured_image = wp_get_attachment_image( $featured_media_id, $size_slug, false, $attr ); + $styles = array_map( + function( $style ) use ( $attributes ) : string { + if ( empty( $attributes[$style['attr']] ) ) { + return ''; + } + return sprintf( + "%s;", + safecss_filter_attr( + "{$style['prop']}:{$attributes[$style['attr']]}" + ) + ); + }, + $style_attribute_map + ); - $featured_image = $is_link ? self::add_link( $link, $featured_image, $rel ) : $featured_image; + $image_attributes = array_merge( + array( + 'class' => '', + 'style' => '' + ), + get_block_core_post_featured_image_border_attributes( $attributes ) + ); - $aspect_ratio = ! empty( $attributes['aspectRatio'] ) - ? esc_attr( safecss_filter_attr( 'aspect-ratio:' . $attributes['aspectRatio'] ) ) . ';' - : ''; - $width = ! empty( $attributes['width'] ) - ? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';' - : ''; - $height = ! empty( $attributes['height'] ) - ? esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';' - : ''; + $image_attributes['style'] .= implode( '', $styles ); + $wrapper_attributes = get_block_wrapper_attributes(); + $feature_image = wp_get_attachment_image( $featured_media_id, $attributes['sizeSlug'], false, $image_attributes ); - if ( ! $height && ! $width && ! $aspect_ratio ) { - $wrapper_attributes = get_block_wrapper_attributes(); + if ( true === $attributes['isLink'] ) { + $inner_content = self::add_link( $author['link'], $feature_image, $attributes['rel'] ); } else { - $wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $aspect_ratio . $width . $height ) ); + $inner_content = $feature_image; } - return "
{$featured_image}
"; + return "
{$inner_content}
"; } /** * Add Link diff --git a/blocks/coauthor-feature-image/src/edit.js b/blocks/coauthor-feature-image/src/edit.js index 6b993d0b..d2cb2124 100644 --- a/blocks/coauthor-feature-image/src/edit.js +++ b/blocks/coauthor-feature-image/src/edit.js @@ -1,4 +1,6 @@ -import classnames from 'classnames'; +/** + * Co-Author Feature Image + */ import { __ } from '@wordpress/i18n'; import { @@ -7,130 +9,54 @@ import { __experimentalUseBorderProps as useBorderProps, InspectorControls, } from '@wordpress/block-editor'; -import { Placeholder, TextControl, PanelBody, ToggleControl } from '@wordpress/components'; +import { TextControl, PanelBody, ToggleControl } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; - -import './editor.scss'; - import DimensionControls from './dimension-controls'; +import PlaceholderImage from '../../components/placeholder-image'; +import { getAvailableSizeSlug, getMediaSrc, getMediaDimensions, getPlaceholderImageDimensions } from './utils' -/** - * - * @param {Object|undefined} media - * @param {String|undefined} slug - * @return {String|undefined} - */ -function getMediaSourceUrlBySizeSlug( media, slug ) { - return ( - media?.media_details?.sizes?.[ slug ]?.source_url || media?.source_url - ); -} - -function getPlaceholderStyles(media, {width, height, aspectRatio, scale, sizeSlug}, imageDimensions) { - const styles = { width, height, objectFit: scale }; - - if ( ( width && height ) || ( (width || height) && ( aspectRatio && 'auto' !== aspectRatio ) ) ) { - return { - width: '100%', - height: '100%', - objectFit: scale - } - } - - const keys = Object.keys( imageDimensions ) - const sizeKey = (! media && 'full' === sizeSlug) ? keys[Math.max(0, keys.length - 1)] : sizeSlug; - const size = imageDimensions[sizeKey]; - - const newStyles = {}; - - if ( size && (! width || ! height )) { - if ( true === size.crop ) { - newStyles['width'] = `${size.width}px`; - if ( ( ! aspectRatio || 'auto' === aspectRatio ) ) { - newStyles['aspectRatio'] = `${size.width}/${size.height}`; - } - } else if ( (size.width >= size.height) && size.width > 0 ) { - newStyles['width'] = `${size.width}px`; - if ( ! media ) { - newStyles['aspectRatio'] = '1/1'; - } - } else if ( size.height > 0 ) { - newStyles['height'] = `${size.height}px`; - if ( ! media ) { - newStyles['aspectRatio'] = '1/1'; - } - } - } - - if ( ((! newStyles['width'] || ! newStyles['height'])) && ( aspectRatio && 'auto' !== aspectRatio ) ) { - newStyles['aspectRatio'] = aspectRatio; - } - - for ( const key in newStyles ) { - if ( ! styles[key] ) { - styles[key] = newStyles[key]; - } - } - - return styles; -} - -function getContainerStyles( { width, height, aspectRatio } ) { - - if ( ( width || height ) ) { - return { width, height, aspectRatio }; - } - - return {} -} +import './editor.scss'; /** * Edit * - * @return {WPElement} Element to render. + * @export + * @param {Object} props { attributes, setAttributes, context, clientId } + * @return {WPElement} */ export default function Edit( { attributes, setAttributes, context, clientId } ) { - const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); - const author = context['cap/author'] || authorPlaceholder; - const borderProps = useBorderProps( attributes ); - const media = useSelect( (select) => { - return 0 !== author.featured_media && select( coreStore ).getMedia( author.featured_media, { context: 'view' } ) - }, [author.featured_media]); - - const { isLink, - rel, - width, - height, - aspectRatio, - sizeSlug, // AKA "resolution" - scale // AKA "object-fit" - } = attributes; + const { aspectRatio, height, isLink, rel, scale, sizeSlug, width } = attributes; - const mediaUrl = getMediaSourceUrlBySizeSlug( media, sizeSlug ); - - const { imageSizes, imageDimensions } = useSelect( select => select( blockEditorStore ).getSettings(), [] ); + // Author + const authorPlaceholder = useSelect( + select => select( 'cap/blocks' ).getAuthorPlaceholder(), + [] + ); + const author = context['cap/author'] || authorPlaceholder; - const imageSizeOptions = imageSizes.map( ( { name, slug } ) => ( { value: slug, label: name } ) ); + // Media + const media = useSelect( + select => 0 !== author.featured_media && select( coreStore ).getMedia( author.featured_media, { context: 'view' } ), + [author.featured_media] + ); - const containerStyles = getContainerStyles( attributes ); + // Image Sizes and Dimensions + const { imageSizes, imageDimensions } = useSelect( + select => select( blockEditorStore ).getSettings(), + [] + ); + const imageSizeOptions = imageSizes.map( ( { name, slug } ) => ({ value: slug, label: name })); + const availableSizeSlug = getAvailableSizeSlug( media, imageDimensions, sizeSlug ); + const dimensions = getMediaDimensions( media, imageDimensions, availableSizeSlug ); + const placeholderDimensions = media ? {} : getPlaceholderImageDimensions(imageDimensions, availableSizeSlug); - const imageEditStyles = { - ...borderProps.style, - ...getPlaceholderStyles( media, attributes, imageDimensions ) - }; + // Border + const borderProps = useBorderProps( attributes ); - const placeholderStyles = { - padding: 0, - minHeight: '100%', - minWidth: '100%', - ...borderProps.style, - ...getPlaceholderStyles( media, attributes, imageDimensions ), - }; - - // don't placehold feature images in a loop where there's no image. - // but do placehold them in author archive contexts. + // Don't placehold feature images for real authors with no image. + // Do placehold them in author archive contexts. const panic = 0 !== author.id && false === media; return ( @@ -143,34 +69,40 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) /> { panic ? null : ( -
+
{ media ? ( { ) : ( - ) }
) } - imageSize.height ) { + return { + width: imageSize.width, + height: imageSize.width / mediaAspectRatio + } + } + + return { + width: imageSize.height * mediaAspectRatio, + height: imageSize.height + } +} + +/** + * Get Media Src + * + * @param {Object} media + * @param {string} sizeSlug + * @return {string} + */ +export function getMediaSrc( media, sizeSlug ) { + return media?.media_details?.sizes[sizeSlug]?.source_url; +} + +/** + * Get Placeholder Image Dimensions + * + * @param {Object} imageDimensions + * @param {string} sizeSlug + * @return {Object} {width,height} + */ +export function getPlaceholderImageDimensions( imageDimensions, sizeSlug ) { + + const size = imageDimensions[sizeSlug]; + + if ( true === size.crop || size.width === size.height ) { + return { + width: size.width, + height: size.height + } + } + + if ( size.width > size.height ) { + return { + width: size.width, + height: size.width + } + } + + return { + width: size.height, + height: size.height + } +} + +/** + * Get Size Keys Intersection + * + * @param {Object} media + * @param {Object} imageDimensions + * @return {Array} + */ +export function getSizeKeysIntersection( media, imageDimensions ) { + + if ( ! media ) { + return Object.keys( imageDimensions ); + } + + const mediaKeys = Object.keys( media.media_details.sizes ); + const sizeKeys = Object.keys( imageDimensions ); + + return Array.from( new Set([...mediaKeys.filter( ( key ) => sizeKeys.includes(key) )])) +} + +/** + * Get Available Size Slug + * + * @param {Object} media + * @param {Object} imageDimensions + * @param {string} sizeSlug + * @return {string} + */ +export function getAvailableSizeSlug( media, imageDimensions, sizeSlug ) { + + if ( media && 'full' === sizeSlug ) { + return sizeSlug; + } + + const keys = getSizeKeysIntersection( media, imageDimensions ); + + if ( sizeSlug && keys.includes( sizeSlug ) ) { + return sizeSlug; + } + + return keys[Math.max(0, keys.length - 1)]; +} diff --git a/blocks/components/placeholder-image.jsx b/blocks/components/placeholder-image.jsx new file mode 100644 index 00000000..6dc79e18 --- /dev/null +++ b/blocks/components/placeholder-image.jsx @@ -0,0 +1,60 @@ +import { useMemo } from "@wordpress/element"; +import { __ } from '@wordpress/i18n'; + +/** + * Encode SVG + * + * @param {string} svgHTML + * @return {string} + */ +function encodeSVG( svgHTML ) { + return encodeURIComponent( + svgHTML + // Strip newlines and tabs + .replace(/[\t\n\r]/gim, '') + // Condense multiple spaces + .replace(/\s\s+/g, ' ') + ) + // Encode parenthesis + .replace(/\(/g, '%28') + .replace(/\)/g, '%29'); +} + +/** + * Get Placeholder Src + * + * @param {Object} { width, height } + * @return {string} + */ +function getPlaceholderSrc( { width, height } ) { + const svg = encodeSVG( + ` + + + ` + ); + return `data:image/svg+xml;charset=UTF-8,${svg}` +} + +/** + * Placeholder Image + * + * @export + * @param {Object} props { dimensions, style, className } + * @return {WPElement} + */ +export default function PlaceholderImage( { dimensions, style, className } ) { + + const src = useMemo(() => getPlaceholderSrc(dimensions), [dimensions]); + + return ( + {__('Placeholder + ); +} From 55469c0b90d70bbf7b8e41210f697c5e03d52d09 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 16 Aug 2023 13:05:57 -0400 Subject: [PATCH 053/123] use image placeholder for avatar, switch to figure --- blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- blocks/coauthor-avatar/build/style-index.css | 2 +- .../class-cap-block-coauthor-avatar.php | 2 +- blocks/coauthor-avatar/src/edit.js | 20 +++++++++++++------ blocks/coauthor-avatar/src/style.css | 2 +- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index e923096f..3c9153a7 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '31d4185601de4d83966b'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '7d7c7bd6275b8594e952'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index a208fb62..6c29cb3d 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){var e,t={631:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,a=n(779),i=n.n(a),l=window.wp.i18n,u=window.wp.blockEditor,c=window.wp.components,s=window.wp.data,p=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,r.registerBlockType)(p.u2,{edit:function(e){var t;let{context:n,attributes:r,setAttributes:a}=e;const{isLink:p,rel:f,size:v}=r,d=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),h=n["cap/author"]||d,{avatar_urls:g}=h;if(!g||0===g.length)return null;const m=Object.keys(g).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,u.__experimentalUseBorderProps)(r),b=null!==(t=g[v])&&void 0!==t?t:"";return(0,o.createElement)(o.Fragment,null,(0,o.createElement)("div",(0,u.useBlockProps)(),""===b?(0,o.createElement)(c.Placeholder,{className:i()("block-editor-media-placeholder",w.className),withIllustration:!0,style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,...w.style}}):(0,o.createElement)("img",{style:{...w.style},width:v,height:v,src:`${g[v]}`})),(0,o.createElement)(u.InspectorControls,null,(0,o.createElement)(c.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,o.createElement)(c.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>a({isLink:!p}),checked:p}),p&&(0,o.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:f,onChange:e=>a({rel:e})}),(0,o.createElement)(c.SelectControl,{label:(0,l.__)("Avatar size"),value:v,options:m,onChange:e=>{a({size:Number(e)})}}))))}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[u])}))?n.splice(u--,1):(l=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[n,o,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,a,i=n[0],l=n[1],u=n[2],c=0;if(i.some((function(t){return 0!==e[t]}))){for(o in l)r.o(l,o)&&(r.m[o]=l[o]);if(u)var s=u(r)}for(t&&t(n);cfunction(e){let{width:t,height:n}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,o.createElement)("img",{alt:(0,i.__)("Placeholder image"),className:r,src:a,style:n,width:t.width,height:t.height})}var u=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,r.registerBlockType)(u.u2,{edit:function(e){var t;let{context:n,attributes:r,setAttributes:u}=e;const{isLink:h,rel:p,size:g}=r,f=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),v=n["cap/author"]||f,{avatar_urls:d}=v;if(!d||0===d.length)return null;const m=Object.keys(d).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,a.__experimentalUseBorderProps)(r),b=null!==(t=d[g])&&void 0!==t?t:"";return(0,o.createElement)(o.Fragment,null,(0,o.createElement)("figure",(0,a.useBlockProps)(),""===b?(0,o.createElement)(c,{className:w.className,dimensions:{width:g,height:g},style:{height:g,width:g,minWidth:"auto",minHeight:"auto",padding:0,...w.style}}):(0,o.createElement)("img",{style:{...w.style},width:g,height:g,src:`${d[g]}`})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,i.__)("Avatar Settings")},(0,o.createElement)(l.ToggleControl,{label:(0,i.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!h}),checked:h}),h&&(0,o.createElement)(l.TextControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Link rel"),value:p,onChange:e=>u({rel:e})}),(0,o.createElement)(l.SelectControl,{label:(0,i.__)("Avatar size"),value:g,options:m,onChange:e=>{u({size:Number(e)})}}))))}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=i)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(l=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[n,o,i]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,i,a=n[0],l=n[1],s=n[2],c=0;if(a.some((function(t){return 0!==e[t]}))){for(o in l)r.o(l,o)&&(r.m[o]=l[o]);if(s)var u=s(r)}for(t&&t(n);c -
+
{ '' === src ? ( - ) : ( - + ) } -
+
Date: Wed, 16 Aug 2023 15:58:22 -0400 Subject: [PATCH 054/123] standardize creation of html in Templating class --- blocks/blocks.php | 2 + .../class-cap-block-coauthor-avatar.php | 86 ++++++++----------- .../class-cap-block-coauthor-description.php | 4 +- .../class-cap-block-coauthor-display-name.php | 24 +++--- ...class-cap-block-coauthor-feature-image.php | 64 +++++--------- .../coauthors/class-cap-block-coauthors.php | 37 +++----- blocks/templating/class-templating.php | 84 ++++++++++++++++++ 7 files changed, 173 insertions(+), 128 deletions(-) create mode 100644 blocks/templating/class-templating.php diff --git a/blocks/blocks.php b/blocks/blocks.php index 5305fedf..570c5635 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -1,4 +1,6 @@ "{$url} {$size}w", - array_values( $avatar_urls ), - array_keys( $avatar_urls ) + fn( $size, $url ) => "{$url} {$size}w", + array_keys( $avatar_urls ), + array_values( $avatar_urls ) ); - $attr = get_block_core_post_featured_image_border_attributes( $attributes ); - - $image = sprintf( - '', - $avatar_urls[$size], - $size, - $size, - "{$size}px", - implode( ', ', $srcset), - $attr['style'] ?? '', - $attr['class'] ?? '' + $image_attributes = Templating::render_attributes( + array_merge( + get_block_core_post_featured_image_border_attributes( $attributes ), + array( + 'src' => $avatar_urls[$size], + 'width' => $size, + 'height' => $size, + 'sizes' => "{$size}px", + 'srcset' => implode( ', ', $srcset), + ) + ) ); - $rel = $attributes['rel'] ?? ''; + $image = Templating::render_self_closing_element( + 'img', + $image_attributes + ); - $inner_content = $is_link ? self::add_link( $link, $image, $rel ) : $image; + if ( $is_link ) { + $link_attributes = Templating::render_attributes( + array( + 'href' => $link, + 'rel' => $rel, + 'title' => sprintf( __( 'Posts by %s', 'co-authors-plus' ), $display_name ), + ) + ); + $inner_content = Templating::render_element('a', $link_attributes, $image); + } else { + $inner_content = $image; + } - return self::get_block_wrapper_function( + return Templating::render_element( 'figure', - get_block_wrapper_attributes() - )( $inner_content ); - } - - /** - * Add Link - * - * @param string $link - * @param string $content - * @param null|string $rel - * @return string - */ - public static function add_link( string $link, string $content, ?string $rel = '' ) : string { - return sprintf( - '%s', - $link, - $rel, - $content + get_block_wrapper_attributes(), + $inner_content ); } - - /** - * Get Block Wrapper Function - * - * @param string $element_name - * @param string $attributes - * @return callable - */ - private static function get_block_wrapper_function( string $element_name, string $attributes ) : callable { - return function( string $content ) use ( $element_name, $attributes ) : string { - return "<{$element_name} {$attributes}>{$content}"; - }; - } } diff --git a/blocks/coauthor-description/class-cap-block-coauthor-description.php b/blocks/coauthor-description/class-cap-block-coauthor-description.php index e0c7554f..91fa79ae 100644 --- a/blocks/coauthor-description/class-cap-block-coauthor-description.php +++ b/blocks/coauthor-description/class-cap-block-coauthor-description.php @@ -48,8 +48,8 @@ public static function render_block( array $attributes, string $content, WP_Bloc return ''; } - return sprintf( - '
%s
', + return Templating::render_element( + 'div', get_block_wrapper_attributes( self::get_custom_block_wrapper_attributes( $attributes ) ), diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index 0d3062b7..9829c273 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -48,24 +48,24 @@ public static function render_block( array $attributes, string $content, WP_Bloc return ''; } - $link = $author['link'] ?? ''; - $is_link = '' !== $link && $attributes['isLink'] ?? false; - $rel = $attributes['rel'] ?? ''; + $link = $author['link'] ?? ''; + $rel = $attributes['rel'] ?? ''; - if ( $is_link ) { - $inner_content = sprintf( - '%s', - $rel, - $link, - sprintf( __( 'Posts by %s', 'co-authors-plus' ), $display_name ), - $display_name + if ( '' !== $link && true === $attributes['isLink'] ) { + $link_attributes = Templating::render_attributes( + array( + 'href' => $link, + 'rel' => $rel, + 'title' => sprintf( __( 'Posts by %s', 'co-authors-plus' ), $display_name ), + ) ); + $inner_content = Templating::render_element( 'a', $link_attributes, $display_name ); } else { $inner_content = $display_name; } - return sprintf( - '

%s

', + return Templating::render_element( + 'p', get_block_wrapper_attributes( self::get_custom_block_wrapper_attributes( $attributes ) ), diff --git a/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php b/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php index b840ed25..30150d4b 100644 --- a/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php +++ b/blocks/coauthor-feature-image/class-cap-block-coauthor-feature-image.php @@ -43,6 +43,8 @@ public static function render_block( array $attributes, string $content, WP_Bloc } $featured_media_id = absint( $author['featured_media'] ?? 0 ); + $display_name = $author['display_name'] ?? ''; + $link = $author['link'] ?? ''; if ( 0 === $featured_media_id ) { return ''; @@ -65,38 +67,27 @@ public static function render_block( array $attributes, string $content, WP_Bloc $attributes['width'] = 'auto'; } - $style_attribute_map = array( - array( - 'prop' => 'width', - 'attr' => 'width' - ), - array( - 'prop' => 'height', - 'attr' => 'height' - ), - array( - 'prop' => 'object-fit', - 'attr' => 'scale' - ), - array( - 'prop' => 'aspect-ratio', - 'attr' => 'aspectRatio' - ) + $style_attribute_key_map = array( + 'width' => 'width', + 'height' => 'height', + 'scale' => 'object-fit', + 'aspectRatio' => 'aspect-ratio', ); $styles = array_map( - function( $style ) use ( $attributes ) : string { - if ( empty( $attributes[$style['attr']] ) ) { + function( string $key, string $style ) use ( $attributes ) : string { + if ( empty( $attributes[$key] ) ) { return ''; } return sprintf( "%s;", safecss_filter_attr( - "{$style['prop']}:{$attributes[$style['attr']]}" + "{$style}:{$attributes[$key]}" ) ); }, - $style_attribute_map + array_keys( $style_attribute_key_map ), + array_values( $style_attribute_key_map ) ); $image_attributes = array_merge( @@ -108,31 +99,22 @@ function( $style ) use ( $attributes ) : string { ); $image_attributes['style'] .= implode( '', $styles ); - $wrapper_attributes = get_block_wrapper_attributes(); + $feature_image = wp_get_attachment_image( $featured_media_id, $attributes['sizeSlug'], false, $image_attributes ); - if ( true === $attributes['isLink'] ) { - $inner_content = self::add_link( $author['link'], $feature_image, $attributes['rel'] ); + if ( '' !== $link && true === $attributes['isLink'] ) { + $link_attributes = Templating::render_attributes( + array( + 'href' => $author['link'], + 'rel' => $attributes['rel'], + 'title' => sprintf( __( 'Posts by %s', 'co-authors-plus' ), $display_name ), + ) + ); + $inner_content = Templating::render_element( 'a', $link_attributes, $feature_image ); } else { $inner_content = $feature_image; } - return "
{$inner_content}
"; - } - /** - * Add Link - * - * @param string $link - * @param string $content - * @param null|string $rel - * @return string - */ - public static function add_link( string $link, string $content, ?string $rel = '' ) : string { - return sprintf( - '%s', - $link, - $rel, - $content - ); + return Templating::render_element( 'figure', get_block_wrapper_attributes(), $inner_content ); } } diff --git a/blocks/coauthors/class-cap-block-coauthors.php b/blocks/coauthors/class-cap-block-coauthors.php index 337221ca..cd5fca21 100644 --- a/blocks/coauthors/class-cap-block-coauthors.php +++ b/blocks/coauthors/class-cap-block-coauthors.php @@ -120,10 +120,7 @@ public static function render_prefix( string $prefix ) : string { if ( empty( $prefix ) ) { return $prefix; } - return self::get_block_wrapper_function( - 'span', - 'class="wp-block-cap-coauthor__prefix"' - )( $prefix ); + return Templating::render_element('span', 'class="wp-block-cap-coauthor__prefix"', $prefix); } /** @@ -136,10 +133,7 @@ public static function render_suffix( string $suffix ) : string { if ( empty( $suffix ) ) { return $suffix; } - return self::get_block_wrapper_function( - 'span', - 'class="wp-block-cap-coauthor__suffix"' - )( $suffix ); + return Templating::render_element('span', 'class="wp-block-cap-coauthor__suffix"', $suffix); } /** @@ -157,7 +151,7 @@ public static function render_coauthor_blocks_with_template( array $template, ar fn( $content ) => str_replace("\n", '', $content ), // To match JSX from editor, trim whitespace around blocks. 'trim', - self::get_block_wrapper_function('div', 'class="wp-block-cap-coauthor"') + Templating::get_render_element_function('div', 'class="wp-block-cap-coauthor"') ), $authors ); @@ -219,7 +213,11 @@ private static function get_separator( array $attributes ) : string { return $separator; } - return "{$separator}"; + return Templating::render_element( + 'span', + 'class="wp-block-cap-coauthor__separator"', + $separator + ); } /** @@ -237,20 +235,11 @@ private static function get_last_separator( array $attributes, string $default ) return $default; } - return "{$last_separator}"; - } - - /** - * Get Block Wrapper Function - * - * @param string $element_name - * @param string $attributes - * @return callable - */ - private static function get_block_wrapper_function( string $element_name, string $attributes ) : callable { - return function( string $content ) use ( $element_name, $attributes ) : string { - return "<{$element_name} {$attributes}>{$content}"; - }; + return Templating::render_element( + 'span', + 'class="wp-block-cap-coauthor__separator"', + $last_separator + ); } /** diff --git a/blocks/templating/class-templating.php b/blocks/templating/class-templating.php new file mode 100644 index 00000000..613b04d6 --- /dev/null +++ b/blocks/templating/class-templating.php @@ -0,0 +1,84 @@ +{$content}"; + } + + /** + * Get Render Element Function + * Dependency inject render_element so you can use in array_map or add_filter. + * + * @param string $name + * @param null|string $attributes + * @return callable + */ + public static function get_render_element_function( string $name, ?string $attributes = '' ) : callable { + return function( string $content ) use ( $name, $attributes ) : string { + return self::render_element( $name, $attributes, $content ); + }; + } + + /** + * Render Self Closing Element + * + * @param string $name + * @param null|string $attributes + * @return string + */ + public static function render_self_closing_element( string $name, ?string $attributes = '' ) : string { + return "<{$name} $attributes/>"; + } + + /** + * Render Attribute String + * + * @param string|int $key Attribute key. + * @param mixed $value Attribute value. For boolean attributes, set value the same as the key. + * @return string + */ + public static function render_attribute_string( string|int $key, $value ) : string { + if ( empty( $value ) ) { + return ''; + } + if ( $key === $value ) { + return $key; + } + return sprintf( '%s="%s"', $key, esc_attr( $value ) ); + } + + /** + * Render Attributes + * + * @param array $attributes An associative array of attributes and their values. + */ + public static function render_attributes( array $attributes ) : string { + + $attribute_strings = array_map( + array( __CLASS__, 'render_attribute_string' ), + array_keys( $attributes ), + array_values( $attributes ) + ); + + $validated_attribute_strings = array_values( + array_filter( + $attribute_strings, + function( $value ) { + return is_string( $value ) && '' !== $value; + } + ) + ); + + return implode( ' ', $validated_attribute_strings ); + } +} \ No newline at end of file From c418f57a865e6d6dd8b99c1b8143736f0510c2cb Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 16 Aug 2023 16:09:10 -0400 Subject: [PATCH 055/123] try to fix error in test with enqueue assets --- blocks/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/blocks.php b/blocks/blocks.php index 570c5635..5b64f547 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -67,7 +67,7 @@ function coauthors_blocks_provide_author_archive_context( array $context, array * Enqueue Store */ function coauthors_blocks_enqueue_store() : void { - $asset = require_once dirname( __FILE__ ) . '/store/build/index.asset.php'; + $asset = require dirname( __FILE__ ) . '/store/build/index.asset.php'; wp_enqueue_script( 'coauthors-blocks-store', From 1835bae19fb4e2e97051b9f370d7038ec7ed0f58 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 16 Aug 2023 16:22:47 -0400 Subject: [PATCH 056/123] Only do author context in WP 5.9 and above --- blocks/blocks.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/blocks/blocks.php b/blocks/blocks.php index 5b64f547..4dfcc134 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -61,7 +61,15 @@ function coauthors_blocks_provide_author_archive_context( array $context, array 'cap/author' => $author ); } -add_action( 'render_block_context', 'coauthors_blocks_provide_author_archive_context', 10, 3 ); +/** + * Need $parent_block which was added in 5.9 + * + * @link https://developer.wordpress.org/reference/hooks/render_block_context/ + */ +if ( is_wp_version_compatible( '5.9' ) ) { + add_action( 'render_block_context', 'coauthors_blocks_provide_author_archive_context', 10, 3 ); +} + /** * Enqueue Store From 25401fa226096d308b6ae180ac104c81149534c9 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 17 Aug 2023 10:23:14 -0400 Subject: [PATCH 057/123] allow choosing a tagName for display name --- blocks/coauthor-display-name/build/block.json | 4 +++ .../build/index.asset.php | 2 +- blocks/coauthor-display-name/build/index.js | 2 +- .../class-cap-block-coauthor-display-name.php | 28 +++++++++++++++--- blocks/coauthor-display-name/src/block.json | 4 +++ blocks/coauthor-display-name/src/edit.js | 29 ++++++++++++++++--- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/blocks/coauthor-display-name/build/block.json b/blocks/coauthor-display-name/build/block.json index a37efad7..ed3d9151 100644 --- a/blocks/coauthor-display-name/build/block.json +++ b/blocks/coauthor-display-name/build/block.json @@ -47,6 +47,10 @@ "type": "string", "default": "author" }, + "tagName": { + "type": "string", + "default": "p" + }, "textAlign": { "type": "string" } diff --git a/blocks/coauthor-display-name/build/index.asset.php b/blocks/coauthor-display-name/build/index.asset.php index c84d6307..51b11d6b 100644 --- a/blocks/coauthor-display-name/build/index.asset.php +++ b/blocks/coauthor-display-name/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'b0522d9b4feffa65c1b3'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '9c6f99fae12200ce4625'); diff --git a/blocks/coauthor-display-name/build/index.js b/blocks/coauthor-display-name/build/index.js index 5e87fd92..9f5298cb 100644 --- a/blocks/coauthor-display-name/build/index.js +++ b/blocks/coauthor-display-name/build/index.js @@ -1 +1 @@ -!function(){var e={779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),d=n["cap/author"]||g,{link:m,display_name:w}=d;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:f,onChange:e=>{u({textAlign:e})}})),(0,t.createElement)("p",(0,r.useBlockProps)({className:c()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:m,rel:p,onClick:e=>e.preventDefault()},w):w),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,l.__)("Settings")},(0,t.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make coauthor name a link"),onChange:()=>u({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(o.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:p,onChange:e=>u({rel:e})})))))}})}()}(); \ No newline at end of file +!function(){var e={779:function(e,t){var n;!function(){"use strict";var l={}.hasOwnProperty;function r(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),m=n["cap/author"]||g,{link:v,display_name:d}=m,b=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.BlockControls,null,(0,t.createElement)(l.AlignmentControl,{value:f,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)(b,(0,l.useBlockProps)({className:u()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:v,rel:p,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(l.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,a.__)("Settings")},(0,t.createElement)(r.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Make coauthor name a link"),onChange:()=>c({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:p,onChange:e=>c({rel:e})})))),(0,t.createElement)(l.InspectorControls,{group:"advanced"},(0,t.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("HTML element"),options:[{label:(0,a.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>c({tagName:e})})))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php index 9829c273..d320e692 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php @@ -43,19 +43,27 @@ public static function render_block( array $attributes, string $content, WP_Bloc } $display_name = $author['display_name'] ?? ''; + $link = $author['link'] ?? ''; if ( '' === $display_name ) { return ''; } - $link = $author['link'] ?? ''; - $rel = $attributes['rel'] ?? ''; + $attributes = array_merge( + array( + 'isLink' => false, + 'rel' => '', + 'tagName' => 'p', + 'textAlign' => '', + ), + $attributes + ); if ( '' !== $link && true === $attributes['isLink'] ) { $link_attributes = Templating::render_attributes( array( 'href' => $link, - 'rel' => $rel, + 'rel' => $attributes['rel'], 'title' => sprintf( __( 'Posts by %s', 'co-authors-plus' ), $display_name ), ) ); @@ -64,8 +72,10 @@ public static function render_block( array $attributes, string $content, WP_Bloc $inner_content = $display_name; } + $tag_name = self::sanitize_tag_name( $attributes['tagName'] ); + return Templating::render_element( - 'p', + $tag_name, get_block_wrapper_attributes( self::get_custom_block_wrapper_attributes( $attributes ) ), @@ -73,6 +83,16 @@ public static function render_block( array $attributes, string $content, WP_Bloc ); } + /** + * Sanitize Tag Name + */ + public static function sanitize_tag_name( string $tag_name ) : string { + if ( in_array( $tag_name, array_keys( wp_kses_allowed_html('post') ), true ) ) { + return $tag_name; + } + return 'p'; + } + /** * Get Custom Block Wrapper Attributes * diff --git a/blocks/coauthor-display-name/src/block.json b/blocks/coauthor-display-name/src/block.json index aec2e661..69b0953b 100644 --- a/blocks/coauthor-display-name/src/block.json +++ b/blocks/coauthor-display-name/src/block.json @@ -47,6 +47,10 @@ "type": "string", "default": "author" }, + "tagName": { + "type": "string", + "default": "p" + }, "textAlign": { "type": "string" } diff --git a/blocks/coauthor-display-name/src/edit.js b/blocks/coauthor-display-name/src/edit.js index 19c6df7f..4ab3da36 100644 --- a/blocks/coauthor-display-name/src/edit.js +++ b/blocks/coauthor-display-name/src/edit.js @@ -11,7 +11,7 @@ import { BlockControls, store as blockEditorStore } from '@wordpress/block-editor'; -import { TextControl, PanelBody, ToggleControl } from '@wordpress/components'; +import { TextControl, PanelBody, ToggleControl, SelectControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import classnames from 'classnames'; @@ -26,11 +26,13 @@ import classnames from 'classnames'; */ export default function Edit( { context, attributes, setAttributes } ) { - const { isLink, rel, textAlign } = attributes; + const { isLink, rel, tagName, textAlign } = attributes; const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); const author = context['cap/author'] || authorPlaceholder; const { link, display_name } = author; + const TagName = tagName; + return ( <> @@ -41,7 +43,7 @@ export default function Edit( { context, attributes, setAttributes } ) { } } /> -

+ { isLink ? ( ) : display_name } -

+ + + )' ), value: 'p' }, + { label: '', value: 'span' }, + { label: '

', value: 'h1' }, + { label: '

', value: 'h2' }, + { label: '

', value: 'h3' }, + { label: '

', value: 'h4' }, + { label: '

', value: 'h5' }, + { label: '
', value: 'h6' }, + ] } + value={ tagName } + onChange={ (value) => setAttributes( {tagName: value}) } + // help={ htmlElementMessages[ tagName ] } + /> + ); } From b11890819581119f90bfbc7bf268642815a54c44 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 17 Aug 2023 11:52:18 -0400 Subject: [PATCH 058/123] add control for verticalAlign to both image blocks --- blocks/coauthor-avatar/build/block.json | 3 ++ blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- blocks/coauthor-avatar/build/style-index.css | 2 +- blocks/coauthor-avatar/src/block.json | 3 ++ blocks/coauthor-avatar/src/edit.js | 37 +++++++++++++++---- blocks/coauthor-avatar/src/style.css | 4 ++ .../coauthor-feature-image/build/block.json | 3 ++ .../build/index.asset.php | 2 +- blocks/coauthor-feature-image/build/index.js | 2 +- .../build/style-index.css | 2 +- ...class-cap-block-coauthor-feature-image.php | 24 ++++++------ blocks/coauthor-feature-image/src/block.json | 3 ++ blocks/coauthor-feature-image/src/edit.js | 30 +++++++++++++-- blocks/coauthor-feature-image/src/index.js | 8 +--- blocks/coauthor-feature-image/src/save.js | 24 ------------ blocks/coauthor-feature-image/src/style.scss | 5 ++- 17 files changed, 97 insertions(+), 59 deletions(-) delete mode 100644 blocks/coauthor-feature-image/src/save.js diff --git a/blocks/coauthor-avatar/build/block.json b/blocks/coauthor-avatar/build/block.json index 3905451d..95f36394 100644 --- a/blocks/coauthor-avatar/build/block.json +++ b/blocks/coauthor-avatar/build/block.json @@ -44,6 +44,9 @@ }, "rel": { "type": "string" + }, + "verticalAlign": { + "type": "string" } }, "textdomain": "coauthor-avatar", diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index 3c9153a7..6eaa011e 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '7d7c7bd6275b8594e952'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '1321f56562865632e450'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index 6c29cb3d..fafe3f88 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){var e,t={756:function(e,t,n){"use strict";var r=window.wp.blocks,o=window.wp.element,i=(n(779),window.wp.i18n),a=window.wp.blockEditor,l=window.wp.components,s=window.wp.data;function c(e){let{dimensions:t,style:n,className:r}=e;const a=(0,o.useMemo)((()=>function(e){let{width:t,height:n}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,o.createElement)("img",{alt:(0,i.__)("Placeholder image"),className:r,src:a,style:n,width:t.width,height:t.height})}var u=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,r.registerBlockType)(u.u2,{edit:function(e){var t;let{context:n,attributes:r,setAttributes:u}=e;const{isLink:h,rel:p,size:g}=r,f=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),v=n["cap/author"]||f,{avatar_urls:d}=v;if(!d||0===d.length)return null;const m=Object.keys(d).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,a.__experimentalUseBorderProps)(r),b=null!==(t=d[g])&&void 0!==t?t:"";return(0,o.createElement)(o.Fragment,null,(0,o.createElement)("figure",(0,a.useBlockProps)(),""===b?(0,o.createElement)(c,{className:w.className,dimensions:{width:g,height:g},style:{height:g,width:g,minWidth:"auto",minHeight:"auto",padding:0,...w.style}}):(0,o.createElement)("img",{style:{...w.style},width:g,height:g,src:`${d[g]}`})),(0,o.createElement)(a.InspectorControls,null,(0,o.createElement)(l.PanelBody,{title:(0,i.__)("Avatar Settings")},(0,o.createElement)(l.ToggleControl,{label:(0,i.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!h}),checked:h}),h&&(0,o.createElement)(l.TextControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Link rel"),value:p,onChange:e=>u({rel:e})}),(0,o.createElement)(l.SelectControl,{label:(0,i.__)("Avatar size"),value:g,options:m,onChange:e=>{u({size:Number(e)})}}))))}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t=i)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(l=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[n,o,i]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var o,i,a=n[0],l=n[1],s=n[2],c=0;if(a.some((function(t){return 0!==e[t]}))){for(o in l)r.o(l,o)&&(r.m[o]=l[o]);if(s)var u=s(r)}for(t&&t(n);cfunction(e){let{width:t,height:n}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,l.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:r,src:o,style:n,width:t.width,height:t.height})}var u=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,r.registerBlockType)(u.u2,{edit:function(e){var t;let{context:n,attributes:r,setAttributes:u}=e;const{isLink:p,rel:h,size:v,verticalAlign:g}=r,f=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),d=n["cap/author"]||f,{avatar_urls:m}=d;if(!m||0===m.length)return null;const b=Object.keys(m).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,o.__experimentalUseBorderProps)(r),y=null!==(t=m[v])&&void 0!==t?t:"";return(0,l.createElement)(l.Fragment,null,(0,l.createElement)("figure",(0,o.useBlockProps)(),""===y?(0,l.createElement)(c,{className:w.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:g,...w.style}}):(0,l.createElement)("img",{style:{...w.style,verticalAlign:g},width:v,height:v,src:`${m[v]}`})),(0,l.createElement)(o.InspectorControls,null,(0,l.createElement)(i.PanelBody,{title:(0,a.__)("Avatar Settings")},(0,l.createElement)(i.SelectControl,{label:(0,a.__)("Avatar size"),value:v,options:b,onChange:e=>{u({size:Number(e)})}}),(0,l.createElement)(i.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!p}),checked:p}),p&&(0,l.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:h,onChange:e=>u({rel:e})})),(0,l.createElement)(i.PanelBody,{initialOpen:!1,title:(0,a.__)("Coauthors Layout")},(0,l.createElement)(i.SelectControl,{label:(0,a.__)("Vertical align"),value:g,options:[{value:"",label:"Middle ( Default )"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{u({verticalAlign:""===e?void 0:e})},help:(0,a.__)('Vertical alignment applies when displaying coauthors in the "inline" layout.')}))))}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function l(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,l,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var l,a,o=n[0],i=n[1],s=n[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(l in i)r.o(i,l)&&(r.m[l]=i[l]);if(s)var u=s(r)}for(t&&t(n);c select( 'cap/blocks' ).getAuthorPlaceholder(), []); const author = context['cap/author'] || authorPlaceholder; const { avatar_urls } = author; @@ -52,12 +52,13 @@ export default function Edit( { context, attributes, setAttributes } ) { minWidth: 'auto', minHeight: 'auto', padding: 0, + verticalAlign, ...borderProps.style } } /> ) : ( + { + setAttributes( { + size: Number( nextSize ) + } ); + } } + /> setAttributes( { isLink: ! isLink } ) } @@ -82,15 +93,27 @@ export default function Edit( { context, attributes, setAttributes } ) { } /> ) } + + { + label={ __( 'Vertical align' ) } + value={ verticalAlign } + options={ [ + {value: '', label: 'Middle ( Default )'}, + {value: 'baseline', label: 'Baseline'}, + {value: 'bottom', label: 'Bottom'}, + {value: 'sub', label: 'Sub'}, + {value: 'super', label: 'Super'}, + {value: 'text-bottom', label: 'Text Bottom'}, + {value: 'text-top', label: 'Text Top'}, + {value: 'top', label: 'Top'}, + ] } + onChange={ ( value ) => { setAttributes( { - size: Number( nextSize ) + verticalAlign: '' === value ? undefined : value } ); } } + help={ __( 'Vertical alignment applies when displaying coauthors in the "inline" layout.' )} /> diff --git a/blocks/coauthor-avatar/src/style.css b/blocks/coauthor-avatar/src/style.css index f20f86e8..cfd9cbc5 100644 --- a/blocks/coauthor-avatar/src/style.css +++ b/blocks/coauthor-avatar/src/style.css @@ -1,3 +1,7 @@ +.wp-block-cap-coauthor-avatar:where(figure) { + margin-block-end: 0; +} + .wp-block-cap-coauthor-avatar :where(img) { display: block; } diff --git a/blocks/coauthor-feature-image/build/block.json b/blocks/coauthor-feature-image/build/block.json index 7eb660b7..1bb5c86b 100644 --- a/blocks/coauthor-feature-image/build/block.json +++ b/blocks/coauthor-feature-image/build/block.json @@ -62,6 +62,9 @@ }, "sizeSlug": { "type": "string" + }, + "verticalAlign": { + "type": "string" } }, "textdomain": "coauthor-feature-image", diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php index 720bea9d..2a0d5468 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '2572a193a917764e0740'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '86d86d08e3448b6e2220'); diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js index 1b7cc4e9..d1e1b218 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-feature-image/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={891:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.i18n,i=window.wp.blockEditor,n=window.wp.components,a=window.wp.data,o=window.wp.coreData;const r=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"cover",label:(0,l._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"contain",label:(0,l._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"fill",label:(0,l._x)("Fill","Scale option for Image dimension control")})),s="cover",c={cover:(0,l.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,l.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,l.__)("Image will be stretched and distorted to completely fill the space.")};var h=e=>{let{clientId:a,attributes:{aspectRatio:o,width:h,height:u,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,n.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),w=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},f=(0,l._x)("Scale","Image scaling options"),v=u||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:a},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:a},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:u||"",min:0,onChange:e=>w("height",e),units:_})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:a},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:h||"",min:0,onChange:e=>w("width",e),units:_})),v&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:f,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:a},(0,t.createElement)(n.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:a},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function u(e){let{dimensions:i,style:n,className:a}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:a,src:o,style:n,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:w,scale:f,sizeSlug:v,width:b}=r,x=(0,a.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),S=c["cap/author"]||x,E=(0,a.useSelect)((e=>0!==S.featured_media&&e(o.store).getMedia(S.featured_media,{context:"view"})),[S.featured_media]),{imageSizes:C,imageDimensions:k}=(0,a.useSelect)((e=>e(i.store).getSettings()),[]),I=C.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),y=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(E,k,v),O=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const n=t[l];if(!0===n.crop||n.width===n.height)return{width:n.width,height:n.height};const a=i.width/i.height;return n.width>n.height?{width:n.width,height:n.width/a}:{width:n.height*a,height:n.height}}(E,k,y),B=E?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,y),N=(0,i.__experimentalUseBorderProps)(r),A=0!==S.id&&!1===E;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(h,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:I}),A?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),E?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:N.className,src:g(E,y),style:{width:!b&&p?"auto":b,height:!p&&b?"auto":p,aspectRatio:d,objectFit:f,...N.style},width:O.width,height:O.height}):(0,t.createElement)(u,{className:N.className,dimensions:B,style:{width:!b&&p?"auto":b,height:!p&&b?"auto":p,aspectRatio:d,objectFit:f,...N.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:(0,l.__)("Settings")},(0,t.createElement)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(n.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:w,onChange:e=>s({rel:e})}))))},save:function(){return(0,t.createElement)("p",i.useBlockProps.save(),"Coauthor Feature Image – hello from the saved content!")}})}},l={};function i(e){var n=l[e];if(void 0!==n)return n.exports;var a=l[e]={exports:{}};return t[e](a,a.exports,i),a.exports}i.m=t,e=[],i.O=function(t,l,n,a){if(!l){var o=1/0;for(h=0;h=a)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,a0&&e[h-1][2]>a;h--)e[h]=e[h-1];e[h]=[l,n,a]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var n,a,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(n in r)i.o(r,n)&&(i.m[n]=r[n]);if(s)var h=s(i)}for(t&&t(l);c{let{clientId:n,attributes:{aspectRatio:o,width:u,height:h,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,a.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),f=h||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:u||"",min:0,onChange:e=>v("width",e),units:_})),f&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:w,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:i,style:a,className:n}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:o,style:a,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:v,scale:w,sizeSlug:f,verticalAlign:b,width:x}=r,S=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,n.useSelect)((e=>0!==E.featured_media&&e(o.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:I}=(0,n.useSelect)((e=>e(i.store).getSettings()),[]),k=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(C,I,f),B=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const a=t[l];if(!0===a.crop||a.width===a.height)return{width:a.width,height:a.height};const n=i.width/i.height;return a.width>a.height?{width:a.width,height:a.width/n}:{width:a.height*n,height:a.height}}(C,I,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(I,O),T=(0,i.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(u,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:k}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:T.className,src:g(C,O),style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:b,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:b,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Feature Image Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:b,options:[{value:"",label:"Middle ( Default )"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)('Vertical alignment applies when displaying coauthors in the "inline" layout.')}))))}})}},l={};function i(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.m=t,e=[],i.O=function(t,l,a,n){if(!l){var o=1/0;for(u=0;u=n)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,n0&&e[u-1][2]>n;u--)e[u]=e[u-1];e[u]=[l,a,n]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)i.o(r,a)&&(i.m[a]=r[a]);if(s)var u=s(i)}for(t&&t(l);c '', - 'height' => '', - 'sizeSlug' => 'thumbnail', - 'scale' => '', - 'aspectRatio' => '', - 'isLink' => false, - 'rel' => '' + 'width' => '', + 'height' => '', + 'sizeSlug' => 'thumbnail', + 'scale' => '', + 'aspectRatio' => '', + 'isLink' => false, + 'rel' => '', + 'verticalAlign' => '', ), $attributes ); @@ -68,10 +69,11 @@ public static function render_block( array $attributes, string $content, WP_Bloc } $style_attribute_key_map = array( - 'width' => 'width', - 'height' => 'height', - 'scale' => 'object-fit', - 'aspectRatio' => 'aspect-ratio', + 'width' => 'width', + 'height' => 'height', + 'scale' => 'object-fit', + 'aspectRatio' => 'aspect-ratio', + 'verticalAlign' => 'vertical-align' ); $styles = array_map( diff --git a/blocks/coauthor-feature-image/src/block.json b/blocks/coauthor-feature-image/src/block.json index d42539fa..846b4120 100644 --- a/blocks/coauthor-feature-image/src/block.json +++ b/blocks/coauthor-feature-image/src/block.json @@ -56,6 +56,9 @@ }, "sizeSlug": { "type": "string" + }, + "verticalAlign": { + "type": "string" } }, "textdomain": "coauthor-feature-image", diff --git a/blocks/coauthor-feature-image/src/edit.js b/blocks/coauthor-feature-image/src/edit.js index d2cb2124..5a09ff8d 100644 --- a/blocks/coauthor-feature-image/src/edit.js +++ b/blocks/coauthor-feature-image/src/edit.js @@ -9,7 +9,7 @@ import { __experimentalUseBorderProps as useBorderProps, InspectorControls, } from '@wordpress/block-editor'; -import { TextControl, PanelBody, ToggleControl } from '@wordpress/components'; +import { TextControl, PanelBody, ToggleControl, SelectControl } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import DimensionControls from './dimension-controls'; @@ -27,7 +27,7 @@ import './editor.scss'; */ export default function Edit( { attributes, setAttributes, context, clientId } ) { - const { aspectRatio, height, isLink, rel, scale, sizeSlug, width } = attributes; + const { aspectRatio, height, isLink, rel, scale, sizeSlug, verticalAlign, width } = attributes; // Author const authorPlaceholder = useSelect( @@ -81,6 +81,7 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) height: ! height && width ? 'auto' : height, aspectRatio, objectFit: scale, + verticalAlign, ...borderProps.style }} width={ dimensions.width } @@ -95,6 +96,7 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) height: ! height && width ? 'auto' : height, aspectRatio, objectFit: scale, + verticalAlign, ...borderProps.style }} /> @@ -104,7 +106,7 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) ) } - + ) } + + { + setAttributes( { + verticalAlign: '' === value ? undefined : value + } ); + } } + help={ __( 'Vertical alignment applies when displaying coauthors in the "inline" layout.' )} + /> + ); diff --git a/blocks/coauthor-feature-image/src/index.js b/blocks/coauthor-feature-image/src/index.js index ade1e478..70099106 100644 --- a/blocks/coauthor-feature-image/src/index.js +++ b/blocks/coauthor-feature-image/src/index.js @@ -18,7 +18,6 @@ import './style.scss'; * Internal dependencies */ import Edit from './edit'; -import save from './save'; import metadata from './block.json'; /** @@ -30,10 +29,5 @@ registerBlockType( metadata.name, { /** * @see ./edit.js */ - edit: Edit, - - /** - * @see ./save.js - */ - save, + edit: Edit } ); diff --git a/blocks/coauthor-feature-image/src/save.js b/blocks/coauthor-feature-image/src/save.js deleted file mode 100644 index 350d12a8..00000000 --- a/blocks/coauthor-feature-image/src/save.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * React hook that is used to mark the block wrapper element. - * It provides all the necessary props like the class name. - * - * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops - */ -import { useBlockProps } from '@wordpress/block-editor'; - -/** - * The save function defines the way in which the different attributes should - * be combined into the final markup, which is then serialized by the block - * editor into `post_content`. - * - * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save - * - * @return {WPElement} Element to render. - */ -export default function save() { - return ( -

- { 'Coauthor Feature Image – hello from the saved content!' } -

- ); -} diff --git a/blocks/coauthor-feature-image/src/style.scss b/blocks/coauthor-feature-image/src/style.scss index 6297261a..2ace1120 100644 --- a/blocks/coauthor-feature-image/src/style.scss +++ b/blocks/coauthor-feature-image/src/style.scss @@ -18,6 +18,9 @@ } .wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-feature-image { - display: inline-flex; + display: inline; +} + +.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-feature-image :where(img) { vertical-align: middle; } From 20d72285d957a652dd7b5e9ff8458ddddbb140c8 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 17 Aug 2023 14:51:18 -0400 Subject: [PATCH 059/123] alignment support more consistent with image block --- blocks/coauthor-avatar/build/block.json | 5 ++++ blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- blocks/coauthor-avatar/build/style-index.css | 2 +- blocks/coauthor-avatar/src/block.json | 4 +-- blocks/coauthor-avatar/src/edit.js | 11 ++++---- blocks/coauthor-avatar/src/style.css | 28 +++++++++++++++++-- .../build/index.asset.php | 2 +- blocks/coauthor-feature-image/build/index.css | 1 - blocks/coauthor-feature-image/build/index.js | 2 +- .../build/style-index.css | 2 +- blocks/coauthor-feature-image/src/edit.js | 7 ++--- blocks/coauthor-feature-image/src/editor.scss | 14 ---------- blocks/coauthor-feature-image/src/index.js | 2 +- .../src/{style.scss => style.css} | 24 ++++++++++++---- 15 files changed, 66 insertions(+), 42 deletions(-) delete mode 100644 blocks/coauthor-feature-image/build/index.css delete mode 100644 blocks/coauthor-feature-image/src/editor.scss rename blocks/coauthor-feature-image/src/{style.scss => style.css} (56%) diff --git a/blocks/coauthor-avatar/build/block.json b/blocks/coauthor-avatar/build/block.json index 95f36394..aaf6e3fc 100644 --- a/blocks/coauthor-avatar/build/block.json +++ b/blocks/coauthor-avatar/build/block.json @@ -8,6 +8,11 @@ "icon": "smiley", "description": "Display a co-author's avatar", "supports": { + "align": [ + "left", + "right", + "center" + ], "html": false, "__experimentalBorder": { "color": true, diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index 6eaa011e..dfaeeeda 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '1321f56562865632e450'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'aba2433cf5fd24ea7dbf'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index fafe3f88..493ea7ec 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){var e,t={756:function(e,t,n){"use strict";var r=window.wp.blocks,l=window.wp.element,a=(n(779),window.wp.i18n),o=window.wp.blockEditor,i=window.wp.components,s=window.wp.data;function c(e){let{dimensions:t,style:n,className:r}=e;const o=(0,l.useMemo)((()=>function(e){let{width:t,height:n}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,l.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:r,src:o,style:n,width:t.width,height:t.height})}var u=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,r.registerBlockType)(u.u2,{edit:function(e){var t;let{context:n,attributes:r,setAttributes:u}=e;const{isLink:p,rel:h,size:v,verticalAlign:g}=r,f=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),d=n["cap/author"]||f,{avatar_urls:m}=d;if(!m||0===m.length)return null;const b=Object.keys(m).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,o.__experimentalUseBorderProps)(r),y=null!==(t=m[v])&&void 0!==t?t:"";return(0,l.createElement)(l.Fragment,null,(0,l.createElement)("figure",(0,o.useBlockProps)(),""===y?(0,l.createElement)(c,{className:w.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:g,...w.style}}):(0,l.createElement)("img",{style:{...w.style,verticalAlign:g},width:v,height:v,src:`${m[v]}`})),(0,l.createElement)(o.InspectorControls,null,(0,l.createElement)(i.PanelBody,{title:(0,a.__)("Avatar Settings")},(0,l.createElement)(i.SelectControl,{label:(0,a.__)("Avatar size"),value:v,options:b,onChange:e=>{u({size:Number(e)})}}),(0,l.createElement)(i.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!p}),checked:p}),p&&(0,l.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:h,onChange:e=>u({rel:e})})),(0,l.createElement)(i.PanelBody,{initialOpen:!1,title:(0,a.__)("Coauthors Layout")},(0,l.createElement)(i.SelectControl,{label:(0,a.__)("Vertical align"),value:g,options:[{value:"",label:"Middle ( Default )"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{u({verticalAlign:""===e?void 0:e})},help:(0,a.__)('Vertical alignment applies when displaying coauthors in the "inline" layout.')}))))}})},779:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function l(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,l,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var l,a,o=n[0],i=n[1],s=n[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(l in i)r.o(i,l)&&(r.m[l]=i[l]);if(s)var u=s(r)}for(t&&t(n);cfunction(e){let{width:t,height:n}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,r.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:l,src:o,style:n,width:t.width,height:t.height})}var u=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,l.registerBlockType)(u.u2,{edit:function(e){var t;let{context:n,attributes:l,setAttributes:u}=e;const{isLink:p,rel:h,size:v,verticalAlign:g}=l,d=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),f=n["cap/author"]||d,{avatar_urls:m}=f;if(!m||0===m.length)return null;const b=Object.keys(m).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,o.__experimentalUseBorderProps)(l),y=null!==(t=m[v])&&void 0!==t?t:"";return(0,r.createElement)(r.Fragment,null,(0,r.createElement)("figure",(0,o.useBlockProps)(),""===y?(0,r.createElement)(c,{className:w.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:g,...w.style}}):(0,r.createElement)("img",{style:{...w.style,verticalAlign:g},width:v,height:v,src:`${m[v]}`})),(0,r.createElement)(o.InspectorControls,null,(0,r.createElement)(i.PanelBody,{title:(0,a.__)("Avatar Settings")},(0,r.createElement)(i.SelectControl,{label:(0,a.__)("Avatar size"),value:v,options:b,onChange:e=>{u({size:Number(e)})}}),(0,r.createElement)(i.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!p}),checked:p}),p&&(0,r.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:h,onChange:e=>u({rel:e})})),(0,r.createElement)(i.PanelBody,{initialOpen:!1,title:(0,a.__)("Coauthors Layout")},(0,r.createElement)(i.SelectControl,{label:(0,a.__)("Vertical align"),value:g,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{u({verticalAlign:""===e?void 0:e})},help:(0,a.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})},779:function(e,t){var n;!function(){"use strict";var l={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(l.O).every((function(e){return l.O[e](n[s])}))?n.splice(s--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},l.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};l.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,o=n[0],i=n[1],s=n[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(r in i)l.o(i,r)&&(l.m[r]=i[r]);if(s)var u=s(l)}for(t&&t(n);c - diff --git a/blocks/coauthor-avatar/src/style.css b/blocks/coauthor-avatar/src/style.css index cfd9cbc5..ae778a99 100644 --- a/blocks/coauthor-avatar/src/style.css +++ b/blocks/coauthor-avatar/src/style.css @@ -1,11 +1,33 @@ -.wp-block-cap-coauthor-avatar:where(figure) { - margin-block-end: 0; +/* Default Layout */ + +.wp-block-cap-coauthor-avatar { + margin-bottom: 0; } .wp-block-cap-coauthor-avatar :where(img) { - display: block; + height: auto; + max-width: 100%; + vertical-align: bottom; +} + +/* Inline Layout */ + +.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-avatar { + display: inline; } .wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-avatar :where(img) { vertical-align: middle; } + +/* Align wide, full */ + +.wp-block-cap-coauthor-avatar:is(.alignfull,.alignwide) :where(img) { + width: 100%; +} + +/* Align left, right, center */ + +.wp-block-cap-coauthor-avatar:is(.alignleft,.alignright,.aligncenter) { + display: table; +} \ No newline at end of file diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-feature-image/build/index.asset.php index 2a0d5468..d7d7c714 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-feature-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '86d86d08e3448b6e2220'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a3bbf694533a78c1f79e'); diff --git a/blocks/coauthor-feature-image/build/index.css b/blocks/coauthor-feature-image/build/index.css deleted file mode 100644 index 8b137891..00000000 --- a/blocks/coauthor-feature-image/build/index.css +++ /dev/null @@ -1 +0,0 @@ - diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-feature-image/build/index.js index d1e1b218..7c4f9cd0 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-feature-image/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={983:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.i18n,i=window.wp.blockEditor,a=window.wp.components,n=window.wp.data,o=window.wp.coreData;const r=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"cover",label:(0,l._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"contain",label:(0,l._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"fill",label:(0,l._x)("Fill","Scale option for Image dimension control")})),s="cover",c={cover:(0,l.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,l.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,l.__)("Image will be stretched and distorted to completely fill the space.")};var u=e=>{let{clientId:n,attributes:{aspectRatio:o,width:u,height:h,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,a.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),f=h||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:u||"",min:0,onChange:e=>v("width",e),units:_})),f&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:w,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:i,style:a,className:n}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:o,style:a,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:v,scale:w,sizeSlug:f,verticalAlign:b,width:x}=r,S=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,n.useSelect)((e=>0!==E.featured_media&&e(o.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:I}=(0,n.useSelect)((e=>e(i.store).getSettings()),[]),k=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(C,I,f),B=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const a=t[l];if(!0===a.crop||a.width===a.height)return{width:a.width,height:a.height};const n=i.width/i.height;return a.width>a.height?{width:a.width,height:a.width/n}:{width:a.height*n,height:a.height}}(C,I,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(I,O),T=(0,i.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(u,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:k}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:T.className,src:g(C,O),style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:b,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:b,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Feature Image Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:b,options:[{value:"",label:"Middle ( Default )"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)('Vertical alignment applies when displaying coauthors in the "inline" layout.')}))))}})}},l={};function i(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.m=t,e=[],i.O=function(t,l,a,n){if(!l){var o=1/0;for(u=0;u=n)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,n0&&e[u-1][2]>n;u--)e[u]=e[u-1];e[u]=[l,a,n]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)i.o(r,a)&&(i.m[a]=r[a]);if(s)var u=s(i)}for(t&&t(l);c{let{clientId:n,attributes:{aspectRatio:o,width:u,height:h,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,a.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),b=h||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:u||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:w,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:i,style:a,className:n}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:o,style:a,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=r,S=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,n.useSelect)((e=>0!==E.featured_media&&e(o.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,n.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(C,k,b),B=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const a=t[l];if(!0===a.crop||a.width===a.height)return{width:a.width,height:a.height};const n=i.width/i.height;return a.width>a.height?{width:a.width,height:a.width/n}:{width:a.height*n,height:a.height}}(C,k,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,O),T=(0,i.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(u,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:T.className,src:g(C,O),style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Feature Image Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:f,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function i(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.m=t,e=[],i.O=function(t,l,a,n){if(!l){var o=1/0;for(u=0;u=n)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,n0&&e[u-1][2]>n;u--)e[u]=e[u-1];e[u]=[l,a,n]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)i.o(r,a)&&(i.m[a]=r[a]);if(s)var u=s(i)}for(t&&t(l);c diff --git a/blocks/coauthor-feature-image/src/editor.scss b/blocks/coauthor-feature-image/src/editor.scss deleted file mode 100644 index 8c20cfa9..00000000 --- a/blocks/coauthor-feature-image/src/editor.scss +++ /dev/null @@ -1,14 +0,0 @@ -/** - * The following styles get applied inside the editor only. - * - * Replace them with your own styles or remove the file completely. - */ - -.wp-block-cap-coauthor-feature-image { - // border: 1px dotted #f00; -} - -.wp-block-cap-coauthor-feature-image .components-placeholder { - // min-width: auto; - // min-height: auto; -} diff --git a/blocks/coauthor-feature-image/src/index.js b/blocks/coauthor-feature-image/src/index.js index 70099106..5701565a 100644 --- a/blocks/coauthor-feature-image/src/index.js +++ b/blocks/coauthor-feature-image/src/index.js @@ -12,7 +12,7 @@ import { registerBlockType } from '@wordpress/blocks'; * * @see https://www.npmjs.com/package/@wordpress/scripts#using-css */ -import './style.scss'; +import './style.css'; /** * Internal dependencies diff --git a/blocks/coauthor-feature-image/src/style.scss b/blocks/coauthor-feature-image/src/style.css similarity index 56% rename from blocks/coauthor-feature-image/src/style.scss rename to blocks/coauthor-feature-image/src/style.css index 2ace1120..04d19f72 100644 --- a/blocks/coauthor-feature-image/src/style.scss +++ b/blocks/coauthor-feature-image/src/style.css @@ -5,18 +5,20 @@ * Replace them with your own styles or remove the file completely. */ -.wp-block-cap-coauthor-feature-image:where(figure) { - margin-block-end: 0; +/* Default Layout */ + +.wp-block-cap-coauthor-feature-image { + margin-bottom: 0; } .wp-block-cap-coauthor-feature-image :where(img) { - display: block; height: auto; max-width: 100%; - margin-left: auto; - margin-right: auto; + vertical-align: bottom; } +/* Inline Layout */ + .wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-feature-image { display: inline; } @@ -24,3 +26,15 @@ .wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-feature-image :where(img) { vertical-align: middle; } + +/* Align wide, full */ + +.wp-block-cap-coauthor-feature-image:is(.alignfull,.alignwide) :where(img) { + width: 100%; +} + +/* Align left, right, center */ + +.wp-block-cap-coauthor-feature-image:is(.alignleft,.alignright,.aligncenter) { + display: table; +} From 628a051c6de7abfddce2d5c27446011e4b1b23f9 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 17 Aug 2023 14:51:29 -0400 Subject: [PATCH 060/123] start documenting --- blocks/readme.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 blocks/readme.md diff --git a/blocks/readme.md b/blocks/readme.md new file mode 100644 index 00000000..aaabd6c6 --- /dev/null +++ b/blocks/readme.md @@ -0,0 +1,39 @@ +## Layout + +The Coauthors block supports two layouts: + +### Inline + +Inline is it's own layout. It applies `display: inline` to all its contents. + +### Block + +Block does not apply a specific layout. The coauthors stack vertically, and can be spaced apart using block spacing, but that's it. You can create your own layout using any of the other blocks like Group / Row / Stack and it will be applied to each coauthor, similar to laying our each post in a query loop. + +## Context + +### Post, Page, Query Loop + +By default, blocks receive the post context. The job of the Coauthors Block is to use this context to find the relevant authors and provide context to its inner blocks. + +### Author Archive + +In author archive templates, the post context is the first post by the author returned in the main query. Since Co-Authors Plus exists to allow multiple attributed authors, we can't be sure which author of the first post matches the requested author archive. + +If you want to display data about the author on their own archive, use the individual CoAuthor blocks directly without wrapping them in the CoAuthors Block. + +The function `coauthors_blocks_provide_author_archive_context` filters the context using the `author_name` query variable to provide the correct author context. + +### Extending + +If you create a custom block that uses the namespace and prefix `cap/coauthor-`, the author archive context will be updated and will match the REST API response used in the editor. + +If you have a differently named custom block, you can use the filter `coauthor_blocks_block_uses_author_context` to opt-in to the author archive context. + +## Example Data + +When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the coauthor blocks replicates the standard REST API response. + +### Extending + +If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthor_blocks_store_data` or the client-side using the filter `cap.author-placeholder` From 771748c6071eca7522f3068462b1ba79f2a858d3 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 4 Sep 2023 12:48:51 -0400 Subject: [PATCH 061/123] add classnames again after rebase from upstream --- package-lock.json | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/package-lock.json b/package-lock.json index 186408b8..7016509c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "devDependencies": { "@wordpress/icons": "^2.10.2", "@wordpress/scripts": "^24.0.0", + "classnames": "^2.3.2", "prettier": "npm:wp-prettier@^2.2.1-beta-1", "prop-types": "^15.8.1", "version-bump-prompt": "^6.1.0" diff --git a/package.json b/package.json index d19cb236..0a9e695f 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "devDependencies": { "@wordpress/icons": "^2.10.2", "@wordpress/scripts": "^24.0.0", + "classnames": "^2.3.2", "prettier": "npm:wp-prettier@^2.2.1-beta-1", "prop-types": "^15.8.1", "version-bump-prompt": "^6.1.0" From a9abea5f4552fa5d1700bc215befd1b89247ee8b Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 4 Sep 2023 15:43:50 -0400 Subject: [PATCH 062/123] naming conventions --- blocks/blocks.php | 45 +++++++++++-------- blocks/coauthor-avatar/build/index.asset.php | 2 +- blocks/coauthor-avatar/build/index.js | 2 +- ...ar.php => class-block-coauthor-avatar.php} | 7 ++- ...p => class-block-coauthor-description.php} | 10 +++-- blocks/coauthor-display-name/build/index.js | 1 - .../build/style-index.css | 1 - .../build/block.json | 6 +-- .../build/index.asset.php | 2 +- .../build/index.js | 2 +- .../build/style-index.css | 1 + .../build/view.asset.php | 0 .../build/view.js | 0 .../class-block-coauthor-featured-image.php} | 10 +++-- .../package-lock.json | 0 .../package.json | 0 .../src/block.json | 6 +-- .../src/dimension-controls.js | 0 .../src/edit.js | 0 .../src/index.js | 0 .../src/style.css | 12 ++--- .../src/utils.js | 0 .../src/view.js | 0 .../build/block.json | 2 +- .../build/index.asset.php | 2 +- blocks/coauthor-name/build/index.js | 1 + .../class-block-coauthor-name.php} | 10 +++-- .../package.json | 0 .../src/block.json | 2 +- .../src/edit.js | 0 .../src/index.js | 0 blocks/coauthors/build/index.asset.php | 2 +- blocks/coauthors/build/index.js | 2 +- ...oauthors.php => class-block-coauthors.php} | 27 ++++++----- blocks/coauthors/src/edit.js | 10 ++--- blocks/templating/class-templating.php | 4 ++ co-authors-plus.php | 8 ++-- ... => class-coauthors-blocks-controller.php} | 20 ++++----- 38 files changed, 116 insertions(+), 81 deletions(-) rename blocks/coauthor-avatar/{class-cap-block-coauthor-avatar.php => class-block-coauthor-avatar.php} (95%) rename blocks/coauthor-description/{class-cap-block-coauthor-description.php => class-block-coauthor-description.php} (91%) delete mode 100644 blocks/coauthor-display-name/build/index.js delete mode 100644 blocks/coauthor-feature-image/build/style-index.css rename blocks/{coauthor-feature-image => coauthor-featured-image}/build/block.json (90%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/build/index.asset.php (69%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/build/index.js (52%) create mode 100644 blocks/coauthor-featured-image/build/style-index.css rename blocks/{coauthor-feature-image => coauthor-featured-image}/build/view.asset.php (100%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/build/view.js (100%) rename blocks/{coauthor-feature-image/class-cap-block-coauthor-feature-image.php => coauthor-featured-image/class-block-coauthor-featured-image.php} (94%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/package-lock.json (100%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/package.json (100%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/src/block.json (89%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/src/dimension-controls.js (100%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/src/edit.js (100%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/src/index.js (100%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/src/style.css (65%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/src/utils.js (100%) rename blocks/{coauthor-feature-image => coauthor-featured-image}/src/view.js (100%) rename blocks/{coauthor-display-name => coauthor-name}/build/block.json (97%) rename blocks/{coauthor-display-name => coauthor-name}/build/index.asset.php (76%) create mode 100644 blocks/coauthor-name/build/index.js rename blocks/{coauthor-display-name/class-cap-block-coauthor-display-name.php => coauthor-name/class-block-coauthor-name.php} (95%) rename blocks/{coauthor-display-name => coauthor-name}/package.json (100%) rename blocks/{coauthor-display-name => coauthor-name}/src/block.json (97%) rename blocks/{coauthor-display-name => coauthor-name}/src/edit.js (100%) rename blocks/{coauthor-display-name => coauthor-name}/src/index.js (100%) rename blocks/coauthors/{class-cap-block-coauthors.php => class-block-coauthors.php} (91%) rename php/api/endpoints/{class-coauthor-blocks-controller.php => class-coauthors-blocks-controller.php} (94%) diff --git a/blocks/blocks.php b/blocks/blocks.php index 4dfcc134..043fcfd5 100644 --- a/blocks/blocks.php +++ b/blocks/blocks.php @@ -1,17 +1,27 @@ array( 'id' => 0, @@ -107,4 +116,4 @@ function coauthors_blocks_enqueue_store() : void { $data ); } -add_action( 'enqueue_block_editor_assets', 'coauthors_blocks_enqueue_store' ); +add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_store' ); diff --git a/blocks/coauthor-avatar/build/index.asset.php b/blocks/coauthor-avatar/build/index.asset.php index dfaeeeda..f1599ab8 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/blocks/coauthor-avatar/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'aba2433cf5fd24ea7dbf'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'e5bdc99e506c4990d155'); diff --git a/blocks/coauthor-avatar/build/index.js b/blocks/coauthor-avatar/build/index.js index 493ea7ec..dbae5105 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/blocks/coauthor-avatar/build/index.js @@ -1 +1 @@ -!function(){var e,t={756:function(e,t,n){"use strict";var l=window.wp.blocks,r=window.wp.element,a=(n(779),window.wp.i18n),o=window.wp.blockEditor,i=window.wp.components,s=window.wp.data;function c(e){let{dimensions:t,style:n,className:l}=e;const o=(0,r.useMemo)((()=>function(e){let{width:t,height:n}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,r.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:l,src:o,style:n,width:t.width,height:t.height})}var u=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,l.registerBlockType)(u.u2,{edit:function(e){var t;let{context:n,attributes:l,setAttributes:u}=e;const{isLink:p,rel:h,size:v,verticalAlign:g}=l,d=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),f=n["cap/author"]||d,{avatar_urls:m}=f;if(!m||0===m.length)return null;const b=Object.keys(m).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,o.__experimentalUseBorderProps)(l),y=null!==(t=m[v])&&void 0!==t?t:"";return(0,r.createElement)(r.Fragment,null,(0,r.createElement)("figure",(0,o.useBlockProps)(),""===y?(0,r.createElement)(c,{className:w.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:g,...w.style}}):(0,r.createElement)("img",{style:{...w.style,verticalAlign:g},width:v,height:v,src:`${m[v]}`})),(0,r.createElement)(o.InspectorControls,null,(0,r.createElement)(i.PanelBody,{title:(0,a.__)("Avatar Settings")},(0,r.createElement)(i.SelectControl,{label:(0,a.__)("Avatar size"),value:v,options:b,onChange:e=>{u({size:Number(e)})}}),(0,r.createElement)(i.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!p}),checked:p}),p&&(0,r.createElement)(i.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:h,onChange:e=>u({rel:e})})),(0,r.createElement)(i.PanelBody,{initialOpen:!1,title:(0,a.__)("Coauthors Layout")},(0,r.createElement)(i.SelectControl,{label:(0,a.__)("Vertical align"),value:g,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{u({verticalAlign:""===e?void 0:e})},help:(0,a.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})},779:function(e,t){var n;!function(){"use strict";var l={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(l.O).every((function(e){return l.O[e](n[s])}))?n.splice(s--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},l.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};l.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,o=n[0],i=n[1],s=n[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(r in i)l.o(i,r)&&(l.m[r]=i[r]);if(s)var u=s(l)}for(t&&t(n);cfunction(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(n)),[n]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:r,src:o,style:a,width:n.width,height:n.height})}var i=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(i.u2,{edit:function(e){var i;let{context:c,attributes:s,setAttributes:u}=e;const{isLink:h,rel:v,size:p,verticalAlign:d}=s,g=(0,r.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),m=c["cap/author"]||g,{avatar_urls:b}=m;if(!b||0===b.length)return null;const f=Object.keys(b).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,n.__experimentalUseBorderProps)(s),k=null!==(i=b[p])&&void 0!==i?i:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,n.useBlockProps)(),""===k?(0,t.createElement)(o,{className:w.className,dimensions:{width:p,height:p},style:{height:p,width:p,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...w.style}}):(0,t.createElement)("img",{style:{...w.style,verticalAlign:d},width:p,height:p,src:`${b[p]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Avatar size"),value:p,options:f,onChange:e=>{u({size:Number(e)})}}),(0,t.createElement)(a.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!h}),checked:h}),h&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>u({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:d,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{u({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function n(e){var a=l[e];if(void 0!==a)return a.exports;var r=l[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.m=t,e=[],n.O=function(t,l,a,r){if(!l){var o=1/0;for(u=0;u=r)&&Object.keys(n.O).every((function(e){return n.O[e](l[c])}))?l.splice(c--,1):(i=!1,r0&&e[u-1][2]>r;u--)e[u]=e[u-1];e[u]=[l,a,r]},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,r,o=l[0],i=l[1],c=l[2],s=0;if(o.some((function(t){return 0!==e[t]}))){for(a in i)n.o(i,a)&&(n.m[a]=i[a]);if(c)var u=c(n)}for(t&&t(l);se("cap/blocks").getAuthorPlaceholder()),[]),m=n["cap/author"]||g,{link:v,display_name:d}=m,b=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.BlockControls,null,(0,t.createElement)(l.AlignmentControl,{value:f,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)(b,(0,l.useBlockProps)({className:u()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:v,rel:p,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(l.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,a.__)("Settings")},(0,t.createElement)(r.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Make coauthor name a link"),onChange:()=>c({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel"),value:p,onChange:e=>c({rel:e})})))),(0,t.createElement)(l.InspectorControls,{group:"advanced"},(0,t.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("HTML element"),options:[{label:(0,a.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>c({tagName:e})})))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-feature-image/build/style-index.css b/blocks/coauthor-feature-image/build/style-index.css deleted file mode 100644 index 3805a8ed..00000000 --- a/blocks/coauthor-feature-image/build/style-index.css +++ /dev/null @@ -1 +0,0 @@ -.wp-block-cap-coauthor-feature-image{margin-bottom:0}.wp-block-cap-coauthor-feature-image :where(img){height:auto;max-width:100%;vertical-align:bottom}.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-feature-image{display:inline}.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-feature-image :where(img){vertical-align:middle}.wp-block-cap-coauthor-feature-image:is(.alignfull,.alignwide) :where(img){width:100%}.wp-block-cap-coauthor-feature-image:is(.alignleft,.alignright,.aligncenter){display:table} diff --git a/blocks/coauthor-feature-image/build/block.json b/blocks/coauthor-featured-image/build/block.json similarity index 90% rename from blocks/coauthor-feature-image/build/block.json rename to blocks/coauthor-featured-image/build/block.json index 1bb5c86b..f3ac35c7 100644 --- a/blocks/coauthor-feature-image/build/block.json +++ b/blocks/coauthor-featured-image/build/block.json @@ -1,12 +1,12 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, - "name": "cap/coauthor-feature-image", + "name": "cap/coauthor-featured-image", "version": "0.1.0", - "title": "Coauthor Feature Image", + "title": "Co-Author Featured Image", "category": "widgets", "icon": "smiley", - "description": "Feature Image from a Guest Author profile.", + "description": "Featured Image from a Guest Author profile.", "supports": { "align": [ "left", diff --git a/blocks/coauthor-feature-image/build/index.asset.php b/blocks/coauthor-featured-image/build/index.asset.php similarity index 69% rename from blocks/coauthor-feature-image/build/index.asset.php rename to blocks/coauthor-featured-image/build/index.asset.php index d7d7c714..2848ff6f 100644 --- a/blocks/coauthor-feature-image/build/index.asset.php +++ b/blocks/coauthor-featured-image/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a3bbf694533a78c1f79e'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '985a000f28e19e79fe0d'); diff --git a/blocks/coauthor-feature-image/build/index.js b/blocks/coauthor-featured-image/build/index.js similarity index 52% rename from blocks/coauthor-feature-image/build/index.js rename to blocks/coauthor-featured-image/build/index.js index 7c4f9cd0..f5539e5b 100644 --- a/blocks/coauthor-feature-image/build/index.js +++ b/blocks/coauthor-featured-image/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={983:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.i18n,i=window.wp.blockEditor,a=window.wp.components,n=window.wp.data,o=window.wp.coreData;const r=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"cover",label:(0,l._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"contain",label:(0,l._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"fill",label:(0,l._x)("Fill","Scale option for Image dimension control")})),s="cover",c={cover:(0,l.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,l.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,l.__)("Image will be stretched and distorted to completely fill the space.")};var u=e=>{let{clientId:n,attributes:{aspectRatio:o,width:u,height:h,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,a.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),b=h||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:u||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:w,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:i,style:a,className:n}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:o,style:a,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-feature-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=r,S=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,n.useSelect)((e=>0!==E.featured_media&&e(o.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,n.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(C,k,b),B=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const a=t[l];if(!0===a.crop||a.width===a.height)return{width:a.width,height:a.height};const n=i.width/i.height;return a.width>a.height?{width:a.width,height:a.width/n}:{width:a.height*n,height:a.height}}(C,k,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,O),T=(0,i.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(u,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:T.className,src:g(C,O),style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Feature Image Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:f,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function i(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.m=t,e=[],i.O=function(t,l,a,n){if(!l){var o=1/0;for(u=0;u=n)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,n0&&e[u-1][2]>n;u--)e[u]=e[u-1];e[u]=[l,a,n]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)i.o(r,a)&&(i.m[a]=r[a]);if(s)var u=s(i)}for(t&&t(l);c{let{clientId:n,attributes:{aspectRatio:o,width:u,height:h,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,a.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),b=h||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:u||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:w,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:i,style:a,className:n}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:o,style:a,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-featured-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=r,S=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,n.useSelect)((e=>0!==E.featured_media&&e(o.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,n.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(C,k,b),B=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const a=t[l];if(!0===a.crop||a.width===a.height)return{width:a.width,height:a.height};const n=i.width/i.height;return a.width>a.height?{width:a.width,height:a.width/n}:{width:a.height*n,height:a.height}}(C,k,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,O),T=(0,i.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(u,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:T.className,src:g(C,O),style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Feature Image Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:f,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function i(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.m=t,e=[],i.O=function(t,l,a,n){if(!l){var o=1/0;for(u=0;u=n)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,n0&&e[u-1][2]>n;u--)e[u]=e[u-1];e[u]=[l,a,n]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)i.o(r,a)&&(i.m[a]=r[a]);if(s)var u=s(i)}for(t&&t(l);c array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '9c6f99fae12200ce4625'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '8f88d663ba1ce7d54409'); diff --git a/blocks/coauthor-name/build/index.js b/blocks/coauthor-name/build/index.js new file mode 100644 index 00000000..5226502f --- /dev/null +++ b/blocks/coauthor-name/build/index.js @@ -0,0 +1 @@ +!function(){var e={779:function(e,t){var n;!function(){"use strict";var l={}.hasOwnProperty;function r(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),m=n["cap/author"]||g,{link:v,display_name:d}=m,b=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.BlockControls,null,(0,t.createElement)(l.AlignmentControl,{value:f,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)(b,(0,l.useBlockProps)({className:u()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:v,rel:p,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(l.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(r.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>c({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:p,onChange:e=>c({rel:e})})))),(0,t.createElement)(l.InspectorControls,{group:"advanced"},(0,t.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("HTML element"),options:[{label:(0,o.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>c({tagName:e})})))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php b/blocks/coauthor-name/class-block-coauthor-name.php similarity index 95% rename from blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php rename to blocks/coauthor-name/class-block-coauthor-name.php index d320e692..14cf2789 100644 --- a/blocks/coauthor-display-name/class-cap-block-coauthor-display-name.php +++ b/blocks/coauthor-name/class-block-coauthor-name.php @@ -1,14 +1,18 @@ array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '992aad811383c5f0a244'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ec17272f585edf49f005'); diff --git a/blocks/coauthors/build/index.js b/blocks/coauthors/build/index.js index 9344efdf..465b1cff 100644 --- a/blocks/coauthors/build/index.js +++ b/blocks/coauthors/build/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,l=window.wp.blockEditor,a=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,v=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),f=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),d=n(779),h=n.n(d);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{a(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,l.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-display-name"]]}))}const g=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:d,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=o,{postId:S}=d,O=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return c()({path:`/coauthor-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(l.store).getBlocks(p))),z=e=>{i({layout:{...E,...e}})},G=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.BlockControls,null,(0,r.createElement)(a.ToolbarGroup,{controls:G}),(0,r.createElement)(l.AlignmentControl,{value:C,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,l.useBlockProps)({className:h()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,l.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),A&&"inline"===E.type&&(m||y)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthor__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const n=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(l.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthor__separator"},k&&n===o.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(m||_)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthor__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(l.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(a.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:x||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:k||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:a,textAlign:i}=o,c={gap:"block"===a.type?(0,l.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=h()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",l.useBlockProps.save({className:s,style:c}),(0,r.createElement)(l.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,r,l]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,l,a=n[0],i=n[1],c=n[2],s=0;if(a.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s{a(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,l.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-name"]]}))}const g=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:d,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=o,{postId:S}=d,O=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return c()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(l.store).getBlocks(p))),z=e=>{i({layout:{...E,...e}})},G=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.BlockControls,null,(0,r.createElement)(a.ToolbarGroup,{controls:G}),(0,r.createElement)(l.AlignmentControl,{value:C,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,l.useBlockProps)({className:h()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,l.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),A&&"inline"===E.type&&(m||y)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const n=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(l.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthors__separator"},k&&n===o.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(m||_)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(l.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(a.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:x||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:k||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:a,textAlign:i}=o,c={gap:"block"===a.type?(0,l.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=h()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",l.useBlockProps.save({className:s,style:c}),(0,r.createElement)(l.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,r,l]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,l,a=n[0],i=n[1],c=n[2],s=0;if(a.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);suser_nicename ) ) @@ -64,7 +71,7 @@ function( stdClass|WP_User $author ) : array { return ''; } - $blocks = self::render_coauthor_blocks_with_template( + $blocks = self::render_coauthors_blocks_with_template( self::get_block_as_template( $block ), $authors ); @@ -120,7 +127,7 @@ public static function render_prefix( string $prefix ) : string { if ( empty( $prefix ) ) { return $prefix; } - return Templating::render_element('span', 'class="wp-block-cap-coauthor__prefix"', $prefix); + return Templating::render_element('span', 'class="wp-block-cap-coauthors__prefix"', $prefix); } /** @@ -133,17 +140,17 @@ public static function render_suffix( string $suffix ) : string { if ( empty( $suffix ) ) { return $suffix; } - return Templating::render_element('span', 'class="wp-block-cap-coauthor__suffix"', $suffix); + return Templating::render_element('span', 'class="wp-block-cap-coauthors__suffix"', $suffix); } /** - * Render CoAuthor Blocks with Template + * Render Co-Authors Blocks with Template * * @param array $template * @param array $authors * @return array */ - public static function render_coauthor_blocks_with_template( array $template, array $authors ) : array { + public static function render_coauthors_blocks_with_template( array $template, array $authors ) : array { return array_map( self::get_composed_map_function( self::get_template_render_function( $template ), @@ -215,7 +222,7 @@ private static function get_separator( array $attributes ) : string { return Templating::render_element( 'span', - 'class="wp-block-cap-coauthor__separator"', + 'class="wp-block-cap-coauthors__separator"', $separator ); } @@ -237,7 +244,7 @@ private static function get_last_separator( array $attributes, string $default ) return Templating::render_element( 'span', - 'class="wp-block-cap-coauthor__separator"', + 'class="wp-block-cap-coauthors__separator"', $last_separator ); } diff --git a/blocks/coauthors/src/edit.js b/blocks/coauthors/src/edit.js index 3f038d78..e0be8ba6 100644 --- a/blocks/coauthors/src/edit.js +++ b/blocks/coauthors/src/edit.js @@ -32,7 +32,7 @@ import MemoizedCoAuthorTemplateBlockPreview from './modules/memoized-coauthor-te function CoAuthorTemplateInnerBlocks () { return
; } @@ -67,7 +67,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is const controller = new AbortController(); apiFetch( { - path: `/coauthor-blocks/v1/coauthors/${postId}/`, + path: `/coauthors-blocks/v1/coauthors/${postId}/`, signal: controller.signal } ) .then( setCoAuthors ) @@ -144,7 +144,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is ( + { ( lastSeparator && index === (all.length - 1) ) ? `${lastSeparator}` : `${separator}` } ) @@ -198,7 +198,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is ( register_routes(); } -add_action( 'rest_api_init', 'cap_register_coauthor_blocks_rest_api_routes' ); +add_action( 'rest_api_init', 'cap_register_coauthors_blocks_rest_api_routes' ); diff --git a/php/api/endpoints/class-coauthor-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php similarity index 94% rename from php/api/endpoints/class-coauthor-blocks-controller.php rename to php/api/endpoints/class-coauthors-blocks-controller.php index 363bf84c..e548daf3 100644 --- a/php/api/endpoints/class-coauthor-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -19,7 +19,7 @@ /** * CoAuthor Blocks */ -class CoAuthor_Blocks_Controller extends WP_REST_Controller { +class CoAuthors_Blocks_Controller extends WP_REST_Controller { /** * Instance of CoAuthors_Plus class @@ -42,7 +42,7 @@ public function __construct( CoAuthors_Plus $coauthors_plus ) { */ public function register_routes() : void { register_rest_route( - 'coauthor-blocks/v1', + 'coauthors-blocks/v1', '/coauthors/(?P[\d]+)', array( 'args' => array( @@ -61,12 +61,12 @@ public function register_routes() : void { ); register_rest_route( - 'coauthor-blocks/v1', + 'coauthors-blocks/v1', '/coauthor/(?P[\d\w-]+)', array( 'args' => array( 'user_nicename' => array( - 'description' => __( 'Nicename / slug for coauthor.' ), + 'description' => __( 'Nicename / slug for co-author.' ), 'type' => 'string', 'validate_callback' => fn( $slug ) => is_string( $slug ), 'sanitize_callback' => fn( $slug ) => sanitize_title( $slug ) @@ -98,7 +98,7 @@ public function get_item( $request ) : WP_REST_Response|WP_Error { if ( ! is_object( $coauthor ) ) { return new WP_Error( 'rest_not_found', - __('Sorry, we could not find that coauthor.'), + __('Sorry, we could not find that co-author.'), array( 'status' => 404 ) ); } @@ -167,7 +167,7 @@ public function get_item_permission_check( WP_REST_Request $request ) : bool|WP_ return new WP_Error( 'rest_cannot_view', - __( 'Sorry, you are not allowed to view coauthors.' ), + __( 'Sorry, you are not allowed to view co-authors.' ), array( 'status' => rest_authorization_required_code() ) ); } @@ -192,7 +192,7 @@ public function get_items_permission_check( WP_REST_Request $request ) : bool|WP return new WP_Error( 'rest_cannot_view', - __( 'Sorry, you are not allowed to view coauthors of this post.' ), + __( 'Sorry, you are not allowed to view co-authors of this post.' ), array( 'status' => rest_authorization_required_code() ) ); } @@ -210,7 +210,7 @@ public function get_item_schema() : array { $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'coauthor-block', + 'title' => 'coauthors-block', 'type' => 'object', 'properties' => array( 'id' => array( @@ -278,7 +278,7 @@ public function get_item_schema() : array { // Take a snapshot of which fields are in the schema pre-filtering. $schema_fields = array_keys( $schema['properties'] ); - $schema = apply_filters( 'rest_coauthor-block_item_schema', $schema ); + $schema = apply_filters( 'rest_coauthors-block_item_schema', $schema ); // Emit a _doing_it_wrong warning if user tries to add new properties using this filter. $new_fields = array_diff( array_keys( $schema['properties'] ), $schema_fields ); @@ -367,6 +367,6 @@ public function prepare_item_for_response( $author, $request ) : WP_REST_Respons * @param stdClass|WP_User $author * @param WP_REST_Request $request Request object. */ - return apply_filters( 'rest_prepare_coauthor-block', $response, $author, $request ); + return apply_filters( 'rest_prepare_coauthors-block', $response, $author, $request ); } } From 0a9b0d9888413de4671d2bf968dca83442433735 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 4 Sep 2023 15:45:38 -0400 Subject: [PATCH 063/123] update readme to match --- blocks/readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blocks/readme.md b/blocks/readme.md index aaabd6c6..0e82962c 100644 --- a/blocks/readme.md +++ b/blocks/readme.md @@ -22,13 +22,13 @@ In author archive templates, the post context is the first post by the author re If you want to display data about the author on their own archive, use the individual CoAuthor blocks directly without wrapping them in the CoAuthors Block. -The function `coauthors_blocks_provide_author_archive_context` filters the context using the `author_name` query variable to provide the correct author context. +The function `provide_author_archive_context` filters the context using the `author_name` query variable to provide the correct author context. ### Extending If you create a custom block that uses the namespace and prefix `cap/coauthor-`, the author archive context will be updated and will match the REST API response used in the editor. -If you have a differently named custom block, you can use the filter `coauthor_blocks_block_uses_author_context` to opt-in to the author archive context. +If you have a differently named custom block, you can use the filter `coauthors_blocks_block_uses_author_context` to opt-in to the author archive context. ## Example Data @@ -36,4 +36,4 @@ When working with Full Site Editing, or in the post editor before the authors ar ### Extending -If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthor_blocks_store_data` or the client-side using the filter `cap.author-placeholder` +If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `cap.author-placeholder` From 8310210ddaaae2377133732b8f56d73961718931 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 6 Sep 2023 15:45:41 -0400 Subject: [PATCH 064/123] reorganize for a single npm run build command --- README.md | 41 +++++ blocks/blocks.php | 119 --------------- blocks/coauthor-avatar/package.json | 5 - .../build/index.asset.php | 1 - blocks/coauthor-description/package.json | 5 - .../build/view.asset.php | 1 - blocks/coauthor-featured-image/build/view.js | 1 - .../coauthor-featured-image/package-lock.json | 6 - blocks/coauthor-featured-image/package.json | 5 - blocks/coauthor-name/package.json | 5 - blocks/coauthors/package.json | 5 - blocks/readme.md | 39 ----- blocks/store/package.json | 5 - .../blocks-store}/index.asset.php | 0 .../build => build/blocks-store}/index.js | 0 .../blocks/block-coauthor-avatar}/block.json | 0 .../block-coauthor-avatar}/index.asset.php | 2 +- .../blocks/block-coauthor-avatar}/index.js | 2 +- .../block-coauthor-avatar}/style-index.css | 0 .../block-coauthor-description}/block.json | 0 .../index.asset.php | 1 + .../block-coauthor-description}/index.css | 0 .../block-coauthor-description}/index.js | 2 +- .../block-coauthor-featured-image}/block.json | 0 .../index.asset.php | 2 +- .../block-coauthor-featured-image}/index.js | 2 +- .../style-index.css | 0 .../blocks/block-coauthor-name}/block.json | 0 .../block-coauthor-name}/index.asset.php | 2 +- .../blocks/block-coauthor-name}/index.js | 2 +- .../blocks/block-coauthors}/block.json | 0 .../blocks/block-coauthors}/index.asset.php | 2 +- .../blocks/block-coauthors}/index.js | 2 +- .../blocks/block-coauthors}/style-index.css | 0 co-authors-plus.php | 3 +- .../class-block-coauthor-avatar.php | 9 +- .../class-block-coauthor-description.php | 9 +- .../class-block-coauthor-featured-image.php | 9 +- .../class-block-coauthor-name.php | 9 +- .../class-block-coauthors.php | 9 +- php/blocks/class-blocks.php | 143 ++++++++++++++++++ .../blocks}/templating/class-templating.php | 0 .../store/src => src/blocks-store}/index.js | 0 .../blocks/block-coauthor-avatar}/block.json | 0 .../blocks/block-coauthor-avatar}/edit.js | 2 +- .../blocks/block-coauthor-avatar}/index.js | 0 .../blocks/block-coauthor-avatar}/style.css | 0 .../block-coauthor-description}/block.json | 0 .../block-coauthor-description}/edit.js | 0 .../block-coauthor-description}/editor.css | 0 .../block-coauthor-description}/index.js | 0 .../block-coauthor-featured-image}/block.json | 0 .../dimension-controls.js | 0 .../block-coauthor-featured-image}/edit.js | 2 +- .../block-coauthor-featured-image}/index.js | 0 .../block-coauthor-featured-image}/style.css | 0 .../block-coauthor-featured-image}/utils.js | 0 .../block-coauthor-featured-image}/view.js | 0 .../blocks/block-coauthor-name}/block.json | 0 .../blocks/block-coauthor-name}/edit.js | 0 .../blocks/block-coauthor-name}/index.js | 0 .../blocks/block-coauthors}/block.json | 0 ...emoized-coauthor-template-block-preview.js | 0 .../blocks/block-coauthors}/edit.js | 2 +- .../blocks/block-coauthors}/index.js | 0 .../blocks/block-coauthors}/save.js | 0 .../blocks/block-coauthors}/style.css | 0 .../blocks}/components/placeholder-image.jsx | 0 webpack.config.js | 14 ++ 69 files changed, 222 insertions(+), 246 deletions(-) delete mode 100644 blocks/blocks.php delete mode 100644 blocks/coauthor-avatar/package.json delete mode 100644 blocks/coauthor-description/build/index.asset.php delete mode 100644 blocks/coauthor-description/package.json delete mode 100644 blocks/coauthor-featured-image/build/view.asset.php delete mode 100644 blocks/coauthor-featured-image/build/view.js delete mode 100644 blocks/coauthor-featured-image/package-lock.json delete mode 100644 blocks/coauthor-featured-image/package.json delete mode 100644 blocks/coauthor-name/package.json delete mode 100644 blocks/coauthors/package.json delete mode 100644 blocks/readme.md delete mode 100644 blocks/store/package.json rename {blocks/store/build => build/blocks-store}/index.asset.php (100%) rename {blocks/store/build => build/blocks-store}/index.js (100%) rename {blocks/coauthor-avatar/build => build/blocks/block-coauthor-avatar}/block.json (100%) rename {blocks/coauthor-avatar/build => build/blocks/block-coauthor-avatar}/index.asset.php (76%) rename {blocks/coauthor-avatar/build => build/blocks/block-coauthor-avatar}/index.js (64%) rename {blocks/coauthor-avatar/build => build/blocks/block-coauthor-avatar}/style-index.css (100%) rename {blocks/coauthor-description/build => build/blocks/block-coauthor-description}/block.json (100%) create mode 100644 build/blocks/block-coauthor-description/index.asset.php rename {blocks/coauthor-description/build => build/blocks/block-coauthor-description}/index.css (100%) rename {blocks/coauthor-description/build => build/blocks/block-coauthor-description}/index.js (93%) rename {blocks/coauthor-featured-image/build => build/blocks/block-coauthor-featured-image}/block.json (100%) rename {blocks/coauthor-featured-image/build => build/blocks/block-coauthor-featured-image}/index.asset.php (69%) rename {blocks/coauthor-featured-image/build => build/blocks/block-coauthor-featured-image}/index.js (96%) rename {blocks/coauthor-featured-image/build => build/blocks/block-coauthor-featured-image}/style-index.css (100%) rename {blocks/coauthor-name/build => build/blocks/block-coauthor-name}/block.json (100%) rename {blocks/coauthor-name/build => build/blocks/block-coauthor-name}/index.asset.php (76%) rename {blocks/coauthor-name/build => build/blocks/block-coauthor-name}/index.js (95%) rename {blocks/coauthors/build => build/blocks/block-coauthors}/block.json (100%) rename {blocks/coauthors/build => build/blocks/block-coauthors}/index.asset.php (64%) rename {blocks/coauthors/build => build/blocks/block-coauthors}/index.js (69%) rename {blocks/coauthors/build => build/blocks/block-coauthors}/style-index.css (100%) rename {blocks/coauthor-avatar => php/blocks/block-coauthor-avatar}/class-block-coauthor-avatar.php (93%) rename {blocks/coauthor-description => php/blocks/block-coauthor-description}/class-block-coauthor-description.php (91%) rename {blocks/coauthor-featured-image => php/blocks/block-coauthor-featured-image}/class-block-coauthor-featured-image.php (95%) rename {blocks/coauthor-name => php/blocks/block-coauthor-name}/class-block-coauthor-name.php (94%) rename {blocks/coauthors => php/blocks/block-coauthors}/class-block-coauthors.php (97%) create mode 100644 php/blocks/class-blocks.php rename {blocks => php/blocks}/templating/class-templating.php (100%) rename {blocks/store/src => src/blocks-store}/index.js (100%) rename {blocks/coauthor-avatar/src => src/blocks/block-coauthor-avatar}/block.json (100%) rename {blocks/coauthor-avatar/src => src/blocks/block-coauthor-avatar}/edit.js (98%) rename {blocks/coauthor-avatar/src => src/blocks/block-coauthor-avatar}/index.js (100%) rename {blocks/coauthor-avatar/src => src/blocks/block-coauthor-avatar}/style.css (100%) rename {blocks/coauthor-description/src => src/blocks/block-coauthor-description}/block.json (100%) rename {blocks/coauthor-description/src => src/blocks/block-coauthor-description}/edit.js (100%) rename {blocks/coauthor-description/src => src/blocks/block-coauthor-description}/editor.css (100%) rename {blocks/coauthor-description/src => src/blocks/block-coauthor-description}/index.js (100%) rename {blocks/coauthor-featured-image/src => src/blocks/block-coauthor-featured-image}/block.json (100%) rename {blocks/coauthor-featured-image/src => src/blocks/block-coauthor-featured-image}/dimension-controls.js (100%) rename {blocks/coauthor-featured-image/src => src/blocks/block-coauthor-featured-image}/edit.js (98%) rename {blocks/coauthor-featured-image/src => src/blocks/block-coauthor-featured-image}/index.js (100%) rename {blocks/coauthor-featured-image/src => src/blocks/block-coauthor-featured-image}/style.css (100%) rename {blocks/coauthor-featured-image/src => src/blocks/block-coauthor-featured-image}/utils.js (100%) rename {blocks/coauthor-featured-image/src => src/blocks/block-coauthor-featured-image}/view.js (100%) rename {blocks/coauthor-name/src => src/blocks/block-coauthor-name}/block.json (100%) rename {blocks/coauthor-name/src => src/blocks/block-coauthor-name}/edit.js (100%) rename {blocks/coauthor-name/src => src/blocks/block-coauthor-name}/index.js (100%) rename {blocks/coauthors/src => src/blocks/block-coauthors}/block.json (100%) rename {blocks/coauthors/src/modules => src/blocks/block-coauthors/components}/memoized-coauthor-template-block-preview.js (100%) rename {blocks/coauthors/src => src/blocks/block-coauthors}/edit.js (98%) rename {blocks/coauthors/src => src/blocks/block-coauthors}/index.js (100%) rename {blocks/coauthors/src => src/blocks/block-coauthors}/save.js (100%) rename {blocks/coauthors/src => src/blocks/block-coauthors}/style.css (100%) rename {blocks => src/blocks}/components/placeholder-image.jsx (100%) create mode 100644 webpack.config.js diff --git a/README.md b/README.md index 4593ab97..39da1a33 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,44 @@ Yes! Guest authors can be disabled entirely through a filter. Having the followi ## Change Log [View the change log](https://github.com/Automattic/Co-Authors-Plus/blob/master/CHANGELOG.md). + +## Blocks +### Layout + +The Co-Authors Block supports two layouts: + +#### Inline + +Inline is it's own layout. It applies `display: inline` to all its contents. + +#### Block + +Block does not apply a specific layout. The co-authors stack vertically, and can be spaced apart using block spacing, but that's it. You can create your own layout using any of the other blocks like Group / Row / Stack and it will be applied to each co-author, similar to laying our each post in a query loop. + +### Context + +#### Post, Page, Query Loop + +By default, blocks receive the post context. The job of the Co-Authors Block is to use this context to find the relevant authors and provide context to its inner blocks. + +#### Author Archive + +In author archive templates, the post context is the first post by the author returned in the main query. Since Co-Authors Plus exists to allow multiple attributed authors, we can't be sure which author of the first post matches the requested author archive. + +If you want to display data about the author on their own archive, use the individual co-author blocks directly without wrapping them in the Co-Authors Block. + +The function `CoAuthors\Blocks::provide_author_archive_context` filters the context using the `author_name` query variable to provide the correct author context. + +#### Extending + +If you create a custom block that uses the namespace and prefix `cap/coauthor-`, the author archive context will be updated and will match the REST API response used in the editor. + +If you have a differently named custom block, you can use the filter `coauthors_blocks_block_uses_author_context` to opt-in to the author archive context. + +### Example Data + +When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the coauthor blocks replicates the standard REST API response. + +#### Extending + +If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `cap.author-placeholder` diff --git a/blocks/blocks.php b/blocks/blocks.php deleted file mode 100644 index 043fcfd5..00000000 --- a/blocks/blocks.php +++ /dev/null @@ -1,119 +0,0 @@ -dispatch( - WP_REST_Request::from_url( - home_url( - sprintf( - '/wp-json/coauthors-blocks/v1/coauthor/%s', - get_query_var( 'author_name' ) - ) - ) - ) - )->get_data(); - - if ( ! is_array( $author ) || ! array_key_exists( 'id', $author ) ) { - return $context; - } - - return array( - 'cap/author' => $author - ); -} -/** - * Need $parent_block which was added in 5.9 - * - * @link https://developer.wordpress.org/reference/hooks/render_block_context/ - */ -if ( is_wp_version_compatible( '5.9' ) ) { - add_action( 'render_block_context', __NAMESPACE__ . '\\provide_author_archive_context', 10, 3 ); -} - -/** - * Enqueue Store - */ -function enqueue_store() : void { - $asset = require dirname( __FILE__ ) . '/store/build/index.asset.php'; - - wp_enqueue_script( - 'coauthors-blocks-store', - plugins_url( '/store/build/index.js', __FILE__ ), - $asset['dependencies'], - $asset['version'] - ); - - $data = apply_filters( - 'coauthors_blocks_store_data', - array( - 'authorPlaceholder' => array( - 'id' => 0, - 'display_name' => 'FirstName LastName', - 'description' => array( - 'raw' => 'Placeholder description from Co-Authors block.', - 'rendered' => '

Placeholder description from Co-Authors block.

' - ), - 'link' => '#', - 'featured_media' => 0, - 'avatar_urls' => array_map( '__return_empty_string', array_flip( rest_get_avatar_sizes() ) ) - ) - ) - ); - - wp_localize_script( - 'coauthors-blocks-store', - 'coAuthorsBlocks', - $data - ); -} -add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_store' ); diff --git a/blocks/coauthor-avatar/package.json b/blocks/coauthor-avatar/package.json deleted file mode 100644 index b6abf47a..00000000 --- a/blocks/coauthor-avatar/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "scripts": { - "build": "../../node_modules/.bin/wp-scripts build" - } -} diff --git a/blocks/coauthor-description/build/index.asset.php b/blocks/coauthor-description/build/index.asset.php deleted file mode 100644 index c11c9fdf..00000000 --- a/blocks/coauthor-description/build/index.asset.php +++ /dev/null @@ -1 +0,0 @@ - array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'c349c7f5f5253a0c7e21'); diff --git a/blocks/coauthor-description/package.json b/blocks/coauthor-description/package.json deleted file mode 100644 index b6abf47a..00000000 --- a/blocks/coauthor-description/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "scripts": { - "build": "../../node_modules/.bin/wp-scripts build" - } -} diff --git a/blocks/coauthor-featured-image/build/view.asset.php b/blocks/coauthor-featured-image/build/view.asset.php deleted file mode 100644 index bda420ce..00000000 --- a/blocks/coauthor-featured-image/build/view.asset.php +++ /dev/null @@ -1 +0,0 @@ - array(), 'version' => '07f6b9b394c20ddc8229'); diff --git a/blocks/coauthor-featured-image/build/view.js b/blocks/coauthor-featured-image/build/view.js deleted file mode 100644 index ad6e2948..00000000 --- a/blocks/coauthor-featured-image/build/view.js +++ /dev/null @@ -1 +0,0 @@ -console.log("Hello World! (from cap-coauthor-feature-image block)"); \ No newline at end of file diff --git a/blocks/coauthor-featured-image/package-lock.json b/blocks/coauthor-featured-image/package-lock.json deleted file mode 100644 index dd50e04b..00000000 --- a/blocks/coauthor-featured-image/package-lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "coauthor-feature-image", - "lockfileVersion": 2, - "requires": true, - "packages": {} -} diff --git a/blocks/coauthor-featured-image/package.json b/blocks/coauthor-featured-image/package.json deleted file mode 100644 index a0142be4..00000000 --- a/blocks/coauthor-featured-image/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "scripts": { - "build": "../../node_modules/.bin/wp-scripts build" - } -} \ No newline at end of file diff --git a/blocks/coauthor-name/package.json b/blocks/coauthor-name/package.json deleted file mode 100644 index b6abf47a..00000000 --- a/blocks/coauthor-name/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "scripts": { - "build": "../../node_modules/.bin/wp-scripts build" - } -} diff --git a/blocks/coauthors/package.json b/blocks/coauthors/package.json deleted file mode 100644 index b6abf47a..00000000 --- a/blocks/coauthors/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "scripts": { - "build": "../../node_modules/.bin/wp-scripts build" - } -} diff --git a/blocks/readme.md b/blocks/readme.md deleted file mode 100644 index 0e82962c..00000000 --- a/blocks/readme.md +++ /dev/null @@ -1,39 +0,0 @@ -## Layout - -The Coauthors block supports two layouts: - -### Inline - -Inline is it's own layout. It applies `display: inline` to all its contents. - -### Block - -Block does not apply a specific layout. The coauthors stack vertically, and can be spaced apart using block spacing, but that's it. You can create your own layout using any of the other blocks like Group / Row / Stack and it will be applied to each coauthor, similar to laying our each post in a query loop. - -## Context - -### Post, Page, Query Loop - -By default, blocks receive the post context. The job of the Coauthors Block is to use this context to find the relevant authors and provide context to its inner blocks. - -### Author Archive - -In author archive templates, the post context is the first post by the author returned in the main query. Since Co-Authors Plus exists to allow multiple attributed authors, we can't be sure which author of the first post matches the requested author archive. - -If you want to display data about the author on their own archive, use the individual CoAuthor blocks directly without wrapping them in the CoAuthors Block. - -The function `provide_author_archive_context` filters the context using the `author_name` query variable to provide the correct author context. - -### Extending - -If you create a custom block that uses the namespace and prefix `cap/coauthor-`, the author archive context will be updated and will match the REST API response used in the editor. - -If you have a differently named custom block, you can use the filter `coauthors_blocks_block_uses_author_context` to opt-in to the author archive context. - -## Example Data - -When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the coauthor blocks replicates the standard REST API response. - -### Extending - -If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `cap.author-placeholder` diff --git a/blocks/store/package.json b/blocks/store/package.json deleted file mode 100644 index b6abf47a..00000000 --- a/blocks/store/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "scripts": { - "build": "../../node_modules/.bin/wp-scripts build" - } -} diff --git a/blocks/store/build/index.asset.php b/build/blocks-store/index.asset.php similarity index 100% rename from blocks/store/build/index.asset.php rename to build/blocks-store/index.asset.php diff --git a/blocks/store/build/index.js b/build/blocks-store/index.js similarity index 100% rename from blocks/store/build/index.js rename to build/blocks-store/index.js diff --git a/blocks/coauthor-avatar/build/block.json b/build/blocks/block-coauthor-avatar/block.json similarity index 100% rename from blocks/coauthor-avatar/build/block.json rename to build/blocks/block-coauthor-avatar/block.json diff --git a/blocks/coauthor-avatar/build/index.asset.php b/build/blocks/block-coauthor-avatar/index.asset.php similarity index 76% rename from blocks/coauthor-avatar/build/index.asset.php rename to build/blocks/block-coauthor-avatar/index.asset.php index f1599ab8..11bf750f 100644 --- a/blocks/coauthor-avatar/build/index.asset.php +++ b/build/blocks/block-coauthor-avatar/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'e5bdc99e506c4990d155'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'd1af74c4edac99f57c88'); diff --git a/blocks/coauthor-avatar/build/index.js b/build/blocks/block-coauthor-avatar/index.js similarity index 64% rename from blocks/coauthor-avatar/build/index.js rename to build/blocks/block-coauthor-avatar/index.js index dbae5105..bc0dd46d 100644 --- a/blocks/coauthor-avatar/build/index.js +++ b/build/blocks/block-coauthor-avatar/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={756:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.i18n,n=window.wp.blockEditor,a=window.wp.components,r=window.wp.data;function o(e){let{dimensions:n,style:a,className:r}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(n)),[n]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:r,src:o,style:a,width:n.width,height:n.height})}var i=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(i.u2,{edit:function(e){var i;let{context:c,attributes:s,setAttributes:u}=e;const{isLink:h,rel:v,size:p,verticalAlign:d}=s,g=(0,r.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),m=c["cap/author"]||g,{avatar_urls:b}=m;if(!b||0===b.length)return null;const f=Object.keys(b).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,n.__experimentalUseBorderProps)(s),k=null!==(i=b[p])&&void 0!==i?i:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,n.useBlockProps)(),""===k?(0,t.createElement)(o,{className:w.className,dimensions:{width:p,height:p},style:{height:p,width:p,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...w.style}}):(0,t.createElement)("img",{style:{...w.style,verticalAlign:d},width:p,height:p,src:`${b[p]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Avatar size"),value:p,options:f,onChange:e=>{u({size:Number(e)})}}),(0,t.createElement)(a.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!h}),checked:h}),h&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>u({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:d,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{u({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function n(e){var a=l[e];if(void 0!==a)return a.exports;var r=l[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.m=t,e=[],n.O=function(t,l,a,r){if(!l){var o=1/0;for(u=0;u=r)&&Object.keys(n.O).every((function(e){return n.O[e](l[c])}))?l.splice(c--,1):(i=!1,r0&&e[u-1][2]>r;u--)e[u]=e[u-1];e[u]=[l,a,r]},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,r,o=l[0],i=l[1],c=l[2],s=0;if(o.some((function(t){return 0!==e[t]}))){for(a in i)n.o(i,a)&&(n.m[a]=i[a]);if(c)var u=c(n)}for(t&&t(l);sfunction(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(n)),[n]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:r,src:o,style:a,width:n.width,height:n.height})}var i=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(i.u2,{edit:function(e){var i;let{context:s,attributes:c,setAttributes:u}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=c,g=(0,r.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),m=s["cap/author"]||g,{avatar_urls:b}=m;if(!b||0===b.length)return null;const f=Object.keys(b).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,n.__experimentalUseBorderProps)(c),_=null!==(i=b[v])&&void 0!==i?i:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,n.useBlockProps)(),""===_?(0,t.createElement)(o,{className:w.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...w.style}}):(0,t.createElement)("img",{style:{...w.style,verticalAlign:d},width:v,height:v,src:`${b[v]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Avatar size"),value:v,options:f,onChange:e=>{u({size:Number(e)})}}),(0,t.createElement)(a.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!h}),checked:h}),h&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:p,onChange:e=>u({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:d,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{u({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function n(e){var a=l[e];if(void 0!==a)return a.exports;var r=l[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.m=t,e=[],n.O=function(t,l,a,r){if(!l){var o=1/0;for(u=0;u=r)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(i=!1,r0&&e[u-1][2]>r;u--)e[u]=e[u-1];e[u]=[l,a,r]},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,r,o=l[0],i=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in i)n.o(i,a)&&(n.m[a]=i[a]);if(s)var u=s(n)}for(t&&t(l);c array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '53022b1fc8be9e6fe3b8'); diff --git a/blocks/coauthor-description/build/index.css b/build/blocks/block-coauthor-description/index.css similarity index 100% rename from blocks/coauthor-description/build/index.css rename to build/blocks/block-coauthor-description/index.css diff --git a/blocks/coauthor-description/build/index.js b/build/blocks/block-coauthor-description/index.js similarity index 93% rename from blocks/coauthor-description/build/index.js rename to build/blocks/block-coauthor-description/index.js index d71cce83..fa72dc8f 100644 --- a/blocks/coauthor-description/build/index.js +++ b/build/blocks/block-coauthor-description/index.js @@ -1 +1 @@ -!function(){var t={779:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var t=[],e=0;et("cap/blocks").getAuthorPlaceholder()),[]),p=n["cap/author"]||s,{description:f}=p;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(o.BlockControls,null,(0,r.createElement)(o.AlignmentControl,{value:c,onChange:t=>{l({textAlign:t})}})),(0,r.createElement)("div",e({},(0,o.useBlockProps)({className:u()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f.rendered}})))}})}()}(); \ No newline at end of file +!function(){var t={184:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var t=[],e=0;et("cap/blocks").getAuthorPlaceholder()),[]),p=n["cap/author"]||s,{description:f}=p;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(o.BlockControls,null,(0,r.createElement)(o.AlignmentControl,{value:c,onChange:t=>{l({textAlign:t})}})),(0,r.createElement)("div",e({},(0,o.useBlockProps)({className:u()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f.rendered}})))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthor-featured-image/build/block.json b/build/blocks/block-coauthor-featured-image/block.json similarity index 100% rename from blocks/coauthor-featured-image/build/block.json rename to build/blocks/block-coauthor-featured-image/block.json diff --git a/blocks/coauthor-featured-image/build/index.asset.php b/build/blocks/block-coauthor-featured-image/index.asset.php similarity index 69% rename from blocks/coauthor-featured-image/build/index.asset.php rename to build/blocks/block-coauthor-featured-image/index.asset.php index 2848ff6f..55774612 100644 --- a/blocks/coauthor-featured-image/build/index.asset.php +++ b/build/blocks/block-coauthor-featured-image/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '985a000f28e19e79fe0d'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '74613b74c8f2a40a4d57'); diff --git a/blocks/coauthor-featured-image/build/index.js b/build/blocks/block-coauthor-featured-image/index.js similarity index 96% rename from blocks/coauthor-featured-image/build/index.js rename to build/blocks/block-coauthor-featured-image/index.js index f5539e5b..11b40ca5 100644 --- a/blocks/coauthor-featured-image/build/index.js +++ b/build/blocks/block-coauthor-featured-image/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={983:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.i18n,i=window.wp.blockEditor,a=window.wp.components,n=window.wp.data,o=window.wp.coreData;const r=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"cover",label:(0,l._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"contain",label:(0,l._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"fill",label:(0,l._x)("Fill","Scale option for Image dimension control")})),s="cover",c={cover:(0,l.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,l.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,l.__)("Image will be stretched and distorted to completely fill the space.")};var u=e=>{let{clientId:n,attributes:{aspectRatio:o,width:u,height:h,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,a.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),b=h||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:u||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:w,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:i,style:a,className:n}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:o,style:a,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-featured-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=r,S=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,n.useSelect)((e=>0!==E.featured_media&&e(o.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,n.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(C,k,b),B=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const a=t[l];if(!0===a.crop||a.width===a.height)return{width:a.width,height:a.height};const n=i.width/i.height;return a.width>a.height?{width:a.width,height:a.width/n}:{width:a.height*n,height:a.height}}(C,k,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,O),T=(0,i.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(u,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:T.className,src:g(C,O),style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Feature Image Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:f,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function i(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.m=t,e=[],i.O=function(t,l,a,n){if(!l){var o=1/0;for(u=0;u=n)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,n0&&e[u-1][2]>n;u--)e[u]=e[u-1];e[u]=[l,a,n]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)i.o(r,a)&&(i.m[a]=r[a]);if(s)var u=s(i)}for(t&&t(l);c{let{clientId:n,attributes:{aspectRatio:o,width:u,height:h,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,a.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),b=h||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:u||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:w,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:i,style:a,className:n}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:o,style:a,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-featured-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=r,S=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,n.useSelect)((e=>0!==E.featured_media&&e(o.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,n.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(C,k,b),B=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const a=t[l];if(!0===a.crop||a.width===a.height)return{width:a.width,height:a.height};const n=i.width/i.height;return a.width>a.height?{width:a.width,height:a.width/n}:{width:a.height*n,height:a.height}}(C,k,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,O),T=(0,i.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(u,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:T.className,src:g(C,O),style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Feature Image Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:f,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function i(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.m=t,e=[],i.O=function(t,l,a,n){if(!l){var o=1/0;for(u=0;u=n)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,n0&&e[u-1][2]>n;u--)e[u]=e[u-1];e[u]=[l,a,n]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={335:0,597:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)i.o(r,a)&&(i.m[a]=r[a]);if(s)var u=s(i)}for(t&&t(l);c array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '8f88d663ba1ce7d54409'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'b5f0d7ff4f1bc015b522'); diff --git a/blocks/coauthor-name/build/index.js b/build/blocks/block-coauthor-name/index.js similarity index 95% rename from blocks/coauthor-name/build/index.js rename to build/blocks/block-coauthor-name/index.js index 5226502f..4e2ebd96 100644 --- a/blocks/coauthor-name/build/index.js +++ b/build/blocks/block-coauthor-name/index.js @@ -1 +1 @@ -!function(){var e={779:function(e,t){var n;!function(){"use strict";var l={}.hasOwnProperty;function r(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),m=n["cap/author"]||g,{link:v,display_name:d}=m,b=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.BlockControls,null,(0,t.createElement)(l.AlignmentControl,{value:f,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)(b,(0,l.useBlockProps)({className:u()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:v,rel:p,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(l.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(r.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>c({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:p,onChange:e=>c({rel:e})})))),(0,t.createElement)(l.InspectorControls,{group:"advanced"},(0,t.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("HTML element"),options:[{label:(0,o.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>c({tagName:e})})))}})}()}(); \ No newline at end of file +!function(){var e={184:function(e,t){var n;!function(){"use strict";var l={}.hasOwnProperty;function r(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),m=n["cap/author"]||g,{link:v,display_name:d}=m,b=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.BlockControls,null,(0,t.createElement)(l.AlignmentControl,{value:f,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)(b,(0,l.useBlockProps)({className:u()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:v,rel:p,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(l.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(r.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>c({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:p,onChange:e=>c({rel:e})})))),(0,t.createElement)(l.InspectorControls,{group:"advanced"},(0,t.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("HTML element"),options:[{label:(0,o.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>c({tagName:e})})))}})}()}(); \ No newline at end of file diff --git a/blocks/coauthors/build/block.json b/build/blocks/block-coauthors/block.json similarity index 100% rename from blocks/coauthors/build/block.json rename to build/blocks/block-coauthors/block.json diff --git a/blocks/coauthors/build/index.asset.php b/build/blocks/block-coauthors/index.asset.php similarity index 64% rename from blocks/coauthors/build/index.asset.php rename to build/blocks/block-coauthors/index.asset.php index d28b2076..693147f2 100644 --- a/blocks/coauthors/build/index.asset.php +++ b/build/blocks/block-coauthors/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ec17272f585edf49f005'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '86b33ca9598a93fd863e'); diff --git a/blocks/coauthors/build/index.js b/build/blocks/block-coauthors/index.js similarity index 69% rename from blocks/coauthors/build/index.js rename to build/blocks/block-coauthors/index.js index 465b1cff..922f7af2 100644 --- a/blocks/coauthors/build/index.js +++ b/build/blocks/block-coauthors/index.js @@ -1 +1 @@ -!function(){var e,t={911:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,l=window.wp.blockEditor,a=window.wp.components,i=window.wp.apiFetch,c=n.n(i),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,v=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),f=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),d=n(779),h=n.n(d);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{a(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},i,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:s}))}));function w(){return(0,r.createElement)("div",(0,l.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-name"]]}))}const g=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:i,clientId:p,context:d,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=o,{postId:S}=d,O=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return c()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(l.store).getBlocks(p))),z=e=>{i({layout:{...E,...e}})},G=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.BlockControls,null,(0,r.createElement)(a.ToolbarGroup,{controls:G}),(0,r.createElement)(l.AlignmentControl,{value:C,onChange:e=>{i({textAlign:e})}})),(0,r.createElement)("div",(0,l.useBlockProps)({className:h()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,l.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),A&&"inline"===E.type&&(m||y)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>i({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const n=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(l.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthors__separator"},k&&n===o.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(m||_)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>i({suffix:e}),tagName:"span"})),(0,r.createElement)(l.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(a.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:x||"",onChange:e=>{i({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:k||"",onChange:e=>{i({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:a,textAlign:i}=o,c={gap:"block"===a.type?(0,l.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=h()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${i}`]:i});return(0,r.createElement)("div",l.useBlockProps.save({className:s,style:c}),(0,r.createElement)(l.InnerBlocks.Content,null))}})},779:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(o.O).every((function(e){return o.O[e](n[c])}))?n.splice(c--,1):(i=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,r,l]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,l,a=n[0],i=n[1],c=n[2],s=0;if(a.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(c)var u=c(o)}for(t&&t(n);s{a(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},c,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function w(){return(0,r.createElement)("div",(0,l.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-name"]]}))}const g=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:c,clientId:p,context:d,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=o,{postId:S}=d,O=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return i()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(l.store).getBlocks(p))),z=e=>{c({layout:{...E,...e}})},G=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.BlockControls,null,(0,r.createElement)(a.ToolbarGroup,{controls:G}),(0,r.createElement)(l.AlignmentControl,{value:C,onChange:e=>{c({textAlign:e})}})),(0,r.createElement)("div",(0,l.useBlockProps)({className:h()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,l.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),A&&"inline"===E.type&&(m||y)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>c({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const n=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(l.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthors__separator"},k&&n===o.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(m||_)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>c({suffix:e}),tagName:"span"})),(0,r.createElement)(l.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(a.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:x||"",onChange:e=>{c({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:k||"",onChange:e=>{c({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:a,textAlign:c}=o,i={gap:"block"===a.type?(0,l.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=h()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${c}`]:c});return(0,r.createElement)("div",l.useBlockProps.save({className:s,style:i}),(0,r.createElement)(l.InnerBlocks.Content,null))}})},184:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(o.O).every((function(e){return o.O[e](n[i])}))?n.splice(i--,1):(c=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,r,l]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,l,a=n[0],c=n[1],i=n[2],s=0;if(a.some((function(t){return 0!==e[t]}))){for(r in c)o.o(c,r)&&(o.m[r]=c[r]);if(i)var u=i(o)}for(t&&t(n);s array( __CLASS__, 'render_block' ), ) diff --git a/blocks/coauthor-description/class-block-coauthor-description.php b/php/blocks/block-coauthor-description/class-block-coauthor-description.php similarity index 91% rename from blocks/coauthor-description/class-block-coauthor-description.php rename to php/blocks/block-coauthor-description/class-block-coauthor-description.php index 5d4268d7..eecc1263 100644 --- a/blocks/coauthor-description/class-block-coauthor-description.php +++ b/php/blocks/block-coauthor-description/class-block-coauthor-description.php @@ -13,23 +13,18 @@ * Block CoAuthor Description */ class Block_CoAuthor_Description { - /** - * Construct - */ - public function __construct() { - add_action( 'init', array( __CLASS__, 'register_block' ) ); - } /** * Register Block */ public static function register_block() : void { register_block_type( - __DIR__ . '/build', + realpath( __DIR__ . '/../../..' ) . '/build/blocks/block-coauthor-description', array( 'render_callback' => array( __CLASS__, 'render_block' ), ) ); } + /** * Render Block * diff --git a/blocks/coauthor-featured-image/class-block-coauthor-featured-image.php b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php similarity index 95% rename from blocks/coauthor-featured-image/class-block-coauthor-featured-image.php rename to php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php index b5bb45aa..656f9a88 100644 --- a/blocks/coauthor-featured-image/class-block-coauthor-featured-image.php +++ b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php @@ -13,23 +13,18 @@ * Block CoAuthor Featured Image */ class Block_CoAuthor_Featured_Image { - /** - * Construct - */ - public function __construct() { - add_action( 'init', array( __CLASS__, 'register_block' ) ); - } /** * Register Block */ public static function register_block() : void { register_block_type( - __DIR__ . '/build', + realpath( __DIR__ . '/../../..' ) . '/build/blocks/block-coauthor-featured-image', array( 'render_callback' => array( __CLASS__, 'render_block' ), ) ); } + /** * Render Block * diff --git a/blocks/coauthor-name/class-block-coauthor-name.php b/php/blocks/block-coauthor-name/class-block-coauthor-name.php similarity index 94% rename from blocks/coauthor-name/class-block-coauthor-name.php rename to php/blocks/block-coauthor-name/class-block-coauthor-name.php index 14cf2789..0aabeb51 100644 --- a/blocks/coauthor-name/class-block-coauthor-name.php +++ b/php/blocks/block-coauthor-name/class-block-coauthor-name.php @@ -13,23 +13,18 @@ * Block CoAuthor Name */ class Block_CoAuthor_Name { - /** - * Construct - */ - public function __construct() { - add_action( 'init', array( __CLASS__, 'register_block' ) ); - } /** * Register Block */ public static function register_block() : void { register_block_type( - __DIR__ . '/build', + realpath( __DIR__ . '/../../..' ) . '/build/blocks/block-coauthor-name', array( 'render_callback' => array( __CLASS__, 'render_block' ), ) ); } + /** * Render Block * diff --git a/blocks/coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php similarity index 97% rename from blocks/coauthors/class-block-coauthors.php rename to php/blocks/block-coauthors/class-block-coauthors.php index 89dca75b..599d326c 100644 --- a/blocks/coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -16,19 +16,12 @@ * Block CoAuthors */ class Block_CoAuthors { - /** - * Construct - */ - public function __construct() { - add_action( 'init', array( __CLASS__, 'register_block' ) ); - } - /** * Register Block */ public static function register_block() : void { register_block_type( - __DIR__ . '/build', + realpath( __DIR__ . '/../../..' ) . '/build/blocks/block-coauthors', array( 'render_callback' => array( __CLASS__, 'render_block' ), ) diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php new file mode 100644 index 00000000..ea0df5c1 --- /dev/null +++ b/php/blocks/class-blocks.php @@ -0,0 +1,143 @@ +dispatch( + WP_REST_Request::from_url( + home_url( + sprintf( + '/wp-json/coauthors-blocks/v1/coauthor/%s', + get_query_var( 'author_name' ) + ) + ) + ) + )->get_data(); + + if ( ! is_array( $author ) || ! array_key_exists( 'id', $author ) ) { + return $context; + } + + return array( + 'cap/author' => $author + ); + } + + /** + * Enqueue Store + */ + public static function enqueue_store() : void { + $asset = require realpath( __DIR__ . '/../..' ) . '/build/blocks-store/index.asset.php'; + + wp_enqueue_script( + 'coauthors-blocks-store', + plugins_url( '/co-authors-plus/build/blocks-store/index.js' ), + $asset['dependencies'], + $asset['version'] + ); + + $data = apply_filters( + 'coauthors_blocks_store_data', + array( + 'authorPlaceholder' => array( + 'id' => 0, + 'display_name' => 'FirstName LastName', + 'description' => array( + 'raw' => 'Placeholder description from Co-Authors block.', + 'rendered' => '

Placeholder description from Co-Authors block.

' + ), + 'link' => '#', + 'featured_media' => 0, + 'avatar_urls' => array_map( '__return_empty_string', array_flip( rest_get_avatar_sizes() ) ) + ) + ) + ); + + wp_localize_script( + 'coauthors-blocks-store', + 'coAuthorsBlocks', + $data + ); + } +} diff --git a/blocks/templating/class-templating.php b/php/blocks/templating/class-templating.php similarity index 100% rename from blocks/templating/class-templating.php rename to php/blocks/templating/class-templating.php diff --git a/blocks/store/src/index.js b/src/blocks-store/index.js similarity index 100% rename from blocks/store/src/index.js rename to src/blocks-store/index.js diff --git a/blocks/coauthor-avatar/src/block.json b/src/blocks/block-coauthor-avatar/block.json similarity index 100% rename from blocks/coauthor-avatar/src/block.json rename to src/blocks/block-coauthor-avatar/block.json diff --git a/blocks/coauthor-avatar/src/edit.js b/src/blocks/block-coauthor-avatar/edit.js similarity index 98% rename from blocks/coauthor-avatar/src/edit.js rename to src/blocks/block-coauthor-avatar/edit.js index e588d4bc..24acee41 100644 --- a/blocks/coauthor-avatar/src/edit.js +++ b/src/blocks/block-coauthor-avatar/edit.js @@ -3,7 +3,7 @@ import { useBlockProps, InspectorControls, __experimentalUseBorderProps as useBo import { SelectControl, PanelBody, ToggleControl, TextControl } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; -import PlaceholderImage from '../../components/placeholder-image'; +import PlaceholderImage from '../components/placeholder-image'; /** * The edit function describes the structure of your block in the context of the diff --git a/blocks/coauthor-avatar/src/index.js b/src/blocks/block-coauthor-avatar/index.js similarity index 100% rename from blocks/coauthor-avatar/src/index.js rename to src/blocks/block-coauthor-avatar/index.js diff --git a/blocks/coauthor-avatar/src/style.css b/src/blocks/block-coauthor-avatar/style.css similarity index 100% rename from blocks/coauthor-avatar/src/style.css rename to src/blocks/block-coauthor-avatar/style.css diff --git a/blocks/coauthor-description/src/block.json b/src/blocks/block-coauthor-description/block.json similarity index 100% rename from blocks/coauthor-description/src/block.json rename to src/blocks/block-coauthor-description/block.json diff --git a/blocks/coauthor-description/src/edit.js b/src/blocks/block-coauthor-description/edit.js similarity index 100% rename from blocks/coauthor-description/src/edit.js rename to src/blocks/block-coauthor-description/edit.js diff --git a/blocks/coauthor-description/src/editor.css b/src/blocks/block-coauthor-description/editor.css similarity index 100% rename from blocks/coauthor-description/src/editor.css rename to src/blocks/block-coauthor-description/editor.css diff --git a/blocks/coauthor-description/src/index.js b/src/blocks/block-coauthor-description/index.js similarity index 100% rename from blocks/coauthor-description/src/index.js rename to src/blocks/block-coauthor-description/index.js diff --git a/blocks/coauthor-featured-image/src/block.json b/src/blocks/block-coauthor-featured-image/block.json similarity index 100% rename from blocks/coauthor-featured-image/src/block.json rename to src/blocks/block-coauthor-featured-image/block.json diff --git a/blocks/coauthor-featured-image/src/dimension-controls.js b/src/blocks/block-coauthor-featured-image/dimension-controls.js similarity index 100% rename from blocks/coauthor-featured-image/src/dimension-controls.js rename to src/blocks/block-coauthor-featured-image/dimension-controls.js diff --git a/blocks/coauthor-featured-image/src/edit.js b/src/blocks/block-coauthor-featured-image/edit.js similarity index 98% rename from blocks/coauthor-featured-image/src/edit.js rename to src/blocks/block-coauthor-featured-image/edit.js index 3ee1bb4d..c7f966e2 100644 --- a/blocks/coauthor-featured-image/src/edit.js +++ b/src/blocks/block-coauthor-featured-image/edit.js @@ -13,7 +13,7 @@ import { TextControl, PanelBody, ToggleControl, SelectControl } from '@wordpress import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import DimensionControls from './dimension-controls'; -import PlaceholderImage from '../../components/placeholder-image'; +import PlaceholderImage from '../components/placeholder-image'; import { getAvailableSizeSlug, getMediaSrc, getMediaDimensions, getPlaceholderImageDimensions } from './utils' /** diff --git a/blocks/coauthor-featured-image/src/index.js b/src/blocks/block-coauthor-featured-image/index.js similarity index 100% rename from blocks/coauthor-featured-image/src/index.js rename to src/blocks/block-coauthor-featured-image/index.js diff --git a/blocks/coauthor-featured-image/src/style.css b/src/blocks/block-coauthor-featured-image/style.css similarity index 100% rename from blocks/coauthor-featured-image/src/style.css rename to src/blocks/block-coauthor-featured-image/style.css diff --git a/blocks/coauthor-featured-image/src/utils.js b/src/blocks/block-coauthor-featured-image/utils.js similarity index 100% rename from blocks/coauthor-featured-image/src/utils.js rename to src/blocks/block-coauthor-featured-image/utils.js diff --git a/blocks/coauthor-featured-image/src/view.js b/src/blocks/block-coauthor-featured-image/view.js similarity index 100% rename from blocks/coauthor-featured-image/src/view.js rename to src/blocks/block-coauthor-featured-image/view.js diff --git a/blocks/coauthor-name/src/block.json b/src/blocks/block-coauthor-name/block.json similarity index 100% rename from blocks/coauthor-name/src/block.json rename to src/blocks/block-coauthor-name/block.json diff --git a/blocks/coauthor-name/src/edit.js b/src/blocks/block-coauthor-name/edit.js similarity index 100% rename from blocks/coauthor-name/src/edit.js rename to src/blocks/block-coauthor-name/edit.js diff --git a/blocks/coauthor-name/src/index.js b/src/blocks/block-coauthor-name/index.js similarity index 100% rename from blocks/coauthor-name/src/index.js rename to src/blocks/block-coauthor-name/index.js diff --git a/blocks/coauthors/src/block.json b/src/blocks/block-coauthors/block.json similarity index 100% rename from blocks/coauthors/src/block.json rename to src/blocks/block-coauthors/block.json diff --git a/blocks/coauthors/src/modules/memoized-coauthor-template-block-preview.js b/src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js similarity index 100% rename from blocks/coauthors/src/modules/memoized-coauthor-template-block-preview.js rename to src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js diff --git a/blocks/coauthors/src/edit.js b/src/blocks/block-coauthors/edit.js similarity index 98% rename from blocks/coauthors/src/edit.js rename to src/blocks/block-coauthors/edit.js index e0be8ba6..23ccefe8 100644 --- a/blocks/coauthors/src/edit.js +++ b/src/blocks/block-coauthors/edit.js @@ -24,7 +24,7 @@ import { list, grid } from '@wordpress/icons'; import classnames from 'classnames'; -import MemoizedCoAuthorTemplateBlockPreview from './modules/memoized-coauthor-template-block-preview'; +import MemoizedCoAuthorTemplateBlockPreview from './components/memoized-coauthor-template-block-preview'; /** * CoAuthor Template Inner Blocks diff --git a/blocks/coauthors/src/index.js b/src/blocks/block-coauthors/index.js similarity index 100% rename from blocks/coauthors/src/index.js rename to src/blocks/block-coauthors/index.js diff --git a/blocks/coauthors/src/save.js b/src/blocks/block-coauthors/save.js similarity index 100% rename from blocks/coauthors/src/save.js rename to src/blocks/block-coauthors/save.js diff --git a/blocks/coauthors/src/style.css b/src/blocks/block-coauthors/style.css similarity index 100% rename from blocks/coauthors/src/style.css rename to src/blocks/block-coauthors/style.css diff --git a/blocks/components/placeholder-image.jsx b/src/blocks/components/placeholder-image.jsx similarity index 100% rename from blocks/components/placeholder-image.jsx rename to src/blocks/components/placeholder-image.jsx diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 00000000..19de81d4 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,14 @@ +const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); + +module.exports = { + ...defaultConfig, + entry : { + 'index': './src/index.js', + 'blocks/block-coauthor-avatar/index': './src/blocks/block-coauthor-avatar/index.js', + 'blocks/block-coauthor-description/index': './src/blocks/block-coauthor-description/index.js', + 'blocks/block-coauthor-featured-image/index': './src/blocks/block-coauthor-featured-image/index.js', + 'blocks/block-coauthor-name/index': './src/blocks/block-coauthor-name/index.js', + 'blocks/block-coauthors/index': './src/blocks/block-coauthors/index.js', + 'blocks-store/index': './src/blocks-store/index.js', + } +}; From ac35c66a672118197c3c3e7e20c4e4d7b15a8919 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 10:23:19 -0400 Subject: [PATCH 065/123] remove union types for php 7.4 compat --- .../class-coauthors-blocks-controller.php | 14 +++++++------- .../block-coauthors/class-block-coauthors.php | 2 +- php/blocks/templating/class-templating.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index e548daf3..edc57e49 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -88,7 +88,7 @@ public function register_routes() : void { * @param WP_REST_Request $request * @return WP_REST_Response|WP_Error */ - public function get_item( $request ) : WP_REST_Response|WP_Error { + public function get_item( $request ) { $coauthor = $this->coauthors_plus->get_coauthor_by( 'user_nicename', @@ -119,7 +119,7 @@ public function get_item( $request ) : WP_REST_Response|WP_Error { * * @param WP_User|stdClass $coauthor */ - public static function is_coauthor( WP_User|stdClass $coauthor ) : bool { + public static function is_coauthor( $coauthor ) : bool { return is_a( $coauthor, 'WP_User' ) || ( property_exists( $coauthor, 'type' ) && 'guest-author' === $coauthor->type ); } @@ -129,7 +129,7 @@ public static function is_coauthor( WP_User|stdClass $coauthor ) : bool { * @param WP_REST_Request $request * @return WP_REST_Response|WP_Error */ - public function get_items( $request ) : WP_REST_Response|WP_Error { + public function get_items( $request ) { $coauthors = get_coauthors( $request->get_param( 'post_id' ) ); @@ -143,7 +143,7 @@ public function get_items( $request ) : WP_REST_Response|WP_Error { return rest_ensure_response( array_map( - function( stdClass|WP_User $author ) use ( $request ) : array { + function( $author ) use ( $request ) : array { return $this->prepare_response_for_collection( $this->prepare_item_for_response( $author, $request ) ); @@ -159,7 +159,7 @@ function( stdClass|WP_User $author ) use ( $request ) : array { * @param WP_REST_Request $request * @return bool|WP_Error */ - public function get_item_permission_check( WP_REST_Request $request ) : bool|WP_Error { + public function get_item_permission_check( WP_REST_Request $request ) { if ( current_user_can( 'edit_posts' ) ) { return true; @@ -178,7 +178,7 @@ public function get_item_permission_check( WP_REST_Request $request ) : bool|WP_ * @param WP_REST_Request $request * @return bool|WP_Error */ - public function get_items_permission_check( WP_REST_Request $request ) : bool|WP_Error { + public function get_items_permission_check( WP_REST_Request $request ) { $post_id = $request->get_param( 'post_id' ); @@ -306,7 +306,7 @@ public function get_item_schema() : array { * @param WP_REST_Request $request * @return WP_REST_Response|WP_Error */ - public function prepare_item_for_response( $author, $request ) : WP_REST_Response|WP_Error { + public function prepare_item_for_response( $author, $request ) { $fields = $this->get_fields_for_response( $request ); diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 599d326c..f5835d69 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -45,7 +45,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc } $authors = array_map( - function( stdClass|WP_User $author ) : array { + function( $author ) : array { return rest_get_server()->dispatch( WP_REST_Request::from_url( home_url( diff --git a/php/blocks/templating/class-templating.php b/php/blocks/templating/class-templating.php index dbcf0e54..f43cd502 100644 --- a/php/blocks/templating/class-templating.php +++ b/php/blocks/templating/class-templating.php @@ -51,7 +51,7 @@ public static function render_self_closing_element( string $name, ?string $attri * @param mixed $value Attribute value. For boolean attributes, set value the same as the key. * @return string */ - public static function render_attribute_string( string|int $key, $value ) : string { + public static function render_attribute_string( $key, $value ) : string { if ( empty( $value ) ) { return ''; } From 4fd55435192bba3bee9d5733904ec753bac69710 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 10:24:10 -0400 Subject: [PATCH 066/123] remove unused permission check --- .../class-coauthors-blocks-controller.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index edc57e49..87673e15 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -153,25 +153,6 @@ function( $author ) use ( $request ) : array { ); } - /** - * Get Item Permission Check - * - * @param WP_REST_Request $request - * @return bool|WP_Error - */ - public function get_item_permission_check( WP_REST_Request $request ) { - - if ( current_user_can( 'edit_posts' ) ) { - return true; - } - - return new WP_Error( - 'rest_cannot_view', - __( 'Sorry, you are not allowed to view co-authors.' ), - array( 'status' => rest_authorization_required_code() ) - ); - } - /** * Get Items Permission Check * From 4c09f801f797bdb9b7c8d38d2e05bcb6cb707cc8 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 10:25:02 -0400 Subject: [PATCH 067/123] use int consistently --- php/api/endpoints/class-coauthors-blocks-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index 87673e15..e8833e35 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -327,7 +327,7 @@ public function prepare_item_for_response( $author, $request ) { } if ( rest_is_field_included( 'featured_media', $fields ) ) { - $data['featured_media'] = (integer) ( 'guest-author' === $author->type ? get_post_thumbnail_id( $author->ID ) : 0 ); + $data['featured_media'] = (int) ( 'guest-author' === $author->type ? get_post_thumbnail_id( $author->ID ) : 0 ); } if ( rest_is_field_included( 'user_nicename', $fields ) ) { From 67709d8fa7b64a63f5dcd10b05565514b683c586 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 10:26:56 -0400 Subject: [PATCH 068/123] document filter to turn off blocks --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 39da1a33..7c3f1eb1 100644 --- a/README.md +++ b/README.md @@ -109,3 +109,7 @@ When working with Full Site Editing, or in the post editor before the authors ar #### Extending If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `cap.author-placeholder` + +### Non-support + +To declare a lack of support for Co-Author Plus blocks, use the filter `coauthors_plus_support_blocks` to return `false`. From 9db703c29ab484b5bd688f09b1ce1b5085fe38cb Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 10:30:41 -0400 Subject: [PATCH 069/123] remove var type for php 7.1 compat --- php/api/endpoints/class-coauthors-blocks-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index e8833e35..593e970f 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -26,7 +26,7 @@ class CoAuthors_Blocks_Controller extends WP_REST_Controller { * * @var CoAuthors_Plus $coauthors_plus */ - public CoAuthors_Plus $coauthors_plus; + public $coauthors_plus; /** * Construct From 3dc96e008df1878c8643497c1019f185a9ef9103 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 10:35:04 -0400 Subject: [PATCH 070/123] esc ( maybe not needed ) to satisfy code sniffer --- php/api/endpoints/class-coauthors-blocks-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index 593e970f..7c5938c3 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -268,7 +268,7 @@ public function get_item_schema() : array { __METHOD__, sprintf( /* translators: %s: register_rest_field */ - __( 'Please use %s to add new schema properties.' ), + esc_html__( 'Please use %s to add new schema properties.' ), 'register_rest_field' ), '5.4.0' From 76b1547202d5d4e4544f05f49b60703e30d446ce Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 10:47:44 -0400 Subject: [PATCH 071/123] remove arrow functions for php 7.1 compat --- php/api/endpoints/class-coauthors-blocks-controller.php | 6 +++--- .../block-coauthor-avatar/class-block-coauthor-avatar.php | 4 +++- php/blocks/block-coauthors/class-block-coauthors.php | 8 ++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index 7c5938c3..5f389aca 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -49,7 +49,7 @@ public function register_routes() : void { 'id' => array( 'description' => __( 'Unique identifier for a post.' ), 'type' => 'integer', - 'validate_callback' => fn( $post_id ) => is_int( $post_id ) + 'validate_callback' => 'is_int' ), ), array( @@ -68,8 +68,8 @@ public function register_routes() : void { 'user_nicename' => array( 'description' => __( 'Nicename / slug for co-author.' ), 'type' => 'string', - 'validate_callback' => fn( $slug ) => is_string( $slug ), - 'sanitize_callback' => fn( $slug ) => sanitize_title( $slug ) + 'validate_callback' => 'is_string', + 'sanitize_callback' => 'sanitize_title' ), ), array( diff --git a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php index 985f2e2e..85e1ed85 100644 --- a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php +++ b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php @@ -53,7 +53,9 @@ public static function render_block( array $attributes, string $content, WP_Bloc $size = $attributes['size'] ?? 24; $srcset = array_map( - fn( $size, $url ) => "{$url} {$size}w", + function( $size, $url ) { + return "{$url} {$size}w"; + }, array_keys( $avatar_urls ), array_values( $avatar_urls ) ); diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index f5835d69..7bd79561 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -104,7 +104,9 @@ public static function get_composed_map_function( ...$fns ) : callable { return function ( $value ) use ( $fns ) { return array_reduce( $fns, - fn( $v, callable $f ) => $f($v), + function( $v, callable $f ) { + return $f($v); + }, $value ); }; @@ -148,7 +150,9 @@ public static function render_coauthors_blocks_with_template( array $template, a self::get_composed_map_function( self::get_template_render_function( $template ), // To match JSX from editor, remove line-breaks between blocks. - fn( $content ) => str_replace("\n", '', $content ), + function( $content ) { + return str_replace("\n", '', $content ); + }, // To match JSX from editor, trim whitespace around blocks. 'trim', Templating::get_render_element_function('div', 'class="wp-block-cap-coauthor"') From 35526e65c9fa5e16d0b940df9f75cd2d6fb3dec3 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 10:52:01 -0400 Subject: [PATCH 072/123] one more arrow function --- php/blocks/block-coauthors/class-block-coauthors.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 7bd79561..3e3152e0 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -170,7 +170,9 @@ function( $content ) { */ private static function merge_blocks_with_separators( array $blocks, array $separators ) : array { return array_map( - fn(...$args) : string => implode($args), + function(...$args) : string { + return implode($args); + }, $blocks, $separators ); From e4a4d45395963b5705eca5990bbb0585bae04305 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 10:56:01 -0400 Subject: [PATCH 073/123] remove viewScript --- build/blocks/block-coauthor-featured-image/block.json | 3 +-- src/blocks/block-coauthor-featured-image/block.json | 5 ++--- src/blocks/block-coauthor-featured-image/view.js | 3 --- 3 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 src/blocks/block-coauthor-featured-image/view.js diff --git a/build/blocks/block-coauthor-featured-image/block.json b/build/blocks/block-coauthor-featured-image/block.json index f3ac35c7..ba582536 100644 --- a/build/blocks/block-coauthor-featured-image/block.json +++ b/build/blocks/block-coauthor-featured-image/block.json @@ -70,6 +70,5 @@ "textdomain": "coauthor-feature-image", "editorScript": "file:./index.js", "editorStyle": "file:./index.css", - "style": "file:./style-index.css", - "viewScript": "file:./view.js" + "style": "file:./style-index.css" } \ No newline at end of file diff --git a/src/blocks/block-coauthor-featured-image/block.json b/src/blocks/block-coauthor-featured-image/block.json index 8994302c..3f619f04 100644 --- a/src/blocks/block-coauthor-featured-image/block.json +++ b/src/blocks/block-coauthor-featured-image/block.json @@ -64,6 +64,5 @@ "textdomain": "coauthor-feature-image", "editorScript": "file:./index.js", "editorStyle": "file:./index.css", - "style": "file:./style-index.css", - "viewScript": "file:./view.js" -} \ No newline at end of file + "style": "file:./style-index.css" +} diff --git a/src/blocks/block-coauthor-featured-image/view.js b/src/blocks/block-coauthor-featured-image/view.js deleted file mode 100644 index 2c36b119..00000000 --- a/src/blocks/block-coauthor-featured-image/view.js +++ /dev/null @@ -1,3 +0,0 @@ -/* eslint-disable no-console */ -console.log("Hello World! (from cap-coauthor-feature-image block)"); -/* eslint-enable no-console */ From fa72a2f930195453a045bca8bd0045f377f76cb6 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 11:01:09 -0400 Subject: [PATCH 074/123] remove use statements, not needed w/o union types --- php/blocks/block-coauthors/class-block-coauthors.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 3e3152e0..95a537f7 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -7,10 +7,8 @@ namespace CoAuthors\Blocks; -use stdClass; use WP_Block; use WP_REST_Request; -use WP_User; /** * Block CoAuthors From bb1be4435c3cc0d9aa1b2f62ecf2e8e13b77d458 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 11:34:39 -0400 Subject: [PATCH 075/123] fix validate and sanitize funcs based on arg count --- .../endpoints/class-coauthors-blocks-controller.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index 5f389aca..b0a1f2fb 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -49,7 +49,9 @@ public function register_routes() : void { 'id' => array( 'description' => __( 'Unique identifier for a post.' ), 'type' => 'integer', - 'validate_callback' => 'is_int' + 'validate_callback' => function( $post_id ) : bool { + return is_int( $post_id ); + }, ), ), array( @@ -68,8 +70,12 @@ public function register_routes() : void { 'user_nicename' => array( 'description' => __( 'Nicename / slug for co-author.' ), 'type' => 'string', - 'validate_callback' => 'is_string', - 'sanitize_callback' => 'sanitize_title' + 'validate_callback' => function( $slug ) : bool { + return is_string( $slug ); + }, + 'sanitize_callback' => function( $slug ) { + return sanitize_title( $slug ); + } ), ), array( From c10a920b04f0e33e8e1c6ec90d8870b34b4f7fc7 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 11:37:01 -0400 Subject: [PATCH 076/123] DRY the server-side get of authors w/ API schema --- .../block-coauthors/class-block-coauthors.php | 25 ++++----- php/blocks/class-blocks.php | 52 +++++++++++++++---- 2 files changed, 51 insertions(+), 26 deletions(-) diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 95a537f7..213cf2e0 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -8,7 +8,6 @@ namespace CoAuthors\Blocks; use WP_Block; -use WP_REST_Request; /** * Block CoAuthors @@ -42,20 +41,16 @@ public static function render_block( array $attributes, string $content, WP_Bloc return ''; } - $authors = array_map( - function( $author ) : array { - return rest_get_server()->dispatch( - WP_REST_Request::from_url( - home_url( - sprintf( - '/wp-json/coauthors-blocks/v1/coauthor/%s', - $author->user_nicename - ) - ) - ) - )->get_data(); - }, - get_coauthors( $post_id ) + $authors = array_values( + array_filter( + array_map( + 'CoAuthors\Blocks::get_author_with_api_schema', + get_coauthors( $post_id ) + ), + function( $author ) : bool { + return ! is_null( $author ); + } + ) ); if ( ! is_array( $authors ) || empty( $authors ) ) { diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index ea0df5c1..c99211b1 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -84,18 +84,9 @@ public static function provide_author_archive_context( array $context, array $pa return $context; } - $author = rest_get_server()->dispatch( - WP_REST_Request::from_url( - home_url( - sprintf( - '/wp-json/coauthors-blocks/v1/coauthor/%s', - get_query_var( 'author_name' ) - ) - ) - ) - )->get_data(); + $author = self::get_author_with_api_schema( get_queried_object() ); - if ( ! is_array( $author ) || ! array_key_exists( 'id', $author ) ) { + if ( ! is_array( $author ) ) { return $context; } @@ -140,4 +131,43 @@ public static function enqueue_store() : void { $data ); } + + /** + * Get CoAuthor with API Schema + * + * @param false|WP_User|stdClass $author + * @return null|array + */ + public static function get_author_with_api_schema( $author ) : ?array { + if ( ! ( is_a( $author, 'stdClass' ) || is_a( $author, 'WP_User' ) ) ) { + return null; + } + + $data = rest_get_server()->dispatch( + WP_REST_Request::from_url( + home_url( + sprintf( + '/wp-json/coauthors-blocks/v1/coauthor/%s', + $author->user_nicename + ) + ) + ) + )->get_data(); + + if ( ! is_array( $data ) ) { + return null; + } + + // Lack of an `id` indicates an author was not found. + if ( ! array_key_exists( 'id', $data ) ) { + return null; + } + + // The presence of `code` indicates this is an error response. + if ( array_key_exists( 'code', $data ) ) { + return null; + } + + return $data; + } } From e74e2f4cc7bcbfe03b8e2a8cc630b08a1416a128 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 11:41:29 -0400 Subject: [PATCH 077/123] improve function comment --- php/blocks/class-blocks.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index c99211b1..d86d0dbb 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -134,9 +134,12 @@ public static function enqueue_store() : void { /** * Get CoAuthor with API Schema - * - * @param false|WP_User|stdClass $author - * @return null|array + * + * Use the global WP_REST_Server to fetch author data, + * so that it matches what a user would see in the editor. + * + * @param false|WP_User|stdClass $author An author object from CoAuthors Plus. + * @return null|array Either an array of data about an author, or null. */ public static function get_author_with_api_schema( $author ) : ?array { if ( ! ( is_a( $author, 'stdClass' ) || is_a( $author, 'WP_User' ) ) ) { From 55b5f0821e4b8d23309258d18dae9e8be74f66cd Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 11:57:54 -0400 Subject: [PATCH 078/123] revert change to gitignore From 0f0cd64f34e8f81530761cb935177a1ec95f8d7f Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 12:02:52 -0400 Subject: [PATCH 079/123] update readme based on compat changes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7c3f1eb1..0702bb11 100644 --- a/README.md +++ b/README.md @@ -94,17 +94,17 @@ In author archive templates, the post context is the first post by the author re If you want to display data about the author on their own archive, use the individual co-author blocks directly without wrapping them in the Co-Authors Block. -The function `CoAuthors\Blocks::provide_author_archive_context` filters the context using the `author_name` query variable to provide the correct author context. +The function `CoAuthors\Blocks::provide_author_archive_context` filters the context so the correct author is provided. #### Extending -If you create a custom block that uses the namespace and prefix `cap/coauthor-`, the author archive context will be updated and will match the REST API response used in the editor. +If you create a custom block that uses the namespace and prefix `cap/coauthor-`, the author archive context will be updated. If you have a differently named custom block, you can use the filter `coauthors_blocks_block_uses_author_context` to opt-in to the author archive context. ### Example Data -When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the coauthor blocks replicates the standard REST API response. +When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the co-author blocks resembles a response to the `/coauthors-blocks/v1/coauthor/:user-nicename` REST API endpoint. #### Extending @@ -112,4 +112,4 @@ If you have written a plugin that modifies the REST API response, you can simila ### Non-support -To declare a lack of support for Co-Author Plus blocks, use the filter `coauthors_plus_support_blocks` to return `false`. +To declare a lack of support for Co-Author Plus blocks on your site, use the filter `coauthors_plus_support_blocks` to return `false`. From b0f482c44ed49c3205f974eb597bd9f8e56ea60b Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 7 Sep 2023 13:57:59 -0400 Subject: [PATCH 080/123] use same textdomain in all blocks --- build/blocks/block-coauthor-avatar/block.json | 2 +- build/blocks/block-coauthor-featured-image/block.json | 2 +- src/blocks/block-coauthor-avatar/block.json | 2 +- src/blocks/block-coauthor-featured-image/block.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/blocks/block-coauthor-avatar/block.json b/build/blocks/block-coauthor-avatar/block.json index aaf6e3fc..f0630639 100644 --- a/build/blocks/block-coauthor-avatar/block.json +++ b/build/blocks/block-coauthor-avatar/block.json @@ -54,7 +54,7 @@ "type": "string" } }, - "textdomain": "coauthor-avatar", + "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "style": "file:./style-index.css" } \ No newline at end of file diff --git a/build/blocks/block-coauthor-featured-image/block.json b/build/blocks/block-coauthor-featured-image/block.json index ba582536..3d4dca40 100644 --- a/build/blocks/block-coauthor-featured-image/block.json +++ b/build/blocks/block-coauthor-featured-image/block.json @@ -67,7 +67,7 @@ "type": "string" } }, - "textdomain": "coauthor-feature-image", + "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "editorStyle": "file:./index.css", "style": "file:./style-index.css" diff --git a/src/blocks/block-coauthor-avatar/block.json b/src/blocks/block-coauthor-avatar/block.json index 4880cdd2..59a0e5b3 100644 --- a/src/blocks/block-coauthor-avatar/block.json +++ b/src/blocks/block-coauthor-avatar/block.json @@ -50,7 +50,7 @@ "type": "string" } }, - "textdomain": "coauthor-avatar", + "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "style": "file:./style-index.css" } diff --git a/src/blocks/block-coauthor-featured-image/block.json b/src/blocks/block-coauthor-featured-image/block.json index 3f619f04..fdc7e40c 100644 --- a/src/blocks/block-coauthor-featured-image/block.json +++ b/src/blocks/block-coauthor-featured-image/block.json @@ -61,7 +61,7 @@ "type": "string" } }, - "textdomain": "coauthor-feature-image", + "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "editorStyle": "file:./index.css", "style": "file:./style-index.css" From 0a7304cddcb937af45417476cefa648f103e33ab Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 13 Sep 2023 16:20:26 -0400 Subject: [PATCH 081/123] Update all blocks to start with version 1.0.0 --- build/blocks/block-coauthor-avatar/block.json | 2 +- build/blocks/block-coauthor-description/block.json | 2 +- build/blocks/block-coauthor-featured-image/block.json | 2 +- build/blocks/block-coauthor-name/block.json | 2 +- build/blocks/block-coauthors/block.json | 2 +- src/blocks/block-coauthor-avatar/block.json | 2 +- src/blocks/block-coauthor-description/block.json | 2 +- src/blocks/block-coauthor-featured-image/block.json | 2 +- src/blocks/block-coauthor-name/block.json | 2 +- src/blocks/block-coauthors/block.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build/blocks/block-coauthor-avatar/block.json b/build/blocks/block-coauthor-avatar/block.json index f0630639..b7933a63 100644 --- a/build/blocks/block-coauthor-avatar/block.json +++ b/build/blocks/block-coauthor-avatar/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "name": "cap/coauthor-avatar", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Author Avatar", "category": "widgets", "icon": "smiley", diff --git a/build/blocks/block-coauthor-description/block.json b/build/blocks/block-coauthor-description/block.json index aab8a9a5..9fa70938 100644 --- a/build/blocks/block-coauthor-description/block.json +++ b/build/blocks/block-coauthor-description/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "name": "cap/coauthor-description", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Author Description", "category": "widgets", "icon": "smiley", diff --git a/build/blocks/block-coauthor-featured-image/block.json b/build/blocks/block-coauthor-featured-image/block.json index 3d4dca40..0d17a6a8 100644 --- a/build/blocks/block-coauthor-featured-image/block.json +++ b/build/blocks/block-coauthor-featured-image/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "cap/coauthor-featured-image", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Author Featured Image", "category": "widgets", "icon": "smiley", diff --git a/build/blocks/block-coauthor-name/block.json b/build/blocks/block-coauthor-name/block.json index b57a457a..2e4ef3a4 100644 --- a/build/blocks/block-coauthor-name/block.json +++ b/build/blocks/block-coauthor-name/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "name": "cap/coauthor-name", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Author Name", "category": "widgets", "icon": "smiley", diff --git a/build/blocks/block-coauthors/block.json b/build/blocks/block-coauthors/block.json index 0a804cb4..08bc0a92 100644 --- a/build/blocks/block-coauthors/block.json +++ b/build/blocks/block-coauthors/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "name": "cap/coauthors", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Authors", "category": "widgets", "icon": "smiley", diff --git a/src/blocks/block-coauthor-avatar/block.json b/src/blocks/block-coauthor-avatar/block.json index 59a0e5b3..76ed73b8 100644 --- a/src/blocks/block-coauthor-avatar/block.json +++ b/src/blocks/block-coauthor-avatar/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "name": "cap/coauthor-avatar", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Author Avatar", "category": "widgets", "icon": "smiley", diff --git a/src/blocks/block-coauthor-description/block.json b/src/blocks/block-coauthor-description/block.json index 29f38887..587d7ba7 100644 --- a/src/blocks/block-coauthor-description/block.json +++ b/src/blocks/block-coauthor-description/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "name": "cap/coauthor-description", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Author Description", "category": "widgets", "icon": "smiley", diff --git a/src/blocks/block-coauthor-featured-image/block.json b/src/blocks/block-coauthor-featured-image/block.json index fdc7e40c..0ea041ec 100644 --- a/src/blocks/block-coauthor-featured-image/block.json +++ b/src/blocks/block-coauthor-featured-image/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "cap/coauthor-featured-image", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Author Featured Image", "category": "widgets", "icon": "smiley", diff --git a/src/blocks/block-coauthor-name/block.json b/src/blocks/block-coauthor-name/block.json index 4e7d77bd..ec20ce5a 100644 --- a/src/blocks/block-coauthor-name/block.json +++ b/src/blocks/block-coauthor-name/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "name": "cap/coauthor-name", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Author Name", "category": "widgets", "icon": "smiley", diff --git a/src/blocks/block-coauthors/block.json b/src/blocks/block-coauthors/block.json index 709a5e42..72aa1aab 100644 --- a/src/blocks/block-coauthors/block.json +++ b/src/blocks/block-coauthors/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "name": "cap/coauthors", - "version": "0.1.0", + "version": "1.0.0", "title": "Co-Authors", "category": "widgets", "icon": "smiley", From 78addc63820ae2c186e352335a96a932355f45ee Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 13 Sep 2023 16:58:14 -0400 Subject: [PATCH 082/123] Consistent package name, add docblock since 3.6.0 --- .../class-coauthors-blocks-controller.php | 32 ++++++++++----- .../class-block-coauthor-avatar.php | 12 ++++-- .../class-block-coauthor-description.php | 13 ++++-- .../class-block-coauthor-featured-image.php | 10 ++++- .../class-block-coauthor-name.php | 17 ++++++-- .../block-coauthors/class-block-coauthors.php | 40 +++++++++++++------ php/blocks/class-blocks.php | 18 +++++++++ php/blocks/templating/class-templating.php | 15 +++++-- 8 files changed, 121 insertions(+), 36 deletions(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index b0a1f2fb..ba75233c 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -1,8 +1,9 @@ {$content}"; @@ -23,6 +28,7 @@ public static function render_element( string $name, ?string $attributes = '', ? * Get Render Element Function * Dependency inject render_element so you can use in array_map or add_filter. * + * @since 3.6.0 * @param string $name * @param null|string $attributes * @return callable @@ -35,7 +41,8 @@ public static function get_render_element_function( string $name, ?string $attri /** * Render Self Closing Element - * + * + * @since 3.6.0 * @param string $name * @param null|string $attributes * @return string @@ -47,6 +54,7 @@ public static function render_self_closing_element( string $name, ?string $attri /** * Render Attribute String * + * @since 3.6.0 * @param string|int $key Attribute key. * @param mixed $value Attribute value. For boolean attributes, set value the same as the key. * @return string @@ -63,7 +71,8 @@ public static function render_attribute_string( $key, $value ) : string { /** * Render Attributes - * + * + * @since 3.6.0 * @param array $attributes An associative array of attributes and their values. */ public static function render_attributes( array $attributes ) : string { From 54d2ddcf6b469784e1ce52460a79dd78d01959fe Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 15 Sep 2023 10:29:18 -0400 Subject: [PATCH 083/123] All source files have newline at end of file --- php/blocks/templating/class-templating.php | 2 +- src/blocks/block-coauthor-avatar/style.css | 2 +- src/blocks/block-coauthor-description/block.json | 2 +- src/blocks/block-coauthor-name/block.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/php/blocks/templating/class-templating.php b/php/blocks/templating/class-templating.php index c150167a..135f6127 100644 --- a/php/blocks/templating/class-templating.php +++ b/php/blocks/templating/class-templating.php @@ -94,4 +94,4 @@ function( $value ) { return implode( ' ', $validated_attribute_strings ); } -} \ No newline at end of file +} diff --git a/src/blocks/block-coauthor-avatar/style.css b/src/blocks/block-coauthor-avatar/style.css index ae778a99..df1c6541 100644 --- a/src/blocks/block-coauthor-avatar/style.css +++ b/src/blocks/block-coauthor-avatar/style.css @@ -30,4 +30,4 @@ .wp-block-cap-coauthor-avatar:is(.alignleft,.alignright,.aligncenter) { display: table; -} \ No newline at end of file +} diff --git a/src/blocks/block-coauthor-description/block.json b/src/blocks/block-coauthor-description/block.json index 587d7ba7..15347b4a 100644 --- a/src/blocks/block-coauthor-description/block.json +++ b/src/blocks/block-coauthor-description/block.json @@ -46,4 +46,4 @@ "textdomain": "co-authors-plus", "editorScript": "file:./index.js", "editorStyle": "file:./index.css" -} \ No newline at end of file +} diff --git a/src/blocks/block-coauthor-name/block.json b/src/blocks/block-coauthor-name/block.json index ec20ce5a..e780aac7 100644 --- a/src/blocks/block-coauthor-name/block.json +++ b/src/blocks/block-coauthor-name/block.json @@ -59,4 +59,4 @@ "editorScript": "file:./index.js", "editorStyle": "file:./index.css", "style": "file:./style-index.css" -} \ No newline at end of file +} From df0d892498d2ac1d8c1c1582d6c1a3e41a364f15 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 15 Sep 2023 10:41:07 -0400 Subject: [PATCH 084/123] Use __DIR__ instead of dirname( __FILE__ ) --- co-authors-plus.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 0cc10f3d..014f3d01 100755 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -35,10 +35,10 @@ require_once __DIR__ . '/php/class-coauthors-iterator.php'; // Blocks -require_once dirname( __FILE__ ) . '/php/blocks/class-blocks.php'; +require_once __DIR__ . '/php/blocks/class-blocks.php'; // REST APIs for Blocks -require_once dirname( __FILE__ ) . '/php/api/endpoints/class-coauthors-blocks-controller.php'; +require_once __DIR__ . '/php/api/endpoints/class-coauthors-blocks-controller.php'; if ( defined( 'WP_CLI' ) && WP_CLI ) { require_once __DIR__ . '/php/class-wp-cli.php'; From 13855744ff22913c06a3c5550a698c187721777a Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 15 Sep 2023 11:05:34 -0400 Subject: [PATCH 085/123] Replace all uses for realpath with plugin constant --- .../block-coauthor-avatar/class-block-coauthor-avatar.php | 2 +- .../class-block-coauthor-description.php | 2 +- .../class-block-coauthor-featured-image.php | 2 +- php/blocks/block-coauthor-name/class-block-coauthor-name.php | 2 +- php/blocks/block-coauthors/class-block-coauthors.php | 2 +- php/blocks/class-blocks.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php index a56f3f13..b87a46ea 100644 --- a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php +++ b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php @@ -23,7 +23,7 @@ class Block_CoAuthor_Avatar { */ public static function register_block() : void { register_block_type( - realpath( __DIR__ . '/../../..' ) . '/build/blocks/block-coauthor-avatar', + dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthor-avatar', array( 'render_callback' => array( __CLASS__, 'render_block' ), ) diff --git a/php/blocks/block-coauthor-description/class-block-coauthor-description.php b/php/blocks/block-coauthor-description/class-block-coauthor-description.php index 9355e4cb..bd09f8dc 100644 --- a/php/blocks/block-coauthor-description/class-block-coauthor-description.php +++ b/php/blocks/block-coauthor-description/class-block-coauthor-description.php @@ -23,7 +23,7 @@ class Block_CoAuthor_Description { */ public static function register_block() : void { register_block_type( - realpath( __DIR__ . '/../../..' ) . '/build/blocks/block-coauthor-description', + dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthor-description', array( 'render_callback' => array( __CLASS__, 'render_block' ), ) diff --git a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php index f0588333..c5fed932 100644 --- a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php +++ b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php @@ -23,7 +23,7 @@ class Block_CoAuthor_Featured_Image { */ public static function register_block() : void { register_block_type( - realpath( __DIR__ . '/../../..' ) . '/build/blocks/block-coauthor-featured-image', + dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthor-featured-image', array( 'render_callback' => array( __CLASS__, 'render_block' ), ) diff --git a/php/blocks/block-coauthor-name/class-block-coauthor-name.php b/php/blocks/block-coauthor-name/class-block-coauthor-name.php index 205bbbb5..ee07474e 100644 --- a/php/blocks/block-coauthor-name/class-block-coauthor-name.php +++ b/php/blocks/block-coauthor-name/class-block-coauthor-name.php @@ -23,7 +23,7 @@ class Block_CoAuthor_Name { */ public static function register_block() : void { register_block_type( - realpath( __DIR__ . '/../../..' ) . '/build/blocks/block-coauthor-name', + dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthor-name', array( 'render_callback' => array( __CLASS__, 'render_block' ), ) diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 72279da0..7e014995 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -23,7 +23,7 @@ class Block_CoAuthors { */ public static function register_block() : void { register_block_type( - realpath( __DIR__ . '/../../..' ) . '/build/blocks/block-coauthors', + dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthors', array( 'render_callback' => array( __CLASS__, 'render_block' ), ) diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index a84d78d4..32e26abc 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -116,7 +116,7 @@ public static function provide_author_archive_context( array $context, array $pa * @since 3.6.0 */ public static function enqueue_store() : void { - $asset = require realpath( __DIR__ . '/../..' ) . '/build/blocks-store/index.asset.php'; + $asset = require dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks-store/index.asset.php'; wp_enqueue_script( 'coauthors-blocks-store', From c91405d409bb2bac016bca3824bd9518e7cb0b53 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 15 Sep 2023 11:35:41 -0400 Subject: [PATCH 086/123] Fix arg key, validate and sanitize in right order --- php/api/endpoints/class-coauthors-blocks-controller.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index ba75233c..dd999b6a 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -53,12 +53,15 @@ public function register_routes() : void { '/coauthors/(?P[\d]+)', array( 'args' => array( - 'id' => array( + 'post_id' => array( 'description' => __( 'Unique identifier for a post.' ), 'type' => 'integer', 'validate_callback' => function( $post_id ) : bool { - return is_int( $post_id ); + return 0 !== absint( $post_id ); }, + 'sanitize_callback' => function( $post_id ) : int { + return absint( $post_id ); + } ), ), array( From 0e61ba5afe8e1014c398f816ae0229f6d63c980f Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 15 Sep 2023 11:41:45 -0400 Subject: [PATCH 087/123] Remove digit regex also covered by word --- php/api/endpoints/class-coauthors-blocks-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index dd999b6a..95495800 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -74,7 +74,7 @@ public function register_routes() : void { register_rest_route( 'coauthors-blocks/v1', - '/coauthor/(?P[\d\w-]+)', + '/coauthor/(?P[\w-]+)', array( 'args' => array( 'user_nicename' => array( From 0dbbd85462dea70e1ab80ab316e7d0d9de3b2904 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 15 Sep 2023 13:19:33 -0400 Subject: [PATCH 088/123] Fix PHPCS warnings about space and punctuation --- .../class-block-coauthor-avatar.php | 20 ++++++++-------- .../class-block-coauthor-description.php | 10 ++++---- .../class-block-coauthor-featured-image.php | 14 +++++------ .../class-block-coauthor-name.php | 10 ++++---- .../block-coauthors/class-block-coauthors.php | 24 +++++++++---------- php/blocks/class-blocks.php | 12 +++++----- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php index b87a46ea..d3aad54f 100644 --- a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php +++ b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php @@ -33,8 +33,8 @@ public static function register_block() : void { * Render Block * * @since 3.6.0 - * @param array $attributes - * @param string $content + * @param array $attributes + * @param string $content * @param WP_Block $block * @return string */ @@ -53,12 +53,12 @@ public static function render_block( array $attributes, string $content, WP_Bloc } $display_name = $author['display_name'] ?? ''; - $link = $author['link'] ?? ''; - $is_link = '' !== $link && $attributes['isLink'] ?? false; - $rel = $attributes['rel'] ?? ''; + $link = $author['link'] ?? ''; + $is_link = '' !== $link && $attributes['isLink'] ?? false; + $rel = $attributes['rel'] ?? ''; + $size = $attributes['size'] ?? 24; - $size = $attributes['size'] ?? 24; - $srcset = array_map( + $srcset = array_map( function( $size, $url ) { return "{$url} {$size}w"; }, @@ -70,11 +70,11 @@ function( $size, $url ) { array_merge( get_block_core_post_featured_image_border_attributes( $attributes ), array( - 'src' => $avatar_urls[$size], + 'src' => $avatar_urls[ $size ], 'width' => $size, 'height' => $size, 'sizes' => "{$size}px", - 'srcset' => implode( ', ', $srcset), + 'srcset' => implode( ', ', $srcset ), ) ) ); @@ -92,7 +92,7 @@ function( $size, $url ) { 'title' => sprintf( __( 'Posts by %s', 'co-authors-plus' ), $display_name ), ) ); - $inner_content = Templating::render_element('a', $link_attributes, $image); + $inner_content = Templating::render_element( 'a', $link_attributes, $image ); } else { $inner_content = $image; } diff --git a/php/blocks/block-coauthor-description/class-block-coauthor-description.php b/php/blocks/block-coauthor-description/class-block-coauthor-description.php index bd09f8dc..37f8f47a 100644 --- a/php/blocks/block-coauthor-description/class-block-coauthor-description.php +++ b/php/blocks/block-coauthor-description/class-block-coauthor-description.php @@ -6,9 +6,9 @@ * @since 3.6.0 */ - namespace CoAuthors\Blocks; +namespace CoAuthors\Blocks; - use WP_Block; +use WP_Block; /** * Block CoAuthor Description @@ -34,8 +34,8 @@ public static function register_block() : void { * Render Block * * @since 3.6.0 - * @param array $attributes - * @param string $content + * @param array $attributes + * @param string $content * @param WP_Block $block * @return string */ @@ -81,7 +81,7 @@ public static function get_custom_block_wrapper_attributes( array $attributes ) } return array( - 'class' => $default['class'] . ' ' . esc_attr( "has-text-align-{$text_align}" ) + 'class' => $default['class'] . ' ' . esc_attr( "has-text-align-{$text_align}" ), ); } } diff --git a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php index c5fed932..d684f5fe 100644 --- a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php +++ b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php @@ -34,8 +34,8 @@ public static function register_block() : void { * Render Block * * @since 3.6.0 - * @param array $attributes - * @param string $content + * @param array $attributes + * @param string $content * @param WP_Block $block * @return string */ @@ -78,16 +78,16 @@ public static function render_block( array $attributes, string $content, WP_Bloc 'height' => 'height', 'scale' => 'object-fit', 'aspectRatio' => 'aspect-ratio', - 'verticalAlign' => 'vertical-align' + 'verticalAlign' => 'vertical-align', ); $styles = array_map( function( string $key, string $style ) use ( $attributes ) : string { - if ( empty( $attributes[$key] ) ) { + if ( empty( $attributes[ $key ] ) ) { return ''; } return sprintf( - "%s;", + '%s;', safecss_filter_attr( "{$style}:{$attributes[$key]}" ) @@ -100,7 +100,7 @@ function( string $key, string $style ) use ( $attributes ) : string { $image_attributes = array_merge( array( 'class' => '', - 'style' => '' + 'style' => '', ), get_block_core_post_featured_image_border_attributes( $attributes ) ); @@ -117,7 +117,7 @@ function( string $key, string $style ) use ( $attributes ) : string { 'title' => sprintf( __( 'Posts by %s', 'co-authors-plus' ), $display_name ), ) ); - $inner_content = Templating::render_element( 'a', $link_attributes, $feature_image ); + $inner_content = Templating::render_element( 'a', $link_attributes, $feature_image ); } else { $inner_content = $feature_image; } diff --git a/php/blocks/block-coauthor-name/class-block-coauthor-name.php b/php/blocks/block-coauthor-name/class-block-coauthor-name.php index ee07474e..0a2c3edd 100644 --- a/php/blocks/block-coauthor-name/class-block-coauthor-name.php +++ b/php/blocks/block-coauthor-name/class-block-coauthor-name.php @@ -34,8 +34,8 @@ public static function register_block() : void { * Render Block * * @since 3.6.0 - * @param array $attributes - * @param string $content + * @param array $attributes + * @param string $content * @param WP_Block $block * @return string */ @@ -72,7 +72,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc 'title' => sprintf( __( 'Posts by %s', 'co-authors-plus' ), $display_name ), ) ); - $inner_content = Templating::render_element( 'a', $link_attributes, $display_name ); + $inner_content = Templating::render_element( 'a', $link_attributes, $display_name ); } else { $inner_content = $display_name; } @@ -96,7 +96,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc * @return string */ public static function sanitize_tag_name( string $tag_name ) : string { - if ( in_array( $tag_name, array_keys( wp_kses_allowed_html('post') ), true ) ) { + if ( in_array( $tag_name, array_keys( wp_kses_allowed_html( 'post' ) ), true ) ) { return $tag_name; } return 'p'; @@ -117,7 +117,7 @@ public static function get_custom_block_wrapper_attributes( array $attributes ) return array(); } return array( - 'class' => esc_attr( "has-text-align-{$text_align}" ) + 'class' => esc_attr( "has-text-align-{$text_align}" ), ); } } diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 7e014995..879b188a 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -34,8 +34,8 @@ public static function register_block() : void { * Render Block * * @since 3.6.0 - * @param array $attributes - * @param string $content + * @param array $attributes + * @param string $content * @param WP_Block $block * @return string */ @@ -105,7 +105,7 @@ public static function get_composed_map_function( ...$fns ) : callable { return array_reduce( $fns, function( $v, callable $f ) { - return $f($v); + return $f( $v ); }, $value ); @@ -123,7 +123,7 @@ public static function render_prefix( string $prefix ) : string { if ( empty( $prefix ) ) { return $prefix; } - return Templating::render_element('span', 'class="wp-block-cap-coauthors__prefix"', $prefix); + return Templating::render_element( 'span', 'class="wp-block-cap-coauthors__prefix"', $prefix ); } /** @@ -137,7 +137,7 @@ public static function render_suffix( string $suffix ) : string { if ( empty( $suffix ) ) { return $suffix; } - return Templating::render_element('span', 'class="wp-block-cap-coauthors__suffix"', $suffix); + return Templating::render_element( 'span', 'class="wp-block-cap-coauthors__suffix"', $suffix ); } /** @@ -154,11 +154,11 @@ public static function render_coauthors_blocks_with_template( array $template, a self::get_template_render_function( $template ), // To match JSX from editor, remove line-breaks between blocks. function( $content ) { - return str_replace("\n", '', $content ); + return str_replace( "\n", '', $content ); }, // To match JSX from editor, trim whitespace around blocks. 'trim', - Templating::get_render_element_function('div', 'class="wp-block-cap-coauthor"') + Templating::get_render_element_function( 'div', 'class="wp-block-cap-coauthor"' ) ), $authors ); @@ -174,8 +174,8 @@ function( $content ) { */ private static function merge_blocks_with_separators( array $blocks, array $separators ) : array { return array_map( - function(...$args) : string { - return implode($args); + function( ...$args ) : string { + return implode( $args ); }, $blocks, $separators @@ -186,7 +186,7 @@ function(...$args) : string { * Get Separators * * @since 3.6.0 - * @param int $count + * @param int $count * @param array $attributes */ private static function get_separators( int $count, array $attributes ) : array { @@ -236,7 +236,7 @@ private static function get_separator( array $attributes ) : string { * Get Last Separator * * @since 3.6.0 - * @param array $attributes + * @param array $attributes * @param string $default */ private static function get_last_separator( array $attributes, string $default ) : string { @@ -291,7 +291,7 @@ private static function get_block_as_template( WP_Block $block ) : array { $block->parsed_block, array( 'innerContent' => array_slice( $block->parsed_block['innerContent'], 1, -1 ), - 'blockName' => 'core/null' + 'blockName' => 'core/null', ) ); } diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 32e26abc..26ec7552 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -67,7 +67,7 @@ public static function initialize_blocks() : void { * Provide Author Archive Context * * @since 3.6.0 - * @param array $context, + * @param array $context * @param array $parsed_block * @return array */ @@ -89,7 +89,7 @@ public static function provide_author_archive_context( array $context, array $pa */ $uses_author_context = apply_filters( 'coauthors_blocks_block_uses_author_context', - 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ), + 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ), $parsed_block['blockName'] ); @@ -106,7 +106,7 @@ public static function provide_author_archive_context( array $context, array $pa } return array( - 'cap/author' => $author + 'cap/author' => $author, ); } @@ -133,12 +133,12 @@ public static function enqueue_store() : void { 'display_name' => 'FirstName LastName', 'description' => array( 'raw' => 'Placeholder description from Co-Authors block.', - 'rendered' => '

Placeholder description from Co-Authors block.

' + 'rendered' => '

Placeholder description from Co-Authors block.

', ), 'link' => '#', 'featured_media' => 0, - 'avatar_urls' => array_map( '__return_empty_string', array_flip( rest_get_avatar_sizes() ) ) - ) + 'avatar_urls' => array_map( '__return_empty_string', array_flip( rest_get_avatar_sizes() ) ), + ), ) ); From d977c42be5d38db5ab1bca15e8f3639bef356668 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 15 Sep 2023 13:28:38 -0400 Subject: [PATCH 089/123] FIx PHPCS space and punctuation warnings in api --- .../class-coauthors-blocks-controller.php | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index 95495800..db2e7196 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -61,14 +61,14 @@ public function register_routes() : void { }, 'sanitize_callback' => function( $post_id ) : int { return absint( $post_id ); - } + }, ), ), array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permission_check' ), - ) + ), ) ); @@ -85,14 +85,14 @@ public function register_routes() : void { }, 'sanitize_callback' => function( $slug ) { return sanitize_title( $slug ); - } + }, ), ), array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => '__return_true', - ) + ), ) ); } @@ -114,7 +114,7 @@ public function get_item( $request ) { if ( ! is_object( $coauthor ) ) { return new WP_Error( 'rest_not_found', - __('Sorry, we could not find that co-author.'), + __( 'Sorry, we could not find that co-author.' ), array( 'status' => 404 ) ); } @@ -122,7 +122,7 @@ public function get_item( $request ) { if ( ! self::is_coauthor( $coauthor ) ) { return new WP_Error( 'rest_unusable_data', - __('Sorry, an unusable response was produced.'), + __( 'Sorry, an unusable response was produced.' ), array( 'status' => 406 ) ); } @@ -154,7 +154,7 @@ public function get_items( $request ) { if ( ! is_array( $coauthors ) ) { return new WP_Error( 'rest_unusable_data', - __('Sorry, an unusable response was produced.'), + __( 'Sorry, an unusable response was produced.' ), array( 'status' => 406 ) ); } @@ -214,19 +214,19 @@ public function get_item_schema() : array { 'title' => 'coauthors-block', 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'Either user id or guest author id.', 'co-authors-plus' ), 'type' => 'integer', 'context' => array( 'view' ), - 'readonly' => true + 'readonly' => true, ), - 'display_name' => array( + 'display_name' => array( 'description' => __( 'Author name for display.', 'co-authors-plus' ), 'type' => 'string', 'context' => array( 'view' ), - 'readonly' => true + 'readonly' => true, ), - 'description' => array( + 'description' => array( 'description' => __( 'Author description.', 'co-authors-plus' ), 'type' => 'object', 'context' => array( 'view' ), @@ -243,28 +243,28 @@ public function get_item_schema() : array { 'type' => 'string', 'context' => array( 'view' ), 'readonly' => true, - ) - ) + ), + ), ), - 'user_nicename' => array( + 'user_nicename' => array( 'description' => __( 'Unique author slug.', 'co-authors-plus' ), 'type' => 'string', 'context' => array( 'view' ), - 'readonly' => true + 'readonly' => true, ), - 'link' => array( + 'link' => array( 'description' => __( 'URL of author archive.', 'co-authors-plus' ), 'type' => 'string', 'context' => array( 'view' ), - 'readonly' => true + 'readonly' => true, ), 'featured_media' => array( 'description' => __( 'Id of guest author feature image.', 'co-authors-plus' ), 'type' => 'integer', 'context' => array( 'view' ), 'readonly' => true, - ) - ) + ), + ), ); if ( get_option( 'show_avatars' ) ) { From 3bd50f9f7041906bdd4173ec945d530a4698cb89 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 15 Sep 2023 13:32:05 -0400 Subject: [PATCH 090/123] Correctly add filter for render_block_context --- php/blocks/class-blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 26ec7552..02e06cc2 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -36,7 +36,7 @@ public static function initialize_blocks() : void { return; } - add_action( 'render_block_context', array( __CLASS__, 'provide_author_archive_context' ), 10, 2 ); + add_filter( 'render_block_context', array( __CLASS__, 'provide_author_archive_context' ), 10, 2 ); add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_store' ) ); /** From 463b1f285a59c7abb792b32f338dcf160dfdfa91 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 18 Sep 2023 19:43:15 -0400 Subject: [PATCH 091/123] Update type declaration spacing per code standard --- co-authors-plus.php | 2 +- .../class-coauthors-blocks-controller.php | 12 ++++----- .../class-block-coauthor-avatar.php | 4 +-- .../class-block-coauthor-description.php | 6 ++--- .../class-block-coauthor-featured-image.php | 4 +-- .../class-block-coauthor-name.php | 8 +++--- .../block-coauthors/class-block-coauthors.php | 26 +++++++++---------- php/blocks/class-blocks.php | 8 +++--- php/blocks/templating/class-templating.php | 10 +++---- 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 014f3d01..c4b5877e 100755 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -218,7 +218,7 @@ function cap_get_coauthor_terms_for_post( $post_id ) { /** * Register CoAuthor Blocks REST API Routes */ -function cap_register_coauthors_blocks_rest_api_routes() : void { +function cap_register_coauthors_blocks_rest_api_routes(): void { global $coauthors_plus; $controller = new CoAuthors\API\Endpoints\CoAuthors_Blocks_Controller( $coauthors_plus ); $controller->register_routes(); diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index db2e7196..eff53150 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -47,7 +47,7 @@ public function __construct( CoAuthors_Plus $coauthors_plus ) { * * @since 3.6.0 */ - public function register_routes() : void { + public function register_routes(): void { register_rest_route( 'coauthors-blocks/v1', '/coauthors/(?P[\d]+)', @@ -56,10 +56,10 @@ public function register_routes() : void { 'post_id' => array( 'description' => __( 'Unique identifier for a post.' ), 'type' => 'integer', - 'validate_callback' => function( $post_id ) : bool { + 'validate_callback' => function( $post_id ): bool { return 0 !== absint( $post_id ); }, - 'sanitize_callback' => function( $post_id ) : int { + 'sanitize_callback' => function( $post_id ): int { return absint( $post_id ); }, ), @@ -80,7 +80,7 @@ public function register_routes() : void { 'user_nicename' => array( 'description' => __( 'Nicename / slug for co-author.' ), 'type' => 'string', - 'validate_callback' => function( $slug ) : bool { + 'validate_callback' => function( $slug ): bool { return is_string( $slug ); }, 'sanitize_callback' => function( $slug ) { @@ -136,7 +136,7 @@ public function get_item( $request ) { * @since 3.6.0 * @param WP_User|stdClass $coauthor */ - public static function is_coauthor( $coauthor ) : bool { + public static function is_coauthor( $coauthor ): bool { return is_a( $coauthor, 'WP_User' ) || ( property_exists( $coauthor, 'type' ) && 'guest-author' === $coauthor->type ); } @@ -203,7 +203,7 @@ public function get_items_permission_check( WP_REST_Request $request ) { * @since 3.6.0 * @return array Item schema data. */ - public function get_item_schema() : array { + public function get_item_schema(): array { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); diff --git a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php index d3aad54f..2d8d44f7 100644 --- a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php +++ b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php @@ -21,7 +21,7 @@ class Block_CoAuthor_Avatar { * * @since 3.6.0 */ - public static function register_block() : void { + public static function register_block(): void { register_block_type( dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthor-avatar', array( @@ -38,7 +38,7 @@ public static function register_block() : void { * @param WP_Block $block * @return string */ - public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + public static function render_block( array $attributes, string $content, WP_Block $block ): string { $author = $block->context['cap/author'] ?? array(); diff --git a/php/blocks/block-coauthor-description/class-block-coauthor-description.php b/php/blocks/block-coauthor-description/class-block-coauthor-description.php index 37f8f47a..dbc75a18 100644 --- a/php/blocks/block-coauthor-description/class-block-coauthor-description.php +++ b/php/blocks/block-coauthor-description/class-block-coauthor-description.php @@ -21,7 +21,7 @@ class Block_CoAuthor_Description { * * @since 3.6.0 */ - public static function register_block() : void { + public static function register_block(): void { register_block_type( dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthor-description', array( @@ -39,7 +39,7 @@ public static function register_block() : void { * @param WP_Block $block * @return string */ - public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + public static function render_block( array $attributes, string $content, WP_Block $block ): string { $author = $block->context['cap/author'] ?? array(); @@ -68,7 +68,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc * @param array $attributes * @return array */ - public static function get_custom_block_wrapper_attributes( array $attributes ) : array { + public static function get_custom_block_wrapper_attributes( array $attributes ): array { $default = array( 'class' => 'is-layout-flow', diff --git a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php index d684f5fe..fd0beddd 100644 --- a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php +++ b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php @@ -21,7 +21,7 @@ class Block_CoAuthor_Featured_Image { * * @since 3.6.0 */ - public static function register_block() : void { + public static function register_block(): void { register_block_type( dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthor-featured-image', array( @@ -39,7 +39,7 @@ public static function register_block() : void { * @param WP_Block $block * @return string */ - public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + public static function render_block( array $attributes, string $content, WP_Block $block ): string { $author = $block->context['cap/author'] ?? array(); diff --git a/php/blocks/block-coauthor-name/class-block-coauthor-name.php b/php/blocks/block-coauthor-name/class-block-coauthor-name.php index 0a2c3edd..fb806c42 100644 --- a/php/blocks/block-coauthor-name/class-block-coauthor-name.php +++ b/php/blocks/block-coauthor-name/class-block-coauthor-name.php @@ -21,7 +21,7 @@ class Block_CoAuthor_Name { * * @since 3.6.0 */ - public static function register_block() : void { + public static function register_block(): void { register_block_type( dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthor-name', array( @@ -39,7 +39,7 @@ public static function register_block() : void { * @param WP_Block $block * @return string */ - public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + public static function render_block( array $attributes, string $content, WP_Block $block ): string { $author = $block->context['cap/author'] ?? array(); @@ -95,7 +95,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc * @param string $tag_name * @return string */ - public static function sanitize_tag_name( string $tag_name ) : string { + public static function sanitize_tag_name( string $tag_name ): string { if ( in_array( $tag_name, array_keys( wp_kses_allowed_html( 'post' ) ), true ) ) { return $tag_name; } @@ -109,7 +109,7 @@ public static function sanitize_tag_name( string $tag_name ) : string { * @param array $attributes * @return array */ - public static function get_custom_block_wrapper_attributes( array $attributes ) : array { + public static function get_custom_block_wrapper_attributes( array $attributes ): array { $text_align = $attributes['textAlign'] ?? ''; diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 879b188a..ffddd77c 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -21,7 +21,7 @@ class Block_CoAuthors { * * @since 3.6.0 */ - public static function register_block() : void { + public static function register_block(): void { register_block_type( dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthors', array( @@ -39,7 +39,7 @@ public static function register_block() : void { * @param WP_Block $block * @return string */ - public static function render_block( array $attributes, string $content, WP_Block $block ) : string { + public static function render_block( array $attributes, string $content, WP_Block $block ): string { $post_id = array_key_exists( 'postId', $block->context ) ? absint( $block->context['postId'] ) : 0; @@ -100,7 +100,7 @@ function( $author ) : bool { * @param array $fns * @return callable */ - public static function get_composed_map_function( ...$fns ) : callable { + public static function get_composed_map_function( ...$fns ): callable { return function ( $value ) use ( $fns ) { return array_reduce( $fns, @@ -119,7 +119,7 @@ function( $v, callable $f ) { * @param string $prefix * @return string */ - public static function render_prefix( string $prefix ) : string { + public static function render_prefix( string $prefix ): string { if ( empty( $prefix ) ) { return $prefix; } @@ -133,7 +133,7 @@ public static function render_prefix( string $prefix ) : string { * @param string $suffix * @return string */ - public static function render_suffix( string $suffix ) : string { + public static function render_suffix( string $suffix ): string { if ( empty( $suffix ) ) { return $suffix; } @@ -148,7 +148,7 @@ public static function render_suffix( string $suffix ) : string { * @param array $authors * @return array */ - public static function render_coauthors_blocks_with_template( array $template, array $authors ) : array { + public static function render_coauthors_blocks_with_template( array $template, array $authors ): array { return array_map( self::get_composed_map_function( self::get_template_render_function( $template ), @@ -172,7 +172,7 @@ function( $content ) { * @param array $separators * @return array */ - private static function merge_blocks_with_separators( array $blocks, array $separators ) : array { + private static function merge_blocks_with_separators( array $blocks, array $separators ): array { return array_map( function( ...$args ) : string { return implode( $args ); @@ -189,7 +189,7 @@ function( ...$args ) : string { * @param int $count * @param array $attributes */ - private static function get_separators( int $count, array $attributes ) : array { + private static function get_separators( int $count, array $attributes ): array { if ( 1 === $count ) { return array(); } @@ -216,7 +216,7 @@ private static function get_separators( int $count, array $attributes ) : array * @param array $attributes * @return string $separator */ - private static function get_separator( array $attributes ) : string { + private static function get_separator( array $attributes ): string { $separator = esc_html( $attributes['separator'] ?? '' ); @@ -239,7 +239,7 @@ private static function get_separator( array $attributes ) : string { * @param array $attributes * @param string $default */ - private static function get_last_separator( array $attributes, string $default ) : string { + private static function get_last_separator( array $attributes, string $default ): string { $last_separator = esc_html( $attributes['lastSeparator'] ?? '' ); @@ -262,8 +262,8 @@ private static function get_last_separator( array $attributes, string $default ) * @param array $block_template * @return callable */ - private static function get_template_render_function( array $block_template ) : callable { - return function( array $author ) use ( $block_template ) : string { + private static function get_template_render_function( array $block_template ): callable { + return function( array $author ) use ( $block_template ): string { return ( new WP_Block( $block_template, @@ -286,7 +286,7 @@ private static function get_template_render_function( array $block_template ) : * @param WP_Block $block * @return array */ - private static function get_block_as_template( WP_Block $block ) : array { + private static function get_block_as_template( WP_Block $block ): array { return array_merge( $block->parsed_block, array( diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 02e06cc2..5b9c37ed 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -30,7 +30,7 @@ public function __construct() { * * @since 3.6.0 */ - public static function initialize_blocks() : void { + public static function initialize_blocks(): void { if ( ! apply_filters( 'coauthors_plus_support_blocks', true ) ) { return; @@ -71,7 +71,7 @@ public static function initialize_blocks() : void { * @param array $parsed_block * @return array */ - public static function provide_author_archive_context( array $context, array $parsed_block ) : array { + public static function provide_author_archive_context( array $context, array $parsed_block ): array { if ( ! is_author() ) { return $context; } @@ -115,7 +115,7 @@ public static function provide_author_archive_context( array $context, array $pa * * @since 3.6.0 */ - public static function enqueue_store() : void { + public static function enqueue_store(): void { $asset = require dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks-store/index.asset.php'; wp_enqueue_script( @@ -159,7 +159,7 @@ public static function enqueue_store() : void { * @param false|WP_User|stdClass $author An author object from CoAuthors Plus. * @return null|array Either an array of data about an author, or null. */ - public static function get_author_with_api_schema( $author ) : ?array { + public static function get_author_with_api_schema( $author ): ?array { if ( ! ( is_a( $author, 'stdClass' ) || is_a( $author, 'WP_User' ) ) ) { return null; } diff --git a/php/blocks/templating/class-templating.php b/php/blocks/templating/class-templating.php index 135f6127..203ee643 100644 --- a/php/blocks/templating/class-templating.php +++ b/php/blocks/templating/class-templating.php @@ -20,7 +20,7 @@ class Templating { * * @since 3.6.0 */ - public static function render_element( string $name, ?string $attributes = '', ?string $content = '' ) : string { + public static function render_element( string $name, ?string $attributes = '', ?string $content = '' ): string { return "<{$name} $attributes>{$content}"; } @@ -33,7 +33,7 @@ public static function render_element( string $name, ?string $attributes = '', ? * @param null|string $attributes * @return callable */ - public static function get_render_element_function( string $name, ?string $attributes = '' ) : callable { + public static function get_render_element_function( string $name, ?string $attributes = '' ): callable { return function( string $content ) use ( $name, $attributes ) : string { return self::render_element( $name, $attributes, $content ); }; @@ -47,7 +47,7 @@ public static function get_render_element_function( string $name, ?string $attri * @param null|string $attributes * @return string */ - public static function render_self_closing_element( string $name, ?string $attributes = '' ) : string { + public static function render_self_closing_element( string $name, ?string $attributes = '' ): string { return "<{$name} $attributes/>"; } @@ -59,7 +59,7 @@ public static function render_self_closing_element( string $name, ?string $attri * @param mixed $value Attribute value. For boolean attributes, set value the same as the key. * @return string */ - public static function render_attribute_string( $key, $value ) : string { + public static function render_attribute_string( $key, $value ): string { if ( empty( $value ) ) { return ''; } @@ -75,7 +75,7 @@ public static function render_attribute_string( $key, $value ) : string { * @since 3.6.0 * @param array $attributes An associative array of attributes and their values. */ - public static function render_attributes( array $attributes ) : string { + public static function render_attributes( array $attributes ): string { $attribute_strings = array_map( array( __CLASS__, 'render_attribute_string' ), From 7735e6aae883ce093b89fc946fd1915e391cbfd0 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 18 Sep 2023 19:45:41 -0400 Subject: [PATCH 092/123] Use Automattic\CoAuthorsPlus for package name --- php/api/endpoints/class-coauthors-blocks-controller.php | 2 +- .../block-coauthor-avatar/class-block-coauthor-avatar.php | 2 +- .../class-block-coauthor-description.php | 2 +- .../class-block-coauthor-featured-image.php | 2 +- php/blocks/block-coauthor-name/class-block-coauthor-name.php | 2 +- php/blocks/block-coauthors/class-block-coauthors.php | 2 +- php/blocks/class-blocks.php | 2 +- php/blocks/templating/class-templating.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index eff53150..59b7930a 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -2,7 +2,7 @@ /** * CoAuthor Blocks * - * @package CoAuthors + * @package Automattic\CoAuthorsPlus * @since 3.6.0 */ diff --git a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php index 2d8d44f7..1b3e23d6 100644 --- a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php +++ b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php @@ -2,7 +2,7 @@ /** * Co-Author Avatar * - * @package CoAuthors + * @package Automattic\CoAuthorsPlus * @since 3.6.0 */ diff --git a/php/blocks/block-coauthor-description/class-block-coauthor-description.php b/php/blocks/block-coauthor-description/class-block-coauthor-description.php index dbc75a18..3ac37894 100644 --- a/php/blocks/block-coauthor-description/class-block-coauthor-description.php +++ b/php/blocks/block-coauthor-description/class-block-coauthor-description.php @@ -2,7 +2,7 @@ /** * Co-Author Description Block * - * @package CoAuthors + * @package Automattic\CoAuthorsPlus * @since 3.6.0 */ diff --git a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php index fd0beddd..ee6cdb8e 100644 --- a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php +++ b/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php @@ -2,7 +2,7 @@ /** * Co-Author Display Featured Image * - * @package CoAuthors + * @package Automattic\CoAuthorsPlus * @since 3.6.0 */ diff --git a/php/blocks/block-coauthor-name/class-block-coauthor-name.php b/php/blocks/block-coauthor-name/class-block-coauthor-name.php index fb806c42..efe71c35 100644 --- a/php/blocks/block-coauthor-name/class-block-coauthor-name.php +++ b/php/blocks/block-coauthor-name/class-block-coauthor-name.php @@ -2,7 +2,7 @@ /** * Co-Author Name Block * - * @package CoAuthors + * @package Automattic\CoAuthorsPlus * @since 3.6.0 */ diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index ffddd77c..9add8e35 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -2,7 +2,7 @@ /** * Co-Authors Block * - * @package CoAuthors + * @package Automattic\CoAuthorsPlus * @since 3.6.0 */ diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 5b9c37ed..19247f0b 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -2,7 +2,7 @@ /** * Blocks * - * @package CoAuthors + * @package Automattic\CoAuthorsPlus * @since 3.6.0 */ diff --git a/php/blocks/templating/class-templating.php b/php/blocks/templating/class-templating.php index 203ee643..f4ec3ab4 100644 --- a/php/blocks/templating/class-templating.php +++ b/php/blocks/templating/class-templating.php @@ -2,7 +2,7 @@ /** * Templating * - * @package CoAuthors + * @package Automattic\CoAuthorsPlus * @since 3.6.0 */ From a71a22b96d45d2a0c6cadc2b2a902b5ec2b1cd9c Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 18 Sep 2023 19:58:25 -0400 Subject: [PATCH 093/123] Change __construct to run, call it statically --- co-authors-plus.php | 2 +- php/blocks/class-blocks.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index c4b5877e..e940bac0 100755 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -47,7 +47,7 @@ global $coauthors_plus; $coauthors_plus = new CoAuthors_Plus(); $coauthors_endpoint = new CoAuthors\API\Endpoints( $coauthors_plus ); -new CoAuthors\Blocks(); +CoAuthors\Blocks::run(); if ( ! function_exists( 'wp_notify_postauthor' ) ) : /** diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 19247f0b..be6141c8 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -17,11 +17,11 @@ */ class Blocks { /** - * Construct + * Run * * @since 3.6.0 */ - public function __construct() { + public static function run(): void { add_action( 'init', array( __CLASS__, 'initialize_blocks' ) ); } From cdc0c09f0f0ae1802f469199dcd9a42dca81ea2e Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 18 Sep 2023 20:00:37 -0400 Subject: [PATCH 094/123] Remove single-use variable in route registration --- co-authors-plus.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index e940bac0..7075896b 100755 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -220,7 +220,6 @@ function cap_get_coauthor_terms_for_post( $post_id ) { */ function cap_register_coauthors_blocks_rest_api_routes(): void { global $coauthors_plus; - $controller = new CoAuthors\API\Endpoints\CoAuthors_Blocks_Controller( $coauthors_plus ); - $controller->register_routes(); + (new CoAuthors\API\Endpoints\CoAuthors_Blocks_Controller( $coauthors_plus ))->register_routes(); } add_action( 'rest_api_init', 'cap_register_coauthors_blocks_rest_api_routes' ); From 8d2654b64f600579d1371d0e363149cc4d2de898 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 21 Sep 2023 14:27:54 -0400 Subject: [PATCH 095/123] Use correct text domain in API controller --- .../class-coauthors-blocks-controller.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index 59b7930a..ed3c515f 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -54,7 +54,7 @@ public function register_routes(): void { array( 'args' => array( 'post_id' => array( - 'description' => __( 'Unique identifier for a post.' ), + 'description' => __( 'Unique identifier for a post.', 'co-authors-plus' ), 'type' => 'integer', 'validate_callback' => function( $post_id ): bool { return 0 !== absint( $post_id ); @@ -78,7 +78,7 @@ public function register_routes(): void { array( 'args' => array( 'user_nicename' => array( - 'description' => __( 'Nicename / slug for co-author.' ), + 'description' => __( 'Nicename / slug for co-author.', 'co-authors-plus' ), 'type' => 'string', 'validate_callback' => function( $slug ): bool { return is_string( $slug ); @@ -114,7 +114,7 @@ public function get_item( $request ) { if ( ! is_object( $coauthor ) ) { return new WP_Error( 'rest_not_found', - __( 'Sorry, we could not find that co-author.' ), + __( 'Sorry, we could not find that co-author.', 'co-authors-plus' ), array( 'status' => 404 ) ); } @@ -122,7 +122,7 @@ public function get_item( $request ) { if ( ! self::is_coauthor( $coauthor ) ) { return new WP_Error( 'rest_unusable_data', - __( 'Sorry, an unusable response was produced.' ), + __( 'Sorry, an unusable response was produced.', 'co-authors-plus' ), array( 'status' => 406 ) ); } @@ -154,7 +154,7 @@ public function get_items( $request ) { if ( ! is_array( $coauthors ) ) { return new WP_Error( 'rest_unusable_data', - __( 'Sorry, an unusable response was produced.' ), + __( 'Sorry, an unusable response was produced.', 'co-authors-plus' ), array( 'status' => 406 ) ); } @@ -192,7 +192,7 @@ public function get_items_permission_check( WP_REST_Request $request ) { return new WP_Error( 'rest_cannot_view', - __( 'Sorry, you are not allowed to view co-authors of this post.' ), + __( 'Sorry, you are not allowed to view co-authors of this post.', 'co-authors-plus' ), array( 'status' => rest_authorization_required_code() ) ); } @@ -215,7 +215,7 @@ public function get_item_schema(): array { 'type' => 'object', 'properties' => array( 'id' => array( - 'description' => __( 'Either user id or guest author id.', 'co-authors-plus' ), + 'description' => __( 'Either user ID or guest author ID.', 'co-authors-plus' ), 'type' => 'integer', 'context' => array( 'view' ), 'readonly' => true, @@ -233,13 +233,13 @@ public function get_item_schema(): array { 'readonly' => true, 'properties' => array( 'raw' => array( - 'description' => __( '', 'co-authors-plus' ), + 'description' => __( 'Author description as stored in database.', 'co-authors-plus' ), 'type' => 'string', 'context' => array( 'view' ), 'readonly' => true, ), 'rendered' => array( - 'description' => __( '', 'co-authors-plus' ), + 'description' => __( 'Author description as rendered in HTML content.', 'co-authors-plus' ), 'type' => 'string', 'context' => array( 'view' ), 'readonly' => true, @@ -259,7 +259,7 @@ public function get_item_schema(): array { 'readonly' => true, ), 'featured_media' => array( - 'description' => __( 'Id of guest author feature image.', 'co-authors-plus' ), + 'description' => __( 'ID of guest author featured image.', 'co-authors-plus' ), 'type' => 'integer', 'context' => array( 'view' ), 'readonly' => true, @@ -288,7 +288,7 @@ public function get_item_schema(): array { __METHOD__, sprintf( /* translators: %s: register_rest_field */ - esc_html__( 'Please use %s to add new schema properties.' ), + esc_html__( 'Please use %s to add new schema properties.', 'co-authors-plus' ), 'register_rest_field' ), '5.4.0' From 29de04dcc7d8c159712f84bfd9ef160bdba378d5 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 21 Sep 2023 15:10:19 -0400 Subject: [PATCH 096/123] Update description block so UI says biography --- build/blocks/block-coauthor-description/block.json | 9 +++++++-- src/blocks/block-coauthor-description/block.json | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/build/blocks/block-coauthor-description/block.json b/build/blocks/block-coauthor-description/block.json index 9fa70938..64a1b256 100644 --- a/build/blocks/block-coauthor-description/block.json +++ b/build/blocks/block-coauthor-description/block.json @@ -3,10 +3,15 @@ "apiVersion": 2, "name": "cap/coauthor-description", "version": "1.0.0", - "title": "Co-Author Description", + "title": "Co-Author Biography", "category": "widgets", "icon": "smiley", - "description": "Display a co-author's description.", + "description": "Display a co-author's biographical description.", + "keywords": [ + "description", + "bio", + "biography" + ], "supports": { "html": false, "color": { diff --git a/src/blocks/block-coauthor-description/block.json b/src/blocks/block-coauthor-description/block.json index 15347b4a..04d87ba1 100644 --- a/src/blocks/block-coauthor-description/block.json +++ b/src/blocks/block-coauthor-description/block.json @@ -3,10 +3,15 @@ "apiVersion": 2, "name": "cap/coauthor-description", "version": "1.0.0", - "title": "Co-Author Description", + "title": "Co-Author Biography", "category": "widgets", "icon": "smiley", - "description": "Display a co-author's description.", + "description": "Display a co-author's biographical description.", + "keywords": [ + "description", + "bio", + "biography" + ], "supports": { "html": false, "color": { From 80533d0367509955a75aeb9c221b32ecdf40cf6d Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 22 Sep 2023 10:10:32 -0400 Subject: [PATCH 097/123] Provide i18n by moving separator attributes to PHP --- build/blocks/block-coauthors/block.json | 16 ------ .../block-coauthors/class-block-coauthors.php | 49 +++++++++++++++++++ src/blocks/block-coauthors/block.json | 16 ------ 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/build/blocks/block-coauthors/block.json b/build/blocks/block-coauthors/block.json index 08bc0a92..ea25755b 100644 --- a/build/blocks/block-coauthors/block.json +++ b/build/blocks/block-coauthors/block.json @@ -40,28 +40,12 @@ } }, "attributes": { - "separator": { - "type": "string", - "default": ", " - }, - "lastSeparator": { - "type": "string", - "default": " and " - }, "layout": { "type": "object", "default": { "type": "inline" } }, - "prefix": { - "type": "string", - "default": "By " - }, - "suffix": { - "type": "string", - "default": "" - }, "textAlign": { "type": "string" } diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 9add8e35..794e2206 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -22,6 +22,9 @@ class Block_CoAuthors { * @since 3.6.0 */ public static function register_block(): void { + + add_filter( 'block_type_metadata_settings', array( __CLASS__, 'separator_internationalization' ), 10, 2 ); + register_block_type( dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthors', array( @@ -30,6 +33,52 @@ public static function register_block(): void { ); } + /** + * Separator Internationalization + * Provide i18n for the default prefix, separators and suffix attributes during block registration. + * + * @param array $settings Array of determined settings for registering a block type. + * @param array $metadata Metadata provided for registering a block type. + * @return array Updated settings that include internationalized attributes. + */ + public static function separator_internationalization( array $settings, array $metadata ): array { + + if ( ! array_key_exists( 'name', $metadata ) ) { + return $settings; + } + + if ( 'cap/coauthors' !== $metadata['name'] ) { + return $settings; + } + + return array_merge( + $settings, + array( + 'attributes' => array_merge( + $settings['attributes'], + array( + 'prefix' => array( + 'type' => 'string', + 'default' => apply_filters( 'coauthors_default_before', __( 'By ', 'co-authors-plus' ) ), + ), + 'separator' => array( + 'type' => 'string', + 'default' => apply_filters( 'coauthors_default_between', ', ' ), + ), + 'lastSeparator' => array( + 'type' => 'string', + 'default' => apply_filters( 'coauthors_default_between_last', __( ' and ', 'co-authors-plus' ) ), + ), + 'suffix' => array( + 'type' => 'string', + 'default' => apply_filters( 'coauthors_default_after', '' ), + ), + ) + ), + ) + ); + } + /** * Render Block * diff --git a/src/blocks/block-coauthors/block.json b/src/blocks/block-coauthors/block.json index 72aa1aab..28ba4d55 100644 --- a/src/blocks/block-coauthors/block.json +++ b/src/blocks/block-coauthors/block.json @@ -38,28 +38,12 @@ } }, "attributes": { - "separator": { - "type": "string", - "default": ", " - }, - "lastSeparator": { - "type": "string", - "default": " and " - }, "layout": { "type": "object", "default": { "type": "inline" } }, - "prefix": { - "type": "string", - "default": "By " - }, - "suffix": { - "type": "string", - "default": "" - }, "textAlign": { "type": "string" } From e81c7c41e431a70c00a03d07ba4bef343477ec38 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 22 Sep 2023 10:37:27 -0400 Subject: [PATCH 098/123] No magic number, use first avatar size --- .../block-coauthor-avatar/class-block-coauthor-avatar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php index 1b3e23d6..c89b2d65 100644 --- a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php +++ b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php @@ -56,7 +56,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc $link = $author['link'] ?? ''; $is_link = '' !== $link && $attributes['isLink'] ?? false; $rel = $attributes['rel'] ?? ''; - $size = $attributes['size'] ?? 24; + $size = $attributes['size'] ?? array_keys( $avatar_urls )[0]; $srcset = array_map( function( $size, $url ) { From 5cef443a00668e6a67f1d16aedc7e53692f009c2 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 22 Sep 2023 10:43:32 -0400 Subject: [PATCH 099/123] Use sanitize_html_class for html classes --- .../class-block-coauthor-description.php | 2 +- php/blocks/block-coauthor-name/class-block-coauthor-name.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/blocks/block-coauthor-description/class-block-coauthor-description.php b/php/blocks/block-coauthor-description/class-block-coauthor-description.php index 3ac37894..f881d32f 100644 --- a/php/blocks/block-coauthor-description/class-block-coauthor-description.php +++ b/php/blocks/block-coauthor-description/class-block-coauthor-description.php @@ -81,7 +81,7 @@ public static function get_custom_block_wrapper_attributes( array $attributes ): } return array( - 'class' => $default['class'] . ' ' . esc_attr( "has-text-align-{$text_align}" ), + 'class' => $default['class'] . ' ' . sanitize_html_class( "has-text-align-{$text_align}" ), ); } } diff --git a/php/blocks/block-coauthor-name/class-block-coauthor-name.php b/php/blocks/block-coauthor-name/class-block-coauthor-name.php index efe71c35..da61c036 100644 --- a/php/blocks/block-coauthor-name/class-block-coauthor-name.php +++ b/php/blocks/block-coauthor-name/class-block-coauthor-name.php @@ -117,7 +117,7 @@ public static function get_custom_block_wrapper_attributes( array $attributes ): return array(); } return array( - 'class' => esc_attr( "has-text-align-{$text_align}" ), + 'class' => sanitize_html_class( "has-text-align-{$text_align}" ), ); } } From 8876417b3b39a4807502160d38d7e39d7dd7d359 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 22 Sep 2023 11:59:24 -0400 Subject: [PATCH 100/123] Separate and document REST API routes --- .../class-coauthors-blocks-controller.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-blocks-controller.php index ed3c515f..d4adea30 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-blocks-controller.php @@ -48,6 +48,20 @@ public function __construct( CoAuthors_Plus $coauthors_plus ) { * @since 3.6.0 */ public function register_routes(): void { + $this->register_coauthors_route(); + $this->register_coauthor_route(); + } + + /** + * Register Co-Authors Route + * + * Provide a post ID as an integer to retrieve an array of associated co-authors. + * + * Example: `/wp-json/coauthors-blocks/v1/coauthors/11111` + * + * @since 3.6.0 + */ + public function register_coauthors_route(): void { register_rest_route( 'coauthors-blocks/v1', '/coauthors/(?P[\d]+)', @@ -71,7 +85,18 @@ public function register_routes(): void { ), ) ); + } + /** + * Register Co-Author Route + * + * Provide a user nicename as a hyphen-separated string to retrieve a single co-author. + * + * Example: `/wp-json/coauthors-blocks/v1/coauthor/user-nicename` + * + * @since 3.6.0 + */ + public function register_coauthor_route(): void { register_rest_route( 'coauthors-blocks/v1', '/coauthor/(?P[\w-]+)', From ef410344aa81d4bf1dc1a0d35a142480df0f5663 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 22 Sep 2023 13:56:18 -0400 Subject: [PATCH 101/123] Add text domain to i18n in edit.js for all blocks --- .../block-coauthor-avatar/index.asset.php | 2 +- build/blocks/block-coauthor-avatar/index.js | 2 +- .../index.asset.php | 2 +- .../block-coauthor-featured-image/index.js | 2 +- .../block-coauthor-name/index.asset.php | 2 +- build/blocks/block-coauthor-name/index.js | 2 +- build/blocks/block-coauthors/index.asset.php | 2 +- build/blocks/block-coauthors/index.js | 2 +- src/blocks/block-coauthor-avatar/edit.js | 59 ++++++++++++++----- .../block-coauthor-featured-image/edit.js | 59 ++++++++++++++----- src/blocks/block-coauthor-name/edit.js | 9 ++- src/blocks/block-coauthors/edit.js | 18 +++--- 12 files changed, 107 insertions(+), 54 deletions(-) diff --git a/build/blocks/block-coauthor-avatar/index.asset.php b/build/blocks/block-coauthor-avatar/index.asset.php index 11bf750f..6a647206 100644 --- a/build/blocks/block-coauthor-avatar/index.asset.php +++ b/build/blocks/block-coauthor-avatar/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'd1af74c4edac99f57c88'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'cd0a28f7e1757a1d76b5'); diff --git a/build/blocks/block-coauthor-avatar/index.js b/build/blocks/block-coauthor-avatar/index.js index bc0dd46d..e2407432 100644 --- a/build/blocks/block-coauthor-avatar/index.js +++ b/build/blocks/block-coauthor-avatar/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={857:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.i18n,n=window.wp.blockEditor,a=window.wp.components,r=window.wp.data;function o(e){let{dimensions:n,style:a,className:r}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(n)),[n]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:r,src:o,style:a,width:n.width,height:n.height})}var i=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(i.u2,{edit:function(e){var i;let{context:s,attributes:c,setAttributes:u}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=c,g=(0,r.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),m=s["cap/author"]||g,{avatar_urls:b}=m;if(!b||0===b.length)return null;const f=Object.keys(b).map((e=>({value:e,label:`${e} x ${e}`}))),w=(0,n.__experimentalUseBorderProps)(c),_=null!==(i=b[v])&&void 0!==i?i:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,n.useBlockProps)(),""===_?(0,t.createElement)(o,{className:w.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...w.style}}):(0,t.createElement)("img",{style:{...w.style,verticalAlign:d},width:v,height:v,src:`${b[v]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Avatar Settings")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Avatar size"),value:v,options:f,onChange:e=>{u({size:Number(e)})}}),(0,t.createElement)(a.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive."),onChange:()=>u({isLink:!h}),checked:h}),h&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:p,onChange:e=>u({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:d,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{u({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function n(e){var a=l[e];if(void 0!==a)return a.exports;var r=l[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.m=t,e=[],n.O=function(t,l,a,r){if(!l){var o=1/0;for(u=0;u=r)&&Object.keys(n.O).every((function(e){return n.O[e](l[s])}))?l.splice(s--,1):(i=!1,r0&&e[u-1][2]>r;u--)e[u]=e[u-1];e[u]=[l,a,r]},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};n.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,r,o=l[0],i=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in i)n.o(i,a)&&(n.m[a]=i[a]);if(s)var u=s(n)}for(t&&t(l);cfunction(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(o)),[o]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:r,style:a,width:o.width,height:o.height})}var i=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(i.u2,{edit:function(e){var i;let{context:s,attributes:u,setAttributes:c}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=u,g=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),m=s["cap/author"]||g,{avatar_urls:_}=m;if(!_||0===_.length)return null;const b=Object.keys(_).map((e=>({value:e,label:`${e} x ${e}`}))),f=(0,o.__experimentalUseBorderProps)(u),w=null!==(i=_[v])&&void 0!==i?i:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,o.useBlockProps)(),""===w?(0,t.createElement)(r,{className:f.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...f.style}}):(0,t.createElement)("img",{style:{...f.style,verticalAlign:d},width:v,height:v,src:`${_[v]}`})),(0,t.createElement)(o.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Avatar Settings","co-authors-plus")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Avatar size","co-authors-plus"),value:v,options:b,onChange:e=>{c({size:Number(e)})}}),(0,t.createElement)(a.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive.","co-authors-plus"),onChange:()=>c({isLink:!h}),checked:h}),h&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align","co-authors-plus"),value:d,options:[{value:"",label:(0,l.__)("Default","co-authors-plus")},{value:"baseline",label:(0,l.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,l.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,l.__)("Middle","co-authors-plus")},{value:"sub",label:(0,l.__)("Sub","co-authors-plus")},{value:"super",label:(0,l.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,l.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,l.__)("Text Top","co-authors-plus")},{value:"top",label:(0,l.__)("Top","co-authors-plus")}],onChange:e=>{c({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))}})}},l={};function o(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.m=t,e=[],o.O=function(t,l,a,n){if(!l){var r=1/0;for(c=0;c=n)&&Object.keys(o.O).every((function(e){return o.O[e](l[s])}))?l.splice(s--,1):(i=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[l,a,n]},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,r=l[0],i=l[1],s=l[2],u=0;if(r.some((function(t){return 0!==e[t]}))){for(a in i)o.o(i,a)&&(o.m[a]=i[a]);if(s)var c=s(o)}for(t&&t(l);u array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '74613b74c8f2a40a4d57'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a6e968eb133431c21528'); diff --git a/build/blocks/block-coauthor-featured-image/index.js b/build/blocks/block-coauthor-featured-image/index.js index 11b40ca5..8523dfc9 100644 --- a/build/blocks/block-coauthor-featured-image/index.js +++ b/build/blocks/block-coauthor-featured-image/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={301:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.i18n,i=window.wp.blockEditor,a=window.wp.components,n=window.wp.data,o=window.wp.coreData;const r=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"cover",label:(0,l._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"contain",label:(0,l._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(a.__experimentalToggleGroupControlOption,{value:"fill",label:(0,l._x)("Fill","Scale option for Image dimension control")})),s="cover",c={cover:(0,l.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,l.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,l.__)("Image will be stretched and distorted to completely fill the space.")};var u=e=>{let{clientId:n,attributes:{aspectRatio:o,width:u,height:h,scale:g,sizeSlug:m},setAttributes:d,imageSizeOptions:p=[]}=e;const _=(0,a.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),b=h||o&&"auto"!==o;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!o,label:(0,l.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:o,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(a.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!u,label:(0,l.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:u||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!g&&g!==s,label:w,onDeselect:()=>d({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:n},(0,t.createElement)(a.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:g,help:c[g],onChange:e=>d({scale:e}),isBlock:!0},r)),!!p.length&&(0,t.createElement)(a.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,l.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:n},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:m||"full",options:p,onChange:e=>d({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:i,style:a,className:n}=e;const o=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(i)),[i]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:o,style:a,width:i.width,height:i.height})}function g(e,t){var l,i;return null==e||null===(l=e.media_details)||void 0===l||null===(i=l.sizes[t])||void 0===i?void 0:i.source_url}var m=JSON.parse('{"u2":"cap/coauthor-featured-image"}');(0,e.registerBlockType)(m.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:c,clientId:m}=e;const{aspectRatio:d,height:p,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=r,S=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,n.useSelect)((e=>0!==E.featured_media&&e(o.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,n.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const i=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),i=Object.keys(t);return Array.from(new Set([...l.filter((e=>i.includes(e)))]))}(e,t);return l&&i.includes(l)?l:i[Math.max(0,i.length-1)]}(C,k,b),B=function(e,t,l){if(!e)return{};const i=e.media_details.sizes[l];if("full"===l)return{width:i.width,height:i.height};const a=t[l];if(!0===a.crop||a.width===a.height)return{width:a.width,height:a.height};const n=i.width/i.height;return a.width>a.height?{width:a.width,height:a.width/n}:{width:a.height*n,height:a.height}}(C,k,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,O),T=(0,i.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(u,{clientId:m,attributes:r,setAttributes:s,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author feature image"),className:T.className,src:g(C,O),style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&p?"auto":x,height:!p&&x?"auto":p,aspectRatio:d,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Feature Image Settings")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make feature image a link to author archive."),onChange:()=>s({isLink:!_}),checked:_}),_&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Coauthors Layout")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align"),value:f,options:[{value:"",label:"Default"},{value:"baseline",label:"Baseline"},{value:"bottom",label:"Bottom"},{value:"middle",label:"Middle"},{value:"sub",label:"Sub"},{value:"super",label:"Super"},{value:"text-bottom",label:"Text Bottom"},{value:"text-top",label:"Text Top"},{value:"top",label:"Top"}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.")}))))}})}},l={};function i(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.m=t,e=[],i.O=function(t,l,a,n){if(!l){var o=1/0;for(u=0;u=n)&&Object.keys(i.O).every((function(e){return i.O[e](l[s])}))?l.splice(s--,1):(r=!1,n0&&e[u-1][2]>n;u--)e[u]=e[u-1];e[u]=[l,a,n]},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={335:0,597:0};i.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,o=l[0],r=l[1],s=l[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in r)i.o(r,a)&&(i.m[a]=r[a]);if(s)var u=s(i)}for(t&&t(l);c{let{clientId:i,attributes:{aspectRatio:n,width:c,height:h,scale:p,sizeSlug:d},setAttributes:g,imageSizeOptions:_=[]}=e;const m=(0,o.__experimentalUseCustomUnits)({availableUnits:(0,a.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||g({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),b=h||n&&"auto"!==n;return(0,t.createElement)(a.InspectorControls,{group:"dimensions"},(0,t.createElement)(o.__experimentalToolsPanelItem,{hasValue:()=>!!n,label:(0,l.__)("Aspect ratio"),onDeselect:()=>g({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:i},(0,t.createElement)(o.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:n,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>g({aspectRatio:e})})),(0,t.createElement)(o.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>g({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:i},(0,t.createElement)(o.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:m})),(0,t.createElement)(o.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!c,label:(0,l.__)("Width"),onDeselect:()=>g({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:i},(0,t.createElement)(o.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:c||"",min:0,onChange:e=>v("width",e),units:m})),b&&(0,t.createElement)(o.__experimentalToolsPanelItem,{hasValue:()=>!!p&&p!==s,label:w,onDeselect:()=>g({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:i},(0,t.createElement)(o.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:p,help:u[p],onChange:e=>g({scale:e}),isBlock:!0},r)),!!_.length&&(0,t.createElement)(o.__experimentalToolsPanelItem,{hasValue:()=>!!d,label:(0,l.__)("Resolution"),onDeselect:()=>g({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:i},(0,t.createElement)(o.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:d||"full",options:_,onChange:e=>g({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:a,style:o,className:i}=e;const n=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(a)),[a]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:i,src:n,style:o,width:a.width,height:a.height})}function p(e,t){var l,a;return null==e||null===(l=e.media_details)||void 0===l||null===(a=l.sizes[t])||void 0===a?void 0:a.source_url}var d=JSON.parse('{"u2":"cap/coauthor-featured-image"}');(0,e.registerBlockType)(d.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:u,clientId:d}=e;const{aspectRatio:g,height:_,isLink:m,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=r,S=(0,i.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=u["cap/author"]||S,C=(0,i.useSelect)((e=>0!==E.featured_media&&e(n.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,i.useSelect)((e=>e(a.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const a=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),a=Object.keys(t);return Array.from(new Set([...l.filter((e=>a.includes(e)))]))}(e,t);return l&&a.includes(l)?l:a[Math.max(0,a.length-1)]}(C,k,b),B=function(e,t,l){if(!e)return{};const a=e.media_details.sizes[l];if("full"===l)return{width:a.width,height:a.height};const o=t[l];if(!0===o.crop||o.width===o.height)return{width:o.width,height:o.height};const i=a.width/a.height;return o.width>o.height?{width:o.width,height:o.width/i}:{width:o.height*i,height:o.height}}(C,k,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,O),T=(0,a.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(c,{clientId:d,attributes:r,setAttributes:s,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,a.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author featured image","co-authors-plus"),className:T.className,src:p(C,O),style:{width:!x&&_?"auto":x,height:!_&&x?"auto":_,aspectRatio:g,objectFit:w,verticalAlign:f,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&_?"auto":x,height:!_&&x?"auto":_,aspectRatio:g,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(a.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,l.__)("Featured Image Settings","co-authors-plus")},(0,t.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>s({isLink:!m}),checked:m}),m&&(0,t.createElement)(o.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel","co-authors-plus"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(o.PanelBody,{initialOpen:!1,title:(0,l.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(o.SelectControl,{label:(0,l.__)("Vertical align","co-authors-plus"),value:f,options:[{value:"",label:(0,l.__)("Default","co-authors-plus")},{value:"baseline",label:(0,l.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,l.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,l.__)("Middle","co-authors-plus")},{value:"sub",label:(0,l.__)("Sub","co-authors-plus")},{value:"super",label:(0,l.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,l.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,l.__)("Text Top","co-authors-plus")},{value:"top",label:(0,l.__)("Top","co-authors-plus")}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))}})}},l={};function a(e){var o=l[e];if(void 0!==o)return o.exports;var i=l[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=function(t,l,o,i){if(!l){var n=1/0;for(c=0;c=i)&&Object.keys(a.O).every((function(e){return a.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[l,o,i]},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={335:0,597:0};a.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,i,n=l[0],r=l[1],s=l[2],u=0;if(n.some((function(t){return 0!==e[t]}))){for(o in r)a.o(r,o)&&(a.m[o]=r[o]);if(s)var c=s(a)}for(t&&t(l);u array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'b5f0d7ff4f1bc015b522'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '530471a71157d61748d3'); diff --git a/build/blocks/block-coauthor-name/index.js b/build/blocks/block-coauthor-name/index.js index 4e2ebd96..d7053441 100644 --- a/build/blocks/block-coauthor-name/index.js +++ b/build/blocks/block-coauthor-name/index.js @@ -1 +1 @@ -!function(){var e={184:function(e,t){var n;!function(){"use strict";var l={}.hasOwnProperty;function r(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),m=n["cap/author"]||g,{link:v,display_name:d}=m,b=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.BlockControls,null,(0,t.createElement)(l.AlignmentControl,{value:f,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)(b,(0,l.useBlockProps)({className:u()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:v,rel:p,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(l.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,o.__)("Settings")},(0,t.createElement)(r.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make coauthor name a link"),onChange:()=>c({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel"),value:p,onChange:e=>c({rel:e})})))),(0,t.createElement)(l.InspectorControls,{group:"advanced"},(0,t.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("HTML element"),options:[{label:(0,o.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>c({tagName:e})})))}})}()}(); \ No newline at end of file +!function(){var e={184:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function l(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),m=n["cap/author"]||g,{link:v,display_name:d}=m,b=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(o.BlockControls,null,(0,t.createElement)(o.AlignmentControl,{value:f,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)(b,(0,o.useBlockProps)({className:i()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:v,rel:p,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(o.InspectorControls,null,(0,t.createElement)(l.PanelBody,{title:(0,r.__)("Settings","co-authors-plus")},(0,t.createElement)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make co-author name a link","co-authors-plus"),onChange:()=>c({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})))),(0,t.createElement)(o.InspectorControls,{group:"advanced"},(0,t.createElement)(l.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("HTML element","co-authors-plus"),options:[{label:(0,r.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>c({tagName:e})})))}})}()}(); \ No newline at end of file diff --git a/build/blocks/block-coauthors/index.asset.php b/build/blocks/block-coauthors/index.asset.php index 693147f2..9e7f2cf3 100644 --- a/build/blocks/block-coauthors/index.asset.php +++ b/build/blocks/block-coauthors/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '86b33ca9598a93fd863e'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ce764864a737c3f17b0f'); diff --git a/build/blocks/block-coauthors/index.js b/build/blocks/block-coauthors/index.js index 922f7af2..804ddbe9 100644 --- a/build/blocks/block-coauthors/index.js +++ b/build/blocks/block-coauthors/index.js @@ -1 +1 @@ -!function(){var e,t={441:function(e,t,n){"use strict";var o=window.wp.blocks,r=window.wp.element,l=window.wp.blockEditor,a=window.wp.components,c=window.wp.apiFetch,i=n.n(c),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,v=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),f=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),d=n(184),h=n.n(d);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{a(n)},s={display:o?"none":void 0};return(0,r.createElement)("div",m({},c,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function w(){return(0,r.createElement)("div",(0,l.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-name"]]}))}const g=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,o.registerBlockType)(y.u2,{edit:function(e){var t,n;let{attributes:o,setAttributes:c,clientId:p,context:d,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=o,{postId:S}=d,O=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return i()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(l.store).getBlocks(p))),z=e=>{c({layout:{...E,...e}})},G=[{icon:v,title:(0,u.__)("Inline"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,u.__)("Block"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.BlockControls,null,(0,r.createElement)(a.ToolbarGroup,{controls:G}),(0,r.createElement)(l.AlignmentControl,{value:C,onChange:e=>{c({textAlign:e})}})),(0,r.createElement)("div",(0,l.useBlockProps)({className:h()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,l.__experimentalGetGapCSSValue)(null==o||null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap)}}),A&&"inline"===E.type&&(m||y)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix"),placeholder:(0,u.__)("Prefix")+" ",value:y,onChange:e=>c({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const n=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(l.BlockContextProvider,{key:e.id,value:{"cap/author":e}},n?(0,r.createElement)(w,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:n}))})).reduce(((e,t,n,o)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthors__separator"},k&&n===o.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(m||_)&&(0,r.createElement)(l.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>c({suffix:e}),tagName:"span"})),(0,r.createElement)(l.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(a.PanelBody,{title:(0,u.__)("CoAuthors Layout")},(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Separator"),value:x||"",onChange:e=>{c({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.")}),(0,r.createElement)(a.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator"),value:k||"",onChange:e=>{c({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to distinguish the last author.")}))))},save:function(e){var t,n;let{attributes:o}=e;const{layout:a,textAlign:c}=o,i={gap:"block"===a.type?(0,l.__experimentalGetGapCSSValue)(null===(t=o.style)||void 0===t||null===(n=t.spacing)||void 0===n?void 0:n.blockGap):null},s=h()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${c}`]:c});return(0,r.createElement)("div",l.useBlockProps.save({className:s,style:i}),(0,r.createElement)(l.InnerBlocks.Content,null))}})},184:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(o.O).every((function(e){return o.O[e](n[i])}))?n.splice(i--,1):(c=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,r,l]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,l,a=n[0],c=n[1],i=n[2],s=0;if(a.some((function(t){return 0!==e[t]}))){for(r in c)o.o(c,r)&&(o.m[r]=c[r]);if(i)var u=i(o)}for(t&&t(n);s{l(o)},s={display:n?"none":void 0};return(0,r.createElement)("div",m({},c,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function w(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-name"]]}))}const g=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,n.registerBlockType)(y.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:c,clientId:p,context:f,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=n,{postId:S}=f,O=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[B,P]=(0,r.useState)([O]),[A,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return i()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(P).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{c({layout:{...E,...e}})},G=[{icon:h,title:(0,u.__)("Inline","co-authors-plus"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:v,title:(0,u.__)("Block","co-authors-plus"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:G}),(0,r.createElement)(a.AlignmentControl,{value:C,onChange:e=>{c({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:d()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),B&&"inline"===E.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix","co-authors-plus"),placeholder:(0,u.__)("Prefix","co-authors-plus")+" ",value:y,onChange:e=>c({prefix:e}),tagName:"span"}),B&&B.map((e=>{var t;const o=e.id===(A||(null===(t=B[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},o?(0,r.createElement)(w,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthors__separator"},k&&o===n.length-1?`${k}`:`${x}`),t))),B&&"inline"===E.type&&(m||_)&&(0,r.createElement)(a.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>c({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("Co-authors Layout","co-authors-plus")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{c({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator","co-authors-plus"),value:k||"",onChange:e=>{c({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:l,textAlign:c}=n,i={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},s=d()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${c}`]:c});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:i}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](o[i])}))?o.splice(i--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[o,r,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,a,l=o[0],c=o[1],i=o[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in c)n.o(c,r)&&(n.m[r]=c[r]);if(i)var u=i(n)}for(t&&t(o);s - + { @@ -77,14 +77,14 @@ export default function Edit( { context, attributes, setAttributes } ) { } } /> setAttributes( { isLink: ! isLink } ) } checked={ isLink } /> { isLink && ( setAttributes( { rel: newRel } ) @@ -92,27 +92,54 @@ export default function Edit( { context, attributes, setAttributes } ) { /> ) } - + { setAttributes( { verticalAlign: '' === value ? undefined : value } ); } } - help={ __( 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.' )} + help={ __( 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', 'co-authors-plus' )} /> diff --git a/src/blocks/block-coauthor-featured-image/edit.js b/src/blocks/block-coauthor-featured-image/edit.js index c7f966e2..3dbc7759 100644 --- a/src/blocks/block-coauthor-featured-image/edit.js +++ b/src/blocks/block-coauthor-featured-image/edit.js @@ -71,7 +71,7 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) { media ? ( {__('Author - + setAttributes( { isLink: ! isLink } ) } checked={ isLink } /> { isLink && ( setAttributes( { rel: newRel } ) @@ -122,27 +122,54 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) /> ) } - + { setAttributes( { verticalAlign: '' === value ? undefined : value } ); } } - help={ __( 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.' )} + help={ __( 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', 'co-authors-plus' )} /> diff --git a/src/blocks/block-coauthor-name/edit.js b/src/blocks/block-coauthor-name/edit.js index 4ab3da36..54c21d0e 100644 --- a/src/blocks/block-coauthor-name/edit.js +++ b/src/blocks/block-coauthor-name/edit.js @@ -57,10 +57,10 @@ export default function Edit( { context, attributes, setAttributes } ) { } - + setAttributes( { isLink: ! isLink } ) } checked={ isLink } /> @@ -68,7 +68,7 @@ export default function Edit( { context, attributes, setAttributes } ) { <> setAttributes( { rel: newRel } ) @@ -81,7 +81,7 @@ export default function Edit( { context, attributes, setAttributes } ) { )' ), value: 'p' }, { label: '', value: 'span' }, @@ -94,7 +94,6 @@ export default function Edit( { context, attributes, setAttributes } ) { ] } value={ tagName } onChange={ (value) => setAttributes( {tagName: value}) } - // help={ htmlElementMessages[ tagName ] } /> diff --git a/src/blocks/block-coauthors/edit.js b/src/blocks/block-coauthors/edit.js index 23ccefe8..7f21e161 100644 --- a/src/blocks/block-coauthors/edit.js +++ b/src/blocks/block-coauthors/edit.js @@ -103,13 +103,13 @@ export default function Edit( { attributes, setAttributes, clientId, context, is const layoutControls = [ { icon: list, - title: __( 'Inline' ), + title: __( 'Inline', 'co-authors-plus' ), onClick: () => setLayout( { type: 'inline' } ), isActive: layout.type === 'inline', }, { icon: grid, - title: __( 'Block' ), + title: __( 'Block', 'co-authors-plus' ), onClick: () => setLayout( { type: 'block' } ), isActive: layout.type === 'block', @@ -146,8 +146,8 @@ export default function Edit( { attributes, setAttributes, clientId, context, is allowedFormats={ ALLOWED_FORMATS } className="wp-block-cap-coauthors__prefix" multiline={ false } - aria-label={ __( 'Prefix' ) } - placeholder={ __( 'Prefix' ) + ' ' } + aria-label={ __( 'Prefix', 'co-authors-plus' ) } + placeholder={ __( 'Prefix', 'co-authors-plus' ) + ' ' } value={ prefix } onChange={ ( value ) => setAttributes( { prefix: value } ) @@ -215,24 +215,24 @@ export default function Edit( { attributes, setAttributes, clientId, context, is { 'inline' === layout.type && ( - + { setAttributes( { separator: nextValue } ); } } - help={ __( 'Enter character(s) used to separate authors.' ) } + help={ __( 'Enter character(s) used to separate authors.', 'co-authors-plus' ) } /> { setAttributes( { lastSeparator: nextValue } ); } } - help={ __( 'Enter character(s) used to distinguish the last author.' ) } + help={ __( 'Enter character(s) used to separate the last author.', 'co-authors-plus' ) } /> ) From 72a4a7b95bc7e70fe4a8f3d6b79d334858f9f816 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 22 Sep 2023 14:47:04 -0400 Subject: [PATCH 102/123] Update wordpress/icons dependency --- package-lock.json | 396 ++++++++++++++++++++++++++-------------------- package.json | 2 +- 2 files changed, 222 insertions(+), 176 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7016509c..bba8136d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "@wordpress/i18n": "^4.17.0" }, "devDependencies": { - "@wordpress/icons": "^2.10.2", + "@wordpress/icons": "^9.33.0", "@wordpress/scripts": "^24.0.0", "classnames": "^2.3.2", "prettier": "npm:wp-prettier@^2.2.1-beta-1", @@ -4689,19 +4689,6 @@ "react-dom": "^17.0.0" } }, - "node_modules/@wordpress/components/node_modules/@wordpress/icons": { - "version": "9.13.0", - "resolved": "https://registry.npmjs.org/@wordpress/icons/-/icons-9.13.0.tgz", - "integrity": "sha512-V8q55fI0rtzxRdJbQsAjUgg7V8JbWoncm5SyuvfEtmkL+IKTQUrYgaKO0DKPf7qaTPcZJlnOXUzy6XW+fxHmxA==", - "dependencies": { - "@babel/runtime": "^7.16.0", - "@wordpress/element": "^4.20.0", - "@wordpress/primitives": "^3.20.0" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/@wordpress/compose": { "version": "5.20.0", "resolved": "https://registry.npmjs.org/@wordpress/compose/-/compose-5.20.0.tgz", @@ -4838,9 +4825,9 @@ } }, "node_modules/@wordpress/escape-html": { - "version": "2.22.0", - "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-2.22.0.tgz", - "integrity": "sha512-GUo6VLugIZxen1rdYuotvz6Vqa+5fNtVelNjXLwDqRu0iY2RXeoTux9V5bZWXPnGb54ryqfYmR4gH6F8xZhWzQ==", + "version": "2.42.0", + "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-2.42.0.tgz", + "integrity": "sha512-hC/SfA3mrLEL1QiXEp+yEb7BhgqUkmYnXnuuuGD/xxazPVdMoW80gNxeFYnVQrNnc48EC7JbWGlTuB93D2EeMw==", "dependencies": { "@babel/runtime": "^7.16.0" }, @@ -4948,21 +4935,22 @@ } }, "node_modules/@wordpress/icons": { - "version": "2.10.3", - "resolved": "https://registry.npmjs.org/@wordpress/icons/-/icons-2.10.3.tgz", - "integrity": "sha512-hVXArGOHLE5pL1G3rHNzsUEuTR4/G6lB+enKYwhYSSIqWuSbyXbZq3nvibxpepPrLy9B3d5t6aR6QUmjMVzIcQ==", - "dev": true, + "version": "9.33.0", + "resolved": "https://registry.npmjs.org/@wordpress/icons/-/icons-9.33.0.tgz", + "integrity": "sha512-yD8b2Q21/X1riFIUBbgVh6sVhrnOYpstV9hxa4/MKesWYkyDN75KM6uaor1/tn5wyq40Shnpwxvc9kPUGI4Kgw==", "dependencies": { - "@babel/runtime": "^7.13.10", - "@wordpress/element": "^2.20.3", - "@wordpress/primitives": "^1.12.3" + "@babel/runtime": "^7.16.0", + "@wordpress/element": "^5.19.0", + "@wordpress/primitives": "^3.40.0" + }, + "engines": { + "node": ">=12" } }, "node_modules/@wordpress/icons/node_modules/@types/react": { - "version": "16.14.34", - "resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.34.tgz", - "integrity": "sha512-b99nWeGGReLh6aKBppghVqp93dFJtgtDOzc8NXM6hewD8PQ2zZG5kBLgbx+VJr7Q7WBMjHxaIl3dwpwwPIUgyA==", - "dev": true, + "version": "18.2.22", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.22.tgz", + "integrity": "sha512-60fLTOLqzarLED2O3UQImc/lsNRgG0jE/a1mPW9KjMemY0LMITWEsbS4VvZ4p6rorEHd5YKxxmMKSDK505GHpA==", "dependencies": { "@types/prop-types": "*", "@types/scheduler": "*", @@ -4970,86 +4958,60 @@ } }, "node_modules/@wordpress/icons/node_modules/@types/react-dom": { - "version": "16.9.17", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.17.tgz", - "integrity": "sha512-qSRyxEsrm5btPXnowDOs5jSkgT8ldAA0j6Qp+otHUh+xHzy3sXmgNfyhucZjAjkgpdAUw9rJe0QRtX/l+yaS4g==", - "dev": true, + "version": "18.2.7", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.7.tgz", + "integrity": "sha512-GRaAEriuT4zp9N4p1i8BDBYmEyfo+xQ3yHjJU4eiK5NDa1RmUZG+unZABUTK4/Ox/M+GaHwb6Ow8rUITrtjszA==", "dependencies": { - "@types/react": "^16" + "@types/react": "*" } }, "node_modules/@wordpress/icons/node_modules/@wordpress/element": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-2.20.3.tgz", - "integrity": "sha512-f4ZPTDf9CxiiOXiMxc4v1K7jcBMT4dsiehVOpkKzCDKboNXp4qVf8oe5PE23VGZNEjcOj5Mkg9hB57R0nqvMTw==", - "dev": true, + "version": "5.19.0", + "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-5.19.0.tgz", + "integrity": "sha512-uTRrt6zrtdXT5DkffvKSLoCw0aLOHHbV4dDnh6NNR4n2roxhPK7MQRUpybVfuzyvCTIzKPI/0E3q87AWshePNg==", "dependencies": { - "@babel/runtime": "^7.13.10", - "@types/react": "^16.9.0", - "@types/react-dom": "^16.9.0", - "@wordpress/escape-html": "^1.12.2", - "lodash": "^4.17.19", - "react": "^16.13.1", - "react-dom": "^16.13.1" - } - }, - "node_modules/@wordpress/icons/node_modules/@wordpress/escape-html": { - "version": "1.12.2", - "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-1.12.2.tgz", - "integrity": "sha512-FabgSwznhdaUwe6hr1CsGpgxQbzqEoGevv73WIL1B9GvlZ6csRWodgHfWh4P6fYqpzxFL4WYB8wPJ1PdO32XFA==", - "dev": true, - "dependencies": { - "@babel/runtime": "^7.13.10" - } - }, - "node_modules/@wordpress/icons/node_modules/@wordpress/primitives": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/@wordpress/primitives/-/primitives-1.12.3.tgz", - "integrity": "sha512-LIF44bVlJS7CJEVmk6TLuV6HZMdj5iwkyM8do4ukGY6qnZIzrXpBablgJeDBcyjzWrWRLn+w+tiZ/8l+2egoVA==", - "dev": true, - "dependencies": { - "@babel/runtime": "^7.13.10", - "@wordpress/element": "^2.20.3", - "classnames": "^2.2.5" + "@babel/runtime": "^7.16.0", + "@types/react": "^18.0.21", + "@types/react-dom": "^18.0.6", + "@wordpress/escape-html": "^2.42.0", + "change-case": "^4.1.2", + "is-plain-object": "^5.0.0", + "react": "^18.2.0", + "react-dom": "^18.2.0" + }, + "engines": { + "node": ">=12" } }, "node_modules/@wordpress/icons/node_modules/react": { - "version": "16.14.0", - "resolved": "https://registry.npmjs.org/react/-/react-16.14.0.tgz", - "integrity": "sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==", - "dev": true, + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", + "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", "dependencies": { - "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2" + "loose-envify": "^1.1.0" }, "engines": { "node": ">=0.10.0" } }, "node_modules/@wordpress/icons/node_modules/react-dom": { - "version": "16.14.0", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.14.0.tgz", - "integrity": "sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==", - "dev": true, + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", "dependencies": { "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2", - "scheduler": "^0.19.1" + "scheduler": "^0.23.0" }, "peerDependencies": { - "react": "^16.14.0" + "react": "^18.2.0" } }, "node_modules/@wordpress/icons/node_modules/scheduler": { - "version": "0.19.1", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", - "integrity": "sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==", - "dev": true, + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", "dependencies": { - "loose-envify": "^1.1.0", - "object-assign": "^4.1.1" + "loose-envify": "^1.1.0" } }, "node_modules/@wordpress/is-shallow-equal": { @@ -5153,18 +5115,85 @@ } }, "node_modules/@wordpress/primitives": { - "version": "3.20.0", - "resolved": "https://registry.npmjs.org/@wordpress/primitives/-/primitives-3.20.0.tgz", - "integrity": "sha512-+30QC2bPv3sj3aYlS9q0TZh8LSYIERd49CizHqJ2/M9XCpWV6jLPwZk+k3pcOJHIpHEBNB9lB+4UG7ulj8WxkQ==", + "version": "3.40.0", + "resolved": "https://registry.npmjs.org/@wordpress/primitives/-/primitives-3.40.0.tgz", + "integrity": "sha512-NGrcMsIKA7bBRVJPkiweOeUlnai335fyQTpwASwkpfWLbUTQ+LwKDn6hnwAsLpYot7uwflar2TPJdakglwzfIQ==", "dependencies": { "@babel/runtime": "^7.16.0", - "@wordpress/element": "^4.20.0", + "@wordpress/element": "^5.19.0", "classnames": "^2.3.1" }, "engines": { "node": ">=12" } }, + "node_modules/@wordpress/primitives/node_modules/@types/react": { + "version": "18.2.22", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.22.tgz", + "integrity": "sha512-60fLTOLqzarLED2O3UQImc/lsNRgG0jE/a1mPW9KjMemY0LMITWEsbS4VvZ4p6rorEHd5YKxxmMKSDK505GHpA==", + "dependencies": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "node_modules/@wordpress/primitives/node_modules/@types/react-dom": { + "version": "18.2.7", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.7.tgz", + "integrity": "sha512-GRaAEriuT4zp9N4p1i8BDBYmEyfo+xQ3yHjJU4eiK5NDa1RmUZG+unZABUTK4/Ox/M+GaHwb6Ow8rUITrtjszA==", + "dependencies": { + "@types/react": "*" + } + }, + "node_modules/@wordpress/primitives/node_modules/@wordpress/element": { + "version": "5.19.0", + "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-5.19.0.tgz", + "integrity": "sha512-uTRrt6zrtdXT5DkffvKSLoCw0aLOHHbV4dDnh6NNR4n2roxhPK7MQRUpybVfuzyvCTIzKPI/0E3q87AWshePNg==", + "dependencies": { + "@babel/runtime": "^7.16.0", + "@types/react": "^18.0.21", + "@types/react-dom": "^18.0.6", + "@wordpress/escape-html": "^2.42.0", + "change-case": "^4.1.2", + "is-plain-object": "^5.0.0", + "react": "^18.2.0", + "react-dom": "^18.2.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@wordpress/primitives/node_modules/react": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", + "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", + "dependencies": { + "loose-envify": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/@wordpress/primitives/node_modules/react-dom": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.0" + }, + "peerDependencies": { + "react": "^18.2.0" + } + }, + "node_modules/@wordpress/primitives/node_modules/scheduler": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", + "dependencies": { + "loose-envify": "^1.1.0" + } + }, "node_modules/@wordpress/priority-queue": { "version": "2.22.0", "resolved": "https://registry.npmjs.org/@wordpress/priority-queue/-/priority-queue-2.22.0.tgz", @@ -22840,18 +22869,6 @@ "use-lilius": "^2.0.1", "uuid": "^8.3.0", "valtio": "^1.7.0" - }, - "dependencies": { - "@wordpress/icons": { - "version": "9.13.0", - "resolved": "https://registry.npmjs.org/@wordpress/icons/-/icons-9.13.0.tgz", - "integrity": "sha512-V8q55fI0rtzxRdJbQsAjUgg7V8JbWoncm5SyuvfEtmkL+IKTQUrYgaKO0DKPf7qaTPcZJlnOXUzy6XW+fxHmxA==", - "requires": { - "@babel/runtime": "^7.16.0", - "@wordpress/element": "^4.20.0", - "@wordpress/primitives": "^3.20.0" - } - } } }, "@wordpress/compose": { @@ -22957,9 +22974,9 @@ } }, "@wordpress/escape-html": { - "version": "2.22.0", - "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-2.22.0.tgz", - "integrity": "sha512-GUo6VLugIZxen1rdYuotvz6Vqa+5fNtVelNjXLwDqRu0iY2RXeoTux9V5bZWXPnGb54ryqfYmR4gH6F8xZhWzQ==", + "version": "2.42.0", + "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-2.42.0.tgz", + "integrity": "sha512-hC/SfA3mrLEL1QiXEp+yEb7BhgqUkmYnXnuuuGD/xxazPVdMoW80gNxeFYnVQrNnc48EC7JbWGlTuB93D2EeMw==", "requires": { "@babel/runtime": "^7.16.0" } @@ -23027,21 +23044,19 @@ } }, "@wordpress/icons": { - "version": "2.10.3", - "resolved": "https://registry.npmjs.org/@wordpress/icons/-/icons-2.10.3.tgz", - "integrity": "sha512-hVXArGOHLE5pL1G3rHNzsUEuTR4/G6lB+enKYwhYSSIqWuSbyXbZq3nvibxpepPrLy9B3d5t6aR6QUmjMVzIcQ==", - "dev": true, + "version": "9.33.0", + "resolved": "https://registry.npmjs.org/@wordpress/icons/-/icons-9.33.0.tgz", + "integrity": "sha512-yD8b2Q21/X1riFIUBbgVh6sVhrnOYpstV9hxa4/MKesWYkyDN75KM6uaor1/tn5wyq40Shnpwxvc9kPUGI4Kgw==", "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/element": "^2.20.3", - "@wordpress/primitives": "^1.12.3" + "@babel/runtime": "^7.16.0", + "@wordpress/element": "^5.19.0", + "@wordpress/primitives": "^3.40.0" }, "dependencies": { "@types/react": { - "version": "16.14.34", - "resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.34.tgz", - "integrity": "sha512-b99nWeGGReLh6aKBppghVqp93dFJtgtDOzc8NXM6hewD8PQ2zZG5kBLgbx+VJr7Q7WBMjHxaIl3dwpwwPIUgyA==", - "dev": true, + "version": "18.2.22", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.22.tgz", + "integrity": "sha512-60fLTOLqzarLED2O3UQImc/lsNRgG0jE/a1mPW9KjMemY0LMITWEsbS4VvZ4p6rorEHd5YKxxmMKSDK505GHpA==", "requires": { "@types/prop-types": "*", "@types/scheduler": "*", @@ -23049,80 +23064,51 @@ } }, "@types/react-dom": { - "version": "16.9.17", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.17.tgz", - "integrity": "sha512-qSRyxEsrm5btPXnowDOs5jSkgT8ldAA0j6Qp+otHUh+xHzy3sXmgNfyhucZjAjkgpdAUw9rJe0QRtX/l+yaS4g==", - "dev": true, + "version": "18.2.7", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.7.tgz", + "integrity": "sha512-GRaAEriuT4zp9N4p1i8BDBYmEyfo+xQ3yHjJU4eiK5NDa1RmUZG+unZABUTK4/Ox/M+GaHwb6Ow8rUITrtjszA==", "requires": { - "@types/react": "^16" + "@types/react": "*" } }, "@wordpress/element": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-2.20.3.tgz", - "integrity": "sha512-f4ZPTDf9CxiiOXiMxc4v1K7jcBMT4dsiehVOpkKzCDKboNXp4qVf8oe5PE23VGZNEjcOj5Mkg9hB57R0nqvMTw==", - "dev": true, + "version": "5.19.0", + "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-5.19.0.tgz", + "integrity": "sha512-uTRrt6zrtdXT5DkffvKSLoCw0aLOHHbV4dDnh6NNR4n2roxhPK7MQRUpybVfuzyvCTIzKPI/0E3q87AWshePNg==", "requires": { - "@babel/runtime": "^7.13.10", - "@types/react": "^16.9.0", - "@types/react-dom": "^16.9.0", - "@wordpress/escape-html": "^1.12.2", - "lodash": "^4.17.19", - "react": "^16.13.1", - "react-dom": "^16.13.1" - } - }, - "@wordpress/escape-html": { - "version": "1.12.2", - "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-1.12.2.tgz", - "integrity": "sha512-FabgSwznhdaUwe6hr1CsGpgxQbzqEoGevv73WIL1B9GvlZ6csRWodgHfWh4P6fYqpzxFL4WYB8wPJ1PdO32XFA==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/primitives": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/@wordpress/primitives/-/primitives-1.12.3.tgz", - "integrity": "sha512-LIF44bVlJS7CJEVmk6TLuV6HZMdj5iwkyM8do4ukGY6qnZIzrXpBablgJeDBcyjzWrWRLn+w+tiZ/8l+2egoVA==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/element": "^2.20.3", - "classnames": "^2.2.5" + "@babel/runtime": "^7.16.0", + "@types/react": "^18.0.21", + "@types/react-dom": "^18.0.6", + "@wordpress/escape-html": "^2.42.0", + "change-case": "^4.1.2", + "is-plain-object": "^5.0.0", + "react": "^18.2.0", + "react-dom": "^18.2.0" } }, "react": { - "version": "16.14.0", - "resolved": "https://registry.npmjs.org/react/-/react-16.14.0.tgz", - "integrity": "sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==", - "dev": true, + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", + "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", "requires": { - "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2" + "loose-envify": "^1.1.0" } }, "react-dom": { - "version": "16.14.0", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.14.0.tgz", - "integrity": "sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==", - "dev": true, + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", "requires": { "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2", - "scheduler": "^0.19.1" + "scheduler": "^0.23.0" } }, "scheduler": { - "version": "0.19.1", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", - "integrity": "sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==", - "dev": true, + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", "requires": { - "loose-envify": "^1.1.0", - "object-assign": "^4.1.1" + "loose-envify": "^1.1.0" } } } @@ -23191,13 +23177,73 @@ "requires": {} }, "@wordpress/primitives": { - "version": "3.20.0", - "resolved": "https://registry.npmjs.org/@wordpress/primitives/-/primitives-3.20.0.tgz", - "integrity": "sha512-+30QC2bPv3sj3aYlS9q0TZh8LSYIERd49CizHqJ2/M9XCpWV6jLPwZk+k3pcOJHIpHEBNB9lB+4UG7ulj8WxkQ==", + "version": "3.40.0", + "resolved": "https://registry.npmjs.org/@wordpress/primitives/-/primitives-3.40.0.tgz", + "integrity": "sha512-NGrcMsIKA7bBRVJPkiweOeUlnai335fyQTpwASwkpfWLbUTQ+LwKDn6hnwAsLpYot7uwflar2TPJdakglwzfIQ==", "requires": { "@babel/runtime": "^7.16.0", - "@wordpress/element": "^4.20.0", + "@wordpress/element": "^5.19.0", "classnames": "^2.3.1" + }, + "dependencies": { + "@types/react": { + "version": "18.2.22", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.22.tgz", + "integrity": "sha512-60fLTOLqzarLED2O3UQImc/lsNRgG0jE/a1mPW9KjMemY0LMITWEsbS4VvZ4p6rorEHd5YKxxmMKSDK505GHpA==", + "requires": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "@types/react-dom": { + "version": "18.2.7", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.7.tgz", + "integrity": "sha512-GRaAEriuT4zp9N4p1i8BDBYmEyfo+xQ3yHjJU4eiK5NDa1RmUZG+unZABUTK4/Ox/M+GaHwb6Ow8rUITrtjszA==", + "requires": { + "@types/react": "*" + } + }, + "@wordpress/element": { + "version": "5.19.0", + "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-5.19.0.tgz", + "integrity": "sha512-uTRrt6zrtdXT5DkffvKSLoCw0aLOHHbV4dDnh6NNR4n2roxhPK7MQRUpybVfuzyvCTIzKPI/0E3q87AWshePNg==", + "requires": { + "@babel/runtime": "^7.16.0", + "@types/react": "^18.0.21", + "@types/react-dom": "^18.0.6", + "@wordpress/escape-html": "^2.42.0", + "change-case": "^4.1.2", + "is-plain-object": "^5.0.0", + "react": "^18.2.0", + "react-dom": "^18.2.0" + } + }, + "react": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", + "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", + "requires": { + "loose-envify": "^1.1.0" + } + }, + "react-dom": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", + "requires": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.0" + } + }, + "scheduler": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", + "requires": { + "loose-envify": "^1.1.0" + } + } } }, "@wordpress/priority-queue": { diff --git a/package.json b/package.json index 0a9e695f..074b17ff 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@wordpress/i18n": "^4.17.0" }, "devDependencies": { - "@wordpress/icons": "^2.10.2", + "@wordpress/icons": "^9.33.0", "@wordpress/scripts": "^24.0.0", "classnames": "^2.3.2", "prettier": "npm:wp-prettier@^2.2.1-beta-1", From 6d4684fcedc15ae08a1a184d60d30d1f05f220ec Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Fri, 22 Sep 2023 14:48:16 -0400 Subject: [PATCH 103/123] Add icons for each block --- build/blocks/block-coauthor-avatar/block.json | 1 - build/blocks/block-coauthor-avatar/index.asset.php | 2 +- build/blocks/block-coauthor-avatar/index.js | 2 +- build/blocks/block-coauthor-description/block.json | 1 - build/blocks/block-coauthor-description/index.asset.php | 2 +- build/blocks/block-coauthor-description/index.js | 2 +- build/blocks/block-coauthor-featured-image/block.json | 1 - build/blocks/block-coauthor-featured-image/index.asset.php | 2 +- build/blocks/block-coauthor-featured-image/index.js | 2 +- build/blocks/block-coauthor-name/block.json | 1 - build/blocks/block-coauthor-name/index.asset.php | 2 +- build/blocks/block-coauthor-name/index.js | 2 +- build/blocks/block-coauthors/block.json | 1 - build/blocks/block-coauthors/index.asset.php | 2 +- build/blocks/block-coauthors/index.js | 2 +- src/blocks/block-coauthor-avatar/block.json | 1 - src/blocks/block-coauthor-avatar/index.js | 4 +++- src/blocks/block-coauthor-description/block.json | 1 - src/blocks/block-coauthor-description/index.js | 5 +++-- src/blocks/block-coauthor-featured-image/block.json | 1 - src/blocks/block-coauthor-featured-image/index.js | 4 +++- src/blocks/block-coauthor-name/block.json | 1 - src/blocks/block-coauthor-name/index.js | 4 +++- src/blocks/block-coauthors/block.json | 1 - src/blocks/block-coauthors/index.js | 3 +++ 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/build/blocks/block-coauthor-avatar/block.json b/build/blocks/block-coauthor-avatar/block.json index b7933a63..3a9a204f 100644 --- a/build/blocks/block-coauthor-avatar/block.json +++ b/build/blocks/block-coauthor-avatar/block.json @@ -5,7 +5,6 @@ "version": "1.0.0", "title": "Co-Author Avatar", "category": "widgets", - "icon": "smiley", "description": "Display a co-author's avatar", "supports": { "align": [ diff --git a/build/blocks/block-coauthor-avatar/index.asset.php b/build/blocks/block-coauthor-avatar/index.asset.php index 6a647206..e4fcdd7e 100644 --- a/build/blocks/block-coauthor-avatar/index.asset.php +++ b/build/blocks/block-coauthor-avatar/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'cd0a28f7e1757a1d76b5'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '51e75e8924d159603b0f'); diff --git a/build/blocks/block-coauthor-avatar/index.js b/build/blocks/block-coauthor-avatar/index.js index e2407432..78c2f169 100644 --- a/build/blocks/block-coauthor-avatar/index.js +++ b/build/blocks/block-coauthor-avatar/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={857:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.i18n,o=window.wp.blockEditor,a=window.wp.components,n=window.wp.data;function r(e){let{dimensions:o,style:a,className:n}=e;const r=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(o)),[o]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:n,src:r,style:a,width:o.width,height:o.height})}var i=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(i.u2,{edit:function(e){var i;let{context:s,attributes:u,setAttributes:c}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=u,g=(0,n.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),m=s["cap/author"]||g,{avatar_urls:_}=m;if(!_||0===_.length)return null;const b=Object.keys(_).map((e=>({value:e,label:`${e} x ${e}`}))),f=(0,o.__experimentalUseBorderProps)(u),w=null!==(i=_[v])&&void 0!==i?i:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,o.useBlockProps)(),""===w?(0,t.createElement)(r,{className:f.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...f.style}}):(0,t.createElement)("img",{style:{...f.style,verticalAlign:d},width:v,height:v,src:`${_[v]}`})),(0,t.createElement)(o.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,l.__)("Avatar Settings","co-authors-plus")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Avatar size","co-authors-plus"),value:v,options:b,onChange:e=>{c({size:Number(e)})}}),(0,t.createElement)(a.ToggleControl,{label:(0,l.__)("Make avatar a link to author archive.","co-authors-plus"),onChange:()=>c({isLink:!h}),checked:h}),h&&(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})),(0,t.createElement)(a.PanelBody,{initialOpen:!1,title:(0,l.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(a.SelectControl,{label:(0,l.__)("Vertical align","co-authors-plus"),value:d,options:[{value:"",label:(0,l.__)("Default","co-authors-plus")},{value:"baseline",label:(0,l.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,l.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,l.__)("Middle","co-authors-plus")},{value:"sub",label:(0,l.__)("Sub","co-authors-plus")},{value:"super",label:(0,l.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,l.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,l.__)("Text Top","co-authors-plus")},{value:"top",label:(0,l.__)("Top","co-authors-plus")}],onChange:e=>{c({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))}})}},l={};function o(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.m=t,e=[],o.O=function(t,l,a,n){if(!l){var r=1/0;for(c=0;c=n)&&Object.keys(o.O).every((function(e){return o.O[e](l[s])}))?l.splice(s--,1):(i=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[l,a,n]},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,r=l[0],i=l[1],s=l[2],u=0;if(r.some((function(t){return 0!==e[t]}))){for(a in i)o.o(i,a)&&(o.m[a]=i[a]);if(s)var c=s(o)}for(t&&t(l);ufunction(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:n,src:r,style:o,width:l.width,height:l.height})}var u=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(u.u2,{edit:function(e){var l;let{context:o,attributes:u,setAttributes:c}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=u,m=(0,i.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),g=o["cap/author"]||m,{avatar_urls:_}=g;if(!_||0===_.length)return null;const w=Object.keys(_).map((e=>({value:e,label:`${e} x ${e}`}))),b=(0,n.__experimentalUseBorderProps)(u),f=null!==(l=_[v])&&void 0!==l?l:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,n.useBlockProps)(),""===f?(0,t.createElement)(s,{className:b.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...b.style}}):(0,t.createElement)("img",{style:{...b.style,verticalAlign:d},width:v,height:v,src:`${_[v]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,a.__)("Avatar Settings","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Avatar size","co-authors-plus"),value:v,options:w,onChange:e=>{c({size:Number(e)})}}),(0,t.createElement)(r.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive.","co-authors-plus"),onChange:()=>c({isLink:!h}),checked:h}),h&&(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})),(0,t.createElement)(r.PanelBody,{initialOpen:!1,title:(0,a.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Vertical align","co-authors-plus"),value:d,options:[{value:"",label:(0,a.__)("Default","co-authors-plus")},{value:"baseline",label:(0,a.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,a.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,a.__)("Middle","co-authors-plus")},{value:"sub",label:(0,a.__)("Sub","co-authors-plus")},{value:"super",label:(0,a.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,a.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,a.__)("Text Top","co-authors-plus")},{value:"top",label:(0,a.__)("Top","co-authors-plus")}],onChange:e=>{c({verticalAlign:""===e?void 0:e})},help:(0,a.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:o})}},l={};function o(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.m=t,e=[],o.O=function(t,l,a,n){if(!l){var r=1/0;for(c=0;c=n)&&Object.keys(o.O).every((function(e){return o.O[e](l[s])}))?l.splice(s--,1):(i=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[l,a,n]},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,r=l[0],i=l[1],s=l[2],u=0;if(r.some((function(t){return 0!==e[t]}))){for(a in i)o.o(i,a)&&(o.m[a]=i[a]);if(s)var c=s(o)}for(t&&t(l);u array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '53022b1fc8be9e6fe3b8'); + array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '7ab35d3b1fa8612137e8'); diff --git a/build/blocks/block-coauthor-description/index.js b/build/blocks/block-coauthor-description/index.js index fa72dc8f..de286e49 100644 --- a/build/blocks/block-coauthor-description/index.js +++ b/build/blocks/block-coauthor-description/index.js @@ -1 +1 @@ -!function(){var t={184:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var t=[],e=0;et("cap/blocks").getAuthorPlaceholder()),[]),p=n["cap/author"]||s,{description:f}=p;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(o.BlockControls,null,(0,r.createElement)(o.AlignmentControl,{value:c,onChange:t=>{l({textAlign:t})}})),(0,r.createElement)("div",e({},(0,o.useBlockProps)({className:u()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f.rendered}})))}})}()}(); \ No newline at end of file +!function(){var t={184:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var t=[],e=0;et("cap/blocks").getAuthorPlaceholder()),[]),p=n["cap/author"]||s,{description:f}=p;return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(a.BlockControls,null,(0,e.createElement)(a.AlignmentControl,{value:c,onChange:t=>{o({textAlign:t})}})),(0,e.createElement)("div",i({},(0,a.useBlockProps)({className:u()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f.rendered}})))},icon:o})}()}(); \ No newline at end of file diff --git a/build/blocks/block-coauthor-featured-image/block.json b/build/blocks/block-coauthor-featured-image/block.json index 0d17a6a8..73efed6c 100644 --- a/build/blocks/block-coauthor-featured-image/block.json +++ b/build/blocks/block-coauthor-featured-image/block.json @@ -5,7 +5,6 @@ "version": "1.0.0", "title": "Co-Author Featured Image", "category": "widgets", - "icon": "smiley", "description": "Featured Image from a Guest Author profile.", "supports": { "align": [ diff --git a/build/blocks/block-coauthor-featured-image/index.asset.php b/build/blocks/block-coauthor-featured-image/index.asset.php index 48a3e8a5..b626675e 100644 --- a/build/blocks/block-coauthor-featured-image/index.asset.php +++ b/build/blocks/block-coauthor-featured-image/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a6e968eb133431c21528'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'd5400753091b01ccc087'); diff --git a/build/blocks/block-coauthor-featured-image/index.js b/build/blocks/block-coauthor-featured-image/index.js index 8523dfc9..04e6720d 100644 --- a/build/blocks/block-coauthor-featured-image/index.js +++ b/build/blocks/block-coauthor-featured-image/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={301:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.i18n,a=window.wp.blockEditor,o=window.wp.components,i=window.wp.data,n=window.wp.coreData;const r=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(o.__experimentalToggleGroupControlOption,{value:"cover",label:(0,l._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(o.__experimentalToggleGroupControlOption,{value:"contain",label:(0,l._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(o.__experimentalToggleGroupControlOption,{value:"fill",label:(0,l._x)("Fill","Scale option for Image dimension control")})),s="cover",u={cover:(0,l.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,l.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,l.__)("Image will be stretched and distorted to completely fill the space.")};var c=e=>{let{clientId:i,attributes:{aspectRatio:n,width:c,height:h,scale:p,sizeSlug:d},setAttributes:g,imageSizeOptions:_=[]}=e;const m=(0,o.__experimentalUseCustomUnits)({availableUnits:(0,a.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||g({[e]:l<0?"0":t})},w=(0,l._x)("Scale","Image scaling options"),b=h||n&&"auto"!==n;return(0,t.createElement)(a.InspectorControls,{group:"dimensions"},(0,t.createElement)(o.__experimentalToolsPanelItem,{hasValue:()=>!!n,label:(0,l.__)("Aspect ratio"),onDeselect:()=>g({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:i},(0,t.createElement)(o.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Aspect ratio"),value:n,options:[{label:(0,l.__)("Original"),value:"auto"},{label:(0,l.__)("Square"),value:"1"},{label:(0,l.__)("16:9"),value:"16/9"},{label:(0,l.__)("4:3"),value:"4/3"},{label:(0,l.__)("3:2"),value:"3/2"},{label:(0,l.__)("9:16"),value:"9/16"},{label:(0,l.__)("3:4"),value:"3/4"},{label:(0,l.__)("2:3"),value:"2/3"}],onChange:e=>g({aspectRatio:e})})),(0,t.createElement)(o.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!h,label:(0,l.__)("Height"),onDeselect:()=>g({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:i},(0,t.createElement)(o.__experimentalUnitControl,{label:(0,l.__)("Height"),labelPosition:"top",value:h||"",min:0,onChange:e=>v("height",e),units:m})),(0,t.createElement)(o.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!c,label:(0,l.__)("Width"),onDeselect:()=>g({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:i},(0,t.createElement)(o.__experimentalUnitControl,{label:(0,l.__)("Width"),labelPosition:"top",value:c||"",min:0,onChange:e=>v("width",e),units:m})),b&&(0,t.createElement)(o.__experimentalToolsPanelItem,{hasValue:()=>!!p&&p!==s,label:w,onDeselect:()=>g({scale:s}),resetAllFilter:()=>({scale:s}),isShownByDefault:!0,panelId:i},(0,t.createElement)(o.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:p,help:u[p],onChange:e=>g({scale:e}),isBlock:!0},r)),!!_.length&&(0,t.createElement)(o.__experimentalToolsPanelItem,{hasValue:()=>!!d,label:(0,l.__)("Resolution"),onDeselect:()=>g({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:i},(0,t.createElement)(o.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Resolution"),value:d||"full",options:_,onChange:e=>g({sizeSlug:e}),help:(0,l.__)("Select the size of the source image.")})))};function h(e){let{dimensions:a,style:o,className:i}=e;const n=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(a)),[a]);return(0,t.createElement)("img",{alt:(0,l.__)("Placeholder image"),className:i,src:n,style:o,width:a.width,height:a.height})}function p(e,t){var l,a;return null==e||null===(l=e.media_details)||void 0===l||null===(a=l.sizes[t])||void 0===a?void 0:a.source_url}var d=JSON.parse('{"u2":"cap/coauthor-featured-image"}');(0,e.registerBlockType)(d.u2,{edit:function(e){let{attributes:r,setAttributes:s,context:u,clientId:d}=e;const{aspectRatio:g,height:_,isLink:m,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=r,S=(0,i.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=u["cap/author"]||S,C=(0,i.useSelect)((e=>0!==E.featured_media&&e(n.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,i.useSelect)((e=>e(a.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),O=function(e,t,l){if(e&&"full"===l)return l;const a=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),a=Object.keys(t);return Array.from(new Set([...l.filter((e=>a.includes(e)))]))}(e,t);return l&&a.includes(l)?l:a[Math.max(0,a.length-1)]}(C,k,b),B=function(e,t,l){if(!e)return{};const a=e.media_details.sizes[l];if("full"===l)return{width:a.width,height:a.height};const o=t[l];if(!0===o.crop||o.width===o.height)return{width:o.width,height:o.height};const i=a.width/a.height;return o.width>o.height?{width:o.width,height:o.width/i}:{width:o.height*i,height:o.height}}(C,k,O),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,O),T=(0,a.__experimentalUseBorderProps)(r),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(c,{clientId:d,attributes:r,setAttributes:s,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,a.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,l.__)("Author featured image","co-authors-plus"),className:T.className,src:p(C,O),style:{width:!x&&_?"auto":x,height:!_&&x?"auto":_,aspectRatio:g,objectFit:w,verticalAlign:f,...T.style},width:B.width,height:B.height}):(0,t.createElement)(h,{className:T.className,dimensions:A,style:{width:!x&&_?"auto":x,height:!_&&x?"auto":_,aspectRatio:g,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(a.InspectorControls,null,(0,t.createElement)(o.PanelBody,{title:(0,l.__)("Featured Image Settings","co-authors-plus")},(0,t.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>s({isLink:!m}),checked:m}),m&&(0,t.createElement)(o.TextControl,{__nextHasNoMarginBottom:!0,label:(0,l.__)("Link rel","co-authors-plus"),value:v,onChange:e=>s({rel:e})})),(0,t.createElement)(o.PanelBody,{initialOpen:!1,title:(0,l.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(o.SelectControl,{label:(0,l.__)("Vertical align","co-authors-plus"),value:f,options:[{value:"",label:(0,l.__)("Default","co-authors-plus")},{value:"baseline",label:(0,l.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,l.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,l.__)("Middle","co-authors-plus")},{value:"sub",label:(0,l.__)("Sub","co-authors-plus")},{value:"super",label:(0,l.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,l.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,l.__)("Text Top","co-authors-plus")},{value:"top",label:(0,l.__)("Top","co-authors-plus")}],onChange:e=>{s({verticalAlign:""===e?void 0:e})},help:(0,l.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))}})}},l={};function a(e){var o=l[e];if(void 0!==o)return o.exports;var i=l[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=function(t,l,o,i){if(!l){var n=1/0;for(c=0;c=i)&&Object.keys(a.O).every((function(e){return a.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[l,o,i]},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={335:0,597:0};a.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,i,n=l[0],r=l[1],s=l[2],u=0;if(n.some((function(t){return 0!==e[t]}))){for(o in r)a.o(r,o)&&(a.m[o]=r[o]);if(s)var c=s(a)}for(t&&t(l);u{let{clientId:l,attributes:{aspectRatio:a,width:r,height:s,scale:p,sizeSlug:m},setAttributes:d,imageSizeOptions:g=[]}=e;const _=(0,n.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,o._x)("Scale","Image scaling options"),b=s||a&&"auto"!==a;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!a,label:(0,o.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Aspect ratio"),value:a,options:[{label:(0,o.__)("Original"),value:"auto"},{label:(0,o.__)("Square"),value:"1"},{label:(0,o.__)("16:9"),value:"16/9"},{label:(0,o.__)("4:3"),value:"4/3"},{label:(0,o.__)("3:2"),value:"3/2"},{label:(0,o.__)("9:16"),value:"9/16"},{label:(0,o.__)("3:4"),value:"3/4"},{label:(0,o.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!s,label:(0,o.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Height"),labelPosition:"top",value:s||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!r,label:(0,o.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Width"),labelPosition:"top",value:r||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!p&&p!==u,label:w,onDeselect:()=>d({scale:u}),resetAllFilter:()=>({scale:u}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:p,help:h[p],onChange:e=>d({scale:e}),isBlock:!0},c)),!!g.length&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,o.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Resolution"),value:m||"full",options:g,onChange:e=>d({sizeSlug:e}),help:(0,o.__)("Select the size of the source image.")})))};function m(e){let{dimensions:l,style:a,className:i}=e;const n=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,o.__)("Placeholder image"),className:i,src:n,style:a,width:l.width,height:l.height})}function d(e,t){var l,a;return null==e||null===(l=e.media_details)||void 0===l||null===(a=l.sizes[t])||void 0===a?void 0:a.source_url}var g=JSON.parse('{"u2":"cap/coauthor-featured-image"}');(0,e.registerBlockType)(g.u2,{edit:function(e){let{attributes:l,setAttributes:a,context:c,clientId:u}=e;const{aspectRatio:h,height:g,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=l,S=(0,r.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,r.useSelect)((e=>0!==E.featured_media&&e(s.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,r.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),B=function(e,t,l){if(e&&"full"===l)return l;const a=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),a=Object.keys(t);return Array.from(new Set([...l.filter((e=>a.includes(e)))]))}(e,t);return l&&a.includes(l)?l:a[Math.max(0,a.length-1)]}(C,k,b),O=function(e,t,l){if(!e)return{};const a=e.media_details.sizes[l];if("full"===l)return{width:a.width,height:a.height};const o=t[l];if(!0===o.crop||o.width===o.height)return{width:o.width,height:o.height};const i=a.width/a.height;return o.width>o.height?{width:o.width,height:o.width/i}:{width:o.height*i,height:o.height}}(C,k,B),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,B),T=(0,i.__experimentalUseBorderProps)(l),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(p,{clientId:u,attributes:l,setAttributes:a,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,o.__)("Author featured image","co-authors-plus"),className:T.className,src:d(C,B),style:{width:!x&&g?"auto":x,height:!g&&x?"auto":g,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style},width:O.width,height:O.height}):(0,t.createElement)(m,{className:T.className,dimensions:A,style:{width:!x&&g?"auto":x,height:!g&&x?"auto":g,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:(0,o.__)("Featured Image Settings","co-authors-plus")},(0,t.createElement)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>a({isLink:!_}),checked:_}),_&&(0,t.createElement)(n.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel","co-authors-plus"),value:v,onChange:e=>a({rel:e})})),(0,t.createElement)(n.PanelBody,{initialOpen:!1,title:(0,o.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(n.SelectControl,{label:(0,o.__)("Vertical align","co-authors-plus"),value:f,options:[{value:"",label:(0,o.__)("Default","co-authors-plus")},{value:"baseline",label:(0,o.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,o.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,o.__)("Middle","co-authors-plus")},{value:"sub",label:(0,o.__)("Sub","co-authors-plus")},{value:"super",label:(0,o.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,o.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,o.__)("Text Top","co-authors-plus")},{value:"top",label:(0,o.__)("Top","co-authors-plus")}],onChange:e=>{a({verticalAlign:""===e?void 0:e})},help:(0,o.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:a})}},l={};function a(e){var o=l[e];if(void 0!==o)return o.exports;var i=l[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=function(t,l,o,i){if(!l){var n=1/0;for(u=0;u=i)&&Object.keys(a.O).every((function(e){return a.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[l,o,i]},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={335:0,597:0};a.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,i,n=l[0],r=l[1],s=l[2],c=0;if(n.some((function(t){return 0!==e[t]}))){for(o in r)a.o(r,o)&&(a.m[o]=r[o]);if(s)var u=s(a)}for(t&&t(l);c array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '530471a71157d61748d3'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '7ea4fb2a6653b8b06014'); diff --git a/build/blocks/block-coauthor-name/index.js b/build/blocks/block-coauthor-name/index.js index d7053441..ce2b24c7 100644 --- a/build/blocks/block-coauthor-name/index.js +++ b/build/blocks/block-coauthor-name/index.js @@ -1 +1 @@ -!function(){var e={184:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function l(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),m=n["cap/author"]||g,{link:v,display_name:d}=m,b=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(o.BlockControls,null,(0,t.createElement)(o.AlignmentControl,{value:f,onChange:e=>{c({textAlign:e})}})),(0,t.createElement)(b,(0,o.useBlockProps)({className:i()({[`has-text-align-${f}`]:f})}),s?(0,t.createElement)("a",{href:v,rel:p,onClick:e=>e.preventDefault()},d):d),(0,t.createElement)(o.InspectorControls,null,(0,t.createElement)(l.PanelBody,{title:(0,r.__)("Settings","co-authors-plus")},(0,t.createElement)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make co-author name a link","co-authors-plus"),onChange:()=>c({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})))),(0,t.createElement)(o.InspectorControls,{group:"advanced"},(0,t.createElement)(l.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("HTML element","co-authors-plus"),options:[{label:(0,r.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>c({tagName:e})})))}})}()}(); \ No newline at end of file +!function(){var e={184:function(e,t){var n;!function(){"use strict";var l={}.hasOwnProperty;function o(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),g=n["cap/author"]||m,{link:d,display_name:f}=g,w=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:v,onChange:e=>{o({textAlign:e})}})),(0,t.createElement)(w,(0,r.useBlockProps)({className:s()({[`has-text-align-${v}`]:v})}),c?(0,t.createElement)("a",{href:d,rel:p,onClick:e=>e.preventDefault()},f):f),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,i.__)("Settings","co-authors-plus")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Make co-author name a link","co-authors-plus"),onChange:()=>o({isLink:!c}),checked:c}),c&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Link rel","co-authors-plus"),value:p,onChange:e=>o({rel:e})})))),(0,t.createElement)(r.InspectorControls,{group:"advanced"},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("HTML element","co-authors-plus"),options:[{label:(0,i.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>o({tagName:e})})))},icon:o})}()}(); \ No newline at end of file diff --git a/build/blocks/block-coauthors/block.json b/build/blocks/block-coauthors/block.json index ea25755b..61e6fe48 100644 --- a/build/blocks/block-coauthors/block.json +++ b/build/blocks/block-coauthors/block.json @@ -5,7 +5,6 @@ "version": "1.0.0", "title": "Co-Authors", "category": "widgets", - "icon": "smiley", "description": "Display the co-authors for a post.", "supports": { "html": false, diff --git a/build/blocks/block-coauthors/index.asset.php b/build/blocks/block-coauthors/index.asset.php index 9e7f2cf3..df8d749a 100644 --- a/build/blocks/block-coauthors/index.asset.php +++ b/build/blocks/block-coauthors/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ce764864a737c3f17b0f'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'e46f69cfdde7d5f80416'); diff --git a/build/blocks/block-coauthors/index.js b/build/blocks/block-coauthors/index.js index 804ddbe9..e1bc771e 100644 --- a/build/blocks/block-coauthors/index.js +++ b/build/blocks/block-coauthors/index.js @@ -1 +1 @@ -!function(){var e,t={441:function(e,t,o){"use strict";var n=window.wp.blocks,r=window.wp.element,a=window.wp.blockEditor,l=window.wp.components,c=window.wp.apiFetch,i=o.n(c),s=window.wp.data,u=window.wp.i18n,p=window.wp.primitives,h=(0,r.createElement)(p.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(p.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),v=(0,r.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),f=o(184),d=o.n(f);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(o)},s={display:n?"none":void 0};return(0,r.createElement)("div",m({},c,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function w(){return(0,r.createElement)("div",(0,a.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-name"]]}))}const g=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"cap/coauthors"}');(0,n.registerBlockType)(y.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:c,clientId:p,context:f,isSelected:m}=e;const{prefix:y,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=n,{postId:S}=f,O=(0,s.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[B,P]=(0,r.useState)([O]),[A,I]=(0,r.useState)(),N=(0,s.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return i()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(P).catch(V),()=>{e.abort()}}),[S]);const j=(0,s.useSelect)((e=>e(a.store).getBlocks(p))),z=e=>{c({layout:{...E,...e}})},G=[{icon:h,title:(0,u.__)("Inline","co-authors-plus"),onClick:()=>z({type:"inline"}),isActive:"inline"===E.type},{icon:v,title:(0,u.__)("Block","co-authors-plus"),onClick:()=>z({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(a.BlockControls,null,(0,r.createElement)(l.ToolbarGroup,{controls:G}),(0,r.createElement)(a.AlignmentControl,{value:C,onChange:e=>{c({textAlign:e})}})),(0,r.createElement)("div",(0,a.useBlockProps)({className:d()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,a.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),B&&"inline"===E.type&&(m||y)&&(0,r.createElement)(a.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__prefix",multiline:!1,"aria-label":(0,u.__)("Prefix","co-authors-plus"),placeholder:(0,u.__)("Prefix","co-authors-plus")+" ",value:y,onChange:e=>c({prefix:e}),tagName:"span"}),B&&B.map((e=>{var t;const o=e.id===(A||(null===(t=B[0])||void 0===t?void 0:t.id));return(0,r.createElement)(a.BlockContextProvider,{key:e.id,value:{"cap/author":e}},o?(0,r.createElement)(w,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthors__separator"},k&&o===n.length-1?`${k}`:`${x}`),t))),B&&"inline"===E.type&&(m||_)&&(0,r.createElement)(a.RichText,{allowedFormats:g,className:"wp-block-cap-coauthors__suffix",multiline:!1,"aria-label":(0,u.__)("Suffix"),placeholder:(0,u.__)("Suffix")+" ",value:_,onChange:e=>c({suffix:e}),tagName:"span"})),(0,r.createElement)(a.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(l.PanelBody,{title:(0,u.__)("Co-authors Layout","co-authors-plus")},(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{c({separator:e})},help:(0,u.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(l.TextControl,{autoComplete:"off",label:(0,u.__)("Last Separator","co-authors-plus"),value:k||"",onChange:e=>{c({lastSeparator:e})},help:(0,u.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:l,textAlign:c}=n,i={gap:"block"===l.type?(0,a.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},s=d()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${c}`]:c});return(0,r.createElement)("div",a.useBlockProps.save({className:s,style:i}),(0,r.createElement)(a.InnerBlocks.Content,null))}})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](o[i])}))?o.splice(i--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[o,r,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,a,l=o[0],c=o[1],i=o[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in c)n.o(c,r)&&(n.m[r]=c[r]);if(i)var u=i(n)}for(t&&t(o);s{a(o)},s={display:n?"none":void 0};return(0,r.createElement)("div",w({},l,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function g(){return(0,r.createElement)("div",(0,c.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var x=JSON.parse('{"u2":"cap/coauthors"}');(0,n.registerBlockType)(x.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:a,clientId:l,context:s,isSelected:d}=e;const{prefix:w,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=n,{postId:S}=s,O=(0,p.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,z]=(0,r.useState)(),I=(0,p.useDispatch)("core/notices");function N(e){"AbortError"!==e.name&&I.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return u()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(N),()=>{e.abort()}}),[S]);const j=(0,p.useSelect)((e=>e(c.store).getBlocks(l))),G=e=>{a({layout:{...E,...e}})},V=[{icon:h,title:(0,v.__)("Inline","co-authors-plus"),onClick:()=>G({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,v.__)("Block","co-authors-plus"),onClick:()=>G({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(c.BlockControls,null,(0,r.createElement)(i.ToolbarGroup,{controls:V}),(0,r.createElement)(c.AlignmentControl,{value:C,onChange:e=>{a({textAlign:e})}})),(0,r.createElement)("div",(0,c.useBlockProps)({className:m()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,c.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),A&&"inline"===E.type&&(d||w)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-cap-coauthors__prefix",multiline:!1,"aria-label":(0,v.__)("Prefix","co-authors-plus"),placeholder:(0,v.__)("Prefix","co-authors-plus")+" ",value:w,onChange:e=>a({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const o=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(c.BlockContextProvider,{key:e.id,value:{"cap/author":e}},o?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:z,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthors__separator"},k&&o===n.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(d||_)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-cap-coauthors__suffix",multiline:!1,"aria-label":(0,v.__)("Suffix"),placeholder:(0,v.__)("Suffix")+" ",value:_,onChange:e=>a({suffix:e}),tagName:"span"})),(0,r.createElement)(c.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(i.PanelBody,{title:(0,v.__)("Co-authors Layout","co-authors-plus")},(0,r.createElement)(i.TextControl,{autoComplete:"off",label:(0,v.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{a({separator:e})},help:(0,v.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(i.TextControl,{autoComplete:"off",label:(0,v.__)("Last Separator","co-authors-plus"),value:k||"",onChange:e=>{a({lastSeparator:e})},help:(0,v.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:a,textAlign:l}=n,i={gap:"block"===a.type?(0,c.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},s=m()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${l}`]:l});return(0,r.createElement)("div",c.useBlockProps.save({className:s,style:i}),(0,r.createElement)(c.InnerBlocks.Content,null))},icon:l})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](o[i])}))?o.splice(i--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[o,r,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,a,l=o[0],c=o[1],i=o[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in c)n.o(c,r)&&(n.m[r]=c[r]);if(i)var u=i(n)}for(t&&t(o);s Date: Tue, 26 Sep 2023 14:36:11 -0400 Subject: [PATCH 104/123] Update block namespace, simplify author context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Changed block namespaces from cap to co-authors-plus. - Removed the coauthor- prefix from individual block names and reduced their length overall. - Updated the functions related to providing author context in archive templates so they don’t rely on the coauthor- prefix, instead using metadata from the block registry. --- README.md | 11 ++++-- build/blocks-store/index.asset.php | 2 +- build/blocks-store/index.js | 2 +- build/blocks/block-coauthor-avatar/block.json | 4 +- .../block-coauthor-avatar/index.asset.php | 2 +- build/blocks/block-coauthor-avatar/index.js | 2 +- .../block-coauthor-avatar/style-index.css | 2 +- .../block-coauthor-description/block.json | 4 +- .../index.asset.php | 2 +- .../block-coauthor-description/index.css | 2 +- .../block-coauthor-description/index.js | 2 +- .../block-coauthor-featured-image/index.js | 1 - .../style-index.css | 1 - .../block.json | 4 +- .../index.asset.php | 2 +- build/blocks/block-coauthor-image/index.js | 1 + .../block-coauthor-image/style-index.css | 1 + build/blocks/block-coauthor-name/block.json | 4 +- .../block-coauthor-name/index.asset.php | 2 +- build/blocks/block-coauthor-name/index.js | 2 +- build/blocks/block-coauthors/block.json | 2 +- build/blocks/block-coauthors/index.asset.php | 2 +- build/blocks/block-coauthors/index.js | 2 +- build/blocks/block-coauthors/style-index.css | 2 +- .../class-block-coauthor-avatar.php | 2 +- .../class-block-coauthor-description.php | 2 +- .../class-block-coauthor-image.php} | 10 ++--- .../class-block-coauthor-name.php | 2 +- .../block-coauthors/class-block-coauthors.php | 14 +++---- php/blocks/class-blocks.php | 39 +++++++++++-------- src/blocks-store/index.js | 4 +- src/blocks/block-coauthor-avatar/block.json | 4 +- src/blocks/block-coauthor-avatar/edit.js | 4 +- src/blocks/block-coauthor-avatar/style.css | 12 +++--- .../block-coauthor-description/block.json | 4 +- src/blocks/block-coauthor-description/edit.js | 4 +- .../block-coauthor-description/editor.css | 2 +- .../block.json | 4 +- .../dimension-controls.js | 0 .../edit.js | 6 +-- .../index.js | 0 .../style.css | 12 +++--- .../utils.js | 0 src/blocks/block-coauthor-name/block.json | 4 +- src/blocks/block-coauthor-name/edit.js | 4 +- src/blocks/block-coauthors/block.json | 2 +- ...emoized-coauthor-template-block-preview.js | 2 +- src/blocks/block-coauthors/edit.js | 14 +++---- src/blocks/block-coauthors/style.css | 4 +- webpack.config.js | 2 +- 50 files changed, 114 insertions(+), 104 deletions(-) delete mode 100644 build/blocks/block-coauthor-featured-image/index.js delete mode 100644 build/blocks/block-coauthor-featured-image/style-index.css rename build/blocks/{block-coauthor-featured-image => block-coauthor-image}/block.json (95%) rename build/blocks/{block-coauthor-featured-image => block-coauthor-image}/index.asset.php (64%) create mode 100644 build/blocks/block-coauthor-image/index.js create mode 100644 build/blocks/block-coauthor-image/style-index.css rename php/blocks/{block-coauthor-featured-image/class-block-coauthor-featured-image.php => block-coauthor-image/class-block-coauthor-image.php} (93%) rename src/blocks/{block-coauthor-featured-image => block-coauthor-image}/block.json (95%) rename src/blocks/{block-coauthor-featured-image => block-coauthor-image}/dimension-controls.js (100%) rename src/blocks/{block-coauthor-featured-image => block-coauthor-image}/edit.js (95%) rename src/blocks/{block-coauthor-featured-image => block-coauthor-image}/index.js (100%) rename src/blocks/{block-coauthor-featured-image => block-coauthor-image}/style.css (50%) rename src/blocks/{block-coauthor-featured-image => block-coauthor-image}/utils.js (100%) diff --git a/README.md b/README.md index 0702bb11..277a070a 100644 --- a/README.md +++ b/README.md @@ -98,9 +98,14 @@ The function `CoAuthors\Blocks::provide_author_archive_context` filters the cont #### Extending -If you create a custom block that uses the namespace and prefix `cap/coauthor-`, the author archive context will be updated. +If you make a custom block and want to use the author context on the author archive, add `co-authors-plus/author` to the `usesContext` property in your block.json file. -If you have a differently named custom block, you can use the filter `coauthors_blocks_block_uses_author_context` to opt-in to the author archive context. +Example: +```json +{ + "usesContext": ['co-authors-plus/author'] +} +``` ### Example Data @@ -108,7 +113,7 @@ When working with Full Site Editing, or in the post editor before the authors ar #### Extending -If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `cap.author-placeholder` +If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `co-authors-plus.author-placeholder` ### Non-support diff --git a/build/blocks-store/index.asset.php b/build/blocks-store/index.asset.php index ddd6f624..b14de6c9 100644 --- a/build/blocks-store/index.asset.php +++ b/build/blocks-store/index.asset.php @@ -1 +1 @@ - array('wp-data', 'wp-hooks'), 'version' => '2f09dca744215aa9be3a'); + array('wp-data', 'wp-hooks'), 'version' => '82f1cda3f1d3fbb0136c'); diff --git a/build/blocks-store/index.js b/build/blocks-store/index.js index af5501ed..f51ca210 100644 --- a/build/blocks-store/index.js +++ b/build/blocks-store/index.js @@ -1 +1 @@ -!function(){"use strict";var e=window.wp.data,o=window.wp.hooks;(0,e.register)((0,e.createReduxStore)("cap/blocks",{reducer:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.coAuthorsBlocks;return e},selectors:{getAuthorPlaceholder:e=>(0,o.applyFilters)("cap.author-placeholder",e.authorPlaceholder)}}))}(); \ No newline at end of file +!function(){"use strict";var o=window.wp.data,e=window.wp.hooks;(0,o.register)((0,o.createReduxStore)("co-authors-plus/blocks",{reducer:function(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.coAuthorsBlocks;return o},selectors:{getAuthorPlaceholder:o=>(0,e.applyFilters)("co-authors-plus.author-placeholder",o.authorPlaceholder)}}))}(); \ No newline at end of file diff --git a/build/blocks/block-coauthor-avatar/block.json b/build/blocks/block-coauthor-avatar/block.json index 3a9a204f..3102d125 100644 --- a/build/blocks/block-coauthor-avatar/block.json +++ b/build/blocks/block-coauthor-avatar/block.json @@ -1,7 +1,7 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, - "name": "cap/coauthor-avatar", + "name": "co-authors-plus/avatar", "version": "1.0.0", "title": "Co-Author Avatar", "category": "widgets", @@ -35,7 +35,7 @@ } }, "usesContext": [ - "cap/author" + "co-authors-plus/author" ], "attributes": { "size": { diff --git a/build/blocks/block-coauthor-avatar/index.asset.php b/build/blocks/block-coauthor-avatar/index.asset.php index e4fcdd7e..1105dfba 100644 --- a/build/blocks/block-coauthor-avatar/index.asset.php +++ b/build/blocks/block-coauthor-avatar/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '51e75e8924d159603b0f'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ce44ef6d19849cf4f628'); diff --git a/build/blocks/block-coauthor-avatar/index.js b/build/blocks/block-coauthor-avatar/index.js index 78c2f169..e29e6b02 100644 --- a/build/blocks/block-coauthor-avatar/index.js +++ b/build/blocks/block-coauthor-avatar/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={601:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.primitives,o=(0,t.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(l.Path,{fillRule:"evenodd",d:"M7.25 16.437a6.5 6.5 0 1 1 9.5 0V16A2.75 2.75 0 0 0 14 13.25h-4A2.75 2.75 0 0 0 7.25 16v.437Zm1.5 1.193a6.47 6.47 0 0 0 3.25.87 6.47 6.47 0 0 0 3.25-.87V16c0-.69-.56-1.25-1.25-1.25h-4c-.69 0-1.25.56-1.25 1.25v1.63ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm10-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z",clipRule:"evenodd"})),a=window.wp.i18n,n=window.wp.blockEditor,r=window.wp.components,i=window.wp.data;function s(e){let{dimensions:l,style:o,className:n}=e;const r=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:n,src:r,style:o,width:l.width,height:l.height})}var u=JSON.parse('{"u2":"cap/coauthor-avatar"}');(0,e.registerBlockType)(u.u2,{edit:function(e){var l;let{context:o,attributes:u,setAttributes:c}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=u,m=(0,i.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),g=o["cap/author"]||m,{avatar_urls:_}=g;if(!_||0===_.length)return null;const w=Object.keys(_).map((e=>({value:e,label:`${e} x ${e}`}))),b=(0,n.__experimentalUseBorderProps)(u),f=null!==(l=_[v])&&void 0!==l?l:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,n.useBlockProps)(),""===f?(0,t.createElement)(s,{className:b.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...b.style}}):(0,t.createElement)("img",{style:{...b.style,verticalAlign:d},width:v,height:v,src:`${_[v]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,a.__)("Avatar Settings","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Avatar size","co-authors-plus"),value:v,options:w,onChange:e=>{c({size:Number(e)})}}),(0,t.createElement)(r.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive.","co-authors-plus"),onChange:()=>c({isLink:!h}),checked:h}),h&&(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})),(0,t.createElement)(r.PanelBody,{initialOpen:!1,title:(0,a.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Vertical align","co-authors-plus"),value:d,options:[{value:"",label:(0,a.__)("Default","co-authors-plus")},{value:"baseline",label:(0,a.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,a.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,a.__)("Middle","co-authors-plus")},{value:"sub",label:(0,a.__)("Sub","co-authors-plus")},{value:"super",label:(0,a.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,a.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,a.__)("Text Top","co-authors-plus")},{value:"top",label:(0,a.__)("Top","co-authors-plus")}],onChange:e=>{c({verticalAlign:""===e?void 0:e})},help:(0,a.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:o})}},l={};function o(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.m=t,e=[],o.O=function(t,l,a,n){if(!l){var r=1/0;for(c=0;c=n)&&Object.keys(o.O).every((function(e){return o.O[e](l[s])}))?l.splice(s--,1):(i=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[l,a,n]},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,r=l[0],i=l[1],s=l[2],u=0;if(r.some((function(t){return 0!==e[t]}))){for(a in i)o.o(i,a)&&(o.m[a]=i[a]);if(s)var c=s(o)}for(t&&t(l);ufunction(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:n,src:r,style:o,width:l.width,height:l.height})}var u=JSON.parse('{"u2":"co-authors-plus/avatar"}');(0,e.registerBlockType)(u.u2,{edit:function(e){var l;let{context:o,attributes:u,setAttributes:c}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=u,m=(0,s.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),g=o["co-authors-plus/author"]||m,{avatar_urls:_}=g;if(!_||0===_.length)return null;const w=Object.keys(_).map((e=>({value:e,label:`${e} x ${e}`}))),b=(0,n.__experimentalUseBorderProps)(u),f=null!==(l=_[v])&&void 0!==l?l:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,n.useBlockProps)(),""===f?(0,t.createElement)(i,{className:b.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...b.style}}):(0,t.createElement)("img",{style:{...b.style,verticalAlign:d},width:v,height:v,src:`${_[v]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,a.__)("Avatar Settings","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Avatar size","co-authors-plus"),value:v,options:w,onChange:e=>{c({size:Number(e)})}}),(0,t.createElement)(r.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive.","co-authors-plus"),onChange:()=>c({isLink:!h}),checked:h}),h&&(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})),(0,t.createElement)(r.PanelBody,{initialOpen:!1,title:(0,a.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Vertical align","co-authors-plus"),value:d,options:[{value:"",label:(0,a.__)("Default","co-authors-plus")},{value:"baseline",label:(0,a.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,a.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,a.__)("Middle","co-authors-plus")},{value:"sub",label:(0,a.__)("Sub","co-authors-plus")},{value:"super",label:(0,a.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,a.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,a.__)("Text Top","co-authors-plus")},{value:"top",label:(0,a.__)("Top","co-authors-plus")}],onChange:e=>{c({verticalAlign:""===e?void 0:e})},help:(0,a.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:o})}},l={};function o(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.m=t,e=[],o.O=function(t,l,a,n){if(!l){var r=1/0;for(c=0;c=n)&&Object.keys(o.O).every((function(e){return o.O[e](l[i])}))?l.splice(i--,1):(s=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[l,a,n]},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,r=l[0],s=l[1],i=l[2],u=0;if(r.some((function(t){return 0!==e[t]}))){for(a in s)o.o(s,a)&&(o.m[a]=s[a]);if(i)var c=i(o)}for(t&&t(l);u array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '7ab35d3b1fa8612137e8'); + array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'd61297f0bd62592218f0'); diff --git a/build/blocks/block-coauthor-description/index.css b/build/blocks/block-coauthor-description/index.css index 4bcbaa2b..ae02f029 100644 --- a/build/blocks/block-coauthor-description/index.css +++ b/build/blocks/block-coauthor-description/index.css @@ -1 +1 @@ -.wp-block-cap-coauthor-description a{pointer-events:none} +.wp-block-co-authors-plus-description a{pointer-events:none} diff --git a/build/blocks/block-coauthor-description/index.js b/build/blocks/block-coauthor-description/index.js index de286e49..452cc935 100644 --- a/build/blocks/block-coauthor-description/index.js +++ b/build/blocks/block-coauthor-description/index.js @@ -1 +1 @@ -!function(){var t={184:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var t=[],e=0;et("cap/blocks").getAuthorPlaceholder()),[]),p=n["cap/author"]||s,{description:f}=p;return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(a.BlockControls,null,(0,e.createElement)(a.AlignmentControl,{value:c,onChange:t=>{o({textAlign:t})}})),(0,e.createElement)("div",i({},(0,a.useBlockProps)({className:u()({[`has-text-align-${c}`]:c,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f.rendered}})))},icon:o})}()}(); \ No newline at end of file +!function(){var t={184:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var t=[],e=0;et("co-authors-plus/blocks").getAuthorPlaceholder()),[]),p=n["co-authors-plus/author"]||c,{description:f}=p;return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(a.BlockControls,null,(0,e.createElement)(a.AlignmentControl,{value:u,onChange:t=>{o({textAlign:t})}})),(0,e.createElement)("div",i({},(0,a.useBlockProps)({className:s()({[`has-text-align-${u}`]:u,"is-layout-flow":!0})}),{dangerouslySetInnerHTML:{__html:f.rendered}})))},icon:o})}()}(); \ No newline at end of file diff --git a/build/blocks/block-coauthor-featured-image/index.js b/build/blocks/block-coauthor-featured-image/index.js deleted file mode 100644 index 04e6720d..00000000 --- a/build/blocks/block-coauthor-featured-image/index.js +++ /dev/null @@ -1 +0,0 @@ -!function(){"use strict";var e,t={516:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.primitives,a=(0,t.createElement)(l.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,t.createElement)(l.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z"})),o=window.wp.i18n,i=window.wp.blockEditor,n=window.wp.components,r=window.wp.data,s=window.wp.coreData;const c=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"cover",label:(0,o._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"contain",label:(0,o._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"fill",label:(0,o._x)("Fill","Scale option for Image dimension control")})),u="cover",h={cover:(0,o.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,o.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,o.__)("Image will be stretched and distorted to completely fill the space.")};var p=e=>{let{clientId:l,attributes:{aspectRatio:a,width:r,height:s,scale:p,sizeSlug:m},setAttributes:d,imageSizeOptions:g=[]}=e;const _=(0,n.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||d({[e]:l<0?"0":t})},w=(0,o._x)("Scale","Image scaling options"),b=s||a&&"auto"!==a;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!a,label:(0,o.__)("Aspect ratio"),onDeselect:()=>d({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Aspect ratio"),value:a,options:[{label:(0,o.__)("Original"),value:"auto"},{label:(0,o.__)("Square"),value:"1"},{label:(0,o.__)("16:9"),value:"16/9"},{label:(0,o.__)("4:3"),value:"4/3"},{label:(0,o.__)("3:2"),value:"3/2"},{label:(0,o.__)("9:16"),value:"9/16"},{label:(0,o.__)("3:4"),value:"3/4"},{label:(0,o.__)("2:3"),value:"2/3"}],onChange:e=>d({aspectRatio:e})})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!s,label:(0,o.__)("Height"),onDeselect:()=>d({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Height"),labelPosition:"top",value:s||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!r,label:(0,o.__)("Width"),onDeselect:()=>d({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Width"),labelPosition:"top",value:r||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!p&&p!==u,label:w,onDeselect:()=>d({scale:u}),resetAllFilter:()=>({scale:u}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:p,help:h[p],onChange:e=>d({scale:e}),isBlock:!0},c)),!!g.length&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,o.__)("Resolution"),onDeselect:()=>d({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Resolution"),value:m||"full",options:g,onChange:e=>d({sizeSlug:e}),help:(0,o.__)("Select the size of the source image.")})))};function m(e){let{dimensions:l,style:a,className:i}=e;const n=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,o.__)("Placeholder image"),className:i,src:n,style:a,width:l.width,height:l.height})}function d(e,t){var l,a;return null==e||null===(l=e.media_details)||void 0===l||null===(a=l.sizes[t])||void 0===a?void 0:a.source_url}var g=JSON.parse('{"u2":"cap/coauthor-featured-image"}');(0,e.registerBlockType)(g.u2,{edit:function(e){let{attributes:l,setAttributes:a,context:c,clientId:u}=e;const{aspectRatio:h,height:g,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=l,S=(0,r.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),E=c["cap/author"]||S,C=(0,r.useSelect)((e=>0!==E.featured_media&&e(s.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,r.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),B=function(e,t,l){if(e&&"full"===l)return l;const a=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),a=Object.keys(t);return Array.from(new Set([...l.filter((e=>a.includes(e)))]))}(e,t);return l&&a.includes(l)?l:a[Math.max(0,a.length-1)]}(C,k,b),O=function(e,t,l){if(!e)return{};const a=e.media_details.sizes[l];if("full"===l)return{width:a.width,height:a.height};const o=t[l];if(!0===o.crop||o.width===o.height)return{width:o.width,height:o.height};const i=a.width/a.height;return o.width>o.height?{width:o.width,height:o.width/i}:{width:o.height*i,height:o.height}}(C,k,B),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,B),T=(0,i.__experimentalUseBorderProps)(l),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(p,{clientId:u,attributes:l,setAttributes:a,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,o.__)("Author featured image","co-authors-plus"),className:T.className,src:d(C,B),style:{width:!x&&g?"auto":x,height:!g&&x?"auto":g,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style},width:O.width,height:O.height}):(0,t.createElement)(m,{className:T.className,dimensions:A,style:{width:!x&&g?"auto":x,height:!g&&x?"auto":g,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:(0,o.__)("Featured Image Settings","co-authors-plus")},(0,t.createElement)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>a({isLink:!_}),checked:_}),_&&(0,t.createElement)(n.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel","co-authors-plus"),value:v,onChange:e=>a({rel:e})})),(0,t.createElement)(n.PanelBody,{initialOpen:!1,title:(0,o.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(n.SelectControl,{label:(0,o.__)("Vertical align","co-authors-plus"),value:f,options:[{value:"",label:(0,o.__)("Default","co-authors-plus")},{value:"baseline",label:(0,o.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,o.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,o.__)("Middle","co-authors-plus")},{value:"sub",label:(0,o.__)("Sub","co-authors-plus")},{value:"super",label:(0,o.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,o.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,o.__)("Text Top","co-authors-plus")},{value:"top",label:(0,o.__)("Top","co-authors-plus")}],onChange:e=>{a({verticalAlign:""===e?void 0:e})},help:(0,o.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:a})}},l={};function a(e){var o=l[e];if(void 0!==o)return o.exports;var i=l[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=function(t,l,o,i){if(!l){var n=1/0;for(u=0;u=i)&&Object.keys(a.O).every((function(e){return a.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[l,o,i]},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={335:0,597:0};a.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,i,n=l[0],r=l[1],s=l[2],c=0;if(n.some((function(t){return 0!==e[t]}))){for(o in r)a.o(r,o)&&(a.m[o]=r[o]);if(s)var u=s(a)}for(t&&t(l);c array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'd5400753091b01ccc087'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '51e049dab7cf7dd36c96'); diff --git a/build/blocks/block-coauthor-image/index.js b/build/blocks/block-coauthor-image/index.js new file mode 100644 index 00000000..856fb44f --- /dev/null +++ b/build/blocks/block-coauthor-image/index.js @@ -0,0 +1 @@ +!function(){"use strict";var e,t={62:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.primitives,a=(0,t.createElement)(l.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,t.createElement)(l.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z"})),o=window.wp.i18n,i=window.wp.blockEditor,n=window.wp.components,r=window.wp.data,s=window.wp.coreData;const c=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"cover",label:(0,o._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"contain",label:(0,o._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"fill",label:(0,o._x)("Fill","Scale option for Image dimension control")})),u="cover",h={cover:(0,o.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,o.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,o.__)("Image will be stretched and distorted to completely fill the space.")};var p=e=>{let{clientId:l,attributes:{aspectRatio:a,width:r,height:s,scale:p,sizeSlug:m},setAttributes:g,imageSizeOptions:d=[]}=e;const _=(0,n.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||g({[e]:l<0?"0":t})},w=(0,o._x)("Scale","Image scaling options"),b=s||a&&"auto"!==a;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!a,label:(0,o.__)("Aspect ratio"),onDeselect:()=>g({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Aspect ratio"),value:a,options:[{label:(0,o.__)("Original"),value:"auto"},{label:(0,o.__)("Square"),value:"1"},{label:(0,o.__)("16:9"),value:"16/9"},{label:(0,o.__)("4:3"),value:"4/3"},{label:(0,o.__)("3:2"),value:"3/2"},{label:(0,o.__)("9:16"),value:"9/16"},{label:(0,o.__)("3:4"),value:"3/4"},{label:(0,o.__)("2:3"),value:"2/3"}],onChange:e=>g({aspectRatio:e})})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!s,label:(0,o.__)("Height"),onDeselect:()=>g({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Height"),labelPosition:"top",value:s||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!r,label:(0,o.__)("Width"),onDeselect:()=>g({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Width"),labelPosition:"top",value:r||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!p&&p!==u,label:w,onDeselect:()=>g({scale:u}),resetAllFilter:()=>({scale:u}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:p,help:h[p],onChange:e=>g({scale:e}),isBlock:!0},c)),!!d.length&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,o.__)("Resolution"),onDeselect:()=>g({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Resolution"),value:m||"full",options:d,onChange:e=>g({sizeSlug:e}),help:(0,o.__)("Select the size of the source image.")})))};function m(e){let{dimensions:l,style:a,className:i}=e;const n=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,o.__)("Placeholder image"),className:i,src:n,style:a,width:l.width,height:l.height})}function g(e,t){var l,a;return null==e||null===(l=e.media_details)||void 0===l||null===(a=l.sizes[t])||void 0===a?void 0:a.source_url}var d=JSON.parse('{"u2":"co-authors-plus/image"}');(0,e.registerBlockType)(d.u2,{edit:function(e){let{attributes:l,setAttributes:a,context:c,clientId:u}=e;const{aspectRatio:h,height:d,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=l,S=(0,r.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),E=c["co-authors-plus/author"]||S,C=(0,r.useSelect)((e=>0!==E.featured_media&&e(s.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,r.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),B=function(e,t,l){if(e&&"full"===l)return l;const a=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),a=Object.keys(t);return Array.from(new Set([...l.filter((e=>a.includes(e)))]))}(e,t);return l&&a.includes(l)?l:a[Math.max(0,a.length-1)]}(C,k,b),O=function(e,t,l){if(!e)return{};const a=e.media_details.sizes[l];if("full"===l)return{width:a.width,height:a.height};const o=t[l];if(!0===o.crop||o.width===o.height)return{width:o.width,height:o.height};const i=a.width/a.height;return o.width>o.height?{width:o.width,height:o.width/i}:{width:o.height*i,height:o.height}}(C,k,B),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,B),T=(0,i.__experimentalUseBorderProps)(l),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(p,{clientId:u,attributes:l,setAttributes:a,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,o.__)("Author featured image","co-authors-plus"),className:T.className,src:g(C,B),style:{width:!x&&d?"auto":x,height:!d&&x?"auto":d,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style},width:O.width,height:O.height}):(0,t.createElement)(m,{className:T.className,dimensions:A,style:{width:!x&&d?"auto":x,height:!d&&x?"auto":d,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:(0,o.__)("Image Settings","co-authors-plus")},(0,t.createElement)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>a({isLink:!_}),checked:_}),_&&(0,t.createElement)(n.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel","co-authors-plus"),value:v,onChange:e=>a({rel:e})})),(0,t.createElement)(n.PanelBody,{initialOpen:!1,title:(0,o.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(n.SelectControl,{label:(0,o.__)("Vertical align","co-authors-plus"),value:f,options:[{value:"",label:(0,o.__)("Default","co-authors-plus")},{value:"baseline",label:(0,o.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,o.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,o.__)("Middle","co-authors-plus")},{value:"sub",label:(0,o.__)("Sub","co-authors-plus")},{value:"super",label:(0,o.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,o.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,o.__)("Text Top","co-authors-plus")},{value:"top",label:(0,o.__)("Top","co-authors-plus")}],onChange:e=>{a({verticalAlign:""===e?void 0:e})},help:(0,o.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:a})}},l={};function a(e){var o=l[e];if(void 0!==o)return o.exports;var i=l[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=function(t,l,o,i){if(!l){var n=1/0;for(u=0;u=i)&&Object.keys(a.O).every((function(e){return a.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[l,o,i]},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={461:0,286:0};a.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,i,n=l[0],r=l[1],s=l[2],c=0;if(n.some((function(t){return 0!==e[t]}))){for(o in r)a.o(r,o)&&(a.m[o]=r[o]);if(s)var u=s(a)}for(t&&t(l);c array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '7ea4fb2a6653b8b06014'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '3a57c4d58ba62fabefff'); diff --git a/build/blocks/block-coauthor-name/index.js b/build/blocks/block-coauthor-name/index.js index ce2b24c7..3e07a0e1 100644 --- a/build/blocks/block-coauthor-name/index.js +++ b/build/blocks/block-coauthor-name/index.js @@ -1 +1 @@ -!function(){var e={184:function(e,t){var n;!function(){"use strict";var l={}.hasOwnProperty;function o(){for(var e=[],t=0;te("cap/blocks").getAuthorPlaceholder()),[]),g=n["cap/author"]||m,{link:d,display_name:f}=g,w=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:v,onChange:e=>{o({textAlign:e})}})),(0,t.createElement)(w,(0,r.useBlockProps)({className:s()({[`has-text-align-${v}`]:v})}),c?(0,t.createElement)("a",{href:d,rel:p,onClick:e=>e.preventDefault()},f):f),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,i.__)("Settings","co-authors-plus")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Make co-author name a link","co-authors-plus"),onChange:()=>o({isLink:!c}),checked:c}),c&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Link rel","co-authors-plus"),value:p,onChange:e=>o({rel:e})})))),(0,t.createElement)(r.InspectorControls,{group:"advanced"},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("HTML element","co-authors-plus"),options:[{label:(0,i.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>o({tagName:e})})))},icon:o})}()}(); \ No newline at end of file +!function(){var e={184:function(e,t){var n;!function(){"use strict";var o={}.hasOwnProperty;function l(){for(var e=[],t=0;te("co-authors-plus/blocks").getAuthorPlaceholder()),[]),g=n["co-authors-plus/author"]||m,{link:d,display_name:f}=g,w=h;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:v,onChange:e=>{l({textAlign:e})}})),(0,t.createElement)(w,(0,r.useBlockProps)({className:c()({[`has-text-align-${v}`]:v})}),s?(0,t.createElement)("a",{href:d,rel:p,onClick:e=>e.preventDefault()},f):f),(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(a.PanelBody,{title:(0,u.__)("Settings","co-authors-plus")},(0,t.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,u.__)("Make co-author name a link","co-authors-plus"),onChange:()=>l({isLink:!s}),checked:s}),s&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,u.__)("Link rel","co-authors-plus"),value:p,onChange:e=>l({rel:e})})))),(0,t.createElement)(r.InspectorControls,{group:"advanced"},(0,t.createElement)(a.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,u.__)("HTML element","co-authors-plus"),options:[{label:(0,u.__)("Default (

)"),value:"p"},{label:"",value:"span"},{label:"

",value:"h1"},{label:"

",value:"h2"},{label:"

",value:"h3"},{label:"

",value:"h4"},{label:"

",value:"h5"},{label:"
",value:"h6"}],value:h,onChange:e=>l({tagName:e})})))},icon:l})}()}(); \ No newline at end of file diff --git a/build/blocks/block-coauthors/block.json b/build/blocks/block-coauthors/block.json index 61e6fe48..6a74b225 100644 --- a/build/blocks/block-coauthors/block.json +++ b/build/blocks/block-coauthors/block.json @@ -1,7 +1,7 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, - "name": "cap/coauthors", + "name": "co-authors-plus/coauthors", "version": "1.0.0", "title": "Co-Authors", "category": "widgets", diff --git a/build/blocks/block-coauthors/index.asset.php b/build/blocks/block-coauthors/index.asset.php index df8d749a..9c017cf4 100644 --- a/build/blocks/block-coauthors/index.asset.php +++ b/build/blocks/block-coauthors/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'e46f69cfdde7d5f80416'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'e78745f41ce5a8016414'); diff --git a/build/blocks/block-coauthors/index.js b/build/blocks/block-coauthors/index.js index e1bc771e..55598fdc 100644 --- a/build/blocks/block-coauthors/index.js +++ b/build/blocks/block-coauthors/index.js @@ -1 +1 @@ -!function(){var e,t={749:function(e,t,o){"use strict";var n=window.wp.blocks,r=window.wp.element,a=window.wp.primitives,l=(0,r.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(a.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})),c=window.wp.blockEditor,i=window.wp.components,s=window.wp.apiFetch,u=o.n(s),p=window.wp.data,v=window.wp.i18n,h=(0,r.createElement)(a.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(a.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),f=(0,r.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(a.Path,{d:"m3 5c0-1.10457.89543-2 2-2h13.5c1.1046 0 2 .89543 2 2v13.5c0 1.1046-.8954 2-2 2h-13.5c-1.10457 0-2-.8954-2-2zm2-.5h6v6.5h-6.5v-6c0-.27614.22386-.5.5-.5zm-.5 8v6c0 .2761.22386.5.5.5h6v-6.5zm8 0v6.5h6c.2761 0 .5-.2239.5-.5v-6zm0-8v6.5h6.5v-6c0-.27614-.2239-.5-.5-.5z",fillRule:"evenodd",clipRule:"evenodd"})),d=o(184),m=o.n(d);function w(){return w=Object.assign?Object.assign.bind():function(e){for(var t=1;t{a(o)},s={display:n?"none":void 0};return(0,r.createElement)("div",w({},l,{tabIndex:0,role:"button",onClick:i,onKeyUp:i,style:s}))}));function g(){return(0,r.createElement)("div",(0,c.useInnerBlocksProps)({className:"wp-block-cap-coauthor"},{template:[["cap/coauthor-name"]]}))}const y=["core/bold","core/italic","core/text-color"];var x=JSON.parse('{"u2":"cap/coauthors"}');(0,n.registerBlockType)(x.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:a,clientId:l,context:s,isSelected:d}=e;const{prefix:w,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=n,{postId:S}=s,O=(0,p.useSelect)((e=>e("cap/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,z]=(0,r.useState)(),I=(0,p.useDispatch)("core/notices");function N(e){"AbortError"!==e.name&&I.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return u()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(N),()=>{e.abort()}}),[S]);const j=(0,p.useSelect)((e=>e(c.store).getBlocks(l))),G=e=>{a({layout:{...E,...e}})},V=[{icon:h,title:(0,v.__)("Inline","co-authors-plus"),onClick:()=>G({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,v.__)("Block","co-authors-plus"),onClick:()=>G({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(c.BlockControls,null,(0,r.createElement)(i.ToolbarGroup,{controls:V}),(0,r.createElement)(c.AlignmentControl,{value:C,onChange:e=>{a({textAlign:e})}})),(0,r.createElement)("div",(0,c.useBlockProps)({className:m()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,c.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),A&&"inline"===E.type&&(d||w)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-cap-coauthors__prefix",multiline:!1,"aria-label":(0,v.__)("Prefix","co-authors-plus"),placeholder:(0,v.__)("Prefix","co-authors-plus")+" ",value:w,onChange:e=>a({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const o=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(c.BlockContextProvider,{key:e.id,value:{"cap/author":e}},o?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:z,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-cap-coauthors__separator"},k&&o===n.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(d||_)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-cap-coauthors__suffix",multiline:!1,"aria-label":(0,v.__)("Suffix"),placeholder:(0,v.__)("Suffix")+" ",value:_,onChange:e=>a({suffix:e}),tagName:"span"})),(0,r.createElement)(c.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(i.PanelBody,{title:(0,v.__)("Co-authors Layout","co-authors-plus")},(0,r.createElement)(i.TextControl,{autoComplete:"off",label:(0,v.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{a({separator:e})},help:(0,v.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(i.TextControl,{autoComplete:"off",label:(0,v.__)("Last Separator","co-authors-plus"),value:k||"",onChange:e=>{a({lastSeparator:e})},help:(0,v.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:a,textAlign:l}=n,i={gap:"block"===a.type?(0,c.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},s=m()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${l}`]:l});return(0,r.createElement)("div",c.useBlockProps.save({className:s,style:i}),(0,r.createElement)(c.InnerBlocks.Content,null))},icon:l})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](o[i])}))?o.splice(i--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[o,r,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,a,l=o[0],c=o[1],i=o[2],s=0;if(l.some((function(t){return 0!==e[t]}))){for(r in c)n.o(c,r)&&(n.m[r]=c[r]);if(i)var u=i(n)}for(t&&t(o);s{l(o)},i={display:n?"none":void 0};return(0,r.createElement)("div",w({},a,{tabIndex:0,role:"button",onClick:s,onKeyUp:s,style:i}))}));function g(){return(0,r.createElement)("div",(0,c.useInnerBlocksProps)({className:"wp-block-co-authors-plus-coauthor"},{template:[["co-authors-plus/name"]]}))}const y=["core/bold","core/italic","core/text-color"];var x=JSON.parse('{"u2":"co-authors-plus/coauthors"}');(0,n.registerBlockType)(x.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:l,clientId:a,context:i,isSelected:d}=e;const{prefix:w,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=n,{postId:S}=i,O=(0,p.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,z]=(0,r.useState)(),I=(0,p.useDispatch)("core/notices");function N(e){"AbortError"!==e.name&&I.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return u()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(N),()=>{e.abort()}}),[S]);const j=(0,p.useSelect)((e=>e(c.store).getBlocks(a))),G=e=>{l({layout:{...E,...e}})},V=[{icon:v,title:(0,h.__)("Inline","co-authors-plus"),onClick:()=>G({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,h.__)("Block","co-authors-plus"),onClick:()=>G({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(c.BlockControls,null,(0,r.createElement)(s.ToolbarGroup,{controls:V}),(0,r.createElement)(c.AlignmentControl,{value:C,onChange:e=>{l({textAlign:e})}})),(0,r.createElement)("div",(0,c.useBlockProps)({className:m()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,c.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),A&&"inline"===E.type&&(d||w)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__prefix",multiline:!1,"aria-label":(0,h.__)("Prefix","co-authors-plus"),placeholder:(0,h.__)("Prefix","co-authors-plus")+" ",value:w,onChange:e=>l({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const o=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(c.BlockContextProvider,{key:e.id,value:{"co-authors-plus/author":e}},o?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:z,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-co-authors-plus-coauthors__separator"},k&&o===n.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(d||_)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__suffix",multiline:!1,"aria-label":(0,h.__)("Suffix"),placeholder:(0,h.__)("Suffix")+" ",value:_,onChange:e=>l({suffix:e}),tagName:"span"})),(0,r.createElement)(c.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(s.PanelBody,{title:(0,h.__)("Co-authors Layout","co-authors-plus")},(0,r.createElement)(s.TextControl,{autoComplete:"off",label:(0,h.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{l({separator:e})},help:(0,h.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(s.TextControl,{autoComplete:"off",label:(0,h.__)("Last Separator","co-authors-plus"),value:k||"",onChange:e=>{l({lastSeparator:e})},help:(0,h.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:l,textAlign:a}=n,s={gap:"block"===l.type?(0,c.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},i=m()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${a}`]:a});return(0,r.createElement)("div",c.useBlockProps.save({className:i,style:s}),(0,r.createElement)(c.InnerBlocks.Content,null))},icon:a})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(n.O).every((function(e){return n.O[e](o[s])}))?o.splice(s--,1):(c=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[o,r,l]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,l,a=o[0],c=o[1],s=o[2],i=0;if(a.some((function(t){return 0!==e[t]}))){for(r in c)n.o(c,r)&&(n.m[r]=c[r]);if(s)var u=s(n)}for(t&&t(o);icontext['cap/author'] ?? array(); + $author = $block->context['co-authors-plus/author'] ?? array(); if ( empty( $author ) ) { return ''; diff --git a/php/blocks/block-coauthor-description/class-block-coauthor-description.php b/php/blocks/block-coauthor-description/class-block-coauthor-description.php index f881d32f..9098a308 100644 --- a/php/blocks/block-coauthor-description/class-block-coauthor-description.php +++ b/php/blocks/block-coauthor-description/class-block-coauthor-description.php @@ -41,7 +41,7 @@ public static function register_block(): void { */ public static function render_block( array $attributes, string $content, WP_Block $block ): string { - $author = $block->context['cap/author'] ?? array(); + $author = $block->context['co-authors-plus/author'] ?? array(); if ( empty( $author ) ) { return ''; diff --git a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php b/php/blocks/block-coauthor-image/class-block-coauthor-image.php similarity index 93% rename from php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php rename to php/blocks/block-coauthor-image/class-block-coauthor-image.php index ee6cdb8e..12a9c507 100644 --- a/php/blocks/block-coauthor-featured-image/class-block-coauthor-featured-image.php +++ b/php/blocks/block-coauthor-image/class-block-coauthor-image.php @@ -1,6 +1,6 @@ array( __CLASS__, 'render_block' ), ) @@ -41,7 +41,7 @@ public static function register_block(): void { */ public static function render_block( array $attributes, string $content, WP_Block $block ): string { - $author = $block->context['cap/author'] ?? array(); + $author = $block->context['co-authors-plus/author'] ?? array(); if ( empty( $author ) ) { return ''; diff --git a/php/blocks/block-coauthor-name/class-block-coauthor-name.php b/php/blocks/block-coauthor-name/class-block-coauthor-name.php index da61c036..8b31e81b 100644 --- a/php/blocks/block-coauthor-name/class-block-coauthor-name.php +++ b/php/blocks/block-coauthor-name/class-block-coauthor-name.php @@ -41,7 +41,7 @@ public static function register_block(): void { */ public static function render_block( array $attributes, string $content, WP_Block $block ): string { - $author = $block->context['cap/author'] ?? array(); + $author = $block->context['co-authors-plus/author'] ?? array(); if ( empty( $author ) ) { return ''; diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 794e2206..1f4de0af 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -47,7 +47,7 @@ public static function separator_internationalization( array $settings, array $m return $settings; } - if ( 'cap/coauthors' !== $metadata['name'] ) { + if ( 'co-authors-plus/coauthors' !== $metadata['name'] ) { return $settings; } @@ -172,7 +172,7 @@ public static function render_prefix( string $prefix ): string { if ( empty( $prefix ) ) { return $prefix; } - return Templating::render_element( 'span', 'class="wp-block-cap-coauthors__prefix"', $prefix ); + return Templating::render_element( 'span', 'class="wp-block-co-authors-plus-coauthors__prefix"', $prefix ); } /** @@ -186,7 +186,7 @@ public static function render_suffix( string $suffix ): string { if ( empty( $suffix ) ) { return $suffix; } - return Templating::render_element( 'span', 'class="wp-block-cap-coauthors__suffix"', $suffix ); + return Templating::render_element( 'span', 'class="wp-block-co-authors-plus-coauthors__suffix"', $suffix ); } /** @@ -207,7 +207,7 @@ function( $content ) { }, // To match JSX from editor, trim whitespace around blocks. 'trim', - Templating::get_render_element_function( 'div', 'class="wp-block-cap-coauthor"' ) + Templating::get_render_element_function( 'div', 'class="wp-block-co-authors-plus-coauthor"' ) ), $authors ); @@ -276,7 +276,7 @@ private static function get_separator( array $attributes ): string { return Templating::render_element( 'span', - 'class="wp-block-cap-coauthors__separator"', + 'class="wp-block-co-authors-plus-coauthors__separator"', $separator ); } @@ -299,7 +299,7 @@ private static function get_last_separator( array $attributes, string $default ) return Templating::render_element( 'span', - 'class="wp-block-cap-coauthors__separator"', + 'class="wp-block-co-authors-plus-coauthors__separator"', $last_separator ); } @@ -317,7 +317,7 @@ private static function get_template_render_function( array $block_template ): c new WP_Block( $block_template, array( - 'cap/author' => $author, + 'co-authors-plus/author' => $author, ) ) )->render( diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index be6141c8..311345f3 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -9,6 +9,7 @@ namespace CoAuthors; use WP_REST_Request; +use WP_Block_Type_Registry; /** * Blocks @@ -59,8 +60,8 @@ public static function initialize_blocks(): void { require_once __DIR__ . '/block-coauthor-name/class-block-coauthor-name.php'; Blocks\Block_CoAuthor_Name::register_block(); - require_once __DIR__ . '/block-coauthor-featured-image/class-block-coauthor-featured-image.php'; - Blocks\Block_CoAuthor_Featured_Image::register_block(); + require_once __DIR__ . '/block-coauthor-image/class-block-coauthor-image.php'; + Blocks\Block_CoAuthor_Image::register_block(); } /** @@ -80,20 +81,8 @@ public static function provide_author_archive_context( array $context, array $pa return $context; } - /** - * Block Uses Author Context - * - * @since 3.6.0 - * @param bool - * @param string - */ - $uses_author_context = apply_filters( - 'coauthors_blocks_block_uses_author_context', - 'cap/coauthor-' === substr( $parsed_block['blockName'], 0, 13 ), - $parsed_block['blockName'] - ); - - $has_author_context = array_key_exists( 'cap/author', $context ) && is_array( $context['cap/author'] ); + $uses_author_context = self::block_uses_author_context( $parsed_block['blockName'] ); + $has_author_context = array_key_exists( 'co-authors-plus/author', $context ) && is_array( $context['co-authors-plus/author'] ); if ( ! $uses_author_context || $has_author_context ) { return $context; @@ -106,10 +95,26 @@ public static function provide_author_archive_context( array $context, array $pa } return array( - 'cap/author' => $author, + 'co-authors-plus/author' => $author, ); } + /** + * Block Uses Author Context + * + * @param string $block_name Block name to check for use of author context. + * @return bool Whether the `uses_context` property of the registered block type includes `'co-authors-plus/author'` + */ + public static function block_uses_author_context( string $block_name ): bool { + $block = WP_Block_Type_Registry::get_instance()->get_registered( $block_name ); + + if ( ! is_a( $block, 'WP_Block_Type' ) ) { + return false; + } + + return in_array( 'co-authors-plus/author', $block->uses_context, true ); + } + /** * Enqueue Store * diff --git a/src/blocks-store/index.js b/src/blocks-store/index.js index 4231195a..eb1deda2 100644 --- a/src/blocks-store/index.js +++ b/src/blocks-store/index.js @@ -2,12 +2,12 @@ import { createReduxStore, register } from '@wordpress/data'; import { applyFilters } from '@wordpress/hooks'; register( - createReduxStore( 'cap/blocks', { + createReduxStore( 'co-authors-plus/blocks', { reducer: ( state = window.coAuthorsBlocks ) => { return state; }, selectors: { - getAuthorPlaceholder: ( state ) => applyFilters( 'cap.author-placeholder', state.authorPlaceholder ), + getAuthorPlaceholder: ( state ) => applyFilters( 'co-authors-plus.author-placeholder', state.authorPlaceholder ), }, } ) ); diff --git a/src/blocks/block-coauthor-avatar/block.json b/src/blocks/block-coauthor-avatar/block.json index f416014d..50d4f6f0 100644 --- a/src/blocks/block-coauthor-avatar/block.json +++ b/src/blocks/block-coauthor-avatar/block.json @@ -1,7 +1,7 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, - "name": "cap/coauthor-avatar", + "name": "co-authors-plus/avatar", "version": "1.0.0", "title": "Co-Author Avatar", "category": "widgets", @@ -31,7 +31,7 @@ } }, "usesContext": [ - "cap/author" + "co-authors-plus/author" ], "attributes": { "size" : { diff --git a/src/blocks/block-coauthor-avatar/edit.js b/src/blocks/block-coauthor-avatar/edit.js index 93a647ff..56db0856 100644 --- a/src/blocks/block-coauthor-avatar/edit.js +++ b/src/blocks/block-coauthor-avatar/edit.js @@ -16,8 +16,8 @@ import PlaceholderImage from '../components/placeholder-image'; export default function Edit( { context, attributes, setAttributes } ) { const { isLink, rel, size, verticalAlign } = attributes; - const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); - const author = context['cap/author'] || authorPlaceholder; + const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []); + const author = context['co-authors-plus/author'] || authorPlaceholder; const { avatar_urls } = author; if ( ! avatar_urls || 0 === avatar_urls.length ) { diff --git a/src/blocks/block-coauthor-avatar/style.css b/src/blocks/block-coauthor-avatar/style.css index df1c6541..65351f6c 100644 --- a/src/blocks/block-coauthor-avatar/style.css +++ b/src/blocks/block-coauthor-avatar/style.css @@ -1,10 +1,10 @@ /* Default Layout */ -.wp-block-cap-coauthor-avatar { +.wp-block-co-authors-plus-avatar { margin-bottom: 0; } -.wp-block-cap-coauthor-avatar :where(img) { +.wp-block-co-authors-plus-avatar :where(img) { height: auto; max-width: 100%; vertical-align: bottom; @@ -12,22 +12,22 @@ /* Inline Layout */ -.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-avatar { +.wp-block-co-authors-plus-coauthors.is-layout-cap-inline .wp-block-co-authors-plus-avatar { display: inline; } -.wp-block-cap-coauthors.is-layout-cap-inline .wp-block-cap-coauthor-avatar :where(img) { +.wp-block-co-authors-plus-coauthors.is-layout-cap-inline .wp-block-co-authors-plus-avatar :where(img) { vertical-align: middle; } /* Align wide, full */ -.wp-block-cap-coauthor-avatar:is(.alignfull,.alignwide) :where(img) { +.wp-block-co-authors-plus-avatar:is(.alignfull,.alignwide) :where(img) { width: 100%; } /* Align left, right, center */ -.wp-block-cap-coauthor-avatar:is(.alignleft,.alignright,.aligncenter) { +.wp-block-co-authors-plus-avatar:is(.alignleft,.alignright,.aligncenter) { display: table; } diff --git a/src/blocks/block-coauthor-description/block.json b/src/blocks/block-coauthor-description/block.json index 1f7a6096..b5ae87fe 100644 --- a/src/blocks/block-coauthor-description/block.json +++ b/src/blocks/block-coauthor-description/block.json @@ -1,7 +1,7 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, - "name": "cap/coauthor-description", + "name": "co-authors-plus/description", "version": "1.0.0", "title": "Co-Author Biography", "category": "widgets", @@ -40,7 +40,7 @@ } }, "usesContext": [ - "cap/author" + "co-authors-plus/author" ], "attributes": { "textAlign": { diff --git a/src/blocks/block-coauthor-description/edit.js b/src/blocks/block-coauthor-description/edit.js index 4fc6207c..843310b3 100644 --- a/src/blocks/block-coauthor-description/edit.js +++ b/src/blocks/block-coauthor-description/edit.js @@ -21,8 +21,8 @@ import './editor.css'; export default function Edit( { context, attributes, setAttributes } ) { const { textAlign } = attributes; - const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); - const author = context['cap/author'] || authorPlaceholder; + const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []); + const author = context['co-authors-plus/author'] || authorPlaceholder; const { description } = author; return ( diff --git a/src/blocks/block-coauthor-description/editor.css b/src/blocks/block-coauthor-description/editor.css index a984e75e..7a48d580 100644 --- a/src/blocks/block-coauthor-description/editor.css +++ b/src/blocks/block-coauthor-description/editor.css @@ -1,3 +1,3 @@ -.wp-block-cap-coauthor-description a { +.wp-block-co-authors-plus-description a { pointer-events: none; } diff --git a/src/blocks/block-coauthor-featured-image/block.json b/src/blocks/block-coauthor-image/block.json similarity index 95% rename from src/blocks/block-coauthor-featured-image/block.json rename to src/blocks/block-coauthor-image/block.json index e1071fc2..dd4e6c6f 100644 --- a/src/blocks/block-coauthor-featured-image/block.json +++ b/src/blocks/block-coauthor-image/block.json @@ -1,7 +1,7 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, - "name": "cap/coauthor-featured-image", + "name": "co-authors-plus/image", "version": "1.0.0", "title": "Co-Author Featured Image", "category": "widgets", @@ -30,7 +30,7 @@ } }, "usesContext": [ - "cap/author" + "co-authors-plus/author" ], "attributes": { "isLink": { diff --git a/src/blocks/block-coauthor-featured-image/dimension-controls.js b/src/blocks/block-coauthor-image/dimension-controls.js similarity index 100% rename from src/blocks/block-coauthor-featured-image/dimension-controls.js rename to src/blocks/block-coauthor-image/dimension-controls.js diff --git a/src/blocks/block-coauthor-featured-image/edit.js b/src/blocks/block-coauthor-image/edit.js similarity index 95% rename from src/blocks/block-coauthor-featured-image/edit.js rename to src/blocks/block-coauthor-image/edit.js index 3dbc7759..b200aa12 100644 --- a/src/blocks/block-coauthor-featured-image/edit.js +++ b/src/blocks/block-coauthor-image/edit.js @@ -29,10 +29,10 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) // Author const authorPlaceholder = useSelect( - select => select( 'cap/blocks' ).getAuthorPlaceholder(), + select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), [] ); - const author = context['cap/author'] || authorPlaceholder; + const author = context['co-authors-plus/author'] || authorPlaceholder; // Media const media = useSelect( @@ -104,7 +104,7 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) ) } - + select( 'cap/blocks' ).getAuthorPlaceholder(), []); - const author = context['cap/author'] || authorPlaceholder; + const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []); + const author = context['co-authors-plus/author'] || authorPlaceholder; const { link, display_name } = author; const TagName = tagName; diff --git a/src/blocks/block-coauthors/block.json b/src/blocks/block-coauthors/block.json index 1a5dd5cd..3559271e 100644 --- a/src/blocks/block-coauthors/block.json +++ b/src/blocks/block-coauthors/block.json @@ -1,7 +1,7 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, - "name": "cap/coauthors", + "name": "co-authors-plus/coauthors", "version": "1.0.0", "title": "Co-Authors", "category": "widgets", diff --git a/src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js b/src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js index a61c84a9..40913f53 100644 --- a/src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js +++ b/src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js @@ -14,7 +14,7 @@ function CoAuthorTemplateBlockPreview({ const blockPreviewProps = useBlockPreview( { blocks, props: { - className: 'wp-block-cap-coauthor', + className: 'wp-block-co-authors-plus-coauthor', }, } ); diff --git a/src/blocks/block-coauthors/edit.js b/src/blocks/block-coauthors/edit.js index 7f21e161..71fa228a 100644 --- a/src/blocks/block-coauthors/edit.js +++ b/src/blocks/block-coauthors/edit.js @@ -31,8 +31,8 @@ import MemoizedCoAuthorTemplateBlockPreview from './components/memoized-coauthor */ function CoAuthorTemplateInnerBlocks () { return
; } @@ -54,7 +54,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is const { prefix, separator, lastSeparator, suffix, layout, textAlign } = attributes; const { postId } = context; - const authorPlaceholder = useSelect( select => select( 'cap/blocks' ).getAuthorPlaceholder(), []); + const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []); const [ coAuthors, setCoAuthors ] = useState([authorPlaceholder]); const [ activeBlockContextId, setActiveBlockContextId ] = useState(); const noticesDispatch = useDispatch('core/notices'); @@ -144,7 +144,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is ( { isHidden ? () : null } + { ( lastSeparator && index === (all.length - 1) ) ? `${lastSeparator}` : `${separator}` } ) @@ -198,7 +198,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is ( Date: Wed, 27 Sep 2023 11:05:18 -0400 Subject: [PATCH 105/123] Make block descriptions more uniform and useful --- build/blocks/block-coauthor-avatar/block.json | 2 +- build/blocks/block-coauthor-description/block.json | 2 +- build/blocks/block-coauthor-image/block.json | 2 +- build/blocks/block-coauthor-name/block.json | 2 +- build/blocks/block-coauthors/block.json | 2 +- src/blocks/block-coauthor-avatar/block.json | 2 +- src/blocks/block-coauthor-description/block.json | 2 +- src/blocks/block-coauthor-image/block.json | 2 +- src/blocks/block-coauthor-name/block.json | 2 +- src/blocks/block-coauthors/block.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build/blocks/block-coauthor-avatar/block.json b/build/blocks/block-coauthor-avatar/block.json index 3102d125..6811dccb 100644 --- a/build/blocks/block-coauthor-avatar/block.json +++ b/build/blocks/block-coauthor-avatar/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Author Avatar", "category": "widgets", - "description": "Display a co-author's avatar", + "description": "Displays a small scale version of a co-author's avatar. Utilizes fallbacks from Gravatar so everyone has an avatar.", "supports": { "align": [ "left", diff --git a/build/blocks/block-coauthor-description/block.json b/build/blocks/block-coauthor-description/block.json index af3e2e84..98c17113 100644 --- a/build/blocks/block-coauthor-description/block.json +++ b/build/blocks/block-coauthor-description/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Author Biography", "category": "widgets", - "description": "Display a co-author's biographical description.", + "description": "Displays a co-author's biographical description.", "keywords": [ "description", "bio", diff --git a/build/blocks/block-coauthor-image/block.json b/build/blocks/block-coauthor-image/block.json index fa57ecd5..9ce6ac7d 100644 --- a/build/blocks/block-coauthor-image/block.json +++ b/build/blocks/block-coauthor-image/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Author Featured Image", "category": "widgets", - "description": "Featured Image from a Guest Author profile.", + "description": "Uses your theme's image sizes to display a scalable avatar for a co-author with a guest author profile. Does not fallback to Gravatar images.", "supports": { "align": [ "left", diff --git a/build/blocks/block-coauthor-name/block.json b/build/blocks/block-coauthor-name/block.json index 488aeb69..fb3af6f8 100644 --- a/build/blocks/block-coauthor-name/block.json +++ b/build/blocks/block-coauthor-name/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Author Name", "category": "widgets", - "description": "Display a co-author's name.", + "description": "Displays a co-author's display name and optionally links to their author archive.", "supports": { "html": false, "color": { diff --git a/build/blocks/block-coauthors/block.json b/build/blocks/block-coauthors/block.json index 6a74b225..8b7fbb64 100644 --- a/build/blocks/block-coauthors/block.json +++ b/build/blocks/block-coauthors/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Authors", "category": "widgets", - "description": "Display the co-authors for a post.", + "description": "Displays the co-authors of a post by using blocks to create a template. Start with co-author name and add any other co-author blocks.", "supports": { "html": false, "color": { diff --git a/src/blocks/block-coauthor-avatar/block.json b/src/blocks/block-coauthor-avatar/block.json index 50d4f6f0..da29810a 100644 --- a/src/blocks/block-coauthor-avatar/block.json +++ b/src/blocks/block-coauthor-avatar/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Author Avatar", "category": "widgets", - "description": "Display a co-author's avatar", + "description": "Displays a small scale version of a co-author's avatar. Utilizes fallbacks from Gravatar so everyone has an avatar.", "supports": { "align": [ "left", "right", "center" ], "html": false, diff --git a/src/blocks/block-coauthor-description/block.json b/src/blocks/block-coauthor-description/block.json index b5ae87fe..3db3d8b4 100644 --- a/src/blocks/block-coauthor-description/block.json +++ b/src/blocks/block-coauthor-description/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Author Biography", "category": "widgets", - "description": "Display a co-author's biographical description.", + "description": "Displays a co-author's biographical description.", "keywords": [ "description", "bio", diff --git a/src/blocks/block-coauthor-image/block.json b/src/blocks/block-coauthor-image/block.json index dd4e6c6f..0c3f4e13 100644 --- a/src/blocks/block-coauthor-image/block.json +++ b/src/blocks/block-coauthor-image/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Author Featured Image", "category": "widgets", - "description": "Featured Image from a Guest Author profile.", + "description": "Uses your theme's image sizes to display a scalable avatar for a co-author with a guest author profile. Does not fallback to Gravatar images.", "supports": { "align": [ "left", "right", "center", "wide", "full" ], "__experimentalBorder": { diff --git a/src/blocks/block-coauthor-name/block.json b/src/blocks/block-coauthor-name/block.json index 28a57f0b..1916e8ca 100644 --- a/src/blocks/block-coauthor-name/block.json +++ b/src/blocks/block-coauthor-name/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Author Name", "category": "widgets", - "description": "Display a co-author's name.", + "description": "Displays a co-author's display name and optionally links to their author archive.", "supports": { "html": false, "color": { diff --git a/src/blocks/block-coauthors/block.json b/src/blocks/block-coauthors/block.json index 3559271e..177192f3 100644 --- a/src/blocks/block-coauthors/block.json +++ b/src/blocks/block-coauthors/block.json @@ -5,7 +5,7 @@ "version": "1.0.0", "title": "Co-Authors", "category": "widgets", - "description": "Display the co-authors for a post.", + "description": "Displays the co-authors of a post by using blocks to create a template. Start with co-author name and add any other co-author blocks.", "supports": { "html": false, "color": { From 6362e8123d1e2c58ad11b66890a4c7d69467fda4 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 27 Sep 2023 13:40:30 -0400 Subject: [PATCH 106/123] Expand readme with notes on each block --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 277a070a..aeb936e3 100644 --- a/README.md +++ b/README.md @@ -70,51 +70,85 @@ Yes! Guest authors can be disabled entirely through a filter. Having the followi [View the change log](https://github.com/Automattic/Co-Authors-Plus/blob/master/CHANGELOG.md). ## Blocks -### Layout + +### Co-Authors + +Use this block to create a repeating template that displays the co-authors of a post. By default it contains the Co-Author Name block, but you can add any other block you want to the template. If you choose another Co-Author block like avatar, biography or image it will automatically be supplied the author `context` that it needs. This works similarly to creating a Post Template in a Query Loop block. The Co-Authors Block supports two layouts: -#### Inline +#### Inline Layout + +Use the inline layout to display co-authors in a list on a single wrapping line. + +You can control the characters displayed before, between and after co-authors in the list using the block settings, or change the defaults using the following server-side filters: + +``` +coauthors_default_before +coauthors_default_between +coauthors_default_between_last +coauthors_default_after +``` + +#### Block Layout + +Use the block layout to display co-authors in a vertical stack. While using the block layout you can use block spacing settings to control the vertical space between co-authors. + +Then you can create your own layout using blocks like group, row or stack and it will be applied to each co-author, similar to applying a layout to each post in a query loop. + +### Co-Author Name + +This block displays a co-author's `Display Name` and optionally turns it into a link to their author archive. + +Using the block's advanced settings you can select which HTML element is used to output the name. This is useful in contexts such as an author archive where you might want their name to be a heading. + +### Co-Author Avatar + +Like the post author avatar, or comment author avatar, this block displays a small scale square image of a co-author and utilizes the Gravatar default avatars as configured in your site's discussion options. + +To customize the available sizes, use the [rest_avatar_sizes](https://developer.wordpress.org/reference/hooks/rest_avatar_sizes/) filter. + +### Co-Author Biography -Inline is it's own layout. It applies `display: inline` to all its contents. +This block outputs the biographical information for a co-author based on either their user or guest author data. -#### Block +The content is wrapped in paragraph elements using `wpautop` and is escaped using `wp_kses_post`. -Block does not apply a specific layout. The co-authors stack vertically, and can be spaced apart using block spacing, but that's it. You can create your own layout using any of the other blocks like Group / Row / Stack and it will be applied to each co-author, similar to laying our each post in a query loop. +### Co-Author Image -### Context +This block requires the use of Guest Authors. Because guest author avatars are uploaded to the WordPress media library, there are more options for displaying these images. -#### Post, Page, Query Loop +This block utilizes the image sizes configured in your theme and your site's media settings to present a guest author's avatar at a larger scale or higher resolution. It does not support Gravatars. -By default, blocks receive the post context. The job of the Co-Authors Block is to use this context to find the relevant authors and provide context to its inner blocks. +## Block Context -#### Author Archive +### Post, Page, Query Loop -In author archive templates, the post context is the first post by the author returned in the main query. Since Co-Authors Plus exists to allow multiple attributed authors, we can't be sure which author of the first post matches the requested author archive. +By default, all blocks receive the post context. The job of the Co-Authors Block is to use this context to find the relevant authors and provide context to its inner blocks. -If you want to display data about the author on their own archive, use the individual co-author blocks directly without wrapping them in the Co-Authors Block. +### Author Archive -The function `CoAuthors\Blocks::provide_author_archive_context` filters the context so the correct author is provided. +If you want to display data about the author on their own archive, use the individual co-author blocks directly without wrapping them in the Co-Authors Block. During requests for an author archive the correct context is derived from the `author_name` query variable and provided to all blocks that declare their use of the context `co-authors-plus/author`. -#### Extending +### Extending -If you make a custom block and want to use the author context on the author archive, add `co-authors-plus/author` to the `usesContext` property in your block.json file. +If you make a custom block and want to use the author context, add `co-authors-plus/author` to the `usesContext` property in your block.json file. Example: ```json { - "usesContext": ['co-authors-plus/author'] + "usesContext": ["co-authors-plus/author"] } ``` -### Example Data +## Block Example Data When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the co-author blocks resembles a response to the `/coauthors-blocks/v1/coauthor/:user-nicename` REST API endpoint. -#### Extending +### Extending If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `co-authors-plus.author-placeholder` -### Non-support +## Block Non-support To declare a lack of support for Co-Author Plus blocks on your site, use the filter `coauthors_plus_support_blocks` to return `false`. From c70ecca045f8a562f81dc20809216460de777904 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 27 Sep 2023 15:36:04 -0400 Subject: [PATCH 107/123] Update REST API endpoints to existing namespace --- README.md | 4 ++-- build/blocks/block-coauthors/index.asset.php | 2 +- build/blocks/block-coauthors/index.js | 2 +- co-authors-plus.php | 10 ++++---- ...ler.php => class-coauthors-controller.php} | 24 ++++++++++--------- php/blocks/class-blocks.php | 2 +- src/blocks/block-coauthors/edit.js | 2 +- 7 files changed, 24 insertions(+), 22 deletions(-) rename php/api/endpoints/{class-coauthors-blocks-controller.php => class-coauthors-controller.php} (95%) diff --git a/README.md b/README.md index aeb936e3..f8fa8617 100644 --- a/README.md +++ b/README.md @@ -143,11 +143,11 @@ Example: ## Block Example Data -When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the co-author blocks resembles a response to the `/coauthors-blocks/v1/coauthor/:user-nicename` REST API endpoint. +When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the co-author blocks resembles a response to the `/coauthors/v1/coauthor/:user-nicename` REST API endpoint. ### Extending -If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `co-authors-plus.author-placeholder` +If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `co-authors-plus.author-placeholder`. ## Block Non-support diff --git a/build/blocks/block-coauthors/index.asset.php b/build/blocks/block-coauthors/index.asset.php index 9c017cf4..e5a173bc 100644 --- a/build/blocks/block-coauthors/index.asset.php +++ b/build/blocks/block-coauthors/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'e78745f41ce5a8016414'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'a2ad2bb468dc3d48a9da'); diff --git a/build/blocks/block-coauthors/index.js b/build/blocks/block-coauthors/index.js index 55598fdc..7a12a16a 100644 --- a/build/blocks/block-coauthors/index.js +++ b/build/blocks/block-coauthors/index.js @@ -1 +1 @@ -!function(){var e,t={749:function(e,t,o){"use strict";var n=window.wp.blocks,r=window.wp.element,l=window.wp.primitives,a=(0,r.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(l.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})),c=window.wp.blockEditor,s=window.wp.components,i=window.wp.apiFetch,u=o.n(i),p=window.wp.data,h=window.wp.i18n,v=(0,r.createElement)(l.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(l.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),f=(0,r.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(l.Path,{d:"m3 5c0-1.10457.89543-2 2-2h13.5c1.1046 0 2 .89543 2 2v13.5c0 1.1046-.8954 2-2 2h-13.5c-1.10457 0-2-.8954-2-2zm2-.5h6v6.5h-6.5v-6c0-.27614.22386-.5.5-.5zm-.5 8v6c0 .2761.22386.5.5.5h6v-6.5zm8 0v6.5h6c.2761 0 .5-.2239.5-.5v-6zm0-8v6.5h6.5v-6c0-.27614-.2239-.5-.5-.5z",fillRule:"evenodd",clipRule:"evenodd"})),d=o(184),m=o.n(d);function w(){return w=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(o)},i={display:n?"none":void 0};return(0,r.createElement)("div",w({},a,{tabIndex:0,role:"button",onClick:s,onKeyUp:s,style:i}))}));function g(){return(0,r.createElement)("div",(0,c.useInnerBlocksProps)({className:"wp-block-co-authors-plus-coauthor"},{template:[["co-authors-plus/name"]]}))}const y=["core/bold","core/italic","core/text-color"];var x=JSON.parse('{"u2":"co-authors-plus/coauthors"}');(0,n.registerBlockType)(x.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:l,clientId:a,context:i,isSelected:d}=e;const{prefix:w,separator:x,lastSeparator:k,suffix:_,layout:E,textAlign:C}=n,{postId:S}=i,O=(0,p.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,z]=(0,r.useState)(),I=(0,p.useDispatch)("core/notices");function N(e){"AbortError"!==e.name&&I.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return u()({path:`/coauthors-blocks/v1/coauthors/${S}/`,signal:e.signal}).then(B).catch(N),()=>{e.abort()}}),[S]);const j=(0,p.useSelect)((e=>e(c.store).getBlocks(a))),G=e=>{l({layout:{...E,...e}})},V=[{icon:v,title:(0,h.__)("Inline","co-authors-plus"),onClick:()=>G({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,h.__)("Block","co-authors-plus"),onClick:()=>G({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(c.BlockControls,null,(0,r.createElement)(s.ToolbarGroup,{controls:V}),(0,r.createElement)(c.AlignmentControl,{value:C,onChange:e=>{l({textAlign:e})}})),(0,r.createElement)("div",(0,c.useBlockProps)({className:m()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,c.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),A&&"inline"===E.type&&(d||w)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__prefix",multiline:!1,"aria-label":(0,h.__)("Prefix","co-authors-plus"),placeholder:(0,h.__)("Prefix","co-authors-plus")+" ",value:w,onChange:e=>l({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const o=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(c.BlockContextProvider,{key:e.id,value:{"co-authors-plus/author":e}},o?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:z,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-co-authors-plus-coauthors__separator"},k&&o===n.length-1?`${k}`:`${x}`),t))),A&&"inline"===E.type&&(d||_)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__suffix",multiline:!1,"aria-label":(0,h.__)("Suffix"),placeholder:(0,h.__)("Suffix")+" ",value:_,onChange:e=>l({suffix:e}),tagName:"span"})),(0,r.createElement)(c.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(s.PanelBody,{title:(0,h.__)("Co-authors Layout","co-authors-plus")},(0,r.createElement)(s.TextControl,{autoComplete:"off",label:(0,h.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{l({separator:e})},help:(0,h.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(s.TextControl,{autoComplete:"off",label:(0,h.__)("Last Separator","co-authors-plus"),value:k||"",onChange:e=>{l({lastSeparator:e})},help:(0,h.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:l,textAlign:a}=n,s={gap:"block"===l.type?(0,c.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},i=m()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${a}`]:a});return(0,r.createElement)("div",c.useBlockProps.save({className:i,style:s}),(0,r.createElement)(c.InnerBlocks.Content,null))},icon:a})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(n.O).every((function(e){return n.O[e](o[s])}))?o.splice(s--,1):(c=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[o,r,l]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,l,a=o[0],c=o[1],s=o[2],i=0;if(a.some((function(t){return 0!==e[t]}))){for(r in c)n.o(c,r)&&(n.m[r]=c[r]);if(s)var u=s(n)}for(t&&t(o);i{l(o)},i={display:n?"none":void 0};return(0,r.createElement)("div",w({},a,{tabIndex:0,role:"button",onClick:s,onKeyUp:s,style:i}))}));function g(){return(0,r.createElement)("div",(0,c.useInnerBlocksProps)({className:"wp-block-co-authors-plus-coauthor"},{template:[["co-authors-plus/name"]]}))}const y=["core/bold","core/italic","core/text-color"];var x=JSON.parse('{"u2":"co-authors-plus/coauthors"}');(0,n.registerBlockType)(x.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:l,clientId:a,context:i,isSelected:f}=e;const{prefix:w,separator:x,lastSeparator:_,suffix:k,layout:E,textAlign:C}=n,{postId:S}=i,O=(0,p.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,z]=(0,r.useState)(),I=(0,p.useDispatch)("core/notices");function N(e){"AbortError"!==e.name&&I.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return u()({path:`/coauthors/v1/coauthors?post_id=${S}`,signal:e.signal}).then(B).catch(N),()=>{e.abort()}}),[S]);const j=(0,p.useSelect)((e=>e(c.store).getBlocks(a))),G=e=>{l({layout:{...E,...e}})},V=[{icon:v,title:(0,h.__)("Inline","co-authors-plus"),onClick:()=>G({type:"inline"}),isActive:"inline"===E.type},{icon:d,title:(0,h.__)("Block","co-authors-plus"),onClick:()=>G({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(c.BlockControls,null,(0,r.createElement)(s.ToolbarGroup,{controls:V}),(0,r.createElement)(c.AlignmentControl,{value:C,onChange:e=>{l({textAlign:e})}})),(0,r.createElement)("div",(0,c.useBlockProps)({className:m()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,c.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),A&&"inline"===E.type&&(f||w)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__prefix",multiline:!1,"aria-label":(0,h.__)("Prefix","co-authors-plus"),placeholder:(0,h.__)("Prefix","co-authors-plus")+" ",value:w,onChange:e=>l({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const o=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(c.BlockContextProvider,{key:e.id,value:{"co-authors-plus/author":e}},o?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:z,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-co-authors-plus-coauthors__separator"},_&&o===n.length-1?`${_}`:`${x}`),t))),A&&"inline"===E.type&&(f||k)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__suffix",multiline:!1,"aria-label":(0,h.__)("Suffix"),placeholder:(0,h.__)("Suffix")+" ",value:k,onChange:e=>l({suffix:e}),tagName:"span"})),(0,r.createElement)(c.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(s.PanelBody,{title:(0,h.__)("Co-authors Layout","co-authors-plus")},(0,r.createElement)(s.TextControl,{autoComplete:"off",label:(0,h.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{l({separator:e})},help:(0,h.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(s.TextControl,{autoComplete:"off",label:(0,h.__)("Last Separator","co-authors-plus"),value:_||"",onChange:e=>{l({lastSeparator:e})},help:(0,h.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:l,textAlign:a}=n,s={gap:"block"===l.type?(0,c.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},i=m()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${a}`]:a});return(0,r.createElement)("div",c.useBlockProps.save({className:i,style:s}),(0,r.createElement)(c.InnerBlocks.Content,null))},icon:a})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(n.O).every((function(e){return n.O[e](o[s])}))?o.splice(s--,1):(c=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[o,r,l]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,l,a=o[0],c=o[1],s=o[2],i=0;if(a.some((function(t){return 0!==e[t]}))){for(r in c)n.o(c,r)&&(n.m[r]=c[r]);if(s)var u=s(n)}for(t&&t(o);iregister_routes(); + (new CoAuthors\API\Endpoints\CoAuthors_Controller( $coauthors_plus ))->register_routes(); } -add_action( 'rest_api_init', 'cap_register_coauthors_blocks_rest_api_routes' ); +add_action( 'rest_api_init', 'cap_register_coauthors_rest_api_routes' ); diff --git a/php/api/endpoints/class-coauthors-blocks-controller.php b/php/api/endpoints/class-coauthors-controller.php similarity index 95% rename from php/api/endpoints/class-coauthors-blocks-controller.php rename to php/api/endpoints/class-coauthors-controller.php index d4adea30..a12792c1 100644 --- a/php/api/endpoints/class-coauthors-blocks-controller.php +++ b/php/api/endpoints/class-coauthors-controller.php @@ -1,6 +1,6 @@ [\d]+)', + 'coauthors/v1', + '/coauthors', array( 'args' => array( 'post_id' => array( 'description' => __( 'Unique identifier for a post.', 'co-authors-plus' ), 'type' => 'integer', + 'required' => true, 'validate_callback' => function( $post_id ): bool { return 0 !== absint( $post_id ); }, @@ -92,19 +93,20 @@ public function register_coauthors_route(): void { * * Provide a user nicename as a hyphen-separated string to retrieve a single co-author. * - * Example: `/wp-json/coauthors-blocks/v1/coauthor/user-nicename` + * Example: `/wp-json/coauthors/v1/coauthor/user-nicename` * * @since 3.6.0 */ public function register_coauthor_route(): void { register_rest_route( - 'coauthors-blocks/v1', + 'coauthors/v1', '/coauthor/(?P[\w-]+)', array( 'args' => array( 'user_nicename' => array( 'description' => __( 'Nicename / slug for co-author.', 'co-authors-plus' ), 'type' => 'string', + 'required' => true, 'validate_callback' => function( $slug ): bool { return is_string( $slug ); }, @@ -236,7 +238,7 @@ public function get_item_schema(): array { $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'coauthors-block', + 'title' => 'coauthor', 'type' => 'object', 'properties' => array( 'id' => array( @@ -304,7 +306,7 @@ public function get_item_schema(): array { // Take a snapshot of which fields are in the schema pre-filtering. $schema_fields = array_keys( $schema['properties'] ); - $schema = apply_filters( 'rest_coauthors-block_item_schema', $schema ); + $schema = apply_filters( 'rest_coauthors_item_schema', $schema ); // Emit a _doing_it_wrong warning if user tries to add new properties using this filter. $new_fields = array_diff( array_keys( $schema['properties'] ), $schema_fields ); @@ -394,6 +396,6 @@ public function prepare_item_for_response( $author, $request ) { * @param stdClass|WP_User $author * @param WP_REST_Request $request Request object. */ - return apply_filters( 'rest_prepare_coauthors-block', $response, $author, $request ); + return apply_filters( 'rest_prepare_coauthor', $response, $author, $request ); } } diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 311345f3..7ae243d7 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -173,7 +173,7 @@ public static function get_author_with_api_schema( $author ): ?array { WP_REST_Request::from_url( home_url( sprintf( - '/wp-json/coauthors-blocks/v1/coauthor/%s', + '/wp-json/coauthors/v1/coauthor/%s', $author->user_nicename ) ) diff --git a/src/blocks/block-coauthors/edit.js b/src/blocks/block-coauthors/edit.js index 71fa228a..10739fe3 100644 --- a/src/blocks/block-coauthors/edit.js +++ b/src/blocks/block-coauthors/edit.js @@ -67,7 +67,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is const controller = new AbortController(); apiFetch( { - path: `/coauthors-blocks/v1/coauthors/${postId}/`, + path: `/coauthors/v1/coauthors?post_id=${postId}`, signal: controller.signal } ) .then( setCoAuthors ) From bb06e708eb2803c596b79151a3f3d841cf3b9c13 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 28 Sep 2023 09:31:46 -0400 Subject: [PATCH 108/123] Move blocks to theme category, same as Post Author --- build/blocks/block-coauthor-avatar/block.json | 2 +- build/blocks/block-coauthor-description/block.json | 2 +- build/blocks/block-coauthor-image/block.json | 2 +- build/blocks/block-coauthor-name/block.json | 2 +- build/blocks/block-coauthors/block.json | 2 +- src/blocks/block-coauthor-avatar/block.json | 2 +- src/blocks/block-coauthor-description/block.json | 2 +- src/blocks/block-coauthor-image/block.json | 2 +- src/blocks/block-coauthor-name/block.json | 2 +- src/blocks/block-coauthors/block.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build/blocks/block-coauthor-avatar/block.json b/build/blocks/block-coauthor-avatar/block.json index 6811dccb..438be4ee 100644 --- a/build/blocks/block-coauthor-avatar/block.json +++ b/build/blocks/block-coauthor-avatar/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/avatar", "version": "1.0.0", "title": "Co-Author Avatar", - "category": "widgets", + "category": "theme", "description": "Displays a small scale version of a co-author's avatar. Utilizes fallbacks from Gravatar so everyone has an avatar.", "supports": { "align": [ diff --git a/build/blocks/block-coauthor-description/block.json b/build/blocks/block-coauthor-description/block.json index 98c17113..66a8561a 100644 --- a/build/blocks/block-coauthor-description/block.json +++ b/build/blocks/block-coauthor-description/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/description", "version": "1.0.0", "title": "Co-Author Biography", - "category": "widgets", + "category": "theme", "description": "Displays a co-author's biographical description.", "keywords": [ "description", diff --git a/build/blocks/block-coauthor-image/block.json b/build/blocks/block-coauthor-image/block.json index 9ce6ac7d..02172277 100644 --- a/build/blocks/block-coauthor-image/block.json +++ b/build/blocks/block-coauthor-image/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/image", "version": "1.0.0", "title": "Co-Author Featured Image", - "category": "widgets", + "category": "theme", "description": "Uses your theme's image sizes to display a scalable avatar for a co-author with a guest author profile. Does not fallback to Gravatar images.", "supports": { "align": [ diff --git a/build/blocks/block-coauthor-name/block.json b/build/blocks/block-coauthor-name/block.json index fb3af6f8..4784e640 100644 --- a/build/blocks/block-coauthor-name/block.json +++ b/build/blocks/block-coauthor-name/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/name", "version": "1.0.0", "title": "Co-Author Name", - "category": "widgets", + "category": "theme", "description": "Displays a co-author's display name and optionally links to their author archive.", "supports": { "html": false, diff --git a/build/blocks/block-coauthors/block.json b/build/blocks/block-coauthors/block.json index 8b7fbb64..f9acccb0 100644 --- a/build/blocks/block-coauthors/block.json +++ b/build/blocks/block-coauthors/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/coauthors", "version": "1.0.0", "title": "Co-Authors", - "category": "widgets", + "category": "theme", "description": "Displays the co-authors of a post by using blocks to create a template. Start with co-author name and add any other co-author blocks.", "supports": { "html": false, diff --git a/src/blocks/block-coauthor-avatar/block.json b/src/blocks/block-coauthor-avatar/block.json index da29810a..14ea30f8 100644 --- a/src/blocks/block-coauthor-avatar/block.json +++ b/src/blocks/block-coauthor-avatar/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/avatar", "version": "1.0.0", "title": "Co-Author Avatar", - "category": "widgets", + "category": "theme", "description": "Displays a small scale version of a co-author's avatar. Utilizes fallbacks from Gravatar so everyone has an avatar.", "supports": { "align": [ "left", "right", "center" ], diff --git a/src/blocks/block-coauthor-description/block.json b/src/blocks/block-coauthor-description/block.json index 3db3d8b4..d036f767 100644 --- a/src/blocks/block-coauthor-description/block.json +++ b/src/blocks/block-coauthor-description/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/description", "version": "1.0.0", "title": "Co-Author Biography", - "category": "widgets", + "category": "theme", "description": "Displays a co-author's biographical description.", "keywords": [ "description", diff --git a/src/blocks/block-coauthor-image/block.json b/src/blocks/block-coauthor-image/block.json index 0c3f4e13..b8ed363b 100644 --- a/src/blocks/block-coauthor-image/block.json +++ b/src/blocks/block-coauthor-image/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/image", "version": "1.0.0", "title": "Co-Author Featured Image", - "category": "widgets", + "category": "theme", "description": "Uses your theme's image sizes to display a scalable avatar for a co-author with a guest author profile. Does not fallback to Gravatar images.", "supports": { "align": [ "left", "right", "center", "wide", "full" ], diff --git a/src/blocks/block-coauthor-name/block.json b/src/blocks/block-coauthor-name/block.json index 1916e8ca..4b5d0440 100644 --- a/src/blocks/block-coauthor-name/block.json +++ b/src/blocks/block-coauthor-name/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/name", "version": "1.0.0", "title": "Co-Author Name", - "category": "widgets", + "category": "theme", "description": "Displays a co-author's display name and optionally links to their author archive.", "supports": { "html": false, diff --git a/src/blocks/block-coauthors/block.json b/src/blocks/block-coauthors/block.json index 177192f3..d882d73f 100644 --- a/src/blocks/block-coauthors/block.json +++ b/src/blocks/block-coauthors/block.json @@ -4,7 +4,7 @@ "name": "co-authors-plus/coauthors", "version": "1.0.0", "title": "Co-Authors", - "category": "widgets", + "category": "theme", "description": "Displays the co-authors of a post by using blocks to create a template. Start with co-author name and add any other co-author blocks.", "supports": { "html": false, From 0c3ddcf7e1617c6b7229a801f55c517e8ab5e668 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Thu, 28 Sep 2023 10:08:17 -0400 Subject: [PATCH 109/123] Fix, coauthors API endpoint should be plural --- README.md | 2 +- php/api/endpoints/class-coauthors-controller.php | 4 ++-- php/blocks/class-blocks.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f8fa8617..d9d4004d 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ Example: ## Block Example Data -When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the co-author blocks resembles a response to the `/coauthors/v1/coauthor/:user-nicename` REST API endpoint. +When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the co-author blocks resembles a response to the `/coauthors/v1/coauthors/:user-nicename` REST API endpoint. ### Extending diff --git a/php/api/endpoints/class-coauthors-controller.php b/php/api/endpoints/class-coauthors-controller.php index a12792c1..1c9da7f4 100644 --- a/php/api/endpoints/class-coauthors-controller.php +++ b/php/api/endpoints/class-coauthors-controller.php @@ -93,14 +93,14 @@ public function register_coauthors_route(): void { * * Provide a user nicename as a hyphen-separated string to retrieve a single co-author. * - * Example: `/wp-json/coauthors/v1/coauthor/user-nicename` + * Example: `/wp-json/coauthors/v1/coauthors/user-nicename` * * @since 3.6.0 */ public function register_coauthor_route(): void { register_rest_route( 'coauthors/v1', - '/coauthor/(?P[\w-]+)', + '/coauthors/(?P[\w-]+)', array( 'args' => array( 'user_nicename' => array( diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 7ae243d7..2a5c7a61 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -173,7 +173,7 @@ public static function get_author_with_api_schema( $author ): ?array { WP_REST_Request::from_url( home_url( sprintf( - '/wp-json/coauthors/v1/coauthor/%s', + '/wp-json/coauthors/v1/coauthors/%s', $author->user_nicename ) ) From b66d2f4afa27866d660fe11a50c9bbc3fc81eeb4 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 23 Oct 2023 17:48:24 -0400 Subject: [PATCH 110/123] Applied format:js for consistency --- src/blocks/block-coauthor-avatar/block.json | 6 +- src/blocks/block-coauthor-avatar/edit.js | 224 ++++++++------- src/blocks/block-coauthor-avatar/index.js | 2 +- .../block-coauthor-description/block.json | 10 +- src/blocks/block-coauthor-description/edit.js | 29 +- .../block-coauthor-description/index.js | 2 +- src/blocks/block-coauthor-image/block.json | 4 +- src/blocks/block-coauthor-image/edit.js | 254 +++++++++++------- src/blocks/block-coauthor-image/index.js | 4 +- src/blocks/block-coauthor-image/utils.js | 59 ++-- src/blocks/block-coauthor-name/block.json | 4 +- src/blocks/block-coauthor-name/edit.js | 136 ++++++---- src/blocks/block-coauthor-name/index.js | 2 +- src/blocks/block-coauthors/block.json | 2 +- ...emoized-coauthor-template-block-preview.js | 5 +- src/blocks/block-coauthors/edit.js | 210 ++++++++------- src/blocks/block-coauthors/index.js | 2 +- src/blocks/block-coauthors/save.js | 22 +- src/blocks/components/placeholder-image.jsx | 50 ++-- 19 files changed, 568 insertions(+), 459 deletions(-) diff --git a/src/blocks/block-coauthor-avatar/block.json b/src/blocks/block-coauthor-avatar/block.json index 14ea30f8..df6b33a7 100644 --- a/src/blocks/block-coauthor-avatar/block.json +++ b/src/blocks/block-coauthor-avatar/block.json @@ -30,11 +30,9 @@ } } }, - "usesContext": [ - "co-authors-plus/author" - ], + "usesContext": [ "co-authors-plus/author" ], "attributes": { - "size" : { + "size": { "type": "number", "default": 24 }, diff --git a/src/blocks/block-coauthor-avatar/edit.js b/src/blocks/block-coauthor-avatar/edit.js index 56db0856..46dfee66 100644 --- a/src/blocks/block-coauthor-avatar/edit.js +++ b/src/blocks/block-coauthor-avatar/edit.js @@ -1,6 +1,16 @@ import { __ } from '@wordpress/i18n'; -import { useBlockProps, InspectorControls, __experimentalUseBorderProps as useBorderProps, store as blockEditorStore } from '@wordpress/block-editor'; -import { SelectControl, PanelBody, ToggleControl, TextControl } from '@wordpress/components'; +import { + useBlockProps, + InspectorControls, + __experimentalUseBorderProps as useBorderProps, + store as blockEditorStore, +} from '@wordpress/block-editor'; +import { + SelectControl, + PanelBody, + ToggleControl, + TextControl, +} from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import PlaceholderImage from '../components/placeholder-image'; @@ -14,135 +24,143 @@ import PlaceholderImage from '../components/placeholder-image'; * @return {WPElement} Element to render. */ export default function Edit( { context, attributes, setAttributes } ) { - const { isLink, rel, size, verticalAlign } = attributes; - const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []); - const author = context['co-authors-plus/author'] || authorPlaceholder; + const authorPlaceholder = useSelect( + ( select ) => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), + [] + ); + const author = context[ 'co-authors-plus/author' ] || authorPlaceholder; const { avatar_urls } = author; if ( ! avatar_urls || 0 === avatar_urls.length ) { return null; } - const sizes = Object.keys( avatar_urls ).map( (size) => { + const sizes = Object.keys( avatar_urls ).map( ( size ) => { return { value: size, - label: `${ size } x ${ size }` + label: `${ size } x ${ size }`, }; - }); + } ); const borderProps = useBorderProps( attributes ); - const src = avatar_urls[size] ?? ''; - + const src = avatar_urls[ size ] ?? ''; + return ( <> -
- { - '' === src ? - ( +
+ { '' === src ? ( ) : ( - ) - } -
- - - { - setAttributes( { - size: Number( nextSize ) - } ); - } } - /> - setAttributes( { isLink: ! isLink } ) } - checked={ isLink } - /> - { isLink && ( - - setAttributes( { rel: newRel } ) - } + style={ { ...borderProps.style, verticalAlign } } + width={ size } + height={ size } + src={ `${ avatar_urls[ size ] }` } /> ) } - - - { - setAttributes( { - verticalAlign: '' === value ? undefined : value - } ); - } } - help={ __( 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', 'co-authors-plus' )} - /> - - +
+ + + { + setAttributes( { + size: Number( nextSize ), + } ); + } } + /> + setAttributes( { isLink: ! isLink } ) } + checked={ isLink } + /> + { isLink && ( + + setAttributes( { rel: newRel } ) + } + /> + ) } + + + { + setAttributes( { + verticalAlign: '' === value ? undefined : value, + } ); + } } + help={ __( + 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', + 'co-authors-plus' + ) } + /> + + ); } diff --git a/src/blocks/block-coauthor-avatar/index.js b/src/blocks/block-coauthor-avatar/index.js index afc75931..f58908ed 100644 --- a/src/blocks/block-coauthor-avatar/index.js +++ b/src/blocks/block-coauthor-avatar/index.js @@ -27,5 +27,5 @@ registerBlockType( metadata.name, { * @see ./edit.js */ edit: Edit, - icon + icon, } ); diff --git a/src/blocks/block-coauthor-description/block.json b/src/blocks/block-coauthor-description/block.json index d036f767..5782ce4c 100644 --- a/src/blocks/block-coauthor-description/block.json +++ b/src/blocks/block-coauthor-description/block.json @@ -6,11 +6,7 @@ "title": "Co-Author Biography", "category": "theme", "description": "Displays a co-author's biographical description.", - "keywords": [ - "description", - "bio", - "biography" - ], + "keywords": [ "description", "bio", "biography" ], "supports": { "html": false, "color": { @@ -39,9 +35,7 @@ } } }, - "usesContext": [ - "co-authors-plus/author" - ], + "usesContext": [ "co-authors-plus/author" ], "attributes": { "textAlign": { "type": "string" diff --git a/src/blocks/block-coauthor-description/edit.js b/src/blocks/block-coauthor-description/edit.js index 843310b3..67a02d31 100644 --- a/src/blocks/block-coauthor-description/edit.js +++ b/src/blocks/block-coauthor-description/edit.js @@ -4,7 +4,12 @@ * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ -import { useBlockProps, AlignmentControl, BlockControls, store as blockEditorStore } from '@wordpress/block-editor'; +import { + useBlockProps, + AlignmentControl, + BlockControls, + store as blockEditorStore, +} from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import classnames from 'classnames'; @@ -19,10 +24,12 @@ import './editor.css'; * @return {WPElement} Element to render. */ export default function Edit( { context, attributes, setAttributes } ) { - const { textAlign } = attributes; - const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []); - const author = context['co-authors-plus/author'] || authorPlaceholder; + const authorPlaceholder = useSelect( + ( select ) => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), + [] + ); + const author = context[ 'co-authors-plus/author' ] || authorPlaceholder; const { description } = author; return ( @@ -36,14 +43,12 @@ export default function Edit( { context, attributes, setAttributes } ) { />
diff --git a/src/blocks/block-coauthor-description/index.js b/src/blocks/block-coauthor-description/index.js index 52b858a3..4b4e8463 100644 --- a/src/blocks/block-coauthor-description/index.js +++ b/src/blocks/block-coauthor-description/index.js @@ -21,5 +21,5 @@ registerBlockType( metadata.name, { * @see ./edit.js */ edit: Edit, - icon + icon, } ); diff --git a/src/blocks/block-coauthor-image/block.json b/src/blocks/block-coauthor-image/block.json index b8ed363b..69edc190 100644 --- a/src/blocks/block-coauthor-image/block.json +++ b/src/blocks/block-coauthor-image/block.json @@ -29,9 +29,7 @@ } } }, - "usesContext": [ - "co-authors-plus/author" - ], + "usesContext": [ "co-authors-plus/author" ], "attributes": { "isLink": { "type": "boolean", diff --git a/src/blocks/block-coauthor-image/edit.js b/src/blocks/block-coauthor-image/edit.js index b200aa12..bdc30b6b 100644 --- a/src/blocks/block-coauthor-image/edit.js +++ b/src/blocks/block-coauthor-image/edit.js @@ -9,12 +9,22 @@ import { __experimentalUseBorderProps as useBorderProps, InspectorControls, } from '@wordpress/block-editor'; -import { TextControl, PanelBody, ToggleControl, SelectControl } from '@wordpress/components'; +import { + TextControl, + PanelBody, + ToggleControl, + SelectControl, +} from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import DimensionControls from './dimension-controls'; import PlaceholderImage from '../components/placeholder-image'; -import { getAvailableSizeSlug, getMediaSrc, getMediaDimensions, getPlaceholderImageDimensions } from './utils' +import { + getAvailableSizeSlug, + getMediaSrc, + getMediaDimensions, + getPlaceholderImageDimensions, +} from './utils'; /** * Edit @@ -23,32 +33,62 @@ import { getAvailableSizeSlug, getMediaSrc, getMediaDimensions, getPlaceholderIm * @param {Object} props { attributes, setAttributes, context, clientId } * @return {WPElement} */ -export default function Edit( { attributes, setAttributes, context, clientId } ) { - - const { aspectRatio, height, isLink, rel, scale, sizeSlug, verticalAlign, width } = attributes; +export default function Edit( { + attributes, + setAttributes, + context, + clientId, +} ) { + const { + aspectRatio, + height, + isLink, + rel, + scale, + sizeSlug, + verticalAlign, + width, + } = attributes; // Author const authorPlaceholder = useSelect( - select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), + ( select ) => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), [] ); - const author = context['co-authors-plus/author'] || authorPlaceholder; + const author = context[ 'co-authors-plus/author' ] || authorPlaceholder; // Media const media = useSelect( - select => 0 !== author.featured_media && select( coreStore ).getMedia( author.featured_media, { context: 'view' } ), - [author.featured_media] + ( select ) => + 0 !== author.featured_media && + select( coreStore ).getMedia( author.featured_media, { + context: 'view', + } ), + [ author.featured_media ] ); // Image Sizes and Dimensions const { imageSizes, imageDimensions } = useSelect( - select => select( blockEditorStore ).getSettings(), + ( select ) => select( blockEditorStore ).getSettings(), [] ); - const imageSizeOptions = imageSizes.map( ( { name, slug } ) => ({ value: slug, label: name })); - const availableSizeSlug = getAvailableSizeSlug( media, imageDimensions, sizeSlug ); - const dimensions = getMediaDimensions( media, imageDimensions, availableSizeSlug ); - const placeholderDimensions = media ? {} : getPlaceholderImageDimensions(imageDimensions, availableSizeSlug); + const imageSizeOptions = imageSizes.map( ( { name, slug } ) => ( { + value: slug, + label: name, + } ) ); + const availableSizeSlug = getAvailableSizeSlug( + media, + imageDimensions, + sizeSlug + ); + const dimensions = getMediaDimensions( + media, + imageDimensions, + availableSizeSlug + ); + const placeholderDimensions = media + ? {} + : getPlaceholderImageDimensions( imageDimensions, availableSizeSlug ); // Border const borderProps = useBorderProps( attributes ); @@ -65,49 +105,51 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) setAttributes={ setAttributes } imageSizeOptions={ imageSizeOptions } /> - { - panic ? null : ( -
- { - media ? ( - {__( - ) : ( - - ) - } -
- ) - } + { panic ? null : ( +
+ { media ? ( + { + ) : ( + + ) } +
+ ) } setAttributes( { isLink: ! isLink } ) } checked={ isLink } /> @@ -122,56 +164,62 @@ export default function Edit( { attributes, setAttributes, context, clientId } ) /> ) } - - { - setAttributes( { - verticalAlign: '' === value ? undefined : value - } ); - } } - help={ __( 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', 'co-authors-plus' )} - /> - + + { + setAttributes( { + verticalAlign: '' === value ? undefined : value, + } ); + } } + help={ __( + 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', + 'co-authors-plus' + ) } + /> + ); diff --git a/src/blocks/block-coauthor-image/index.js b/src/blocks/block-coauthor-image/index.js index edc33d76..31c6727f 100644 --- a/src/blocks/block-coauthor-image/index.js +++ b/src/blocks/block-coauthor-image/index.js @@ -4,7 +4,7 @@ * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ */ import { registerBlockType } from '@wordpress/blocks'; -import { image as icon } from '@wordpress/icons' +import { image as icon } from '@wordpress/icons'; /** * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. @@ -31,5 +31,5 @@ registerBlockType( metadata.name, { * @see ./edit.js */ edit: Edit, - icon + icon, } ); diff --git a/src/blocks/block-coauthor-image/utils.js b/src/blocks/block-coauthor-image/utils.js index 40f621fa..0032d9cb 100644 --- a/src/blocks/block-coauthor-image/utils.js +++ b/src/blocks/block-coauthor-image/utils.js @@ -11,22 +11,22 @@ export function getMediaDimensions( media, imageDimensions, sizeSlug ) { return {}; } - const mediaSize = media.media_details.sizes[sizeSlug]; - + const mediaSize = media.media_details.sizes[ sizeSlug ]; + if ( 'full' === sizeSlug ) { return { width: mediaSize.width, - height: mediaSize.height - } + height: mediaSize.height, + }; } - const imageSize = imageDimensions[sizeSlug]; + const imageSize = imageDimensions[ sizeSlug ]; if ( true === imageSize.crop || imageSize.width === imageSize.height ) { return { width: imageSize.width, - height: imageSize.height - } + height: imageSize.height, + }; } const mediaAspectRatio = mediaSize.width / mediaSize.height; @@ -34,14 +34,14 @@ export function getMediaDimensions( media, imageDimensions, sizeSlug ) { if ( imageSize.width > imageSize.height ) { return { width: imageSize.width, - height: imageSize.width / mediaAspectRatio - } + height: imageSize.width / mediaAspectRatio, + }; } return { width: imageSize.height * mediaAspectRatio, - height: imageSize.height - } + height: imageSize.height, + }; } /** @@ -52,7 +52,7 @@ export function getMediaDimensions( media, imageDimensions, sizeSlug ) { * @return {string} */ export function getMediaSrc( media, sizeSlug ) { - return media?.media_details?.sizes[sizeSlug]?.source_url; + return media?.media_details?.sizes[ sizeSlug ]?.source_url; } /** @@ -63,67 +63,68 @@ export function getMediaSrc( media, sizeSlug ) { * @return {Object} {width,height} */ export function getPlaceholderImageDimensions( imageDimensions, sizeSlug ) { - - const size = imageDimensions[sizeSlug]; + const size = imageDimensions[ sizeSlug ]; if ( true === size.crop || size.width === size.height ) { return { width: size.width, - height: size.height - } + height: size.height, + }; } if ( size.width > size.height ) { return { width: size.width, - height: size.width - } + height: size.width, + }; } return { width: size.height, - height: size.height - } + height: size.height, + }; } /** * Get Size Keys Intersection - * + * * @param {Object} media * @param {Object} imageDimensions * @return {Array} */ export function getSizeKeysIntersection( media, imageDimensions ) { - if ( ! media ) { return Object.keys( imageDimensions ); } const mediaKeys = Object.keys( media.media_details.sizes ); - const sizeKeys = Object.keys( imageDimensions ); - - return Array.from( new Set([...mediaKeys.filter( ( key ) => sizeKeys.includes(key) )])) + const sizeKeys = Object.keys( imageDimensions ); + + return Array.from( + new Set( [ + ...mediaKeys.filter( ( key ) => sizeKeys.includes( key ) ), + ] ) + ); } /** * Get Available Size Slug - * + * * @param {Object} media * @param {Object} imageDimensions * @param {string} sizeSlug * @return {string} */ export function getAvailableSizeSlug( media, imageDimensions, sizeSlug ) { - if ( media && 'full' === sizeSlug ) { return sizeSlug; } const keys = getSizeKeysIntersection( media, imageDimensions ); - + if ( sizeSlug && keys.includes( sizeSlug ) ) { return sizeSlug; } - return keys[Math.max(0, keys.length - 1)]; + return keys[ Math.max( 0, keys.length - 1 ) ]; } diff --git a/src/blocks/block-coauthor-name/block.json b/src/blocks/block-coauthor-name/block.json index 4b5d0440..44270bd5 100644 --- a/src/blocks/block-coauthor-name/block.json +++ b/src/blocks/block-coauthor-name/block.json @@ -34,9 +34,7 @@ } } }, - "usesContext": [ - "co-authors-plus/author" - ], + "usesContext": [ "co-authors-plus/author" ], "attributes": { "isLink": { "type": "boolean", diff --git a/src/blocks/block-coauthor-name/edit.js b/src/blocks/block-coauthor-name/edit.js index 4f552a41..309f0f52 100644 --- a/src/blocks/block-coauthor-name/edit.js +++ b/src/blocks/block-coauthor-name/edit.js @@ -9,9 +9,14 @@ import { InspectorControls, AlignmentControl, BlockControls, - store as blockEditorStore + store as blockEditorStore, } from '@wordpress/block-editor'; -import { TextControl, PanelBody, ToggleControl, SelectControl } from '@wordpress/components'; +import { + TextControl, + PanelBody, + ToggleControl, + SelectControl, +} from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import classnames from 'classnames'; @@ -25,77 +30,90 @@ import classnames from 'classnames'; * @return {WPElement} Element to render. */ export default function Edit( { context, attributes, setAttributes } ) { - const { isLink, rel, tagName, textAlign } = attributes; - const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []); - const author = context['co-authors-plus/author'] || authorPlaceholder; + const authorPlaceholder = useSelect( + ( select ) => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), + [] + ); + const author = context[ 'co-authors-plus/author' ] || authorPlaceholder; const { link, display_name } = author; const TagName = tagName; return ( <> - - { - setAttributes( { textAlign: nextAlign } ); - } } - /> - - - { - isLink ? ( + + { + setAttributes( { textAlign: nextAlign } ); + } } + /> + + + { isLink ? ( event.preventDefault() } > { display_name } - ) : display_name - } - - - - + + + setAttributes( { isLink: ! isLink } ) } + checked={ isLink } + /> + { isLink && ( + <> + + setAttributes( { rel: newRel } ) + } + /> + + ) } + + + + setAttributes( { isLink: ! isLink } ) } - checked={ isLink } + label={ __( 'HTML element', 'co-authors-plus' ) } + options={ [ + { label: __( 'Default (

)' ), value: 'p' }, + { label: '', value: 'span' }, + { label: '

', value: 'h1' }, + { label: '

', value: 'h2' }, + { label: '

', value: 'h3' }, + { label: '

', value: 'h4' }, + { label: '

', value: 'h5' }, + { label: '
', value: 'h6' }, + ] } + value={ tagName } + onChange={ ( value ) => + setAttributes( { tagName: value } ) + } /> - { isLink && ( - <> - - setAttributes( { rel: newRel } ) - } - /> - - ) } - - - - )' ), value: 'p' }, - { label: '', value: 'span' }, - { label: '

', value: 'h1' }, - { label: '

', value: 'h2' }, - { label: '

', value: 'h3' }, - { label: '

', value: 'h4' }, - { label: '

', value: 'h5' }, - { label: '
', value: 'h6' }, - ] } - value={ tagName } - onChange={ (value) => setAttributes( {tagName: value}) } - /> - + ); } diff --git a/src/blocks/block-coauthor-name/index.js b/src/blocks/block-coauthor-name/index.js index f059437a..1a50659e 100644 --- a/src/blocks/block-coauthor-name/index.js +++ b/src/blocks/block-coauthor-name/index.js @@ -22,5 +22,5 @@ registerBlockType( metadata.name, { * @see ./edit.js */ edit: Edit, - icon + icon, } ); diff --git a/src/blocks/block-coauthors/block.json b/src/blocks/block-coauthors/block.json index d882d73f..c5251d14 100644 --- a/src/blocks/block-coauthors/block.json +++ b/src/blocks/block-coauthors/block.json @@ -28,7 +28,7 @@ "spacing": { "margin": true, "padding": true, - "blockGap": ["vertical"], + "blockGap": [ "vertical" ], "__experimentalDefaultControls": { "margin": false, "padding": false, diff --git a/src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js b/src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js index 40913f53..bf0e9d0a 100644 --- a/src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js +++ b/src/blocks/block-coauthors/components/memoized-coauthor-template-block-preview.js @@ -4,13 +4,12 @@ import { __experimentalUseBlockPreview as useBlockPreview } from '@wordpress/blo /** * CoAuthor Template Block Preview */ -function CoAuthorTemplateBlockPreview({ +function CoAuthorTemplateBlockPreview( { blocks, blockContextId, isHidden, setActiveBlockContextId, -}) { - +} ) { const blockPreviewProps = useBlockPreview( { blocks, props: { diff --git a/src/blocks/block-coauthors/edit.js b/src/blocks/block-coauthors/edit.js index 10739fe3..2687e0bc 100644 --- a/src/blocks/block-coauthors/edit.js +++ b/src/blocks/block-coauthors/edit.js @@ -13,7 +13,7 @@ import { InspectorControls, RichText, __experimentalGetGapCSSValue, - AlignmentControl + AlignmentControl, } from '@wordpress/block-editor'; import { TextControl, ToolbarGroup, PanelBody } from '@wordpress/components'; import apiFetch from '@wordpress/api-fetch'; @@ -29,18 +29,18 @@ import MemoizedCoAuthorTemplateBlockPreview from './components/memoized-coauthor /** * CoAuthor Template Inner Blocks */ -function CoAuthorTemplateInnerBlocks () { - return
; +function CoAuthorTemplateInnerBlocks() { + return ( +
+ ); } -const ALLOWED_FORMATS = [ - 'core/bold', - 'core/italic', - 'core/text-color', -]; +const ALLOWED_FORMATS = [ 'core/bold', 'core/italic', 'core/text-color' ]; /** * The edit function describes the structure of your block in the context of the @@ -50,16 +50,25 @@ const ALLOWED_FORMATS = [ * * @return {WPElement} Element to render. */ -export default function Edit( { attributes, setAttributes, clientId, context, isSelected } ) { - - const { prefix, separator, lastSeparator, suffix, layout, textAlign } = attributes; +export default function Edit( { + attributes, + setAttributes, + clientId, + context, + isSelected, +} ) { + const { prefix, separator, lastSeparator, suffix, layout, textAlign } = + attributes; const { postId } = context; - const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []); - const [ coAuthors, setCoAuthors ] = useState([authorPlaceholder]); + const authorPlaceholder = useSelect( + ( select ) => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), + [] + ); + const [ coAuthors, setCoAuthors ] = useState( [ authorPlaceholder ] ); const [ activeBlockContextId, setActiveBlockContextId ] = useState(); - const noticesDispatch = useDispatch('core/notices'); + const noticesDispatch = useDispatch( 'core/notices' ); - useEffect(()=>{ + useEffect( () => { if ( ! postId ) { return; } @@ -67,38 +76,40 @@ export default function Edit( { attributes, setAttributes, clientId, context, is const controller = new AbortController(); apiFetch( { - path: `/coauthors/v1/coauthors?post_id=${postId}`, - signal: controller.signal + path: `/coauthors/v1/coauthors?post_id=${ postId }`, + signal: controller.signal, } ) - .then( setCoAuthors ) - .catch( handleError ) + .then( setCoAuthors ) + .catch( handleError ); return () => { controller.abort(); - } - },[postId]); + }; + }, [ postId ] ); /** * Handle Error - * + * * @param {Error} */ function handleError( error ) { if ( 'AbortError' === error.name ) { return; } - noticesDispatch.createErrorNotice( error.message, { isDismissible: true } ); + noticesDispatch.createErrorNotice( error.message, { + isDismissible: true, + } ); } - const blocks = useSelect( (select) => { + const blocks = useSelect( ( select ) => { return select( blockEditorStore ).getBlocks( clientId ); - }); + } ); const setLayout = ( nextLayout ) => { setAttributes( { layout: { ...layout, ...nextLayout }, } ); - } + }; const layoutControls = [ { @@ -110,8 +121,7 @@ export default function Edit( { attributes, setAttributes, clientId, context, is { icon: grid, title: __( 'Block', 'co-authors-plus' ), - onClick: () => - setLayout( { type: 'block' } ), + onClick: () => setLayout( { type: 'block' } ), isActive: layout.type === 'block', }, ]; @@ -127,75 +137,81 @@ export default function Edit( { attributes, setAttributes, clientId, context, is } } /> -
- { - coAuthors && + gap: __experimentalGetGapCSSValue( + attributes?.style?.spacing?.blockGap + ), + }, + } ) } + > + { coAuthors && 'inline' === layout.type && - ( isSelected || prefix ) && - ( + ( isSelected || prefix ) && ( setAttributes( { prefix: value } ) } tagName="span" /> - ) - } - { - coAuthors && + ) } + { coAuthors && coAuthors - .map( ( author ) => { - const isHidden = author.id === ( activeBlockContextId || coAuthors[0]?.id ); - return ( - - { isHidden ? () : null } - - - ); - }) - .reduce( ( previous, current, index, all ) => ( - <> - { previous } - { - 'inline' === layout.type && - ( - - { ( lastSeparator && index === (all.length - 1) ) ? `${lastSeparator}` : `${separator}` } - - ) - } - { current } - - )) - } - { - coAuthors && + .map( ( author ) => { + const isHidden = + author.id === + ( activeBlockContextId || coAuthors[ 0 ]?.id ); + return ( + + { isHidden ? ( + + ) : null } + + + ); + } ) + .reduce( ( previous, current, index, all ) => ( + <> + { previous } + { 'inline' === layout.type && ( + + { lastSeparator && + index === all.length - 1 + ? `${ lastSeparator }` + : `${ separator }` } + + ) } + { current } + + ) ) } + { coAuthors && 'inline' === layout.type && - ( isSelected || suffix ) && - ( + ( isSelected || suffix ) && ( - ) - } + ) }
- { - 'inline' === layout.type && - ( - + { 'inline' === layout.type && ( + { setAttributes( { separator: nextValue } ); } } - help={ __( 'Enter character(s) used to separate authors.', 'co-authors-plus' ) } + help={ __( + 'Enter character(s) used to separate authors.', + 'co-authors-plus' + ) } /> { setAttributes( { lastSeparator: nextValue } ); } } - help={ __( 'Enter character(s) used to separate the last author.', 'co-authors-plus' ) } + help={ __( + 'Enter character(s) used to separate the last author.', + 'co-authors-plus' + ) } /> - - ) - } + + ) } ); diff --git a/src/blocks/block-coauthors/index.js b/src/blocks/block-coauthors/index.js index 702f20cd..d6b58a83 100644 --- a/src/blocks/block-coauthors/index.js +++ b/src/blocks/block-coauthors/index.js @@ -34,5 +34,5 @@ registerBlockType( metadata.name, { */ save, - icon + icon, } ); diff --git a/src/blocks/block-coauthors/save.js b/src/blocks/block-coauthors/save.js index 0461c4c9..a4c787b3 100644 --- a/src/blocks/block-coauthors/save.js +++ b/src/blocks/block-coauthors/save.js @@ -1,7 +1,11 @@ /** * Save */ -import { useBlockProps, InnerBlocks, __experimentalGetGapCSSValue } from '@wordpress/block-editor'; +import { + useBlockProps, + InnerBlocks, + __experimentalGetGapCSSValue, +} from '@wordpress/block-editor'; import classnames from 'classnames'; /** @@ -10,17 +14,21 @@ import classnames from 'classnames'; * @return {WPElement} Element to render. */ export default function save( { attributes } ) { - const { layout, textAlign } = attributes; const style = { - gap: 'block' === layout.type ? __experimentalGetGapCSSValue( attributes.style?.spacing?.blockGap ) : null + gap: + 'block' === layout.type + ? __experimentalGetGapCSSValue( + attributes.style?.spacing?.blockGap + ) + : null, }; - const className = classnames({ - [`is-layout-cap-${layout.type}`]: layout.type, - [`has-text-align-${ textAlign }`]: textAlign - }); + const className = classnames( { + [ `is-layout-cap-${ layout.type }` ]: layout.type, + [ `has-text-align-${ textAlign }` ]: textAlign, + } ); return (
diff --git a/src/blocks/components/placeholder-image.jsx b/src/blocks/components/placeholder-image.jsx index 6dc79e18..c6cac7f7 100644 --- a/src/blocks/components/placeholder-image.jsx +++ b/src/blocks/components/placeholder-image.jsx @@ -1,23 +1,25 @@ -import { useMemo } from "@wordpress/element"; +import { useMemo } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; /** * Encode SVG - * + * * @param {string} svgHTML * @return {string} */ function encodeSVG( svgHTML ) { - return encodeURIComponent( - svgHTML - // Strip newlines and tabs - .replace(/[\t\n\r]/gim, '') - // Condense multiple spaces - .replace(/\s\s+/g, ' ') - ) - // Encode parenthesis - .replace(/\(/g, '%28') - .replace(/\)/g, '%29'); + return ( + encodeURIComponent( + svgHTML + // Strip newlines and tabs + .replace( /[\t\n\r]/gim, '' ) + // Condense multiple spaces + .replace( /\s\s+/g, ' ' ) + ) + // Encode parenthesis + .replace( /\(/g, '%28' ) + .replace( /\)/g, '%29' ) + ); } /** @@ -28,12 +30,12 @@ function encodeSVG( svgHTML ) { */ function getPlaceholderSrc( { width, height } ) { const svg = encodeSVG( - ` - - + ` + + ` ); - return `data:image/svg+xml;charset=UTF-8,${svg}` + return `data:image/svg+xml;charset=UTF-8,${ svg }`; } /** @@ -44,17 +46,19 @@ function getPlaceholderSrc( { width, height } ) { * @return {WPElement} */ export default function PlaceholderImage( { dimensions, style, className } ) { + const src = useMemo( + () => getPlaceholderSrc( dimensions ), + [ dimensions ] + ); - const src = useMemo(() => getPlaceholderSrc(dimensions), [dimensions]); - return ( {__('Placeholder ); } From 509ce20b6fe50d812f5ea6cd3431ea73f6fe4935 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 23 Oct 2023 17:57:42 -0400 Subject: [PATCH 111/123] Add coauthors keyword for easier block search --- build/blocks/block-coauthor-avatar/block.json | 3 +++ build/blocks/block-coauthor-description/block.json | 1 + build/blocks/block-coauthor-image/block.json | 3 +++ build/blocks/block-coauthor-name/block.json | 3 +++ src/blocks/block-coauthor-avatar/block.json | 1 + src/blocks/block-coauthor-description/block.json | 2 +- src/blocks/block-coauthor-image/block.json | 1 + src/blocks/block-coauthor-name/block.json | 1 + 8 files changed, 14 insertions(+), 1 deletion(-) diff --git a/build/blocks/block-coauthor-avatar/block.json b/build/blocks/block-coauthor-avatar/block.json index 438be4ee..8adf7f7f 100644 --- a/build/blocks/block-coauthor-avatar/block.json +++ b/build/blocks/block-coauthor-avatar/block.json @@ -6,6 +6,9 @@ "title": "Co-Author Avatar", "category": "theme", "description": "Displays a small scale version of a co-author's avatar. Utilizes fallbacks from Gravatar so everyone has an avatar.", + "keywords": [ + "coauthors" + ], "supports": { "align": [ "left", diff --git a/build/blocks/block-coauthor-description/block.json b/build/blocks/block-coauthor-description/block.json index 66a8561a..50746c5a 100644 --- a/build/blocks/block-coauthor-description/block.json +++ b/build/blocks/block-coauthor-description/block.json @@ -7,6 +7,7 @@ "category": "theme", "description": "Displays a co-author's biographical description.", "keywords": [ + "coauthors", "description", "bio", "biography" diff --git a/build/blocks/block-coauthor-image/block.json b/build/blocks/block-coauthor-image/block.json index 02172277..6fbaba48 100644 --- a/build/blocks/block-coauthor-image/block.json +++ b/build/blocks/block-coauthor-image/block.json @@ -6,6 +6,9 @@ "title": "Co-Author Featured Image", "category": "theme", "description": "Uses your theme's image sizes to display a scalable avatar for a co-author with a guest author profile. Does not fallback to Gravatar images.", + "keywords": [ + "coauthors" + ], "supports": { "align": [ "left", diff --git a/build/blocks/block-coauthor-name/block.json b/build/blocks/block-coauthor-name/block.json index 4784e640..9339a948 100644 --- a/build/blocks/block-coauthor-name/block.json +++ b/build/blocks/block-coauthor-name/block.json @@ -6,6 +6,9 @@ "title": "Co-Author Name", "category": "theme", "description": "Displays a co-author's display name and optionally links to their author archive.", + "keywords": [ + "coauthors" + ], "supports": { "html": false, "color": { diff --git a/src/blocks/block-coauthor-avatar/block.json b/src/blocks/block-coauthor-avatar/block.json index df6b33a7..85788047 100644 --- a/src/blocks/block-coauthor-avatar/block.json +++ b/src/blocks/block-coauthor-avatar/block.json @@ -6,6 +6,7 @@ "title": "Co-Author Avatar", "category": "theme", "description": "Displays a small scale version of a co-author's avatar. Utilizes fallbacks from Gravatar so everyone has an avatar.", + "keywords": [ "coauthors" ], "supports": { "align": [ "left", "right", "center" ], "html": false, diff --git a/src/blocks/block-coauthor-description/block.json b/src/blocks/block-coauthor-description/block.json index 5782ce4c..3082c8e1 100644 --- a/src/blocks/block-coauthor-description/block.json +++ b/src/blocks/block-coauthor-description/block.json @@ -6,7 +6,7 @@ "title": "Co-Author Biography", "category": "theme", "description": "Displays a co-author's biographical description.", - "keywords": [ "description", "bio", "biography" ], + "keywords": [ "coauthors", "description", "bio", "biography" ], "supports": { "html": false, "color": { diff --git a/src/blocks/block-coauthor-image/block.json b/src/blocks/block-coauthor-image/block.json index 69edc190..c7c42386 100644 --- a/src/blocks/block-coauthor-image/block.json +++ b/src/blocks/block-coauthor-image/block.json @@ -6,6 +6,7 @@ "title": "Co-Author Featured Image", "category": "theme", "description": "Uses your theme's image sizes to display a scalable avatar for a co-author with a guest author profile. Does not fallback to Gravatar images.", + "keywords": [ "coauthors" ], "supports": { "align": [ "left", "right", "center", "wide", "full" ], "__experimentalBorder": { diff --git a/src/blocks/block-coauthor-name/block.json b/src/blocks/block-coauthor-name/block.json index 44270bd5..39502fe8 100644 --- a/src/blocks/block-coauthor-name/block.json +++ b/src/blocks/block-coauthor-name/block.json @@ -6,6 +6,7 @@ "title": "Co-Author Name", "category": "theme", "description": "Displays a co-author's display name and optionally links to their author archive.", + "keywords": [ "coauthors" ], "supports": { "html": false, "color": { From 954638cbc887a3835193eb16943b0191a25ba404 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 23 Oct 2023 18:03:08 -0400 Subject: [PATCH 112/123] Provide i18n of author placeholder content --- php/blocks/class-blocks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 2a5c7a61..0af43945 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -135,10 +135,10 @@ public static function enqueue_store(): void { array( 'authorPlaceholder' => array( 'id' => 0, - 'display_name' => 'FirstName LastName', + 'display_name' => __( 'FirstName LastName', 'co-authors-plus' ), 'description' => array( - 'raw' => 'Placeholder description from Co-Authors block.', - 'rendered' => '

Placeholder description from Co-Authors block.

', + 'raw' => __( 'Placeholder description from Co-Authors block.', 'co-authors-plus' ), + 'rendered' => '

' . __( 'Placeholder description from Co-Authors block.', 'co-authors-plus' ) . '

', ), 'link' => '#', 'featured_media' => 0, From 90be7a99b755ec4ed96bd7af1cb51c374c320ff0 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 23 Oct 2023 18:17:59 -0400 Subject: [PATCH 113/123] esc display_name and link, clarify render_element --- .../block-coauthor-avatar/class-block-coauthor-avatar.php | 4 ++-- .../block-coauthor-image/class-block-coauthor-image.php | 4 ++-- php/blocks/block-coauthor-name/class-block-coauthor-name.php | 4 ++-- php/blocks/templating/class-templating.php | 5 ++++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php index d1b48a6b..1d963a8e 100644 --- a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php +++ b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php @@ -52,8 +52,8 @@ public static function render_block( array $attributes, string $content, WP_Bloc return ''; } - $display_name = $author['display_name'] ?? ''; - $link = $author['link'] ?? ''; + $display_name = esc_html( $author['display_name'] ?? '' ); + $link = esc_url( $author['link'] ?? '' ); $is_link = '' !== $link && $attributes['isLink'] ?? false; $rel = $attributes['rel'] ?? ''; $size = $attributes['size'] ?? array_keys( $avatar_urls )[0]; diff --git a/php/blocks/block-coauthor-image/class-block-coauthor-image.php b/php/blocks/block-coauthor-image/class-block-coauthor-image.php index 12a9c507..ded383fa 100644 --- a/php/blocks/block-coauthor-image/class-block-coauthor-image.php +++ b/php/blocks/block-coauthor-image/class-block-coauthor-image.php @@ -48,8 +48,8 @@ public static function render_block( array $attributes, string $content, WP_Bloc } $featured_media_id = absint( $author['featured_media'] ?? 0 ); - $display_name = $author['display_name'] ?? ''; - $link = $author['link'] ?? ''; + $display_name = esc_html( $author['display_name'] ?? '' ); + $link = esc_url( $author['link'] ?? '' ); if ( 0 === $featured_media_id ) { return ''; diff --git a/php/blocks/block-coauthor-name/class-block-coauthor-name.php b/php/blocks/block-coauthor-name/class-block-coauthor-name.php index 8b31e81b..b410f6bf 100644 --- a/php/blocks/block-coauthor-name/class-block-coauthor-name.php +++ b/php/blocks/block-coauthor-name/class-block-coauthor-name.php @@ -47,8 +47,8 @@ public static function render_block( array $attributes, string $content, WP_Bloc return ''; } - $display_name = $author['display_name'] ?? ''; - $link = $author['link'] ?? ''; + $display_name = esc_html( $author['display_name'] ?? '' ); + $link = esc_url( $author['link'] ?? '' ); if ( '' === $display_name ) { return ''; diff --git a/php/blocks/templating/class-templating.php b/php/blocks/templating/class-templating.php index f4ec3ab4..31360633 100644 --- a/php/blocks/templating/class-templating.php +++ b/php/blocks/templating/class-templating.php @@ -17,7 +17,10 @@ class Templating { /** * Render Element - * + * + * @param string $name HTML element tag name. + * @param string|null $attributes HTML attributes. + * @param string|null $content Inner HTML content. * @since 3.6.0 */ public static function render_element( string $name, ?string $attributes = '', ?string $content = '' ): string { From e36b07e9d90f59cb358ec31e2a63ad46a2376f01 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 23 Oct 2023 18:28:36 -0400 Subject: [PATCH 114/123] =?UTF-8?q?Don=E2=80=99t=20misuse=20the=20406=20re?= =?UTF-8?q?sponse=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/api/endpoints/class-coauthors-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/api/endpoints/class-coauthors-controller.php b/php/api/endpoints/class-coauthors-controller.php index 1c9da7f4..6f4ff03e 100644 --- a/php/api/endpoints/class-coauthors-controller.php +++ b/php/api/endpoints/class-coauthors-controller.php @@ -150,7 +150,7 @@ public function get_item( $request ) { return new WP_Error( 'rest_unusable_data', __( 'Sorry, an unusable response was produced.', 'co-authors-plus' ), - array( 'status' => 406 ) + array( 'status' => 404 ) ); } From dd52632b80a49aea4f29471112a8665aa2f29a3d Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 30 Oct 2023 19:44:00 -0400 Subject: [PATCH 115/123] Update GET coauthors API endpoint to be public * Adds `get_authors_with_api_schema` function that returns the co-authors from the WP_REST_Server so the schema and data match the editor. * Uses that new function in the Co-Authors Block when getting the authors for a post. --- .../endpoints/class-coauthors-controller.php | 28 +-------------- .../block-coauthors/class-block-coauthors.php | 15 ++------ php/blocks/class-blocks.php | 35 +++++++++++++++++++ 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/php/api/endpoints/class-coauthors-controller.php b/php/api/endpoints/class-coauthors-controller.php index 6f4ff03e..33aaa573 100644 --- a/php/api/endpoints/class-coauthors-controller.php +++ b/php/api/endpoints/class-coauthors-controller.php @@ -82,7 +82,7 @@ public function register_coauthors_route(): void { array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permission_check' ), + 'permission_callback' => '__return_true' ), ) ); @@ -198,32 +198,6 @@ function( $author ) use ( $request ) : array { ); } - /** - * Get Items Permission Check - * - * @since 3.6.0 - * @param WP_REST_Request $request - * @return bool|WP_Error - */ - public function get_items_permission_check( WP_REST_Request $request ) { - - $post_id = $request->get_param( 'post_id' ); - - if ( current_user_can( 'edit_post', $post_id ) ) { - return true; - } - - if ( is_coauthor_for_post( get_current_user(), $post_id ) ) { - return true; - } - - return new WP_Error( - 'rest_cannot_view', - __( 'Sorry, you are not allowed to view co-authors of this post.', 'co-authors-plus' ), - array( 'status' => rest_authorization_required_code() ) - ); - } - /** * Retrieves the CoAuthor schema, conforming to JSON Schema. * diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 1f4de0af..71ae8e1d 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -9,6 +9,7 @@ namespace CoAuthors\Blocks; use WP_Block; +use CoAuthors\Blocks; /** * Block CoAuthors @@ -96,19 +97,9 @@ public static function render_block( array $attributes, string $content, WP_Bloc return ''; } - $authors = array_values( - array_filter( - array_map( - 'CoAuthors\Blocks::get_author_with_api_schema', - get_coauthors( $post_id ) - ), - function( $author ) : bool { - return ! is_null( $author ); - } - ) - ); + $authors = Blocks::get_authors_with_api_schema( $post_id ); - if ( ! is_array( $authors ) || empty( $authors ) ) { + if ( empty( $authors ) ) { return ''; } diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 0af43945..2f8abd81 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -196,4 +196,39 @@ public static function get_author_with_api_schema( $author ): ?array { return $data; } + + /** + * Get CoAuthors with API Schema + * + * Use the global WP_REST_Server to fetch co-authors for a post, + * so that it matches what a user would see in the editor. + * + * @since 3.6.0 + * @param int $post_id Post ID for querying co-authors. + * @param array $data Co-authors as returned by the REST API. + */ + public static function get_authors_with_api_schema( int $post_id ): array { + + $data = rest_get_server()->dispatch( + WP_REST_Request::from_url( + home_url( + sprintf( + '/wp-json/coauthors/v1/coauthors?post_id=%d', + $post_id + ) + ) + ) + )->get_data(); + + if ( ! is_array( $data ) ) { + return array(); + } + + // The presence of `code` indicates this is an error response. + if ( array_key_exists( 'code', $data ) ) { + return array(); + } + + return $data; + } } From f262210eed0ab6fac51a7750d8822a0712fc9f99 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 6 Nov 2023 17:46:36 -0500 Subject: [PATCH 116/123] Fix error in featured_media property for WP_User Co-authors who are WordPress users do not have a type property. So checking it to make sure they are a guest author fails. --- .../endpoints/class-coauthors-controller.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/php/api/endpoints/class-coauthors-controller.php b/php/api/endpoints/class-coauthors-controller.php index 33aaa573..7faef532 100644 --- a/php/api/endpoints/class-coauthors-controller.php +++ b/php/api/endpoints/class-coauthors-controller.php @@ -164,7 +164,17 @@ public function get_item( $request ) { * @param WP_User|stdClass $coauthor */ public static function is_coauthor( $coauthor ): bool { - return is_a( $coauthor, 'WP_User' ) || ( property_exists( $coauthor, 'type' ) && 'guest-author' === $coauthor->type ); + return is_a( $coauthor, 'WP_User' ) || self::is_guest_author( $coauthor ); + } + + /** + * Is Guest Author + * + * @since 3.6.0 + * @param WP_User|stdClass $coauthor + */ + public static function is_guest_author( $coauthor ): bool { + return property_exists( $coauthor, 'type' ) && 'guest-author' === $coauthor->type; } /** @@ -349,7 +359,11 @@ public function prepare_item_for_response( $author, $request ) { } if ( rest_is_field_included( 'featured_media', $fields ) ) { - $data['featured_media'] = (int) ( 'guest-author' === $author->type ? get_post_thumbnail_id( $author->ID ) : 0 ); + if ( self::is_guest_author( $author ) ) { + $data['featured_media'] = (int) get_post_thumbnail_id( $author->ID ); + } else { + $data['featured_media'] = 0; + } } if ( rest_is_field_included( 'user_nicename', $fields ) ) { From 972f8729b5a5a5188032a2829f52927b907e9866 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 13 Dec 2023 14:11:30 -0500 Subject: [PATCH 117/123] Address review of layout settings for avatar block - Switch from figure element to div to eliminate need for removing margin. Same as default WP avatar. - Eliminated redundant display:inline, handled by parent. - Removed alignfull and alignwide styles which are not supported. - Updated render function to correctly support vertical-align styles. --- build/blocks/block-coauthor-avatar/block.json | 2 +- .../block-coauthor-avatar/index.asset.php | 2 +- build/blocks/block-coauthor-avatar/index.js | 2 +- .../block-coauthor-avatar/style-index.css | 2 +- .../class-block-coauthor-avatar.php | 48 ++++++++++++++----- src/blocks/block-coauthor-avatar/block.json | 2 +- src/blocks/block-coauthor-avatar/edit.js | 6 +-- src/blocks/block-coauthor-avatar/style.css | 14 ------ 8 files changed, 43 insertions(+), 35 deletions(-) diff --git a/build/blocks/block-coauthor-avatar/block.json b/build/blocks/block-coauthor-avatar/block.json index 8adf7f7f..4edb4a8e 100644 --- a/build/blocks/block-coauthor-avatar/block.json +++ b/build/blocks/block-coauthor-avatar/block.json @@ -1,6 +1,6 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, + "apiVersion": 3, "name": "co-authors-plus/avatar", "version": "1.0.0", "title": "Co-Author Avatar", diff --git a/build/blocks/block-coauthor-avatar/index.asset.php b/build/blocks/block-coauthor-avatar/index.asset.php index 1105dfba..6569c982 100644 --- a/build/blocks/block-coauthor-avatar/index.asset.php +++ b/build/blocks/block-coauthor-avatar/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ce44ef6d19849cf4f628'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '5778275863c0d5c029a7'); diff --git a/build/blocks/block-coauthor-avatar/index.js b/build/blocks/block-coauthor-avatar/index.js index e29e6b02..9cacba12 100644 --- a/build/blocks/block-coauthor-avatar/index.js +++ b/build/blocks/block-coauthor-avatar/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={601:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.primitives,o=(0,t.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(l.Path,{fillRule:"evenodd",d:"M7.25 16.437a6.5 6.5 0 1 1 9.5 0V16A2.75 2.75 0 0 0 14 13.25h-4A2.75 2.75 0 0 0 7.25 16v.437Zm1.5 1.193a6.47 6.47 0 0 0 3.25.87 6.47 6.47 0 0 0 3.25-.87V16c0-.69-.56-1.25-1.25-1.25h-4c-.69 0-1.25.56-1.25 1.25v1.63ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm10-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z",clipRule:"evenodd"})),a=window.wp.i18n,n=window.wp.blockEditor,r=window.wp.components,s=window.wp.data;function i(e){let{dimensions:l,style:o,className:n}=e;const r=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:n,src:r,style:o,width:l.width,height:l.height})}var u=JSON.parse('{"u2":"co-authors-plus/avatar"}');(0,e.registerBlockType)(u.u2,{edit:function(e){var l;let{context:o,attributes:u,setAttributes:c}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=u,m=(0,s.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),g=o["co-authors-plus/author"]||m,{avatar_urls:_}=g;if(!_||0===_.length)return null;const w=Object.keys(_).map((e=>({value:e,label:`${e} x ${e}`}))),b=(0,n.__experimentalUseBorderProps)(u),f=null!==(l=_[v])&&void 0!==l?l:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("figure",(0,n.useBlockProps)(),""===f?(0,t.createElement)(i,{className:b.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...b.style}}):(0,t.createElement)("img",{style:{...b.style,verticalAlign:d},width:v,height:v,src:`${_[v]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,a.__)("Avatar Settings","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Avatar size","co-authors-plus"),value:v,options:w,onChange:e=>{c({size:Number(e)})}}),(0,t.createElement)(r.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive.","co-authors-plus"),onChange:()=>c({isLink:!h}),checked:h}),h&&(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})),(0,t.createElement)(r.PanelBody,{initialOpen:!1,title:(0,a.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Vertical align","co-authors-plus"),value:d,options:[{value:"",label:(0,a.__)("Default","co-authors-plus")},{value:"baseline",label:(0,a.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,a.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,a.__)("Middle","co-authors-plus")},{value:"sub",label:(0,a.__)("Sub","co-authors-plus")},{value:"super",label:(0,a.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,a.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,a.__)("Text Top","co-authors-plus")},{value:"top",label:(0,a.__)("Top","co-authors-plus")}],onChange:e=>{c({verticalAlign:""===e?void 0:e})},help:(0,a.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:o})}},l={};function o(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.m=t,e=[],o.O=function(t,l,a,n){if(!l){var r=1/0;for(c=0;c=n)&&Object.keys(o.O).every((function(e){return o.O[e](l[i])}))?l.splice(i--,1):(s=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[l,a,n]},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,r=l[0],s=l[1],i=l[2],u=0;if(r.some((function(t){return 0!==e[t]}))){for(a in s)o.o(s,a)&&(o.m[a]=s[a]);if(i)var c=i(o)}for(t&&t(l);ufunction(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:n,src:r,style:o,width:l.width,height:l.height})}var u=JSON.parse('{"u2":"co-authors-plus/avatar"}');(0,e.registerBlockType)(u.u2,{edit:function(e){var l;let{context:o,attributes:u,setAttributes:c}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=u,m=(0,s.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),g=o["co-authors-plus/author"]||m,{avatar_urls:_}=g;if(!_||0===_.length)return null;const w=Object.keys(_).map((e=>({value:e,label:`${e} x ${e}`}))),b=(0,n.__experimentalUseBorderProps)(u),f=null!==(l=_[v])&&void 0!==l?l:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,n.useBlockProps)(),""===f?(0,t.createElement)(i,{className:b.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...b.style}}):(0,t.createElement)("img",{style:{...b.style,verticalAlign:d},width:v,height:v,src:`${_[v]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,a.__)("Avatar Settings","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Avatar size","co-authors-plus"),value:v,options:w,onChange:e=>{c({size:Number(e)})}}),(0,t.createElement)(r.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive.","co-authors-plus"),onChange:()=>c({isLink:!h}),checked:h}),h&&(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})),(0,t.createElement)(r.PanelBody,{initialOpen:!1,title:(0,a.__)("Co-Authors Layout","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Vertical align","co-authors-plus"),value:d,options:[{value:"",label:(0,a.__)("Default","co-authors-plus")},{value:"baseline",label:(0,a.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,a.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,a.__)("Middle","co-authors-plus")},{value:"sub",label:(0,a.__)("Sub","co-authors-plus")},{value:"super",label:(0,a.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,a.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,a.__)("Text Top","co-authors-plus")},{value:"top",label:(0,a.__)("Top","co-authors-plus")}],onChange:e=>{c({verticalAlign:""===e?void 0:e})},help:(0,a.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:o})}},l={};function o(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.m=t,e=[],o.O=function(t,l,a,n){if(!l){var r=1/0;for(c=0;c=n)&&Object.keys(o.O).every((function(e){return o.O[e](l[i])}))?l.splice(i--,1):(s=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[l,a,n]},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,r=l[0],s=l[1],i=l[2],u=0;if(r.some((function(t){return 0!==e[t]}))){for(a in s)o.o(s,a)&&(o.m[a]=s[a]);if(i)var c=i(o)}for(t&&t(l);u $avatar_urls[ $size ], - 'width' => $size, - 'height' => $size, - 'sizes' => "{$size}px", - 'srcset' => implode( ', ', $srcset ), - ) - ) + $image_attributes = array_merge( + array( + 'src' => $avatar_urls[ $size ], + 'width' => $size, + 'height' => $size, + 'sizes' => "{$size}px", + 'srcset' => implode( ', ', $srcset ), + 'style' => '', + 'class' => '' + ), + get_block_core_post_featured_image_border_attributes( $attributes ), + ); + + $style_attribute_key_map = array( + 'verticalAlign' => 'vertical-align', ); + $styles = array_map( + function( string $key, string $style ) use ( $attributes ) : string { + if ( empty( $attributes[ $key ] ) ) { + return ''; + } + return sprintf( + '%s;', + safecss_filter_attr( + "{$style}:{$attributes[$key]}" + ) + ); + }, + array_keys( $style_attribute_key_map ), + array_values( $style_attribute_key_map ) + ); + + $image_attributes['style'] .= implode( '', $styles ); + $image = Templating::render_self_closing_element( 'img', - $image_attributes + Templating::render_attributes( $image_attributes ) ); if ( $is_link ) { @@ -98,7 +120,7 @@ function( $size, $url ) { } return Templating::render_element( - 'figure', + 'div', get_block_wrapper_attributes(), $inner_content ); diff --git a/src/blocks/block-coauthor-avatar/block.json b/src/blocks/block-coauthor-avatar/block.json index 85788047..999cb924 100644 --- a/src/blocks/block-coauthor-avatar/block.json +++ b/src/blocks/block-coauthor-avatar/block.json @@ -1,6 +1,6 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, + "apiVersion": 3, "name": "co-authors-plus/avatar", "version": "1.0.0", "title": "Co-Author Avatar", diff --git a/src/blocks/block-coauthor-avatar/edit.js b/src/blocks/block-coauthor-avatar/edit.js index 46dfee66..8bd814f1 100644 --- a/src/blocks/block-coauthor-avatar/edit.js +++ b/src/blocks/block-coauthor-avatar/edit.js @@ -49,7 +49,7 @@ export default function Edit( { context, attributes, setAttributes } ) { return ( <> -
+
{ '' === src ? ( ) } -
+
Date: Wed, 13 Dec 2023 14:13:05 -0500 Subject: [PATCH 118/123] Update layout icons for Co-Authors Block --- src/blocks/block-coauthors/edit.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/blocks/block-coauthors/edit.js b/src/blocks/block-coauthors/edit.js index 2687e0bc..846f1977 100644 --- a/src/blocks/block-coauthors/edit.js +++ b/src/blocks/block-coauthors/edit.js @@ -20,7 +20,7 @@ import apiFetch from '@wordpress/api-fetch'; import { useSelect, useDispatch } from '@wordpress/data'; import { useState, useEffect } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; -import { list, grid } from '@wordpress/icons'; +import { row, stack } from '@wordpress/icons'; import classnames from 'classnames'; @@ -113,13 +113,13 @@ export default function Edit( { const layoutControls = [ { - icon: list, + icon: row, title: __( 'Inline', 'co-authors-plus' ), onClick: () => setLayout( { type: 'inline' } ), isActive: layout.type === 'inline', }, { - icon: grid, + icon: stack, title: __( 'Block', 'co-authors-plus' ), onClick: () => setLayout( { type: 'block' } ), isActive: layout.type === 'block', From fbacc98570e23cf9b399d5cc6850572533d1e93d Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 13 Dec 2023 14:15:45 -0500 Subject: [PATCH 119/123] Address apiVersion and naming convention feedback - Updated all blocks to use apiVersion 3. - Updated use of `Co-Authors` for consistency. - Updated readme for consistency with block UI. --- README.md | 2 +- build/blocks/block-coauthor-avatar/style-index.css | 2 +- build/blocks/block-coauthor-description/block.json | 2 +- build/blocks/block-coauthor-image/index.asset.php | 2 +- build/blocks/block-coauthor-image/index.js | 2 +- build/blocks/block-coauthor-name/block.json | 2 +- build/blocks/block-coauthors/block.json | 2 +- build/blocks/block-coauthors/index.asset.php | 2 +- build/blocks/block-coauthors/index.js | 2 +- src/blocks/block-coauthor-description/block.json | 2 +- src/blocks/block-coauthor-image/edit.js | 2 +- src/blocks/block-coauthor-name/block.json | 2 +- src/blocks/block-coauthors/block.json | 2 +- src/blocks/block-coauthors/edit.js | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d9d4004d..e7508dc6 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ This block outputs the biographical information for a co-author based on either The content is wrapped in paragraph elements using `wpautop` and is escaped using `wp_kses_post`. -### Co-Author Image +### Co-Author Featured Image This block requires the use of Guest Authors. Because guest author avatars are uploaded to the WordPress media library, there are more options for displaying these images. diff --git a/build/blocks/block-coauthor-avatar/style-index.css b/build/blocks/block-coauthor-avatar/style-index.css index 0a769f9c..e30ac813 100644 --- a/build/blocks/block-coauthor-avatar/style-index.css +++ b/build/blocks/block-coauthor-avatar/style-index.css @@ -1 +1 @@ -.wp-block-co-authors-plus-avatar{margin-bottom:0}.wp-block-co-authors-plus-avatar :where(img){height:auto;max-width:100%;vertical-align:bottom}.wp-block-co-authors-plus-coauthors.is-layout-cap-inline .wp-block-co-authors-plus-avatar :where(img){vertical-align:middle}.wp-block-co-authors-plus-avatar:is(.alignfull,.alignwide) :where(img){width:100%}.wp-block-co-authors-plus-avatar:is(.alignleft,.alignright,.aligncenter){display:table} +.wp-block-co-authors-plus-avatar :where(img){height:auto;max-width:100%;vertical-align:bottom}.wp-block-co-authors-plus-coauthors.is-layout-cap-inline .wp-block-co-authors-plus-avatar :where(img){vertical-align:middle}.wp-block-co-authors-plus-avatar:is(.alignleft,.alignright,.aligncenter){display:table} diff --git a/build/blocks/block-coauthor-description/block.json b/build/blocks/block-coauthor-description/block.json index 50746c5a..332bac0b 100644 --- a/build/blocks/block-coauthor-description/block.json +++ b/build/blocks/block-coauthor-description/block.json @@ -1,6 +1,6 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, + "apiVersion": 3, "name": "co-authors-plus/description", "version": "1.0.0", "title": "Co-Author Biography", diff --git a/build/blocks/block-coauthor-image/index.asset.php b/build/blocks/block-coauthor-image/index.asset.php index 705b3986..a3e1e0e8 100644 --- a/build/blocks/block-coauthor-image/index.asset.php +++ b/build/blocks/block-coauthor-image/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '51e049dab7cf7dd36c96'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2f63fdbfb2b1caab2a26'); diff --git a/build/blocks/block-coauthor-image/index.js b/build/blocks/block-coauthor-image/index.js index 856fb44f..2155e69b 100644 --- a/build/blocks/block-coauthor-image/index.js +++ b/build/blocks/block-coauthor-image/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={62:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.primitives,a=(0,t.createElement)(l.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,t.createElement)(l.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z"})),o=window.wp.i18n,i=window.wp.blockEditor,n=window.wp.components,r=window.wp.data,s=window.wp.coreData;const c=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"cover",label:(0,o._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"contain",label:(0,o._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"fill",label:(0,o._x)("Fill","Scale option for Image dimension control")})),u="cover",h={cover:(0,o.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,o.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,o.__)("Image will be stretched and distorted to completely fill the space.")};var p=e=>{let{clientId:l,attributes:{aspectRatio:a,width:r,height:s,scale:p,sizeSlug:m},setAttributes:g,imageSizeOptions:d=[]}=e;const _=(0,n.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||g({[e]:l<0?"0":t})},w=(0,o._x)("Scale","Image scaling options"),b=s||a&&"auto"!==a;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!a,label:(0,o.__)("Aspect ratio"),onDeselect:()=>g({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Aspect ratio"),value:a,options:[{label:(0,o.__)("Original"),value:"auto"},{label:(0,o.__)("Square"),value:"1"},{label:(0,o.__)("16:9"),value:"16/9"},{label:(0,o.__)("4:3"),value:"4/3"},{label:(0,o.__)("3:2"),value:"3/2"},{label:(0,o.__)("9:16"),value:"9/16"},{label:(0,o.__)("3:4"),value:"3/4"},{label:(0,o.__)("2:3"),value:"2/3"}],onChange:e=>g({aspectRatio:e})})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!s,label:(0,o.__)("Height"),onDeselect:()=>g({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Height"),labelPosition:"top",value:s||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!r,label:(0,o.__)("Width"),onDeselect:()=>g({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Width"),labelPosition:"top",value:r||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!p&&p!==u,label:w,onDeselect:()=>g({scale:u}),resetAllFilter:()=>({scale:u}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:p,help:h[p],onChange:e=>g({scale:e}),isBlock:!0},c)),!!d.length&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,o.__)("Resolution"),onDeselect:()=>g({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Resolution"),value:m||"full",options:d,onChange:e=>g({sizeSlug:e}),help:(0,o.__)("Select the size of the source image.")})))};function m(e){let{dimensions:l,style:a,className:i}=e;const n=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,o.__)("Placeholder image"),className:i,src:n,style:a,width:l.width,height:l.height})}function g(e,t){var l,a;return null==e||null===(l=e.media_details)||void 0===l||null===(a=l.sizes[t])||void 0===a?void 0:a.source_url}var d=JSON.parse('{"u2":"co-authors-plus/image"}');(0,e.registerBlockType)(d.u2,{edit:function(e){let{attributes:l,setAttributes:a,context:c,clientId:u}=e;const{aspectRatio:h,height:d,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=l,S=(0,r.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),E=c["co-authors-plus/author"]||S,C=(0,r.useSelect)((e=>0!==E.featured_media&&e(s.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,r.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),B=function(e,t,l){if(e&&"full"===l)return l;const a=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),a=Object.keys(t);return Array.from(new Set([...l.filter((e=>a.includes(e)))]))}(e,t);return l&&a.includes(l)?l:a[Math.max(0,a.length-1)]}(C,k,b),O=function(e,t,l){if(!e)return{};const a=e.media_details.sizes[l];if("full"===l)return{width:a.width,height:a.height};const o=t[l];if(!0===o.crop||o.width===o.height)return{width:o.width,height:o.height};const i=a.width/a.height;return o.width>o.height?{width:o.width,height:o.width/i}:{width:o.height*i,height:o.height}}(C,k,B),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,B),T=(0,i.__experimentalUseBorderProps)(l),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(p,{clientId:u,attributes:l,setAttributes:a,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,o.__)("Author featured image","co-authors-plus"),className:T.className,src:g(C,B),style:{width:!x&&d?"auto":x,height:!d&&x?"auto":d,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style},width:O.width,height:O.height}):(0,t.createElement)(m,{className:T.className,dimensions:A,style:{width:!x&&d?"auto":x,height:!d&&x?"auto":d,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:(0,o.__)("Image Settings","co-authors-plus")},(0,t.createElement)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>a({isLink:!_}),checked:_}),_&&(0,t.createElement)(n.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel","co-authors-plus"),value:v,onChange:e=>a({rel:e})})),(0,t.createElement)(n.PanelBody,{initialOpen:!1,title:(0,o.__)("Co-authors Layout","co-authors-plus")},(0,t.createElement)(n.SelectControl,{label:(0,o.__)("Vertical align","co-authors-plus"),value:f,options:[{value:"",label:(0,o.__)("Default","co-authors-plus")},{value:"baseline",label:(0,o.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,o.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,o.__)("Middle","co-authors-plus")},{value:"sub",label:(0,o.__)("Sub","co-authors-plus")},{value:"super",label:(0,o.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,o.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,o.__)("Text Top","co-authors-plus")},{value:"top",label:(0,o.__)("Top","co-authors-plus")}],onChange:e=>{a({verticalAlign:""===e?void 0:e})},help:(0,o.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:a})}},l={};function a(e){var o=l[e];if(void 0!==o)return o.exports;var i=l[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=function(t,l,o,i){if(!l){var n=1/0;for(u=0;u=i)&&Object.keys(a.O).every((function(e){return a.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[l,o,i]},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={461:0,286:0};a.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,i,n=l[0],r=l[1],s=l[2],c=0;if(n.some((function(t){return 0!==e[t]}))){for(o in r)a.o(r,o)&&(a.m[o]=r[o]);if(s)var u=s(a)}for(t&&t(l);c{let{clientId:l,attributes:{aspectRatio:a,width:r,height:s,scale:p,sizeSlug:m},setAttributes:g,imageSizeOptions:d=[]}=e;const _=(0,n.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||g({[e]:l<0?"0":t})},w=(0,o._x)("Scale","Image scaling options"),b=s||a&&"auto"!==a;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!a,label:(0,o.__)("Aspect ratio"),onDeselect:()=>g({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Aspect ratio"),value:a,options:[{label:(0,o.__)("Original"),value:"auto"},{label:(0,o.__)("Square"),value:"1"},{label:(0,o.__)("16:9"),value:"16/9"},{label:(0,o.__)("4:3"),value:"4/3"},{label:(0,o.__)("3:2"),value:"3/2"},{label:(0,o.__)("9:16"),value:"9/16"},{label:(0,o.__)("3:4"),value:"3/4"},{label:(0,o.__)("2:3"),value:"2/3"}],onChange:e=>g({aspectRatio:e})})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!s,label:(0,o.__)("Height"),onDeselect:()=>g({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Height"),labelPosition:"top",value:s||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!r,label:(0,o.__)("Width"),onDeselect:()=>g({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Width"),labelPosition:"top",value:r||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!p&&p!==u,label:w,onDeselect:()=>g({scale:u}),resetAllFilter:()=>({scale:u}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:p,help:h[p],onChange:e=>g({scale:e}),isBlock:!0},c)),!!d.length&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,o.__)("Resolution"),onDeselect:()=>g({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Resolution"),value:m||"full",options:d,onChange:e=>g({sizeSlug:e}),help:(0,o.__)("Select the size of the source image.")})))};function m(e){let{dimensions:l,style:a,className:i}=e;const n=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,o.__)("Placeholder image"),className:i,src:n,style:a,width:l.width,height:l.height})}function g(e,t){var l,a;return null==e||null===(l=e.media_details)||void 0===l||null===(a=l.sizes[t])||void 0===a?void 0:a.source_url}var d=JSON.parse('{"u2":"co-authors-plus/image"}');(0,e.registerBlockType)(d.u2,{edit:function(e){let{attributes:l,setAttributes:a,context:c,clientId:u}=e;const{aspectRatio:h,height:d,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=l,S=(0,r.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),E=c["co-authors-plus/author"]||S,C=(0,r.useSelect)((e=>0!==E.featured_media&&e(s.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,r.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),B=function(e,t,l){if(e&&"full"===l)return l;const a=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),a=Object.keys(t);return Array.from(new Set([...l.filter((e=>a.includes(e)))]))}(e,t);return l&&a.includes(l)?l:a[Math.max(0,a.length-1)]}(C,k,b),O=function(e,t,l){if(!e)return{};const a=e.media_details.sizes[l];if("full"===l)return{width:a.width,height:a.height};const o=t[l];if(!0===o.crop||o.width===o.height)return{width:o.width,height:o.height};const i=a.width/a.height;return o.width>o.height?{width:o.width,height:o.width/i}:{width:o.height*i,height:o.height}}(C,k,B),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,B),T=(0,i.__experimentalUseBorderProps)(l),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(p,{clientId:u,attributes:l,setAttributes:a,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,o.__)("Author featured image","co-authors-plus"),className:T.className,src:g(C,B),style:{width:!x&&d?"auto":x,height:!d&&x?"auto":d,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style},width:O.width,height:O.height}):(0,t.createElement)(m,{className:T.className,dimensions:A,style:{width:!x&&d?"auto":x,height:!d&&x?"auto":d,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:(0,o.__)("Image Settings","co-authors-plus")},(0,t.createElement)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>a({isLink:!_}),checked:_}),_&&(0,t.createElement)(n.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel","co-authors-plus"),value:v,onChange:e=>a({rel:e})})),(0,t.createElement)(n.PanelBody,{initialOpen:!1,title:(0,o.__)("Co-Authors Layout","co-authors-plus")},(0,t.createElement)(n.SelectControl,{label:(0,o.__)("Vertical align","co-authors-plus"),value:f,options:[{value:"",label:(0,o.__)("Default","co-authors-plus")},{value:"baseline",label:(0,o.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,o.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,o.__)("Middle","co-authors-plus")},{value:"sub",label:(0,o.__)("Sub","co-authors-plus")},{value:"super",label:(0,o.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,o.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,o.__)("Text Top","co-authors-plus")},{value:"top",label:(0,o.__)("Top","co-authors-plus")}],onChange:e=>{a({verticalAlign:""===e?void 0:e})},help:(0,o.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:a})}},l={};function a(e){var o=l[e];if(void 0!==o)return o.exports;var i=l[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=function(t,l,o,i){if(!l){var n=1/0;for(u=0;u=i)&&Object.keys(a.O).every((function(e){return a.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[l,o,i]},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={461:0,286:0};a.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,i,n=l[0],r=l[1],s=l[2],c=0;if(n.some((function(t){return 0!==e[t]}))){for(o in r)a.o(r,o)&&(a.m[o]=r[o]);if(s)var u=s(a)}for(t&&t(l);c array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'a2ad2bb468dc3d48a9da'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '3b48c28181cec9a66691'); diff --git a/build/blocks/block-coauthors/index.js b/build/blocks/block-coauthors/index.js index 7a12a16a..48788bd2 100644 --- a/build/blocks/block-coauthors/index.js +++ b/build/blocks/block-coauthors/index.js @@ -1 +1 @@ -!function(){var e,t={749:function(e,t,o){"use strict";var n=window.wp.blocks,r=window.wp.element,l=window.wp.primitives,a=(0,r.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(l.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})),c=window.wp.blockEditor,s=window.wp.components,i=window.wp.apiFetch,u=o.n(i),p=window.wp.data,h=window.wp.i18n,v=(0,r.createElement)(l.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(l.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),d=(0,r.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(l.Path,{d:"m3 5c0-1.10457.89543-2 2-2h13.5c1.1046 0 2 .89543 2 2v13.5c0 1.1046-.8954 2-2 2h-13.5c-1.10457 0-2-.8954-2-2zm2-.5h6v6.5h-6.5v-6c0-.27614.22386-.5.5-.5zm-.5 8v6c0 .2761.22386.5.5.5h6v-6.5zm8 0v6.5h6c.2761 0 .5-.2239.5-.5v-6zm0-8v6.5h6.5v-6c0-.27614-.2239-.5-.5-.5z",fillRule:"evenodd",clipRule:"evenodd"})),f=o(184),m=o.n(f);function w(){return w=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l(o)},i={display:n?"none":void 0};return(0,r.createElement)("div",w({},a,{tabIndex:0,role:"button",onClick:s,onKeyUp:s,style:i}))}));function g(){return(0,r.createElement)("div",(0,c.useInnerBlocksProps)({className:"wp-block-co-authors-plus-coauthor"},{template:[["co-authors-plus/name"]]}))}const y=["core/bold","core/italic","core/text-color"];var x=JSON.parse('{"u2":"co-authors-plus/coauthors"}');(0,n.registerBlockType)(x.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:l,clientId:a,context:i,isSelected:f}=e;const{prefix:w,separator:x,lastSeparator:_,suffix:k,layout:E,textAlign:C}=n,{postId:S}=i,O=(0,p.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),[A,B]=(0,r.useState)([O]),[P,z]=(0,r.useState)(),I=(0,p.useDispatch)("core/notices");function N(e){"AbortError"!==e.name&&I.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return u()({path:`/coauthors/v1/coauthors?post_id=${S}`,signal:e.signal}).then(B).catch(N),()=>{e.abort()}}),[S]);const j=(0,p.useSelect)((e=>e(c.store).getBlocks(a))),G=e=>{l({layout:{...E,...e}})},V=[{icon:v,title:(0,h.__)("Inline","co-authors-plus"),onClick:()=>G({type:"inline"}),isActive:"inline"===E.type},{icon:d,title:(0,h.__)("Block","co-authors-plus"),onClick:()=>G({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(c.BlockControls,null,(0,r.createElement)(s.ToolbarGroup,{controls:V}),(0,r.createElement)(c.AlignmentControl,{value:C,onChange:e=>{l({textAlign:e})}})),(0,r.createElement)("div",(0,c.useBlockProps)({className:m()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,c.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),A&&"inline"===E.type&&(f||w)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__prefix",multiline:!1,"aria-label":(0,h.__)("Prefix","co-authors-plus"),placeholder:(0,h.__)("Prefix","co-authors-plus")+" ",value:w,onChange:e=>l({prefix:e}),tagName:"span"}),A&&A.map((e=>{var t;const o=e.id===(P||(null===(t=A[0])||void 0===t?void 0:t.id));return(0,r.createElement)(c.BlockContextProvider,{key:e.id,value:{"co-authors-plus/author":e}},o?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:z,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-co-authors-plus-coauthors__separator"},_&&o===n.length-1?`${_}`:`${x}`),t))),A&&"inline"===E.type&&(f||k)&&(0,r.createElement)(c.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__suffix",multiline:!1,"aria-label":(0,h.__)("Suffix"),placeholder:(0,h.__)("Suffix")+" ",value:k,onChange:e=>l({suffix:e}),tagName:"span"})),(0,r.createElement)(c.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(s.PanelBody,{title:(0,h.__)("Co-authors Layout","co-authors-plus")},(0,r.createElement)(s.TextControl,{autoComplete:"off",label:(0,h.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{l({separator:e})},help:(0,h.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(s.TextControl,{autoComplete:"off",label:(0,h.__)("Last Separator","co-authors-plus"),value:_||"",onChange:e=>{l({lastSeparator:e})},help:(0,h.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:l,textAlign:a}=n,s={gap:"block"===l.type?(0,c.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},i=m()({[`is-layout-cap-${l.type}`]:l.type,[`has-text-align-${a}`]:a});return(0,r.createElement)("div",c.useBlockProps.save({className:i,style:s}),(0,r.createElement)(c.InnerBlocks.Content,null))},icon:a})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=l)&&Object.keys(n.O).every((function(e){return n.O[e](o[s])}))?o.splice(s--,1):(c=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[o,r,l]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,l,a=o[0],c=o[1],s=o[2],i=0;if(a.some((function(t){return 0!==e[t]}))){for(r in c)n.o(c,r)&&(n.m[r]=c[r]);if(s)var u=s(n)}for(t&&t(o);i{a(o)},i={display:n?"none":void 0};return(0,r.createElement)("div",w({},l,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:i}))}));function g(){return(0,r.createElement)("div",(0,s.useInnerBlocksProps)({className:"wp-block-co-authors-plus-coauthor"},{template:[["co-authors-plus/name"]]}))}const y=["core/bold","core/italic","core/text-color"];var x=JSON.parse('{"u2":"co-authors-plus/coauthors"}');(0,n.registerBlockType)(x.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:a,clientId:l,context:i,isSelected:d}=e;const{prefix:w,separator:x,lastSeparator:_,suffix:k,layout:E,textAlign:C}=n,{postId:S}=i,A=(0,p.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),[O,B]=(0,r.useState)([A]),[P,I]=(0,r.useState)(),N=(0,p.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return u()({path:`/coauthors/v1/coauthors?post_id=${S}`,signal:e.signal}).then(B).catch(V),()=>{e.abort()}}),[S]);const j=(0,p.useSelect)((e=>e(s.store).getBlocks(l))),G=e=>{a({layout:{...E,...e}})},H=[{icon:v,title:(0,h.__)("Inline","co-authors-plus"),onClick:()=>G({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,h.__)("Block","co-authors-plus"),onClick:()=>G({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(s.BlockControls,null,(0,r.createElement)(c.ToolbarGroup,{controls:H}),(0,r.createElement)(s.AlignmentControl,{value:C,onChange:e=>{a({textAlign:e})}})),(0,r.createElement)("div",(0,s.useBlockProps)({className:m()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,s.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),O&&"inline"===E.type&&(d||w)&&(0,r.createElement)(s.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__prefix",multiline:!1,"aria-label":(0,h.__)("Prefix","co-authors-plus"),placeholder:(0,h.__)("Prefix","co-authors-plus")+" ",value:w,onChange:e=>a({prefix:e}),tagName:"span"}),O&&O.map((e=>{var t;const o=e.id===(P||(null===(t=O[0])||void 0===t?void 0:t.id));return(0,r.createElement)(s.BlockContextProvider,{key:e.id,value:{"co-authors-plus/author":e}},o?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-co-authors-plus-coauthors__separator"},_&&o===n.length-1?`${_}`:`${x}`),t))),O&&"inline"===E.type&&(d||k)&&(0,r.createElement)(s.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__suffix",multiline:!1,"aria-label":(0,h.__)("Suffix"),placeholder:(0,h.__)("Suffix")+" ",value:k,onChange:e=>a({suffix:e}),tagName:"span"})),(0,r.createElement)(s.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(c.PanelBody,{title:(0,h.__)("Co-Authors Layout","co-authors-plus")},(0,r.createElement)(c.TextControl,{autoComplete:"off",label:(0,h.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{a({separator:e})},help:(0,h.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(c.TextControl,{autoComplete:"off",label:(0,h.__)("Last Separator","co-authors-plus"),value:_||"",onChange:e=>{a({lastSeparator:e})},help:(0,h.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:a,textAlign:l}=n,c={gap:"block"===a.type?(0,s.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},i=m()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${l}`]:l});return(0,r.createElement)("div",s.useBlockProps.save({className:i,style:c}),(0,r.createElement)(s.InnerBlocks.Content,null))},icon:l})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](o[c])}))?o.splice(c--,1):(s=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[o,r,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,a,l=o[0],s=o[1],c=o[2],i=0;if(l.some((function(t){return 0!==e[t]}))){for(r in s)n.o(s,r)&&(n.m[r]=s[r]);if(c)var u=c(n)}for(t&&t(o);i { 'inline' === layout.type && ( Date: Wed, 13 Dec 2023 15:02:48 -0500 Subject: [PATCH 120/123] remove errant comma to fix php 7.1 test failure --- .../block-coauthor-avatar/class-block-coauthor-avatar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php index c5cf1f8d..230ee5cd 100644 --- a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php +++ b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php @@ -76,7 +76,7 @@ function( $size, $url ) { 'style' => '', 'class' => '' ), - get_block_core_post_featured_image_border_attributes( $attributes ), + get_block_core_post_featured_image_border_attributes( $attributes ) ); $style_attribute_key_map = array( From bfd124495772c81419b87414cecad7b78bb60ca7 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Wed, 10 Jan 2024 11:17:30 -0500 Subject: [PATCH 121/123] Allow more layouts, only align where applicable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added block layout controls to the Co-Authors block. - Updated Co-Authors block CSS so the default / flow layout displays co-authors in an inline style suitable for bylines. - Added context that is passed from Co-Authors block to its descendants so controls only relevant to the inline style can be hidden when using other layouts. - Removed support for align from the block.json file of the image and avatar blocks, instead adding it manually in the block’s edit.js so it can be omitted when using the defaut layout. When using other layouts the align controls will be removed where not applicable by `useAvailableAlignments`. --- build/blocks/block-coauthor-avatar/block.json | 11 +- .../block-coauthor-avatar/index.asset.php | 2 +- build/blocks/block-coauthor-avatar/index.js | 2 +- .../block-coauthor-avatar/style-index.css | 2 +- build/blocks/block-coauthor-image/block.json | 13 +- .../block-coauthor-image/index.asset.php | 2 +- build/blocks/block-coauthor-image/index.js | 2 +- .../block-coauthor-image/style-index.css | 2 +- build/blocks/block-coauthors/block.json | 9 +- build/blocks/block-coauthors/index.asset.php | 2 +- build/blocks/block-coauthors/index.js | 2 +- build/blocks/block-coauthors/style-index.css | 2 +- .../class-block-coauthor-avatar.php | 10 +- .../class-block-coauthor-image.php | 12 +- .../block-coauthors/class-block-coauthors.php | 5 +- src/blocks/block-coauthor-avatar/block.json | 9 +- src/blocks/block-coauthor-avatar/edit.js | 140 ++++++++++-------- src/blocks/block-coauthor-avatar/style.css | 9 +- src/blocks/block-coauthor-image/block.json | 9 +- src/blocks/block-coauthor-image/edit.js | 135 ++++++++++------- src/blocks/block-coauthor-image/style.css | 13 +- src/blocks/block-coauthor-name/edit.js | 1 - src/blocks/block-coauthors/block.json | 7 +- src/blocks/block-coauthors/edit.js | 92 ++++++++---- src/blocks/block-coauthors/save.js | 15 +- src/blocks/block-coauthors/style.css | 7 +- 26 files changed, 301 insertions(+), 214 deletions(-) diff --git a/build/blocks/block-coauthor-avatar/block.json b/build/blocks/block-coauthor-avatar/block.json index 4edb4a8e..0692c654 100644 --- a/build/blocks/block-coauthor-avatar/block.json +++ b/build/blocks/block-coauthor-avatar/block.json @@ -10,11 +10,6 @@ "coauthors" ], "supports": { - "align": [ - "left", - "right", - "center" - ], "html": false, "__experimentalBorder": { "color": true, @@ -38,7 +33,8 @@ } }, "usesContext": [ - "co-authors-plus/author" + "co-authors-plus/author", + "co-authors-plus/layout" ], "attributes": { "size": { @@ -54,6 +50,9 @@ }, "verticalAlign": { "type": "string" + }, + "align": { + "type": "string" } }, "textdomain": "co-authors-plus", diff --git a/build/blocks/block-coauthor-avatar/index.asset.php b/build/blocks/block-coauthor-avatar/index.asset.php index 6569c982..b60246a1 100644 --- a/build/blocks/block-coauthor-avatar/index.asset.php +++ b/build/blocks/block-coauthor-avatar/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '5778275863c0d5c029a7'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'b6b841ac8f86f7358245'); diff --git a/build/blocks/block-coauthor-avatar/index.js b/build/blocks/block-coauthor-avatar/index.js index 9cacba12..dcf076b9 100644 --- a/build/blocks/block-coauthor-avatar/index.js +++ b/build/blocks/block-coauthor-avatar/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={601:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.primitives,o=(0,t.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(l.Path,{fillRule:"evenodd",d:"M7.25 16.437a6.5 6.5 0 1 1 9.5 0V16A2.75 2.75 0 0 0 14 13.25h-4A2.75 2.75 0 0 0 7.25 16v.437Zm1.5 1.193a6.47 6.47 0 0 0 3.25.87 6.47 6.47 0 0 0 3.25-.87V16c0-.69-.56-1.25-1.25-1.25h-4c-.69 0-1.25.56-1.25 1.25v1.63ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm10-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z",clipRule:"evenodd"})),a=window.wp.i18n,n=window.wp.blockEditor,r=window.wp.components,s=window.wp.data;function i(e){let{dimensions:l,style:o,className:n}=e;const r=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,a.__)("Placeholder image"),className:n,src:r,style:o,width:l.width,height:l.height})}var u=JSON.parse('{"u2":"co-authors-plus/avatar"}');(0,e.registerBlockType)(u.u2,{edit:function(e){var l;let{context:o,attributes:u,setAttributes:c}=e;const{isLink:h,rel:p,size:v,verticalAlign:d}=u,m=(0,s.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),g=o["co-authors-plus/author"]||m,{avatar_urls:_}=g;if(!_||0===_.length)return null;const w=Object.keys(_).map((e=>({value:e,label:`${e} x ${e}`}))),b=(0,n.__experimentalUseBorderProps)(u),f=null!==(l=_[v])&&void 0!==l?l:"";return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("div",(0,n.useBlockProps)(),""===f?(0,t.createElement)(i,{className:b.className,dimensions:{width:v,height:v},style:{height:v,width:v,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:d,...b.style}}):(0,t.createElement)("img",{style:{...b.style,verticalAlign:d},width:v,height:v,src:`${_[v]}`})),(0,t.createElement)(n.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,a.__)("Avatar Settings","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Avatar size","co-authors-plus"),value:v,options:w,onChange:e=>{c({size:Number(e)})}}),(0,t.createElement)(r.ToggleControl,{label:(0,a.__)("Make avatar a link to author archive.","co-authors-plus"),onChange:()=>c({isLink:!h}),checked:h}),h&&(0,t.createElement)(r.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Link rel","co-authors-plus"),value:p,onChange:e=>c({rel:e})})),(0,t.createElement)(r.PanelBody,{initialOpen:!1,title:(0,a.__)("Co-Authors Layout","co-authors-plus")},(0,t.createElement)(r.SelectControl,{label:(0,a.__)("Vertical align","co-authors-plus"),value:d,options:[{value:"",label:(0,a.__)("Default","co-authors-plus")},{value:"baseline",label:(0,a.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,a.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,a.__)("Middle","co-authors-plus")},{value:"sub",label:(0,a.__)("Sub","co-authors-plus")},{value:"super",label:(0,a.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,a.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,a.__)("Text Top","co-authors-plus")},{value:"top",label:(0,a.__)("Top","co-authors-plus")}],onChange:e=>{c({verticalAlign:""===e?void 0:e})},help:(0,a.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:o})}},l={};function o(e){var a=l[e];if(void 0!==a)return a.exports;var n=l[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.m=t,e=[],o.O=function(t,l,a,n){if(!l){var r=1/0;for(c=0;c=n)&&Object.keys(o.O).every((function(e){return o.O[e](l[i])}))?l.splice(i--,1):(s=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[l,a,n]},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var a,n,r=l[0],s=l[1],i=l[2],u=0;if(r.some((function(t){return 0!==e[t]}))){for(a in s)o.o(s,a)&&(o.m[a]=s[a]);if(i)var c=i(o)}for(t&&t(l);ufunction(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,n.createElement)("img",{alt:(0,i.__)("Placeholder image"),className:o,src:r,style:l,width:t.width,height:t.height})}var d=JSON.parse('{"u2":"co-authors-plus/avatar"}');(0,o.registerBlockType)(d.u2,{edit:function(e){var t;let{context:l,attributes:o,setAttributes:r}=e;const{isLink:a,rel:h,size:d,verticalAlign:g,align:f}=o,m=(0,c.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),_=l["co-authors-plus/author"]||m,w=l["co-authors-plus/layout"]||"",{avatar_urls:b}=_;if(!b||0===b.length)return null;const y=Object.keys(b).map((e=>({value:e,label:`${e} x ${e}`}))),k=(0,u.__experimentalUseBorderProps)(o),x=null!==(t=b[d])&&void 0!==t?t:"";return(0,n.createElement)(n.Fragment,null,"default"!==w?(0,n.createElement)(u.BlockControls,null,(0,n.createElement)(u.BlockAlignmentToolbar,{value:f,onChange:e=>{r({align:e})},controls:["none","left","center","right"]})):null,(0,n.createElement)("div",(0,u.useBlockProps)({className:p()({[`align${f}`]:"default"!==w&&f&&"none"!==f})}),""===x?(0,n.createElement)(v,{className:k.className,dimensions:{width:d,height:d},style:{height:d,width:d,minWidth:"auto",minHeight:"auto",padding:0,verticalAlign:g,...k.style}}):(0,n.createElement)("img",{style:{...k.style,verticalAlign:g},width:d,height:d,src:`${b[d]}`})),(0,n.createElement)(u.InspectorControls,null,(0,n.createElement)(s.PanelBody,{title:(0,i.__)("Avatar Settings","co-authors-plus")},(0,n.createElement)(s.SelectControl,{label:(0,i.__)("Avatar size","co-authors-plus"),value:d,options:y,onChange:e=>{r({size:Number(e)})}}),(0,n.createElement)(s.ToggleControl,{label:(0,i.__)("Make avatar a link to author archive.","co-authors-plus"),onChange:()=>r({isLink:!a}),checked:a}),a&&(0,n.createElement)(s.TextControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Link rel","co-authors-plus"),value:h,onChange:e=>r({rel:e})})),"default"===w?(0,n.createElement)(s.PanelBody,{initialOpen:!1,title:(0,i.__)("Co-Authors Layout","co-authors-plus")},(0,n.createElement)(s.SelectControl,{label:(0,i.__)("Vertical align","co-authors-plus"),value:g,options:[{value:"",label:(0,i.__)("Default","co-authors-plus")},{value:"baseline",label:(0,i.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,i.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,i.__)("Middle","co-authors-plus")},{value:"sub",label:(0,i.__)("Sub","co-authors-plus")},{value:"super",label:(0,i.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,i.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,i.__)("Text Top","co-authors-plus")},{value:"top",label:(0,i.__)("Top","co-authors-plus")}],onChange:e=>{r({verticalAlign:""===e?void 0:e})},help:(0,i.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")})):null))},icon:a})},184:function(e,t){var l;!function(){"use strict";var o={}.hasOwnProperty;function n(){for(var e=[],t=0;t=r)&&Object.keys(o.O).every((function(e){return o.O[e](l[u])}))?l.splice(u--,1):(i=!1,r0&&e[c-1][2]>r;c--)e[c]=e[c-1];e[c]=[l,n,r]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var l in t)o.o(t,l)&&!o.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={893:0,30:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var n,r,a=l[0],i=l[1],u=l[2],s=0;if(a.some((function(t){return 0!==e[t]}))){for(n in i)o.o(i,n)&&(o.m[n]=i[n]);if(u)var c=u(o)}for(t&&t(l);s array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2f63fdbfb2b1caab2a26'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2c80e74d7ff9efae21e8'); diff --git a/build/blocks/block-coauthor-image/index.js b/build/blocks/block-coauthor-image/index.js index 2155e69b..62ba689f 100644 --- a/build/blocks/block-coauthor-image/index.js +++ b/build/blocks/block-coauthor-image/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={62:function(){var e=window.wp.blocks,t=window.wp.element,l=window.wp.primitives,a=(0,t.createElement)(l.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,t.createElement)(l.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z"})),o=window.wp.i18n,i=window.wp.blockEditor,n=window.wp.components,r=window.wp.data,s=window.wp.coreData;const c=(0,t.createElement)(t.Fragment,null,(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"cover",label:(0,o._x)("Cover","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"contain",label:(0,o._x)("Contain","Scale option for Image dimension control")}),(0,t.createElement)(n.__experimentalToggleGroupControlOption,{value:"fill",label:(0,o._x)("Fill","Scale option for Image dimension control")})),u="cover",h={cover:(0,o.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,o.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,o.__)("Image will be stretched and distorted to completely fill the space.")};var p=e=>{let{clientId:l,attributes:{aspectRatio:a,width:r,height:s,scale:p,sizeSlug:m},setAttributes:g,imageSizeOptions:d=[]}=e;const _=(0,n.__experimentalUseCustomUnits)({availableUnits:(0,i.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||g({[e]:l<0?"0":t})},w=(0,o._x)("Scale","Image scaling options"),b=s||a&&"auto"!==a;return(0,t.createElement)(i.InspectorControls,{group:"dimensions"},(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!a,label:(0,o.__)("Aspect ratio"),onDeselect:()=>g({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Aspect ratio"),value:a,options:[{label:(0,o.__)("Original"),value:"auto"},{label:(0,o.__)("Square"),value:"1"},{label:(0,o.__)("16:9"),value:"16/9"},{label:(0,o.__)("4:3"),value:"4/3"},{label:(0,o.__)("3:2"),value:"3/2"},{label:(0,o.__)("9:16"),value:"9/16"},{label:(0,o.__)("3:4"),value:"3/4"},{label:(0,o.__)("2:3"),value:"2/3"}],onChange:e=>g({aspectRatio:e})})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!s,label:(0,o.__)("Height"),onDeselect:()=>g({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Height"),labelPosition:"top",value:s||"",min:0,onChange:e=>v("height",e),units:_})),(0,t.createElement)(n.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!r,label:(0,o.__)("Width"),onDeselect:()=>g({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalUnitControl,{label:(0,o.__)("Width"),labelPosition:"top",value:r||"",min:0,onChange:e=>v("width",e),units:_})),b&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!p&&p!==u,label:w,onDeselect:()=>g({scale:u}),resetAllFilter:()=>({scale:u}),isShownByDefault:!0,panelId:l},(0,t.createElement)(n.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:w,value:p,help:h[p],onChange:e=>g({scale:e}),isBlock:!0},c)),!!d.length&&(0,t.createElement)(n.__experimentalToolsPanelItem,{hasValue:()=>!!m,label:(0,o.__)("Resolution"),onDeselect:()=>g({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:l},(0,t.createElement)(n.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Resolution"),value:m||"full",options:d,onChange:e=>g({sizeSlug:e}),help:(0,o.__)("Select the size of the source image.")})))};function m(e){let{dimensions:l,style:a,className:i}=e;const n=(0,t.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(l)),[l]);return(0,t.createElement)("img",{alt:(0,o.__)("Placeholder image"),className:i,src:n,style:a,width:l.width,height:l.height})}function g(e,t){var l,a;return null==e||null===(l=e.media_details)||void 0===l||null===(a=l.sizes[t])||void 0===a?void 0:a.source_url}var d=JSON.parse('{"u2":"co-authors-plus/image"}');(0,e.registerBlockType)(d.u2,{edit:function(e){let{attributes:l,setAttributes:a,context:c,clientId:u}=e;const{aspectRatio:h,height:d,isLink:_,rel:v,scale:w,sizeSlug:b,verticalAlign:f,width:x}=l,S=(0,r.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),E=c["co-authors-plus/author"]||S,C=(0,r.useSelect)((e=>0!==E.featured_media&&e(s.store).getMedia(E.featured_media,{context:"view"})),[E.featured_media]),{imageSizes:y,imageDimensions:k}=(0,r.useSelect)((e=>e(i.store).getSettings()),[]),I=y.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),B=function(e,t,l){if(e&&"full"===l)return l;const a=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),a=Object.keys(t);return Array.from(new Set([...l.filter((e=>a.includes(e)))]))}(e,t);return l&&a.includes(l)?l:a[Math.max(0,a.length-1)]}(C,k,b),O=function(e,t,l){if(!e)return{};const a=e.media_details.sizes[l];if("full"===l)return{width:a.width,height:a.height};const o=t[l];if(!0===o.crop||o.width===o.height)return{width:o.width,height:o.height};const i=a.width/a.height;return o.width>o.height?{width:o.width,height:o.width/i}:{width:o.height*i,height:o.height}}(C,k,B),A=C?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(k,B),T=(0,i.__experimentalUseBorderProps)(l),N=0!==E.id&&!1===C;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(p,{clientId:u,attributes:l,setAttributes:a,imageSizeOptions:I}),N?null:(0,t.createElement)("figure",(0,i.useBlockProps)(),C?(0,t.createElement)("img",{alt:(0,o.__)("Author featured image","co-authors-plus"),className:T.className,src:g(C,B),style:{width:!x&&d?"auto":x,height:!d&&x?"auto":d,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style},width:O.width,height:O.height}):(0,t.createElement)(m,{className:T.className,dimensions:A,style:{width:!x&&d?"auto":x,height:!d&&x?"auto":d,aspectRatio:h,objectFit:w,verticalAlign:f,...T.style}})),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:(0,o.__)("Image Settings","co-authors-plus")},(0,t.createElement)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>a({isLink:!_}),checked:_}),_&&(0,t.createElement)(n.TextControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Link rel","co-authors-plus"),value:v,onChange:e=>a({rel:e})})),(0,t.createElement)(n.PanelBody,{initialOpen:!1,title:(0,o.__)("Co-Authors Layout","co-authors-plus")},(0,t.createElement)(n.SelectControl,{label:(0,o.__)("Vertical align","co-authors-plus"),value:f,options:[{value:"",label:(0,o.__)("Default","co-authors-plus")},{value:"baseline",label:(0,o.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,o.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,o.__)("Middle","co-authors-plus")},{value:"sub",label:(0,o.__)("Sub","co-authors-plus")},{value:"super",label:(0,o.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,o.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,o.__)("Text Top","co-authors-plus")},{value:"top",label:(0,o.__)("Top","co-authors-plus")}],onChange:e=>{a({verticalAlign:""===e?void 0:e})},help:(0,o.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")}))))},icon:a})}},l={};function a(e){var o=l[e];if(void 0!==o)return o.exports;var i=l[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=function(t,l,o,i){if(!l){var n=1/0;for(u=0;u=i)&&Object.keys(a.O).every((function(e){return a.O[e](l[s])}))?l.splice(s--,1):(r=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[l,o,i]},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={461:0,286:0};a.O.j=function(t){return 0===e[t]};var t=function(t,l){var o,i,n=l[0],r=l[1],s=l[2],c=0;if(n.some((function(t){return 0!==e[t]}))){for(o in r)a.o(r,o)&&(a.m[o]=r[o]);if(s)var u=s(a)}for(t&&t(l);c{let{clientId:t,attributes:{aspectRatio:l,width:o,height:a,scale:i,sizeSlug:c},setAttributes:h,imageSizeOptions:m=[]}=e;const _=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||h({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),w=a||l&&"auto"!==l;return(0,n.createElement)(s.InspectorControls,{group:"dimensions"},(0,n.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>h({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>h({aspectRatio:e})})),(0,n.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!a,label:(0,r.__)("Height"),onDeselect:()=>h({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:a||"",min:0,onChange:e=>v("height",e),units:_})),(0,n.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Width"),onDeselect:()=>h({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:o||"",min:0,onChange:e=>v("width",e),units:_})),w&&(0,n.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==g,label:f,onDeselect:()=>h({scale:g}),resetAllFilter:()=>({scale:g}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:d[i],onChange:e=>h({scale:e}),isBlock:!0},p)),!!m.length&&(0,n.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>h({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,n.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:m,onChange:e=>h({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))};function _(e){let{dimensions:t,style:l,className:o}=e;const a=(0,n.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,n.createElement)("img",{alt:(0,r.__)("Placeholder image"),className:o,src:a,style:l,width:t.width,height:t.height})}function v(e,t){var l,o;return null==e||null===(l=e.media_details)||void 0===l||null===(o=l.sizes[t])||void 0===o?void 0:o.source_url}var f=l(184),w=l.n(f),b=JSON.parse('{"u2":"co-authors-plus/image"}');(0,o.registerBlockType)(b.u2,{edit:function(e){let{attributes:t,setAttributes:l,context:o,clientId:a}=e;const{aspectRatio:i,height:p,isLink:g,rel:d,scale:f,sizeSlug:b,verticalAlign:x,width:S,align:y}=t,E=(0,c.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),C=o["co-authors-plus/author"]||E,k=o["co-authors-plus/layout"]||"",I=(0,c.useSelect)((e=>0!==C.featured_media&&e(h.store).getMedia(C.featured_media,{context:"view"})),[C.featured_media]),{imageSizes:O,imageDimensions:B}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),A=O.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),T=function(e,t,l){if(e&&"full"===l)return l;const o=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),o=Object.keys(t);return Array.from(new Set([...l.filter((e=>o.includes(e)))]))}(e,t);return l&&o.includes(l)?l:o[Math.max(0,o.length-1)]}(I,B,b),N=function(e,t,l){if(!e)return{};const o=e.media_details.sizes[l];if("full"===l)return{width:o.width,height:o.height};const n=t[l];if(!0===n.crop||n.width===n.height)return{width:n.width,height:n.height};const a=o.width/o.height;return n.width>n.height?{width:n.width,height:n.width/a}:{width:n.height*a,height:n.height}}(I,B,T),P=I?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(B,T),z=(0,s.__experimentalUseBorderProps)(t),M=0!==C.id&&!1===I;return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(m,{clientId:a,attributes:t,setAttributes:l,imageSizeOptions:A}),""===k?(0,n.createElement)(s.BlockControls,null,(0,n.createElement)(s.BlockAlignmentToolbar,{value:y,onChange:e=>{l({align:e})},controls:["none","left","center","right","wide","full"]})):null,M?null:(0,n.createElement)("figure",(0,s.useBlockProps)({className:w()({[`align${y}`]:!k&&y&&"none"!==y})}),I?(0,n.createElement)("img",{alt:(0,r.__)("Author featured image","co-authors-plus"),className:z.className,src:v(I,T),style:{width:!S&&p?"auto":S,height:!p&&S?"auto":p,aspectRatio:i,objectFit:f,verticalAlign:x,...z.style},width:N.width,height:N.height}):(0,n.createElement)(_,{className:z.className,dimensions:P,style:{width:!S&&p?"auto":S,height:!p&&S?"auto":p,aspectRatio:i,objectFit:f,verticalAlign:x,...z.style}})),(0,n.createElement)(s.InspectorControls,null,(0,n.createElement)(u.PanelBody,{title:(0,r.__)("Image Settings","co-authors-plus")},(0,n.createElement)(u.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>l({isLink:!g}),checked:g}),g&&(0,n.createElement)(u.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel","co-authors-plus"),value:d,onChange:e=>l({rel:e})})),"default"===k?(0,n.createElement)(u.PanelBody,{initialOpen:!1,title:(0,r.__)("Co-Authors Layout","co-authors-plus")},(0,n.createElement)(u.SelectControl,{label:(0,r.__)("Vertical align","co-authors-plus"),value:x,options:[{value:"",label:(0,r.__)("Default","co-authors-plus")},{value:"baseline",label:(0,r.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,r.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,r.__)("Middle","co-authors-plus")},{value:"sub",label:(0,r.__)("Sub","co-authors-plus")},{value:"super",label:(0,r.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,r.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,r.__)("Text Top","co-authors-plus")},{value:"top",label:(0,r.__)("Top","co-authors-plus")}],onChange:e=>{l({verticalAlign:""===e?void 0:e})},help:(0,r.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")})):null))},icon:i})},184:function(e,t){var l;!function(){"use strict";var o={}.hasOwnProperty;function n(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](l[s])}))?l.splice(s--,1):(r=!1,a0&&e[c-1][2]>a;c--)e[c]=e[c-1];e[c]=[l,n,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var l in t)o.o(t,l)&&!o.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={461:0,286:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var n,a,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(n in r)o.o(r,n)&&(o.m[n]=r[n]);if(s)var c=s(o)}for(t&&t(l);u array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '3b48c28181cec9a66691'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '61fe24e0599aabb66e34'); diff --git a/build/blocks/block-coauthors/index.js b/build/blocks/block-coauthors/index.js index 48788bd2..27e95b37 100644 --- a/build/blocks/block-coauthors/index.js +++ b/build/blocks/block-coauthors/index.js @@ -1 +1 @@ -!function(){var e,t={201:function(e,t,o){"use strict";var n=window.wp.blocks,r=window.wp.element,a=window.wp.primitives,l=(0,r.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(a.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})),s=window.wp.blockEditor,c=window.wp.components,i=window.wp.apiFetch,u=o.n(i),p=window.wp.data,h=window.wp.i18n,v=(0,r.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(a.Path,{d:"M4 6.5h5a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H4V16h5a.5.5 0 0 0 .5-.5v-7A.5.5 0 0 0 9 8H4V6.5Zm16 0h-5a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h5V16h-5a.5.5 0 0 1-.5-.5v-7A.5.5 0 0 1 15 8h5V6.5Z"})),f=(0,r.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(a.Path,{d:"M17.5 4v5a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2V4H8v5a.5.5 0 0 0 .5.5h7A.5.5 0 0 0 16 9V4h1.5Zm0 16v-5a2 2 0 0 0-2-2h-7a2 2 0 0 0-2 2v5H8v-5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 .5.5v5h1.5Z"})),d=o(184),m=o.n(d);function w(){return w=Object.assign?Object.assign.bind():function(e){for(var t=1;t{a(o)},i={display:n?"none":void 0};return(0,r.createElement)("div",w({},l,{tabIndex:0,role:"button",onClick:c,onKeyUp:c,style:i}))}));function g(){return(0,r.createElement)("div",(0,s.useInnerBlocksProps)({className:"wp-block-co-authors-plus-coauthor"},{template:[["co-authors-plus/name"]]}))}const y=["core/bold","core/italic","core/text-color"];var x=JSON.parse('{"u2":"co-authors-plus/coauthors"}');(0,n.registerBlockType)(x.u2,{edit:function(e){var t,o;let{attributes:n,setAttributes:a,clientId:l,context:i,isSelected:d}=e;const{prefix:w,separator:x,lastSeparator:_,suffix:k,layout:E,textAlign:C}=n,{postId:S}=i,A=(0,p.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),[O,B]=(0,r.useState)([A]),[P,I]=(0,r.useState)(),N=(0,p.useDispatch)("core/notices");function V(e){"AbortError"!==e.name&&N.createErrorNotice(e.message,{isDismissible:!0})}(0,r.useEffect)((()=>{if(!S)return;const e=new AbortController;return u()({path:`/coauthors/v1/coauthors?post_id=${S}`,signal:e.signal}).then(B).catch(V),()=>{e.abort()}}),[S]);const j=(0,p.useSelect)((e=>e(s.store).getBlocks(l))),G=e=>{a({layout:{...E,...e}})},H=[{icon:v,title:(0,h.__)("Inline","co-authors-plus"),onClick:()=>G({type:"inline"}),isActive:"inline"===E.type},{icon:f,title:(0,h.__)("Block","co-authors-plus"),onClick:()=>G({type:"block"}),isActive:"block"===E.type}];return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(s.BlockControls,null,(0,r.createElement)(c.ToolbarGroup,{controls:H}),(0,r.createElement)(s.AlignmentControl,{value:C,onChange:e=>{a({textAlign:e})}})),(0,r.createElement)("div",(0,s.useBlockProps)({className:m()({[`is-layout-cap-${E.type}`]:E.type,[`has-text-align-${C}`]:C}),style:{gap:(0,s.__experimentalGetGapCSSValue)(null==n||null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap)}}),O&&"inline"===E.type&&(d||w)&&(0,r.createElement)(s.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__prefix",multiline:!1,"aria-label":(0,h.__)("Prefix","co-authors-plus"),placeholder:(0,h.__)("Prefix","co-authors-plus")+" ",value:w,onChange:e=>a({prefix:e}),tagName:"span"}),O&&O.map((e=>{var t;const o=e.id===(P||(null===(t=O[0])||void 0===t?void 0:t.id));return(0,r.createElement)(s.BlockContextProvider,{key:e.id,value:{"co-authors-plus/author":e}},o?(0,r.createElement)(g,null):null,(0,r.createElement)(b,{blocks:j,blockContextId:e.id,setActiveBlockContextId:I,isHidden:o}))})).reduce(((e,t,o,n)=>(0,r.createElement)(r.Fragment,null,e,"inline"===E.type&&(0,r.createElement)("span",{className:"wp-block-co-authors-plus-coauthors__separator"},_&&o===n.length-1?`${_}`:`${x}`),t))),O&&"inline"===E.type&&(d||k)&&(0,r.createElement)(s.RichText,{allowedFormats:y,className:"wp-block-co-authors-plus-coauthors__suffix",multiline:!1,"aria-label":(0,h.__)("Suffix"),placeholder:(0,h.__)("Suffix")+" ",value:k,onChange:e=>a({suffix:e}),tagName:"span"})),(0,r.createElement)(s.InspectorControls,null,"inline"===E.type&&(0,r.createElement)(c.PanelBody,{title:(0,h.__)("Co-Authors Layout","co-authors-plus")},(0,r.createElement)(c.TextControl,{autoComplete:"off",label:(0,h.__)("Separator","co-authors-plus"),value:x||"",onChange:e=>{a({separator:e})},help:(0,h.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,r.createElement)(c.TextControl,{autoComplete:"off",label:(0,h.__)("Last Separator","co-authors-plus"),value:_||"",onChange:e=>{a({lastSeparator:e})},help:(0,h.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){var t,o;let{attributes:n}=e;const{layout:a,textAlign:l}=n,c={gap:"block"===a.type?(0,s.__experimentalGetGapCSSValue)(null===(t=n.style)||void 0===t||null===(o=t.spacing)||void 0===o?void 0:o.blockGap):null},i=m()({[`is-layout-cap-${a.type}`]:a.type,[`has-text-align-${l}`]:l});return(0,r.createElement)("div",s.useBlockProps.save({className:i,style:c}),(0,r.createElement)(s.InnerBlocks.Content,null))},icon:l})},184:function(e,t){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t=a)&&Object.keys(n.O).every((function(e){return n.O[e](o[c])}))?o.splice(c--,1):(s=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[o,r,a]},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};n.O.j=function(t){return 0===e[t]};var t=function(t,o){var r,a,l=o[0],s=o[1],c=o[2],i=0;if(l.some((function(t){return 0!==e[t]}))){for(r in s)n.o(s,r)&&(n.m[r]=s[r]);if(c)var u=c(n)}for(t&&t(o);i{a(o)},i={display:r?"none":void 0};return(0,n.createElement)("div",b({},l,{tabIndex:0,role:"button",onClick:s,onKeyUp:s,style:i}))}));function E(){return(0,n.createElement)("div",(0,c.useInnerBlocksProps)({className:"wp-block-co-authors-plus-coauthor"},{template:[["co-authors-plus/name"]],__unstableDisableLayoutClassNames:!0}))}const k=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"co-authors-plus/coauthors"}');(0,r.registerBlockType)(y.u2,{edit:function(e){let{attributes:t,setAttributes:o,clientId:r,context:a,isSelected:l,__unstableLayoutClassNames:i}=e;const{prefix:g,separator:b,lastSeparator:y,suffix:C,layout:S,textAlign:A}=t,{type:z,orientation:P}=S||{},{postId:B}=a,O=(0,h.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),[V,N]=(0,n.useState)([O]),[I,j]=(0,n.useState)(),H=(0,h.useDispatch)("core/notices");function G(e){"AbortError"!==e.name&&H.createErrorNotice(e.message,{isDismissible:!0})}(0,n.useEffect)((()=>{if(!B)return;const e=new AbortController;return u()({path:`/coauthors/v1/coauthors?post_id=${B}`,signal:e.signal}).then(N).catch(G),()=>{e.abort()}}),[B]);const M=(0,h.useSelect)((e=>e(c.store).getBlocks(r))),R=e=>{o({layout:e})},T=[{icon:v,title:(0,p.__)("Inline view"),onClick:()=>R({type:"default"}),isActive:"default"===z},{icon:d,title:(0,p.__)("List view"),onClick:()=>R({type:"constrained"}),isActive:"constrained"===z},{icon:m,title:(0,p.__)("Grid view"),onClick:()=>R({type:"grid"}),isActive:"grid"===z},{icon:f,title:(0,p.__)("Row view"),onClick:()=>R({type:"flex",orientation:"horizontal"}),isActive:"flex"===z&&"horizontal"===P},{icon:w,title:(0,p.__)("Stack view"),onClick:()=>R({type:"flex",orientation:"vertical"}),isActive:"flex"===z&&"vertical"===P}];return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(c.BlockControls,null,(0,n.createElement)(s.ToolbarGroup,{controls:T}),(0,n.createElement)(c.AlignmentControl,{value:A,onChange:e=>{o({textAlign:e})}})),(0,n.createElement)("div",(0,c.useBlockProps)({className:x()(i,{[`has-text-align-${A}`]:A})}),V&&"default"===z&&(l||g)&&(0,n.createElement)(c.RichText,{allowedFormats:k,className:"wp-block-co-authors-plus-coauthors__prefix",multiline:!1,"aria-label":(0,p.__)("Prefix","co-authors-plus"),placeholder:(0,p.__)("Prefix","co-authors-plus")+" ",value:g,onChange:e=>o({prefix:e}),tagName:"span"}),V&&V.map((e=>{var t;const o=e.id===(I||(null===(t=V[0])||void 0===t?void 0:t.id));return(0,n.createElement)(c.BlockContextProvider,{key:e.id,value:{"co-authors-plus/author":e,"co-authors-plus/layout":z}},o?(0,n.createElement)(E,null):null,(0,n.createElement)(_,{blocks:M,blockContextId:e.id,setActiveBlockContextId:j,isHidden:o}))})).reduce(((e,t,o,r)=>(0,n.createElement)(n.Fragment,null,e,"default"===z&&(0,n.createElement)("span",{className:"wp-block-co-authors-plus-coauthors__separator"},y&&o===r.length-1?`${y}`:`${b}`),t))),V&&"default"===z&&(l||C)&&(0,n.createElement)(c.RichText,{allowedFormats:k,className:"wp-block-co-authors-plus-coauthors__suffix",multiline:!1,"aria-label":(0,p.__)("Suffix"),placeholder:(0,p.__)("Suffix")+" ",value:C,onChange:e=>o({suffix:e}),tagName:"span"})),(0,n.createElement)(c.InspectorControls,null,"default"===z&&(0,n.createElement)(s.PanelBody,{title:(0,p.__)("Co-Authors Layout","co-authors-plus")},(0,n.createElement)(s.TextControl,{autoComplete:"off",label:(0,p.__)("Separator","co-authors-plus"),value:b||"",onChange:e=>{o({separator:e})},help:(0,p.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,n.createElement)(s.TextControl,{autoComplete:"off",label:(0,p.__)("Last Separator","co-authors-plus"),value:y||"",onChange:e=>{o({lastSeparator:e})},help:(0,p.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){let{attributes:t}=e;const{textAlign:o}=t,r=x()({[`has-text-align-${o}`]:o});return(0,n.createElement)("div",c.useBlockProps.save({className:r}),(0,n.createElement)(c.InnerBlocks.Content,null))},icon:l})},184:function(e,t){var o;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](o[s])}))?o.splice(s--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[o,n,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};r.O.j=function(t){return 0===e[t]};var t=function(t,o){var n,a,l=o[0],c=o[1],s=o[2],i=0;if(l.some((function(t){return 0!==e[t]}))){for(n in c)r.o(c,n)&&(r.m[n]=c[n]);if(s)var u=s(r)}for(t&&t(o);icontext['co-authors-plus/author'] ?? array(); + $layout = $block->context['co-authors-plus/layout'] ?? ''; if ( empty( $author ) ) { return ''; @@ -57,6 +58,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc $is_link = '' !== $link && $attributes['isLink'] ?? false; $rel = $attributes['rel'] ?? ''; $size = $attributes['size'] ?? array_keys( $avatar_urls )[0]; + $align = esc_attr( $attributes['align'] ?? '' ); $srcset = array_map( function( $size, $url ) { @@ -74,7 +76,7 @@ function( $size, $url ) { 'sizes' => "{$size}px", 'srcset' => implode( ', ', $srcset ), 'style' => '', - 'class' => '' + 'class' => '', ), get_block_core_post_featured_image_border_attributes( $attributes ) ); @@ -121,7 +123,11 @@ function( string $key, string $style ) use ( $attributes ) : string { return Templating::render_element( 'div', - get_block_wrapper_attributes(), + get_block_wrapper_attributes( + array( + 'class' => ( 'default' !== $layout && ! empty( $align ) && 'none' !== $align ) ? "align{$align}" : '' + ) + ), $inner_content ); } diff --git a/php/blocks/block-coauthor-image/class-block-coauthor-image.php b/php/blocks/block-coauthor-image/class-block-coauthor-image.php index ded383fa..0467740b 100644 --- a/php/blocks/block-coauthor-image/class-block-coauthor-image.php +++ b/php/blocks/block-coauthor-image/class-block-coauthor-image.php @@ -42,6 +42,7 @@ public static function register_block(): void { public static function render_block( array $attributes, string $content, WP_Block $block ): string { $author = $block->context['co-authors-plus/author'] ?? array(); + $layout = $block->context['co-authors-plus/layout'] ?? ''; if ( empty( $author ) ) { return ''; @@ -50,6 +51,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc $featured_media_id = absint( $author['featured_media'] ?? 0 ); $display_name = esc_html( $author['display_name'] ?? '' ); $link = esc_url( $author['link'] ?? '' ); + $align = esc_attr( $attributes['align'] ?? '' ); if ( 0 === $featured_media_id ) { return ''; @@ -122,6 +124,14 @@ function( string $key, string $style ) use ( $attributes ) : string { $inner_content = $feature_image; } - return Templating::render_element( 'figure', get_block_wrapper_attributes(), $inner_content ); + return Templating::render_element( + 'figure', + get_block_wrapper_attributes( + array( + 'class' => ( 'default' !== $layout && ! empty( $align ) && 'none' !== $align ) ? "align{$align}" : '' + ) + ), + $inner_content + ); } } diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 71ae8e1d..5456984f 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -118,7 +118,7 @@ public static function render_block( array $attributes, string $content, WP_Bloc $separators ); - if ( 'inline' === $attributes['layout']['type'] ) { + if ( 'default' === $attributes['layout']['type'] ) { array_unshift( $blocks_with_separators, self::render_prefix( $attributes['prefix'] ?? '' ) @@ -234,7 +234,7 @@ private static function get_separators( int $count, array $attributes ): array { return array(); } - if ( 'inline' !== $attributes['layout']['type'] ) { + if ( 'default' !== $attributes['layout']['type'] ) { return array(); } @@ -309,6 +309,7 @@ private static function get_template_render_function( array $block_template ): c $block_template, array( 'co-authors-plus/author' => $author, + 'co-authors-plus/layout' => $block_template['attrs']['layout']['type'] ?? 'default' ) ) )->render( diff --git a/src/blocks/block-coauthor-avatar/block.json b/src/blocks/block-coauthor-avatar/block.json index 999cb924..1963598e 100644 --- a/src/blocks/block-coauthor-avatar/block.json +++ b/src/blocks/block-coauthor-avatar/block.json @@ -8,7 +8,6 @@ "description": "Displays a small scale version of a co-author's avatar. Utilizes fallbacks from Gravatar so everyone has an avatar.", "keywords": [ "coauthors" ], "supports": { - "align": [ "left", "right", "center" ], "html": false, "__experimentalBorder": { "color": true, @@ -31,7 +30,10 @@ } } }, - "usesContext": [ "co-authors-plus/author" ], + "usesContext": [ + "co-authors-plus/author", + "co-authors-plus/layout" + ], "attributes": { "size": { "type": "number", @@ -46,6 +48,9 @@ }, "verticalAlign": { "type": "string" + }, + "align": { + "type": "string" } }, "textdomain": "co-authors-plus", diff --git a/src/blocks/block-coauthor-avatar/edit.js b/src/blocks/block-coauthor-avatar/edit.js index 8bd814f1..57f3927c 100644 --- a/src/blocks/block-coauthor-avatar/edit.js +++ b/src/blocks/block-coauthor-avatar/edit.js @@ -3,7 +3,8 @@ import { useBlockProps, InspectorControls, __experimentalUseBorderProps as useBorderProps, - store as blockEditorStore, + BlockControls, + BlockAlignmentToolbar, } from '@wordpress/block-editor'; import { SelectControl, @@ -12,6 +13,7 @@ import { TextControl, } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; +import classnames from 'classnames'; import PlaceholderImage from '../components/placeholder-image'; @@ -24,12 +26,14 @@ import PlaceholderImage from '../components/placeholder-image'; * @return {WPElement} Element to render. */ export default function Edit( { context, attributes, setAttributes } ) { - const { isLink, rel, size, verticalAlign } = attributes; + const { isLink, rel, size, verticalAlign, align } = attributes; const authorPlaceholder = useSelect( ( select ) => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), [] ); const author = context[ 'co-authors-plus/author' ] || authorPlaceholder; + const layout = context[ 'co-authors-plus/layout' ] || ''; + const { avatar_urls } = author; if ( ! avatar_urls || 0 === avatar_urls.length ) { @@ -49,7 +53,21 @@ export default function Edit( { context, attributes, setAttributes } ) { return ( <> -
+ + { 'default' !== layout ? ( + + { setAttributes({align: nextAlign}) } } controls={['none', 'left', 'center', 'right']} /> + + ) : ( + null + ) } + +
{ '' === src ? ( ) } - - { - setAttributes( { - verticalAlign: '' === value ? undefined : value, - } ); - } } - help={ __( - 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', - 'co-authors-plus' - ) } - /> - + { 'default' === layout ? ( + + { + setAttributes( { + verticalAlign: '' === value ? undefined : value, + } ); + } } + help={ __( + 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', + 'co-authors-plus' + ) } + /> + + ) : ( + null + ) } ); diff --git a/src/blocks/block-coauthor-avatar/style.css b/src/blocks/block-coauthor-avatar/style.css index 1330f54b..517ecc45 100644 --- a/src/blocks/block-coauthor-avatar/style.css +++ b/src/blocks/block-coauthor-avatar/style.css @@ -8,12 +8,17 @@ /* Inline Layout */ -.wp-block-co-authors-plus-coauthors.is-layout-cap-inline .wp-block-co-authors-plus-avatar :where(img) { +.wp-block-co-authors-plus-coauthors.is-layout-flow .wp-block-co-authors-plus-avatar :where(img) { vertical-align: middle; } /* Align left, right, center */ -.wp-block-co-authors-plus-avatar:is(.alignleft,.alignright,.aligncenter) { +.wp-block-co-authors-plus-avatar:is(.alignleft,.alignright) { display: table; } + +.wp-block-co-authors-plus-avatar.aligncenter { + display: table; + margin-inline: auto; +} diff --git a/src/blocks/block-coauthor-image/block.json b/src/blocks/block-coauthor-image/block.json index c7c42386..00ac92ec 100644 --- a/src/blocks/block-coauthor-image/block.json +++ b/src/blocks/block-coauthor-image/block.json @@ -8,7 +8,6 @@ "description": "Uses your theme's image sizes to display a scalable avatar for a co-author with a guest author profile. Does not fallback to Gravatar images.", "keywords": [ "coauthors" ], "supports": { - "align": [ "left", "right", "center", "wide", "full" ], "__experimentalBorder": { "color": true, "radius": true, @@ -30,7 +29,10 @@ } } }, - "usesContext": [ "co-authors-plus/author" ], + "usesContext": [ + "co-authors-plus/author", + "co-authors-plus/layout" + ], "attributes": { "isLink": { "type": "boolean", @@ -57,6 +59,9 @@ }, "verticalAlign": { "type": "string" + }, + "align": { + "type": "string" } }, "textdomain": "co-authors-plus", diff --git a/src/blocks/block-coauthor-image/edit.js b/src/blocks/block-coauthor-image/edit.js index 895a2746..efcf3a9c 100644 --- a/src/blocks/block-coauthor-image/edit.js +++ b/src/blocks/block-coauthor-image/edit.js @@ -8,6 +8,8 @@ import { store as blockEditorStore, __experimentalUseBorderProps as useBorderProps, InspectorControls, + BlockControls, + BlockAlignmentToolbar, } from '@wordpress/block-editor'; import { TextControl, @@ -26,6 +28,8 @@ import { getPlaceholderImageDimensions, } from './utils'; +import classnames from 'classnames'; + /** * Edit * @@ -48,6 +52,7 @@ export default function Edit( { sizeSlug, verticalAlign, width, + align } = attributes; // Author @@ -56,6 +61,7 @@ export default function Edit( { [] ); const author = context[ 'co-authors-plus/author' ] || authorPlaceholder; + const layout = context[ 'co-authors-plus/layout' ] || ''; // Media const media = useSelect( @@ -105,8 +111,19 @@ export default function Edit( { setAttributes={ setAttributes } imageSizeOptions={ imageSizeOptions } /> + { + '' === layout ? ( + + { setAttributes({align: nextAlign}) } } controls={['none', 'left', 'center', 'right', 'wide', 'full']} /> + + ) : (null) + } { panic ? null : ( -
+
{ media ? ( { ) } - - { - setAttributes( { - verticalAlign: '' === value ? undefined : value, - } ); - } } - help={ __( - 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', - 'co-authors-plus' - ) } - /> - + { 'default' === layout ? ( + + { + setAttributes( { + verticalAlign: '' === value ? undefined : value, + } ); + } } + help={ __( + 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', + 'co-authors-plus' + ) } + /> + + ) : ( + null + ) } ); diff --git a/src/blocks/block-coauthor-image/style.css b/src/blocks/block-coauthor-image/style.css index 63e2ab10..42f0d671 100644 --- a/src/blocks/block-coauthor-image/style.css +++ b/src/blocks/block-coauthor-image/style.css @@ -19,11 +19,7 @@ /* Inline Layout */ -.wp-block-co-authors-plus-coauthors.is-layout-cap-inline .wp-block-co-authors-plus-image { - display: inline; -} - -.wp-block-co-authors-plus-coauthors.is-layout-cap-inline .wp-block-co-authors-plus-image :where(img) { +.wp-block-co-authors-plus-coauthors.is-layout-flow .wp-block-co-authors-plus-image :where(img) { vertical-align: middle; } @@ -35,6 +31,11 @@ /* Align left, right, center */ -.wp-block-co-authors-plus-image:is(.alignleft,.alignright,.aligncenter) { +.wp-block-co-authors-plus-image:is(.alignleft,.alignright) { + display: table; +} + +.wp-block-co-authors-plus-image.aligncenter { display: table; + margin-inline: auto; } diff --git a/src/blocks/block-coauthor-name/edit.js b/src/blocks/block-coauthor-name/edit.js index 309f0f52..16ac3d50 100644 --- a/src/blocks/block-coauthor-name/edit.js +++ b/src/blocks/block-coauthor-name/edit.js @@ -9,7 +9,6 @@ import { InspectorControls, AlignmentControl, BlockControls, - store as blockEditorStore, } from '@wordpress/block-editor'; import { TextControl, diff --git a/src/blocks/block-coauthors/block.json b/src/blocks/block-coauthors/block.json index bdc3f264..02d35dfc 100644 --- a/src/blocks/block-coauthors/block.json +++ b/src/blocks/block-coauthors/block.json @@ -28,19 +28,20 @@ "spacing": { "margin": true, "padding": true, - "blockGap": [ "vertical" ], + "blockGap": true, "__experimentalDefaultControls": { "margin": false, "padding": false, "blockGap": false } - } + }, + "layout": true }, "attributes": { "layout": { "type": "object", "default": { - "type": "inline" + "type": "default" } }, "textAlign": { diff --git a/src/blocks/block-coauthors/edit.js b/src/blocks/block-coauthors/edit.js index 55701fc7..f83f7873 100644 --- a/src/blocks/block-coauthors/edit.js +++ b/src/blocks/block-coauthors/edit.js @@ -20,8 +20,7 @@ import apiFetch from '@wordpress/api-fetch'; import { useSelect, useDispatch } from '@wordpress/data'; import { useState, useEffect } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; -import { row, stack } from '@wordpress/icons'; - +import { row, stack, grid, list, lineDashed } from '@wordpress/icons'; import classnames from 'classnames'; import MemoizedCoAuthorTemplateBlockPreview from './components/memoized-coauthor-template-block-preview'; @@ -34,7 +33,7 @@ function CoAuthorTemplateInnerBlocks() {
); @@ -56,9 +55,11 @@ export default function Edit( { clientId, context, isSelected, + __unstableLayoutClassNames } ) { - const { prefix, separator, lastSeparator, suffix, layout, textAlign } = - attributes; + const { prefix, separator, lastSeparator, suffix, layout, textAlign } = attributes; + const { type: layoutType, orientation: layoutOrientation } = layout || {}; + const { postId } = context; const authorPlaceholder = useSelect( ( select ) => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), @@ -107,22 +108,55 @@ export default function Edit( { const setLayout = ( nextLayout ) => { setAttributes( { - layout: { ...layout, ...nextLayout }, + layout: nextLayout, } ); }; const layoutControls = [ + { + icon: lineDashed, + title: __( 'Inline view' ), + onClick: () => setLayout( { + type: 'default' + }), + isActive: layoutType === 'default' + }, + { + icon: list, + title: __( 'List view' ), + onClick: () => setLayout( { + type: 'constrained' + } ), + isActive: layoutType === 'constrained', + }, + { + icon: grid, + title: __( 'Grid view' ), + onClick: () => + setLayout( { + type: 'grid' + } ), + isActive: layoutType === 'grid', + }, { icon: row, - title: __( 'Inline', 'co-authors-plus' ), - onClick: () => setLayout( { type: 'inline' } ), - isActive: layout.type === 'inline', + title: __( 'Row view' ), + onClick: () => + setLayout( { + type: 'flex', + orientation: 'horizontal' + } ), + isActive: layoutType === 'flex' && 'horizontal' === layoutOrientation, }, { icon: stack, - title: __( 'Block', 'co-authors-plus' ), - onClick: () => setLayout( { type: 'block' } ), - isActive: layout.type === 'block', + title: __( 'Stack view' ), + onClick: () => + setLayout( { + type: 'flex', + orientation: 'vertical' + } ), + isActive: layoutType === 'flex' && 'vertical' === layoutOrientation, }, ]; @@ -138,20 +172,19 @@ export default function Edit( { />
{ coAuthors && - 'inline' === layout.type && + 'default' === layoutType && ( isSelected || prefix ) && ( { - const isHidden = - author.id === - ( activeBlockContextId || coAuthors[ 0 ]?.id ); + const isHidden = author.id === ( activeBlockContextId || coAuthors[ 0 ]?.id ); return ( { isHidden ? ( @@ -198,7 +230,7 @@ export default function Edit( { .reduce( ( previous, current, index, all ) => ( <> { previous } - { 'inline' === layout.type && ( + { 'default' === layoutType && ( { lastSeparator && index === all.length - 1 @@ -210,7 +242,7 @@ export default function Edit( { ) ) } { coAuthors && - 'inline' === layout.type && + 'default' === layoutType && ( isSelected || suffix ) && ( - { 'inline' === layout.type && ( + { 'default' === layoutType && ( diff --git a/src/blocks/block-coauthors/save.js b/src/blocks/block-coauthors/save.js index a4c787b3..0b8bda78 100644 --- a/src/blocks/block-coauthors/save.js +++ b/src/blocks/block-coauthors/save.js @@ -4,7 +4,6 @@ import { useBlockProps, InnerBlocks, - __experimentalGetGapCSSValue, } from '@wordpress/block-editor'; import classnames from 'classnames'; @@ -14,24 +13,14 @@ import classnames from 'classnames'; * @return {WPElement} Element to render. */ export default function save( { attributes } ) { - const { layout, textAlign } = attributes; - - const style = { - gap: - 'block' === layout.type - ? __experimentalGetGapCSSValue( - attributes.style?.spacing?.blockGap - ) - : null, - }; + const { textAlign } = attributes; const className = classnames( { - [ `is-layout-cap-${ layout.type }` ]: layout.type, [ `has-text-align-${ textAlign }` ]: textAlign, } ); return ( -
+
); diff --git a/src/blocks/block-coauthors/style.css b/src/blocks/block-coauthors/style.css index fa9993a4..69e11bda 100644 --- a/src/blocks/block-coauthors/style.css +++ b/src/blocks/block-coauthors/style.css @@ -1,8 +1,3 @@ -.wp-block-co-authors-plus-coauthors.is-layout-cap-inline :where(*) { +.wp-block-co-authors-plus-coauthors.is-layout-flow [class*=wp-block-co-authors-plus] { display: inline; } - -.wp-block-co-authors-plus-coauthors.is-layout-cap-block { - display: flex; - flex-direction: column; -} From 028e14aa7462ebd3da3a15e18a6ed58d28bace98 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Tue, 16 Jan 2024 18:47:44 -0500 Subject: [PATCH 122/123] Use remove-outline to see cursor in site editor While using the site editor `outlineMode` is enabled, which can obscure the cursor when hovering over the RichText field for the prefix attribute of the Co-Authors Block. The missing cursor makes it unclear you can type in the prefix field. --- build/blocks/block-coauthors/index.asset.php | 2 +- build/blocks/block-coauthors/index.js | 2 +- src/blocks/block-coauthors/edit.js | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build/blocks/block-coauthors/index.asset.php b/build/blocks/block-coauthors/index.asset.php index 4bbfa154..02276ba8 100644 --- a/build/blocks/block-coauthors/index.asset.php +++ b/build/blocks/block-coauthors/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '61fe24e0599aabb66e34'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '73645b9145fe40093212'); diff --git a/build/blocks/block-coauthors/index.js b/build/blocks/block-coauthors/index.js index 27e95b37..838f5491 100644 --- a/build/blocks/block-coauthors/index.js +++ b/build/blocks/block-coauthors/index.js @@ -1 +1 @@ -!function(){var e,t={843:function(e,t,o){"use strict";var r=window.wp.blocks,n=window.wp.element,a=window.wp.primitives,l=(0,n.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(a.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})),c=window.wp.blockEditor,s=window.wp.components,i=window.wp.apiFetch,u=o.n(i),h=window.wp.data,p=window.wp.i18n,v=(0,n.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(a.Path,{fillRule:"evenodd",d:"M5 11.25h3v1.5H5v-1.5zm5.5 0h3v1.5h-3v-1.5zm8.5 0h-3v1.5h3v-1.5z",clipRule:"evenodd"})),d=(0,n.createElement)(a.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)(a.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),m=(0,n.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(a.Path,{d:"m3 5c0-1.10457.89543-2 2-2h13.5c1.1046 0 2 .89543 2 2v13.5c0 1.1046-.8954 2-2 2h-13.5c-1.10457 0-2-.8954-2-2zm2-.5h6v6.5h-6.5v-6c0-.27614.22386-.5.5-.5zm-.5 8v6c0 .2761.22386.5.5.5h6v-6.5zm8 0v6.5h6c.2761 0 .5-.2239.5-.5v-6zm0-8v6.5h6.5v-6c0-.27614-.2239-.5-.5-.5z",fillRule:"evenodd",clipRule:"evenodd"})),f=(0,n.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(a.Path,{d:"M4 6.5h5a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H4V16h5a.5.5 0 0 0 .5-.5v-7A.5.5 0 0 0 9 8H4V6.5Zm16 0h-5a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h5V16h-5a.5.5 0 0 1-.5-.5v-7A.5.5 0 0 1 15 8h5V6.5Z"})),w=(0,n.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(a.Path,{d:"M17.5 4v5a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2V4H8v5a.5.5 0 0 0 .5.5h7A.5.5 0 0 0 16 9V4h1.5Zm0 16v-5a2 2 0 0 0-2-2h-7a2 2 0 0 0-2 2v5H8v-5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 .5.5v5h1.5Z"})),g=o(184),x=o.n(g);function b(){return b=Object.assign?Object.assign.bind():function(e){for(var t=1;t{a(o)},i={display:r?"none":void 0};return(0,n.createElement)("div",b({},l,{tabIndex:0,role:"button",onClick:s,onKeyUp:s,style:i}))}));function E(){return(0,n.createElement)("div",(0,c.useInnerBlocksProps)({className:"wp-block-co-authors-plus-coauthor"},{template:[["co-authors-plus/name"]],__unstableDisableLayoutClassNames:!0}))}const k=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"co-authors-plus/coauthors"}');(0,r.registerBlockType)(y.u2,{edit:function(e){let{attributes:t,setAttributes:o,clientId:r,context:a,isSelected:l,__unstableLayoutClassNames:i}=e;const{prefix:g,separator:b,lastSeparator:y,suffix:C,layout:S,textAlign:A}=t,{type:z,orientation:P}=S||{},{postId:B}=a,O=(0,h.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),[V,N]=(0,n.useState)([O]),[I,j]=(0,n.useState)(),H=(0,h.useDispatch)("core/notices");function G(e){"AbortError"!==e.name&&H.createErrorNotice(e.message,{isDismissible:!0})}(0,n.useEffect)((()=>{if(!B)return;const e=new AbortController;return u()({path:`/coauthors/v1/coauthors?post_id=${B}`,signal:e.signal}).then(N).catch(G),()=>{e.abort()}}),[B]);const M=(0,h.useSelect)((e=>e(c.store).getBlocks(r))),R=e=>{o({layout:e})},T=[{icon:v,title:(0,p.__)("Inline view"),onClick:()=>R({type:"default"}),isActive:"default"===z},{icon:d,title:(0,p.__)("List view"),onClick:()=>R({type:"constrained"}),isActive:"constrained"===z},{icon:m,title:(0,p.__)("Grid view"),onClick:()=>R({type:"grid"}),isActive:"grid"===z},{icon:f,title:(0,p.__)("Row view"),onClick:()=>R({type:"flex",orientation:"horizontal"}),isActive:"flex"===z&&"horizontal"===P},{icon:w,title:(0,p.__)("Stack view"),onClick:()=>R({type:"flex",orientation:"vertical"}),isActive:"flex"===z&&"vertical"===P}];return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(c.BlockControls,null,(0,n.createElement)(s.ToolbarGroup,{controls:T}),(0,n.createElement)(c.AlignmentControl,{value:A,onChange:e=>{o({textAlign:e})}})),(0,n.createElement)("div",(0,c.useBlockProps)({className:x()(i,{[`has-text-align-${A}`]:A})}),V&&"default"===z&&(l||g)&&(0,n.createElement)(c.RichText,{allowedFormats:k,className:"wp-block-co-authors-plus-coauthors__prefix",multiline:!1,"aria-label":(0,p.__)("Prefix","co-authors-plus"),placeholder:(0,p.__)("Prefix","co-authors-plus")+" ",value:g,onChange:e=>o({prefix:e}),tagName:"span"}),V&&V.map((e=>{var t;const o=e.id===(I||(null===(t=V[0])||void 0===t?void 0:t.id));return(0,n.createElement)(c.BlockContextProvider,{key:e.id,value:{"co-authors-plus/author":e,"co-authors-plus/layout":z}},o?(0,n.createElement)(E,null):null,(0,n.createElement)(_,{blocks:M,blockContextId:e.id,setActiveBlockContextId:j,isHidden:o}))})).reduce(((e,t,o,r)=>(0,n.createElement)(n.Fragment,null,e,"default"===z&&(0,n.createElement)("span",{className:"wp-block-co-authors-plus-coauthors__separator"},y&&o===r.length-1?`${y}`:`${b}`),t))),V&&"default"===z&&(l||C)&&(0,n.createElement)(c.RichText,{allowedFormats:k,className:"wp-block-co-authors-plus-coauthors__suffix",multiline:!1,"aria-label":(0,p.__)("Suffix"),placeholder:(0,p.__)("Suffix")+" ",value:C,onChange:e=>o({suffix:e}),tagName:"span"})),(0,n.createElement)(c.InspectorControls,null,"default"===z&&(0,n.createElement)(s.PanelBody,{title:(0,p.__)("Co-Authors Layout","co-authors-plus")},(0,n.createElement)(s.TextControl,{autoComplete:"off",label:(0,p.__)("Separator","co-authors-plus"),value:b||"",onChange:e=>{o({separator:e})},help:(0,p.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,n.createElement)(s.TextControl,{autoComplete:"off",label:(0,p.__)("Last Separator","co-authors-plus"),value:y||"",onChange:e=>{o({lastSeparator:e})},help:(0,p.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){let{attributes:t}=e;const{textAlign:o}=t,r=x()({[`has-text-align-${o}`]:o});return(0,n.createElement)("div",c.useBlockProps.save({className:r}),(0,n.createElement)(c.InnerBlocks.Content,null))},icon:l})},184:function(e,t){var o;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](o[s])}))?o.splice(s--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[o,n,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};r.O.j=function(t){return 0===e[t]};var t=function(t,o){var n,a,l=o[0],c=o[1],s=o[2],i=0;if(l.some((function(t){return 0!==e[t]}))){for(n in c)r.o(c,n)&&(r.m[n]=c[n]);if(s)var u=s(r)}for(t&&t(o);i{a(o)},i={display:r?"none":void 0};return(0,n.createElement)("div",b({},l,{tabIndex:0,role:"button",onClick:s,onKeyUp:s,style:i}))}));function E(){return(0,n.createElement)("div",(0,c.useInnerBlocksProps)({className:"wp-block-co-authors-plus-coauthor"},{template:[["co-authors-plus/name"]],__unstableDisableLayoutClassNames:!0}))}const k=["core/bold","core/italic","core/text-color"];var y=JSON.parse('{"u2":"co-authors-plus/coauthors"}');(0,r.registerBlockType)(y.u2,{edit:function(e){let{attributes:t,setAttributes:o,clientId:r,context:a,isSelected:l,__unstableLayoutClassNames:i}=e;const{prefix:g,separator:b,lastSeparator:y,suffix:C,layout:S,textAlign:A}=t,{type:z,orientation:P}=S||{},{postId:B}=a,O=(0,h.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),[V,N]=(0,n.useState)([O]),[I,j]=(0,n.useState)(),H=(0,h.useDispatch)("core/notices");function G(e){"AbortError"!==e.name&&H.createErrorNotice(e.message,{isDismissible:!0})}(0,n.useEffect)((()=>{if(!B)return;const e=new AbortController;return u()({path:`/coauthors/v1/coauthors?post_id=${B}`,signal:e.signal}).then(N).catch(G),()=>{e.abort()}}),[B]);const M=(0,h.useSelect)((e=>e(c.store).getBlocks(r))),R=e=>{o({layout:e})},T=[{icon:v,title:(0,p.__)("Inline view"),onClick:()=>R({type:"default"}),isActive:"default"===z},{icon:m,title:(0,p.__)("List view"),onClick:()=>R({type:"constrained"}),isActive:"constrained"===z},{icon:d,title:(0,p.__)("Grid view"),onClick:()=>R({type:"grid"}),isActive:"grid"===z},{icon:f,title:(0,p.__)("Row view"),onClick:()=>R({type:"flex",orientation:"horizontal"}),isActive:"flex"===z&&"horizontal"===P},{icon:w,title:(0,p.__)("Stack view"),onClick:()=>R({type:"flex",orientation:"vertical"}),isActive:"flex"===z&&"vertical"===P}];return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(c.BlockControls,null,(0,n.createElement)(s.ToolbarGroup,{controls:T}),(0,n.createElement)(c.AlignmentControl,{value:A,onChange:e=>{o({textAlign:e})}})),(0,n.createElement)("div",(0,c.useBlockProps)({className:x()(i,{[`has-text-align-${A}`]:A},"remove-outline")}),V&&"default"===z&&(l||g)&&(0,n.createElement)(c.RichText,{allowedFormats:k,className:"wp-block-co-authors-plus-coauthors__prefix",multiline:!1,"aria-label":(0,p.__)("Prefix","co-authors-plus"),placeholder:(0,p.__)("Prefix","co-authors-plus")+" ",value:g,onChange:e=>o({prefix:e}),tagName:"span"}),V&&V.map((e=>{var t;const o=e.id===(I||(null===(t=V[0])||void 0===t?void 0:t.id));return(0,n.createElement)(c.BlockContextProvider,{key:e.id,value:{"co-authors-plus/author":e,"co-authors-plus/layout":z}},o?(0,n.createElement)(E,null):null,(0,n.createElement)(_,{blocks:M,blockContextId:e.id,setActiveBlockContextId:j,isHidden:o}))})).reduce(((e,t,o,r)=>(0,n.createElement)(n.Fragment,null,e,"default"===z&&(0,n.createElement)("span",{className:"wp-block-co-authors-plus-coauthors__separator"},y&&o===r.length-1?`${y}`:`${b}`),t))),V&&"default"===z&&(l||C)&&(0,n.createElement)(c.RichText,{allowedFormats:k,className:"wp-block-co-authors-plus-coauthors__suffix",multiline:!1,"aria-label":(0,p.__)("Suffix"),placeholder:(0,p.__)("Suffix")+" ",value:C,onChange:e=>o({suffix:e}),tagName:"span"})),(0,n.createElement)(c.InspectorControls,null,"default"===z&&(0,n.createElement)(s.PanelBody,{title:(0,p.__)("Co-Authors Layout","co-authors-plus")},(0,n.createElement)(s.TextControl,{autoComplete:"off",label:(0,p.__)("Separator","co-authors-plus"),value:b||"",onChange:e=>{o({separator:e})},help:(0,p.__)("Enter character(s) used to separate authors.","co-authors-plus")}),(0,n.createElement)(s.TextControl,{autoComplete:"off",label:(0,p.__)("Last Separator","co-authors-plus"),value:y||"",onChange:e=>{o({lastSeparator:e})},help:(0,p.__)("Enter character(s) used to separate the last author.","co-authors-plus")}))))},save:function(e){let{attributes:t}=e;const{textAlign:o}=t,r=x()({[`has-text-align-${o}`]:o});return(0,n.createElement)("div",c.useBlockProps.save({className:r}),(0,n.createElement)(c.InnerBlocks.Content,null))},icon:l})},184:function(e,t){var o;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e=[],t=0;t=a)&&Object.keys(r.O).every((function(e){return r.O[e](o[s])}))?o.splice(s--,1):(c=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[o,n,a]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={887:0,270:0};r.O.j=function(t){return 0===e[t]};var t=function(t,o){var n,a,l=o[0],c=o[1],s=o[2],i=0;if(l.some((function(t){return 0!==e[t]}))){for(n in c)r.o(c,n)&&(r.m[n]=c[n]);if(s)var u=s(r)}for(t&&t(o);i Date: Thu, 8 Feb 2024 14:32:59 -0500 Subject: [PATCH 123/123] Default feature image block to thumbnail not full Full was considered too big, especially in template editor contexts. --- build/blocks/block-coauthor-image/index.asset.php | 2 +- build/blocks/block-coauthor-image/index.js | 2 +- src/blocks/block-coauthor-image/dimension-controls.js | 2 +- src/blocks/block-coauthor-image/utils.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/blocks/block-coauthor-image/index.asset.php b/build/blocks/block-coauthor-image/index.asset.php index 9040c473..699f315d 100644 --- a/build/blocks/block-coauthor-image/index.asset.php +++ b/build/blocks/block-coauthor-image/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2c80e74d7ff9efae21e8'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '97710ad46fb953ce4975'); diff --git a/build/blocks/block-coauthor-image/index.js b/build/blocks/block-coauthor-image/index.js index 62ba689f..294955e5 100644 --- a/build/blocks/block-coauthor-image/index.js +++ b/build/blocks/block-coauthor-image/index.js @@ -1 +1 @@ -!function(){var e,t={62:function(e,t,l){"use strict";var o=window.wp.blocks,n=window.wp.element,a=window.wp.primitives,i=(0,n.createElement)(a.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)(a.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z"})),r=window.wp.i18n,s=window.wp.blockEditor,u=window.wp.components,c=window.wp.data,h=window.wp.coreData;const p=(0,n.createElement)(n.Fragment,null,(0,n.createElement)(u.__experimentalToggleGroupControlOption,{value:"cover",label:(0,r._x)("Cover","Scale option for Image dimension control")}),(0,n.createElement)(u.__experimentalToggleGroupControlOption,{value:"contain",label:(0,r._x)("Contain","Scale option for Image dimension control")}),(0,n.createElement)(u.__experimentalToggleGroupControlOption,{value:"fill",label:(0,r._x)("Fill","Scale option for Image dimension control")})),g="cover",d={cover:(0,r.__)("Image is scaled and cropped to fill the entire space without being distorted."),contain:(0,r.__)("Image is scaled to fill the space without clipping nor distorting."),fill:(0,r.__)("Image will be stretched and distorted to completely fill the space.")};var m=e=>{let{clientId:t,attributes:{aspectRatio:l,width:o,height:a,scale:i,sizeSlug:c},setAttributes:h,imageSizeOptions:m=[]}=e;const _=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||h({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),w=a||l&&"auto"!==l;return(0,n.createElement)(s.InspectorControls,{group:"dimensions"},(0,n.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>h({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>h({aspectRatio:e})})),(0,n.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!a,label:(0,r.__)("Height"),onDeselect:()=>h({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:a||"",min:0,onChange:e=>v("height",e),units:_})),(0,n.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Width"),onDeselect:()=>h({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:o||"",min:0,onChange:e=>v("width",e),units:_})),w&&(0,n.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==g,label:f,onDeselect:()=>h({scale:g}),resetAllFilter:()=>({scale:g}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:d[i],onChange:e=>h({scale:e}),isBlock:!0},p)),!!m.length&&(0,n.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>h({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,n.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"full",options:m,onChange:e=>h({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))};function _(e){let{dimensions:t,style:l,className:o}=e;const a=(0,n.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,n.createElement)("img",{alt:(0,r.__)("Placeholder image"),className:o,src:a,style:l,width:t.width,height:t.height})}function v(e,t){var l,o;return null==e||null===(l=e.media_details)||void 0===l||null===(o=l.sizes[t])||void 0===o?void 0:o.source_url}var f=l(184),w=l.n(f),b=JSON.parse('{"u2":"co-authors-plus/image"}');(0,o.registerBlockType)(b.u2,{edit:function(e){let{attributes:t,setAttributes:l,context:o,clientId:a}=e;const{aspectRatio:i,height:p,isLink:g,rel:d,scale:f,sizeSlug:b,verticalAlign:x,width:S,align:y}=t,E=(0,c.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),C=o["co-authors-plus/author"]||E,k=o["co-authors-plus/layout"]||"",I=(0,c.useSelect)((e=>0!==C.featured_media&&e(h.store).getMedia(C.featured_media,{context:"view"})),[C.featured_media]),{imageSizes:O,imageDimensions:B}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),A=O.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),T=function(e,t,l){if(e&&"full"===l)return l;const o=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),o=Object.keys(t);return Array.from(new Set([...l.filter((e=>o.includes(e)))]))}(e,t);return l&&o.includes(l)?l:o[Math.max(0,o.length-1)]}(I,B,b),N=function(e,t,l){if(!e)return{};const o=e.media_details.sizes[l];if("full"===l)return{width:o.width,height:o.height};const n=t[l];if(!0===n.crop||n.width===n.height)return{width:n.width,height:n.height};const a=o.width/o.height;return n.width>n.height?{width:n.width,height:n.width/a}:{width:n.height*a,height:n.height}}(I,B,T),P=I?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(B,T),z=(0,s.__experimentalUseBorderProps)(t),M=0!==C.id&&!1===I;return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(m,{clientId:a,attributes:t,setAttributes:l,imageSizeOptions:A}),""===k?(0,n.createElement)(s.BlockControls,null,(0,n.createElement)(s.BlockAlignmentToolbar,{value:y,onChange:e=>{l({align:e})},controls:["none","left","center","right","wide","full"]})):null,M?null:(0,n.createElement)("figure",(0,s.useBlockProps)({className:w()({[`align${y}`]:!k&&y&&"none"!==y})}),I?(0,n.createElement)("img",{alt:(0,r.__)("Author featured image","co-authors-plus"),className:z.className,src:v(I,T),style:{width:!S&&p?"auto":S,height:!p&&S?"auto":p,aspectRatio:i,objectFit:f,verticalAlign:x,...z.style},width:N.width,height:N.height}):(0,n.createElement)(_,{className:z.className,dimensions:P,style:{width:!S&&p?"auto":S,height:!p&&S?"auto":p,aspectRatio:i,objectFit:f,verticalAlign:x,...z.style}})),(0,n.createElement)(s.InspectorControls,null,(0,n.createElement)(u.PanelBody,{title:(0,r.__)("Image Settings","co-authors-plus")},(0,n.createElement)(u.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>l({isLink:!g}),checked:g}),g&&(0,n.createElement)(u.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel","co-authors-plus"),value:d,onChange:e=>l({rel:e})})),"default"===k?(0,n.createElement)(u.PanelBody,{initialOpen:!1,title:(0,r.__)("Co-Authors Layout","co-authors-plus")},(0,n.createElement)(u.SelectControl,{label:(0,r.__)("Vertical align","co-authors-plus"),value:x,options:[{value:"",label:(0,r.__)("Default","co-authors-plus")},{value:"baseline",label:(0,r.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,r.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,r.__)("Middle","co-authors-plus")},{value:"sub",label:(0,r.__)("Sub","co-authors-plus")},{value:"super",label:(0,r.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,r.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,r.__)("Text Top","co-authors-plus")},{value:"top",label:(0,r.__)("Top","co-authors-plus")}],onChange:e=>{l({verticalAlign:""===e?void 0:e})},help:(0,r.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")})):null))},icon:i})},184:function(e,t){var l;!function(){"use strict";var o={}.hasOwnProperty;function n(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](l[s])}))?l.splice(s--,1):(r=!1,a0&&e[c-1][2]>a;c--)e[c]=e[c-1];e[c]=[l,n,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var l in t)o.o(t,l)&&!o.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={461:0,286:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var n,a,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(n in r)o.o(r,n)&&(o.m[n]=r[n]);if(s)var c=s(o)}for(t&&t(l);u{let{clientId:t,attributes:{aspectRatio:l,width:o,height:a,scale:i,sizeSlug:c},setAttributes:h,imageSizeOptions:m=[]}=e;const _=(0,u.__experimentalUseCustomUnits)({availableUnits:(0,s.useSetting)("spacing.units")||["px","%","vw","em","rem"]}),v=(e,t)=>{const l=parseFloat(t);isNaN(l)&&t||h({[e]:l<0?"0":t})},f=(0,r._x)("Scale","Image scaling options"),w=a||l&&"auto"!==l;return(0,n.createElement)(s.InspectorControls,{group:"dimensions"},(0,n.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!l,label:(0,r.__)("Aspect ratio"),onDeselect:()=>h({aspectRatio:void 0}),resetAllFilter:()=>({aspectRatio:void 0}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Aspect ratio"),value:l,options:[{label:(0,r.__)("Original"),value:"auto"},{label:(0,r.__)("Square"),value:"1"},{label:(0,r.__)("16:9"),value:"16/9"},{label:(0,r.__)("4:3"),value:"4/3"},{label:(0,r.__)("3:2"),value:"3/2"},{label:(0,r.__)("9:16"),value:"9/16"},{label:(0,r.__)("3:4"),value:"3/4"},{label:(0,r.__)("2:3"),value:"2/3"}],onChange:e=>h({aspectRatio:e})})),(0,n.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!a,label:(0,r.__)("Height"),onDeselect:()=>h({height:void 0}),resetAllFilter:()=>({height:void 0}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Height"),labelPosition:"top",value:a||"",min:0,onChange:e=>v("height",e),units:_})),(0,n.createElement)(u.__experimentalToolsPanelItem,{className:"single-column",hasValue:()=>!!o,label:(0,r.__)("Width"),onDeselect:()=>h({width:void 0}),resetAllFilter:()=>({width:void 0}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.__experimentalUnitControl,{label:(0,r.__)("Width"),labelPosition:"top",value:o||"",min:0,onChange:e=>v("width",e),units:_})),w&&(0,n.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!i&&i!==g,label:f,onDeselect:()=>h({scale:g}),resetAllFilter:()=>({scale:g}),isShownByDefault:!0,panelId:t},(0,n.createElement)(u.__experimentalToggleGroupControl,{__nextHasNoMarginBottom:!0,label:f,value:i,help:d[i],onChange:e=>h({scale:e}),isBlock:!0},p)),!!m.length&&(0,n.createElement)(u.__experimentalToolsPanelItem,{hasValue:()=>!!c,label:(0,r.__)("Resolution"),onDeselect:()=>h({sizeSlug:void 0}),resetAllFilter:()=>({sizeSlug:void 0}),isShownByDefault:!1,panelId:t},(0,n.createElement)(u.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Resolution"),value:c||"thumbnail",options:m,onChange:e=>h({sizeSlug:e}),help:(0,r.__)("Select the size of the source image.")})))};function _(e){let{dimensions:t,style:l,className:o}=e;const a=(0,n.useMemo)((()=>function(e){let{width:t,height:l}=e;return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`\n\t\t\t\n\t\t\t\n\t\t`.replace(/[\t\n\r]/gim,"").replace(/\s\s+/g," ")).replace(/\(/g,"%28").replace(/\)/g,"%29")}`}(t)),[t]);return(0,n.createElement)("img",{alt:(0,r.__)("Placeholder image"),className:o,src:a,style:l,width:t.width,height:t.height})}function v(e,t){var l,o;return null==e||null===(l=e.media_details)||void 0===l||null===(o=l.sizes[t])||void 0===o?void 0:o.source_url}var f=l(184),w=l.n(f),b=JSON.parse('{"u2":"co-authors-plus/image"}');(0,o.registerBlockType)(b.u2,{edit:function(e){let{attributes:t,setAttributes:l,context:o,clientId:a}=e;const{aspectRatio:i,height:p,isLink:g,rel:d,scale:f,sizeSlug:b,verticalAlign:x,width:S,align:y}=t,E=(0,c.useSelect)((e=>e("co-authors-plus/blocks").getAuthorPlaceholder()),[]),C=o["co-authors-plus/author"]||E,k=o["co-authors-plus/layout"]||"",I=(0,c.useSelect)((e=>0!==C.featured_media&&e(h.store).getMedia(C.featured_media,{context:"view"})),[C.featured_media]),{imageSizes:O,imageDimensions:B}=(0,c.useSelect)((e=>e(s.store).getSettings()),[]),A=O.map((e=>{let{name:t,slug:l}=e;return{value:l,label:t}})),T=function(e,t,l){if(e&&"full"===l)return l;const o=function(e,t){if(!e)return Object.keys(t);const l=Object.keys(e.media_details.sizes),o=Object.keys(t);return Array.from(new Set([...l.filter((e=>o.includes(e)))]))}(e,t);return l&&o.includes(l)?l:o[0]}(I,B,b),N=function(e,t,l){if(!e)return{};const o=e.media_details.sizes[l];if("full"===l)return{width:o.width,height:o.height};const n=t[l];if(!0===n.crop||n.width===n.height)return{width:n.width,height:n.height};const a=o.width/o.height;return n.width>n.height?{width:n.width,height:n.width/a}:{width:n.height*a,height:n.height}}(I,B,T),P=I?{}:function(e,t){const l=e[t];return!0===l.crop||l.width===l.height?{width:l.width,height:l.height}:l.width>l.height?{width:l.width,height:l.width}:{width:l.height,height:l.height}}(B,T),z=(0,s.__experimentalUseBorderProps)(t),D=0!==C.id&&!1===I;return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(m,{clientId:a,attributes:t,setAttributes:l,imageSizeOptions:A}),""===k?(0,n.createElement)(s.BlockControls,null,(0,n.createElement)(s.BlockAlignmentToolbar,{value:y,onChange:e=>{l({align:e})},controls:["none","left","center","right","wide","full"]})):null,D?null:(0,n.createElement)("figure",(0,s.useBlockProps)({className:w()({[`align${y}`]:!k&&y&&"none"!==y})}),I?(0,n.createElement)("img",{alt:(0,r.__)("Author featured image","co-authors-plus"),className:z.className,src:v(I,T),style:{width:!S&&p?"auto":S,height:!p&&S?"auto":p,aspectRatio:i,objectFit:f,verticalAlign:x,...z.style},width:N.width,height:N.height}):(0,n.createElement)(_,{className:z.className,dimensions:P,style:{width:!S&&p?"auto":S,height:!p&&S?"auto":p,aspectRatio:i,objectFit:f,verticalAlign:x,...z.style}})),(0,n.createElement)(s.InspectorControls,null,(0,n.createElement)(u.PanelBody,{title:(0,r.__)("Image Settings","co-authors-plus")},(0,n.createElement)(u.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Make featured image a link to author archive.","co-authors-plus"),onChange:()=>l({isLink:!g}),checked:g}),g&&(0,n.createElement)(u.TextControl,{__nextHasNoMarginBottom:!0,label:(0,r.__)("Link rel","co-authors-plus"),value:d,onChange:e=>l({rel:e})})),"default"===k?(0,n.createElement)(u.PanelBody,{initialOpen:!1,title:(0,r.__)("Co-Authors Layout","co-authors-plus")},(0,n.createElement)(u.SelectControl,{label:(0,r.__)("Vertical align","co-authors-plus"),value:x,options:[{value:"",label:(0,r.__)("Default","co-authors-plus")},{value:"baseline",label:(0,r.__)("Baseline","co-authors-plus")},{value:"bottom",label:(0,r.__)("Bottom","co-authors-plus")},{value:"middle",label:(0,r.__)("Middle","co-authors-plus")},{value:"sub",label:(0,r.__)("Sub","co-authors-plus")},{value:"super",label:(0,r.__)("Super","co-authors-plus")},{value:"text-bottom",label:(0,r.__)("Text Bottom","co-authors-plus")},{value:"text-top",label:(0,r.__)("Text Top","co-authors-plus")},{value:"top",label:(0,r.__)("Top","co-authors-plus")}],onChange:e=>{l({verticalAlign:""===e?void 0:e})},help:(0,r.__)("Vertical alignment defaults to bottom in the block layout and middle in the inline layout.","co-authors-plus")})):null))},icon:i})},184:function(e,t){var l;!function(){"use strict";var o={}.hasOwnProperty;function n(){for(var e=[],t=0;t=a)&&Object.keys(o.O).every((function(e){return o.O[e](l[s])}))?l.splice(s--,1):(r=!1,a0&&e[c-1][2]>a;c--)e[c]=e[c-1];e[c]=[l,n,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var l in t)o.o(t,l)&&!o.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={461:0,286:0};o.O.j=function(t){return 0===e[t]};var t=function(t,l){var n,a,i=l[0],r=l[1],s=l[2],u=0;if(i.some((function(t){return 0!==e[t]}))){for(n in r)o.o(r,n)&&(o.m[n]=r[n]);if(s)var c=s(o)}for(t&&t(l);u