@wordpress/block-library 7.13.0 → 7.13.1-next.957ca95e4c.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 (242) hide show
  1. package/build/columns/transforms.js +10 -1
  2. package/build/columns/transforms.js.map +1 -1
  3. package/build/cover/edit/block-controls.js +9 -2
  4. package/build/cover/edit/block-controls.js.map +1 -1
  5. package/build/gallery/gap-styles.js +5 -4
  6. package/build/gallery/gap-styles.js.map +1 -1
  7. package/build/home-link/index.js +14 -1
  8. package/build/home-link/index.js.map +1 -1
  9. package/build/image/edit.js +3 -1
  10. package/build/image/edit.js.map +1 -1
  11. package/build/image/use-client-width.js +3 -1
  12. package/build/image/use-client-width.js.map +1 -1
  13. package/build/index.js +1 -1
  14. package/build/index.js.map +1 -1
  15. package/build/index.native.js +3 -15
  16. package/build/index.native.js.map +1 -1
  17. package/build/latest-posts/deprecated.js +14 -1
  18. package/build/latest-posts/deprecated.js.map +1 -1
  19. package/build/latest-posts/index.js +14 -1
  20. package/build/latest-posts/index.js.map +1 -1
  21. package/build/list/deprecated.js +84 -1
  22. package/build/list/deprecated.js.map +1 -1
  23. package/build/list/edit.js +153 -134
  24. package/build/list/edit.js.map +1 -1
  25. package/build/list/index.js +29 -34
  26. package/build/list/index.js.map +1 -1
  27. package/build/list/save.js +1 -5
  28. package/build/list/save.js.map +1 -1
  29. package/build/list/{v2/tag-name.js → tag-name.js} +0 -0
  30. package/build/list/tag-name.js.map +1 -0
  31. package/build/list/{v2/tag-name.native.js → tag-name.native.js} +0 -0
  32. package/build/list/tag-name.native.js.map +1 -0
  33. package/build/list/transforms.js +61 -95
  34. package/build/list/transforms.js.map +1 -1
  35. package/build/list/{v2/migrate.js → utils.js} +3 -2
  36. package/build/list/utils.js.map +1 -0
  37. package/build/list-item/edit.native.js +21 -3
  38. package/build/list-item/edit.native.js.map +1 -1
  39. package/build/list-item/hooks/use-copy.js +2 -0
  40. package/build/list-item/hooks/use-copy.js.map +1 -1
  41. package/build/list-item/hooks/use-merge.js +0 -1
  42. package/build/list-item/hooks/use-merge.js.map +1 -1
  43. package/build/list-item/hooks/use-outdent-list-item.js +0 -1
  44. package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
  45. package/build/list-item/hooks/use-space.js +10 -1
  46. package/build/list-item/hooks/use-space.js.map +1 -1
  47. package/build/list-item/index.js +0 -1
  48. package/build/list-item/index.js.map +1 -1
  49. package/build/list-item/utils.js +0 -1
  50. package/build/list-item/utils.js.map +1 -1
  51. package/build/navigation/edit/index.js +6 -3
  52. package/build/navigation/edit/index.js.map +1 -1
  53. package/build/navigation/edit/responsive-wrapper.js +6 -4
  54. package/build/navigation/edit/responsive-wrapper.js.map +1 -1
  55. package/build/navigation/edit/unsaved-inner-blocks.js +4 -15
  56. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  57. package/build/post-excerpt/index.js +4 -2
  58. package/build/post-excerpt/index.js.map +1 -1
  59. package/build/post-terms/edit.js +0 -1
  60. package/build/post-terms/edit.js.map +1 -1
  61. package/build/post-terms/use-post-terms.js +4 -24
  62. package/build/post-terms/use-post-terms.js.map +1 -1
  63. package/build/query-no-results/index.js +13 -0
  64. package/build/query-no-results/index.js.map +1 -1
  65. package/build/query-pagination-numbers/index.js +4 -2
  66. package/build/query-pagination-numbers/index.js.map +1 -1
  67. package/build/query-title/index.js +1 -0
  68. package/build/query-title/index.js.map +1 -1
  69. package/build/quote/index.js +4 -2
  70. package/build/quote/index.js.map +1 -1
  71. package/build/term-description/index.js +6 -0
  72. package/build/term-description/index.js.map +1 -1
  73. package/build/verse/index.js +1 -0
  74. package/build/verse/index.js.map +1 -1
  75. package/build-module/columns/transforms.js +10 -1
  76. package/build-module/columns/transforms.js.map +1 -1
  77. package/build-module/cover/edit/block-controls.js +10 -3
  78. package/build-module/cover/edit/block-controls.js.map +1 -1
  79. package/build-module/gallery/gap-styles.js +6 -5
  80. package/build-module/gallery/gap-styles.js.map +1 -1
  81. package/build-module/home-link/index.js +14 -1
  82. package/build-module/home-link/index.js.map +1 -1
  83. package/build-module/image/edit.js +4 -2
  84. package/build-module/image/edit.js.map +1 -1
  85. package/build-module/image/use-client-width.js +3 -1
  86. package/build-module/image/use-client-width.js.map +1 -1
  87. package/build-module/index.js +1 -1
  88. package/build-module/index.js.map +1 -1
  89. package/build-module/index.native.js +3 -15
  90. package/build-module/index.native.js.map +1 -1
  91. package/build-module/latest-posts/deprecated.js +14 -1
  92. package/build-module/latest-posts/deprecated.js.map +1 -1
  93. package/build-module/latest-posts/index.js +14 -1
  94. package/build-module/latest-posts/index.js.map +1 -1
  95. package/build-module/list/deprecated.js +83 -1
  96. package/build-module/list/deprecated.js.map +1 -1
  97. package/build-module/list/edit.js +151 -134
  98. package/build-module/list/edit.js.map +1 -1
  99. package/build-module/list/index.js +29 -29
  100. package/build-module/list/index.js.map +1 -1
  101. package/build-module/list/save.js +2 -6
  102. package/build-module/list/save.js.map +1 -1
  103. package/build-module/list/{v2/tag-name.js → tag-name.js} +0 -0
  104. package/build-module/list/tag-name.js.map +1 -0
  105. package/build-module/list/{v2/tag-name.native.js → tag-name.native.js} +0 -0
  106. package/build-module/list/tag-name.native.js.map +1 -0
  107. package/build-module/list/transforms.js +62 -97
  108. package/build-module/list/transforms.js.map +1 -1
  109. package/build-module/list/{v2/migrate.js → utils.js} +3 -2
  110. package/build-module/list/utils.js.map +1 -0
  111. package/build-module/list-item/edit.native.js +19 -3
  112. package/build-module/list-item/edit.native.js.map +1 -1
  113. package/build-module/list-item/hooks/use-copy.js +2 -0
  114. package/build-module/list-item/hooks/use-copy.js.map +1 -1
  115. package/build-module/list-item/hooks/use-merge.js +0 -1
  116. package/build-module/list-item/hooks/use-merge.js.map +1 -1
  117. package/build-module/list-item/hooks/use-outdent-list-item.js +0 -1
  118. package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
  119. package/build-module/list-item/hooks/use-space.js +10 -1
  120. package/build-module/list-item/hooks/use-space.js.map +1 -1
  121. package/build-module/list-item/index.js +0 -1
  122. package/build-module/list-item/index.js.map +1 -1
  123. package/build-module/list-item/utils.js +0 -1
  124. package/build-module/list-item/utils.js.map +1 -1
  125. package/build-module/navigation/edit/index.js +5 -3
  126. package/build-module/navigation/edit/index.js.map +1 -1
  127. package/build-module/navigation/edit/responsive-wrapper.js +6 -4
  128. package/build-module/navigation/edit/responsive-wrapper.js.map +1 -1
  129. package/build-module/navigation/edit/unsaved-inner-blocks.js +5 -15
  130. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  131. package/build-module/post-excerpt/index.js +4 -2
  132. package/build-module/post-excerpt/index.js.map +1 -1
  133. package/build-module/post-terms/edit.js +0 -1
  134. package/build-module/post-terms/edit.js.map +1 -1
  135. package/build-module/post-terms/use-post-terms.js +5 -25
  136. package/build-module/post-terms/use-post-terms.js.map +1 -1
  137. package/build-module/query-no-results/index.js +13 -0
  138. package/build-module/query-no-results/index.js.map +1 -1
  139. package/build-module/query-pagination-numbers/index.js +4 -2
  140. package/build-module/query-pagination-numbers/index.js.map +1 -1
  141. package/build-module/query-title/index.js +1 -0
  142. package/build-module/query-title/index.js.map +1 -1
  143. package/build-module/quote/index.js +4 -2
  144. package/build-module/quote/index.js.map +1 -1
  145. package/build-module/term-description/index.js +6 -0
  146. package/build-module/term-description/index.js.map +1 -1
  147. package/build-module/verse/index.js +1 -0
  148. package/build-module/verse/index.js.map +1 -1
  149. package/build-style/button/style-rtl.css +1 -4
  150. package/build-style/button/style.css +1 -4
  151. package/build-style/code/editor-rtl.css +79 -0
  152. package/build-style/code/editor.css +79 -0
  153. package/build-style/cover/editor-rtl.css +0 -3
  154. package/build-style/cover/editor.css +0 -3
  155. package/build-style/editor-rtl.css +9 -44
  156. package/build-style/editor.css +9 -44
  157. package/build-style/group/editor-rtl.css +2 -22
  158. package/build-style/group/editor.css +2 -22
  159. package/build-style/navigation/editor-rtl.css +3 -19
  160. package/build-style/navigation/editor.css +3 -19
  161. package/build-style/navigation/style-rtl.css +8 -1
  162. package/build-style/navigation/style.css +8 -1
  163. package/build-style/style-rtl.css +9 -5
  164. package/build-style/style.css +9 -5
  165. package/package.json +28 -28
  166. package/src/button/style.scss +1 -8
  167. package/src/code/editor.scss +3 -0
  168. package/src/columns/transforms.js +17 -3
  169. package/src/cover/edit/block-controls.js +15 -3
  170. package/src/cover/editor.scss +0 -4
  171. package/src/editor.scss +1 -0
  172. package/src/gallery/gap-styles.js +10 -6
  173. package/src/gallery/index.php +23 -2
  174. package/src/group/editor.scss +1 -28
  175. package/src/home-link/block.json +14 -1
  176. package/src/image/edit.js +3 -3
  177. package/src/image/use-client-width.js +1 -1
  178. package/src/index.js +1 -4
  179. package/src/index.native.js +2 -13
  180. package/src/latest-posts/block.json +14 -1
  181. package/src/list/deprecated.js +71 -1
  182. package/src/list/edit.js +146 -133
  183. package/src/list/index.js +25 -24
  184. package/src/list/save.js +3 -4
  185. package/src/list/{v2/tag-name.js → tag-name.js} +0 -0
  186. package/src/list/{v2/tag-name.native.js → tag-name.native.js} +0 -0
  187. package/src/list/test/__snapshots__/edit.native.js.snap +14 -2
  188. package/src/list/test/edit.native.js +0 -154
  189. package/src/list/transforms.js +57 -111
  190. package/src/list/{v2/migrate.js → utils.js} +2 -2
  191. package/src/list-item/block.json +0 -1
  192. package/src/list-item/edit.native.js +32 -2
  193. package/src/list-item/hooks/use-copy.js +2 -0
  194. package/src/list-item/hooks/use-space.js +10 -2
  195. package/src/list-item/style.native.scss +8 -0
  196. package/src/navigation/edit/index.js +14 -4
  197. package/src/navigation/edit/responsive-wrapper.js +8 -3
  198. package/src/navigation/edit/unsaved-inner-blocks.js +14 -24
  199. package/src/navigation/editor.scss +2 -23
  200. package/src/navigation/index.php +13 -8
  201. package/src/navigation/style.scss +11 -2
  202. package/src/post-excerpt/block.json +4 -2
  203. package/src/post-terms/edit.js +0 -1
  204. package/src/post-terms/use-post-terms.js +10 -15
  205. package/src/query-no-results/block.json +13 -0
  206. package/src/query-pagination-numbers/block.json +4 -2
  207. package/src/query-title/block.json +1 -0
  208. package/src/quote/block.json +4 -2
  209. package/src/term-description/block.json +6 -0
  210. package/src/verse/block.json +1 -0
  211. package/build/list/v2/deprecated.js +0 -117
  212. package/build/list/v2/deprecated.js.map +0 -1
  213. package/build/list/v2/edit.js +0 -200
  214. package/build/list/v2/edit.js.map +0 -1
  215. package/build/list/v2/index.js +0 -36
  216. package/build/list/v2/index.js.map +0 -1
  217. package/build/list/v2/migrate.js.map +0 -1
  218. package/build/list/v2/save.js +0 -34
  219. package/build/list/v2/save.js.map +0 -1
  220. package/build/list/v2/tag-name.js.map +0 -1
  221. package/build/list/v2/tag-name.native.js.map +0 -1
  222. package/build/list/v2/transforms.js +0 -137
  223. package/build/list/v2/transforms.js.map +0 -1
  224. package/build-module/list/v2/deprecated.js +0 -104
  225. package/build-module/list/v2/deprecated.js.map +0 -1
  226. package/build-module/list/v2/edit.js +0 -179
  227. package/build-module/list/v2/edit.js.map +0 -1
  228. package/build-module/list/v2/index.js +0 -21
  229. package/build-module/list/v2/index.js.map +0 -1
  230. package/build-module/list/v2/migrate.js.map +0 -1
  231. package/build-module/list/v2/save.js +0 -23
  232. package/build-module/list/v2/save.js.map +0 -1
  233. package/build-module/list/v2/tag-name.js.map +0 -1
  234. package/build-module/list/v2/tag-name.native.js.map +0 -1
  235. package/build-module/list/v2/transforms.js +0 -127
  236. package/build-module/list/v2/transforms.js.map +0 -1
  237. package/src/list/test/migrate.js +0 -158
  238. package/src/list/v2/deprecated.js +0 -89
  239. package/src/list/v2/edit.js +0 -192
  240. package/src/list/v2/index.js +0 -22
  241. package/src/list/v2/save.js +0 -18
  242. package/src/list/v2/transforms.js +0 -120
