@wordpress/block-library 9.27.1-next.46f643fa0.0 → 9.28.0

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.
Files changed (117) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/cover/edit/index.js +1 -1
  3. package/build/cover/edit/index.js.map +1 -1
  4. package/build/cover/edit/inspector-controls.js +1 -1
  5. package/build/cover/edit/inspector-controls.js.map +1 -1
  6. package/build/file/edit.js +4 -2
  7. package/build/file/edit.js.map +1 -1
  8. package/build/file/edit.native.js +1 -1
  9. package/build/file/edit.native.js.map +1 -1
  10. package/build/file/transforms.js +6 -6
  11. package/build/file/transforms.js.map +1 -1
  12. package/build/file/utils/index.js +5 -0
  13. package/build/file/utils/index.js.map +1 -1
  14. package/build/gallery/use-get-media.js +3 -3
  15. package/build/gallery/use-get-media.js.map +1 -1
  16. package/build/gallery/use-get-media.native.js +3 -3
  17. package/build/gallery/use-get-media.native.js.map +1 -1
  18. package/build/image/edit.native.js +2 -2
  19. package/build/image/edit.native.js.map +1 -1
  20. package/build/image/image.js +1 -1
  21. package/build/image/image.js.map +1 -1
  22. package/build/list-item/edit.js +3 -0
  23. package/build/list-item/edit.js.map +1 -1
  24. package/build/media-text/edit.js +2 -2
  25. package/build/media-text/edit.js.map +1 -1
  26. package/build/more/edit.js +13 -28
  27. package/build/more/edit.js.map +1 -1
  28. package/build/post-comments-count/index.js +3 -0
  29. package/build/post-comments-count/index.js.map +1 -1
  30. package/build/post-comments-link/index.js +3 -0
  31. package/build/post-comments-link/index.js.map +1 -1
  32. package/build/post-featured-image/edit.js +2 -2
  33. package/build/post-featured-image/edit.js.map +1 -1
  34. package/build/site-logo/edit.js +2 -2
  35. package/build/site-logo/edit.js.map +1 -1
  36. package/build/social-link/icons/tiktok.js +2 -2
  37. package/build/social-link/icons/tiktok.js.map +1 -1
  38. package/build/utils/poster-image.js +54 -6
  39. package/build/utils/poster-image.js.map +1 -1
  40. package/build-module/cover/edit/index.js +1 -1
  41. package/build-module/cover/edit/index.js.map +1 -1
  42. package/build-module/cover/edit/inspector-controls.js +1 -1
  43. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  44. package/build-module/file/edit.js +4 -2
  45. package/build-module/file/edit.js.map +1 -1
  46. package/build-module/file/edit.native.js +1 -1
  47. package/build-module/file/edit.native.js.map +1 -1
  48. package/build-module/file/transforms.js +6 -6
  49. package/build-module/file/transforms.js.map +1 -1
  50. package/build-module/file/utils/index.js +5 -0
  51. package/build-module/file/utils/index.js.map +1 -1
  52. package/build-module/gallery/use-get-media.js +3 -3
  53. package/build-module/gallery/use-get-media.js.map +1 -1
  54. package/build-module/gallery/use-get-media.native.js +3 -3
  55. package/build-module/gallery/use-get-media.native.js.map +1 -1
  56. package/build-module/image/edit.native.js +2 -2
  57. package/build-module/image/edit.native.js.map +1 -1
  58. package/build-module/image/image.js +1 -1
  59. package/build-module/image/image.js.map +1 -1
  60. package/build-module/list-item/edit.js +3 -0
  61. package/build-module/list-item/edit.js.map +1 -1
  62. package/build-module/media-text/edit.js +2 -2
  63. package/build-module/media-text/edit.js.map +1 -1
  64. package/build-module/more/edit.js +15 -29
  65. package/build-module/more/edit.js.map +1 -1
  66. package/build-module/post-comments-count/index.js +3 -0
  67. package/build-module/post-comments-count/index.js.map +1 -1
  68. package/build-module/post-comments-link/index.js +3 -0
  69. package/build-module/post-comments-link/index.js.map +1 -1
  70. package/build-module/post-featured-image/edit.js +2 -2
  71. package/build-module/post-featured-image/edit.js.map +1 -1
  72. package/build-module/site-logo/edit.js +2 -2
  73. package/build-module/site-logo/edit.js.map +1 -1
  74. package/build-module/social-link/icons/tiktok.js +2 -2
  75. package/build-module/social-link/icons/tiktok.js.map +1 -1
  76. package/build-module/utils/poster-image.js +57 -9
  77. package/build-module/utils/poster-image.js.map +1 -1
  78. package/build-style/editor-rtl.css +23 -26
  79. package/build-style/editor.css +23 -26
  80. package/build-style/gallery/style-rtl.css +1 -2
  81. package/build-style/gallery/style.css +1 -2
  82. package/build-style/image/style-rtl.css +1 -2
  83. package/build-style/image/style.css +1 -2
  84. package/build-style/more/editor-rtl.css +3 -11
  85. package/build-style/more/editor.css +3 -11
  86. package/build-style/post-featured-image/editor-rtl.css +1 -2
  87. package/build-style/post-featured-image/editor.css +1 -2
  88. package/build-style/style-rtl.css +2 -4
  89. package/build-style/style.css +2 -4
  90. package/package.json +35 -35
  91. package/src/block/index.php +33 -20
  92. package/src/cover/edit/index.js +8 -3
  93. package/src/cover/edit/inspector-controls.js +6 -1
  94. package/src/file/edit.js +9 -4
  95. package/src/file/edit.native.js +5 -1
  96. package/src/file/transforms.js +6 -6
  97. package/src/file/utils/index.js +5 -0
  98. package/src/form-input/index.php +4 -2
  99. package/src/gallery/use-get-media.js +9 -5
  100. package/src/gallery/use-get-media.native.js +10 -6
  101. package/src/image/edit.native.js +4 -2
  102. package/src/image/image.js +6 -1
  103. package/src/image/index.php +1 -1
  104. package/src/image/test/edit.native.js +16 -10
  105. package/src/list-item/edit.js +3 -0
  106. package/src/loginout/index.php +4 -2
  107. package/src/media-text/edit.js +16 -6
  108. package/src/more/edit.js +27 -33
  109. package/src/more/editor.scss +3 -12
  110. package/src/post-comments-count/block.json +3 -0
  111. package/src/post-comments-link/block.json +3 -0
  112. package/src/post-date/index.php +28 -32
  113. package/src/post-featured-image/edit.js +2 -2
  114. package/src/site-logo/edit.js +11 -4
  115. package/src/social-link/icons/tiktok.js +2 -2
  116. package/src/utils/poster-image.js +62 -17
  117. package/src/utils/poster-image.scss +23 -16
