@wordpress/block-library 9.0.4 → 9.2.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 (91) hide show
  1. package/CHANGELOG.md +21 -17
  2. package/build/button/index.js +1 -0
  3. package/build/button/index.js.map +1 -1
  4. package/build/comment-date/edit.js +1 -1
  5. package/build/comment-date/edit.js.map +1 -1
  6. package/build/list-item/edit.native.js +1 -15
  7. package/build/list-item/edit.native.js.map +1 -1
  8. package/build/missing/edit.native.js +29 -4
  9. package/build/missing/edit.native.js.map +1 -1
  10. package/build/post-content/index.js +13 -1
  11. package/build/post-content/index.js.map +1 -1
  12. package/build/post-date/edit.js +1 -1
  13. package/build/post-date/edit.js.map +1 -1
  14. package/build/pullquote/index.js +13 -0
  15. package/build/pullquote/index.js.map +1 -1
  16. package/build/query/edit/inspector-controls/create-new-post-link.js +10 -10
  17. package/build/query/edit/inspector-controls/create-new-post-link.js.map +1 -1
  18. package/build/query/edit/inspector-controls/index.js +2 -2
  19. package/build/query/edit/inspector-controls/index.js.map +1 -1
  20. package/build/quote/index.js +13 -0
  21. package/build/quote/index.js.map +1 -1
  22. package/build/site-tagline/index.js +1 -0
  23. package/build/site-tagline/index.js.map +1 -1
  24. package/build/site-title/index.js +1 -0
  25. package/build/site-title/index.js.map +1 -1
  26. package/build/table-of-contents/index.js +1 -1
  27. package/build/verse/index.js +14 -0
  28. package/build/verse/index.js.map +1 -1
  29. package/build-module/button/index.js +1 -0
  30. package/build-module/button/index.js.map +1 -1
  31. package/build-module/comment-date/edit.js +2 -2
  32. package/build-module/comment-date/edit.js.map +1 -1
  33. package/build-module/list-item/edit.native.js +2 -16
  34. package/build-module/list-item/edit.native.js.map +1 -1
  35. package/build-module/missing/edit.native.js +30 -5
  36. package/build-module/missing/edit.native.js.map +1 -1
  37. package/build-module/post-content/index.js +13 -1
  38. package/build-module/post-content/index.js.map +1 -1
  39. package/build-module/post-date/edit.js +2 -2
  40. package/build-module/post-date/edit.js.map +1 -1
  41. package/build-module/pullquote/index.js +13 -0
  42. package/build-module/pullquote/index.js.map +1 -1
  43. package/build-module/query/edit/inspector-controls/create-new-post-link.js +10 -10
  44. package/build-module/query/edit/inspector-controls/create-new-post-link.js.map +1 -1
  45. package/build-module/query/edit/inspector-controls/index.js +2 -2
  46. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  47. package/build-module/quote/index.js +13 -0
  48. package/build-module/quote/index.js.map +1 -1
  49. package/build-module/site-tagline/index.js +1 -0
  50. package/build-module/site-tagline/index.js.map +1 -1
  51. package/build-module/site-title/index.js +1 -0
  52. package/build-module/site-title/index.js.map +1 -1
  53. package/build-module/table-of-contents/index.js +1 -1
  54. package/build-module/verse/index.js +14 -0
  55. package/build-module/verse/index.js.map +1 -1
  56. package/build-style/editor-rtl.css +0 -11
  57. package/build-style/editor.css +0 -11
  58. package/build-style/image/style-rtl.css +6 -0
  59. package/build-style/image/style.css +6 -0
  60. package/build-style/media-text/style-rtl.css +4 -0
  61. package/build-style/media-text/style.css +4 -0
  62. package/build-style/navigation/editor-rtl.css +0 -11
  63. package/build-style/navigation/editor.css +0 -11
  64. package/build-style/style-rtl.css +10 -0
  65. package/build-style/style.css +10 -0
  66. package/package.json +35 -35
  67. package/src/button/block.json +1 -0
  68. package/src/buttons/test/edit.native.js +48 -8
  69. package/src/comment-date/edit.js +8 -2
  70. package/src/comment-date/index.php +7 -5
  71. package/src/image/style.scss +10 -0
  72. package/src/list-item/edit.native.js +2 -22
  73. package/src/media-text/style.scss +4 -0
  74. package/src/missing/edit.native.js +44 -12
  75. package/src/missing/test/__snapshots__/edit.native.js.snap +75 -59
  76. package/src/navigation/editor.scss +0 -12
  77. package/src/paragraph/test/__snapshots__/edit.native.js.snap +30 -0
  78. package/src/paragraph/test/edit.native.js +99 -0
  79. package/src/post-content/block.json +13 -1
  80. package/src/post-date/edit.js +8 -2
  81. package/src/post-date/index.php +14 -3
  82. package/src/pullquote/block.json +13 -0
  83. package/src/query/edit/inspector-controls/create-new-post-link.js +12 -8
  84. package/src/query/edit/inspector-controls/index.js +5 -3
  85. package/src/quote/block.json +13 -0
  86. package/src/site-logo/index.php +6 -0
  87. package/src/site-tagline/block.json +1 -0
  88. package/src/site-title/block.json +1 -0
  89. package/src/social-links/test/edit.native.js +41 -5
  90. package/src/table-of-contents/block.json +1 -1
  91. package/src/verse/block.json +14 -0
