@wordpress/editor 13.15.0 → 13.16.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/CHANGELOG.md +2 -0
- package/build/components/post-comments/index.js +12 -15
- package/build/components/post-comments/index.js.map +1 -1
- package/build/components/post-excerpt/index.js +9 -20
- package/build/components/post-excerpt/index.js.map +1 -1
- package/build/components/post-pingbacks/index.js +12 -15
- package/build/components/post-pingbacks/index.js.map +1 -1
- package/build/components/post-type-support-check/index.js +10 -14
- package/build/components/post-type-support-check/index.js.map +1 -1
- package/build/hooks/custom-sources-backwards-compatibility.js +1 -24
- package/build/hooks/custom-sources-backwards-compatibility.js.map +1 -1
- package/build/store/actions.js +1 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +2 -2
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/post-comments/index.js +13 -14
- package/build-module/components/post-comments/index.js.map +1 -1
- package/build-module/components/post-excerpt/index.js +10 -19
- package/build-module/components/post-excerpt/index.js.map +1 -1
- package/build-module/components/post-pingbacks/index.js +13 -14
- package/build-module/components/post-pingbacks/index.js.map +1 -1
- package/build-module/components/post-type-support-check/index.js +11 -14
- package/build-module/components/post-type-support-check/index.js.map +1 -1
- package/build-module/hooks/custom-sources-backwards-compatibility.js +2 -24
- package/build-module/hooks/custom-sources-backwards-compatibility.js.map +1 -1
- package/build-module/store/actions.js +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +2 -2
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +30 -30
- package/src/components/post-author/test/check.js +18 -12
- package/src/components/post-comments/index.js +11 -17
- package/src/components/post-excerpt/index.js +10 -16
- package/src/components/post-pingbacks/index.js +11 -15
- package/src/components/post-type-support-check/index.js +8 -10
- package/src/components/post-type-support-check/test/index.js +35 -19
- package/src/hooks/custom-sources-backwards-compatibility.js +1 -25
- package/src/store/actions.js +1 -1
- package/src/store/selectors.js +2 -2
- package/src/store/test/selectors.js +13 -13
|
@@ -3,17 +3,23 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { CheckboxControl } from '@wordpress/components';
|
|
6
|
-
import {
|
|
7
|
-
import { compose } from '@wordpress/compose';
|
|
6
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Internal dependencies
|
|
11
10
|
*/
|
|
12
11
|
import { store as editorStore } from '../../store';
|
|
13
12
|
|
|
14
|
-
function PostPingbacks(
|
|
13
|
+
function PostPingbacks() {
|
|
14
|
+
const pingStatus = useSelect(
|
|
15
|
+
( select ) =>
|
|
16
|
+
select( editorStore ).getEditedPostAttribute( 'ping_status' ) ??
|
|
17
|
+
'open',
|
|
18
|
+
[]
|
|
19
|
+
);
|
|
20
|
+
const { editPost } = useDispatch( editorStore );
|
|
15
21
|
const onTogglePingback = () =>
|
|
16
|
-
|
|
22
|
+
editPost( {
|
|
17
23
|
ping_status: pingStatus === 'open' ? 'closed' : 'open',
|
|
18
24
|
} );
|
|
19
25
|
|
|
@@ -27,14 +33,4 @@ function PostPingbacks( { pingStatus = 'open', ...props } ) {
|
|
|
27
33
|
);
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
export default
|
|
31
|
-
withSelect( ( select ) => {
|
|
32
|
-
return {
|
|
33
|
-
pingStatus:
|
|
34
|
-
select( editorStore ).getEditedPostAttribute( 'ping_status' ),
|
|
35
|
-
};
|
|
36
|
-
} ),
|
|
37
|
-
withDispatch( ( dispatch ) => ( {
|
|
38
|
-
editPost: dispatch( editorStore ).editPost,
|
|
39
|
-
} ) ),
|
|
40
|
-
] )( PostPingbacks );
|
|
36
|
+
export default PostPingbacks;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
5
5
|
import { store as coreStore } from '@wordpress/core-data';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -14,7 +14,6 @@ import { store as editorStore } from '../../store';
|
|
|
14
14
|
* type supports one of the given `supportKeys` prop.
|
|
15
15
|
*
|
|
16
16
|
* @param {Object} props Props.
|
|
17
|
-
* @param {string} [props.postType] Current post type.
|
|
18
17
|
* @param {WPElement} props.children Children to be rendered if post
|
|
19
18
|
* type supports.
|
|
20
19
|
* @param {(string|string[])} props.supportKeys String or string array of keys
|
|
@@ -22,7 +21,12 @@ import { store as editorStore } from '../../store';
|
|
|
22
21
|
*
|
|
23
22
|
* @return {WPComponent} The component to be rendered.
|
|
24
23
|
*/
|
|
25
|
-
export function PostTypeSupportCheck( {
|
|
24
|
+
export function PostTypeSupportCheck( { children, supportKeys } ) {
|
|
25
|
+
const postType = useSelect( ( select ) => {
|
|
26
|
+
const { getEditedPostAttribute } = select( editorStore );
|
|
27
|
+
const { getPostType } = select( coreStore );
|
|
28
|
+
return getPostType( getEditedPostAttribute( 'type' ) );
|
|
29
|
+
}, [] );
|
|
26
30
|
let isSupported = true;
|
|
27
31
|
if ( postType ) {
|
|
28
32
|
isSupported = (
|
|
@@ -37,10 +41,4 @@ export function PostTypeSupportCheck( { postType, children, supportKeys } ) {
|
|
|
37
41
|
return children;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
export default
|
|
41
|
-
const { getEditedPostAttribute } = select( editorStore );
|
|
42
|
-
const { getPostType } = select( coreStore );
|
|
43
|
-
return {
|
|
44
|
-
postType: getPostType( getEditedPostAttribute( 'type' ) ),
|
|
45
|
-
};
|
|
46
|
-
} )( PostTypeSupportCheck );
|
|
44
|
+
export default PostTypeSupportCheck;
|
|
@@ -3,15 +3,37 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { render } from '@testing-library/react';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useSelect } from '@wordpress/data';
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* Internal dependencies
|
|
8
13
|
*/
|
|
9
14
|
import { PostTypeSupportCheck } from '../';
|
|
10
15
|
|
|
16
|
+
jest.mock( '@wordpress/data/src/components/use-select', () => {
|
|
17
|
+
// This allows us to tweak the returned value on each test.
|
|
18
|
+
const mock = jest.fn();
|
|
19
|
+
return mock;
|
|
20
|
+
} );
|
|
21
|
+
|
|
22
|
+
function setupUseSelectMock( postType ) {
|
|
23
|
+
useSelect.mockImplementation( ( cb ) => {
|
|
24
|
+
return cb( () => ( {
|
|
25
|
+
getPostType: () => postType,
|
|
26
|
+
getEditedPostAttribute: () => 'post',
|
|
27
|
+
} ) );
|
|
28
|
+
} );
|
|
29
|
+
}
|
|
30
|
+
|
|
11
31
|
describe( 'PostTypeSupportCheck', () => {
|
|
12
32
|
it( 'renders its children when post type is not known', () => {
|
|
33
|
+
setupUseSelectMock( undefined );
|
|
34
|
+
|
|
13
35
|
const { container } = render(
|
|
14
|
-
<PostTypeSupportCheck
|
|
36
|
+
<PostTypeSupportCheck supportKeys="title">
|
|
15
37
|
Supported
|
|
16
38
|
</PostTypeSupportCheck>
|
|
17
39
|
);
|
|
@@ -20,11 +42,11 @@ describe( 'PostTypeSupportCheck', () => {
|
|
|
20
42
|
} );
|
|
21
43
|
|
|
22
44
|
it( 'does not render its children when post type is known and not supports', () => {
|
|
23
|
-
|
|
45
|
+
setupUseSelectMock( {
|
|
24
46
|
supports: {},
|
|
25
|
-
};
|
|
47
|
+
} );
|
|
26
48
|
const { container } = render(
|
|
27
|
-
<PostTypeSupportCheck
|
|
49
|
+
<PostTypeSupportCheck supportKeys="title">
|
|
28
50
|
Supported
|
|
29
51
|
</PostTypeSupportCheck>
|
|
30
52
|
);
|
|
@@ -33,13 +55,13 @@ describe( 'PostTypeSupportCheck', () => {
|
|
|
33
55
|
} );
|
|
34
56
|
|
|
35
57
|
it( 'renders its children when post type is known and supports', () => {
|
|
36
|
-
|
|
58
|
+
setupUseSelectMock( {
|
|
37
59
|
supports: {
|
|
38
60
|
title: true,
|
|
39
61
|
},
|
|
40
|
-
};
|
|
62
|
+
} );
|
|
41
63
|
const { container } = render(
|
|
42
|
-
<PostTypeSupportCheck
|
|
64
|
+
<PostTypeSupportCheck supportKeys="title">
|
|
43
65
|
Supported
|
|
44
66
|
</PostTypeSupportCheck>
|
|
45
67
|
);
|
|
@@ -48,16 +70,13 @@ describe( 'PostTypeSupportCheck', () => {
|
|
|
48
70
|
} );
|
|
49
71
|
|
|
50
72
|
it( 'renders its children if some of keys supported', () => {
|
|
51
|
-
|
|
73
|
+
setupUseSelectMock( {
|
|
52
74
|
supports: {
|
|
53
75
|
title: true,
|
|
54
76
|
},
|
|
55
|
-
};
|
|
77
|
+
} );
|
|
56
78
|
const { container } = render(
|
|
57
|
-
<PostTypeSupportCheck
|
|
58
|
-
postType={ postType }
|
|
59
|
-
supportKeys={ [ 'title', 'thumbnail' ] }
|
|
60
|
-
>
|
|
79
|
+
<PostTypeSupportCheck supportKeys={ [ 'title', 'thumbnail' ] }>
|
|
61
80
|
Supported
|
|
62
81
|
</PostTypeSupportCheck>
|
|
63
82
|
);
|
|
@@ -66,14 +85,11 @@ describe( 'PostTypeSupportCheck', () => {
|
|
|
66
85
|
} );
|
|
67
86
|
|
|
68
87
|
it( 'does not render its children if none of keys supported', () => {
|
|
69
|
-
|
|
88
|
+
setupUseSelectMock( {
|
|
70
89
|
supports: {},
|
|
71
|
-
};
|
|
90
|
+
} );
|
|
72
91
|
const { container } = render(
|
|
73
|
-
<PostTypeSupportCheck
|
|
74
|
-
postType={ postType }
|
|
75
|
-
supportKeys={ [ 'title', 'thumbnail' ] }
|
|
76
|
-
>
|
|
92
|
+
<PostTypeSupportCheck supportKeys={ [ 'title', 'thumbnail' ] }>
|
|
77
93
|
Supported
|
|
78
94
|
</PostTypeSupportCheck>
|
|
79
95
|
);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import { select as globalSelect, useSelect } from '@wordpress/data';
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
6
5
|
import { useEntityProp } from '@wordpress/core-data';
|
|
7
6
|
import { useMemo } from '@wordpress/element';
|
|
8
7
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
@@ -124,26 +123,3 @@ addFilter(
|
|
|
124
123
|
'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',
|
|
125
124
|
shimAttributeSource
|
|
126
125
|
);
|
|
127
|
-
|
|
128
|
-
// The above filter will only capture blocks registered after the filter was
|
|
129
|
-
// added. There may already be blocks registered by this point, and those must
|
|
130
|
-
// be updated to apply the shim.
|
|
131
|
-
//
|
|
132
|
-
// The following implementation achieves this, albeit with a couple caveats:
|
|
133
|
-
// - Only blocks registered on the global store will be modified.
|
|
134
|
-
// - The block settings are directly mutated, since there is currently no
|
|
135
|
-
// mechanism to update an existing block registration. This is the reason for
|
|
136
|
-
// `getBlockType` separate from `getBlockTypes`, since the latter returns a
|
|
137
|
-
// _copy_ of the block registration (i.e. the mutation would not affect the
|
|
138
|
-
// actual registered block settings).
|
|
139
|
-
//
|
|
140
|
-
// `getBlockTypes` or `getBlockType` implementation could change in the future
|
|
141
|
-
// in regards to creating settings clones, but the corresponding end-to-end
|
|
142
|
-
// tests for meta blocks should cover against any potential regressions.
|
|
143
|
-
//
|
|
144
|
-
// In the future, we could support updating block settings, at which point this
|
|
145
|
-
// implementation could use that mechanism instead.
|
|
146
|
-
globalSelect( blocksStore )
|
|
147
|
-
.getBlockTypes()
|
|
148
|
-
.map( ( { name } ) => globalSelect( blocksStore ).getBlockType( name ) )
|
|
149
|
-
.forEach( shimAttributeSource );
|
package/src/store/actions.js
CHANGED
|
@@ -302,7 +302,7 @@ export const autosave =
|
|
|
302
302
|
};
|
|
303
303
|
|
|
304
304
|
export const __unstableSaveForPreview =
|
|
305
|
-
( { forceIsAutosaveable } ) =>
|
|
305
|
+
( { forceIsAutosaveable } = {} ) =>
|
|
306
306
|
async ( { select, dispatch } ) => {
|
|
307
307
|
if (
|
|
308
308
|
( forceIsAutosaveable || select.isEditedPostAutosaveable() ) &&
|
package/src/store/selectors.js
CHANGED
|
@@ -611,8 +611,8 @@ export const isEditedPostAutosaveable = createRegistrySelector(
|
|
|
611
611
|
return true;
|
|
612
612
|
}
|
|
613
613
|
|
|
614
|
-
// If
|
|
615
|
-
return [ 'title', 'excerpt' ].some(
|
|
614
|
+
// If title, excerpt, or meta have changed, the post is autosaveable.
|
|
615
|
+
return [ 'title', 'excerpt', 'meta' ].some(
|
|
616
616
|
( field ) =>
|
|
617
617
|
getPostRawValue( autosave[ field ] ) !==
|
|
618
618
|
getEditedPostAttribute( state, field )
|
|
@@ -260,7 +260,7 @@ describe( 'selectors', () => {
|
|
|
260
260
|
parent: [ 'core/test-block-b' ],
|
|
261
261
|
} );
|
|
262
262
|
|
|
263
|
-
registerBlockType( 'core/
|
|
263
|
+
registerBlockType( 'core/freeform', {
|
|
264
264
|
save: ( props ) => <RawHTML>{ props.attributes.content }</RawHTML>,
|
|
265
265
|
category: 'text',
|
|
266
266
|
title: 'Test Freeform Content Handler',
|
|
@@ -287,7 +287,7 @@ describe( 'selectors', () => {
|
|
|
287
287
|
save: () => null,
|
|
288
288
|
} );
|
|
289
289
|
|
|
290
|
-
setFreeformContentHandlerName( 'core/
|
|
290
|
+
setFreeformContentHandlerName( 'core/freeform' );
|
|
291
291
|
setDefaultBlockName( 'core/test-default' );
|
|
292
292
|
|
|
293
293
|
cachedSelectors.forEach( ( { clear } ) => clear() );
|
|
@@ -298,7 +298,7 @@ describe( 'selectors', () => {
|
|
|
298
298
|
unregisterBlockType( 'core/test-block-a' );
|
|
299
299
|
unregisterBlockType( 'core/test-block-b' );
|
|
300
300
|
unregisterBlockType( 'core/test-block-c' );
|
|
301
|
-
unregisterBlockType( 'core/
|
|
301
|
+
unregisterBlockType( 'core/freeform' );
|
|
302
302
|
unregisterBlockType( 'core/test-default' );
|
|
303
303
|
|
|
304
304
|
setFreeformContentHandlerName( undefined );
|
|
@@ -1337,7 +1337,7 @@ describe( 'selectors', () => {
|
|
|
1337
1337
|
value: [
|
|
1338
1338
|
{
|
|
1339
1339
|
clientId: 123,
|
|
1340
|
-
name: 'core/
|
|
1340
|
+
name: 'core/freeform',
|
|
1341
1341
|
isValid: true,
|
|
1342
1342
|
attributes: {
|
|
1343
1343
|
content: '',
|
|
@@ -1364,7 +1364,7 @@ describe( 'selectors', () => {
|
|
|
1364
1364
|
value: [
|
|
1365
1365
|
{
|
|
1366
1366
|
clientId: 123,
|
|
1367
|
-
name: 'core/
|
|
1367
|
+
name: 'core/freeform',
|
|
1368
1368
|
isValid: true,
|
|
1369
1369
|
attributes: {
|
|
1370
1370
|
content: '',
|
|
@@ -1741,7 +1741,7 @@ describe( 'selectors', () => {
|
|
|
1741
1741
|
value: [
|
|
1742
1742
|
{
|
|
1743
1743
|
clientId: 123,
|
|
1744
|
-
name: 'core/
|
|
1744
|
+
name: 'core/freeform',
|
|
1745
1745
|
isValid: true,
|
|
1746
1746
|
attributes: {
|
|
1747
1747
|
content: '',
|
|
@@ -1769,7 +1769,7 @@ describe( 'selectors', () => {
|
|
|
1769
1769
|
value: [
|
|
1770
1770
|
{
|
|
1771
1771
|
clientId: 123,
|
|
1772
|
-
name: 'core/
|
|
1772
|
+
name: 'core/freeform',
|
|
1773
1773
|
isValid: true,
|
|
1774
1774
|
attributes: {
|
|
1775
1775
|
content: '',
|
|
@@ -1797,7 +1797,7 @@ describe( 'selectors', () => {
|
|
|
1797
1797
|
value: [
|
|
1798
1798
|
{
|
|
1799
1799
|
clientId: 123,
|
|
1800
|
-
name: 'core/
|
|
1800
|
+
name: 'core/freeform',
|
|
1801
1801
|
isValid: true,
|
|
1802
1802
|
attributes: {
|
|
1803
1803
|
content: 'Test Data',
|
|
@@ -1825,7 +1825,7 @@ describe( 'selectors', () => {
|
|
|
1825
1825
|
value: [
|
|
1826
1826
|
{
|
|
1827
1827
|
clientId: 123,
|
|
1828
|
-
name: 'core/
|
|
1828
|
+
name: 'core/freeform',
|
|
1829
1829
|
isValid: true,
|
|
1830
1830
|
attributes: {
|
|
1831
1831
|
content: '',
|
|
@@ -1833,7 +1833,7 @@ describe( 'selectors', () => {
|
|
|
1833
1833
|
},
|
|
1834
1834
|
{
|
|
1835
1835
|
clientId: 456,
|
|
1836
|
-
name: 'core/
|
|
1836
|
+
name: 'core/freeform',
|
|
1837
1837
|
isValid: true,
|
|
1838
1838
|
attributes: {
|
|
1839
1839
|
content: '',
|
|
@@ -2426,7 +2426,7 @@ describe( 'selectors', () => {
|
|
|
2426
2426
|
} );
|
|
2427
2427
|
|
|
2428
2428
|
it( "returns removep'd serialization of blocks for single unknown", () => {
|
|
2429
|
-
const unknownBlock = createBlock( 'core/
|
|
2429
|
+
const unknownBlock = createBlock( 'core/freeform', {
|
|
2430
2430
|
content: '<p>foo</p>',
|
|
2431
2431
|
} );
|
|
2432
2432
|
const state = {
|
|
@@ -2448,10 +2448,10 @@ describe( 'selectors', () => {
|
|
|
2448
2448
|
} );
|
|
2449
2449
|
|
|
2450
2450
|
it( "returns non-removep'd serialization of blocks for multiple unknown", () => {
|
|
2451
|
-
const firstUnknown = createBlock( 'core/
|
|
2451
|
+
const firstUnknown = createBlock( 'core/freeform', {
|
|
2452
2452
|
content: '<p>foo</p>',
|
|
2453
2453
|
} );
|
|
2454
|
-
const secondUnknown = createBlock( 'core/
|
|
2454
|
+
const secondUnknown = createBlock( 'core/freeform', {
|
|
2455
2455
|
content: '<p>bar</p>',
|
|
2456
2456
|
} );
|
|
2457
2457
|
const state = {
|