@wordpress/edit-post 8.0.4 → 8.2.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 +15 -11
- package/build/components/layout/index.js +86 -47
- package/build/components/layout/index.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/layout/index.js +88 -50
- package/build-module/components/layout/index.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 -31
- package/src/components/layout/index.js +128 -65
- 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';
|
|
@@ -25,16 +27,22 @@ import { __, sprintf } from '@wordpress/i18n';
|
|
|
25
27
|
import { useCallback, useMemo } from '@wordpress/element';
|
|
26
28
|
import { store as noticesStore } from '@wordpress/notices';
|
|
27
29
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
28
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
CommandMenu,
|
|
32
|
+
privateApis as commandsPrivateApis,
|
|
33
|
+
} from '@wordpress/commands';
|
|
29
34
|
import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands';
|
|
30
35
|
import { privateApis as blockLibraryPrivateApis } from '@wordpress/block-library';
|
|
31
36
|
import { addQueryArgs } from '@wordpress/url';
|
|
32
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
|
|
|
@@ -145,12 +153,26 @@ function useEditorStyles() {
|
|
|
145
153
|
] );
|
|
146
154
|
}
|
|
147
155
|
|
|
148
|
-
function Layout( {
|
|
156
|
+
function Layout( {
|
|
157
|
+
postId: initialPostId,
|
|
158
|
+
postType: initialPostType,
|
|
159
|
+
settings,
|
|
160
|
+
initialEdits,
|
|
161
|
+
} ) {
|
|
149
162
|
useCommands();
|
|
150
163
|
useEditPostCommands();
|
|
151
164
|
const paddingAppenderRef = usePaddingAppender();
|
|
152
165
|
const shouldIframe = useShouldIframe();
|
|
153
166
|
const { createErrorNotice } = useDispatch( noticesStore );
|
|
167
|
+
const {
|
|
168
|
+
currentPost,
|
|
169
|
+
onNavigateToEntityRecord,
|
|
170
|
+
onNavigateToPreviousEntityRecord,
|
|
171
|
+
} = useNavigateToEntityRecord(
|
|
172
|
+
initialPostId,
|
|
173
|
+
initialPostType,
|
|
174
|
+
'post-only'
|
|
175
|
+
);
|
|
154
176
|
const {
|
|
155
177
|
mode,
|
|
156
178
|
isFullscreenActive,
|
|
@@ -162,35 +184,61 @@ function Layout( { initialPost } ) {
|
|
|
162
184
|
hasHistory,
|
|
163
185
|
isEditingTemplate,
|
|
164
186
|
isWelcomeGuideVisible,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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 );
|
|
169
195
|
|
|
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.
|
|
@@ -268,48 +316,63 @@ function Layout( { initialPost } ) {
|
|
|
268
316
|
[ createSuccessNotice ]
|
|
269
317
|
);
|
|
270
318
|
|
|
319
|
+
const initialPost = useMemo( () => {
|
|
320
|
+
return {
|
|
321
|
+
type: initialPostType,
|
|
322
|
+
id: initialPostId,
|
|
323
|
+
};
|
|
324
|
+
}, [ initialPostType, initialPostId ] );
|
|
271
325
|
return (
|
|
272
|
-
|
|
273
|
-
<
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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 }
|
|
286
344
|
onActionPerformed={ onActionPerformed }
|
|
287
|
-
|
|
345
|
+
extraSidebarPanels={
|
|
288
346
|
! isEditingTemplate && <MetaBoxes location="side" />
|
|
289
347
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
<
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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>
|
|
313
376
|
);
|
|
314
377
|
}
|
|
315
378
|
|
|
@@ -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
|
package/build/editor.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _data = require("@wordpress/data");
|
|
9
|
-
var _editor = require("@wordpress/editor");
|
|
10
|
-
var _element = require("@wordpress/element");
|
|
11
|
-
var _components = require("@wordpress/components");
|
|
12
|
-
var _coreData = require("@wordpress/core-data");
|
|
13
|
-
var _commands = require("@wordpress/commands");
|
|
14
|
-
var _layout = _interopRequireDefault(require("./components/layout"));
|
|
15
|
-
var _editorInitialization = _interopRequireDefault(require("./components/editor-initialization"));
|
|
16
|
-
var _store = require("./store");
|
|
17
|
-
var _lockUnlock = require("./lock-unlock");
|
|
18
|
-
var _useNavigateToEntityRecord = _interopRequireDefault(require("./hooks/use-navigate-to-entity-record"));
|
|
19
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
|
-
/**
|
|
21
|
-
* WordPress dependencies
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Internal dependencies
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
ExperimentalEditorProvider
|
|
30
|
-
} = (0, _lockUnlock.unlock)(_editor.privateApis);
|
|
31
|
-
function Editor({
|
|
32
|
-
postId: initialPostId,
|
|
33
|
-
postType: initialPostType,
|
|
34
|
-
settings,
|
|
35
|
-
initialEdits,
|
|
36
|
-
...props
|
|
37
|
-
}) {
|
|
38
|
-
const {
|
|
39
|
-
currentPost,
|
|
40
|
-
onNavigateToEntityRecord,
|
|
41
|
-
onNavigateToPreviousEntityRecord
|
|
42
|
-
} = (0, _useNavigateToEntityRecord.default)(initialPostId, initialPostType, 'post-only');
|
|
43
|
-
const {
|
|
44
|
-
post,
|
|
45
|
-
template
|
|
46
|
-
} = (0, _data.useSelect)(select => {
|
|
47
|
-
var _getPostType$viewable;
|
|
48
|
-
const {
|
|
49
|
-
getEditedPostTemplate
|
|
50
|
-
} = select(_store.store);
|
|
51
|
-
const {
|
|
52
|
-
getEntityRecord,
|
|
53
|
-
getPostType,
|
|
54
|
-
canUser
|
|
55
|
-
} = select(_coreData.store);
|
|
56
|
-
const {
|
|
57
|
-
getEditorSettings
|
|
58
|
-
} = select(_editor.store);
|
|
59
|
-
const postObject = getEntityRecord('postType', currentPost.postType, currentPost.postId);
|
|
60
|
-
const supportsTemplateMode = getEditorSettings().supportsTemplateMode;
|
|
61
|
-
const isViewable = (_getPostType$viewable = getPostType(currentPost.postType)?.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false;
|
|
62
|
-
const canViewTemplate = canUser('read', 'templates');
|
|
63
|
-
return {
|
|
64
|
-
template: supportsTemplateMode && isViewable && canViewTemplate && currentPost.postType !== 'wp_template' ? getEditedPostTemplate() : null,
|
|
65
|
-
post: postObject
|
|
66
|
-
};
|
|
67
|
-
}, [currentPost.postType, currentPost.postId]);
|
|
68
|
-
const editorSettings = (0, _element.useMemo)(() => ({
|
|
69
|
-
...settings,
|
|
70
|
-
onNavigateToEntityRecord,
|
|
71
|
-
onNavigateToPreviousEntityRecord,
|
|
72
|
-
defaultRenderingMode: 'post-only'
|
|
73
|
-
}), [settings, onNavigateToEntityRecord, onNavigateToPreviousEntityRecord]);
|
|
74
|
-
const initialPost = (0, _element.useMemo)(() => {
|
|
75
|
-
return {
|
|
76
|
-
type: initialPostType,
|
|
77
|
-
id: initialPostId
|
|
78
|
-
};
|
|
79
|
-
}, [initialPostType, initialPostId]);
|
|
80
|
-
if (!post) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.SlotFillProvider, {
|
|
84
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(ExperimentalEditorProvider, {
|
|
85
|
-
settings: editorSettings,
|
|
86
|
-
post: post,
|
|
87
|
-
initialEdits: initialEdits,
|
|
88
|
-
useSubRegistry: false,
|
|
89
|
-
__unstableTemplate: template,
|
|
90
|
-
...props,
|
|
91
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_editor.ErrorBoundary, {
|
|
92
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_commands.CommandMenu, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_editorInitialization.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_layout.default, {
|
|
93
|
-
initialPost: initialPost
|
|
94
|
-
})]
|
|
95
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_editor.PostLockedModal, {})]
|
|
96
|
-
})
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
var _default = exports.default = Editor;
|
|
100
|
-
//# sourceMappingURL=editor.js.map
|