@wordpress/block-library 9.27.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 (185) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/categories/edit.js +15 -3
  3. package/build/categories/edit.js.map +1 -1
  4. package/build/cover/edit/index.js +1 -1
  5. package/build/cover/edit/index.js.map +1 -1
  6. package/build/cover/edit/inspector-controls.js +5 -3
  7. package/build/cover/edit/inspector-controls.js.map +1 -1
  8. package/build/file/edit.js +5 -2
  9. package/build/file/edit.js.map +1 -1
  10. package/build/file/edit.native.js +1 -1
  11. package/build/file/edit.native.js.map +1 -1
  12. package/build/file/transforms.js +6 -6
  13. package/build/file/transforms.js.map +1 -1
  14. package/build/file/utils/index.js +5 -0
  15. package/build/file/utils/index.js.map +1 -1
  16. package/build/gallery/use-get-media.js +3 -3
  17. package/build/gallery/use-get-media.js.map +1 -1
  18. package/build/gallery/use-get-media.native.js +3 -3
  19. package/build/gallery/use-get-media.native.js.map +1 -1
  20. package/build/image/edit.native.js +2 -2
  21. package/build/image/edit.native.js.map +1 -1
  22. package/build/image/image.js +1 -1
  23. package/build/image/image.js.map +1 -1
  24. package/build/latest-posts/edit.js +0 -2
  25. package/build/latest-posts/edit.js.map +1 -1
  26. package/build/list-item/edit.js +3 -0
  27. package/build/list-item/edit.js.map +1 -1
  28. package/build/media-text/edit.js +2 -2
  29. package/build/media-text/edit.js.map +1 -1
  30. package/build/more/edit.js +13 -28
  31. package/build/more/edit.js.map +1 -1
  32. package/build/paragraph/edit.js +2 -2
  33. package/build/paragraph/edit.js.map +1 -1
  34. package/build/post-comments-count/index.js +3 -0
  35. package/build/post-comments-count/index.js.map +1 -1
  36. package/build/post-comments-link/index.js +3 -0
  37. package/build/post-comments-link/index.js.map +1 -1
  38. package/build/post-date/deprecated.js +104 -1
  39. package/build/post-date/deprecated.js.map +1 -1
  40. package/build/post-date/edit.js +32 -32
  41. package/build/post-date/edit.js.map +1 -1
  42. package/build/post-date/index.js +4 -4
  43. package/build/post-date/index.js.map +1 -1
  44. package/build/post-date/variations.js +32 -3
  45. package/build/post-date/variations.js.map +1 -1
  46. package/build/post-featured-image/edit.js +2 -2
  47. package/build/post-featured-image/edit.js.map +1 -1
  48. package/build/site-logo/edit.js +2 -2
  49. package/build/site-logo/edit.js.map +1 -1
  50. package/build/social-link/icons/tiktok.js +2 -2
  51. package/build/social-link/icons/tiktok.js.map +1 -1
  52. package/build/social-link/variations.js +51 -49
  53. package/build/social-link/variations.js.map +1 -1
  54. package/build/utils/poster-image.js +141 -0
  55. package/build/utils/poster-image.js.map +1 -0
  56. package/build/video/edit.js +6 -2
  57. package/build/video/edit.js.map +1 -1
  58. package/build-module/categories/edit.js +15 -3
  59. package/build-module/categories/edit.js.map +1 -1
  60. package/build-module/cover/edit/index.js +1 -1
  61. package/build-module/cover/edit/index.js.map +1 -1
  62. package/build-module/cover/edit/inspector-controls.js +5 -3
  63. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  64. package/build-module/file/edit.js +5 -2
  65. package/build-module/file/edit.js.map +1 -1
  66. package/build-module/file/edit.native.js +1 -1
  67. package/build-module/file/edit.native.js.map +1 -1
  68. package/build-module/file/transforms.js +6 -6
  69. package/build-module/file/transforms.js.map +1 -1
  70. package/build-module/file/utils/index.js +5 -0
  71. package/build-module/file/utils/index.js.map +1 -1
  72. package/build-module/gallery/use-get-media.js +3 -3
  73. package/build-module/gallery/use-get-media.js.map +1 -1
  74. package/build-module/gallery/use-get-media.native.js +3 -3
  75. package/build-module/gallery/use-get-media.native.js.map +1 -1
  76. package/build-module/image/edit.native.js +2 -2
  77. package/build-module/image/edit.native.js.map +1 -1
  78. package/build-module/image/image.js +1 -1
  79. package/build-module/image/image.js.map +1 -1
  80. package/build-module/latest-posts/edit.js +0 -2
  81. package/build-module/latest-posts/edit.js.map +1 -1
  82. package/build-module/list-item/edit.js +3 -0
  83. package/build-module/list-item/edit.js.map +1 -1
  84. package/build-module/media-text/edit.js +2 -2
  85. package/build-module/media-text/edit.js.map +1 -1
  86. package/build-module/more/edit.js +15 -29
  87. package/build-module/more/edit.js.map +1 -1
  88. package/build-module/paragraph/edit.js +2 -2
  89. package/build-module/paragraph/edit.js.map +1 -1
  90. package/build-module/post-comments-count/index.js +3 -0
  91. package/build-module/post-comments-count/index.js.map +1 -1
  92. package/build-module/post-comments-link/index.js +3 -0
  93. package/build-module/post-comments-link/index.js.map +1 -1
  94. package/build-module/post-date/deprecated.js +104 -1
  95. package/build-module/post-date/deprecated.js.map +1 -1
  96. package/build-module/post-date/edit.js +35 -35
  97. package/build-module/post-date/edit.js.map +1 -1
  98. package/build-module/post-date/index.js +4 -4
  99. package/build-module/post-date/index.js.map +1 -1
  100. package/build-module/post-date/variations.js +32 -3
  101. package/build-module/post-date/variations.js.map +1 -1
  102. package/build-module/post-featured-image/edit.js +2 -2
  103. package/build-module/post-featured-image/edit.js.map +1 -1
  104. package/build-module/site-logo/edit.js +2 -2
  105. package/build-module/site-logo/edit.js.map +1 -1
  106. package/build-module/social-link/icons/tiktok.js +2 -2
  107. package/build-module/social-link/icons/tiktok.js.map +1 -1
  108. package/build-module/social-link/variations.js +52 -50
  109. package/build-module/social-link/variations.js.map +1 -1
  110. package/build-module/utils/poster-image.js +133 -0
  111. package/build-module/utils/poster-image.js.map +1 -0
  112. package/build-module/video/edit.js +6 -2
  113. package/build-module/video/edit.js.map +1 -1
  114. package/build-style/editor-rtl.css +77 -23
  115. package/build-style/editor.css +77 -23
  116. package/build-style/gallery/style-rtl.css +1 -2
  117. package/build-style/gallery/style.css +1 -2
  118. package/build-style/image/style-rtl.css +1 -2
  119. package/build-style/image/style.css +1 -2
  120. package/build-style/more/editor-rtl.css +3 -11
  121. package/build-style/more/editor.css +3 -11
  122. package/build-style/navigation/editor-rtl.css +6 -6
  123. package/build-style/navigation/editor.css +6 -6
  124. package/build-style/page-list/editor-rtl.css +0 -4
  125. package/build-style/page-list/editor.css +0 -4
  126. package/build-style/post-featured-image/editor-rtl.css +1 -2
  127. package/build-style/post-featured-image/editor.css +1 -2
  128. package/build-style/style-rtl.css +3 -4
  129. package/build-style/style.css +3 -4
  130. package/build-style/video/style-rtl.css +1 -0
  131. package/build-style/video/style.css +1 -0
  132. package/package.json +35 -35
  133. package/src/block/index.php +33 -20
  134. package/src/categories/edit.js +13 -1
  135. package/src/cover/edit/index.js +8 -3
  136. package/src/cover/edit/inspector-controls.js +12 -3
  137. package/src/editor.scss +1 -0
  138. package/src/file/edit.js +10 -2
  139. package/src/file/edit.native.js +5 -1
  140. package/src/file/transforms.js +6 -6
  141. package/src/file/utils/index.js +5 -0
  142. package/src/form-input/index.php +4 -2
  143. package/src/gallery/use-get-media.js +9 -5
  144. package/src/gallery/use-get-media.native.js +10 -6
  145. package/src/image/edit.native.js +4 -2
  146. package/src/image/image.js +6 -1
  147. package/src/image/index.php +1 -1
  148. package/src/image/test/edit.native.js +16 -10
  149. package/src/latest-posts/edit.js +0 -2
  150. package/src/list-item/edit.js +3 -0
  151. package/src/loginout/index.php +4 -2
  152. package/src/media-text/edit.js +16 -6
  153. package/src/more/edit.js +27 -33
  154. package/src/more/editor.scss +3 -12
  155. package/src/page-list/editor.scss +0 -6
  156. package/src/paragraph/edit.js +2 -2
  157. package/src/post-comments-count/block.json +3 -0
  158. package/src/post-comments-link/block.json +3 -0
  159. package/src/post-date/block.json +4 -4
  160. package/src/post-date/deprecated.js +104 -1
  161. package/src/post-date/edit.js +74 -86
  162. package/src/post-date/index.php +51 -28
  163. package/src/post-date/variations.js +37 -3
  164. package/src/post-featured-image/edit.js +2 -2
  165. package/src/site-logo/edit.js +11 -4
  166. package/src/social-link/README.md +21 -0
  167. package/src/social-link/icons/tiktok.js +2 -2
  168. package/src/social-link/index.php +49 -49
  169. package/src/social-link/variations.js +51 -49
  170. package/src/utils/poster-image.js +176 -0
  171. package/src/utils/poster-image.scss +82 -0
  172. package/src/video/edit.js +7 -2
  173. package/src/video/index.php +91 -0
  174. package/src/video/style.native.scss +1 -0
  175. package/src/video/style.scss +1 -0
  176. package/build/cover/edit/poster-image.js +0 -81
  177. package/build/cover/edit/poster-image.js.map +0 -1
  178. package/build/video/poster-image.js +0 -81
  179. package/build/video/poster-image.js.map +0 -1
  180. package/build-module/cover/edit/poster-image.js +0 -74
  181. package/build-module/cover/edit/poster-image.js.map +0 -1
  182. package/build-module/video/poster-image.js +0 -74
  183. package/build-module/video/poster-image.js.map +0 -1
  184. package/src/cover/edit/poster-image.js +0 -91
  185. package/src/video/poster-image.js +0 -91
