Skip to content

Commit ca22668

Browse files
authored
Editor Plugin: Minor polish update (#1769)
1 parent e1a9a92 commit ca22668

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

build/editor-plugin/plugin.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '35ef322601ad7ccf1214');
1+
<?php return array('dependencies' => array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '59c90d6c8ab5e740f5a1');

build/editor-plugin/plugin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-blocks.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,12 @@ public static function register_postmeta() {
8989
*/
9090
public static function enqueue_editor_assets() {
9191
$data = array(
92-
'namespace' => ACTIVITYPUB_REST_NAMESPACE,
93-
'defaultAvatarUrl' => ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg',
94-
'enabled' => array(
92+
'namespace' => ACTIVITYPUB_REST_NAMESPACE,
93+
'defaultAvatarUrl' => ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg',
94+
'enabled' => array(
9595
'site' => ! is_user_type_disabled( 'blog' ),
9696
'users' => ! is_user_type_disabled( 'user' ),
9797
),
98-
'maxImageAttachments' => \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ),
9998
);
10099
wp_localize_script( 'wp-editor', '_activityPubOptions', $data );
101100

src/editor-plugin/plugin.js

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PluginDocumentSettingPanel, PluginPreviewMenuItem } from '@wordpress/editor';
1+
import { PluginDocumentSettingPanel, PluginPreviewMenuItem, store as editorStore } from '@wordpress/editor';
22
import { PluginDocumentSettingPanel as DocumentSettingPanel } from '@wordpress/edit-post';
33
import { registerPlugin } from '@wordpress/plugins';
44
import { TextControl, RadioControl, RangeControl, __experimentalText as Text, Tooltip } from '@wordpress/components';
@@ -8,35 +8,38 @@ import { useEntityProp } from '@wordpress/core-data';
88
import { addQueryArgs } from '@wordpress/url';
99
import { __ } from '@wordpress/i18n';
1010
import { SVG, Path } from '@wordpress/primitives';
11-
import { useOptions } from '../shared/use-options';
12-
13-
// Defining our own because it's too new in @wordpress/icons
14-
// https://github.com/WordPress/gutenberg/blob/trunk/packages/icons/src/library/not-allowed.js
15-
const notAllowed = (
16-
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
17-
<Path
18-
fillRule="evenodd"
19-
clipRule="evenodd"
20-
d="M12 18.5A6.5 6.5 0 0 1 6.93 7.931l9.139 9.138A6.473 6.473 0 0 1 12 18.5Zm5.123-2.498a6.5 6.5 0 0 0-9.124-9.124l9.124 9.124ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Z"
21-
/>
22-
</SVG>
23-
);
2411

2512
/**
2613
* Editor plugin for ActivityPub settings in the block editor.
2714
*
28-
* @returns {JSX.Element|null} The settings panel for ActivityPub or null for sync blocks.
15+
* @returns {React.JSX.Element|null} The settings panel for ActivityPub or null for sync blocks.
2916
*/
3017
const EditorPlugin = () => {
31-
const postType = useSelect( ( select ) => select( 'core/editor' ).getCurrentPostType(), [] );
32-
const [ meta, setMeta ] = useEntityProp( 'postType', postType || 'default', 'meta' );
18+
const postType = useSelect( ( select ) => select( editorStore ).getCurrentPostType(), [] );
19+
const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' );
3320

3421
// Don't show when editing sync blocks.
3522
if ( 'wp_block' === postType ) {
3623
return null;
3724
}
3825

39-
const { maxImageAttachments = 4 } = useOptions();
26+
/**
27+
* SVG for the not-allowed icon. Defining our own because it's too new in @wordpress/icons.
28+
*
29+
* @see https://github.com/WordPress/gutenberg/blob/trunk/packages/icons/src/library/not-allowed.js
30+
*
31+
* @var {React.JSX.Element} notAllowed The SVG for the not-allowed icon.
32+
*/
33+
const notAllowed = (
34+
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
35+
<Path
36+
fillRule="evenodd"
37+
clipRule="evenodd"
38+
d="M12 18.5A6.5 6.5 0 0 1 6.93 7.931l9.139 9.138A6.473 6.473 0 0 1 12 18.5Zm5.123-2.498a6.5 6.5 0 0 0-9.124-9.124l9.124 9.124ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Z"
39+
/>
40+
</SVG>
41+
);
42+
4043
const labelStyling = {
4144
verticalAlign: 'middle',
4245
gap: '4px',
@@ -48,11 +51,11 @@ const EditorPlugin = () => {
4851
/**
4952
* Enhances a label with an icon and tooltip.
5053
*
51-
* @param {JSX.Element} icon The icon to display.
52-
* @param {string} text The label text.
53-
* @param {string} tooltip The tooltip text.
54+
* @param {React.JSX.Element} icon The icon to display.
55+
* @param {string} text The label text.
56+
* @param {string} tooltip The tooltip text.
5457
*
55-
* @returns {JSX.Element} The enhanced label component.
58+
* @returns {React.JSX.Element} The enhanced label component.
5659
*/
5760
const enhancedLabel = ( icon, text, tooltip ) => (
5861
<Tooltip text={ tooltip }>
@@ -92,7 +95,7 @@ const EditorPlugin = () => {
9295

9396
<RangeControl
9497
label={ __( 'Maximum Image Attachments', 'activitypub' ) }
95-
value={ meta?.activitypub_max_image_attachments ?? maxImageAttachments }
98+
value={ meta?.activitypub_max_image_attachments }
9699
onChange={ ( value ) => {
97100
setMeta( { ...meta, activitypub_max_image_attachments: value } );
98101
} }
@@ -151,30 +154,29 @@ const EditorPlugin = () => {
151154
);
152155
};
153156

154-
/**
155-
* Opens the Fediverse preview for the current post in a new tab.
156-
*/
157-
function onActivityPubPreview() {
158-
const previewLink = select( 'core/editor' ).getEditedPostPreviewLink();
159-
const fediversePreviewLink = addQueryArgs( previewLink, { activitypub: 'true' } );
160-
161-
window.open( fediversePreviewLink, '_blank' );
162-
}
163-
164157
/**
165158
* Renders the preview menu item for Fediverse preview.
166159
*
167-
* @returns {JSX.Element} The preview menu item component.
160+
* @returns {React.JSX.Element} The preview menu item component.
168161
*/
169162
const EditorPreview = () => {
170-
// check if post was saved
171-
const post_status = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost().status );
163+
const post_status = useSelect( ( select ) => select( editorStore ).getCurrentPost().status, [] );
164+
165+
/**
166+
* Opens the Fediverse preview for the current post in a new tab.
167+
*/
168+
const onActivityPubPreview = () => {
169+
const previewLink = select( editorStore ).getEditedPostPreviewLink();
170+
const fediversePreviewLink = addQueryArgs( previewLink, { activitypub: 'true' } );
171+
172+
window.open( fediversePreviewLink, '_blank' );
173+
};
172174

173175
return (
174176
<>
175177
{ PluginPreviewMenuItem ? (
176178
<PluginPreviewMenuItem
177-
onClick={ () => onActivityPubPreview() }
179+
onClick={ onActivityPubPreview }
178180
icon={ external }
179181
disabled={ post_status === 'auto-draft' }
180182
>

0 commit comments

Comments
 (0)