@wordpress/edit-post 8.0.0 → 8.1.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 +6 -0
- package/build/components/back-button/index.js +3 -1
- package/build/components/back-button/index.js.map +1 -1
- package/build/components/init-pattern-modal/index.js +1 -1
- package/build/components/init-pattern-modal/index.js.map +1 -1
- package/build/components/layout/index.js +93 -61
- package/build/components/layout/index.js.map +1 -1
- package/build/components/preferences-modal/enable-custom-fields.js +1 -0
- package/build/components/preferences-modal/enable-custom-fields.js.map +1 -1
- package/build/components/welcome-guide/index.js +5 -7
- package/build/components/welcome-guide/index.js.map +1 -1
- package/build/index.js +8 -6
- package/build/index.js.map +1 -1
- package/build/store/index.js +3 -0
- package/build/store/index.js.map +1 -1
- package/build/store/private-selectors.js +56 -0
- package/build/store/private-selectors.js.map +1 -0
- package/build/store/selectors.js +6 -43
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/back-button/index.js +3 -1
- package/build-module/components/back-button/index.js.map +1 -1
- package/build-module/components/init-pattern-modal/index.js +1 -1
- package/build-module/components/init-pattern-modal/index.js.map +1 -1
- package/build-module/components/layout/index.js +95 -64
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/preferences-modal/enable-custom-fields.js +1 -0
- package/build-module/components/preferences-modal/enable-custom-fields.js.map +1 -1
- package/build-module/components/welcome-guide/index.js +5 -7
- package/build-module/components/welcome-guide/index.js.map +1 -1
- package/build-module/index.js +9 -7
- package/build-module/index.js.map +1 -1
- package/build-module/store/index.js +3 -0
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-selectors.js +49 -0
- package/build-module/store/private-selectors.js.map +1 -0
- package/build-module/store/selectors.js +6 -43
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +31 -30
- package/src/components/back-button/index.js +13 -6
- package/src/components/init-pattern-modal/index.js +1 -4
- package/src/components/layout/index.js +138 -79
- package/src/components/preferences-modal/enable-custom-fields.js +1 -0
- package/src/components/welcome-guide/index.js +15 -15
- package/src/index.js +10 -8
- package/src/store/index.js +3 -1
- package/src/store/private-selectors.js +52 -0
- package/src/store/selectors.js +10 -61
- package/src/test/__snapshots__/editor.native.js.snap +12 -0
- package/src/test/editor.native.js +34 -0
- package/build/editor.js +0 -100
- package/build/editor.js.map +0 -1
- package/build-module/editor.js +0 -93
- package/build-module/editor.js.map +0 -1
- package/src/editor.js +0 -118
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
UnsavedChangesWarning,
|
|
13
13
|
EditorKeyboardShortcutsRegister,
|
|
14
14
|
EditorSnackbars,
|
|
15
|
+
ErrorBoundary,
|
|
16
|
+
PostLockedModal,
|
|
15
17
|
store as editorStore,
|
|
16
18
|
privateApis as editorPrivateApis,
|
|
17
19
|
} from '@wordpress/editor';
|
|
@@ -20,21 +22,27 @@ import {
|
|
|
20
22
|
privateApis as blockEditorPrivateApis,
|
|
21
23
|
store as blockEditorStore,
|
|
22
24
|
} from '@wordpress/block-editor';
|
|
23
|
-
import { useViewportMatch } from '@wordpress/compose';
|
|
24
25
|
import { PluginArea } from '@wordpress/plugins';
|
|
25
26
|
import { __, sprintf } from '@wordpress/i18n';
|
|
26
27
|
import { useCallback, useMemo } from '@wordpress/element';
|
|
27
28
|
import { store as noticesStore } from '@wordpress/notices';
|
|
28
29
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
29
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
CommandMenu,
|
|
32
|
+
privateApis as commandsPrivateApis,
|
|
33
|
+
} from '@wordpress/commands';
|
|
30
34
|
import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands';
|
|
31
35
|
import { privateApis as blockLibraryPrivateApis } from '@wordpress/block-library';
|
|
32
36
|
import { addQueryArgs } from '@wordpress/url';
|
|
37
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
38
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
39
|
+
import { SlotFillProvider } from '@wordpress/components';
|
|
33
40
|
|
|
34
41
|
/**
|
|
35
42
|
* Internal dependencies
|
|
36
43
|
*/
|
|
37
44
|
import BackButton from '../back-button';
|
|
45
|
+
import EditorInitialization from '../editor-initialization';
|
|
38
46
|
import EditPostKeyboardShortcuts from '../keyboard-shortcuts';
|
|
39
47
|
import InitPatternModal from '../init-pattern-modal';
|
|
40
48
|
import BrowserURL from '../browser-url';
|
|
@@ -46,12 +54,12 @@ import { unlock } from '../../lock-unlock';
|
|
|
46
54
|
import useEditPostCommands from '../../commands/use-commands';
|
|
47
55
|
import { usePaddingAppender } from './use-padding-appender';
|
|
48
56
|
import { useShouldIframe } from './use-should-iframe';
|
|
57
|
+
import useNavigateToEntityRecord from '../../hooks/use-navigate-to-entity-record';
|
|
49
58
|
|
|
50
59
|
const { getLayoutStyles } = unlock( blockEditorPrivateApis );
|
|
51
60
|
const { useCommands } = unlock( coreCommandsPrivateApis );
|
|
52
61
|
const { useCommandContext } = unlock( commandsPrivateApis );
|
|
53
|
-
const {
|
|
54
|
-
unlock( editorPrivateApis );
|
|
62
|
+
const { Editor, FullscreenMode } = unlock( editorPrivateApis );
|
|
55
63
|
const { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis );
|
|
56
64
|
const DESIGN_POST_TYPES = [
|
|
57
65
|
'wp_template',
|
|
@@ -92,7 +100,7 @@ function useEditorStyles() {
|
|
|
92
100
|
) ?? [];
|
|
93
101
|
|
|
94
102
|
const defaultEditorStyles = [
|
|
95
|
-
...editorSettings
|
|
103
|
+
...( editorSettings?.defaultEditorStyles ?? [] ),
|
|
96
104
|
...presetStyles,
|
|
97
105
|
];
|
|
98
106
|
|
|
@@ -119,7 +127,7 @@ function useEditorStyles() {
|
|
|
119
127
|
? editorSettings.styles ?? []
|
|
120
128
|
: defaultEditorStyles;
|
|
121
129
|
|
|
122
|
-
// Add a constant padding for the
|
|
130
|
+
// Add a constant padding for the typewriter effect. When typing at the
|
|
123
131
|
// bottom, there needs to be room to scroll up.
|
|
124
132
|
if (
|
|
125
133
|
! isZoomedOutView &&
|
|
@@ -127,9 +135,12 @@ function useEditorStyles() {
|
|
|
127
135
|
renderingMode === 'post-only' &&
|
|
128
136
|
! DESIGN_POST_TYPES.includes( postType )
|
|
129
137
|
) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
return [
|
|
139
|
+
...baseStyles,
|
|
140
|
+
{
|
|
141
|
+
css: 'body{padding-bottom: 40vh}',
|
|
142
|
+
},
|
|
143
|
+
];
|
|
133
144
|
}
|
|
134
145
|
|
|
135
146
|
return baseStyles;
|
|
@@ -138,59 +149,96 @@ function useEditorStyles() {
|
|
|
138
149
|
editorSettings.disableLayoutStyles,
|
|
139
150
|
editorSettings.styles,
|
|
140
151
|
hasThemeStyleSupport,
|
|
152
|
+
postType,
|
|
141
153
|
] );
|
|
142
154
|
}
|
|
143
155
|
|
|
144
|
-
function Layout( {
|
|
156
|
+
function Layout( {
|
|
157
|
+
postId: initialPostId,
|
|
158
|
+
postType: initialPostType,
|
|
159
|
+
settings,
|
|
160
|
+
initialEdits,
|
|
161
|
+
} ) {
|
|
145
162
|
useCommands();
|
|
146
163
|
useEditPostCommands();
|
|
147
|
-
const isWideViewport = useViewportMatch( 'large' );
|
|
148
164
|
const paddingAppenderRef = usePaddingAppender();
|
|
149
165
|
const shouldIframe = useShouldIframe();
|
|
150
166
|
const { createErrorNotice } = useDispatch( noticesStore );
|
|
167
|
+
const {
|
|
168
|
+
currentPost,
|
|
169
|
+
onNavigateToEntityRecord,
|
|
170
|
+
onNavigateToPreviousEntityRecord,
|
|
171
|
+
} = useNavigateToEntityRecord(
|
|
172
|
+
initialPostId,
|
|
173
|
+
initialPostType,
|
|
174
|
+
'post-only'
|
|
175
|
+
);
|
|
151
176
|
const {
|
|
152
177
|
mode,
|
|
153
178
|
isFullscreenActive,
|
|
154
|
-
sidebarIsOpened,
|
|
155
179
|
hasActiveMetaboxes,
|
|
156
180
|
hasBlockSelected,
|
|
157
181
|
showIconLabels,
|
|
158
182
|
isDistractionFree,
|
|
159
|
-
showBlockBreadcrumbs,
|
|
160
183
|
showMetaBoxes,
|
|
161
184
|
hasHistory,
|
|
162
185
|
isEditingTemplate,
|
|
163
186
|
isWelcomeGuideVisible,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
187
|
+
templateId,
|
|
188
|
+
} = useSelect(
|
|
189
|
+
( select ) => {
|
|
190
|
+
const { get } = select( preferencesStore );
|
|
191
|
+
const { isFeatureActive, getEditedPostTemplateId } = unlock(
|
|
192
|
+
select( editPostStore )
|
|
193
|
+
);
|
|
194
|
+
const { canUser, getPostType } = select( coreStore );
|
|
168
195
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
196
|
+
const supportsTemplateMode = settings.supportsTemplateMode;
|
|
197
|
+
const isViewable =
|
|
198
|
+
getPostType( currentPost.postType )?.viewable ?? false;
|
|
199
|
+
const canViewTemplate = canUser( 'read', 'templates' );
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
mode: select( editorStore ).getEditorMode(),
|
|
203
|
+
isFullscreenActive:
|
|
204
|
+
select( editPostStore ).isFeatureActive( 'fullscreenMode' ),
|
|
205
|
+
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
|
|
206
|
+
hasBlockSelected:
|
|
207
|
+
!! select( blockEditorStore ).getBlockSelectionStart(),
|
|
208
|
+
showIconLabels: get( 'core', 'showIconLabels' ),
|
|
209
|
+
isDistractionFree: get( 'core', 'distractionFree' ),
|
|
210
|
+
showMetaBoxes:
|
|
211
|
+
select( editorStore ).getRenderingMode() === 'post-only',
|
|
212
|
+
isEditingTemplate:
|
|
213
|
+
select( editorStore ).getCurrentPostType() ===
|
|
214
|
+
'wp_template',
|
|
215
|
+
isWelcomeGuideVisible: isFeatureActive( 'welcomeGuide' ),
|
|
216
|
+
templateId:
|
|
217
|
+
supportsTemplateMode &&
|
|
218
|
+
isViewable &&
|
|
219
|
+
canViewTemplate &&
|
|
220
|
+
currentPost.postType !== 'wp_template'
|
|
221
|
+
? getEditedPostTemplateId()
|
|
222
|
+
: null,
|
|
223
|
+
};
|
|
224
|
+
},
|
|
225
|
+
[ settings.supportsTemplateMode, currentPost.postType ]
|
|
226
|
+
);
|
|
187
227
|
|
|
188
228
|
// Set the right context for the command palette
|
|
189
229
|
const commandContext = hasBlockSelected
|
|
190
230
|
? 'block-selection-edit'
|
|
191
231
|
: 'entity-edit';
|
|
192
232
|
useCommandContext( commandContext );
|
|
193
|
-
|
|
233
|
+
const editorSettings = useMemo(
|
|
234
|
+
() => ( {
|
|
235
|
+
...settings,
|
|
236
|
+
onNavigateToEntityRecord,
|
|
237
|
+
onNavigateToPreviousEntityRecord,
|
|
238
|
+
defaultRenderingMode: 'post-only',
|
|
239
|
+
} ),
|
|
240
|
+
[ settings, onNavigateToEntityRecord, onNavigateToPreviousEntityRecord ]
|
|
241
|
+
);
|
|
194
242
|
const styles = useEditorStyles();
|
|
195
243
|
|
|
196
244
|
// We need to add the show-icon-labels class to the body element so it is applied to modals.
|
|
@@ -201,11 +249,7 @@ function Layout( { initialPost } ) {
|
|
|
201
249
|
}
|
|
202
250
|
|
|
203
251
|
const className = clsx( 'edit-post-layout', 'is-mode-' + mode, {
|
|
204
|
-
'is-sidebar-opened': sidebarIsOpened,
|
|
205
252
|
'has-metaboxes': hasActiveMetaboxes,
|
|
206
|
-
'is-distraction-free': isDistractionFree && isWideViewport,
|
|
207
|
-
'has-block-breadcrumbs':
|
|
208
|
-
showBlockBreadcrumbs && ! isDistractionFree && isWideViewport,
|
|
209
253
|
} );
|
|
210
254
|
|
|
211
255
|
function onPluginAreaError( name ) {
|
|
@@ -245,7 +289,7 @@ function Layout( { initialPost } ) {
|
|
|
245
289
|
sprintf(
|
|
246
290
|
// translators: %s: Title of the created post e.g: "Post 1".
|
|
247
291
|
__( '"%s" successfully created.' ),
|
|
248
|
-
title
|
|
292
|
+
decodeEntities( title )
|
|
249
293
|
),
|
|
250
294
|
{
|
|
251
295
|
type: 'snackbar',
|
|
@@ -272,48 +316,63 @@ function Layout( { initialPost } ) {
|
|
|
272
316
|
[ createSuccessNotice ]
|
|
273
317
|
);
|
|
274
318
|
|
|
319
|
+
const initialPost = useMemo( () => {
|
|
320
|
+
return {
|
|
321
|
+
type: initialPostType,
|
|
322
|
+
id: initialPostId,
|
|
323
|
+
};
|
|
324
|
+
}, [ initialPostType, initialPostId ] );
|
|
275
325
|
return (
|
|
276
|
-
|
|
277
|
-
<
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
326
|
+
<SlotFillProvider>
|
|
327
|
+
<ErrorBoundary>
|
|
328
|
+
<CommandMenu />
|
|
329
|
+
<WelcomeGuide postType={ currentPost.postType } />
|
|
330
|
+
<Editor
|
|
331
|
+
settings={ editorSettings }
|
|
332
|
+
initialEdits={ initialEdits }
|
|
333
|
+
postType={ currentPost.postType }
|
|
334
|
+
postId={ currentPost.postId }
|
|
335
|
+
templateId={ templateId }
|
|
336
|
+
className={ className }
|
|
337
|
+
styles={ styles }
|
|
338
|
+
forceIsDirty={ hasActiveMetaboxes }
|
|
339
|
+
contentRef={ paddingAppenderRef }
|
|
340
|
+
disableIframe={ ! shouldIframe }
|
|
341
|
+
// We should auto-focus the canvas (title) on load.
|
|
342
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
343
|
+
autoFocus={ ! isWelcomeGuideVisible }
|
|
290
344
|
onActionPerformed={ onActionPerformed }
|
|
291
|
-
|
|
345
|
+
extraSidebarPanels={
|
|
292
346
|
! isEditingTemplate && <MetaBoxes location="side" />
|
|
293
347
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
<
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
348
|
+
extraContent={
|
|
349
|
+
! isDistractionFree &&
|
|
350
|
+
showMetaBoxes && (
|
|
351
|
+
<div className="edit-post-layout__metaboxes">
|
|
352
|
+
<MetaBoxes location="normal" />
|
|
353
|
+
<MetaBoxes location="advanced" />
|
|
354
|
+
</div>
|
|
355
|
+
)
|
|
356
|
+
}
|
|
357
|
+
>
|
|
358
|
+
<PostLockedModal />
|
|
359
|
+
<EditorInitialization />
|
|
360
|
+
<FullscreenMode isActive={ isFullscreenActive } />
|
|
361
|
+
<BrowserURL hasHistory={ hasHistory } />
|
|
362
|
+
<UnsavedChangesWarning />
|
|
363
|
+
<AutosaveMonitor />
|
|
364
|
+
<LocalAutosaveMonitor />
|
|
365
|
+
<EditPostKeyboardShortcuts />
|
|
366
|
+
<EditorKeyboardShortcutsRegister />
|
|
367
|
+
<BlockKeyboardShortcuts />
|
|
368
|
+
<InitPatternModal />
|
|
369
|
+
<PluginArea onError={ onPluginAreaError } />
|
|
370
|
+
<PostEditorMoreMenu />
|
|
371
|
+
<BackButton initialPost={ initialPost } />
|
|
372
|
+
<EditorSnackbars />
|
|
373
|
+
</Editor>
|
|
374
|
+
</ErrorBoundary>
|
|
375
|
+
</SlotFillProvider>
|
|
317
376
|
);
|
|
318
377
|
}
|
|
319
378
|
|
|
@@ -42,6 +42,7 @@ export function CustomFieldsConfirmation( { willEnable } ) {
|
|
|
42
42
|
className="edit-post-preferences-modal__custom-fields-confirmation-button"
|
|
43
43
|
variant="secondary"
|
|
44
44
|
isBusy={ isReloading }
|
|
45
|
+
__experimentalIsFocusable
|
|
45
46
|
disabled={ isReloading }
|
|
46
47
|
onClick={ () => {
|
|
47
48
|
setIsReloading( true );
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Internal dependencies
|
|
@@ -11,21 +10,22 @@ import WelcomeGuideDefault from './default';
|
|
|
11
10
|
import WelcomeGuideTemplate from './template';
|
|
12
11
|
import { store as editPostStore } from '../../store';
|
|
13
12
|
|
|
14
|
-
export default function WelcomeGuide() {
|
|
15
|
-
const { isActive, isEditingTemplate } = useSelect(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export default function WelcomeGuide( { postType } ) {
|
|
14
|
+
const { isActive, isEditingTemplate } = useSelect(
|
|
15
|
+
( select ) => {
|
|
16
|
+
const { isFeatureActive } = select( editPostStore );
|
|
17
|
+
const _isEditingTemplate = postType === 'wp_template';
|
|
18
|
+
const feature = _isEditingTemplate
|
|
19
|
+
? 'welcomeGuideTemplate'
|
|
20
|
+
: 'welcomeGuide';
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
}, [] );
|
|
22
|
+
return {
|
|
23
|
+
isActive: isFeatureActive( feature ),
|
|
24
|
+
isEditingTemplate: _isEditingTemplate,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
[ postType ]
|
|
28
|
+
);
|
|
29
29
|
|
|
30
30
|
if ( ! isActive ) {
|
|
31
31
|
return null;
|
package/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
__experimentalRegisterExperimentalCoreBlocks,
|
|
8
8
|
} from '@wordpress/block-library';
|
|
9
9
|
import deprecated from '@wordpress/deprecated';
|
|
10
|
-
import { createRoot } from '@wordpress/element';
|
|
10
|
+
import { createRoot, StrictMode } from '@wordpress/element';
|
|
11
11
|
import { dispatch, select } from '@wordpress/data';
|
|
12
12
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
13
13
|
import {
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
/**
|
|
23
23
|
* Internal dependencies
|
|
24
24
|
*/
|
|
25
|
-
import
|
|
25
|
+
import Layout from './components/layout';
|
|
26
26
|
import { unlock } from './lock-unlock';
|
|
27
27
|
|
|
28
28
|
const { BackButton: __experimentalMainDashboardButton } =
|
|
@@ -137,12 +137,14 @@ export function initializeEditor(
|
|
|
137
137
|
window.addEventListener( 'drop', ( e ) => e.preventDefault(), false );
|
|
138
138
|
|
|
139
139
|
root.render(
|
|
140
|
-
<
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
<StrictMode>
|
|
141
|
+
<Layout
|
|
142
|
+
settings={ settings }
|
|
143
|
+
postId={ postId }
|
|
144
|
+
postType={ postType }
|
|
145
|
+
initialEdits={ initialEdits }
|
|
146
|
+
/>
|
|
147
|
+
</StrictMode>
|
|
146
148
|
);
|
|
147
149
|
|
|
148
150
|
return root;
|
package/src/store/index.js
CHANGED
|
@@ -9,7 +9,9 @@ import { createReduxStore, register } from '@wordpress/data';
|
|
|
9
9
|
import reducer from './reducer';
|
|
10
10
|
import * as actions from './actions';
|
|
11
11
|
import * as selectors from './selectors';
|
|
12
|
+
import * as privateSelectors from './private-selectors';
|
|
12
13
|
import { STORE_NAME } from './constants';
|
|
14
|
+
import { unlock } from '../lock-unlock';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Store definition for the edit post namespace.
|
|
@@ -23,5 +25,5 @@ export const store = createReduxStore( STORE_NAME, {
|
|
|
23
25
|
actions,
|
|
24
26
|
selectors,
|
|
25
27
|
} );
|
|
26
|
-
|
|
27
28
|
register( store );
|
|
29
|
+
unlock( store ).registerPrivateSelectors( privateSelectors );
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createRegistrySelector } from '@wordpress/data';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { store as editorStore } from '@wordpress/editor';
|
|
7
|
+
|
|
8
|
+
export const getEditedPostTemplateId = createRegistrySelector(
|
|
9
|
+
( select ) => () => {
|
|
10
|
+
const {
|
|
11
|
+
id: postId,
|
|
12
|
+
type: postType,
|
|
13
|
+
slug,
|
|
14
|
+
} = select( editorStore ).getCurrentPost();
|
|
15
|
+
const { getSite, getEntityRecords } = select( coreStore );
|
|
16
|
+
const siteSettings = getSite();
|
|
17
|
+
// First check if the current page is set as the posts page.
|
|
18
|
+
const isPostsPage = +postId === siteSettings?.page_for_posts;
|
|
19
|
+
if ( isPostsPage ) {
|
|
20
|
+
return select( coreStore ).getDefaultTemplateId( { slug: 'home' } );
|
|
21
|
+
}
|
|
22
|
+
const currentTemplate =
|
|
23
|
+
select( editorStore ).getEditedPostAttribute( 'template' );
|
|
24
|
+
if ( currentTemplate ) {
|
|
25
|
+
const templateWithSameSlug = getEntityRecords(
|
|
26
|
+
'postType',
|
|
27
|
+
'wp_template',
|
|
28
|
+
{ per_page: -1 }
|
|
29
|
+
)?.find( ( template ) => template.slug === currentTemplate );
|
|
30
|
+
if ( ! templateWithSameSlug ) {
|
|
31
|
+
return templateWithSameSlug;
|
|
32
|
+
}
|
|
33
|
+
return templateWithSameSlug.id;
|
|
34
|
+
}
|
|
35
|
+
let slugToCheck;
|
|
36
|
+
// In `draft` status we might not have a slug available, so we use the `single`
|
|
37
|
+
// post type templates slug(ex page, single-post, single-product etc..).
|
|
38
|
+
// Pages do not need the `single` prefix in the slug to be prioritized
|
|
39
|
+
// through template hierarchy.
|
|
40
|
+
if ( slug ) {
|
|
41
|
+
slugToCheck =
|
|
42
|
+
postType === 'page'
|
|
43
|
+
? `${ postType }-${ slug }`
|
|
44
|
+
: `single-${ postType }-${ slug }`;
|
|
45
|
+
} else {
|
|
46
|
+
slugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;
|
|
47
|
+
}
|
|
48
|
+
return select( coreStore ).getDefaultTemplateId( {
|
|
49
|
+
slug: slugToCheck,
|
|
50
|
+
} );
|
|
51
|
+
}
|
|
52
|
+
);
|
package/src/store/selectors.js
CHANGED
|
@@ -14,6 +14,7 @@ import deprecated from '@wordpress/deprecated';
|
|
|
14
14
|
* Internal dependencies
|
|
15
15
|
*/
|
|
16
16
|
import { unlock } from '../lock-unlock';
|
|
17
|
+
import { getEditedPostTemplateId } from './private-selectors';
|
|
17
18
|
|
|
18
19
|
const { interfaceStore } = unlock( editorPrivateApis );
|
|
19
20
|
const EMPTY_ARRAY = [];
|
|
@@ -555,67 +556,15 @@ export function areMetaBoxesInitialized( state ) {
|
|
|
555
556
|
* @return {Object?} Post Template.
|
|
556
557
|
*/
|
|
557
558
|
export const getEditedPostTemplate = createRegistrySelector(
|
|
558
|
-
( select ) => () => {
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
slug,
|
|
563
|
-
} = select( editorStore ).getCurrentPost();
|
|
564
|
-
const { getSite, getEditedEntityRecord, getEntityRecords } =
|
|
565
|
-
select( coreStore );
|
|
566
|
-
const siteSettings = getSite();
|
|
567
|
-
// First check if the current page is set as the posts page.
|
|
568
|
-
const isPostsPage = +postId === siteSettings?.page_for_posts;
|
|
569
|
-
if ( isPostsPage ) {
|
|
570
|
-
const defaultTemplateId = select( coreStore ).getDefaultTemplateId(
|
|
571
|
-
{ slug: 'home' }
|
|
572
|
-
);
|
|
573
|
-
return getEditedEntityRecord(
|
|
574
|
-
'postType',
|
|
575
|
-
'wp_template',
|
|
576
|
-
defaultTemplateId
|
|
577
|
-
);
|
|
578
|
-
}
|
|
579
|
-
const currentTemplate =
|
|
580
|
-
select( editorStore ).getEditedPostAttribute( 'template' );
|
|
581
|
-
if ( currentTemplate ) {
|
|
582
|
-
const templateWithSameSlug = getEntityRecords(
|
|
583
|
-
'postType',
|
|
584
|
-
'wp_template',
|
|
585
|
-
{ per_page: -1 }
|
|
586
|
-
)?.find( ( template ) => template.slug === currentTemplate );
|
|
587
|
-
if ( ! templateWithSameSlug ) {
|
|
588
|
-
return templateWithSameSlug;
|
|
589
|
-
}
|
|
590
|
-
return getEditedEntityRecord(
|
|
591
|
-
'postType',
|
|
592
|
-
'wp_template',
|
|
593
|
-
templateWithSameSlug.id
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
let slugToCheck;
|
|
597
|
-
// In `draft` status we might not have a slug available, so we use the `single`
|
|
598
|
-
// post type templates slug(ex page, single-post, single-product etc..).
|
|
599
|
-
// Pages do not need the `single` prefix in the slug to be prioritized
|
|
600
|
-
// through template hierarchy.
|
|
601
|
-
if ( slug ) {
|
|
602
|
-
slugToCheck =
|
|
603
|
-
postType === 'page'
|
|
604
|
-
? `${ postType }-${ slug }`
|
|
605
|
-
: `single-${ postType }-${ slug }`;
|
|
606
|
-
} else {
|
|
607
|
-
slugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;
|
|
559
|
+
( select ) => ( state ) => {
|
|
560
|
+
const templateId = getEditedPostTemplateId( state );
|
|
561
|
+
if ( ! templateId ) {
|
|
562
|
+
return undefined;
|
|
608
563
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
? select( coreStore ).getEditedEntityRecord(
|
|
615
|
-
'postType',
|
|
616
|
-
'wp_template',
|
|
617
|
-
defaultTemplateId
|
|
618
|
-
)
|
|
619
|
-
: null;
|
|
564
|
+
return select( coreStore ).getEditedEntityRecord(
|
|
565
|
+
'postType',
|
|
566
|
+
'wp_template',
|
|
567
|
+
templateId
|
|
568
|
+
);
|
|
620
569
|
}
|
|
621
570
|
);
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`Editor adds empty image block when pasting unsupported HTML local image path 1`] = `
|
|
4
|
+
"<!-- wp:image -->
|
|
5
|
+
<figure class="wp-block-image"><img src="" alt=""/></figure>
|
|
6
|
+
<!-- /wp:image -->"
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
exports[`Editor adds image block when pasting HTML local image path 1`] = `
|
|
10
|
+
"<!-- wp:image -->
|
|
11
|
+
<figure class="wp-block-image"><img src="file:///path/to/file.png" alt=""/></figure>
|
|
12
|
+
<!-- /wp:image -->"
|
|
13
|
+
`;
|
|
14
|
+
|
|
3
15
|
exports[`Editor appends media correctly for allowed types 1`] = `
|
|
4
16
|
"<!-- wp:image -->
|
|
5
17
|
<figure class="wp-block-image"><img src="https://test-site.files.wordpress.com/local-image-1.jpeg" alt=""/></figure>
|
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
getEditorHtml,
|
|
10
10
|
getEditorTitle,
|
|
11
11
|
initializeEditor,
|
|
12
|
+
pasteIntoRichText,
|
|
12
13
|
screen,
|
|
13
14
|
setupCoreBlocks,
|
|
15
|
+
within,
|
|
14
16
|
} from 'test/helpers';
|
|
15
17
|
import { BackHandler } from 'react-native';
|
|
16
18
|
|
|
@@ -98,6 +100,38 @@ describe( 'Editor', () => {
|
|
|
98
100
|
} );
|
|
99
101
|
} );
|
|
100
102
|
|
|
103
|
+
it( 'adds empty image block when pasting unsupported HTML local image path', async () => {
|
|
104
|
+
await initializeEditor();
|
|
105
|
+
await addBlock( screen, 'Paragraph' );
|
|
106
|
+
|
|
107
|
+
const paragraphBlock = getBlock( screen, 'Paragraph' );
|
|
108
|
+
fireEvent.press( paragraphBlock );
|
|
109
|
+
const paragraphTextInput =
|
|
110
|
+
within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
|
|
111
|
+
|
|
112
|
+
pasteIntoRichText( paragraphTextInput, {
|
|
113
|
+
text: '<div><img src="file:LOW-RES.png"></div>',
|
|
114
|
+
} );
|
|
115
|
+
|
|
116
|
+
expect( getEditorHtml() ).toMatchSnapshot();
|
|
117
|
+
} );
|
|
118
|
+
|
|
119
|
+
it( 'adds image block when pasting HTML local image path', async () => {
|
|
120
|
+
await initializeEditor();
|
|
121
|
+
await addBlock( screen, 'Paragraph' );
|
|
122
|
+
|
|
123
|
+
const paragraphBlock = getBlock( screen, 'Paragraph' );
|
|
124
|
+
fireEvent.press( paragraphBlock );
|
|
125
|
+
const paragraphTextInput =
|
|
126
|
+
within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
|
|
127
|
+
|
|
128
|
+
pasteIntoRichText( paragraphTextInput, {
|
|
129
|
+
files: [ 'file:///path/to/file.png' ],
|
|
130
|
+
} );
|
|
131
|
+
|
|
132
|
+
expect( getEditorHtml() ).toMatchSnapshot();
|
|
133
|
+
} );
|
|
134
|
+
|
|
101
135
|
it( 'appends media correctly for allowed types', async () => {
|
|
102
136
|
// Arrange
|
|
103
137
|
requestMediaImport
|