@@ -9,6 +9,7 @@
9
9
  * Renders the `core/post-date` block on the server.
10
10
  *
11
11
  * @since 5.8.0
12
+ * @since 6.9.0 Added `datetime` attribute and Block Bindings support.
12
13
  *
13
14
  * @param array $attributes Block attributes.
14
15
  * @param string $content Block default content.
@@ -18,44 +19,39 @@
18
19
  function render_block_core_post_date( $attributes, $content, $block ) {
19
20
  $classes = array();
20
21
 
21
- if ( ! isset( $attributes['datetime'] ) ) {
22
+ if (
23
+ isset( $attributes['metadata']['bindings']['datetime']['source'] ) &&
24
+ isset( $attributes['metadata']['bindings']['datetime']['args'] )
25
+ ) {
22
26
  /*
23
- * This can mean two things:
24
- *
25
- * 1. We're dealing with the legacy version of the block that didn't have the `datetime` attribute.
26
- * 2. The `datetime` attribute is bound to a Block Bindings source, but we're on a version of WordPress
27
- * that doesn't support binding that attribute to a Block Bindings source.
28
- *
29
- * In both cases, we set the `datetime` attribute to its correct value by applying Block Bindings manually.
27
+ * We might be running on a version of WordPress that doesn't support binding the block's `datetime` attribute
28
+ * to a Block Bindings source. In this case, we need to manually set the `datetime` attribute to its correct value.
29
+ * This branch can be removed once the minimum required WordPress version is 6.9 or newer.
30
30
  */
31
- if (
32
- isset( $attributes['metadata']['bindings']['datetime']['source'] ) &&
33
- isset( $attributes['metadata']['bindings']['datetime']['args'] )
34
- ) {
35
- // We're using a version of WordPress that doesn't support binding the block's `datetime` attribute to a Block Bindings source.
36
- // This branch can be removed once the minimum required WordPress version supports the `core/post-data` source.
37
- $source = get_block_bindings_source( $attributes['metadata']['bindings']['datetime']['source'] );
38
- $source_args = $attributes['metadata']['bindings']['datetime']['args'];
31
+ $source = get_block_bindings_source( $attributes['metadata']['bindings']['datetime']['source'] );
32
+ $source_args = $attributes['metadata']['bindings']['datetime']['args'];
33
+
34
+ $attributes['datetime'] = $source->get_value( $source_args, $block, 'datetime' );
35
+ } elseif ( ! isset( $attributes['datetime'] ) ) {
36
+ /*
37
+ * This is the legacy version of the block that didn't have the `datetime` attribute.
38
+ * This branch needs to be kept for backward compatibility.
39
+ */
40
+ $source = get_block_bindings_source( 'core/post-data' );
41
+ if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
42
+ $source_args = array(
43
+ 'key' => 'modified',
44
+ );
39
45
  } else {
40
- // This is the legacy version of the block that didn't have the `datetime` attribute.
41
- // This branch needs to be kept for backward compatibility.
42
- $source = get_block_bindings_source( 'core/post-data' );
43
- if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
44
- $source_args = array(
45
- 'key' => 'modified',
46
- );
47
- } else {
48
- $source_args = array(
49
- 'key' => 'date',
50
- );
51
- }
46
+ $source_args = array(
47
+ 'key' => 'date',
48
+ );
52
49
  }
53
-
54
50
  $attributes['datetime'] = $source->get_value( $source_args, $block, 'datetime' );
51
+ }
55
52
 
56
- if ( isset( $source_args['key'] ) && 'modified' === $source_args['key'] ) {
57
- $classes[] = 'wp-block-post-date__modified-date';
58
- }
53
+ if ( isset( $source_args['key'] ) && 'modified' === $source_args['key'] ) {
54
+ $classes[] = 'wp-block-post-date__modified-date';
59
55
  }
60
56
 
61
57
  if ( empty( $attributes['datetime'] ) ) {
@@ -133,12 +133,12 @@ export default function PostFeaturedImageEdit( {
133
133
 
134
134
  const { media, postType, postPermalink } = useSelect(
135
135
  ( select ) => {
136
- const { getMedia, getPostType, getEditedEntityRecord } =
136
+ const { getEntityRecord, getPostType, getEditedEntityRecord } =
137
137
  select( coreStore );
138
138
  return {
139
139
  media:
140
140
  featuredImage &&
141
- getMedia( featuredImage, {
141
+ getEntityRecord( 'postType', 'attachment', featuredImage, {
142
142
  context: 'view',
143
143
  } ),
144
144
  postType: postTypeSlug && getPostType( postTypeSlug ),
@@ -454,12 +454,19 @@ export default function LogoEdit( {
454
454
  const _siteIconId = siteSettings?.site_icon;
455
455
  const mediaItem =
456
456
  _siteLogoId &&
457
- select( coreStore ).getMedia( _siteLogoId, {
458
- context: 'view',
459
- } );
457
+ select( coreStore ).getEntityRecord(
458
+ 'postType',
459
+ 'attachment',
460
+ _siteLogoId,
461
+ {
462
+ context: 'view',
463
+ }
464
+ );
460
465
  const _isRequestingMediaItem =
461
466
  !! _siteLogoId &&
462
- ! select( coreStore ).hasFinishedResolution( 'getMedia', [
467
+ ! select( coreStore ).hasFinishedResolution( 'getEntityRecord', [
468
+ 'postType',
469
+ 'attachment',
463
470
  _siteLogoId,
464
471
  { context: 'view' },
465
472
  ] );
@@ -4,7 +4,7 @@
4
4
  import { Path, SVG } from '@wordpress/primitives';
5
5
 
6
6
  export const TiktokIcon = () => (
7
- <SVG width="24" height="24" viewBox="0 0 32 32" version="1.1">
8
- <Path d="M16.708 0.027c1.745-0.027 3.48-0.011 5.213-0.027 0.105 2.041 0.839 4.12 2.333 5.563 1.491 1.479 3.6 2.156 5.652 2.385v5.369c-1.923-0.063-3.855-0.463-5.6-1.291-0.76-0.344-1.468-0.787-2.161-1.24-0.009 3.896 0.016 7.787-0.025 11.667-0.104 1.864-0.719 3.719-1.803 5.255-1.744 2.557-4.771 4.224-7.88 4.276-1.907 0.109-3.812-0.411-5.437-1.369-2.693-1.588-4.588-4.495-4.864-7.615-0.032-0.667-0.043-1.333-0.016-1.984 0.24-2.537 1.495-4.964 3.443-6.615 2.208-1.923 5.301-2.839 8.197-2.297 0.027 1.975-0.052 3.948-0.052 5.923-1.323-0.428-2.869-0.308-4.025 0.495-0.844 0.547-1.485 1.385-1.819 2.333-0.276 0.676-0.197 1.427-0.181 2.145 0.317 2.188 2.421 4.027 4.667 3.828 1.489-0.016 2.916-0.88 3.692-2.145 0.251-0.443 0.532-0.896 0.547-1.417 0.131-2.385 0.079-4.76 0.095-7.145 0.011-5.375-0.016-10.735 0.025-16.093z" />
7
+ <SVG width="24" height="24" viewBox="0 0 24 24" version="1.1">
8
+ <Path d="M12.4044 3.01519C13.4086 3 14.4072 3.009 15.4045 3C15.465 4.14812 15.8874 5.31762 16.7472 6.12935C17.6053 6.96134 18.819 7.34217 20 7.47099V10.4912C18.8933 10.4558 17.7814 10.2308 16.7771 9.76499C16.3397 9.57148 15.9323 9.32227 15.5334 9.06745C15.5283 11.2591 15.5426 13.4479 15.5191 15.6305C15.4592 16.679 15.1053 17.7225 14.4814 18.5866C13.4777 20.025 11.7356 20.9627 9.94635 20.992C8.84885 21.0533 7.7525 20.7608 6.81729 20.2219C5.26743 19.3286 4.17683 17.6933 4.01799 15.9382C3.99957 15.563 3.99324 15.1883 4.00878 14.8221C4.14691 13.395 4.86917 12.0297 5.99027 11.101C7.26101 10.0192 9.04107 9.50397 10.7078 9.80886C10.7233 10.9199 10.6778 12.0297 10.6778 13.1407C9.91643 12.9 9.02668 12.9675 8.36139 13.4192C7.87566 13.7269 7.50675 14.1983 7.31453 14.7316C7.15569 15.1118 7.20116 15.5343 7.21036 15.9382C7.3928 17.169 8.60368 18.2035 9.89628 18.0916C10.7532 18.0826 11.5745 17.5965 12.0211 16.8849C12.1655 16.6357 12.3273 16.3809 12.3359 16.0878C12.4113 14.7462 12.3814 13.4102 12.3906 12.0685C12.3969 9.04495 12.3814 6.02979 12.4049 3.01575L12.4044 3.01519Z" />
9
9
  </SVG>
10
10
  );
@@ -6,26 +6,73 @@ import clsx from 'clsx';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor';
9
+ import {
10
+ MediaUpload,
11
+ MediaUploadCheck,
12
+ store as blockEditorStore,
13
+ } from '@wordpress/block-editor';
14
+ import { store as noticesStore } from '@wordpress/notices';
10
15
  import {
11
16
  Button,
12
17
  BaseControl,
18
+ DropZone,
19
+ Spinner,
13
20
  __experimentalHStack as HStack,
14
21
  __experimentalToolsPanelItem as ToolsPanelItem,
15
22
  } from '@wordpress/components';
23
+ import { isBlobURL } from '@wordpress/blob';
16
24
  import { __, sprintf } from '@wordpress/i18n';
17
- import { useRef } from '@wordpress/element';
25
+ import { useRef, useState } from '@wordpress/element';
18
26
  import { useInstanceId } from '@wordpress/compose';
27
+ import { useSelect, useDispatch } from '@wordpress/data';
19
28
 
20
29
  const POSTER_IMAGE_ALLOWED_MEDIA_TYPES = [ 'image' ];
21
30
 
22
31
  function PosterImage( { poster, onChange } ) {
23
32
  const posterButtonRef = useRef();
33
+ const [ isLoading, setIsLoading ] = useState( false );
24
34
  const descriptionId = useInstanceId(
25
35
  PosterImage,
26
36
  'block-library-poster-image-description'
27
37
  );
28
38
 
39
+ const { getSettings } = useSelect( blockEditorStore );
40
+ const { createErrorNotice } = useDispatch( noticesStore );
41
+
42
+ const onDropFiles = ( filesList ) => {
43
+ getSettings().mediaUpload( {
44
+ allowedTypes: POSTER_IMAGE_ALLOWED_MEDIA_TYPES,
45
+ filesList,
46
+ onFileChange: ( [ image ] ) => {
47
+ if ( isBlobURL( image?.url ) ) {
48
+ setIsLoading( true );
49
+ return;
50
+ }
51
+
52
+ if ( image ) {
53
+ onChange( image );
54
+ }
55
+ setIsLoading( false );
56
+ },
57
+ onError: ( message ) => {
58
+ createErrorNotice( message, {
59
+ id: 'poster-image-upload-notice',
60
+ type: 'snackbar',
61
+ } );
62
+ setIsLoading( false );
63
+ },
64
+ multiple: false,
65
+ } );
66
+ };
67
+
68
+ const getPosterButtonContent = () => {
69
+ if ( ! poster && isLoading ) {
70
+ return <Spinner />;
71
+ }
72
+
73
+ return ! poster ? __( 'Set poster image' ) : __( 'Replace' );
74
+ };
75
+
29
76
  return (
30
77
  <MediaUploadCheck>
31
78
  <ToolsPanelItem
@@ -48,24 +95,19 @@ function PosterImage( { poster, onChange } ) {
48
95
  __next40pxDefaultSize
49
96
  onClick={ open }
50
97
  aria-haspopup="dialog"
51
- aria-label={
52
- ! poster
53
- ? null
54
- : __(
55
- 'Edit or replace the poster image.'
56
- )
57
- }
58
- className={
59
- poster
60
- ? 'block-library-poster-image__preview'
61
- : 'block-library-poster-image__toggle'
62
- }
98
+ aria-label={ __(
99
+ 'Edit or replace the poster image.'
100
+ ) }
101
+ className="block-library-poster-image__preview"
102
+ disabled={ isLoading }
103
+ accessibleWhenDisabled
63
104
  >
64
105
  <img
65
106
  src={ poster }
66
107
  alt={ __( 'Poster image preview' ) }
67
108
  className="block-library-poster-image__preview-image"
68
109
  />
110
+ { isLoading && <Spinner /> }
69
111
  </Button>
70
112
  ) }
71
113
  <HStack
@@ -87,10 +129,10 @@ function PosterImage( { poster, onChange } ) {
87
129
  variant={
88
130
  ! poster ? 'secondary' : undefined
89
131
  }
132
+ disabled={ isLoading }
133
+ accessibleWhenDisabled
90
134
  >
91
- { ! poster
92
- ? __( 'Set poster image' )
93
- : __( 'Replace' ) }
135
+ { getPosterButtonContent() }
94
136
  </Button>
95
137
  <p id={ descriptionId } hidden>
96
138
  { poster
@@ -115,11 +157,14 @@ function PosterImage( { poster, onChange } ) {
115
157
  posterButtonRef.current.focus();
116
158
  } }
117
159
  className="block-library-poster-image__action"
160
+ disabled={ isLoading }
161
+ accessibleWhenDisabled
118
162
  >
119
163
  { __( 'Remove' ) }
120
164
  </Button>
121
165
  ) }
122
166
  </HStack>
167
+ <DropZone onFilesDrop={ onDropFiles } />
123
168
  </div>
124
169
  ) }
125
170
  />
@@ -13,9 +13,31 @@
13
13
  opacity: 1;
14
14
  margin-top: $grid-unit-20;
15
15
  }
16
+
17
+ .components-drop-zone__content {
18
+ border-radius: $radius-small;
19
+ }
20
+
21
+ // Align text and icons horizontally to avoid clipping when the poster image is not set.
22
+ .components-drop-zone .components-drop-zone__content-inner {
23
+ display: flex;
24
+ align-items: center;
25
+ gap: $grid-unit-10;
26
+
27
+ .components-drop-zone__content-icon {
28
+ margin: 0;
29
+ }
30
+ }
31
+
32
+ .components-spinner {
33
+ position: absolute;
34
+ top: 50%;
35
+ left: 50%;
36
+ margin-top: -9px;
37
+ margin-left: -9px;
38
+ }
16
39
  }
17
40
 
18
- .block-library-poster-image__toggle,
19
41
  .block-library-poster-image__preview {
20
42
  width: 100%;
21
43
  padding: 0;
@@ -25,9 +47,6 @@
25
47
 
26
48
  display: flex;
27
49
  justify-content: center;
28
- }
29
-
30
- .block-library-poster-image__preview {
31
50
  height: auto !important;
32
51
  outline: $border-width solid rgba($black, 0.1);
33
52
 
@@ -39,18 +58,6 @@
39
58
  }
40
59
  }
41
60
 
42
- .block-library-poster-image__toggle {
43
- box-shadow: inset 0 0 0 $border-width $gray-400;
44
-
45
- &:focus:not(:disabled) {
46
- // Allow smooth transition between focused and unfocused box-shadow states.
47
- box-shadow:
48
- 0 0 0 currentColor inset,
49
- 0 0 0 var(--wp-admin-border-width-focus)
50
- var(--wp-admin-theme-color);
51
- }
52
- }
53
-
54
61
  .block-library-poster-image__actions {
55
62
  &:not(.block-library-poster-image__actions-select) {
56
63
  bottom: 0;