@wordpress/editor 12.13.0 → 12.15.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 +4 -0
- package/build/components/editor-history/redo.js +2 -1
- package/build/components/editor-history/redo.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/register-shortcuts.js +11 -1
- package/build/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
- package/build/components/post-taxonomies/flat-term-selector.js +7 -1
- package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build/components/post-title/index.js +15 -1
- package/build/components/post-title/index.js.map +1 -1
- package/build/components/post-url/label.js +1 -1
- package/build/components/post-url/label.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +1 -1
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/hooks/custom-sources-backwards-compatibility.js +8 -5
- package/build/hooks/custom-sources-backwards-compatibility.js.map +1 -1
- package/build/store/actions.js +1 -7
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +17 -9
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +36 -16
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/editor-history/redo.js +3 -2
- package/build-module/components/editor-history/redo.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js +10 -1
- package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
- package/build-module/components/post-taxonomies/flat-term-selector.js +8 -2
- package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build-module/components/post-title/index.js +16 -2
- package/build-module/components/post-title/index.js.map +1 -1
- package/build-module/components/post-url/label.js +2 -2
- package/build-module/components/post-url/label.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +1 -1
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/hooks/custom-sources-backwards-compatibility.js +9 -6
- package/build-module/hooks/custom-sources-backwards-compatibility.js.map +1 -1
- package/build-module/store/actions.js +1 -6
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +17 -8
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +36 -15
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +28 -28
- package/src/components/editor-history/redo.js +6 -2
- package/src/components/global-keyboard-shortcuts/register-shortcuts.js +13 -0
- package/src/components/post-author/test/check.js +7 -7
- package/src/components/post-last-revision/test/check.js +7 -7
- package/src/components/post-pending-status/test/check.js +5 -5
- package/src/components/post-schedule/test/check.js +5 -5
- package/src/components/post-slug/test/check.js +3 -3
- package/src/components/post-sticky/test/index.js +11 -7
- package/src/components/post-taxonomies/flat-term-selector.js +10 -2
- package/src/components/post-title/index.js +16 -2
- package/src/components/post-url/label.js +2 -2
- package/src/components/post-visibility/test/check.js +16 -8
- package/src/components/provider/use-block-editor-settings.js +2 -0
- package/src/components/theme-support-check/test/index.js +13 -15
- package/src/hooks/custom-sources-backwards-compatibility.js +14 -12
- package/src/store/actions.js +1 -6
- package/src/store/reducer.js +16 -10
- package/src/store/selectors.js +29 -28
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { __, isRTL } from '@wordpress/i18n';
|
|
5
5
|
import { Button } from '@wordpress/components';
|
|
6
6
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
7
|
-
import { displayShortcut } from '@wordpress/keycodes';
|
|
7
|
+
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
|
|
8
8
|
import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons';
|
|
9
9
|
import { forwardRef } from '@wordpress/element';
|
|
10
10
|
|
|
@@ -14,6 +14,10 @@ import { forwardRef } from '@wordpress/element';
|
|
|
14
14
|
import { store as editorStore } from '../../store';
|
|
15
15
|
|
|
16
16
|
function EditorHistoryRedo( props, ref ) {
|
|
17
|
+
const shortcut = isAppleOS()
|
|
18
|
+
? displayShortcut.primaryShift( 'z' )
|
|
19
|
+
: displayShortcut.primary( 'y' );
|
|
20
|
+
|
|
17
21
|
const hasRedo = useSelect(
|
|
18
22
|
( select ) => select( editorStore ).hasEditorRedo(),
|
|
19
23
|
[]
|
|
@@ -26,7 +30,7 @@ function EditorHistoryRedo( props, ref ) {
|
|
|
26
30
|
icon={ ! isRTL() ? redoIcon : undoIcon }
|
|
27
31
|
/* translators: button label text should, if possible, be under 16 characters. */
|
|
28
32
|
label={ __( 'Redo' ) }
|
|
29
|
-
shortcut={
|
|
33
|
+
shortcut={ shortcut }
|
|
30
34
|
// If there are no redo levels we don't want to actually disable this
|
|
31
35
|
// button, because it will remove focus for keyboard users.
|
|
32
36
|
// See: https://github.com/WordPress/gutenberg/issues/3486
|
|
@@ -6,6 +6,7 @@ import { useDispatch } from '@wordpress/data';
|
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
import { BlockEditorKeyboardShortcuts } from '@wordpress/block-editor';
|
|
8
8
|
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
9
|
+
import { isAppleOS } from '@wordpress/keycodes';
|
|
9
10
|
|
|
10
11
|
function EditorKeyboardShortcutsRegister() {
|
|
11
12
|
// Registering the shortcuts.
|
|
@@ -39,6 +40,18 @@ function EditorKeyboardShortcutsRegister() {
|
|
|
39
40
|
modifier: 'primaryShift',
|
|
40
41
|
character: 'z',
|
|
41
42
|
},
|
|
43
|
+
// Disable on Apple OS because it conflicts with the browser's
|
|
44
|
+
// history shortcut. It's a fine alias for both Windows and Linux.
|
|
45
|
+
// Since there's no conflict for Ctrl+Shift+Z on both Windows and
|
|
46
|
+
// Linux, we keep it as the default for consistency.
|
|
47
|
+
aliases: isAppleOS()
|
|
48
|
+
? []
|
|
49
|
+
: [
|
|
50
|
+
{
|
|
51
|
+
modifier: 'primary',
|
|
52
|
+
character: 'y',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
42
55
|
} );
|
|
43
56
|
}, [ registerShortcut ] );
|
|
44
57
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -26,8 +26,8 @@ describe( 'PostAuthorCheck', () => {
|
|
|
26
26
|
hasAssignAuthorAction: true,
|
|
27
27
|
} ) );
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
expect(
|
|
29
|
+
render( <PostAuthorCheck>authors</PostAuthorCheck> );
|
|
30
|
+
expect( screen.queryByText( 'authors' ) ).not.toBeInTheDocument();
|
|
31
31
|
} );
|
|
32
32
|
|
|
33
33
|
it( "should not render anything if doesn't have author action", () => {
|
|
@@ -36,8 +36,8 @@ describe( 'PostAuthorCheck', () => {
|
|
|
36
36
|
hasAssignAuthorAction: false,
|
|
37
37
|
} ) );
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
expect(
|
|
39
|
+
render( <PostAuthorCheck>authors</PostAuthorCheck> );
|
|
40
|
+
expect( screen.queryByText( 'authors' ) ).not.toBeInTheDocument();
|
|
41
41
|
} );
|
|
42
42
|
|
|
43
43
|
it( 'should render control', () => {
|
|
@@ -46,7 +46,7 @@ describe( 'PostAuthorCheck', () => {
|
|
|
46
46
|
hasAssignAuthorAction: true,
|
|
47
47
|
} ) );
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
expect(
|
|
49
|
+
render( <PostAuthorCheck>authors</PostAuthorCheck> );
|
|
50
|
+
expect( screen.getByText( 'authors' ) ).toBeVisible();
|
|
51
51
|
} );
|
|
52
52
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -10,32 +10,32 @@ import { PostLastRevisionCheck } from '../check';
|
|
|
10
10
|
|
|
11
11
|
describe( 'PostLastRevisionCheck', () => {
|
|
12
12
|
it( 'should not render anything if the last revision ID is unknown', () => {
|
|
13
|
-
|
|
13
|
+
render(
|
|
14
14
|
<PostLastRevisionCheck revisionsCount={ 2 }>
|
|
15
15
|
Children
|
|
16
16
|
</PostLastRevisionCheck>
|
|
17
17
|
);
|
|
18
18
|
|
|
19
|
-
expect(
|
|
19
|
+
expect( screen.queryByText( 'Children' ) ).not.toBeInTheDocument();
|
|
20
20
|
} );
|
|
21
21
|
|
|
22
22
|
it( 'should not render anything if there is only one revision', () => {
|
|
23
|
-
|
|
23
|
+
render(
|
|
24
24
|
<PostLastRevisionCheck lastRevisionId={ 1 } revisionsCount={ 1 }>
|
|
25
25
|
Children
|
|
26
26
|
</PostLastRevisionCheck>
|
|
27
27
|
);
|
|
28
28
|
|
|
29
|
-
expect(
|
|
29
|
+
expect( screen.queryByText( 'Children' ) ).not.toBeInTheDocument();
|
|
30
30
|
} );
|
|
31
31
|
|
|
32
32
|
it( 'should render if there are two revisions', () => {
|
|
33
|
-
|
|
33
|
+
render(
|
|
34
34
|
<PostLastRevisionCheck lastRevisionId={ 1 } revisionsCount={ 2 }>
|
|
35
35
|
Children
|
|
36
36
|
</PostLastRevisionCheck>
|
|
37
37
|
);
|
|
38
38
|
|
|
39
|
-
expect(
|
|
39
|
+
expect( screen.getByText( 'Children' ) ).toBeVisible();
|
|
40
40
|
} );
|
|
41
41
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -10,20 +10,20 @@ import { PostPendingStatusCheck } from '../check';
|
|
|
10
10
|
|
|
11
11
|
describe( 'PostPendingStatusCheck', () => {
|
|
12
12
|
it( "should not render anything if the user doesn't have the right capabilities", () => {
|
|
13
|
-
|
|
13
|
+
render(
|
|
14
14
|
<PostPendingStatusCheck hasPublishAction={ false }>
|
|
15
15
|
status
|
|
16
16
|
</PostPendingStatusCheck>
|
|
17
17
|
);
|
|
18
|
-
expect(
|
|
18
|
+
expect( screen.queryByText( 'status' ) ).not.toBeInTheDocument();
|
|
19
19
|
} );
|
|
20
20
|
|
|
21
21
|
it( 'should render if the user has the correct capability', () => {
|
|
22
|
-
|
|
22
|
+
render(
|
|
23
23
|
<PostPendingStatusCheck hasPublishAction={ true }>
|
|
24
24
|
status
|
|
25
25
|
</PostPendingStatusCheck>
|
|
26
26
|
);
|
|
27
|
-
expect(
|
|
27
|
+
expect( screen.getByText( 'status' ) ).toBeVisible();
|
|
28
28
|
} );
|
|
29
29
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -10,18 +10,18 @@ import { PostScheduleCheck } from '../check';
|
|
|
10
10
|
|
|
11
11
|
describe( 'PostScheduleCheck', () => {
|
|
12
12
|
it( "should not render anything if the user doesn't have the right capabilities", () => {
|
|
13
|
-
|
|
13
|
+
render(
|
|
14
14
|
<PostScheduleCheck hasPublishAction={ false }>
|
|
15
15
|
yes
|
|
16
16
|
</PostScheduleCheck>
|
|
17
17
|
);
|
|
18
|
-
expect(
|
|
18
|
+
expect( screen.queryByText( 'yes' ) ).not.toBeInTheDocument();
|
|
19
19
|
} );
|
|
20
20
|
|
|
21
21
|
it( 'should render if the user has the correct capability', () => {
|
|
22
|
-
|
|
22
|
+
render(
|
|
23
23
|
<PostScheduleCheck hasPublishAction={ true }>yes</PostScheduleCheck>
|
|
24
24
|
);
|
|
25
|
-
expect(
|
|
25
|
+
expect( screen.getByText( 'yes' ) ).toBeVisible();
|
|
26
26
|
} );
|
|
27
27
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -10,8 +10,8 @@ import PostSlugCheck from '../check';
|
|
|
10
10
|
|
|
11
11
|
describe( 'PostSlugCheck', () => {
|
|
12
12
|
it( 'should render control', () => {
|
|
13
|
-
|
|
13
|
+
render( <PostSlugCheck>slug</PostSlugCheck> );
|
|
14
14
|
|
|
15
|
-
expect(
|
|
15
|
+
expect( screen.getByText( 'slug' ) ).toBeVisible();
|
|
16
16
|
} );
|
|
17
17
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -10,29 +10,33 @@ import { PostStickyCheck } from '../check';
|
|
|
10
10
|
|
|
11
11
|
describe( 'PostSticky', () => {
|
|
12
12
|
it( 'should not render anything if the post type is not "post"', () => {
|
|
13
|
-
|
|
13
|
+
render(
|
|
14
14
|
<PostStickyCheck postType="page" hasStickyAction={ true }>
|
|
15
15
|
Can Toggle Sticky
|
|
16
16
|
</PostStickyCheck>
|
|
17
17
|
);
|
|
18
|
-
expect(
|
|
18
|
+
expect(
|
|
19
|
+
screen.queryByText( 'Can Toggle Sticky' )
|
|
20
|
+
).not.toBeInTheDocument();
|
|
19
21
|
} );
|
|
20
22
|
|
|
21
23
|
it( "should not render anything if post doesn't support stickying", () => {
|
|
22
|
-
|
|
24
|
+
render(
|
|
23
25
|
<PostStickyCheck postType="post" hasStickyAction={ false }>
|
|
24
26
|
Can Toggle Sticky
|
|
25
27
|
</PostStickyCheck>
|
|
26
28
|
);
|
|
27
|
-
expect(
|
|
29
|
+
expect(
|
|
30
|
+
screen.queryByText( 'Can Toggle Sticky' )
|
|
31
|
+
).not.toBeInTheDocument();
|
|
28
32
|
} );
|
|
29
33
|
|
|
30
34
|
it( 'should render if the post supports stickying', () => {
|
|
31
|
-
|
|
35
|
+
render(
|
|
32
36
|
<PostStickyCheck postType="post" hasStickyAction={ true }>
|
|
33
37
|
Can Toggle Sticky
|
|
34
38
|
</PostStickyCheck>
|
|
35
39
|
);
|
|
36
|
-
expect(
|
|
40
|
+
expect( screen.getByText( 'Can Toggle Sticky' ) ).toBeVisible();
|
|
37
41
|
} );
|
|
38
42
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { escape as escapeString, find, get
|
|
4
|
+
import { escape as escapeString, find, get } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -202,7 +202,15 @@ export function FlatTermSelector( { slug } ) {
|
|
|
202
202
|
...( terms ?? [] ),
|
|
203
203
|
...( searchResults ?? [] ),
|
|
204
204
|
];
|
|
205
|
-
const uniqueTerms =
|
|
205
|
+
const uniqueTerms = termNames.reduce( ( acc, name ) => {
|
|
206
|
+
if (
|
|
207
|
+
! acc.some( ( n ) => n.toLowerCase() === name.toLowerCase() )
|
|
208
|
+
) {
|
|
209
|
+
acc.push( name );
|
|
210
|
+
}
|
|
211
|
+
return acc;
|
|
212
|
+
}, [] );
|
|
213
|
+
|
|
206
214
|
const newTermNames = uniqueTerms.filter(
|
|
207
215
|
( termName ) =>
|
|
208
216
|
! find( availableTerms, ( term ) =>
|
|
@@ -19,7 +19,12 @@ import { ENTER } from '@wordpress/keycodes';
|
|
|
19
19
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
20
20
|
import { pasteHandler } from '@wordpress/blocks';
|
|
21
21
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
__unstableUseRichText as useRichText,
|
|
24
|
+
create,
|
|
25
|
+
toHTMLString,
|
|
26
|
+
insert,
|
|
27
|
+
} from '@wordpress/rich-text';
|
|
23
28
|
import { useMergeRefs } from '@wordpress/compose';
|
|
24
29
|
|
|
25
30
|
/**
|
|
@@ -169,7 +174,16 @@ function PostTitle( _, forwardedRef ) {
|
|
|
169
174
|
onInsertBlockAfter( content );
|
|
170
175
|
}
|
|
171
176
|
} else {
|
|
172
|
-
|
|
177
|
+
const value = {
|
|
178
|
+
...create( { html: title } ),
|
|
179
|
+
...selection,
|
|
180
|
+
};
|
|
181
|
+
const newValue = insert( value, create( { html: content } ) );
|
|
182
|
+
onUpdate( toHTMLString( { value: newValue } ) );
|
|
183
|
+
setSelection( {
|
|
184
|
+
start: newValue.start,
|
|
185
|
+
end: newValue.end,
|
|
186
|
+
} );
|
|
173
187
|
}
|
|
174
188
|
}
|
|
175
189
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import { filterURLForDisplay } from '@wordpress/url';
|
|
5
|
+
import { filterURLForDisplay, safeDecodeURIComponent } from '@wordpress/url';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
@@ -18,5 +18,5 @@ export function usePostURLLabel() {
|
|
|
18
18
|
( select ) => select( editorStore ).getCurrentPost().link,
|
|
19
19
|
[]
|
|
20
20
|
);
|
|
21
|
-
return filterURLForDisplay( postLink );
|
|
21
|
+
return filterURLForDisplay( safeDecodeURIComponent( postLink ) );
|
|
22
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -9,19 +9,27 @@ import { shallow } from 'enzyme';
|
|
|
9
9
|
import { PostVisibilityCheck } from '../check';
|
|
10
10
|
|
|
11
11
|
describe( 'PostVisibilityCheck', () => {
|
|
12
|
-
const
|
|
12
|
+
const renderProp = ( { canEdit } ) => ( canEdit ? 'yes' : 'no' );
|
|
13
13
|
|
|
14
14
|
it( "should not render the edit link if the user doesn't have the right capability", () => {
|
|
15
|
-
|
|
16
|
-
<PostVisibilityCheck
|
|
15
|
+
render(
|
|
16
|
+
<PostVisibilityCheck
|
|
17
|
+
hasPublishAction={ false }
|
|
18
|
+
render={ renderProp }
|
|
19
|
+
/>
|
|
17
20
|
);
|
|
18
|
-
expect(
|
|
21
|
+
expect( screen.queryByText( 'yes' ) ).not.toBeInTheDocument();
|
|
22
|
+
expect( screen.getByText( 'no' ) ).toBeVisible();
|
|
19
23
|
} );
|
|
20
24
|
|
|
21
25
|
it( 'should render if the user has the correct capability', () => {
|
|
22
|
-
|
|
23
|
-
<PostVisibilityCheck
|
|
26
|
+
render(
|
|
27
|
+
<PostVisibilityCheck
|
|
28
|
+
hasPublishAction={ true }
|
|
29
|
+
render={ renderProp }
|
|
30
|
+
/>
|
|
24
31
|
);
|
|
25
|
-
expect(
|
|
32
|
+
expect( screen.queryByText( 'no' ) ).not.toBeInTheDocument();
|
|
33
|
+
expect( screen.getByText( 'yes' ) ).toBeVisible();
|
|
26
34
|
} );
|
|
27
35
|
} );
|
|
@@ -128,7 +128,9 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
128
128
|
'colors',
|
|
129
129
|
'disableCustomColors',
|
|
130
130
|
'disableCustomFontSizes',
|
|
131
|
+
'disableCustomSpacingSizes',
|
|
131
132
|
'disableCustomGradients',
|
|
133
|
+
'disableLayoutStyles',
|
|
132
134
|
'enableCustomLineHeight',
|
|
133
135
|
'enableCustomSpacing',
|
|
134
136
|
'enableCustomUnits',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -10,10 +10,8 @@ import { ThemeSupportCheck } from '../index';
|
|
|
10
10
|
|
|
11
11
|
describe( 'ThemeSupportCheck', () => {
|
|
12
12
|
it( "should not render if there's no support check provided", () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
);
|
|
16
|
-
expect( wrapper.type() ).toBe( null );
|
|
13
|
+
render( <ThemeSupportCheck>foobar</ThemeSupportCheck> );
|
|
14
|
+
expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
|
|
17
15
|
} );
|
|
18
16
|
|
|
19
17
|
it( 'should render if post-thumbnails are supported', () => {
|
|
@@ -21,7 +19,7 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
21
19
|
'post-thumbnails': true,
|
|
22
20
|
};
|
|
23
21
|
const supportKeys = 'post-thumbnails';
|
|
24
|
-
|
|
22
|
+
render(
|
|
25
23
|
<ThemeSupportCheck
|
|
26
24
|
supportKeys={ supportKeys }
|
|
27
25
|
themeSupports={ themeSupports }
|
|
@@ -29,7 +27,7 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
29
27
|
foobar
|
|
30
28
|
</ThemeSupportCheck>
|
|
31
29
|
);
|
|
32
|
-
expect(
|
|
30
|
+
expect( screen.getByText( 'foobar' ) ).toBeVisible();
|
|
33
31
|
} );
|
|
34
32
|
|
|
35
33
|
it( 'should render if post-thumbnails are supported for the post type', () => {
|
|
@@ -37,7 +35,7 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
37
35
|
'post-thumbnails': [ 'post' ],
|
|
38
36
|
};
|
|
39
37
|
const supportKeys = 'post-thumbnails';
|
|
40
|
-
|
|
38
|
+
render(
|
|
41
39
|
<ThemeSupportCheck
|
|
42
40
|
supportKeys={ supportKeys }
|
|
43
41
|
postType={ 'post' }
|
|
@@ -46,7 +44,7 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
46
44
|
foobar
|
|
47
45
|
</ThemeSupportCheck>
|
|
48
46
|
);
|
|
49
|
-
expect(
|
|
47
|
+
expect( screen.getByText( 'foobar' ) ).toBeVisible();
|
|
50
48
|
} );
|
|
51
49
|
|
|
52
50
|
it( "should not render if post-thumbnails aren't supported for the post type", () => {
|
|
@@ -54,7 +52,7 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
54
52
|
'post-thumbnails': [ 'post' ],
|
|
55
53
|
};
|
|
56
54
|
const supportKeys = 'post-thumbnails';
|
|
57
|
-
|
|
55
|
+
render(
|
|
58
56
|
<ThemeSupportCheck
|
|
59
57
|
supportKeys={ supportKeys }
|
|
60
58
|
postType={ 'page' }
|
|
@@ -63,7 +61,7 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
63
61
|
foobar
|
|
64
62
|
</ThemeSupportCheck>
|
|
65
63
|
);
|
|
66
|
-
expect(
|
|
64
|
+
expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
|
|
67
65
|
} );
|
|
68
66
|
|
|
69
67
|
it( 'should not render if post-thumbnails is limited and false is passed for postType', () => {
|
|
@@ -71,7 +69,7 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
71
69
|
'post-thumbnails': [ 'post' ],
|
|
72
70
|
};
|
|
73
71
|
const supportKeys = 'post-thumbnails';
|
|
74
|
-
|
|
72
|
+
render(
|
|
75
73
|
<ThemeSupportCheck
|
|
76
74
|
supportKeys={ supportKeys }
|
|
77
75
|
postType={ false }
|
|
@@ -80,7 +78,7 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
80
78
|
foobar
|
|
81
79
|
</ThemeSupportCheck>
|
|
82
80
|
);
|
|
83
|
-
expect(
|
|
81
|
+
expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
|
|
84
82
|
} );
|
|
85
83
|
|
|
86
84
|
it( "should not render if theme doesn't support post-thumbnails", () => {
|
|
@@ -88,7 +86,7 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
88
86
|
'post-thumbnails': false,
|
|
89
87
|
};
|
|
90
88
|
const supportKeys = 'post-thumbnails';
|
|
91
|
-
|
|
89
|
+
render(
|
|
92
90
|
<ThemeSupportCheck
|
|
93
91
|
supportKeys={ supportKeys }
|
|
94
92
|
themeSupports={ themeSupports }
|
|
@@ -96,6 +94,6 @@ describe( 'ThemeSupportCheck', () => {
|
|
|
96
94
|
foobar
|
|
97
95
|
</ThemeSupportCheck>
|
|
98
96
|
);
|
|
99
|
-
expect(
|
|
97
|
+
expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
|
|
100
98
|
} );
|
|
101
99
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { pickBy, mapValues, isEmpty
|
|
4
|
+
import { pickBy, mapValues, isEmpty } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -69,17 +69,19 @@ const createWithMetaAttributeSource = ( metaAttributes ) =>
|
|
|
69
69
|
<BlockEdit
|
|
70
70
|
attributes={ mergedAttributes }
|
|
71
71
|
setAttributes={ ( nextAttributes ) => {
|
|
72
|
-
const nextMeta =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
metaAttributes[ attributeKey ]
|
|
72
|
+
const nextMeta = Object.fromEntries(
|
|
73
|
+
Object.entries(
|
|
74
|
+
// Filter to intersection of keys between the updated
|
|
75
|
+
// attributes and those with an associated meta key.
|
|
76
|
+
pickBy(
|
|
77
|
+
nextAttributes,
|
|
78
|
+
( value, key ) => metaAttributes[ key ]
|
|
79
|
+
)
|
|
80
|
+
).map( ( [ attributeKey, value ] ) => [
|
|
81
|
+
// Rename the keys to the expected meta key name.
|
|
82
|
+
metaAttributes[ attributeKey ],
|
|
83
|
+
value,
|
|
84
|
+
] )
|
|
83
85
|
);
|
|
84
86
|
|
|
85
87
|
if ( ! isEmpty( nextMeta ) ) {
|
package/src/store/actions.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { has } from 'lodash';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
@@ -48,7 +43,7 @@ export const setupEditor =
|
|
|
48
43
|
// included as part of editor setup action. Assume edited content as
|
|
49
44
|
// canonical if provided, falling back to post.
|
|
50
45
|
let content;
|
|
51
|
-
if (
|
|
46
|
+
if ( 'content' in edits ) {
|
|
52
47
|
content = edits.content;
|
|
53
48
|
} else {
|
|
54
49
|
content = post.content.raw;
|
package/src/store/reducer.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { omit, isEqual } from 'lodash';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
@@ -39,7 +34,12 @@ export function getPostRawValue( value ) {
|
|
|
39
34
|
* @return {boolean} Whether the two objects have the same keys.
|
|
40
35
|
*/
|
|
41
36
|
export function hasSameKeys( a, b ) {
|
|
42
|
-
|
|
37
|
+
const keysA = Object.keys( a ).sort();
|
|
38
|
+
const keysB = Object.keys( b ).sort();
|
|
39
|
+
return (
|
|
40
|
+
keysA.length === keysB.length &&
|
|
41
|
+
keysA.every( ( key, index ) => keysB[ index ] === key )
|
|
42
|
+
);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -184,8 +184,11 @@ export function postSavingLock( state = {}, action ) {
|
|
|
184
184
|
case 'LOCK_POST_SAVING':
|
|
185
185
|
return { ...state, [ action.lockName ]: true };
|
|
186
186
|
|
|
187
|
-
case 'UNLOCK_POST_SAVING':
|
|
188
|
-
|
|
187
|
+
case 'UNLOCK_POST_SAVING': {
|
|
188
|
+
const { [ action.lockName ]: removedLockName, ...restState } =
|
|
189
|
+
state;
|
|
190
|
+
return restState;
|
|
191
|
+
}
|
|
189
192
|
}
|
|
190
193
|
return state;
|
|
191
194
|
}
|
|
@@ -205,8 +208,11 @@ export function postAutosavingLock( state = {}, action ) {
|
|
|
205
208
|
case 'LOCK_POST_AUTOSAVING':
|
|
206
209
|
return { ...state, [ action.lockName ]: true };
|
|
207
210
|
|
|
208
|
-
case 'UNLOCK_POST_AUTOSAVING':
|
|
209
|
-
|
|
211
|
+
case 'UNLOCK_POST_AUTOSAVING': {
|
|
212
|
+
const { [ action.lockName ]: removedLockName, ...restState } =
|
|
213
|
+
state;
|
|
214
|
+
return restState;
|
|
215
|
+
}
|
|
210
216
|
}
|
|
211
217
|
return state;
|
|
212
218
|
}
|