@wordpress/block-library 7.3.1 → 7.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/audio/edit.js +1 -1
- package/build/audio/edit.js.map +1 -1
- package/build/comment-template/edit.js +3 -1
- package/build/comment-template/edit.js.map +1 -1
- package/build/comment-template/hooks.js +14 -4
- package/build/comment-template/hooks.js.map +1 -1
- package/build/comments-pagination/edit.js +18 -1
- package/build/comments-pagination/edit.js.map +1 -1
- package/build/comments-query-loop/edit.js +2 -2
- package/build/comments-query-loop/edit.js.map +1 -1
- package/build/comments-title/edit.js +151 -0
- package/build/comments-title/edit.js.map +1 -0
- package/build/comments-title/index.js +101 -0
- package/build/comments-title/index.js.map +1 -0
- package/build/cover/transforms.js +33 -32
- package/build/cover/transforms.js.map +1 -1
- package/build/index.js +6 -4
- package/build/index.js.map +1 -1
- package/build/list/index.js +13 -2
- package/build/list/index.js.map +1 -1
- package/build/navigation/edit/index.js +17 -1
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/inner-blocks.js +5 -7
- package/build/navigation/edit/inner-blocks.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +7 -2
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/navigation-link/edit.js +29 -30
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-submenu/edit.js +14 -14
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/post-comments/edit.js +141 -35
- package/build/post-comments/edit.js.map +1 -1
- package/build/post-comments/index.js +2 -1
- package/build/post-comments/index.js.map +1 -1
- package/build/post-comments-form/edit.js +22 -1
- package/build/post-comments-form/edit.js.map +1 -1
- package/build/post-comments-form/index.js +1 -0
- package/build/post-comments-form/index.js.map +1 -1
- package/build/post-content/edit.js +1 -1
- package/build/post-content/edit.js.map +1 -1
- package/build/post-featured-image/edit.js +19 -7
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/query-no-results/edit.js +1 -1
- package/build/query-no-results/edit.js.map +1 -1
- package/build/quote/index.js +13 -2
- package/build/quote/index.js.map +1 -1
- package/build-module/audio/edit.js +1 -1
- package/build-module/audio/edit.js.map +1 -1
- package/build-module/comment-template/edit.js +3 -1
- package/build-module/comment-template/edit.js.map +1 -1
- package/build-module/comment-template/hooks.js +14 -4
- package/build-module/comment-template/hooks.js.map +1 -1
- package/build-module/comments-pagination/edit.js +19 -2
- package/build-module/comments-pagination/edit.js.map +1 -1
- package/build-module/comments-query-loop/edit.js +2 -2
- package/build-module/comments-query-loop/edit.js.map +1 -1
- package/build-module/comments-title/edit.js +135 -0
- package/build-module/comments-title/edit.js.map +1 -0
- package/build-module/comments-title/index.js +88 -0
- package/build-module/comments-title/index.js.map +1 -0
- package/build-module/cover/transforms.js +33 -32
- package/build-module/cover/transforms.js.map +1 -1
- package/build-module/index.js +5 -4
- package/build-module/index.js.map +1 -1
- package/build-module/list/index.js +9 -3
- package/build-module/list/index.js.map +1 -1
- package/build-module/navigation/edit/index.js +17 -1
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/inner-blocks.js +5 -7
- package/build-module/navigation/edit/inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +6 -2
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/navigation-link/edit.js +29 -30
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +14 -14
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/post-comments/edit.js +143 -38
- package/build-module/post-comments/edit.js.map +1 -1
- package/build-module/post-comments/index.js +2 -1
- package/build-module/post-comments/index.js.map +1 -1
- package/build-module/post-comments-form/edit.js +21 -1
- package/build-module/post-comments-form/edit.js.map +1 -1
- package/build-module/post-comments-form/index.js +1 -0
- package/build-module/post-comments-form/index.js.map +1 -1
- package/build-module/post-content/edit.js +1 -1
- package/build-module/post-content/edit.js.map +1 -1
- package/build-module/post-featured-image/edit.js +19 -7
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/query-no-results/edit.js +1 -1
- package/build-module/query-no-results/edit.js.map +1 -1
- package/build-module/quote/index.js +9 -3
- package/build-module/quote/index.js.map +1 -1
- package/build-style/comment-content/style-rtl.css +81 -0
- package/build-style/comment-content/style.css +81 -0
- package/build-style/comments-title/editor-rtl.css +79 -0
- package/build-style/comments-title/editor.css +79 -0
- package/build-style/cover/style-rtl.css +1 -1
- package/build-style/cover/style.css +1 -1
- package/build-style/editor-rtl.css +12 -0
- package/build-style/editor.css +12 -0
- package/build-style/latest-posts/style-rtl.css +2 -0
- package/build-style/latest-posts/style.css +4 -0
- package/build-style/post-comments/editor-rtl.css +79 -0
- package/build-style/post-comments/editor.css +79 -0
- package/build-style/post-comments/style-rtl.css +1 -3
- package/build-style/post-comments/style.css +1 -3
- package/build-style/post-comments-form/editor-rtl.css +79 -0
- package/build-style/post-comments-form/editor.css +79 -0
- package/build-style/post-comments-form/style-rtl.css +9 -0
- package/build-style/post-comments-form/style.css +9 -0
- package/build-style/style-rtl.css +13 -4
- package/build-style/style.css +15 -4
- package/package.json +28 -28
- package/src/audio/edit.js +1 -1
- package/src/comment-author-name/index.php +7 -5
- package/src/comment-content/index.php +25 -3
- package/src/comment-content/style.scss +5 -0
- package/src/comment-edit-link/index.php +1 -4
- package/src/comment-reply-link/index.php +1 -4
- package/src/comment-template/edit.js +5 -2
- package/src/comment-template/hooks.js +15 -2
- package/src/comment-template/index.php +23 -2
- package/src/comments-pagination/edit.js +23 -0
- package/src/comments-query-loop/edit.js +2 -0
- package/src/comments-title/block.json +70 -0
- package/src/comments-title/edit.js +213 -0
- package/src/comments-title/editor.scss +4 -0
- package/src/comments-title/index.js +18 -0
- package/src/comments-title/index.php +75 -0
- package/src/cover/index.php +1 -1
- package/src/cover/style.scss +1 -1
- package/src/cover/transforms.js +51 -28
- package/src/editor.scss +3 -0
- package/src/index.js +8 -2
- package/src/latest-posts/style.scss +4 -0
- package/src/list/index.js +7 -3
- package/src/navigation/edit/index.js +24 -0
- package/src/navigation/edit/inner-blocks.js +5 -7
- package/src/navigation/edit/navigation-menu-selector.js +15 -9
- package/src/navigation-link/edit.js +40 -43
- package/src/navigation-submenu/edit.js +13 -17
- package/src/post-comments/block.json +2 -1
- package/src/post-comments/edit.js +204 -44
- package/src/post-comments/editor.scss +3 -0
- package/src/post-comments/style.scss +1 -5
- package/src/post-comments-form/block.json +1 -0
- package/src/post-comments-form/edit.js +39 -2
- package/src/post-comments-form/editor.scss +3 -0
- package/src/post-comments-form/index.php +16 -5
- package/src/post-comments-form/style.scss +11 -0
- package/src/post-content/edit.js +15 -1
- package/src/post-featured-image/edit.js +24 -12
- package/src/query-no-results/edit.js +1 -1
- package/src/quote/index.js +7 -3
|
@@ -342,7 +342,35 @@ function navStripHTML( html ) {
|
|
|
342
342
|
* Add transforms to Link Control
|
|
343
343
|
*/
|
|
344
344
|
|
|
345
|
-
function LinkControlTransforms( {
|
|
345
|
+
function LinkControlTransforms( { clientId, replace } ) {
|
|
346
|
+
const { getBlock, blockTransforms } = useSelect(
|
|
347
|
+
( select ) => {
|
|
348
|
+
const {
|
|
349
|
+
getBlock: _getBlock,
|
|
350
|
+
getBlockRootClientId,
|
|
351
|
+
getBlockTransformItems,
|
|
352
|
+
} = select( blockEditorStore );
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
getBlock: _getBlock,
|
|
356
|
+
blockTransforms: getBlockTransformItems(
|
|
357
|
+
[ _getBlock( clientId ) ],
|
|
358
|
+
getBlockRootClientId( clientId )
|
|
359
|
+
),
|
|
360
|
+
};
|
|
361
|
+
},
|
|
362
|
+
[ clientId ]
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
const featuredBlocks = [
|
|
366
|
+
'core/site-logo',
|
|
367
|
+
'core/social-links',
|
|
368
|
+
'core/search',
|
|
369
|
+
];
|
|
370
|
+
const transforms = blockTransforms.filter( ( item ) => {
|
|
371
|
+
return featuredBlocks.includes( item.name );
|
|
372
|
+
} );
|
|
373
|
+
|
|
346
374
|
if ( ! transforms?.length ) {
|
|
347
375
|
return null;
|
|
348
376
|
}
|
|
@@ -359,8 +387,11 @@ function LinkControlTransforms( { block, transforms, replace } ) {
|
|
|
359
387
|
key={ `transform-${ index }` }
|
|
360
388
|
onClick={ () =>
|
|
361
389
|
replace(
|
|
362
|
-
|
|
363
|
-
switchToBlockType(
|
|
390
|
+
clientId,
|
|
391
|
+
switchToBlockType(
|
|
392
|
+
getBlock( clientId ),
|
|
393
|
+
item.name
|
|
394
|
+
)
|
|
364
395
|
)
|
|
365
396
|
}
|
|
366
397
|
className="link-control-transform__item"
|
|
@@ -421,30 +452,20 @@ export default function NavigationLinkEdit( {
|
|
|
421
452
|
isAtMaxNesting,
|
|
422
453
|
isTopLevelLink,
|
|
423
454
|
isParentOfSelectedBlock,
|
|
424
|
-
|
|
455
|
+
hasChildren,
|
|
425
456
|
userCanCreatePages,
|
|
426
457
|
userCanCreatePosts,
|
|
427
|
-
thisBlock,
|
|
428
|
-
blockTransforms,
|
|
429
458
|
} = useSelect(
|
|
430
459
|
( select ) => {
|
|
431
460
|
const {
|
|
432
|
-
getBlock,
|
|
433
461
|
getBlocks,
|
|
462
|
+
getBlockCount,
|
|
434
463
|
getBlockName,
|
|
435
464
|
getBlockRootClientId,
|
|
436
|
-
getClientIdsOfDescendants,
|
|
437
465
|
hasSelectedInnerBlock,
|
|
438
|
-
getSelectedBlockClientId,
|
|
439
466
|
getBlockParentsByBlockName,
|
|
440
|
-
getBlockTransformItems,
|
|
441
467
|
} = select( blockEditorStore );
|
|
442
468
|
|
|
443
|
-
const selectedBlockId = getSelectedBlockClientId();
|
|
444
|
-
|
|
445
|
-
const descendants = getClientIdsOfDescendants( [ clientId ] )
|
|
446
|
-
.length;
|
|
447
|
-
|
|
448
469
|
return {
|
|
449
470
|
innerBlocks: getBlocks( clientId ),
|
|
450
471
|
isAtMaxNesting:
|
|
@@ -459,14 +480,7 @@ export default function NavigationLinkEdit( {
|
|
|
459
480
|
clientId,
|
|
460
481
|
true
|
|
461
482
|
),
|
|
462
|
-
|
|
463
|
-
clientId,
|
|
464
|
-
false
|
|
465
|
-
),
|
|
466
|
-
hasDescendants: !! descendants,
|
|
467
|
-
selectedBlockHasDescendants: !! getClientIdsOfDescendants( [
|
|
468
|
-
selectedBlockId,
|
|
469
|
-
] )?.length,
|
|
483
|
+
hasChildren: !! getBlockCount( clientId ),
|
|
470
484
|
userCanCreatePages: select( coreStore ).canUser(
|
|
471
485
|
'create',
|
|
472
486
|
'pages'
|
|
@@ -475,11 +489,6 @@ export default function NavigationLinkEdit( {
|
|
|
475
489
|
'create',
|
|
476
490
|
'posts'
|
|
477
491
|
),
|
|
478
|
-
thisBlock: getBlock( clientId ),
|
|
479
|
-
blockTransforms: getBlockTransformItems(
|
|
480
|
-
[ getBlock( clientId ) ],
|
|
481
|
-
getBlockRootClientId( clientId )
|
|
482
|
-
),
|
|
483
492
|
};
|
|
484
493
|
},
|
|
485
494
|
[ clientId ]
|
|
@@ -506,15 +515,6 @@ export default function NavigationLinkEdit( {
|
|
|
506
515
|
replaceBlock( clientId, newSubmenu );
|
|
507
516
|
}
|
|
508
517
|
|
|
509
|
-
const featuredBlocks = [
|
|
510
|
-
'core/site-logo',
|
|
511
|
-
'core/social-links',
|
|
512
|
-
'core/search',
|
|
513
|
-
];
|
|
514
|
-
const featuredTransforms = blockTransforms.filter( ( item ) => {
|
|
515
|
-
return featuredBlocks.includes( item.name );
|
|
516
|
-
} );
|
|
517
|
-
|
|
518
518
|
useEffect( () => {
|
|
519
519
|
// Show the LinkControl on mount if the URL is empty
|
|
520
520
|
// ( When adding a new menu item)
|
|
@@ -524,7 +524,7 @@ export default function NavigationLinkEdit( {
|
|
|
524
524
|
setIsLinkOpen( true );
|
|
525
525
|
}
|
|
526
526
|
// If block has inner blocks, transform to Submenu.
|
|
527
|
-
if (
|
|
527
|
+
if ( hasChildren ) {
|
|
528
528
|
transformToSubmenu();
|
|
529
529
|
}
|
|
530
530
|
}, [] );
|
|
@@ -634,7 +634,7 @@ export default function NavigationLinkEdit( {
|
|
|
634
634
|
'is-editing': isSelected || isParentOfSelectedBlock,
|
|
635
635
|
'is-dragging-within': isDraggingWithin,
|
|
636
636
|
'has-link': !! url,
|
|
637
|
-
'has-child':
|
|
637
|
+
'has-child': hasChildren,
|
|
638
638
|
'has-text-color': !! textColor || !! customTextColor,
|
|
639
639
|
[ getColorClassName( 'color', textColor ) ]: !! textColor,
|
|
640
640
|
'has-background': !! backgroundColor || customBackgroundColor,
|
|
@@ -860,10 +860,7 @@ export default function NavigationLinkEdit( {
|
|
|
860
860
|
! url
|
|
861
861
|
? () => (
|
|
862
862
|
<LinkControlTransforms
|
|
863
|
-
|
|
864
|
-
transforms={
|
|
865
|
-
featuredTransforms
|
|
866
|
-
}
|
|
863
|
+
clientId={ clientId }
|
|
867
864
|
replace={ replaceBlock }
|
|
868
865
|
/>
|
|
869
866
|
)
|
|
@@ -309,37 +309,33 @@ export default function NavigationSubmenuEdit( {
|
|
|
309
309
|
isTopLevelItem,
|
|
310
310
|
isParentOfSelectedBlock,
|
|
311
311
|
isImmediateParentOfSelectedBlock,
|
|
312
|
-
|
|
313
|
-
|
|
312
|
+
hasChildren,
|
|
313
|
+
selectedBlockHasChildren,
|
|
314
314
|
userCanCreatePages,
|
|
315
315
|
userCanCreatePosts,
|
|
316
316
|
onlyDescendantIsEmptyLink,
|
|
317
317
|
} = useSelect(
|
|
318
318
|
( select ) => {
|
|
319
319
|
const {
|
|
320
|
-
getClientIdsOfDescendants,
|
|
321
320
|
hasSelectedInnerBlock,
|
|
322
321
|
getSelectedBlockClientId,
|
|
323
322
|
getBlockParentsByBlockName,
|
|
324
323
|
getBlock,
|
|
324
|
+
getBlockCount,
|
|
325
|
+
getBlockOrder,
|
|
325
326
|
} = select( blockEditorStore );
|
|
326
327
|
|
|
327
328
|
let _onlyDescendantIsEmptyLink;
|
|
328
329
|
|
|
329
330
|
const selectedBlockId = getSelectedBlockClientId();
|
|
330
331
|
|
|
331
|
-
const
|
|
332
|
-
.length;
|
|
333
|
-
|
|
334
|
-
const selectedBlockDescendants = getClientIdsOfDescendants( [
|
|
335
|
-
selectedBlockId,
|
|
336
|
-
] );
|
|
332
|
+
const selectedBlockChildren = getBlockOrder( selectedBlockId );
|
|
337
333
|
|
|
338
334
|
// Check for a single descendant in the submenu. If that block
|
|
339
335
|
// is a link block in a "placeholder" state with no label then
|
|
340
336
|
// we can consider as an "empty" link.
|
|
341
|
-
if (
|
|
342
|
-
const singleBlock = getBlock(
|
|
337
|
+
if ( selectedBlockChildren?.length === 1 ) {
|
|
338
|
+
const singleBlock = getBlock( selectedBlockChildren[ 0 ] );
|
|
343
339
|
|
|
344
340
|
_onlyDescendantIsEmptyLink =
|
|
345
341
|
singleBlock?.name === 'core/navigation-link' &&
|
|
@@ -360,8 +356,8 @@ export default function NavigationSubmenuEdit( {
|
|
|
360
356
|
clientId,
|
|
361
357
|
false
|
|
362
358
|
),
|
|
363
|
-
|
|
364
|
-
|
|
359
|
+
hasChildren: !! getBlockCount( clientId ),
|
|
360
|
+
selectedBlockHasChildren: !! selectedBlockChildren?.length,
|
|
365
361
|
userCanCreatePages: select( coreStore ).canUser(
|
|
366
362
|
'create',
|
|
367
363
|
'pages'
|
|
@@ -481,7 +477,7 @@ export default function NavigationSubmenuEdit( {
|
|
|
481
477
|
'is-editing': isSelected || isParentOfSelectedBlock,
|
|
482
478
|
'is-dragging-within': isDraggingWithin,
|
|
483
479
|
'has-link': !! url,
|
|
484
|
-
'has-child':
|
|
480
|
+
'has-child': hasChildren,
|
|
485
481
|
'has-text-color': !! textColor || !! customTextColor,
|
|
486
482
|
[ getColorClassName( 'color', textColor ) ]: !! textColor,
|
|
487
483
|
'has-background': !! backgroundColor || customBackgroundColor,
|
|
@@ -538,9 +534,9 @@ export default function NavigationSubmenuEdit( {
|
|
|
538
534
|
renderAppender:
|
|
539
535
|
isSelected ||
|
|
540
536
|
( isImmediateParentOfSelectedBlock &&
|
|
541
|
-
!
|
|
537
|
+
! selectedBlockHasChildren ) ||
|
|
542
538
|
// Show the appender while dragging to allow inserting element between item and the appender.
|
|
543
|
-
|
|
539
|
+
hasChildren
|
|
544
540
|
? InnerBlocks.ButtonBlockAppender
|
|
545
541
|
: false,
|
|
546
542
|
}
|
|
@@ -554,7 +550,7 @@ export default function NavigationSubmenuEdit( {
|
|
|
554
550
|
}
|
|
555
551
|
|
|
556
552
|
const canConvertToLink =
|
|
557
|
-
!
|
|
553
|
+
! selectedBlockHasChildren || onlyDescendantIsEmptyLink;
|
|
558
554
|
|
|
559
555
|
return (
|
|
560
556
|
<Fragment>
|
|
@@ -6,65 +6,89 @@ import classnames from 'classnames';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { useSelect } from '@wordpress/data';
|
|
10
9
|
import {
|
|
11
10
|
AlignmentControl,
|
|
12
11
|
BlockControls,
|
|
13
12
|
Warning,
|
|
14
13
|
useBlockProps,
|
|
14
|
+
store as blockEditorStore,
|
|
15
15
|
} from '@wordpress/block-editor';
|
|
16
|
-
import { __ } from '@wordpress/i18n';
|
|
17
|
-
import {
|
|
18
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const comments = select( coreStore ).getEntityRecords(
|
|
24
|
-
'root',
|
|
25
|
-
'comment',
|
|
26
|
-
{
|
|
27
|
-
post: postId,
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
// TODO: "No Comments" placeholder should be editable.
|
|
31
|
-
return comments && comments.length
|
|
32
|
-
? comments.map( ( comment ) => (
|
|
33
|
-
<RawHTML
|
|
34
|
-
className="wp-block-post-comments__comment"
|
|
35
|
-
key={ comment.id }
|
|
36
|
-
>
|
|
37
|
-
{ comment.content.rendered }
|
|
38
|
-
</RawHTML>
|
|
39
|
-
) )
|
|
40
|
-
: __( 'No comments.' );
|
|
41
|
-
},
|
|
42
|
-
[ postId ]
|
|
43
|
-
);
|
|
44
|
-
}
|
|
16
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
17
|
+
import { useSelect } from '@wordpress/data';
|
|
18
|
+
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
|
|
19
|
+
import {
|
|
20
|
+
__experimentalUseDisabled as useDisabled,
|
|
21
|
+
useInstanceId,
|
|
22
|
+
} from '@wordpress/compose';
|
|
45
23
|
|
|
46
24
|
export default function PostCommentsEdit( {
|
|
47
|
-
attributes,
|
|
25
|
+
attributes: { textAlign },
|
|
48
26
|
setAttributes,
|
|
49
|
-
context,
|
|
27
|
+
context: { postType, postId },
|
|
50
28
|
} ) {
|
|
51
|
-
|
|
52
|
-
|
|
29
|
+
let [ postTitle ] = useEntityProp( 'postType', postType, 'title', postId );
|
|
30
|
+
postTitle = postTitle || __( 'Post Title' );
|
|
31
|
+
|
|
32
|
+
const [ commentStatus ] = useEntityProp(
|
|
33
|
+
'postType',
|
|
34
|
+
postType,
|
|
35
|
+
'comment_status',
|
|
36
|
+
postId
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const { avatarURL, defaultCommentStatus } = useSelect(
|
|
40
|
+
( select ) =>
|
|
41
|
+
select( blockEditorStore ).getSettings()
|
|
42
|
+
.__experimentalDiscussionSettings
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const isSiteEditor = postType === undefined || postId === undefined;
|
|
46
|
+
|
|
47
|
+
const postTypeSupportsComments = useSelect( ( select ) =>
|
|
48
|
+
postType
|
|
49
|
+
? !! select( coreStore ).getPostType( postType )?.supports.comments
|
|
50
|
+
: false
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
let warning = __(
|
|
54
|
+
'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.'
|
|
55
|
+
);
|
|
56
|
+
let showPlacholder = true;
|
|
57
|
+
|
|
58
|
+
if ( ! isSiteEditor && 'open' !== commentStatus ) {
|
|
59
|
+
if ( 'closed' === commentStatus ) {
|
|
60
|
+
warning = sprintf(
|
|
61
|
+
/* translators: 1: Post type (i.e. "post", "page") */
|
|
62
|
+
__(
|
|
63
|
+
'Post Comments block: Comments to this %s are not allowed.'
|
|
64
|
+
),
|
|
65
|
+
postType
|
|
66
|
+
);
|
|
67
|
+
showPlacholder = false;
|
|
68
|
+
} else if ( ! postTypeSupportsComments ) {
|
|
69
|
+
warning = sprintf(
|
|
70
|
+
/* translators: 1: Post type (i.e. "post", "page") */
|
|
71
|
+
__(
|
|
72
|
+
'Post Comments block: Comments for this post type (%s) are not enabled.'
|
|
73
|
+
),
|
|
74
|
+
postType
|
|
75
|
+
);
|
|
76
|
+
showPlacholder = false;
|
|
77
|
+
} else if ( 'open' !== defaultCommentStatus ) {
|
|
78
|
+
warning = __( 'Post Comments block: Comments are not enabled.' );
|
|
79
|
+
showPlacholder = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
53
83
|
const blockProps = useBlockProps( {
|
|
54
84
|
className: classnames( {
|
|
55
85
|
[ `has-text-align-${ textAlign }` ]: textAlign,
|
|
56
86
|
} ),
|
|
57
87
|
} );
|
|
58
88
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
<Warning>
|
|
63
|
-
{ __( 'Post comments block: no post found.' ) }
|
|
64
|
-
</Warning>
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
89
|
+
const disabledRef = useDisabled();
|
|
90
|
+
|
|
91
|
+
const textareaId = useInstanceId( PostCommentsEdit );
|
|
68
92
|
|
|
69
93
|
return (
|
|
70
94
|
<>
|
|
@@ -78,7 +102,143 @@ export default function PostCommentsEdit( {
|
|
|
78
102
|
</BlockControls>
|
|
79
103
|
|
|
80
104
|
<div { ...blockProps }>
|
|
81
|
-
<
|
|
105
|
+
<Warning>{ warning }</Warning>
|
|
106
|
+
|
|
107
|
+
{ showPlacholder && (
|
|
108
|
+
<div
|
|
109
|
+
className="wp-block-post-comments__placeholder"
|
|
110
|
+
ref={ disabledRef }
|
|
111
|
+
>
|
|
112
|
+
<h3>
|
|
113
|
+
{ __( 'One response to' ) } “{ postTitle }”
|
|
114
|
+
</h3>
|
|
115
|
+
|
|
116
|
+
<div className="navigation">
|
|
117
|
+
<div className="alignleft">
|
|
118
|
+
<a href="#top">« { __( 'Older Comments' ) }</a>
|
|
119
|
+
</div>
|
|
120
|
+
<div className="alignright">
|
|
121
|
+
<a href="#top">{ __( 'Newer Comments' ) } »</a>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<ol className="commentlist">
|
|
126
|
+
<li className="comment even thread-even depth-1">
|
|
127
|
+
<article className="comment-body">
|
|
128
|
+
<footer className="comment-meta">
|
|
129
|
+
<div className="comment-author vcard">
|
|
130
|
+
<img
|
|
131
|
+
alt="Commenter Avatar"
|
|
132
|
+
src={ avatarURL }
|
|
133
|
+
className="avatar avatar-32 photo"
|
|
134
|
+
height="32"
|
|
135
|
+
width="32"
|
|
136
|
+
loading="lazy"
|
|
137
|
+
/>
|
|
138
|
+
<b className="fn">
|
|
139
|
+
<a href="#top" className="url">
|
|
140
|
+
{ __(
|
|
141
|
+
'A WordPress Commenter'
|
|
142
|
+
) }
|
|
143
|
+
</a>
|
|
144
|
+
</b>{ ' ' }
|
|
145
|
+
<span className="says">
|
|
146
|
+
{ __( 'says' ) }:
|
|
147
|
+
</span>
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
<div className="comment-metadata">
|
|
151
|
+
<a href="#top">
|
|
152
|
+
<time dateTime="2000-01-01T00:00:00+00:00">
|
|
153
|
+
{ __(
|
|
154
|
+
'January 1, 2000 at 00:00 am'
|
|
155
|
+
) }
|
|
156
|
+
</time>
|
|
157
|
+
</a>{ ' ' }
|
|
158
|
+
<span className="edit-link">
|
|
159
|
+
<a
|
|
160
|
+
className="comment-edit-link"
|
|
161
|
+
href="#top"
|
|
162
|
+
>
|
|
163
|
+
{ __( 'Edit' ) }
|
|
164
|
+
</a>
|
|
165
|
+
</span>
|
|
166
|
+
</div>
|
|
167
|
+
</footer>
|
|
168
|
+
|
|
169
|
+
<div className="comment-content">
|
|
170
|
+
<p>
|
|
171
|
+
{ __( 'Hi, this is a comment.' ) }
|
|
172
|
+
<br />
|
|
173
|
+
{ __(
|
|
174
|
+
'To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.'
|
|
175
|
+
) }
|
|
176
|
+
<br />
|
|
177
|
+
{ __(
|
|
178
|
+
'Commenter avatars come from'
|
|
179
|
+
) }{ ' ' }
|
|
180
|
+
<a href="https://gravatar.com/">
|
|
181
|
+
Gravatar
|
|
182
|
+
</a>
|
|
183
|
+
.
|
|
184
|
+
</p>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<div className="reply">
|
|
188
|
+
<a
|
|
189
|
+
className="comment-reply-link"
|
|
190
|
+
href="#top"
|
|
191
|
+
aria-label="Reply to A WordPress Commenter"
|
|
192
|
+
>
|
|
193
|
+
{ __( 'Reply' ) }
|
|
194
|
+
</a>
|
|
195
|
+
</div>
|
|
196
|
+
</article>
|
|
197
|
+
</li>
|
|
198
|
+
</ol>
|
|
199
|
+
|
|
200
|
+
<div className="navigation">
|
|
201
|
+
<div className="alignleft">
|
|
202
|
+
<a href="#top">« { __( 'Older Comments' ) }</a>
|
|
203
|
+
</div>
|
|
204
|
+
<div className="alignright">
|
|
205
|
+
<a href="#top">{ __( 'Newer Comments' ) } »</a>
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
|
|
209
|
+
<div className="comment-respond">
|
|
210
|
+
<h3 className="comment-reply-title">
|
|
211
|
+
{ __( 'Leave a Reply' ) }
|
|
212
|
+
</h3>
|
|
213
|
+
|
|
214
|
+
<form className="comment-form" noValidate>
|
|
215
|
+
<p className="comment-form-comment">
|
|
216
|
+
<label
|
|
217
|
+
htmlFor={ `comment-${ textareaId }` }
|
|
218
|
+
>
|
|
219
|
+
{ __( 'Comment' ) }{ ' ' }
|
|
220
|
+
<span className="required">*</span>
|
|
221
|
+
</label>
|
|
222
|
+
<textarea
|
|
223
|
+
id={ `comment-${ textareaId }` }
|
|
224
|
+
name="comment"
|
|
225
|
+
cols="45"
|
|
226
|
+
rows="8"
|
|
227
|
+
required
|
|
228
|
+
/>
|
|
229
|
+
</p>
|
|
230
|
+
<p className="form-submit wp-block-button">
|
|
231
|
+
<input
|
|
232
|
+
name="submit"
|
|
233
|
+
type="submit"
|
|
234
|
+
className="submit wp-block-button__link"
|
|
235
|
+
value={ __( 'Post Comment' ) }
|
|
236
|
+
/>
|
|
237
|
+
</p>
|
|
238
|
+
</form>
|
|
239
|
+
</div>
|
|
240
|
+
</div>
|
|
241
|
+
) }
|
|
82
242
|
</div>
|
|
83
243
|
</>
|
|
84
244
|
);
|
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
} from '@wordpress/block-editor';
|
|
15
15
|
import { useEntityProp } from '@wordpress/core-data';
|
|
16
16
|
import { __, sprintf } from '@wordpress/i18n';
|
|
17
|
+
import {
|
|
18
|
+
__experimentalUseDisabled as useDisabled,
|
|
19
|
+
useInstanceId,
|
|
20
|
+
} from '@wordpress/compose';
|
|
17
21
|
|
|
18
22
|
export default function PostCommentsFormEdit( {
|
|
19
23
|
attributes,
|
|
@@ -36,6 +40,10 @@ export default function PostCommentsFormEdit( {
|
|
|
36
40
|
|
|
37
41
|
const isInSiteEditor = postType === undefined || postId === undefined;
|
|
38
42
|
|
|
43
|
+
const disabledFormRef = useDisabled();
|
|
44
|
+
|
|
45
|
+
const instanceId = useInstanceId( PostCommentsFormEdit );
|
|
46
|
+
|
|
39
47
|
return (
|
|
40
48
|
<>
|
|
41
49
|
<BlockControls group="block">
|
|
@@ -67,8 +75,37 @@ export default function PostCommentsFormEdit( {
|
|
|
67
75
|
</Warning>
|
|
68
76
|
) }
|
|
69
77
|
|
|
70
|
-
{ ( 'open' === commentStatus || isInSiteEditor ) &&
|
|
71
|
-
|
|
78
|
+
{ ( 'open' === commentStatus || isInSiteEditor ) && (
|
|
79
|
+
<div>
|
|
80
|
+
<h3>{ __( 'Leave a Reply' ) }</h3>
|
|
81
|
+
<form
|
|
82
|
+
noValidate
|
|
83
|
+
className="comment-form"
|
|
84
|
+
ref={ disabledFormRef }
|
|
85
|
+
>
|
|
86
|
+
<p>
|
|
87
|
+
<label htmlFor={ `comment-${ instanceId }` }>
|
|
88
|
+
{ __( 'Comment' ) }
|
|
89
|
+
</label>
|
|
90
|
+
<textarea
|
|
91
|
+
id={ `comment-${ instanceId }` }
|
|
92
|
+
name="comment"
|
|
93
|
+
cols="45"
|
|
94
|
+
rows="8"
|
|
95
|
+
/>
|
|
96
|
+
</p>
|
|
97
|
+
<p>
|
|
98
|
+
<input
|
|
99
|
+
name="submit"
|
|
100
|
+
className="submit wp-block-button__link"
|
|
101
|
+
label={ __( 'Post Comment' ) }
|
|
102
|
+
value={ __( 'Post Comment' ) }
|
|
103
|
+
readOnly
|
|
104
|
+
/>
|
|
105
|
+
</p>
|
|
106
|
+
</form>
|
|
107
|
+
</div>
|
|
108
|
+
) }
|
|
72
109
|
</div>
|
|
73
110
|
</>
|
|
74
111
|
);
|
|
@@ -18,20 +18,32 @@ function render_block_core_post_comments_form( $attributes, $content, $block ) {
|
|
|
18
18
|
return '';
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
$classes = '';
|
|
21
|
+
$classes = 'comment-respond'; // See comment further below.
|
|
22
22
|
if ( isset( $attributes['textAlign'] ) ) {
|
|
23
23
|
$classes .= 'has-text-align-' . $attributes['textAlign'];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
|
|
27
|
+
|
|
28
|
+
add_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' );
|
|
29
|
+
|
|
26
30
|
ob_start();
|
|
27
31
|
comment_form( array(), $block->context['postId'] );
|
|
28
|
-
$form
|
|
29
|
-
|
|
32
|
+
$form = ob_get_clean();
|
|
33
|
+
|
|
34
|
+
remove_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' );
|
|
35
|
+
|
|
36
|
+
// We use the outermost wrapping `<div />` returned by `comment_form()`
|
|
37
|
+
// which is identified by its default classname `comment-respond` to inject
|
|
38
|
+
// our wrapper attributes. This way, it is guaranteed that all styling applied
|
|
39
|
+
// to the block is carried along when the comment form is moved to the location
|
|
40
|
+
// of the 'Reply' link that the user clicked by Core's `comment-reply.js` script.
|
|
41
|
+
$form = str_replace( 'class="comment-respond"', $wrapper_attributes, $form );
|
|
30
42
|
|
|
31
43
|
// Enqueue the comment-reply script.
|
|
32
44
|
wp_enqueue_script( 'comment-reply' );
|
|
33
45
|
|
|
34
|
-
return
|
|
46
|
+
return $form;
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
/**
|
|
@@ -62,4 +74,3 @@ function post_comments_form_block_form_defaults( $fields ) {
|
|
|
62
74
|
|
|
63
75
|
return $fields;
|
|
64
76
|
}
|
|
65
|
-
add_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' );
|
|
@@ -67,4 +67,15 @@
|
|
|
67
67
|
margin-top: 0.35em;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
.comment-reply-title {
|
|
72
|
+
align-items: baseline;
|
|
73
|
+
display: flex;
|
|
74
|
+
justify-content: space-between;
|
|
75
|
+
margin-bottom: 0;
|
|
76
|
+
|
|
77
|
+
:where(small) {
|
|
78
|
+
font-size: var(--wp--preset--font-size--medium, smaller);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
70
81
|
}
|