-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathedit.js
237 lines (216 loc) · 6.09 KB
/
edit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
AlignmentControl,
BlockControls,
Warning,
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __, sprintf } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
export default function PostCommentsEdit( {
attributes: { textAlign },
setAttributes,
context: { postType, postId },
} ) {
let [ postTitle ] = useEntityProp( 'postType', postType, 'title', postId );
postTitle = postTitle || __( 'Post Title' );
const [ commentStatus ] = useEntityProp(
'postType',
postType,
'comment_status',
postId
);
const { avatarURL, defaultCommentStatus } = useSelect(
( select ) =>
select( blockEditorStore ).getSettings()
.__experimentalDiscussionSettings
);
const isSiteEditor = postType === undefined || postId === undefined;
const postTypeSupportsComments = useSelect( ( select ) =>
postType
? !! select( coreStore ).getPostType( postType )?.supports.comments
: false
);
let warning = __(
'Post Comments block: This is just a placeholder, not a real comment. The final styling may differ because it also depends on the current theme. For better compatibility with the Block Editor, please consider replacing this block with the "Comments Query Loop" block.'
);
let showPlacholder = true;
if ( ! isSiteEditor && 'open' !== commentStatus ) {
if ( 'closed' === commentStatus ) {
warning = sprintf(
/* translators: 1: Post type (i.e. "post", "page") */
__(
'Post Comments block: Comments to this %s are not allowed.'
),
postType
);
showPlacholder = false;
} else if ( ! postTypeSupportsComments ) {
warning = sprintf(
/* translators: 1: Post type (i.e. "post", "page") */
__(
'Post Comments block: Comments for this post type (%s) are not enabled.'
),
postType
);
showPlacholder = false;
} else if ( 'open' !== defaultCommentStatus ) {
warning = __( 'Post Comments block: Comments are not enabled.' );
showPlacholder = false;
}
}
const blockProps = useBlockProps( {
className: classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
} );
const disabledRef = useDisabled();
return (
<>
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
<div { ...blockProps }>
<Warning>{ warning }</Warning>
{ showPlacholder && (
<div
className="wp-block-post-comments__placeholder"
ref={ disabledRef }
>
<h3>
{ __( 'One response to' ) } “{ postTitle }”
</h3>
<div className="navigation">
<div className="alignleft">
<a href="#top">« { __( 'Older Comments' ) }</a>
</div>
<div className="alignright">
<a href="#top">{ __( 'Newer Comments' ) } »</a>
</div>
</div>
<ol className="commentlist">
<li className="comment even thread-even depth-1">
<article className="comment-body">
<footer className="comment-meta">
<div className="comment-author vcard">
<img
alt="Commenter Avatar"
src={ avatarURL }
className="avatar avatar-32 photo"
height="32"
width="32"
loading="lazy"
/>
<b className="fn">
<a href="#top" className="url">
{ __(
'A WordPress Commenter'
) }
</a>
</b>{ ' ' }
<span className="says">
{ __( 'says' ) }:
</span>
</div>
<div className="comment-metadata">
<a href="#top">
<time dateTime="2000-01-01T00:00:00+00:00">
{ __(
'January 1, 2000 at 00:00 am'
) }
</time>
</a>{ ' ' }
<span className="edit-link">
<a
className="comment-edit-link"
href="#top"
>
{ __( 'Edit' ) }
</a>
</span>
</div>
</footer>
<div className="comment-content">
<p>
{ __( 'Hi, this is a comment.' ) }
<br />
{ __(
'To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.'
) }
<br />
{ __(
'Commenter avatars come from'
) }{ ' ' }
<a href="https://gravatar.com/">
Gravatar
</a>
.
</p>
</div>
<div className="reply">
<a
className="comment-reply-link"
href="#top"
aria-label="Reply to A WordPress Commenter"
>
{ __( 'Reply' ) }
</a>
</div>
</article>
</li>
</ol>
<div className="navigation">
<div className="alignleft">
<a href="#top">« { __( 'Older Comments' ) }</a>
</div>
<div className="alignright">
<a href="#top">{ __( 'Newer Comments' ) } »</a>
</div>
</div>
<div className="comment-respond">
<h3 className="comment-reply-title">
{ __( 'Leave a Reply' ) }
</h3>
<form className="comment-form" noValidate>
<p className="comment-form-comment">
<label htmlFor="comment">
{ __( 'Comment' ) }{ ' ' }
<span className="required">*</span>
</label>
<textarea
name="comment"
cols="45"
rows="8"
required
/>
</p>
<p className="form-submit wp-block-button">
<input
name="submit"
type="submit"
className="submit wp-block-button__link"
value={ __( 'Post Comment' ) }
/>
</p>
</form>
</div>
</div>
) }
</div>
</>
);
}