@wordpress/editor 13.13.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 +4 -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/media-categories/index.js +1 -22
- package/build/components/media-categories/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 +3 -4
- 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-switch-to-draft-button/index.js +3 -5
- package/build/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build/components/post-sync-status/index.js +82 -22
- 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/components/provider/use-block-editor-settings.js +1 -1
- package/build/components/provider/use-block-editor-settings.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/media-categories/index.js +1 -22
- package/build-module/components/media-categories/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 +3 -4
- 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-switch-to-draft-button/index.js +5 -7
- package/build-module/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build-module/components/post-sync-status/index.js +81 -24
- 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/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/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 +4 -22
- package/build-style/style.css +4 -22
- 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/media-categories/index.js +1 -21
- 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 +3 -4
- package/src/components/post-saved-state/index.js +2 -5
- package/src/components/post-schedule/label.js +4 -4
- package/src/components/post-switch-to-draft-button/index.js +3 -4
- package/src/components/post-sync-status/index.js +100 -27
- package/src/components/post-sync-status/style.scss +2 -2
- package/src/components/post-text-editor/index.js +34 -57
- package/src/components/post-title/style.native.scss +5 -5
- package/src/components/post-trash/style.scss +2 -2
- package/src/components/provider/use-block-editor-settings.js +1 -0
- 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
|
@@ -4,10 +4,39 @@
|
|
|
4
4
|
import { render, screen, within } from '@testing-library/react';
|
|
5
5
|
import userEvent from '@testing-library/user-event';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* Internal dependencies
|
|
9
14
|
*/
|
|
10
|
-
import
|
|
15
|
+
import PostPreviewButton from '..';
|
|
16
|
+
|
|
17
|
+
jest.useRealTimers();
|
|
18
|
+
|
|
19
|
+
jest.mock( '@wordpress/data/src/components/use-select', () => jest.fn() );
|
|
20
|
+
jest.mock( '@wordpress/data/src/components/use-dispatch/use-dispatch', () =>
|
|
21
|
+
jest.fn()
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
function mockUseSelect( overrides ) {
|
|
25
|
+
useSelect.mockImplementation( ( map ) =>
|
|
26
|
+
map( () => ( {
|
|
27
|
+
getPostType: () => ( { viewable: true } ),
|
|
28
|
+
getCurrentPostId: () => 123,
|
|
29
|
+
getCurrentPostType: () => 'post',
|
|
30
|
+
getCurrentPostAttribute: () => undefined,
|
|
31
|
+
getEditedPostPreviewLink: () => undefined,
|
|
32
|
+
isEditedPostSaveable: () => false,
|
|
33
|
+
...overrides,
|
|
34
|
+
} ) )
|
|
35
|
+
);
|
|
36
|
+
useDispatch.mockImplementation( () => ( {
|
|
37
|
+
__unstableSaveForPreview: () => Promise.resolve(),
|
|
38
|
+
} ) );
|
|
39
|
+
}
|
|
11
40
|
|
|
12
41
|
describe( 'PostPreviewButton', () => {
|
|
13
42
|
const documentWrite = jest.fn();
|
|
@@ -42,33 +71,39 @@ describe( 'PostPreviewButton', () => {
|
|
|
42
71
|
} );
|
|
43
72
|
|
|
44
73
|
it( 'should render with `editor-post-preview` class if no `className` is specified.', () => {
|
|
74
|
+
mockUseSelect();
|
|
75
|
+
|
|
45
76
|
render( <PostPreviewButton /> );
|
|
46
77
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
78
|
+
const button = screen.getByRole( 'button' );
|
|
79
|
+
expect( button ).toHaveClass( 'editor-post-preview' );
|
|
50
80
|
} );
|
|
51
81
|
|
|
52
82
|
it( 'should render with a custom class and not `editor-post-preview` if `className` is specified.', () => {
|
|
83
|
+
mockUseSelect();
|
|
84
|
+
|
|
53
85
|
render( <PostPreviewButton className="foo-bar" /> );
|
|
54
86
|
|
|
55
87
|
const button = screen.getByRole( 'button' );
|
|
56
|
-
|
|
57
88
|
expect( button ).toHaveClass( 'foo-bar' );
|
|
58
89
|
expect( button ).not.toHaveClass( 'editor-post-preview' );
|
|
59
90
|
} );
|
|
60
91
|
|
|
61
92
|
it( 'should render a tertiary button if no classname is specified.', () => {
|
|
93
|
+
mockUseSelect();
|
|
94
|
+
|
|
62
95
|
render( <PostPreviewButton /> );
|
|
63
96
|
|
|
64
|
-
|
|
97
|
+
const button = screen.getByRole( 'button' );
|
|
98
|
+
expect( button ).toHaveClass( 'is-tertiary' );
|
|
65
99
|
} );
|
|
66
100
|
|
|
67
101
|
it( 'should render the button in its default variant if a custom classname is specified.', () => {
|
|
102
|
+
mockUseSelect();
|
|
103
|
+
|
|
68
104
|
render( <PostPreviewButton className="foo-bar" /> );
|
|
69
105
|
|
|
70
106
|
const button = screen.getByRole( 'button' );
|
|
71
|
-
|
|
72
107
|
expect( button ).not.toHaveClass( 'is-primary' );
|
|
73
108
|
expect( button ).not.toHaveClass( 'is-secondary' );
|
|
74
109
|
expect( button ).not.toHaveClass( 'is-tertiary' );
|
|
@@ -76,12 +111,13 @@ describe( 'PostPreviewButton', () => {
|
|
|
76
111
|
} );
|
|
77
112
|
|
|
78
113
|
it( 'should render `textContent` if specified.', () => {
|
|
114
|
+
mockUseSelect();
|
|
115
|
+
|
|
79
116
|
const textContent = 'Foo bar';
|
|
80
117
|
|
|
81
118
|
render( <PostPreviewButton textContent={ textContent } /> );
|
|
82
119
|
|
|
83
120
|
const button = screen.getByRole( 'button' );
|
|
84
|
-
|
|
85
121
|
expect( button ).toHaveTextContent( textContent );
|
|
86
122
|
expect(
|
|
87
123
|
within( button ).queryByText( 'Preview' )
|
|
@@ -92,213 +128,113 @@ describe( 'PostPreviewButton', () => {
|
|
|
92
128
|
} );
|
|
93
129
|
|
|
94
130
|
it( 'should render `Preview` with accessibility text if `textContent` not specified.', () => {
|
|
131
|
+
mockUseSelect();
|
|
132
|
+
|
|
95
133
|
render( <PostPreviewButton /> );
|
|
96
134
|
|
|
97
135
|
const button = screen.getByRole( 'button' );
|
|
98
|
-
|
|
99
136
|
expect( within( button ).getByText( 'Preview' ) ).toBeVisible();
|
|
100
137
|
expect(
|
|
101
138
|
within( button ).getByText( '(opens in a new tab)' )
|
|
102
139
|
).toBeInTheDocument();
|
|
103
140
|
} );
|
|
104
141
|
|
|
105
|
-
it( 'should be disabled if post is not saveable.',
|
|
106
|
-
|
|
142
|
+
it( 'should be disabled if post is not saveable.', () => {
|
|
143
|
+
mockUseSelect( { isEditedPostSaveable: () => false } );
|
|
144
|
+
|
|
145
|
+
render( <PostPreviewButton /> );
|
|
107
146
|
|
|
108
147
|
expect( screen.getByRole( 'button' ) ).toBeDisabled();
|
|
109
148
|
} );
|
|
110
149
|
|
|
111
|
-
it( 'should not be disabled if post is saveable.',
|
|
112
|
-
|
|
150
|
+
it( 'should not be disabled if post is saveable.', () => {
|
|
151
|
+
mockUseSelect( { isEditedPostSaveable: () => true } );
|
|
152
|
+
|
|
153
|
+
render( <PostPreviewButton /> );
|
|
113
154
|
|
|
114
155
|
expect( screen.getByRole( 'button' ) ).toBeEnabled();
|
|
115
156
|
} );
|
|
116
157
|
|
|
117
|
-
it( 'should set `href` to
|
|
158
|
+
it( 'should set `href` to edited post preview link if specified.', () => {
|
|
118
159
|
const url = 'https://wordpress.org';
|
|
160
|
+
mockUseSelect( {
|
|
161
|
+
getEditedPostPreviewLink: () => url,
|
|
162
|
+
isEditedPostSaveable: () => true,
|
|
163
|
+
} );
|
|
119
164
|
|
|
120
|
-
render(
|
|
121
|
-
<PostPreviewButton isSaveable postId={ 123 } previewLink={ url } />
|
|
122
|
-
);
|
|
165
|
+
render( <PostPreviewButton /> );
|
|
123
166
|
|
|
124
167
|
expect( screen.getByRole( 'link' ) ).toHaveAttribute( 'href', url );
|
|
125
168
|
} );
|
|
126
169
|
|
|
127
|
-
it( 'should set `href` to
|
|
170
|
+
it( 'should set `href` to current post link if specified.', () => {
|
|
128
171
|
const url = 'https://wordpress.org';
|
|
172
|
+
mockUseSelect( {
|
|
173
|
+
getCurrentPostAttribute: () => url,
|
|
174
|
+
isEditedPostSaveable: () => true,
|
|
175
|
+
} );
|
|
129
176
|
|
|
130
|
-
render(
|
|
131
|
-
<PostPreviewButton
|
|
132
|
-
isSaveable
|
|
133
|
-
postId={ 123 }
|
|
134
|
-
currentPostLink={ url }
|
|
135
|
-
/>
|
|
136
|
-
);
|
|
177
|
+
render( <PostPreviewButton /> );
|
|
137
178
|
|
|
138
179
|
expect( screen.getByRole( 'link' ) ).toHaveAttribute( 'href', url );
|
|
139
180
|
} );
|
|
140
181
|
|
|
141
|
-
it( 'should prioritize
|
|
182
|
+
it( 'should prioritize preview link if both preview link and link attribute are specified.', () => {
|
|
142
183
|
const url1 = 'https://wordpress.org';
|
|
143
184
|
const url2 = 'https://wordpress.com';
|
|
185
|
+
mockUseSelect( {
|
|
186
|
+
getEditedPostPreviewLink: () => url1,
|
|
187
|
+
getCurrentPostAttribute: () => url2,
|
|
188
|
+
isEditedPostSaveable: () => true,
|
|
189
|
+
} );
|
|
144
190
|
|
|
145
|
-
render(
|
|
146
|
-
<PostPreviewButton
|
|
147
|
-
isSaveable
|
|
148
|
-
postId={ 123 }
|
|
149
|
-
previewLink={ url1 }
|
|
150
|
-
currentPostLink={ url2 }
|
|
151
|
-
/>
|
|
152
|
-
);
|
|
191
|
+
render( <PostPreviewButton /> );
|
|
153
192
|
|
|
154
193
|
expect( screen.getByRole( 'link' ) ).toHaveAttribute( 'href', url1 );
|
|
155
194
|
} );
|
|
156
195
|
|
|
157
|
-
it( 'should properly set target
|
|
158
|
-
|
|
159
|
-
|
|
196
|
+
it( 'should properly set link target', () => {
|
|
197
|
+
mockUseSelect( {
|
|
198
|
+
getEditedPostPreviewLink: () => 'https://wordpress.org',
|
|
199
|
+
isEditedPostSaveable: () => true,
|
|
200
|
+
} );
|
|
160
201
|
|
|
161
|
-
render(
|
|
162
|
-
<PostPreviewButton
|
|
163
|
-
isSaveable
|
|
164
|
-
postId={ postId }
|
|
165
|
-
previewLink={ url }
|
|
166
|
-
/>
|
|
167
|
-
);
|
|
202
|
+
render( <PostPreviewButton /> );
|
|
168
203
|
|
|
169
204
|
expect( screen.getByRole( 'link' ) ).toHaveAttribute(
|
|
170
205
|
'target',
|
|
171
|
-
|
|
172
|
-
);
|
|
173
|
-
} );
|
|
174
|
-
|
|
175
|
-
it( 'should save post if `isDraft` is `true`', async () => {
|
|
176
|
-
const user = userEvent.setup();
|
|
177
|
-
const url = 'https://wordpress.org';
|
|
178
|
-
const savePost = jest.fn();
|
|
179
|
-
const autosave = jest.fn();
|
|
180
|
-
|
|
181
|
-
render(
|
|
182
|
-
<PostPreviewButton
|
|
183
|
-
isAutosaveable
|
|
184
|
-
isSaveable
|
|
185
|
-
isDraft
|
|
186
|
-
postId={ 123 }
|
|
187
|
-
previewLink={ url }
|
|
188
|
-
savePost={ savePost }
|
|
189
|
-
autosave={ autosave }
|
|
190
|
-
/>
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
await user.click( screen.getByRole( 'link' ) );
|
|
194
|
-
|
|
195
|
-
expect( savePost ).toHaveBeenCalledWith(
|
|
196
|
-
expect.objectContaining( { isPreview: true } )
|
|
197
|
-
);
|
|
198
|
-
expect( autosave ).not.toHaveBeenCalled();
|
|
199
|
-
} );
|
|
200
|
-
|
|
201
|
-
it( 'should autosave post if `isDraft` is `false`', async () => {
|
|
202
|
-
const user = userEvent.setup();
|
|
203
|
-
const url = 'https://wordpress.org';
|
|
204
|
-
const savePost = jest.fn();
|
|
205
|
-
const autosave = jest.fn();
|
|
206
|
-
|
|
207
|
-
render(
|
|
208
|
-
<PostPreviewButton
|
|
209
|
-
isAutosaveable
|
|
210
|
-
isSaveable
|
|
211
|
-
isDraft={ false }
|
|
212
|
-
postId={ 123 }
|
|
213
|
-
previewLink={ url }
|
|
214
|
-
savePost={ savePost }
|
|
215
|
-
autosave={ autosave }
|
|
216
|
-
/>
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
await user.click( screen.getByRole( 'link' ) );
|
|
220
|
-
|
|
221
|
-
expect( savePost ).not.toHaveBeenCalled();
|
|
222
|
-
expect( autosave ).toHaveBeenCalledWith(
|
|
223
|
-
expect.objectContaining( { isPreview: true } )
|
|
206
|
+
'wp-preview-123'
|
|
224
207
|
);
|
|
225
208
|
} );
|
|
226
209
|
|
|
227
210
|
it( 'should open a window with the specified target', async () => {
|
|
228
211
|
const user = userEvent.setup();
|
|
229
|
-
const postId = 123;
|
|
230
|
-
const url = 'https://wordpress.org';
|
|
231
212
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
savePost={ jest.fn() }
|
|
239
|
-
autosave={ jest.fn() }
|
|
240
|
-
/>
|
|
241
|
-
);
|
|
213
|
+
mockUseSelect( {
|
|
214
|
+
getEditedPostPreviewLink: () => 'https://wordpress.org',
|
|
215
|
+
isEditedPostSaveable: () => true,
|
|
216
|
+
} );
|
|
217
|
+
|
|
218
|
+
render( <PostPreviewButton /> );
|
|
242
219
|
|
|
243
220
|
await user.click( screen.getByRole( 'link' ) );
|
|
244
221
|
|
|
245
|
-
expect( global.open ).toHaveBeenCalledWith(
|
|
246
|
-
'',
|
|
247
|
-
`wp-preview-${ postId }`
|
|
248
|
-
);
|
|
222
|
+
expect( global.open ).toHaveBeenCalledWith( '', 'wp-preview-123' );
|
|
249
223
|
} );
|
|
250
224
|
|
|
251
|
-
it( 'should
|
|
225
|
+
it( 'should display a `Generating preview` message while waiting for autosaving', async () => {
|
|
252
226
|
const user = userEvent.setup();
|
|
253
|
-
const postId = 123;
|
|
254
|
-
const url = 'https://wordpress.org';
|
|
255
|
-
|
|
256
|
-
const { rerender } = render(
|
|
257
|
-
<PostPreviewButton
|
|
258
|
-
isSaveable
|
|
259
|
-
postId={ postId }
|
|
260
|
-
savePost={ jest.fn() }
|
|
261
|
-
autosave={ jest.fn() }
|
|
262
|
-
/>
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
await user.click( screen.getByRole( 'button' ) );
|
|
266
227
|
|
|
267
|
-
|
|
228
|
+
mockUseSelect( {
|
|
229
|
+
getEditedPostPreviewLink: () => 'https://wordpress.org',
|
|
230
|
+
isEditedPostSaveable: () => true,
|
|
231
|
+
} );
|
|
268
232
|
|
|
269
|
-
|
|
270
|
-
<PostPreviewButton
|
|
271
|
-
isSaveable
|
|
272
|
-
postId={ postId }
|
|
273
|
-
previewLink={ url }
|
|
274
|
-
savePost={ jest.fn() }
|
|
275
|
-
autosave={ jest.fn() }
|
|
276
|
-
/>
|
|
277
|
-
);
|
|
233
|
+
render( <PostPreviewButton /> );
|
|
278
234
|
|
|
279
|
-
|
|
280
|
-
} );
|
|
235
|
+
await user.click( screen.getByRole( 'link' ) );
|
|
281
236
|
|
|
282
|
-
it( 'should display a `Generating preview` message while waiting for autosaving', async () => {
|
|
283
|
-
const user = userEvent.setup();
|
|
284
237
|
const previewText = 'Generating preview…';
|
|
285
|
-
const url = 'https://wordpress.org';
|
|
286
|
-
const savePost = jest.fn();
|
|
287
|
-
const autosave = jest.fn();
|
|
288
|
-
|
|
289
|
-
render(
|
|
290
|
-
<PostPreviewButton
|
|
291
|
-
isAutosaveable
|
|
292
|
-
isSaveable
|
|
293
|
-
isDraft={ false }
|
|
294
|
-
postId={ 123 }
|
|
295
|
-
previewLink={ url }
|
|
296
|
-
savePost={ savePost }
|
|
297
|
-
autosave={ autosave }
|
|
298
|
-
/>
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
await user.click( screen.getByRole( 'link' ) );
|
|
302
238
|
|
|
303
239
|
expect( documentWrite ).toHaveBeenCalledWith(
|
|
304
240
|
expect.stringContaining( previewText )
|
|
@@ -102,7 +102,6 @@ export class PostPublishButton extends Component {
|
|
|
102
102
|
render() {
|
|
103
103
|
const {
|
|
104
104
|
forceIsDirty,
|
|
105
|
-
forceIsSaving,
|
|
106
105
|
hasPublishAction,
|
|
107
106
|
isBeingScheduled,
|
|
108
107
|
isOpen,
|
|
@@ -124,7 +123,6 @@ export class PostPublishButton extends Component {
|
|
|
124
123
|
|
|
125
124
|
const isButtonDisabled =
|
|
126
125
|
( isSaving ||
|
|
127
|
-
forceIsSaving ||
|
|
128
126
|
! isSaveable ||
|
|
129
127
|
isPostSavingLocked ||
|
|
130
128
|
( ! isPublishable && ! forceIsDirty ) ) &&
|
|
@@ -133,7 +131,6 @@ export class PostPublishButton extends Component {
|
|
|
133
131
|
const isToggleDisabled =
|
|
134
132
|
( isPublished ||
|
|
135
133
|
isSaving ||
|
|
136
|
-
forceIsSaving ||
|
|
137
134
|
! isSaveable ||
|
|
138
135
|
( ! isPublishable && ! forceIsDirty ) ) &&
|
|
139
136
|
( ! hasNonPostEntityChanges || isSavingNonPostEntityChanges );
|
|
@@ -187,7 +184,6 @@ export class PostPublishButton extends Component {
|
|
|
187
184
|
: __( 'Publish' );
|
|
188
185
|
const buttonChildren = (
|
|
189
186
|
<PublishButtonLabel
|
|
190
|
-
forceIsSaving={ forceIsSaving }
|
|
191
187
|
hasNonPostEntityChanges={ hasNonPostEntityChanges }
|
|
192
188
|
/>
|
|
193
189
|
);
|
|
@@ -231,10 +227,9 @@ export default compose( [
|
|
|
231
227
|
hasNonPostEntityChanges,
|
|
232
228
|
isSavingNonPostEntityChanges,
|
|
233
229
|
} = select( editorStore );
|
|
234
|
-
const _isAutoSaving = isAutosavingPost();
|
|
235
230
|
return {
|
|
236
|
-
isSaving: isSavingPost()
|
|
237
|
-
isAutoSaving:
|
|
231
|
+
isSaving: isSavingPost(),
|
|
232
|
+
isAutoSaving: isAutosavingPost(),
|
|
238
233
|
isBeingScheduled: isEditedPostBeingScheduled(),
|
|
239
234
|
visibility: getEditedPostVisibility(),
|
|
240
235
|
isSaveable: isEditedPostSaveable(),
|
|
@@ -44,7 +44,7 @@ export function PublishButtonLabel( {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export default compose( [
|
|
47
|
-
withSelect( ( select
|
|
47
|
+
withSelect( ( select ) => {
|
|
48
48
|
const {
|
|
49
49
|
isCurrentPostPublished,
|
|
50
50
|
isEditedPostBeingScheduled,
|
|
@@ -57,7 +57,7 @@ export default compose( [
|
|
|
57
57
|
return {
|
|
58
58
|
isPublished: isCurrentPostPublished(),
|
|
59
59
|
isBeingScheduled: isEditedPostBeingScheduled(),
|
|
60
|
-
isSaving:
|
|
60
|
+
isSaving: isSavingPost(),
|
|
61
61
|
isPublishing: isPublishingPost(),
|
|
62
62
|
hasPublishAction:
|
|
63
63
|
getCurrentPost()._links?.[ 'wp:action-publish' ] ?? false,
|
|
@@ -19,16 +19,6 @@ describe( 'PostPublishButton', () => {
|
|
|
19
19
|
).toHaveAttribute( 'aria-disabled', 'true' );
|
|
20
20
|
} );
|
|
21
21
|
|
|
22
|
-
it( 'should be true if forceIsSaving is true', () => {
|
|
23
|
-
render(
|
|
24
|
-
<PostPublishButton isPublishable isSaveable forceIsSaving />
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
expect(
|
|
28
|
-
screen.getByRole( 'button', { name: 'Submit for Review' } )
|
|
29
|
-
).toHaveAttribute( 'aria-disabled', 'true' );
|
|
30
|
-
} );
|
|
31
|
-
|
|
32
22
|
it( 'should be true if post is not publishable and not forceIsDirty', () => {
|
|
33
23
|
render(
|
|
34
24
|
<PostPublishButton
|
|
@@ -51,7 +51,6 @@ export class PostPublishPanel extends Component {
|
|
|
51
51
|
render() {
|
|
52
52
|
const {
|
|
53
53
|
forceIsDirty,
|
|
54
|
-
forceIsSaving,
|
|
55
54
|
isBeingScheduled,
|
|
56
55
|
isPublished,
|
|
57
56
|
isPublishSidebarEnabled,
|
|
@@ -87,10 +86,9 @@ export class PostPublishPanel extends Component {
|
|
|
87
86
|
<>
|
|
88
87
|
<div className="editor-post-publish-panel__header-publish-button">
|
|
89
88
|
<PostPublishButton
|
|
90
|
-
focusOnMount
|
|
89
|
+
focusOnMount
|
|
91
90
|
onSubmit={ this.onSubmit }
|
|
92
91
|
forceIsDirty={ forceIsDirty }
|
|
93
|
-
forceIsSaving={ forceIsSaving }
|
|
94
92
|
/>
|
|
95
93
|
</div>
|
|
96
94
|
<div className="editor-post-publish-panel__header-cancel-button">
|
|
@@ -141,6 +139,7 @@ export default compose( [
|
|
|
141
139
|
isCurrentPostScheduled,
|
|
142
140
|
isEditedPostBeingScheduled,
|
|
143
141
|
isEditedPostDirty,
|
|
142
|
+
isAutosavingPost,
|
|
144
143
|
isSavingPost,
|
|
145
144
|
isSavingNonPostEntityChanges,
|
|
146
145
|
} = select( editorStore );
|
|
@@ -155,7 +154,7 @@ export default compose( [
|
|
|
155
154
|
isDirty: isEditedPostDirty(),
|
|
156
155
|
isPublished: isCurrentPostPublished(),
|
|
157
156
|
isPublishSidebarEnabled: isPublishSidebarEnabled(),
|
|
158
|
-
isSaving: isSavingPost(),
|
|
157
|
+
isSaving: isSavingPost() && ! isAutosavingPost(),
|
|
159
158
|
isSavingNonPostEntityChanges: isSavingNonPostEntityChanges(),
|
|
160
159
|
isScheduled: isCurrentPostScheduled(),
|
|
161
160
|
};
|
|
@@ -29,14 +29,11 @@ import { store as editorStore } from '../../store';
|
|
|
29
29
|
* @param {Object} props Component props.
|
|
30
30
|
* @param {?boolean} props.forceIsDirty Whether to force the post to be marked
|
|
31
31
|
* as dirty.
|
|
32
|
-
* @param {?boolean} props.forceIsSaving Whether to force the post to be marked
|
|
33
|
-
* as being saved.
|
|
34
32
|
* @param {?boolean} props.showIconLabels Whether interface buttons show labels instead of icons
|
|
35
33
|
* @return {import('@wordpress/element').WPComponent} The component.
|
|
36
34
|
*/
|
|
37
35
|
export default function PostSavedState( {
|
|
38
36
|
forceIsDirty,
|
|
39
|
-
forceIsSaving,
|
|
40
37
|
showIconLabels = false,
|
|
41
38
|
} ) {
|
|
42
39
|
const [ forceSavedMessage, setForceSavedMessage ] = useState( false );
|
|
@@ -72,14 +69,14 @@ export default function PostSavedState( {
|
|
|
72
69
|
isNew: isEditedPostNew(),
|
|
73
70
|
isPending: 'pending' === getEditedPostAttribute( 'status' ),
|
|
74
71
|
isPublished: isCurrentPostPublished(),
|
|
75
|
-
isSaving:
|
|
72
|
+
isSaving: isSavingPost(),
|
|
76
73
|
isSaveable: isEditedPostSaveable(),
|
|
77
74
|
isScheduled: isCurrentPostScheduled(),
|
|
78
75
|
hasPublishAction:
|
|
79
76
|
getCurrentPost()?._links?.[ 'wp:action-publish' ] ?? false,
|
|
80
77
|
};
|
|
81
78
|
},
|
|
82
|
-
[ forceIsDirty
|
|
79
|
+
[ forceIsDirty ]
|
|
83
80
|
);
|
|
84
81
|
|
|
85
82
|
const { savePost } = useDispatch( editorStore );
|
|
@@ -33,7 +33,7 @@ export function getFullPostScheduleLabel( dateAttribute ) {
|
|
|
33
33
|
|
|
34
34
|
const timezoneAbbreviation = getTimezoneAbbreviation();
|
|
35
35
|
const formattedDate = dateI18n(
|
|
36
|
-
// translators: If using a space between 'g:i' and 'a', use a non-breaking
|
|
36
|
+
// translators: If using a space between 'g:i' and 'a', use a non-breaking space.
|
|
37
37
|
_x( 'F j, Y g:i\xa0a', 'post schedule full date format' ),
|
|
38
38
|
date
|
|
39
39
|
);
|
|
@@ -62,7 +62,7 @@ export function getPostScheduleLabel(
|
|
|
62
62
|
return sprintf(
|
|
63
63
|
// translators: %s: Time of day the post is scheduled for.
|
|
64
64
|
__( 'Today at %s' ),
|
|
65
|
-
// translators: If using a space between 'g:i' and 'a', use a non-breaking
|
|
65
|
+
// translators: If using a space between 'g:i' and 'a', use a non-breaking space.
|
|
66
66
|
dateI18n( _x( 'g:i\xa0a', 'post schedule time format' ), date )
|
|
67
67
|
);
|
|
68
68
|
}
|
|
@@ -74,14 +74,14 @@ export function getPostScheduleLabel(
|
|
|
74
74
|
return sprintf(
|
|
75
75
|
// translators: %s: Time of day the post is scheduled for.
|
|
76
76
|
__( 'Tomorrow at %s' ),
|
|
77
|
-
// translators: If using a space between 'g:i' and 'a', use a non-breaking
|
|
77
|
+
// translators: If using a space between 'g:i' and 'a', use a non-breaking space.
|
|
78
78
|
dateI18n( _x( 'g:i\xa0a', 'post schedule time format' ), date )
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
if ( date.getFullYear() === now.getFullYear() ) {
|
|
83
83
|
return dateI18n(
|
|
84
|
-
// translators: If using a space between 'g:i' and 'a', use a non-breaking
|
|
84
|
+
// translators: If using a space between 'g:i' and 'a', use a non-breaking space.
|
|
85
85
|
_x( 'F j g:i\xa0a', 'post schedule date format without year' ),
|
|
86
86
|
date
|
|
87
87
|
);
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import {
|
|
5
5
|
Button,
|
|
6
|
-
FlexItem,
|
|
7
6
|
__experimentalConfirmDialog as ConfirmDialog,
|
|
8
7
|
} from '@wordpress/components';
|
|
9
8
|
import { __ } from '@wordpress/i18n';
|
|
@@ -41,7 +40,7 @@ function PostSwitchToDraftButton( {
|
|
|
41
40
|
};
|
|
42
41
|
|
|
43
42
|
return (
|
|
44
|
-
|
|
43
|
+
<>
|
|
45
44
|
<Button
|
|
46
45
|
className="editor-post-switch-to-draft"
|
|
47
46
|
onClick={ () => {
|
|
@@ -49,7 +48,7 @@ function PostSwitchToDraftButton( {
|
|
|
49
48
|
} }
|
|
50
49
|
disabled={ isSaving }
|
|
51
50
|
variant="secondary"
|
|
52
|
-
style={ {
|
|
51
|
+
style={ { flexGrow: '1', justifyContent: 'center' } }
|
|
53
52
|
>
|
|
54
53
|
{ __( 'Switch to draft' ) }
|
|
55
54
|
</Button>
|
|
@@ -60,7 +59,7 @@ function PostSwitchToDraftButton( {
|
|
|
60
59
|
>
|
|
61
60
|
{ alertMessage }
|
|
62
61
|
</ConfirmDialog>
|
|
63
|
-
|
|
62
|
+
</>
|
|
64
63
|
);
|
|
65
64
|
}
|
|
66
65
|
|