@wordpress/block-library 6.0.17 → 6.0.18
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/columns/index.js +1 -2
- package/build/columns/index.js.map +1 -1
- package/build/navigation/index.js +1 -5
- package/build/navigation/index.js.map +1 -1
- package/build/post-author/edit.js +1 -1
- package/build/post-author/edit.js.map +1 -1
- package/build/post-content/edit.js +1 -1
- package/build/post-content/edit.js.map +1 -1
- package/build/post-date/edit.js +1 -1
- package/build/post-date/edit.js.map +1 -1
- package/build/post-excerpt/edit.js +1 -1
- package/build/post-excerpt/edit.js.map +1 -1
- package/build/post-featured-image/edit.js +1 -1
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/post-title/edit.js +1 -1
- package/build/post-title/edit.js.map +1 -1
- package/build/site-logo/edit.js +108 -10
- package/build/site-logo/edit.js.map +1 -1
- package/build/site-logo/index.js +5 -1
- package/build/site-logo/index.js.map +1 -1
- package/build/template-part/index.js +25 -1
- package/build/template-part/index.js.map +1 -1
- package/build-module/columns/index.js +1 -2
- package/build-module/columns/index.js.map +1 -1
- package/build-module/navigation/index.js +1 -5
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/post-author/edit.js +1 -1
- package/build-module/post-author/edit.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-date/edit.js +1 -1
- package/build-module/post-date/edit.js.map +1 -1
- package/build-module/post-excerpt/edit.js +1 -1
- package/build-module/post-excerpt/edit.js.map +1 -1
- package/build-module/post-featured-image/edit.js +1 -1
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/post-title/edit.js +1 -1
- package/build-module/post-title/edit.js.map +1 -1
- package/build-module/site-logo/edit.js +109 -11
- package/build-module/site-logo/edit.js.map +1 -1
- package/build-module/site-logo/index.js +5 -1
- package/build-module/site-logo/index.js.map +1 -1
- package/build-module/template-part/index.js +25 -1
- package/build-module/template-part/index.js.map +1 -1
- package/build-style/editor-rtl.css +18 -8
- package/build-style/editor.css +18 -8
- package/build-style/navigation/editor-rtl.css +13 -6
- package/build-style/navigation/editor.css +13 -6
- package/package.json +7 -7
- package/src/columns/block.json +1 -2
- package/src/editor.scss +5 -2
- package/src/navigation/block.json +1 -11
- package/src/navigation/editor.scss +18 -8
- package/src/post-author/edit.js +1 -1
- package/src/post-content/edit.js +1 -1
- package/src/post-content/index.php +6 -1
- package/src/post-date/edit.js +1 -1
- package/src/post-excerpt/edit.js +1 -1
- package/src/post-excerpt/index.php +1 -1
- package/src/post-featured-image/edit.js +1 -1
- package/src/post-title/edit.js +1 -1
- package/src/post-title/index.php +1 -1
- package/src/site-logo/block.json +5 -1
- package/src/site-logo/edit.js +124 -7
- package/src/site-logo/index.php +17 -0
- package/src/template-part/index.js +28 -0
package/src/site-logo/edit.js
CHANGED
|
@@ -8,7 +8,12 @@ import { includes, pick } from 'lodash';
|
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { isBlobURL } from '@wordpress/blob';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
createInterpolateElement,
|
|
13
|
+
useEffect,
|
|
14
|
+
useState,
|
|
15
|
+
useRef,
|
|
16
|
+
} from '@wordpress/element';
|
|
12
17
|
import { __, isRTL } from '@wordpress/i18n';
|
|
13
18
|
import {
|
|
14
19
|
MenuItem,
|
|
@@ -53,7 +58,7 @@ const ACCEPT_MEDIA_STRING = 'image/*';
|
|
|
53
58
|
|
|
54
59
|
const SiteLogo = ( {
|
|
55
60
|
alt,
|
|
56
|
-
attributes: { align, width, height, isLink, linkTarget },
|
|
61
|
+
attributes: { align, width, height, isLink, linkTarget, shouldSyncIcon },
|
|
57
62
|
containerRef,
|
|
58
63
|
isSelected,
|
|
59
64
|
setAttributes,
|
|
@@ -61,6 +66,9 @@ const SiteLogo = ( {
|
|
|
61
66
|
logoUrl,
|
|
62
67
|
siteUrl,
|
|
63
68
|
logoId,
|
|
69
|
+
iconId,
|
|
70
|
+
setIcon,
|
|
71
|
+
canUserEdit,
|
|
64
72
|
} ) => {
|
|
65
73
|
const clientWidth = useClientWidth( containerRef, [ align ] );
|
|
66
74
|
const isLargeViewport = useViewportMatch( 'medium' );
|
|
@@ -84,6 +92,15 @@ const SiteLogo = ( {
|
|
|
84
92
|
};
|
|
85
93
|
}, [] );
|
|
86
94
|
|
|
95
|
+
useEffect( () => {
|
|
96
|
+
// Turn the `Use as site icon` toggle off if it is on but the logo and icon have
|
|
97
|
+
// fallen out of sync. This can happen if the toggle is saved in the `on` position,
|
|
98
|
+
// but changes are later made to the site icon in the Customizer.
|
|
99
|
+
if ( shouldSyncIcon && logoId !== iconId ) {
|
|
100
|
+
setAttributes( { shouldSyncIcon: false } );
|
|
101
|
+
}
|
|
102
|
+
}, [] );
|
|
103
|
+
|
|
87
104
|
useEffect( () => {
|
|
88
105
|
if ( ! isSelected ) {
|
|
89
106
|
setIsEditingImage( false );
|
|
@@ -250,6 +267,25 @@ const SiteLogo = ( {
|
|
|
250
267
|
</ResizableBox>
|
|
251
268
|
);
|
|
252
269
|
|
|
270
|
+
const syncSiteIconHelpText = createInterpolateElement(
|
|
271
|
+
__(
|
|
272
|
+
'Site Icons are what you see in browser tabs, bookmark bars, and within the WordPress mobile apps. To use a custom icon that is different from your site logo, use the <a>Site Icon settings</a>.'
|
|
273
|
+
),
|
|
274
|
+
{
|
|
275
|
+
a: (
|
|
276
|
+
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
277
|
+
<a
|
|
278
|
+
href={
|
|
279
|
+
siteUrl +
|
|
280
|
+
'/wp-admin/customize.php?autofocus[section]=title_tagline'
|
|
281
|
+
}
|
|
282
|
+
target="_blank"
|
|
283
|
+
rel="noopener noreferrer"
|
|
284
|
+
/>
|
|
285
|
+
),
|
|
286
|
+
}
|
|
287
|
+
);
|
|
288
|
+
|
|
253
289
|
return (
|
|
254
290
|
<>
|
|
255
291
|
<InspectorControls>
|
|
@@ -286,6 +322,19 @@ const SiteLogo = ( {
|
|
|
286
322
|
/>
|
|
287
323
|
</>
|
|
288
324
|
) }
|
|
325
|
+
{ canUserEdit && (
|
|
326
|
+
<>
|
|
327
|
+
<ToggleControl
|
|
328
|
+
label={ __( 'Use as site icon' ) }
|
|
329
|
+
onChange={ ( value ) => {
|
|
330
|
+
setAttributes( { shouldSyncIcon: value } );
|
|
331
|
+
setIcon( value ? logoId : undefined );
|
|
332
|
+
} }
|
|
333
|
+
checked={ !! shouldSyncIcon }
|
|
334
|
+
help={ syncSiteIconHelpText }
|
|
335
|
+
/>
|
|
336
|
+
</>
|
|
337
|
+
) }
|
|
289
338
|
</PanelBody>
|
|
290
339
|
</InspectorControls>
|
|
291
340
|
<BlockControls group="block">
|
|
@@ -308,7 +357,7 @@ export default function LogoEdit( {
|
|
|
308
357
|
setAttributes,
|
|
309
358
|
isSelected,
|
|
310
359
|
} ) {
|
|
311
|
-
const { width } = attributes;
|
|
360
|
+
const { className: styleClass, width, shouldSyncIcon } = attributes;
|
|
312
361
|
const [ logoUrl, setLogoUrl ] = useState();
|
|
313
362
|
const ref = useRef();
|
|
314
363
|
|
|
@@ -316,6 +365,7 @@ export default function LogoEdit( {
|
|
|
316
365
|
siteLogoId,
|
|
317
366
|
canUserEdit,
|
|
318
367
|
url,
|
|
368
|
+
siteIconId,
|
|
319
369
|
mediaItemData,
|
|
320
370
|
isRequestingMediaItem,
|
|
321
371
|
} = useSelect( ( select ) => {
|
|
@@ -328,6 +378,7 @@ export default function LogoEdit( {
|
|
|
328
378
|
const _readOnlyLogo = siteData?.site_logo;
|
|
329
379
|
const _canUserEdit = canUser( 'update', 'settings' );
|
|
330
380
|
const _siteLogoId = _canUserEdit ? _siteLogo : _readOnlyLogo;
|
|
381
|
+
const _siteIconId = siteSettings?.site_icon;
|
|
331
382
|
const mediaItem =
|
|
332
383
|
_siteLogoId &&
|
|
333
384
|
select( coreStore ).getMedia( _siteLogoId, {
|
|
@@ -339,6 +390,7 @@ export default function LogoEdit( {
|
|
|
339
390
|
_siteLogoId,
|
|
340
391
|
{ context: 'view' },
|
|
341
392
|
] );
|
|
393
|
+
|
|
342
394
|
return {
|
|
343
395
|
siteLogoId: _siteLogoId,
|
|
344
396
|
canUserEdit: _canUserEdit,
|
|
@@ -349,14 +401,59 @@ export default function LogoEdit( {
|
|
|
349
401
|
alt: mediaItem.alt_text,
|
|
350
402
|
},
|
|
351
403
|
isRequestingMediaItem: _isRequestingMediaItem,
|
|
404
|
+
siteIconId: _siteIconId,
|
|
352
405
|
};
|
|
353
406
|
}, [] );
|
|
354
407
|
|
|
408
|
+
const { getGlobalBlockCount } = useSelect( blockEditorStore );
|
|
355
409
|
const { editEntityRecord } = useDispatch( coreStore );
|
|
356
|
-
|
|
410
|
+
|
|
411
|
+
useEffect( () => {
|
|
412
|
+
// Cleanup function to discard unsaved changes to the icon and logo when
|
|
413
|
+
// the block is removed.
|
|
414
|
+
return () => {
|
|
415
|
+
// Do nothing if the block is being rendered in the styles preview or the
|
|
416
|
+
// block inserter.
|
|
417
|
+
if (
|
|
418
|
+
styleClass?.includes(
|
|
419
|
+
'block-editor-block-types-list__site-logo-example'
|
|
420
|
+
) ||
|
|
421
|
+
styleClass?.includes(
|
|
422
|
+
'block-editor-block-styles__block-preview-container'
|
|
423
|
+
)
|
|
424
|
+
) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const logoBlockCount = getGlobalBlockCount( 'core/site-logo' );
|
|
429
|
+
|
|
430
|
+
// Only discard unsaved changes if we are removing the last Site Logo block
|
|
431
|
+
// on the page.
|
|
432
|
+
if ( logoBlockCount === 0 ) {
|
|
433
|
+
editEntityRecord( 'root', 'site', undefined, {
|
|
434
|
+
site_logo: undefined,
|
|
435
|
+
site_icon: undefined,
|
|
436
|
+
} );
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
}, [] );
|
|
440
|
+
|
|
441
|
+
const setLogo = ( newValue, shouldForceSync = false ) => {
|
|
442
|
+
// `shouldForceSync` is used to force syncing when the attribute
|
|
443
|
+
// may not have updated yet.
|
|
444
|
+
if ( shouldSyncIcon || shouldForceSync ) {
|
|
445
|
+
setIcon( newValue );
|
|
446
|
+
}
|
|
447
|
+
|
|
357
448
|
editEntityRecord( 'root', 'site', undefined, {
|
|
358
449
|
site_logo: newValue,
|
|
359
450
|
} );
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
const setIcon = ( newValue ) =>
|
|
454
|
+
editEntityRecord( 'root', 'site', undefined, {
|
|
455
|
+
site_icon: newValue,
|
|
456
|
+
} );
|
|
360
457
|
|
|
361
458
|
let alt = null;
|
|
362
459
|
if ( mediaItemData ) {
|
|
@@ -365,7 +462,24 @@ export default function LogoEdit( {
|
|
|
365
462
|
setLogoUrl( mediaItemData.url );
|
|
366
463
|
}
|
|
367
464
|
}
|
|
368
|
-
|
|
465
|
+
|
|
466
|
+
const onInitialSelectLogo = ( media ) => {
|
|
467
|
+
// Initialize the syncSiteIcon toggle. If we currently have no Site logo and no
|
|
468
|
+
// site icon, automatically sync the logo to the icon.
|
|
469
|
+
if ( shouldSyncIcon === undefined ) {
|
|
470
|
+
const shouldForceSync = ! siteIconId;
|
|
471
|
+
setAttributes( { shouldSyncIcon: shouldForceSync } );
|
|
472
|
+
|
|
473
|
+
// Because we cannot rely on the `shouldSyncIcon` attribute to have updated by
|
|
474
|
+
// the time `setLogo` is called, pass an argument to force the syncing.
|
|
475
|
+
onSelectLogo( media, shouldForceSync );
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
onSelectLogo( media );
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
const onSelectLogo = ( media, shouldForceSync = false ) => {
|
|
369
483
|
if ( ! media ) {
|
|
370
484
|
return;
|
|
371
485
|
}
|
|
@@ -377,7 +491,7 @@ export default function LogoEdit( {
|
|
|
377
491
|
return;
|
|
378
492
|
}
|
|
379
493
|
|
|
380
|
-
setLogo( media.id );
|
|
494
|
+
setLogo( media.id, shouldForceSync );
|
|
381
495
|
};
|
|
382
496
|
|
|
383
497
|
const onRemoveLogo = () => {
|
|
@@ -423,6 +537,9 @@ export default function LogoEdit( {
|
|
|
423
537
|
setLogo={ setLogo }
|
|
424
538
|
logoId={ mediaItemData?.id || siteLogoId }
|
|
425
539
|
siteUrl={ url }
|
|
540
|
+
setIcon={ setIcon }
|
|
541
|
+
iconId={ siteIconId }
|
|
542
|
+
canUserEdit={ canUserEdit }
|
|
426
543
|
/>
|
|
427
544
|
);
|
|
428
545
|
}
|
|
@@ -481,7 +598,7 @@ export default function LogoEdit( {
|
|
|
481
598
|
) }
|
|
482
599
|
{ ! logoUrl && canUserEdit && (
|
|
483
600
|
<MediaPlaceholder
|
|
484
|
-
onSelect={
|
|
601
|
+
onSelect={ onInitialSelectLogo }
|
|
485
602
|
accept={ ACCEPT_MEDIA_STRING }
|
|
486
603
|
allowedTypes={ ALLOWED_MEDIA_TYPES }
|
|
487
604
|
onError={ onUploadError }
|
package/src/site-logo/index.php
CHANGED
|
@@ -76,6 +76,23 @@ function register_block_core_site_logo_setting() {
|
|
|
76
76
|
|
|
77
77
|
add_action( 'rest_api_init', 'register_block_core_site_logo_setting', 10 );
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Register a core site setting for a site icon
|
|
81
|
+
*/
|
|
82
|
+
function register_block_core_site_icon_setting() {
|
|
83
|
+
register_setting(
|
|
84
|
+
'general',
|
|
85
|
+
'site_icon',
|
|
86
|
+
array(
|
|
87
|
+
'show_in_rest' => true,
|
|
88
|
+
'type' => 'integer',
|
|
89
|
+
'description' => __( 'Site icon.' ),
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
add_action( 'rest_api_init', 'register_block_core_site_icon_setting', 10 );
|
|
95
|
+
|
|
79
96
|
/**
|
|
80
97
|
* Registers the `core/site-logo` block on the server.
|
|
81
98
|
*/
|
|
@@ -50,3 +50,31 @@ addFilter(
|
|
|
50
50
|
'core/template-part',
|
|
51
51
|
enhanceTemplatePartVariations
|
|
52
52
|
);
|
|
53
|
+
|
|
54
|
+
// Prevent adding template parts inside post templates.
|
|
55
|
+
const DISALLOWED_PARENTS = [ 'core/post-template', 'core/post-content' ];
|
|
56
|
+
addFilter(
|
|
57
|
+
'blockEditor.__unstableCanInsertBlockType',
|
|
58
|
+
'removeTemplatePartsFromPostTemplates',
|
|
59
|
+
(
|
|
60
|
+
can,
|
|
61
|
+
blockType,
|
|
62
|
+
rootClientId,
|
|
63
|
+
{ getBlock, getBlockParentsByBlockName }
|
|
64
|
+
) => {
|
|
65
|
+
if ( blockType.name !== 'core/template-part' ) {
|
|
66
|
+
return can;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for ( const disallowedParentType of DISALLOWED_PARENTS ) {
|
|
70
|
+
const hasDisallowedParent =
|
|
71
|
+
getBlock( rootClientId )?.name === disallowedParentType ||
|
|
72
|
+
getBlockParentsByBlockName( rootClientId, disallowedParentType )
|
|
73
|
+
.length;
|
|
74
|
+
if ( hasDisallowedParent ) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
);
|