@@ -18,6 +18,7 @@ import {
18
18
  } from '@wordpress/icons';
19
19
  import { useMergeRefs } from '@wordpress/compose';
20
20
  import { useSelect } from '@wordpress/data';
21
+ import { displayShortcut } from '@wordpress/keycodes';
21
22
 
22
23
  /**
23
24
  * Internal dependencies
@@ -53,6 +54,7 @@ export function IndentUI( { clientId } ) {
53
54
  <ToolbarButton
54
55
  icon={ isRTL() ? formatOutdentRTL : formatOutdent }
55
56
  title={ __( 'Outdent' ) }
57
+ shortcut={ displayShortcut.shift( 'Tab' ) }
56
58
  description={ __( 'Outdent list item' ) }
57
59
  disabled={ ! canOutdent }
58
60
  onClick={ () => outdentListItem() }
@@ -60,6 +62,7 @@ export function IndentUI( { clientId } ) {
60
62
  <ToolbarButton
61
63
  icon={ isRTL() ? formatIndentRTL : formatIndent }
62
64
  title={ __( 'Indent' ) }
65
+ shortcut="Tab"
63
66
  description={ __( 'Indent list item' ) }
64
67
  disabled={ ! canIndent }
65
68
  onClick={ () => indentListItem() }
@@ -23,14 +23,16 @@ function render_block_core_loginout( $attributes ) {
23
23
  */