@@ -21,8 +21,7 @@ import { useState, useCallback, useRef } from '@wordpress/element';
21
21
  /**
22
22
  * Internal dependencies
23
23
  */
24
- import { useSplit, useMerge, useEnter } from './hooks';
25
- import { convertToListItems } from './utils';
24
+ import { useMerge, useEnter } from './hooks';
26
25
  import { IndentUI } from './edit.js';
27
26
  import styles from './style.scss';
28
27
  import ListStyleType from './list-style-type';
@@ -32,7 +31,6 @@ const OPACITY = '9e';
32
31
  export default function ListItemEdit( {
33
32
  attributes,
34
33
  setAttributes,
35
- onReplace,
36
34
  clientId,
37
35
  style,
38
36
  mergeBlocks,
@@ -118,24 +116,7 @@ export default function ListItemEdit( {
118
116
 
119
117
  const preventDefault = useRef( false );
120
118
  const { onEnter } = useEnter( { content, clientId }, preventDefault );
121
- const onSplit = useSplit( clientId );
122
119
  const onMerge = useMerge( clientId, mergeBlocks );
123
- const onSplitList = useCallback(
124
- ( value ) => {
125
- if ( ! preventDefault.current ) {
126
- return onSplit( value );
127
- }
128
- },
129
- [ clientId, onSplit ]
130
- );
131
- const onReplaceList = useCallback(
132
- ( blocks, ...args ) => {
133
- if ( ! preventDefault.current ) {
134
- onReplace( convertToListItems( blocks ), ...args );
135
- }
136
- },
137
- [ clientId, onReplace, convertToListItems ]
138
- );
139
120
  const onLayout = useCallback( ( { nativeEvent } ) => {
140
121
  setContentWidth( ( prevState ) => {
141
122
  const { width } = nativeEvent.layout;
@@ -166,6 +147,7 @@ export default function ListItemEdit( {
166
147
  onLayout={ onLayout }
167
148
  >
168
149
  <RichText
150
+ __unstableUseSplitSelection
169
151
  identifier="content"
170
152
  tagName="p"
171
153
  onChange={ ( nextContent ) =>
@@ -176,9 +158,7 @@ export default function ListItemEdit( {
176
158
  placeholderTextColor={
177
159
  defaultPlaceholderTextColorWithOpacity
178
160
  }
179
- onSplit={ onSplitList }
180
161
  onMerge={ onMerge }
181
- onReplace={ onReplaceList }
182
162
  onEnter={ onEnter }
183
163
  style={ styleWithPlaceholderOpacity }
184
164
  deleteEnter
@@ -68,6 +68,10 @@
68
68
  /*!rtl:end:ignore*/
69
69
  }
70
70
 
71
+ .wp-block-media-text__media a {
72
+ display: inline-block;
73
+ }
74
+
71
75
  .wp-block-media-text__media img,
72
76
  .wp-block-media-text__media video {
73
77
  height: auto;
@@ -1,12 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import {
5
- View,
6
- Text,
7
- TouchableWithoutFeedback,
8
- TouchableOpacity,
9
- } from 'react-native';
4
+ import { View, Text, TouchableOpacity } from 'react-native';
10
5
 
11
6
  /**
12
7
  * WordPress dependencies
@@ -25,6 +20,7 @@ import {
25
20
  store as blockEditorStore,
26
21
  } from '@wordpress/block-editor';
27
22
  import { store as noticesStore } from '@wordpress/notices';
23
+ import { requestUnsupportedBlockFallback } from '@wordpress/react-native-bridge';
28
24
 
29
25
  /**
30
26
  * Internal dependencies
@@ -48,11 +44,40 @@ export class UnsupportedBlockEdit extends Component {
48
44
  }
49
45
 
50
46
  toggleSheet() {
47
+ const { attributes, block, clientId } = this.props;
48
+ const { originalName } = attributes;
49
+ const title = this.getTitle();
50
+ const blockContent = serialize( block ? [ block ] : [] );
51
+
52
+ if ( this.canEditUnsupportedBlock() ) {
53
+ requestUnsupportedBlockFallback(
54
+ blockContent,
55
+ clientId,
56
+ originalName,
57
+ title
58
+ );
59
+ return;
60
+ }
61
+
51
62
  this.setState( {
52
63
  showHelp: ! this.state.showHelp,
53
64
  } );
54
65
  }
55
66
 
67
+ canEditUnsupportedBlock() {
68
+ const {
69
+ canEnableUnsupportedBlockEditor,
70
+ isEditableInUnsupportedBlockEditor,
71
+ isUnsupportedBlockEditorSupported,
72
+ } = this.props;
73
+
74
+ return (
75
+ ! canEnableUnsupportedBlockEditor &&
76
+ isUnsupportedBlockEditorSupported &&
77
+ isEditableInUnsupportedBlockEditor
78
+ );
79
+ }
80
+
56
81
  closeSheet() {
57
82
  this.setState( {
58
83
  showHelp: false,
@@ -171,7 +196,8 @@ export class UnsupportedBlockEdit extends Component {
171
196
 
172
197
  render() {
173
198
  const { originalName } = this.props.attributes;
174
- const { getStylesFromColorScheme, preferredColorScheme } = this.props;
199
+ const { isSelected, getStylesFromColorScheme, preferredColorScheme } =
200
+ this.props;
175
201
  const blockType = coreBlocks[ originalName ];
176
202
 
177
203
  const title = this.getTitle();
@@ -186,7 +212,11 @@ export class UnsupportedBlockEdit extends Component {
186
212
  );
187
213
 
188
214
  const subtitle = (
189
- <Text style={ subTitleStyle }>{ __( 'Unsupported' ) }</Text>
215
+ <Text style={ subTitleStyle }>
216
+ { this.canEditUnsupportedBlock()
217
+ ? __( 'Tap to edit' )
218
+ : __( 'Unsupported' ) }
219
+ </Text>
190
220
  );
191
221
 
192
222
  const icon = blockType
@@ -198,8 +228,9 @@ export class UnsupportedBlockEdit extends Component {
198
228
  );
199
229
  const iconClassName = 'unsupported-icon' + '-' + preferredColorScheme;
200
230
  return (
201
- <TouchableWithoutFeedback
202
- disabled={ ! this.props.isSelected }
231
+ <TouchableOpacity
232
+ disabled={ ! isSelected }
233
+ activeOpacity={ 0.5 }
203
234
  accessibilityLabel={ __( 'Help button' ) }
204
235
  accessibilityRole="button"
205
236
  accessibilityHint={ __( 'Tap here to show help' ) }
@@ -211,7 +242,8 @@ export class UnsupportedBlockEdit extends Component {
211
242
  styles.unsupportedBlockDark
212
243
  ) }
213
244
  >
214
- { this.renderHelpIcon() }
245
+ { ! this.canEditUnsupportedBlock() &&
246
+ this.renderHelpIcon() }
215
247
  <View style={ styles.unsupportedBlockHeader }>
216
248
  <Icon
217
249
  className={ iconClassName }
@@ -223,7 +255,7 @@ export class UnsupportedBlockEdit extends Component {
223
255
  { subtitle }
224
256
  { this.renderSheet( title, originalName ) }
225
257
  </View>
226
- </TouchableWithoutFeedback>
258
+ </TouchableOpacity>
227
259
  );
228
260
  }
229
261
  }
@@ -14,7 +14,16 @@ exports[`Missing block renders without crashing 1`] = `
14
14
  "selected": undefined,
15
15
  }
16
16
  }
17
+ accessibilityValue={
18
+ {
19
+ "max": undefined,
20
+ "min": undefined,
21
+ "now": undefined,
22
+ "text": undefined,
23
+ }
24
+ }
17
25
  accessible={true}
26
+ collapsable={false}
18
27
  focusable={true}
19
28
  onClick={[Function]}
20
29
  onResponderGrant={[Function]}
@@ -23,72 +32,79 @@ exports[`Missing block renders without crashing 1`] = `
23
32
  onResponderTerminate={[Function]}
24
33
  onResponderTerminationRequest={[Function]}
25
34
  onStartShouldSetResponder={[Function]}
35
+ style={
36
+ {
37
+ "opacity": 1,
38
+ }
39
+ }
26
40
  >
27
- <View
28
- accessibilityHint="Tap here to show help"
29
- accessibilityLabel="Help button"
30
- accessibilityRole="button"
31
- accessibilityState={
32
- {
33
- "busy": undefined,
34
- "checked": undefined,
35
- "disabled": undefined,
36
- "expanded": undefined,
37
- "selected": undefined,
41
+ <View>
42
+ <View
43
+ accessibilityHint="Tap here to show help"
44
+ accessibilityLabel="Help button"
45
+ accessibilityRole="button"
46
+ accessibilityState={
47
+ {
48
+ "busy": undefined,
49
+ "checked": undefined,
50
+ "disabled": undefined,
51
+ "expanded": undefined,
52
+ "selected": undefined,
53
+ }
38
54
  }
39
- }
40
- accessibilityValue={
41
- {
42
- "max": undefined,
43
- "min": undefined,
44
- "now": undefined,
45
- "text": undefined,
55
+ accessibilityValue={
56
+ {
57
+ "max": undefined,
58
+ "min": undefined,
59
+ "now": undefined,
60
+ "text": undefined,
61
+ }
46
62
  }
47
- }
48
- accessible={true}
49
- collapsable={false}
50
- focusable={true}
51
- onClick={[Function]}
52
- onResponderGrant={[Function]}
53
- onResponderMove={[Function]}
54
- onResponderRelease={[Function]}
55
- onResponderTerminate={[Function]}
56
- onResponderTerminationRequest={[Function]}
57
- onStartShouldSetResponder={[Function]}
58
- style={
59
- {
60
- "opacity": 1,
63
+ accessible={true}
64
+ collapsable={false}
65
+ focusable={true}
66
+ onClick={[Function]}
67
+ onResponderGrant={[Function]}
68
+ onResponderMove={[Function]}
69
+ onResponderRelease={[Function]}
70
+ onResponderTerminate={[Function]}
71
+ onResponderTerminationRequest={[Function]}
72
+ onStartShouldSetResponder={[Function]}
73
+ style={
74
+ {
75
+ "opacity": 1,
76
+ }
61
77
  }
62
- }
63
- >
64
- <Svg
65
- height={24}
66
- label="Help icon"
67
- style={{}}
68
- viewBox="0 0 24 24"
69
- width={24}
70
- xmlns="http://www.w3.org/2000/svg"
71
- >
72
- Path
73
- </Svg>
74
- </View>
75
- <View>
76
- <Svg
77
- fill="white"
78
- height={24}
79
- style={{}}
80
- viewBox="0 0 24 24"
81
- width={24}
82
- xmlns="http://www.w3.org/2000/svg"
83
78
  >
84
- Path
85
- </Svg>
79
+ <Svg
80
+ height={24}
81
+ label="Help icon"
82
+ style={{}}
83
+ viewBox="0 0 24 24"
84
+ width={24}
85
+ xmlns="http://www.w3.org/2000/svg"
86
+ >
87
+ Path
88
+ </Svg>
89
+ </View>
90
+ <View>
91
+ <Svg
92
+ fill="white"
93
+ height={24}
94
+ style={{}}
95
+ viewBox="0 0 24 24"
96
+ width={24}
97
+ xmlns="http://www.w3.org/2000/svg"
98
+ >
99
+ Path
100
+ </Svg>
101
+ <Text>
102
+ missing/block/title
103
+ </Text>
104
+ </View>
86
105
  <Text>
87
- missing/block/title
106
+ Unsupported
88
107
  </Text>
89
108
  </View>
90
- <Text>
91
- Unsupported
92
- </Text>
93
109
  </View>
94
110
  `;
@@ -457,12 +457,6 @@ $color-control-label-height: 20px;
457
457
  }
458
458
  }
459
459
 
460
- .has-fixed-toolbar .wp-block-navigation__responsive-container.is-menu-open {
461
- @include break-medium() {
462
- top: $admin-bar-height + $header-height + $block-toolbar-height + $border-width;
463
- }
464
- }
465
-
466
460
  .is-mobile-preview .wp-block-navigation__responsive-container.is-menu-open,
467
461
  .is-tablet-preview .wp-block-navigation__responsive-container.is-menu-open {
468
462
  top: $admin-bar-height + $header-height + $block-toolbar-height + $border-width;
@@ -479,12 +473,6 @@ $color-control-label-height: 20px;
479
473
  }
480
474
  }
481
475
 
482
- .has-fixed-toolbar .wp-block-navigation__responsive-container.is-menu-open {
483
- @include break-medium() {
484
- top: $header-height + $block-toolbar-height + $border-width;
485
- }
486
- }
487
-
488
476
  .is-mobile-preview .wp-block-navigation__responsive-container.is-menu-open,
489
477
  .is-tablet-preview .wp-block-navigation__responsive-container.is-menu-open {
490
478
  top: $header-height + $block-toolbar-height + $border-width;
@@ -1,5 +1,35 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`Paragraph block should be able to use a prefix to create a Heading block 1`] = `
4
+ "<!-- wp:heading {"level":1} -->
5
+ <h1 class="wp-block-heading"></h1>
6
+ <!-- /wp:heading -->"
7
+ `;
8
+
9
+ exports[`Paragraph block should be able to use a prefix to create a List block 1`] = `
10
+ "<!-- wp:list -->
11
+ <ul class="wp-block-list"><!-- wp:list-item -->
12
+ <li></li>
13
+ <!-- /wp:list-item --></ul>
14
+ <!-- /wp:list -->"
15
+ `;
16
+
17
+ exports[`Paragraph block should be able to use a prefix to create a Quote block 1`] = `
18
+ "<!-- wp:quote -->
19
+ <blockquote class="wp-block-quote"><!-- wp:paragraph -->
20
+ <p></p>
21
+ <!-- /wp:paragraph --></blockquote>
22
+ <!-- /wp:quote -->"
23
+ `;
24
+
25
+ exports[`Paragraph block should be able to use a prefix to create a numbered List block 1`] = `
26
+ "<!-- wp:list {"ordered":true} -->
27
+ <ol class="wp-block-list"><!-- wp:list-item -->
28
+ <li></li>
29
+ <!-- /wp:list-item --></ol>
30
+ <!-- /wp:list -->"
31
+ `;
32
+
3
33
  exports[`Paragraph block should prevent deleting the first Paragraph block when pressing backspace at the start 1`] = `
4
34
  "<!-- wp:paragraph -->
5
35
  <p>A quick brown fox jumps over the lazy dog.</p>
@@ -90,6 +90,105 @@ describe( 'Paragraph block', () => {
90
90
  expect( getEditorHtml() ).toMatchSnapshot();
91
91
  } );
92
92
 
93
+ it( 'should be able to use a prefix to create a Heading block', async () => {
94
+ const screen = await initializeEditor();
95
+ await addBlock( screen, 'Paragraph' );
96
+ const text = '# ';
97
+
98
+ const paragraphBlock = getBlock( screen, 'Paragraph' );
99
+ fireEvent.press( paragraphBlock );
100
+ const paragraphTextInput =
101
+ within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
102
+ typeInRichText( paragraphTextInput, text, {
103
+ finalSelectionStart: 1,
104
+ finalSelectionEnd: 1,
105
+ } );
106
+
107
+ fireEvent( paragraphTextInput, 'onChange', {
108
+ nativeEvent: { text },
109
+ preventDefault() {},
110
+ } );
111
+
112
+ const headingBlock = getBlock( screen, 'Heading' );
113
+ expect( headingBlock ).toBeVisible();
114
+ expect( getEditorHtml() ).toMatchSnapshot();
115
+ } );
116
+
117
+ it( 'should be able to use a prefix to create a Quote block', async () => {
118
+ const screen = await initializeEditor();
119
+ await addBlock( screen, 'Paragraph' );
120
+ const text = '> ';
121
+
122
+ const paragraphBlock = getBlock( screen, 'Paragraph' );
123
+ fireEvent.press( paragraphBlock );
124
+ const paragraphTextInput =
125
+ within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
126
+ typeInRichText( paragraphTextInput, text, {
127
+ finalSelectionStart: 1,
128
+ finalSelectionEnd: 1,
129
+ } );
130
+
131
+ fireEvent( paragraphTextInput, 'onChange', {
132
+ nativeEvent: { text },
133
+ preventDefault() {},
134
+ } );
135
+ const quoteBlock = getBlock( screen, 'Quote' );
136
+ await triggerBlockListLayout( quoteBlock );
137
+
138
+ expect( quoteBlock ).toBeVisible();
139
+ expect( getEditorHtml() ).toMatchSnapshot();
140
+ } );
141
+
142
+ it( 'should be able to use a prefix to create a List block', async () => {
143
+ const screen = await initializeEditor();
144
+ await addBlock( screen, 'Paragraph' );
145
+ const text = '- ';
146
+
147
+ const paragraphBlock = getBlock( screen, 'Paragraph' );
148
+ fireEvent.press( paragraphBlock );
149
+ const paragraphTextInput =
150
+ within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
151
+ typeInRichText( paragraphTextInput, text, {
152
+ finalSelectionStart: 1,
153
+ finalSelectionEnd: 1,
154
+ } );
155
+
156
+ fireEvent( paragraphTextInput, 'onChange', {
157
+ nativeEvent: { text },
158
+ preventDefault() {},
159
+ } );
160
+ const listBlock = getBlock( screen, 'List' );
161
+ await triggerBlockListLayout( listBlock );
162
+
163
+ expect( listBlock ).toBeVisible();
164
+ expect( getEditorHtml() ).toMatchSnapshot();
165
+ } );
166
+
167
+ it( 'should be able to use a prefix to create a numbered List block', async () => {
168
+ const screen = await initializeEditor();
169
+ await addBlock( screen, 'Paragraph' );
170
+ const text = '1. ';
171
+
172
+ const paragraphBlock = getBlock( screen, 'Paragraph' );
173
+ fireEvent.press( paragraphBlock );
174
+ const paragraphTextInput =
175
+ within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
176
+ typeInRichText( paragraphTextInput, text, {
177
+ finalSelectionStart: 2,
178
+ finalSelectionEnd: 2,
179
+ } );
180
+
181
+ fireEvent( paragraphTextInput, 'onChange', {
182
+ nativeEvent: { text },
183
+ preventDefault() {},
184
+ } );
185
+ const listBlock = getBlock( screen, 'List' );
186
+ await triggerBlockListLayout( listBlock );
187
+
188
+ expect( listBlock ).toBeVisible();
189
+ expect( getEditorHtml() ).toMatchSnapshot();
190
+ } );
191
+
93
192
  it( 'should bold text', async () => {
94
193
  // Arrange
95
194
  const screen = await initializeEditor();
@@ -11,11 +11,23 @@
11
11
  "align": [ "wide", "full" ],
12
12
  "html": false,
13
13
  "layout": true,
14
+ "background": {
15
+ "backgroundImage": true,
16
+ "backgroundSize": true,
17
+ "__experimentalDefaultControls": {
18
+ "backgroundImage": true
19
+ }
20
+ },
14
21
  "dimensions": {
15
22
  "minHeight": true
16
23
  },
17
24
  "spacing": {
18
- "blockGap": true
25
+ "blockGap": true,
26
+ "padding": true,
27
+ "__experimentalDefaultControls": {
28
+ "margin": false,
29
+ "padding": false
30
+ }
19
31
  },
20
32
  "color": {
21
33
  "gradients": true,
@@ -8,7 +8,11 @@ import clsx from 'clsx';
8
8
  */
9
9
  import { useEntityProp, store as coreStore } from '@wordpress/core-data';
10
10
  import { useMemo, useState } from '@wordpress/element';
11
- import { dateI18n, getSettings as getDateSettings } from '@wordpress/date';
11
+ import {
12
+ dateI18n,
13
+ humanTimeDiff,
14
+ getSettings as getDateSettings,
15
+ } from '@wordpress/date';
12
16
  import {
13
17
  AlignmentControl,
14
18
  BlockControls,
@@ -82,7 +86,9 @@ export default function PostDateEdit( {
82
86
 
83
87
  let postDate = date ? (
84
88
  <time dateTime={ dateI18n( 'c', date ) } ref={ setPopoverAnchor }>
85
- { dateI18n( format || siteFormat, date ) }
89
+ { format === 'human-diff'
90
+ ? humanTimeDiff( date )
91
+ : dateI18n( format || siteFormat, date ) }
86
92
  </time>
87
93
  ) : (
88
94
  dateLabel
@@ -20,8 +20,14 @@ function render_block_core_post_date( $attributes, $content, $block ) {
20
20
  return '';
21
21
  }
22
22
 
23
- $post_ID = $block->context['postId'];
24
- $formatted_date = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
23
+ $post_ID = $block->context['postId'];
24
+
25
+ if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
26
+ // translators: %s: human-readable time difference.
27
+ $formatted_date = sprintf( __( '%s ago', 'gutenberg' ), human_time_diff( get_post_timestamp( $post_ID ) ) );
28
+ } else {
29
+ $formatted_date = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
30
+ }
25
31
  $unformatted_date = esc_attr( get_the_date( 'c', $post_ID ) );
26
32
  $classes = array();
27
33
 
@@ -38,7 +44,12 @@ function render_block_core_post_date( $attributes, $content, $block ) {
38
44
  */
39
45
  if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
40
46
  if ( get_the_modified_date( 'Ymdhi', $post_ID ) > get_the_date( 'Ymdhi', $post_ID ) ) {
41
- $formatted_date = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
47
+ if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
48
+ // translators: %s: human-readable time difference.
49
+ $formatted_date = sprintf( __( '%s ago', 'gutenberg' ), human_time_diff( get_post_timestamp( $post_ID, 'modified' ) ) );
50
+ } else {
51
+ $formatted_date = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
52
+ }
42
53
  $unformatted_date = esc_attr( get_the_modified_date( 'c', $post_ID ) );
43
54
  $classes[] = 'wp-block-post-date__modified-date';
44
55
  } else {
@@ -26,6 +26,13 @@
26
26
  "supports": {
27
27
  "anchor": true,
28
28
  "align": [ "left", "right", "wide", "full" ],
29
+ "background": {
30
+ "backgroundImage": true,
31
+ "backgroundSize": true,
32
+ "__experimentalDefaultControls": {
33
+ "backgroundImage": true
34
+ }
35
+ },
29
36
  "color": {
30
37
  "gradients": true,
31
38
  "background": true,
@@ -35,6 +42,12 @@
35
42
  "text": true
36
43
  }
37
44
  },
45
+ "dimensions": {
46
+ "minHeight": true,
47
+ "__experimentalDefaultControls": {
48
+ "minHeight": false
49
+ }
50
+ },
38
51
  "spacing": {
39
52
  "margin": true,
40
53
  "padding": true
@@ -1,23 +1,27 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { __ } from '@wordpress/i18n';
5
4
  import { createInterpolateElement } from '@wordpress/element';
6
5
  import { addQueryArgs } from '@wordpress/url';
6
+ import { store as coreStore } from '@wordpress/core-data';
7
+ import { useSelect } from '@wordpress/data';
7
8
 
8
- const CreateNewPostLink = ( {
9
- attributes: { query: { postType } = {} } = {},
10
- } ) => {
11
- if ( ! postType ) {
12
- return null;
13
- }
9
+ const CreateNewPostLink = ( { postType } ) => {
14
10
  const newPostUrl = addQueryArgs( 'post-new.php', {
15
11
  post_type: postType,
16
12
  } );
13
+
14
+ const addNewItemLabel = useSelect(
15
+ ( select ) => {
16
+ const { getPostType } = select( coreStore );
17
+ return getPostType( postType )?.labels?.add_new_item;
18
+ },
19
+ [ postType ]
20
+ );
17
21
  return (
18
22
  <div className="wp-block-query__create-new-link">
19
23
  { createInterpolateElement(
20
- __( '<a>Add new post</a>' ),
24
+ '<a>' + addNewItemLabel + '</a>',
21
25
  // eslint-disable-next-line jsx-a11y/anchor-has-content
22
26
  { a: <a href={ newPostUrl } /> }
23
27
  ) }
@@ -131,9 +131,11 @@ export default function QueryInspectorControls( props ) {
131
131
 
132
132
  return (
133
133
  <>
134
- <BlockInfo>
135
- <CreateNewPostLink { ...props } />
136
- </BlockInfo>
134
+ { !! postType && (
135
+ <BlockInfo>
136
+ <CreateNewPostLink postType={ postType } />
137
+ </BlockInfo>
138
+ ) }
137
139
  { showSettingsPanel && (
138
140
  <PanelBody title={ __( 'Settings' ) }>
139
141
  { showInheritControl && (