1- import { PluginDocumentSettingPanel , PluginPreviewMenuItem } from '@wordpress/editor' ;
1+ import { PluginDocumentSettingPanel , PluginPreviewMenuItem , store as editorStore } from '@wordpress/editor' ;
22import { PluginDocumentSettingPanel as DocumentSettingPanel } from '@wordpress/edit-post' ;
33import { registerPlugin } from '@wordpress/plugins' ;
44import { TextControl , RadioControl , RangeControl , __experimentalText as Text , Tooltip } from '@wordpress/components' ;
@@ -8,35 +8,38 @@ import { useEntityProp } from '@wordpress/core-data';
88import { addQueryArgs } from '@wordpress/url' ;
99import { __ } from '@wordpress/i18n' ;
1010import { 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 */
3017const 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 */
169162const 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