24
24
  $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
25
25
 
26
- $classes = is_user_logged_in() ? 'logged-in' : 'logged-out';
26
+ $user_logged_in = is_user_logged_in();
27
+
28
+ $classes = $user_logged_in ? 'logged-in' : 'logged-out';
27
29
  $contents = wp_loginout(
28
30
  isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '',
29
31
  false
30
32
  );
31
33
 
32
34
  // If logged-out and displayLoginAsForm is true, show the login form.
33
- if ( ! is_user_logged_in() && ! empty( $attributes['displayLoginAsForm'] ) ) {
35
+ if ( ! $user_logged_in && ! empty( $attributes['displayLoginAsForm'] ) ) {
34
36
  // Add a class.
35
37
  $classes .= ' has-login-form';
36
38
 
@@ -199,9 +199,14 @@ function MediaTextEdit( {
199
199
  return {
200
200
  featuredImageMedia:
201
201
  featuredImage && useFeaturedImage
202
- ? select( coreStore ).getMedia( featuredImage, {
203
- context: 'view',
204
- } )
202
+ ? select( coreStore ).getEntityRecord(
203
+ 'postType',
204
+ 'attachment',
205
+ featuredImage,
206
+ {
207
+ context: 'view',
208
+ }
209
+ )
205
210
  : undefined,
206
211
  };
207
212
  },
@@ -213,9 +218,14 @@ function MediaTextEdit( {
213
218
  return {
214
219
  image:
215
220
  mediaId && isSelected
216
- ? select( coreStore ).getMedia( mediaId, {
217
- context: 'view',
218
- } )
221
+ ? select( coreStore ).getEntityRecord(
222
+ 'postType',
223
+ 'attachment',
224
+ mediaId,
225
+ {
226
+ context: 'view',
227
+ }
228
+ )
219
229
  : null,
220
230
  };
221
231
  },
package/src/more/edit.js CHANGED
@@ -7,9 +7,13 @@ import {
7
7
  __experimentalToolsPanelItem as ToolsPanelItem,
8
8
  ToggleControl,
9
9
  } from '@wordpress/components';
10
- import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
11
- import { ENTER } from '@wordpress/keycodes';
10
+ import {
11
+ InspectorControls,
12
+ PlainText,
13
+ useBlockProps,
14
+ } from '@wordpress/block-editor';
12
15
  import { getDefaultBlockName, createBlock } from '@wordpress/blocks';
16
+
13
17
  /**
14
18
  * Internal dependencies
15
19
  */
@@ -22,29 +26,6 @@ export default function MoreEdit( {
22
26
  insertBlocksAfter,
23
27
  setAttributes,
24
28
  } ) {
25
- const onChangeInput = ( event ) => {
26
- setAttributes( {
27
- customText: event.target.value,
28
- } );
29
- };
30
-
31
- const onKeyDown = ( { keyCode } ) => {
32
- if ( keyCode === ENTER ) {
33
- insertBlocksAfter( [ createBlock( getDefaultBlockName() ) ] );
34
- }
35
- };
36
-
37
- const getHideExcerptHelp = ( checked ) =>
38
- checked
39
- ? __( 'The excerpt is hidden.' )
40
- : __( 'The excerpt is visible.' );
41
-
42
- const toggleHideExcerpt = () => setAttributes( { noTeaser: ! noTeaser } );
43
-
44
- const style = {
45
- width: `${ ( customText ? customText : DEFAULT_TEXT ).length + 1.2 }em`,
46
- };
47
-
48
29
  const dropdownMenuProps = useToolsPanelDropdownMenuProps();
49
30
 
50
31
  return (
@@ -73,21 +54,34 @@ export default function MoreEdit( {
73
54
  'Hide the excerpt on the full content page'
74
55
  ) }
75
56
  checked={ !! noTeaser }
76
- onChange={ toggleHideExcerpt }
77
- help={ getHideExcerptHelp }
57
+ onChange={ () =>
58
+ setAttributes( { noTeaser: ! noTeaser } )
59
+ }
60
+ help={ ( checked ) =>
61
+ checked
62
+ ? __( 'The excerpt is hidden.' )
63
+ : __( 'The excerpt is visible.' )
64
+ }
78
65
  />
79
66
  </ToolsPanelItem>
80
67
  </ToolsPanel>
81
68
  </InspectorControls>
82
69
  <div { ...useBlockProps() }>
83
- <input
84
- aria-label={ __( '“Read more” link text' ) }
85
- type="text"
70
+ <PlainText
71
+ __experimentalVersion={ 2 }
72
+ tagName="span"
73
+ aria-label={ __( '"Read more" text' ) }
86
74
  value={ customText }
87
75
  placeholder={ DEFAULT_TEXT }
88
- onChange={ onChangeInput }
89
- onKeyDown={ onKeyDown }
90
- style={ style }
76
+ onChange={ ( value ) =>
77
+ setAttributes( { customText: value } )
78
+ }
79
+ disableLineBreaks
80
+ __unstableOnSplitAtEnd={ () =>
81
+ insertBlocksAfter(
82
+ createBlock( getDefaultBlockName() )
83
+ )
84
+ }
91
85
  />
92
86
  </div>
93
87
  </>
@@ -11,27 +11,18 @@
11
11
  white-space: nowrap;
12
12
 
13
13
  // Label
14
- input[type="text"] {
14
+ .rich-text {
15
15
  position: relative;
16
16
  font-size: $default-font-size;
17
17
  text-transform: uppercase;
18
18
  font-weight: 600;
19
19
  font-family: $default-font;
20
20
  color: $gray-700;
21
- border: none;
22
- box-shadow: none;
21
+ display: inline-flex;
23
22
  white-space: nowrap;
24
23
  text-align: center;
25
- margin: 0;
26
- border-radius: 4px;
27
24
  background: $white;
28
- padding: 6px 8px;
29
- height: $button-size-small;
30
- max-width: 100%;
31
-
32
- &:focus {
33
- box-shadow: none;
34
- }
25
+ padding: 10px 36px;
35
26
  }
36
27
 
37
28
  // Dashed line
@@ -1,10 +1,4 @@
1
1
  .wp-block-navigation {
2
- // Block wrapper gets the classes in the editor, and there's an extra div wrapper for now, so background styles need to be inherited.
3
- .wp-block-page-list > div,
4
- .wp-block-page-list {
5
- background-color: inherit;
6
- }
7
-
8
2
  // space-between justification.
9
3
  &.items-justified-space-between {
10
4
  .wp-block-page-list > div,
@@ -81,8 +81,8 @@ function DropCapControl( { clientId, attributes, setAttributes, name } ) {
81
81
  hasValue={ () => !! dropCap }
82
82
  label={ __( 'Drop cap' ) }
83
83
  isShownByDefault={ isDropCapControlEnabledByDefault }
84
- onDeselect={ () => setAttributes( { dropCap: undefined } ) }
85
- resetAllFilter={ () => ( { dropCap: undefined } ) }
84
+ onDeselect={ () => setAttributes( { dropCap: false } ) }
85
+ resetAllFilter={ () => ( { dropCap: false } ) }
86
86
  panelId={ clientId }
87
87
  >
88
88
  <ToggleControl
@@ -12,6 +12,9 @@
12
12
  }
13
13
  },
14
14
  "usesContext": [ "postId" ],
15
+ "example": {
16
+ "viewportWidth": 350
17
+ },
15
18
  "supports": {
16
19
  "html": false,
17
20
  "color": {
@@ -12,6 +12,9 @@
12
12
  "type": "string"
13
13
  }
14
14
  },
15
+ "example": {
16
+ "viewportWidth": 350
17
+ },
15
18
  "supports": {
16
19
  "html": false,
17
20
  "color": {
@@ -7,6 +7,10 @@
7
7
  "description": "Display the publish date for an entry such as a post or page.",
8
8
  "textdomain": "default",
9
9
  "attributes": {
10
+ "datetime": {
11
+ "type": "string",
12
+ "role": "content"
13
+ },
10
14
  "textAlign": {
11
15
  "type": "string"
12
16
  },
@@ -17,10 +21,6 @@
17
21
  "type": "boolean",
18
22
  "default": false,
19
23
  "role": "content"
20
- },
21
- "displayType": {
22
- "type": "string",
23
- "default": "date"
24
24
  }
25
25
  },
26
26
  "usesContext": [ "postId", "postType", "queryId" ],
@@ -1,8 +1,111 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import clsx from 'clsx';
5
+
1
6
  /**
2
7
  * Internal dependencies
3
8
  */
4
9
  import migrateFontFamily from '../utils/migrate-font-family';
5
10
 
11
+ const v2 = {
12
+ attributes: {
13
+ textAlign: {
14
+ type: 'string',
15
+ },
16
+ format: {
17
+ type: 'string',
18
+ },
19
+ isLink: {
20
+ type: 'boolean',
21
+ default: false,
22
+ role: 'content',
23
+ },
24
+ displayType: {
25
+ type: 'string',
26
+ default: 'date',
27
+ },
28
+ },
29
+ supports: {
30
+ html: false,
31
+ color: {
32
+ gradients: true,
33
+ link: true,
34
+ __experimentalDefaultControls: {
35
+ background: true,
36
+ text: true,
37
+ link: true,
38
+ },
39
+ },
40
+ spacing: {
41
+ margin: true,
42
+ padding: true,
43
+ },
44
+ typography: {
45
+ fontSize: true,
46
+ lineHeight: true,
47
+ __experimentalFontFamily: true,
48
+ __experimentalFontWeight: true,
49
+ __experimentalFontStyle: true,
50
+ __experimentalTextTransform: true,
51
+ __experimentalTextDecoration: true,
52
+ __experimentalLetterSpacing: true,
53
+ __experimentalDefaultControls: {
54
+ fontSize: true,
55
+ },
56
+ },
57
+ interactivity: {
58
+ clientNavigation: true,
59
+ },
60
+ __experimentalBorder: {
61
+ radius: true,
62
+ color: true,
63
+ width: true,
64
+ style: true,
65
+ __experimentalDefaultControls: {
66
+ radius: true,
67
+ color: true,
68
+ width: true,
69
+ style: true,
70
+ },
71
+ },
72
+ },
73
+ save() {
74
+ return null;
75
+ },
76
+ migrate( { className, displayType, metadata, ...otherAttributes } ) {
77
+ if ( displayType === 'date' || displayType === 'modified' ) {
78
+ if ( displayType === 'modified' ) {
79
+ className = clsx(
80
+ className,
81
+ 'wp-block-post-date__modified-date'
82
+ );
83
+ }
84
+
85
+ return {
86
+ ...otherAttributes,
87
+ className,
88
+ metadata: {
89
+ ...metadata,
90
+ bindings: {
91
+ datetime: {
92
+ source: 'core/post-data',
93
+ args: { key: displayType },
94
+ },
95
+ },
96
+ },
97
+ };
98
+ }
99
+ },
100
+ isEligible( attributes ) {
101
+ // If there's neither an explicit `datetime` attribute nor a block binding for that attribute,
102
+ // then we're dealing with an old version of the block.
103
+ return (
104
+ ! attributes.datetime && ! attributes?.metadata?.bindings?.datetime
105
+ );
106
+ },
107
+ };
108
+
6
109
  const v1 = {
7
110
  attributes: {
8
111
  textAlign: {
@@ -49,4 +152,4 @@ const v1 = {
49
152
  *
50
153
  * See block-deprecation.md
51
154
  */
52
- export default [ v1 ];
155
+ export default [ v2, v1 ];
@@ -7,7 +7,7 @@ import clsx from 'clsx';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { useEntityProp, store as coreStore } from '@wordpress/core-data';
10
- import { useMemo, useState } from '@wordpress/element';
10
+ import { useEffect, useMemo, useState } from '@wordpress/element';
11
11
  import {
12
12
  dateI18n,
13
13
  humanTimeDiff,
@@ -17,6 +17,7 @@ import {
17
17
  AlignmentControl,
18
18
  BlockControls,
19
19
  InspectorControls,
20
+ store as blockEditorStore,
20
21
  useBlockProps,
21
22
  __experimentalDateFormatPicker as DateFormatPicker,
22
23
  __experimentalPublishDateTimePicker as PublishDateTimePicker,
@@ -32,7 +33,7 @@ import {
32
33
  import { __, _x, sprintf } from '@wordpress/i18n';
33
34
  import { edit } from '@wordpress/icons';
34
35
  import { DOWN } from '@wordpress/keycodes';
35
- import { useSelect } from '@wordpress/data';
36
+ import { useSelect, useDispatch } from '@wordpress/data';
36
37
 
37
38
  /**
38
39
  * Internal dependencies
@@ -40,14 +41,17 @@ import { useSelect } from '@wordpress/data';
40
41
  import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
41
42
 
42
43
  export default function PostDateEdit( {
43
- attributes: { textAlign, format, isLink, displayType },
44
- context: { postId, postType: postTypeSlug, queryId },
44
+ attributes: { datetime, textAlign, format, isLink, metadata },
45
+ context: { postType: postTypeSlug, queryId },
45
46
  setAttributes,
46
47
  } ) {
48
+ const displayType =
49
+ metadata?.bindings?.datetime?.source === 'core/post-data' &&
50
+ metadata?.bindings?.datetime?.args?.key;
51
+
47
52
  const blockProps = useBlockProps( {
48
53
  className: clsx( {
49
54
  [ `has-text-align-${ textAlign }` ]: textAlign,
50
- [ `wp-block-post-date__modified-date` ]: displayType === 'modified',
51
55
  } ),
52
56
  } );
53
57
  const dropdownMenuProps = useToolsPanelDropdownMenuProps();
@@ -61,6 +65,19 @@ export default function PostDateEdit( {
61
65
  [ popoverAnchor ]
62
66
  );
63
67
 
68
+ const { __unstableMarkNextChangeAsNotPersistent } =
69
+ useDispatch( blockEditorStore );
70
+
71
+ // We need to set the datetime to a default value upon first loading
72
+ // to discern the block from its legacy version (which would default
73
+ // to the containing post's publish date).
74
+ useEffect( () => {
75
+ if ( datetime === undefined ) {
76
+ __unstableMarkNextChangeAsNotPersistent();
77
+ setAttributes( { datetime: new Date() } );
78
+ }
79
+ }, [ datetime ] );
80
+
64
81
  const isDescendentOfQueryLoop = Number.isFinite( queryId );
65
82
  const dateSettings = getDateSettings();
66
83
  const [ siteFormat = dateSettings.formats.date ] = useEntityProp(
@@ -73,12 +90,6 @@ export default function PostDateEdit( {
73
90
  'site',
74
91
  'time_format'
75
92
  );
76
- const [ date, setDate ] = useEntityProp(
77
- 'postType',
78
- postTypeSlug,
79
- displayType,
80
- postId
81
- );
82
93
 
83
94
  const postType = useSelect(
84
95
  ( select ) =>
@@ -88,20 +99,15 @@ export default function PostDateEdit( {
88
99
  [ postTypeSlug ]
89
100
  );
90
101
 
91
- const dateLabel =
92
- displayType === 'date' ? __( 'Post Date' ) : __( 'Post Modified Date' );
93
-
94
- let postDate = date ? (
95
- <time dateTime={ dateI18n( 'c', date ) } ref={ setPopoverAnchor }>
102
+ let postDate = (
103
+ <time dateTime={ dateI18n( 'c', datetime ) } ref={ setPopoverAnchor }>
96
104
  { format === 'human-diff'
97
- ? humanTimeDiff( date )
98
- : dateI18n( format || siteFormat, date ) }
105
+ ? humanTimeDiff( datetime )
106
+ : dateI18n( format || siteFormat, datetime ) }
99
107
  </time>
100
- ) : (
101
- dateLabel
102
108
  );
103
109
 
104
- if ( isLink && date ) {
110
+ if ( isLink && datetime ) {
105
111
  postDate = (
106
112
  <a
107
113
  href="#post-date-pseudo-link"
@@ -121,49 +127,53 @@ export default function PostDateEdit( {
121
127
  setAttributes( { textAlign: nextAlign } );
122
128
  } }
123
129
  />
124
- { date &&
125
- displayType === 'date' &&
126
- ! isDescendentOfQueryLoop && (
127
- <ToolbarGroup>
128
- <Dropdown
129
- popoverProps={ popoverProps }
130
- renderContent={ ( { onClose } ) => (
131
- <PublishDateTimePicker
132
- currentDate={ date }
133
- onChange={ setDate }
134
- is12Hour={ is12HourFormat(
135
- siteTimeFormat
136
- ) }
137
- onClose={ onClose }
138
- dateOrder={
139
- /* translators: Order of day, month, and year. Available formats are 'dmy', 'mdy', and 'ymd'. */
140
- _x( 'dmy', 'date order' )
141
- }
130
+ { displayType !== 'modified' && ! isDescendentOfQueryLoop && (
131
+ <ToolbarGroup>
132
+ <Dropdown
133
+ popoverProps={ popoverProps }
134
+ renderContent={ ( { onClose } ) => (
135
+ <PublishDateTimePicker
136
+ title={
137
+ displayType === 'date'
138
+ ? __( 'Publish Date' )
139
+ : __( 'Date' )
140
+ }
141
+ currentDate={ datetime }
142
+ onChange={ ( newDatetime ) =>
143
+ setAttributes( {
144
+ datetime: newDatetime,
145
+ } )
146
+ }
147
+ is12Hour={ is12HourFormat(
148
+ siteTimeFormat
149
+ ) }
150
+ onClose={ onClose }
151
+ dateOrder={
152
+ /* translators: Order of day, month, and year. Available formats are 'dmy', 'mdy', and 'ymd'. */
153
+ _x( 'dmy', 'date order' )
154
+ }
155
+ />
156
+ ) }
157
+ renderToggle={ ( { isOpen, onToggle } ) => {
158
+ const openOnArrowDown = ( event ) => {
159
+ if ( ! isOpen && event.keyCode === DOWN ) {
160
+ event.preventDefault();
161
+ onToggle();
162
+ }
163
+ };
164
+ return (
165
+ <ToolbarButton
166
+ aria-expanded={ isOpen }
167
+ icon={ edit }
168
+ title={ __( 'Change Date' ) }
169
+ onClick={ onToggle }
170
+ onKeyDown={ openOnArrowDown }
142
171
  />
143
- ) }
144
- renderToggle={ ( { isOpen, onToggle } ) => {
145
- const openOnArrowDown = ( event ) => {
146
- if (
147
- ! isOpen &&
148
- event.keyCode === DOWN
149
- ) {
150
- event.preventDefault();
151
- onToggle();
152
- }
153
- };
154
- return (
155
- <ToolbarButton
156
- aria-expanded={ isOpen }
157
- icon={ edit }
158
- title={ __( 'Change Date' ) }
159
- onClick={ onToggle }
160
- onKeyDown={ openOnArrowDown }
161
- />
162
- );
163
- } }
164
- />
165
- </ToolbarGroup>
166
- ) }
172
+ );
173
+ } }
174
+ />
175
+ </ToolbarGroup>
176
+ ) }
167
177
  </BlockControls>
168
178
 
169
179
  <InspectorControls>
@@ -171,9 +181,9 @@ export default function PostDateEdit( {
171
181
  label={ __( 'Settings' ) }
172
182
  resetAll={ () => {
173
183
  setAttributes( {
184
+ datetime: undefined,
174
185
  format: undefined,
175
186
  isLink: false,
176
- displayType: 'date',
177
187
  } );
178
188
  } }
179
189
  dropdownMenuProps={ dropdownMenuProps }
@@ -225,28 +235,6 @@ export default function PostDateEdit( {
225
235
  checked={ isLink }
226
236
  />
227
237
  </ToolsPanelItem>
228
- <ToolsPanelItem
229
- hasValue={ () => displayType !== 'date' }
230
- label={ __( 'Display last modified date' ) }
231
- onDeselect={ () =>
232
- setAttributes( { displayType: 'date' } )
233
- }
234
- isShownByDefault
235
- >
236
- <ToggleControl
237
- __nextHasNoMarginBottom
238
- label={ __( 'Display last modified date' ) }
239
- onChange={ ( value ) =>
240
- setAttributes( {
241
- displayType: value ? 'modified' : 'date',
242
- } )
243
- }
244
- checked={ displayType === 'modified' }
245
- help={ __(
246
- 'Only shows if the post has been modified'
247
- ) }
248
- />
249
- </ToolsPanelItem>
250
238
  </ToolsPanel>
251
239
  </InspectorControls>
252
240