@@ -7,7 +7,7 @@ export default function useClientWidth( ref, dependencies ) {
7
7
  const [ clientWidth, setClientWidth ] = useState();
8
8
 
9
9
  function calculateClientWidth() {
10
- setClientWidth( ref.current.clientWidth );
10
+ setClientWidth( ref.current?.clientWidth );
11
11
  }
12
12
 
13
13
  useEffect( calculateClientWidth, dependencies );
package/src/index.js CHANGED
@@ -290,10 +290,7 @@ export const registerCoreBlocks = (
290
290
  export const __experimentalRegisterExperimentalCoreBlocks = process.env
291
291
  .IS_GUTENBERG_PLUGIN
292
292
  ? ( { enableFSEBlocks } = {} ) => {
293
- const enabledExperiments = [
294
- window.__experimentalEnableListBlockV2 ? 'list-v2' : null,
295
- enableFSEBlocks ? 'fse' : null,
296
- ];
293
+ const enabledExperiments = [ enableFSEBlocks ? 'fse' : null ];
297
294
  getAllBlocks()
298
295
  .filter( ( { metadata } ) =>
299
296
  isBlockMetadataExperimental( metadata )
@@ -186,14 +186,6 @@ const devOnly = ( block ) => ( !! __DEV__ ? block : null );
186
186
  const iOSOnly = ( block ) =>
187
187
  Platform.OS === 'ios' ? block : devOnly( block );
188
188
 
189
- // To be removed once List V2 is released on the web editor.
190
- function listCheck( listBlock, blocksFlags ) {
191
- if ( blocksFlags?.__experimentalEnableListBlockV2 ) {
192
- listBlock.settings = listBlock?.settingsV2;
193
- }
194
- return listBlock;
195
- }
196
-
197
189
  // Hide the Classic block and SocialLink block
198
190
  addFilter(
199
191
  'blocks.registerBlockType',
@@ -245,11 +237,8 @@ addFilter(
245
237
  *
246
238
  * registerCoreBlocks();
247
239
  * ```
248
- * @param {Object} [blocksFlags] Experimental flags
249
- *
250
- *
251
240
  */
252
- export const registerCoreBlocks = ( blocksFlags ) => {
241
+ export const registerCoreBlocks = () => {
253
242
  // When adding new blocks to this list please also consider updating /src/block-support/supported-blocks.json in the Gutenberg-Mobile repo
254
243
  [
255
244
  paragraph,
@@ -261,7 +250,7 @@ export const registerCoreBlocks = ( blocksFlags ) => {
261
250
  video,
262
251
  nextpage,
263
252
  separator,
264
- listCheck( list, blocksFlags ),
253
+ list,
265
254
  listItem,
266
255
  quote,
267
256
  mediaText,
@@ -84,7 +84,20 @@
84
84
  },
85
85
  "supports": {
86
86
  "align": true,
87
- "html": false
87
+ "html": false,
88
+ "typography": {
89
+ "fontSize": true,
90
+ "lineHeight": true,
91
+ "__experimentalFontFamily": true,
92
+ "__experimentalFontWeight": true,
93
+ "__experimentalFontStyle": true,
94
+ "__experimentalTextTransform": true,
95
+ "__experimentalTextDecoration": true,
96
+ "__experimentalLetterSpacing": true,
97
+ "__experimentalDefaultControls": {
98
+ "fontSize": true
99
+ }
100
+ }
88
101
  },
89
102
  "editorStyle": "wp-block-latest-posts-editor",
90
103
  "style": "wp-block-latest-posts"
@@ -7,6 +7,7 @@ import { RichText, useBlockProps } from '@wordpress/block-editor';
7
7
  * Internal dependencies
8
8
  */
9
9
  import migrateFontFamily from '../utils/migrate-font-family';
10
+ import { migrateToListV2 } from './utils';
10
11
 
11
12
  const v0 = {
12
13
  attributes: {
@@ -68,6 +69,75 @@ const v0 = {
68
69
  },
69
70
  };
70
71
 
72
+ const v1 = {
73
+ attributes: {
74
+ ordered: {
75
+ type: 'boolean',
76
+ default: false,
77
+ __experimentalRole: 'content',
78
+ },
79
+ values: {
80
+ type: 'string',
81
+ source: 'html',
82
+ selector: 'ol,ul',
83
+ multiline: 'li',
84
+ __unstableMultilineWrapperTags: [ 'ol', 'ul' ],
85
+ default: '',
86
+ __experimentalRole: 'content',
87
+ },
88
+ type: {
89
+ type: 'string',
90
+ },
91
+ start: {
92
+ type: 'number',
93
+ },
94
+ reversed: {
95
+ type: 'boolean',
96
+ },
97
+ placeholder: {
98
+ type: 'string',
99
+ },
100
+ },
101
+ supports: {
102
+ anchor: true,
103
+ className: false,
104
+ typography: {
105
+ fontSize: true,
106
+ __experimentalFontFamily: true,
107
+ lineHeight: true,
108
+ __experimentalFontStyle: true,
109
+ __experimentalFontWeight: true,
110
+ __experimentalLetterSpacing: true,
111
+ __experimentalTextTransform: true,
112
+ __experimentalDefaultControls: {
113
+ fontSize: true,
114
+ },
115
+ },
116
+ color: {
117
+ gradients: true,
118
+ link: true,
119
+ __experimentalDefaultControls: {
120
+ background: true,
121
+ text: true,
122
+ },
123
+ },
124
+ __unstablePasteTextInline: true,
125
+ __experimentalSelector: 'ol,ul',
126
+ __experimentalSlashInserter: true,
127
+ },
128
+ save( { attributes } ) {
129
+ const { ordered, values, type, reversed, start } = attributes;
130
+ const TagName = ordered ? 'ol' : 'ul';
131
+
132
+ return (
133
+ <TagName { ...useBlockProps.save( { type, reversed, start } ) }>
134
+ <RichText.Content value={ values } multiline="li" />
135
+ </TagName>
136
+ );
137
+ },
138
+ migrate: migrateToListV2,
139
+ };
140
+
71
141
  /**
72
142
  * New deprecations need to be placed first
73
143
  * for them to have higher priority.
@@ -76,4 +146,4 @@ const v0 = {
76
146
  *
77
147
  * See block-deprecation.md
78
148
  */
79
- export default [ v0 ];
149
+ export default [ v1, v0 ];
package/src/list/edit.js CHANGED
@@ -1,177 +1,190 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { last } from 'lodash';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
- import { __, _x, isRTL } from '@wordpress/i18n';
5
- import { createBlock } from '@wordpress/blocks';
6
9
  import {
7
- RichText,
8
10
  BlockControls,
9
- RichTextShortcut,
10
11
  useBlockProps,
12
+ useInnerBlocksProps,
13
+ store as blockEditorStore,
11
14
  } from '@wordpress/block-editor';
12
15
  import { ToolbarButton } from '@wordpress/components';
13
- import {
14
- __unstableCanIndentListItems as canIndentListItems,
15
- __unstableCanOutdentListItems as canOutdentListItems,
16
- __unstableIndentListItems as indentListItems,
17
- __unstableOutdentListItems as outdentListItems,
18
- __unstableChangeListType as changeListType,
19
- __unstableIsListRootSelected as isListRootSelected,
20
- __unstableIsActiveListType as isActiveListType,
21
- } from '@wordpress/rich-text';
16
+ import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
17
+ import { isRTL, __ } from '@wordpress/i18n';
22
18
  import {
23
19
  formatListBullets,
24
20
  formatListBulletsRTL,
25
21
  formatListNumbered,
26
22
  formatListNumberedRTL,
27
- formatIndent,
28
- formatIndentRTL,
29
23
  formatOutdent,
30
24
  formatOutdentRTL,
31
25
  } from '@wordpress/icons';
26
+ import { createBlock } from '@wordpress/blocks';
27
+ import { useCallback, useEffect, Platform } from '@wordpress/element';
28
+ import deprecated from '@wordpress/deprecated';
32
29
 
33
30
  /**
34
31
  * Internal dependencies
35
32
  */
36
- import { name } from './';
37
33
  import OrderedListSettings from './ordered-list-settings';
34
+ import { migrateToListV2 } from './utils';
35
+ import TagName from './tag-name';
38
36
 
39
- export default function ListEdit( {
40
- attributes,
41
- setAttributes,
42
- mergeBlocks,
43
- onReplace,
44
- style,
45
- } ) {
46
- const { ordered, values, type, reversed, start, placeholder } = attributes;
47
- const tagName = ordered ? 'ol' : 'ul';
37
+ const TEMPLATE = [ [ 'core/list-item' ] ];
38
+ const NATIVE_MARGIN_SPACING = 8;
48
39
 
49
- const controls = ( { value, onChange, onFocus } ) => (
50
- <>
51
- <RichTextShortcut
52
- type="primary"
53
- character="["
54
- onUse={ () => {
55
- onChange( outdentListItems( value ) );
56
- } }
57
- />
58
- <RichTextShortcut
59
- type="primary"
60
- character="]"
61
- onUse={ () => {
62
- onChange( indentListItems( value, { type: tagName } ) );
63
- } }
64
- />
65
- <RichTextShortcut
66
- type="primary"
67
- character="m"
68
- onUse={ () => {
69
- onChange( indentListItems( value, { type: tagName } ) );
70
- } }
71
- />
72
- <RichTextShortcut
73
- type="primaryShift"
74
- character="m"
75
- onUse={ () => {
76
- onChange( outdentListItems( value ) );
77
- } }
78
- />
79
- <BlockControls group="block">
80
- <ToolbarButton
81
- icon={ isRTL() ? formatListBulletsRTL : formatListBullets }
82
- title={ __( 'Unordered' ) }
83
- describedBy={ __( 'Convert to unordered list' ) }
84
- isActive={ isActiveListType( value, 'ul', tagName ) }
85
- onClick={ () => {
86
- onChange( changeListType( value, { type: 'ul' } ) );
87
- onFocus();
40
+ /**
41
+ * At the moment, deprecations don't handle create blocks from attributes
42
+ * (like when using CPT templates). For this reason, this hook is necessary
43
+ * to avoid breaking templates using the old list block format.
44
+ *
45
+ * @param {Object} attributes Block attributes.
46
+ * @param {string} clientId Block client ID.
47
+ */
48
+ function useMigrateOnLoad( attributes, clientId ) {
49
+ const registry = useRegistry();
50
+ const { updateBlockAttributes, replaceInnerBlocks } =
51
+ useDispatch( blockEditorStore );
88
52
 
89
- if ( isListRootSelected( value ) ) {
90
- setAttributes( { ordered: false } );
91
- }
92
- } }
93
- />
94
- <ToolbarButton
95
- icon={
96
- isRTL() ? formatListNumberedRTL : formatListNumbered
97
- }
98
- title={ __( 'Ordered' ) }
99
- describedBy={ __( 'Convert to ordered list' ) }
100
- isActive={ isActiveListType( value, 'ol', tagName ) }
101
- onClick={ () => {
102
- onChange( changeListType( value, { type: 'ol' } ) );
103
- onFocus();
53
+ useEffect( () => {
54
+ // As soon as the block is loaded, migrate it to the new version.
104
55
 
105
- if ( isListRootSelected( value ) ) {
106
- setAttributes( { ordered: true } );
107
- }
108
- } }
109
- />
110
- <ToolbarButton
111
- icon={ isRTL() ? formatOutdentRTL : formatOutdent }
112
- title={ __( 'Outdent' ) }
113
- describedBy={ __( 'Outdent list item' ) }
114
- shortcut={ _x( 'Backspace', 'keyboard key' ) }
115
- isDisabled={ ! canOutdentListItems( value ) }
116
- onClick={ () => {
117
- onChange( outdentListItems( value ) );
118
- onFocus();
119
- } }
120
- />
121
- <ToolbarButton
122
- icon={ isRTL() ? formatIndentRTL : formatIndent }
123
- title={ __( 'Indent' ) }
124
- describedBy={ __( 'Indent list item' ) }
125
- shortcut={ _x( 'Space', 'keyboard key' ) }
126
- isDisabled={ ! canIndentListItems( value ) }
127
- onClick={ () => {
128
- onChange( indentListItems( value, { type: tagName } ) );
129
- onFocus();
130
- } }
131
- />
132
- </BlockControls>
56
+ if ( ! attributes.values ) {
57
+ return;
58
+ }
59
+
60
+ const [ newAttributes, newInnerBlocks ] = migrateToListV2( attributes );
61
+
62
+ deprecated( 'Value attribute on the list block', {
63
+ since: '6.0',
64
+ version: '6.5',
65
+ alternative: 'inner blocks',
66
+ } );
67
+
68
+ registry.batch( () => {
69
+ updateBlockAttributes( clientId, newAttributes );
70
+ replaceInnerBlocks( clientId, newInnerBlocks );
71
+ } );
72
+ }, [ attributes.values ] );
73
+ }
74
+
75
+ function useOutdentList( clientId ) {
76
+ const { canOutdent } = useSelect(
77
+ ( innerSelect ) => {
78
+ const { getBlockRootClientId, getBlock } =
79
+ innerSelect( blockEditorStore );
80
+ const parentId = getBlockRootClientId( clientId );
81
+ return {
82
+ canOutdent:
83
+ !! parentId &&
84
+ getBlock( parentId ).name === 'core/list-item',
85
+ };
86
+ },
87
+ [ clientId ]
88
+ );
89
+ const { replaceBlocks, selectionChange } = useDispatch( blockEditorStore );
90
+ const { getBlockRootClientId, getBlockAttributes, getBlock } =
91
+ useSelect( blockEditorStore );
92
+
93
+ return [
94
+ canOutdent,
95
+ useCallback( () => {
96
+ const parentBlockId = getBlockRootClientId( clientId );
97
+ const parentBlockAttributes = getBlockAttributes( parentBlockId );
98
+ // Create a new parent block without the inner blocks.
99
+ const newParentBlock = createBlock(
100
+ 'core/list-item',
101
+ parentBlockAttributes
102
+ );
103
+ const { innerBlocks } = getBlock( clientId );
104
+ // Replace the parent block with a new parent block without inner blocks,
105
+ // and make the inner blocks siblings of the parent.
106
+ replaceBlocks(
107
+ [ parentBlockId ],
108
+ [ newParentBlock, ...innerBlocks ]
109
+ );
110
+ // Select the last child of the list being outdent.
111
+ selectionChange( last( innerBlocks ).clientId );
112
+ }, [ clientId ] ),
113
+ ];
114
+ }
115
+
116
+ function IndentUI( { clientId } ) {
117
+ const [ canOutdent, outdentList ] = useOutdentList( clientId );
118
+ return (
119
+ <>
120
+ <ToolbarButton
121
+ icon={ isRTL() ? formatOutdentRTL : formatOutdent }
122
+ title={ __( 'Outdent' ) }
123
+ describedBy={ __( 'Outdent list item' ) }
124
+ disabled={ ! canOutdent }
125
+ onClick={ outdentList }
126
+ />
133
127
  </>
134
128
  );
129
+ }
135
130
 
131
+ export default function Edit( { attributes, setAttributes, clientId, style } ) {
136
132
  const blockProps = useBlockProps( {
137
- style,
133
+ ...( Platform.isNative && { style } ),
134
+ } );
135
+ const innerBlocksProps = useInnerBlocksProps( blockProps, {
136
+ allowedBlocks: [ 'core/list-item' ],
137
+ template: TEMPLATE,
138
+ templateInsertUpdatesSelection: true,
139
+ ...( Platform.isNative && {
140
+ marginVertical: NATIVE_MARGIN_SPACING,
141
+ marginHorizontal: NATIVE_MARGIN_SPACING,
142
+ useCompactList: true,
143
+ } ),
138
144
  } );
145
+ useMigrateOnLoad( attributes, clientId );
146
+ const { ordered, type, reversed, start } = attributes;
147
+
148
+ const controls = (
149
+ <BlockControls group="block">
150
+ <ToolbarButton
151
+ icon={ isRTL() ? formatListBulletsRTL : formatListBullets }
152
+ title={ __( 'Unordered' ) }
153
+ describedBy={ __( 'Convert to unordered list' ) }
154
+ isActive={ ordered === false }
155
+ onClick={ () => {
156
+ setAttributes( { ordered: false } );
157
+ } }
158
+ />
159
+ <ToolbarButton
160
+ icon={ isRTL() ? formatListNumberedRTL : formatListNumbered }
161
+ title={ __( 'Ordered' ) }
162
+ describedBy={ __( 'Convert to ordered list' ) }
163
+ isActive={ ordered === true }
164
+ onClick={ () => {
165
+ setAttributes( { ordered: true } );
166
+ } }
167
+ />
168
+ <IndentUI clientId={ clientId } />
169
+ </BlockControls>
170
+ );
139
171
 
140
172
  return (
141
173
  <>
142
- <RichText
143
- identifier="values"
144
- multiline="li"
145
- tagName={ tagName }
146
- onChange={ ( nextValues ) =>
147
- setAttributes( { values: nextValues } )
148
- }
149
- value={ values }
150
- aria-label={ __( 'List text' ) }
151
- placeholder={ placeholder || __( 'List' ) }
152
- onMerge={ mergeBlocks }
153
- onSplit={ ( value ) =>
154
- createBlock( name, { ...attributes, values: value } )
155
- }
156
- __unstableOnSplitMiddle={ () =>
157
- createBlock( 'core/paragraph' )
158
- }
159
- onReplace={ onReplace }
160
- onRemove={ () => onReplace( [] ) }
161
- start={ start }
174
+ <TagName
175
+ ordered={ ordered }
162
176
  reversed={ reversed }
177
+ start={ start }
163
178
  type={ type }
164
- { ...blockProps }
165
- >
166
- { controls }
167
- </RichText>
179
+ { ...innerBlocksProps }
180
+ />
181
+ { controls }
168
182
  { ordered && (
169
183
  <OrderedListSettings
170
184
  setAttributes={ setAttributes }
171
185
  ordered={ ordered }
172
186
  reversed={ reversed }
173
187
  start={ start }
174
- placeholder={ placeholder }
175
188
  />
176
189
  ) }
177
190
  </>
package/src/list/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { list as icon } from '@wordpress/icons';
5
+ import { __ } from '@wordpress/i18n';
5
6
 
6
7
  /**
7
8
  * Internal dependencies
@@ -11,41 +12,41 @@ import edit from './edit';
11
12
  import metadata from './block.json';
12
13
  import save from './save';
13
14
  import transforms from './transforms';
14
- import settingsV2 from './v2';
15
15
 
16
16
  const { name } = metadata;
17
17
 
18
- export { metadata, name, settingsV2 };
18
+ export { metadata, name };
19
19
 
20
- const settingsV1 = {
20
+ const settings = {
21
21
  icon,
22
22
  example: {
23
- attributes: {
24
- values: '<li>Alice.</li><li>The White Rabbit.</li><li>The Cheshire Cat.</li><li>The Mad Hatter.</li><li>The Queen of Hearts.</li>',
25
- },
23
+ innerBlocks: [
24
+ {
25
+ name: 'core/list-item',
26
+ attributes: { content: __( 'Alice.' ) },
27
+ },
28
+ {
29
+ name: 'core/list-item',
30
+ attributes: { content: __( 'The White Rabbit.' ) },
31
+ },
32
+ {
33
+ name: 'core/list-item',
34
+ attributes: { content: __( 'The Cheshire Cat.' ) },
35
+ },
36
+ {
37
+ name: 'core/list-item',
38
+ attributes: { content: __( 'The Mad Hatter.' ) },
39
+ },
40
+ {
41
+ name: 'core/list-item',
42
+ attributes: { content: __( 'The Queen of Hearts.' ) },
43
+ },
44
+ ],
26
45
  },
27
46
  transforms,
28
- merge( attributes, attributesToMerge ) {
29
- const { values } = attributesToMerge;
30
-
31
- if ( ! values || values === '<li></li>' ) {
32
- return attributes;
33
- }
34
-
35
- return {
36
- ...attributes,
37
- values: attributes.values + values,
38
- };
39
- },
40
47
  edit,
41
48
  save,
42
49
  deprecated,
43
50
  };
44
51
 
45
- let settings = settingsV1;
46
- if ( process.env.IS_GUTENBERG_PLUGIN ) {
47
- settings = window?.__experimentalEnableListBlockV2
48
- ? settingsV2
49
- : settingsV1;
50
- }
51
52
  export { settings };
package/src/list/save.js CHANGED
@@ -1,15 +1,14 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { RichText, useBlockProps } from '@wordpress/block-editor';
4
+ import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
5
5
 
6
6
  export default function save( { attributes } ) {
7
- const { ordered, values, type, reversed, start } = attributes;
7
+ const { ordered, type, reversed, start } = attributes;
8
8
  const TagName = ordered ? 'ol' : 'ul';
9
-
10
9
  return (
11
10
  <TagName { ...useBlockProps.save( { type, reversed, start } ) }>
12
- <RichText.Content value={ values } multiline="li" />
11
+ <InnerBlocks.Content />
13
12
  </TagName>
14
13
  );
15
14
  }
File without changes
@@ -122,12 +122,24 @@ exports[`List V2 block shows different indentation levels 1`] = `
122
122
 
123
123
  exports[`List block inserts block 1`] = `
124
124
  "<!-- wp:list -->
125
- <ul><li></li></ul>
125
+ <ul><!-- wp:list-item -->
126
+ <li></li>
127
+ <!-- /wp:list-item --></ul>
126
128
  <!-- /wp:list -->"
127
129
  `;
128
130
 
129
131
  exports[`List block renders a list with a few items 1`] = `
130
132
  "<!-- wp:list -->
131
- <ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>
133
+ <ul><!-- wp:list-item -->
134
+ <li>Item 1</li>
135
+ <!-- /wp:list-item -->
136
+
137
+ <!-- wp:list-item -->
138
+ <li>Item 2</li>
139
+ <!-- /wp:list-item -->
140
+
141
+ <!-- wp:list-item -->
142
+ <li>Item 3</li>
143
+ <!-- /wp:list-item --></ul>
132
144
  <!-- /wp:list -->"
133
145
  `;