@wordpress/editor 13.14.0 → 13.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 +2 -0
- package/build/components/entities-saved-states/entity-record-item.js +3 -37
- package/build/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build/components/entities-saved-states/entity-type-list.js +2 -4
- package/build/components/entities-saved-states/entity-type-list.js.map +1 -1
- package/build/components/entities-saved-states/index.js +0 -1
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/{save-shortcut.js → index.js} +13 -25
- package/build/components/global-keyboard-shortcuts/index.js.map +1 -0
- package/build/components/index.js +32 -19
- package/build/components/index.js.map +1 -1
- package/build/components/post-preview-button/index.js +62 -157
- package/build/components/post-preview-button/index.js.map +1 -1
- package/build/components/post-publish-button/index.js +4 -9
- package/build/components/post-publish-button/index.js.map +1 -1
- package/build/components/post-publish-button/label.js +2 -4
- package/build/components/post-publish-button/label.js.map +1 -1
- package/build/components/post-publish-panel/index.js +1 -3
- package/build/components/post-publish-panel/index.js.map +1 -1
- package/build/components/post-saved-state/index.js +2 -5
- package/build/components/post-saved-state/index.js.map +1 -1
- package/build/components/post-schedule/label.js +4 -4
- package/build/components/post-schedule/label.js.map +1 -1
- package/build/components/post-sync-status/index.js +84 -5
- package/build/components/post-sync-status/index.js.map +1 -1
- package/build/components/post-text-editor/index.js +51 -58
- package/build/components/post-text-editor/index.js.map +1 -1
- package/build/store/actions.js +37 -3
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +53 -61
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/entities-saved-states/entity-record-item.js +6 -40
- package/build-module/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build-module/components/entities-saved-states/entity-type-list.js +2 -4
- package/build-module/components/entities-saved-states/entity-type-list.js.map +1 -1
- package/build-module/components/entities-saved-states/index.js +0 -1
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/{save-shortcut.js → index.js} +12 -23
- package/build-module/components/global-keyboard-shortcuts/index.js.map +1 -0
- package/build-module/components/index.js +9 -4
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/post-preview-button/index.js +63 -149
- package/build-module/components/post-preview-button/index.js.map +1 -1
- package/build-module/components/post-publish-button/index.js +4 -9
- package/build-module/components/post-publish-button/index.js.map +1 -1
- package/build-module/components/post-publish-button/label.js +2 -4
- package/build-module/components/post-publish-button/label.js.map +1 -1
- package/build-module/components/post-publish-panel/index.js +1 -3
- package/build-module/components/post-publish-panel/index.js.map +1 -1
- package/build-module/components/post-saved-state/index.js +2 -5
- package/build-module/components/post-saved-state/index.js.map +1 -1
- package/build-module/components/post-schedule/label.js +4 -4
- package/build-module/components/post-schedule/label.js.map +1 -1
- package/build-module/components/post-sync-status/index.js +84 -8
- package/build-module/components/post-sync-status/index.js.map +1 -1
- package/build-module/components/post-text-editor/index.js +48 -56
- package/build-module/components/post-text-editor/index.js.map +1 -1
- package/build-module/store/actions.js +31 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +46 -55
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +0 -18
- package/build-style/style.css +0 -18
- package/package.json +30 -30
- package/src/components/entities-saved-states/entity-record-item.js +3 -61
- package/src/components/entities-saved-states/entity-type-list.js +0 -2
- package/src/components/entities-saved-states/index.js +0 -1
- package/src/components/entities-saved-states/style.scss +0 -15
- package/src/components/global-keyboard-shortcuts/index.js +49 -0
- package/src/components/index.js +12 -3
- package/src/components/post-preview-button/index.js +73 -156
- package/src/components/post-preview-button/test/index.js +94 -158
- package/src/components/post-publish-button/index.js +2 -7
- package/src/components/post-publish-button/label.js +2 -2
- package/src/components/post-publish-button/test/index.js +0 -10
- package/src/components/post-publish-panel/index.js +1 -3
- package/src/components/post-saved-state/index.js +2 -5
- package/src/components/post-schedule/label.js +4 -4
- package/src/components/post-sync-status/index.js +100 -7
- package/src/components/post-text-editor/index.js +34 -57
- package/src/components/post-title/style.native.scss +5 -5
- package/src/store/actions.js +34 -2
- package/src/store/selectors.js +45 -41
- package/src/store/test/selectors.js +36 -25
- package/build/components/global-keyboard-shortcuts/save-shortcut.js.map +0 -1
- package/build/components/global-keyboard-shortcuts/text-editor-shortcuts.js +0 -22
- package/build/components/global-keyboard-shortcuts/text-editor-shortcuts.js.map +0 -1
- package/build/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -45
- package/build/components/global-keyboard-shortcuts/visual-editor-shortcuts.js.map +0 -1
- package/build-module/components/global-keyboard-shortcuts/save-shortcut.js.map +0 -1
- package/build-module/components/global-keyboard-shortcuts/text-editor-shortcuts.js +0 -12
- package/build-module/components/global-keyboard-shortcuts/text-editor-shortcuts.js.map +0 -1
- package/build-module/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -32
- package/build-module/components/global-keyboard-shortcuts/visual-editor-shortcuts.js.map +0 -1
- package/src/components/global-keyboard-shortcuts/save-shortcut.js +0 -55
- package/src/components/global-keyboard-shortcuts/text-editor-shortcuts.js +0 -8
- package/src/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -29
- package/src/components/post-text-editor/test/index.js +0 -156
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* WordPress dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { useShortcut } from '@wordpress/keyboard-shortcuts';
|
|
7
|
-
import { useDispatch } from '@wordpress/data';
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import SaveShortcut from './save-shortcut';
|
|
13
|
-
import { store as editorStore } from '../../store';
|
|
14
|
-
|
|
15
|
-
function VisualEditorGlobalKeyboardShortcuts() {
|
|
16
|
-
const {
|
|
17
|
-
redo,
|
|
18
|
-
undo
|
|
19
|
-
} = useDispatch(editorStore);
|
|
20
|
-
useShortcut('core/editor/undo', event => {
|
|
21
|
-
undo();
|
|
22
|
-
event.preventDefault();
|
|
23
|
-
});
|
|
24
|
-
useShortcut('core/editor/redo', event => {
|
|
25
|
-
redo();
|
|
26
|
-
event.preventDefault();
|
|
27
|
-
});
|
|
28
|
-
return createElement(SaveShortcut, null);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default VisualEditorGlobalKeyboardShortcuts;
|
|
32
|
-
//# sourceMappingURL=visual-editor-shortcuts.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/global-keyboard-shortcuts/visual-editor-shortcuts.js"],"names":["useShortcut","useDispatch","SaveShortcut","store","editorStore","VisualEditorGlobalKeyboardShortcuts","redo","undo","event","preventDefault"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,+BAA5B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,aAArC;;AAEA,SAASC,mCAAT,GAA+C;AAC9C,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBN,WAAW,CAAEG,WAAF,CAAlC;AAEAJ,EAAAA,WAAW,CAAE,kBAAF,EAAwBQ,KAAF,IAAa;AAC7CD,IAAAA,IAAI;AACJC,IAAAA,KAAK,CAACC,cAAN;AACA,GAHU,CAAX;AAKAT,EAAAA,WAAW,CAAE,kBAAF,EAAwBQ,KAAF,IAAa;AAC7CF,IAAAA,IAAI;AACJE,IAAAA,KAAK,CAACC,cAAN;AACA,GAHU,CAAX;AAKA,SAAO,cAAC,YAAD,OAAP;AACA;;AAED,eAAeJ,mCAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport SaveShortcut from './save-shortcut';\nimport { store as editorStore } from '../../store';\n\nfunction VisualEditorGlobalKeyboardShortcuts() {\n\tconst { redo, undo } = useDispatch( editorStore );\n\n\tuseShortcut( 'core/editor/undo', ( event ) => {\n\t\tundo();\n\t\tevent.preventDefault();\n\t} );\n\n\tuseShortcut( 'core/editor/redo', ( event ) => {\n\t\tredo();\n\t\tevent.preventDefault();\n\t} );\n\n\treturn <SaveShortcut />;\n}\n\nexport default VisualEditorGlobalKeyboardShortcuts;\n"]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useShortcut } from '@wordpress/keyboard-shortcuts';
|
|
5
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
|
-
import { parse } from '@wordpress/blocks';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
import { store as editorStore } from '../../store';
|
|
12
|
-
|
|
13
|
-
function SaveShortcut( { resetBlocksOnSave } ) {
|
|
14
|
-
const { resetEditorBlocks, savePost } = useDispatch( editorStore );
|
|
15
|
-
const { isEditedPostDirty, getPostEdits, isPostSavingLocked } =
|
|
16
|
-
useSelect( editorStore );
|
|
17
|
-
|
|
18
|
-
useShortcut( 'core/editor/save', ( event ) => {
|
|
19
|
-
event.preventDefault();
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Do not save the post if post saving is locked.
|
|
23
|
-
*/
|
|
24
|
-
if ( isPostSavingLocked() ) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// TODO: This should be handled in the `savePost` effect in
|
|
29
|
-
// considering `isSaveable`. See note on `isEditedPostSaveable`
|
|
30
|
-
// selector about dirtiness and meta-boxes.
|
|
31
|
-
//
|
|
32
|
-
// See: `isEditedPostSaveable`
|
|
33
|
-
if ( ! isEditedPostDirty() ) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// The text editor requires that editor blocks are updated for a
|
|
38
|
-
// save to work correctly. Usually this happens when the textarea
|
|
39
|
-
// for the code editors blurs, but the shortcut can be used without
|
|
40
|
-
// blurring the textarea.
|
|
41
|
-
if ( resetBlocksOnSave ) {
|
|
42
|
-
const postEdits = getPostEdits();
|
|
43
|
-
if ( postEdits.content && typeof postEdits.content === 'string' ) {
|
|
44
|
-
const blocks = parse( postEdits.content );
|
|
45
|
-
resetEditorBlocks( blocks );
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
savePost();
|
|
50
|
-
} );
|
|
51
|
-
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default SaveShortcut;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useShortcut } from '@wordpress/keyboard-shortcuts';
|
|
5
|
-
import { useDispatch } from '@wordpress/data';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import SaveShortcut from './save-shortcut';
|
|
11
|
-
import { store as editorStore } from '../../store';
|
|
12
|
-
|
|
13
|
-
function VisualEditorGlobalKeyboardShortcuts() {
|
|
14
|
-
const { redo, undo } = useDispatch( editorStore );
|
|
15
|
-
|
|
16
|
-
useShortcut( 'core/editor/undo', ( event ) => {
|
|
17
|
-
undo();
|
|
18
|
-
event.preventDefault();
|
|
19
|
-
} );
|
|
20
|
-
|
|
21
|
-
useShortcut( 'core/editor/redo', ( event ) => {
|
|
22
|
-
redo();
|
|
23
|
-
event.preventDefault();
|
|
24
|
-
} );
|
|
25
|
-
|
|
26
|
-
return <SaveShortcut />;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default VisualEditorGlobalKeyboardShortcuts;
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { act, render, screen } from '@testing-library/react';
|
|
5
|
-
import userEvent from '@testing-library/user-event';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* WordPress dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { useSelect } from '@wordpress/data';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal dependencies
|
|
14
|
-
*/
|
|
15
|
-
import PostTextEditor from '../';
|
|
16
|
-
|
|
17
|
-
// "Downgrade" ReactAutosizeTextarea to a regular textarea. Assumes aligned
|
|
18
|
-
// props interface.
|
|
19
|
-
jest.mock( 'react-autosize-textarea', () => ( props ) => (
|
|
20
|
-
<textarea { ...props } />
|
|
21
|
-
) );
|
|
22
|
-
|
|
23
|
-
jest.mock( '@wordpress/data/src/components/use-select', () => {
|
|
24
|
-
// This allows us to tweak the returned value on each test.
|
|
25
|
-
const mock = jest.fn();
|
|
26
|
-
return mock;
|
|
27
|
-
} );
|
|
28
|
-
|
|
29
|
-
let mockEditPost = jest.fn();
|
|
30
|
-
let mockResetEditorBlocks = jest.fn();
|
|
31
|
-
|
|
32
|
-
jest.mock( '@wordpress/data/src/components/use-dispatch', () => {
|
|
33
|
-
return {
|
|
34
|
-
useDispatch: () => ( {
|
|
35
|
-
editPost: mockEditPost,
|
|
36
|
-
resetEditorBlocks: mockResetEditorBlocks,
|
|
37
|
-
} ),
|
|
38
|
-
};
|
|
39
|
-
} );
|
|
40
|
-
|
|
41
|
-
describe( 'PostTextEditor', () => {
|
|
42
|
-
beforeEach( () => {
|
|
43
|
-
useSelect.mockImplementation( () => 'Hello World' );
|
|
44
|
-
|
|
45
|
-
mockEditPost = jest.fn();
|
|
46
|
-
mockResetEditorBlocks = jest.fn();
|
|
47
|
-
} );
|
|
48
|
-
|
|
49
|
-
it( 'should render via the value from useSelect', () => {
|
|
50
|
-
render( <PostTextEditor /> );
|
|
51
|
-
|
|
52
|
-
expect( screen.getByLabelText( 'Type text or HTML' ) ).toHaveValue(
|
|
53
|
-
'Hello World'
|
|
54
|
-
);
|
|
55
|
-
} );
|
|
56
|
-
|
|
57
|
-
it( 'should render via the state value when edits made', async () => {
|
|
58
|
-
const user = userEvent.setup();
|
|
59
|
-
render( <PostTextEditor /> );
|
|
60
|
-
|
|
61
|
-
const textarea = screen.getByLabelText( 'Type text or HTML' );
|
|
62
|
-
|
|
63
|
-
await user.clear( textarea );
|
|
64
|
-
await user.type( textarea, 'Hello Chicken' );
|
|
65
|
-
|
|
66
|
-
expect( textarea ).toHaveValue( 'Hello Chicken' );
|
|
67
|
-
expect( mockEditPost ).toHaveBeenCalledWith( {
|
|
68
|
-
content: 'Hello Chicken',
|
|
69
|
-
} );
|
|
70
|
-
} );
|
|
71
|
-
|
|
72
|
-
it( 'should render via the state value when edits made, even if prop value changes', async () => {
|
|
73
|
-
const user = userEvent.setup();
|
|
74
|
-
const { rerender } = render( <PostTextEditor /> );
|
|
75
|
-
|
|
76
|
-
const textarea = screen.getByLabelText( 'Type text or HTML' );
|
|
77
|
-
|
|
78
|
-
await user.clear( textarea );
|
|
79
|
-
await user.type( textarea, 'Hello Chicken' );
|
|
80
|
-
|
|
81
|
-
useSelect.mockImplementation( () => 'Goodbye World' );
|
|
82
|
-
|
|
83
|
-
rerender( <PostTextEditor /> );
|
|
84
|
-
|
|
85
|
-
expect( textarea ).toHaveValue( 'Hello Chicken' );
|
|
86
|
-
expect( mockEditPost ).toHaveBeenCalledWith( {
|
|
87
|
-
content: 'Hello Chicken',
|
|
88
|
-
} );
|
|
89
|
-
} );
|
|
90
|
-
|
|
91
|
-
it( 'should render via the state value when edits made, even if prop value changes and state value empty', async () => {
|
|
92
|
-
const user = userEvent.setup();
|
|
93
|
-
const { rerender } = render( <PostTextEditor /> );
|
|
94
|
-
|
|
95
|
-
const textarea = screen.getByLabelText( 'Type text or HTML' );
|
|
96
|
-
|
|
97
|
-
await user.clear( textarea );
|
|
98
|
-
|
|
99
|
-
useSelect.mockImplementation( () => 'Goodbye World' );
|
|
100
|
-
|
|
101
|
-
rerender( <PostTextEditor /> );
|
|
102
|
-
|
|
103
|
-
expect( textarea ).toHaveValue( '' );
|
|
104
|
-
expect( mockEditPost ).toHaveBeenCalledWith( {
|
|
105
|
-
content: '',
|
|
106
|
-
} );
|
|
107
|
-
} );
|
|
108
|
-
|
|
109
|
-
it( 'calls onPersist after changes made and user stops editing', async () => {
|
|
110
|
-
const user = userEvent.setup();
|
|
111
|
-
render( <PostTextEditor /> );
|
|
112
|
-
|
|
113
|
-
const textarea = screen.getByLabelText( 'Type text or HTML' );
|
|
114
|
-
|
|
115
|
-
await user.clear( textarea );
|
|
116
|
-
|
|
117
|
-
// Stop editing.
|
|
118
|
-
act( () => {
|
|
119
|
-
textarea.blur();
|
|
120
|
-
} );
|
|
121
|
-
|
|
122
|
-
expect( mockResetEditorBlocks ).toHaveBeenCalledWith( [] );
|
|
123
|
-
} );
|
|
124
|
-
|
|
125
|
-
it( 'does not call onPersist after user stops editing without changes', () => {
|
|
126
|
-
render( <PostTextEditor /> );
|
|
127
|
-
|
|
128
|
-
// Stop editing.
|
|
129
|
-
screen.getByLabelText( 'Type text or HTML' ).blur();
|
|
130
|
-
|
|
131
|
-
expect( mockResetEditorBlocks ).not.toHaveBeenCalled();
|
|
132
|
-
} );
|
|
133
|
-
|
|
134
|
-
it( 'resets to prop value after user stops editing', async () => {
|
|
135
|
-
// This isn't the most realistic case, since typically we'd assume the
|
|
136
|
-
// parent renderer to pass the value as it had received onPersist. The
|
|
137
|
-
// test here is more an edge case to stress that it's intentionally
|
|
138
|
-
// differentiating between state and prop values.
|
|
139
|
-
const user = userEvent.setup();
|
|
140
|
-
const { rerender } = render( <PostTextEditor /> );
|
|
141
|
-
|
|
142
|
-
const textarea = screen.getByLabelText( 'Type text or HTML' );
|
|
143
|
-
|
|
144
|
-
await user.clear( textarea );
|
|
145
|
-
|
|
146
|
-
useSelect.mockImplementation( () => 'Goodbye World' );
|
|
147
|
-
|
|
148
|
-
rerender( <PostTextEditor /> );
|
|
149
|
-
|
|
150
|
-
act( () => {
|
|
151
|
-
textarea.blur();
|
|
152
|
-
} );
|
|
153
|
-
|
|
154
|
-
expect( textarea ).toHaveValue( 'Goodbye World' );
|
|
155
|
-
} );
|
|
156
|
-
} );
|