@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.
- package/build/columns/transforms.js +10 -1
- package/build/columns/transforms.js.map +1 -1
- package/build/cover/edit/block-controls.js +9 -2
- package/build/cover/edit/block-controls.js.map +1 -1
- package/build/gallery/gap-styles.js +5 -4
- package/build/gallery/gap-styles.js.map +1 -1
- package/build/home-link/index.js +14 -1
- package/build/home-link/index.js.map +1 -1
- package/build/image/edit.js +3 -1
- package/build/image/edit.js.map +1 -1
- package/build/image/use-client-width.js +3 -1
- package/build/image/use-client-width.js.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/index.native.js +3 -15
- package/build/index.native.js.map +1 -1
- package/build/latest-posts/deprecated.js +14 -1
- package/build/latest-posts/deprecated.js.map +1 -1
- package/build/latest-posts/index.js +14 -1
- package/build/latest-posts/index.js.map +1 -1
- package/build/list/deprecated.js +84 -1
- package/build/list/deprecated.js.map +1 -1
- package/build/list/edit.js +153 -134
- package/build/list/edit.js.map +1 -1
- package/build/list/index.js +29 -34
- package/build/list/index.js.map +1 -1
- package/build/list/save.js +1 -5
- package/build/list/save.js.map +1 -1
- package/build/list/{v2/tag-name.js → tag-name.js} +0 -0
- package/build/list/tag-name.js.map +1 -0
- package/build/list/{v2/tag-name.native.js → tag-name.native.js} +0 -0
- package/build/list/tag-name.native.js.map +1 -0
- package/build/list/transforms.js +61 -95
- package/build/list/transforms.js.map +1 -1
- package/build/list/{v2/migrate.js → utils.js} +3 -2
- package/build/list/utils.js.map +1 -0
- package/build/list-item/edit.native.js +21 -3
- package/build/list-item/edit.native.js.map +1 -1
- package/build/list-item/hooks/use-copy.js +2 -0
- package/build/list-item/hooks/use-copy.js.map +1 -1
- package/build/list-item/hooks/use-merge.js +0 -1
- package/build/list-item/hooks/use-merge.js.map +1 -1
- package/build/list-item/hooks/use-outdent-list-item.js +0 -1
- package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
- package/build/list-item/hooks/use-space.js +10 -1
- package/build/list-item/hooks/use-space.js.map +1 -1
- package/build/list-item/index.js +0 -1
- package/build/list-item/index.js.map +1 -1
- package/build/list-item/utils.js +0 -1
- package/build/list-item/utils.js.map +1 -1
- package/build/navigation/edit/index.js +6 -3
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/responsive-wrapper.js +6 -4
- package/build/navigation/edit/responsive-wrapper.js.map +1 -1
- package/build/navigation/edit/unsaved-inner-blocks.js +4 -15
- package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build/post-excerpt/index.js +4 -2
- package/build/post-excerpt/index.js.map +1 -1
- package/build/post-terms/edit.js +0 -1
- package/build/post-terms/edit.js.map +1 -1
- package/build/post-terms/use-post-terms.js +4 -24
- package/build/post-terms/use-post-terms.js.map +1 -1
- package/build/query-no-results/index.js +13 -0
- package/build/query-no-results/index.js.map +1 -1
- package/build/query-pagination-numbers/index.js +4 -2
- package/build/query-pagination-numbers/index.js.map +1 -1
- package/build/query-title/index.js +1 -0
- package/build/query-title/index.js.map +1 -1
- package/build/quote/index.js +4 -2
- package/build/quote/index.js.map +1 -1
- package/build/term-description/index.js +6 -0
- package/build/term-description/index.js.map +1 -1
- package/build/verse/index.js +1 -0
- package/build/verse/index.js.map +1 -1
- package/build-module/columns/transforms.js +10 -1
- package/build-module/columns/transforms.js.map +1 -1
- package/build-module/cover/edit/block-controls.js +10 -3
- package/build-module/cover/edit/block-controls.js.map +1 -1
- package/build-module/gallery/gap-styles.js +6 -5
- package/build-module/gallery/gap-styles.js.map +1 -1
- package/build-module/home-link/index.js +14 -1
- package/build-module/home-link/index.js.map +1 -1
- package/build-module/image/edit.js +4 -2
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/use-client-width.js +3 -1
- package/build-module/image/use-client-width.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +3 -15
- package/build-module/index.native.js.map +1 -1
- package/build-module/latest-posts/deprecated.js +14 -1
- package/build-module/latest-posts/deprecated.js.map +1 -1
- package/build-module/latest-posts/index.js +14 -1
- package/build-module/latest-posts/index.js.map +1 -1
- package/build-module/list/deprecated.js +83 -1
- package/build-module/list/deprecated.js.map +1 -1
- package/build-module/list/edit.js +151 -134
- package/build-module/list/edit.js.map +1 -1
- package/build-module/list/index.js +29 -29
- package/build-module/list/index.js.map +1 -1
- package/build-module/list/save.js +2 -6
- package/build-module/list/save.js.map +1 -1
- package/build-module/list/{v2/tag-name.js → tag-name.js} +0 -0
- package/build-module/list/tag-name.js.map +1 -0
- package/build-module/list/{v2/tag-name.native.js → tag-name.native.js} +0 -0
- package/build-module/list/tag-name.native.js.map +1 -0
- package/build-module/list/transforms.js +62 -97
- package/build-module/list/transforms.js.map +1 -1
- package/build-module/list/{v2/migrate.js → utils.js} +3 -2
- package/build-module/list/utils.js.map +1 -0
- package/build-module/list-item/edit.native.js +19 -3
- package/build-module/list-item/edit.native.js.map +1 -1
- package/build-module/list-item/hooks/use-copy.js +2 -0
- package/build-module/list-item/hooks/use-copy.js.map +1 -1
- package/build-module/list-item/hooks/use-merge.js +0 -1
- package/build-module/list-item/hooks/use-merge.js.map +1 -1
- package/build-module/list-item/hooks/use-outdent-list-item.js +0 -1
- package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
- package/build-module/list-item/hooks/use-space.js +10 -1
- package/build-module/list-item/hooks/use-space.js.map +1 -1
- package/build-module/list-item/index.js +0 -1
- package/build-module/list-item/index.js.map +1 -1
- package/build-module/list-item/utils.js +0 -1
- package/build-module/list-item/utils.js.map +1 -1
- package/build-module/navigation/edit/index.js +5 -3
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/responsive-wrapper.js +6 -4
- package/build-module/navigation/edit/responsive-wrapper.js.map +1 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js +5 -15
- package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build-module/post-excerpt/index.js +4 -2
- package/build-module/post-excerpt/index.js.map +1 -1
- package/build-module/post-terms/edit.js +0 -1
- package/build-module/post-terms/edit.js.map +1 -1
- package/build-module/post-terms/use-post-terms.js +5 -25
- package/build-module/post-terms/use-post-terms.js.map +1 -1
- package/build-module/query-no-results/index.js +13 -0
- package/build-module/query-no-results/index.js.map +1 -1
- package/build-module/query-pagination-numbers/index.js +4 -2
- package/build-module/query-pagination-numbers/index.js.map +1 -1
- package/build-module/query-title/index.js +1 -0
- package/build-module/query-title/index.js.map +1 -1
- package/build-module/quote/index.js +4 -2
- package/build-module/quote/index.js.map +1 -1
- package/build-module/term-description/index.js +6 -0
- package/build-module/term-description/index.js.map +1 -1
- package/build-module/verse/index.js +1 -0
- package/build-module/verse/index.js.map +1 -1
- package/build-style/button/style-rtl.css +1 -4
- package/build-style/button/style.css +1 -4
- package/build-style/code/editor-rtl.css +79 -0
- package/build-style/code/editor.css +79 -0
- package/build-style/cover/editor-rtl.css +0 -3
- package/build-style/cover/editor.css +0 -3
- package/build-style/editor-rtl.css +9 -44
- package/build-style/editor.css +9 -44
- package/build-style/group/editor-rtl.css +2 -22
- package/build-style/group/editor.css +2 -22
- package/build-style/navigation/editor-rtl.css +3 -19
- package/build-style/navigation/editor.css +3 -19
- package/build-style/navigation/style-rtl.css +8 -1
- package/build-style/navigation/style.css +8 -1
- package/build-style/style-rtl.css +9 -5
- package/build-style/style.css +9 -5
- package/package.json +28 -28
- package/src/button/style.scss +1 -8
- package/src/code/editor.scss +3 -0
- package/src/columns/transforms.js +17 -3
- package/src/cover/edit/block-controls.js +15 -3
- package/src/cover/editor.scss +0 -4
- package/src/editor.scss +1 -0
- package/src/gallery/gap-styles.js +10 -6
- package/src/gallery/index.php +23 -2
- package/src/group/editor.scss +1 -28
- package/src/home-link/block.json +14 -1
- package/src/image/edit.js +3 -3
- package/src/image/use-client-width.js +1 -1
- package/src/index.js +1 -4
- package/src/index.native.js +2 -13
- package/src/latest-posts/block.json +14 -1
- package/src/list/deprecated.js +71 -1
- package/src/list/edit.js +146 -133
- package/src/list/index.js +25 -24
- package/src/list/save.js +3 -4
- package/src/list/{v2/tag-name.js → tag-name.js} +0 -0
- package/src/list/{v2/tag-name.native.js → tag-name.native.js} +0 -0
- package/src/list/test/__snapshots__/edit.native.js.snap +14 -2
- package/src/list/test/edit.native.js +0 -154
- package/src/list/transforms.js +57 -111
- package/src/list/{v2/migrate.js → utils.js} +2 -2
- package/src/list-item/block.json +0 -1
- package/src/list-item/edit.native.js +32 -2
- package/src/list-item/hooks/use-copy.js +2 -0
- package/src/list-item/hooks/use-space.js +10 -2
- package/src/list-item/style.native.scss +8 -0
- package/src/navigation/edit/index.js +14 -4
- package/src/navigation/edit/responsive-wrapper.js +8 -3
- package/src/navigation/edit/unsaved-inner-blocks.js +14 -24
- package/src/navigation/editor.scss +2 -23
- package/src/navigation/index.php +13 -8
- package/src/navigation/style.scss +11 -2
- package/src/post-excerpt/block.json +4 -2
- package/src/post-terms/edit.js +0 -1
- package/src/post-terms/use-post-terms.js +10 -15
- package/src/query-no-results/block.json +13 -0
- package/src/query-pagination-numbers/block.json +4 -2
- package/src/query-title/block.json +1 -0
- package/src/quote/block.json +4 -2
- package/src/term-description/block.json +6 -0
- package/src/verse/block.json +1 -0
- package/build/list/v2/deprecated.js +0 -117
- package/build/list/v2/deprecated.js.map +0 -1
- package/build/list/v2/edit.js +0 -200
- package/build/list/v2/edit.js.map +0 -1
- package/build/list/v2/index.js +0 -36
- package/build/list/v2/index.js.map +0 -1
- package/build/list/v2/migrate.js.map +0 -1
- package/build/list/v2/save.js +0 -34
- package/build/list/v2/save.js.map +0 -1
- package/build/list/v2/tag-name.js.map +0 -1
- package/build/list/v2/tag-name.native.js.map +0 -1
- package/build/list/v2/transforms.js +0 -137
- package/build/list/v2/transforms.js.map +0 -1
- package/build-module/list/v2/deprecated.js +0 -104
- package/build-module/list/v2/deprecated.js.map +0 -1
- package/build-module/list/v2/edit.js +0 -179
- package/build-module/list/v2/edit.js.map +0 -1
- package/build-module/list/v2/index.js +0 -21
- package/build-module/list/v2/index.js.map +0 -1
- package/build-module/list/v2/migrate.js.map +0 -1
- package/build-module/list/v2/save.js +0 -23
- package/build-module/list/v2/save.js.map +0 -1
- package/build-module/list/v2/tag-name.js.map +0 -1
- package/build-module/list/v2/tag-name.native.js.map +0 -1
- package/build-module/list/v2/transforms.js +0 -127
- package/build-module/list/v2/transforms.js.map +0 -1
- package/src/list/test/migrate.js +0 -158
- package/src/list/v2/deprecated.js +0 -89
- package/src/list/v2/edit.js +0 -192
- package/src/list/v2/index.js +0 -22
- package/src/list/v2/save.js +0 -18
- 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
|
|
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 )
|
package/src/index.native.js
CHANGED
|
@@ -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 = (
|
|
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
|
-
|
|
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"
|
package/src/list/deprecated.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
90
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
<
|
|
143
|
-
|
|
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
|
-
{ ...
|
|
165
|
-
|
|
166
|
-
|
|
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
|
|
18
|
+
export { metadata, name };
|
|
19
19
|
|
|
20
|
-
const
|
|
20
|
+
const settings = {
|
|
21
21
|
icon,
|
|
22
22
|
example: {
|
|
23
|
-
|
|
24
|
-
|
|
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 {
|
|
4
|
+
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
|
|
5
5
|
|
|
6
6
|
export default function save( { attributes } ) {
|
|
7
|
-
const { ordered,
|
|
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
|
-
<
|
|
11
|
+
<InnerBlocks.Content />
|
|
13
12
|
</TagName>
|
|
14
13
|
);
|
|
15
14
|
}
|
|
File without changes
|
|
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
|
|
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
|
|
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
|
`;
|