Skip to content

Commit dce490f

Browse files
authored
Prettier: Update editor-plugin (#1688)
1 parent ae25ca7 commit dce490f

File tree

3 files changed

+60
-33
lines changed

3 files changed

+60
-33
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ vendor
55

66
# Temporary ignores while breaking out each component.
77
assets
8-
src/editor-plugin
98
src/follow-me
109
src/followers
1110
src/reactions

src/editor-plugin/block.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
2-
"name": "editor-plugin",
3-
"title": "Editor Plugin: not a block, but block.json is very useful.",
4-
"category": "widgets",
5-
"icon": "admin-comments",
6-
"keywords": [
7-
],
8-
"editorScript": "file:./plugin.js"
2+
"name": "editor-plugin",
3+
"title": "Editor Plugin: not a block, but block.json is very useful.",
4+
"category": "widgets",
5+
"icon": "admin-comments",
6+
"keywords": [],
7+
"editorScript": "file:./plugin.js"
98
}

src/editor-plugin/plugin.js

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,37 @@ const notAllowed = (
2020
</SVG>
2121
);
2222

23-
23+
/**
24+
* Editor plugin for ActivityPub settings in the block editor.
25+
*
26+
* @returns {JSX.Element|null} The settings panel for ActivityPub or null for sync blocks.
27+
*/
2428
const EditorPlugin = () => {
25-
const postType = useSelect(
26-
( select ) => select( 'core/editor' ).getCurrentPostType(),
27-
[]
28-
);
29+
const postType = useSelect( ( select ) => select( 'core/editor' ).getCurrentPostType(), [] );
2930
const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' );
3031

3132
const labelStyling = {
32-
verticalAlign: "middle",
33-
gap: "4px",
34-
justifyContent: "start",
35-
display: "inline-flex",
36-
alignItems: "center"
37-
}
33+
verticalAlign: 'middle',
34+
gap: '4px',
35+
justifyContent: 'start',
36+
display: 'inline-flex',
37+
alignItems: 'center',
38+
};
3839

40+
/**
41+
* Enhances a label with an icon and tooltip.
42+
*
43+
* @param {JSX.Element} icon The icon to display.
44+
* @param {string} text The label text.
45+
* @param {string} tooltip The tooltip text.
46+
*
47+
* @returns {JSX.Element} The enhanced label component.
48+
*/
3949
const enhancedLabel = ( icon, text, tooltip ) => (
4050
<Tooltip text={ tooltip }>
4151
<Text style={ labelStyling }>
4252
<Icon icon={ icon } />
43-
{text}
53+
{ text }
4454
</Text>
4555
</Tooltip>
4656
);
@@ -51,34 +61,42 @@ const EditorPlugin = () => {
5161
}
5262

5363
return (
54-
<PluginDocumentSettingPanel
55-
name="activitypub"
56-
title={ __( 'Fediverse ⁂', 'activitypub' ) }
57-
>
64+
<PluginDocumentSettingPanel name="activitypub" title={ __( 'Fediverse ⁂', 'activitypub' ) }>
5865
<TextControl
5966
label={ __( 'Content Warning', 'activitypub' ) }
6067
value={ meta?.activitypub_content_warning }
6168
onChange={ ( value ) => {
6269
setMeta( { ...meta, activitypub_content_warning: value } );
6370
} }
6471
placeholder={ __( 'Optional content warning', 'activitypub' ) }
65-
help={ __( 'Content warnings do not change the content on your site, only in the fediverse.', 'activitypub' ) }
72+
help={ __(
73+
'Content warnings do not change the content on your site, only in the fediverse.',
74+
'activitypub'
75+
) }
6676
/>
6777

6878
<RangeControl
6979
label={ __( 'Maximum Image Attachments', 'activitypub' ) }
70-
value={ meta?.activitypub_max_image_attachments ?? window._activityPubOptions?.maxImageAttachments ?? 4 }
80+
value={
81+
meta?.activitypub_max_image_attachments ?? window._activityPubOptions?.maxImageAttachments ?? 4
82+
}
7183
onChange={ ( value ) => {
7284
setMeta( { ...meta, activitypub_max_image_attachments: value } );
7385
} }
7486
min={ 0 }
7587
max={ 10 }
76-
help={ __( 'Maximum number of image attachments to include when sharing to the fediverse.', 'activitypub' ) }
88+
help={ __(
89+
'Maximum number of image attachments to include when sharing to the fediverse.',
90+
'activitypub'
91+
) }
7792
/>
7893

7994
<RadioControl
8095
label={ __( 'Visibility', 'activitypub' ) }
81-
help={ __( 'This adjusts the visibility of a post in the fediverse, but note that it won\'t affect how the post appears on the blog.', 'activitypub' ) }
96+
help={ __(
97+
"This adjusts the visibility of a post in the fediverse, but note that it won't affect how the post appears on the blog.",
98+
'activitypub'
99+
) }
82100
selected={ meta?.activitypub_content_visibility || 'public' }
83101
options={ [
84102
{
@@ -87,23 +105,26 @@ const EditorPlugin = () => {
87105
__( 'Public', 'activitypub' ),
88106
__( 'Post will be visible to everyone and appear in public timelines.', 'activitypub' )
89107
),
90-
value: 'public'
108+
value: 'public',
91109
},
92110
{
93111
label: enhancedLabel(
94112
people,
95113
__( 'Quiet public', 'activitypub' ),
96-
__( 'Post will be visible to everyone but will not appear in public timelines.', 'activitypub' )
114+
__(
115+
'Post will be visible to everyone but will not appear in public timelines.',
116+
'activitypub'
117+
)
97118
),
98-
value: 'quiet_public'
119+
value: 'quiet_public',
99120
},
100121
{
101122
label: enhancedLabel(
102123
notAllowed,
103124
__( 'Do not federate', 'activitypub' ),
104125
__( 'Post will not be shared to the Fediverse.', 'activitypub' )
105126
),
106-
value: 'local'
127+
value: 'local',
107128
},
108129
] }
109130
onChange={ ( value ) => {
@@ -113,15 +134,23 @@ const EditorPlugin = () => {
113134
/>
114135
</PluginDocumentSettingPanel>
115136
);
116-
}
137+
};
117138

139+
/**
140+
* Opens the Fediverse preview for the current post in a new tab.
141+
*/
118142
function onActivityPubPreview() {
119143
const previewLink = select( 'core/editor' ).getEditedPostPreviewLink();
120144
const fediversePreviewLink = addQueryArgs( previewLink, { activitypub: 'true' } );
121145

122146
window.open( fediversePreviewLink, '_blank' );
123147
}
124148

149+
/**
150+
* Renders the preview menu item for Fediverse preview.
151+
*
152+
* @returns {JSX.Element} The preview menu item component.
153+
*/
125154
const EditorPreview = () => {
126155
// check if post was saved
127156
const post_status = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost().status );

0 commit comments

Comments
 (0)