1
- import { PluginDocumentSettingPanel , PluginPreviewMenuItem } from '@wordpress/editor' ;
1
+ import { PluginDocumentSettingPanel , PluginPreviewMenuItem , store as editorStore } from '@wordpress/editor' ;
2
2
import { PluginDocumentSettingPanel as DocumentSettingPanel } from '@wordpress/edit-post' ;
3
3
import { registerPlugin } from '@wordpress/plugins' ;
4
4
import { TextControl , RadioControl , RangeControl , __experimentalText as Text , Tooltip } from '@wordpress/components' ;
@@ -8,35 +8,38 @@ import { useEntityProp } from '@wordpress/core-data';
8
8
import { addQueryArgs } from '@wordpress/url' ;
9
9
import { __ } from '@wordpress/i18n' ;
10
10
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
- ) ;
24
11
25
12
/**
26
13
* Editor plugin for ActivityPub settings in the block editor.
27
14
*
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.
29
16
*/
30
17
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' ) ;
33
20
34
21
// Don't show when editing sync blocks.
35
22
if ( 'wp_block' === postType ) {
36
23
return null ;
37
24
}
38
25
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
+
40
43
const labelStyling = {
41
44
verticalAlign : 'middle' ,
42
45
gap : '4px' ,
@@ -48,11 +51,11 @@ const EditorPlugin = () => {
48
51
/**
49
52
* Enhances a label with an icon and tooltip.
50
53
*
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.
54
57
*
55
- * @returns {JSX.Element } The enhanced label component.
58
+ * @returns {React. JSX.Element } The enhanced label component.
56
59
*/
57
60
const enhancedLabel = ( icon , text , tooltip ) => (
58
61
< Tooltip text = { tooltip } >
@@ -92,7 +95,7 @@ const EditorPlugin = () => {
92
95
93
96
< RangeControl
94
97
label = { __ ( 'Maximum Image Attachments' , 'activitypub' ) }
95
- value = { meta ?. activitypub_max_image_attachments ?? maxImageAttachments }
98
+ value = { meta ?. activitypub_max_image_attachments }
96
99
onChange = { ( value ) => {
97
100
setMeta ( { ...meta , activitypub_max_image_attachments : value } ) ;
98
101
} }
@@ -151,30 +154,29 @@ const EditorPlugin = () => {
151
154
) ;
152
155
} ;
153
156
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
-
164
157
/**
165
158
* Renders the preview menu item for Fediverse preview.
166
159
*
167
- * @returns {JSX.Element } The preview menu item component.
160
+ * @returns {React. JSX.Element } The preview menu item component.
168
161
*/
169
162
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
+ } ;
172
174
173
175
return (
174
176
< >
175
177
{ PluginPreviewMenuItem ? (
176
178
< PluginPreviewMenuItem
177
- onClick = { ( ) => onActivityPubPreview ( ) }
179
+ onClick = { onActivityPubPreview }
178
180
icon = { external }
179
181
disabled = { post_status === 'auto-draft' }
180
182
>
0 commit comments