@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
@@ -1,89 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { RichText, useBlockProps } from '@wordpress/block-editor';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import initialDeprecations from '../deprecated';
10
- import { migrateToListV2 } from './migrate';
11
-
12
- const v1 = {
13
- attributes: {
14
- ordered: {
15
- type: 'boolean',
16
- default: false,
17
- __experimentalRole: 'content',
18
- },
19
- values: {
20
- type: 'string',
21
- source: 'html',
22
- selector: 'ol,ul',
23
- multiline: 'li',
24
- __unstableMultilineWrapperTags: [ 'ol', 'ul' ],
25
- default: '',
26
- __experimentalRole: 'content',
27
- },
28
- type: {
29
- type: 'string',
30
- },
31
- start: {
32
- type: 'number',
33
- },
34
- reversed: {
35
- type: 'boolean',
36
- },
37
- placeholder: {
38
- type: 'string',
39
- },
40
- },
41
- supports: {
42
- anchor: true,
43
- className: false,
44
- typography: {
45
- fontSize: true,
46
- __experimentalFontFamily: true,
47
- lineHeight: true,
48
- __experimentalFontStyle: true,
49
- __experimentalFontWeight: true,
50
- __experimentalLetterSpacing: true,
51
- __experimentalTextTransform: true,
52
- __experimentalDefaultControls: {
53
- fontSize: true,
54
- },
55
- },
56
- color: {
57
- gradients: true,
58
- link: true,
59
- __experimentalDefaultControls: {
60
- background: true,
61
- text: true,
62
- },
63
- },
64
- __unstablePasteTextInline: true,
65
- __experimentalSelector: 'ol,ul',
66
- __experimentalSlashInserter: true,
67
- },
68
- save( { attributes } ) {
69
- const { ordered, values, type, reversed, start } = attributes;
70
- const TagName = ordered ? 'ol' : 'ul';
71
-
72
- return (
73
- <TagName { ...useBlockProps.save( { type, reversed, start } ) }>
74
- <RichText.Content value={ values } multiline="li" />
75
- </TagName>
76
- );
77
- },
78
- migrate: migrateToListV2,
79
- };
80
-
81
- /**
82
- * New deprecations need to be placed first
83
- * for them to have higher priority.
84
- *
85
- * Old deprecations may need to be updated as well.
86
- *
87
- * See block-deprecation.md
88
- */
89
- export default [ v1, ...initialDeprecations ];
@@ -1,192 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { last } from 'lodash';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import {
10
- BlockControls,
11
- useBlockProps,
12
- useInnerBlocksProps,
13
- store as blockEditorStore,
14
- } from '@wordpress/block-editor';
15
- import { ToolbarButton } from '@wordpress/components';
16
- import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
17
- import { isRTL, __ } from '@wordpress/i18n';
18
- import {
19
- formatListBullets,
20
- formatListBulletsRTL,
21
- formatListNumbered,
22
- formatListNumberedRTL,
23
- formatOutdent,
24
- formatOutdentRTL,
25
- } from '@wordpress/icons';
26
- import { createBlock } from '@wordpress/blocks';
27
- import { useCallback, useEffect, Platform } from '@wordpress/element';
28
- import deprecated from '@wordpress/deprecated';
29
-
30
- /**
31
- * Internal dependencies
32
- */
33
- import OrderedListSettings from '../ordered-list-settings';
34
- import { migrateToListV2 } from './migrate';
35
- import TagName from './tag-name';
36
-
37
- const TEMPLATE = [ [ 'core/list-item' ] ];
38
- const NATIVE_MARGIN_SPACING = 8;
39
-
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 );
52
-
53
- useEffect( () => {
54
- // As soon as the block is loaded, migrate it to the new version.
55
-
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
- />
127
- </>
128
- );
129
- }
130
-
131
- function Edit( { attributes, setAttributes, clientId, style } ) {
132
- const blockProps = useBlockProps( {
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
- } ),
143
- } );
144
- useMigrateOnLoad( attributes, clientId );
145
- const { ordered, reversed, start } = attributes;
146
-
147
- const controls = (
148
- <BlockControls group="block">
149
- <ToolbarButton
150
- icon={ isRTL() ? formatListBulletsRTL : formatListBullets }
151
- title={ __( 'Unordered' ) }
152
- describedBy={ __( 'Convert to unordered list' ) }
153
- isActive={ ordered === false }
154
- onClick={ () => {
155
- setAttributes( { ordered: false } );
156
- } }
157
- />
158
- <ToolbarButton
159
- icon={ isRTL() ? formatListNumberedRTL : formatListNumbered }
160
- title={ __( 'Ordered' ) }
161
- describedBy={ __( 'Convert to ordered list' ) }
162
- isActive={ ordered === true }
163
- onClick={ () => {
164
- setAttributes( { ordered: true } );
165
- } }
166
- />
167
- <IndentUI clientId={ clientId } />
168
- </BlockControls>
169
- );
170
-
171
- return (
172
- <>
173
- <TagName
174
- ordered={ ordered }
175
- reversed={ reversed }
176
- start={ start }
177
- { ...innerBlocksProps }
178
- />
179
- { controls }
180
- { ordered && (
181
- <OrderedListSettings
182
- setAttributes={ setAttributes }
183
- ordered={ ordered }
184
- reversed={ reversed }
185
- start={ start }
186
- />
187
- ) }
188
- </>
189
- );
190
- }
191
-
192
- export default Edit;
@@ -1,22 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { list as icon } from '@wordpress/icons';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import edit from './edit';
10
- import save from './save';
11
- import transforms from './transforms';
12
- import deprecated from './deprecated';
13
-
14
- const settings = {
15
- icon,
16
- edit,
17
- save,
18
- transforms,
19
- deprecated,
20
- };
21
-
22
- export default settings;
@@ -1,18 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
5
-
6
- export default function save( { attributes } ) {
7
- const { ordered, reversed, start } = attributes;
8
- const TagName = ordered ? 'ol' : 'ul';
9
- return (
10
- <TagName
11
- reversed={ reversed }
12
- start={ start }
13
- { ...useBlockProps.save() }
14
- >
15
- <InnerBlocks.Content />
16
- </TagName>
17
- );
18
- }
@@ -1,120 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { createBlock } from '@wordpress/blocks';
5
- import { create, split, toHTMLString } from '@wordpress/rich-text';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import { createListBlockFromDOMElement } from './migrate';
11
-
12
- function getListContentSchema( { phrasingContentSchema } ) {
13
- const listContentSchema = {
14
- ...phrasingContentSchema,
15
- ul: {},
16
- ol: { attributes: [ 'type', 'start', 'reversed' ] },
17
- };
18
-
19
- // Recursion is needed.
20
- // Possible: ul > li > ul.
21
- // Impossible: ul > ul.
22
- [ 'ul', 'ol' ].forEach( ( tag ) => {
23
- listContentSchema[ tag ].children = {
24
- li: {
25
- children: listContentSchema,
26
- },
27
- };
28
- } );
29
-
30
- return listContentSchema;
31
- }
32
-
33
- function getListContentFlat( blocks ) {
34
- return blocks.flatMap( ( { name, attributes, innerBlocks = [] } ) => {
35
- if ( name === 'core/list-item' ) {
36
- return [ attributes.content, ...getListContentFlat( innerBlocks ) ];
37
- }
38
- return getListContentFlat( innerBlocks );
39
- } );
40
- }
41
-
42
- const transforms = {
43
- from: [
44
- {
45
- type: 'block',
46
- isMultiBlock: true,
47
- blocks: [ 'core/paragraph', 'core/heading' ],
48
- transform: ( blockAttributes ) => {
49
- let childBlocks = [];
50
- if ( blockAttributes.length > 1 ) {
51
- childBlocks = blockAttributes.map( ( { content } ) => {
52
- return createBlock( 'core/list-item', { content } );
53
- } );
54
- } else if ( blockAttributes.length === 1 ) {
55
- const value = create( {
56
- html: blockAttributes[ 0 ].content,
57
- } );
58
- childBlocks = split( value, '\n' ).map( ( result ) => {
59
- return createBlock( 'core/list-item', {
60
- content: toHTMLString( { value: result } ),
61
- } );
62
- } );
63
- }
64
- return createBlock(
65
- 'core/list',
66
- {
67
- anchor: blockAttributes.anchor,
68
- },
69
- childBlocks
70
- );
71
- },
72
- },
73
- ...[ '*', '-' ].map( ( prefix ) => ( {
74
- type: 'prefix',
75
- prefix,
76
- transform( content ) {
77
- return createBlock( 'core/list', {}, [
78
- createBlock( 'core/list-item', { content } ),
79
- ] );
80
- },
81
- } ) ),
82
- ...[ '1.', '1)' ].map( ( prefix ) => ( {
83
- type: 'prefix',
84
- prefix,
85
- transform( content ) {
86
- return createBlock(
87
- 'core/list',
88
- {
89
- ordered: true,
90
- },
91
- [ createBlock( 'core/list-item', { content } ) ]
92
- );
93
- },
94
- } ) ),
95
- {
96
- type: 'raw',
97
- selector: 'ol,ul',
98
- schema: ( args ) => ( {
99
- ol: getListContentSchema( args ).ol,
100
- ul: getListContentSchema( args ).ul,
101
- } ),
102
- transform: createListBlockFromDOMElement,
103
- },
104
- ],
105
- to: [
106
- ...[ 'core/paragraph', 'core/heading' ].map( ( block ) => ( {
107
- type: 'block',
108
- blocks: [ block ],
109
- transform: ( _attributes, childBlocks ) => {
110
- return getListContentFlat( childBlocks ).map( ( content ) =>
111
- createBlock( block, {
112
- content,
113
- } )
114
- );
115
- },
116
- } ) ),
117
- ],
118
- };
119
-
120
- export default transforms;