@wordpress/edit-post 7.27.2 → 7.28.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/block-settings-menu/plugin-block-settings-menu-item.js +1 -2
- package/build/components/block-settings-menu/plugin-block-settings-menu-item.js.map +1 -1
- package/build/components/browser-url/index.js +1 -2
- package/build/components/browser-url/index.js.map +1 -1
- package/build/components/header/fullscreen-mode-close/index.js +11 -8
- package/build/components/header/fullscreen-mode-close/index.js.map +1 -1
- package/build/components/header/header-toolbar/index.native.js +1 -2
- package/build/components/header/header-toolbar/index.native.js.map +1 -1
- package/build/components/header/index.js +6 -5
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/main-dashboard-button/index.js +1 -2
- package/build/components/header/main-dashboard-button/index.js.map +1 -1
- package/build/components/header/mode-switcher/index.js +1 -2
- package/build/components/header/mode-switcher/index.js.map +1 -1
- package/build/components/header/more-menu/index.js +1 -2
- package/build/components/header/more-menu/index.js.map +1 -1
- package/build/components/header/plugin-more-menu-item/index.js +1 -2
- package/build/components/header/plugin-more-menu-item/index.js.map +1 -1
- package/build/components/header/post-publish-button-or-toggle.js +1 -2
- package/build/components/header/post-publish-button-or-toggle.js.map +1 -1
- package/build/components/header/tools-more-menu-group/index.js +1 -2
- package/build/components/header/tools-more-menu-group/index.js.map +1 -1
- package/build/components/header/writing-menu/index.js +4 -18
- package/build/components/header/writing-menu/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +1 -2
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -2
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +2 -5
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +1 -2
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -2
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/layout/actions-panel.js +1 -2
- package/build/components/layout/actions-panel.js.map +1 -1
- package/build/components/layout/index.js +7 -5
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/index.native.js +1 -2
- package/build/components/layout/index.native.js.map +1 -1
- package/build/components/meta-boxes/meta-box-visibility.js +1 -2
- package/build/components/meta-boxes/meta-box-visibility.js.map +1 -1
- package/build/components/meta-boxes/meta-boxes-area/index.js +1 -2
- package/build/components/meta-boxes/meta-boxes-area/index.js.map +1 -1
- package/build/components/preferences-modal/enable-custom-fields.js +1 -2
- package/build/components/preferences-modal/enable-custom-fields.js.map +1 -1
- package/build/components/preferences-modal/enable-panel.js +1 -2
- package/build/components/preferences-modal/enable-panel.js.map +1 -1
- package/build/components/preferences-modal/enable-publish-sidebar.js +1 -2
- package/build/components/preferences-modal/enable-publish-sidebar.js.map +1 -1
- package/build/components/preferences-modal/index.js +1 -2
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/preferences-modal/meta-boxes-section.js +1 -2
- package/build/components/preferences-modal/meta-boxes-section.js.map +1 -1
- package/build/components/sidebar/plugin-document-setting-panel/index.js +1 -2
- package/build/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
- package/build/components/sidebar/plugin-post-publish-panel/index.js +1 -2
- package/build/components/sidebar/plugin-post-publish-panel/index.js.map +1 -1
- package/build/components/sidebar/plugin-post-status-info/index.js +1 -2
- package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
- package/build/components/sidebar/plugin-pre-publish-panel/index.js +1 -2
- package/build/components/sidebar/plugin-pre-publish-panel/index.js.map +1 -1
- package/build/components/sidebar/post-format/index.js +1 -2
- package/build/components/sidebar/post-format/index.js.map +1 -1
- package/build/components/sidebar/post-pending-status/index.js +1 -2
- package/build/components/sidebar/post-pending-status/index.js.map +1 -1
- package/build/components/sidebar/post-slug/index.js +1 -2
- package/build/components/sidebar/post-slug/index.js.map +1 -1
- package/build/components/sidebar/post-sticky/index.js +1 -2
- package/build/components/sidebar/post-sticky/index.js.map +1 -1
- package/build/components/sidebar/post-visibility/index.js +2 -2
- package/build/components/sidebar/post-visibility/index.js.map +1 -1
- package/build/components/sidebar/settings-header/index.js +12 -4
- package/build/components/sidebar/settings-header/index.js.map +1 -1
- package/build/components/sidebar/settings-sidebar/index.js +28 -6
- package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build/components/sidebar/template-summary/index.js +1 -2
- package/build/components/sidebar/template-summary/index.js.map +1 -1
- package/build/components/visual-editor/block-inspector-button.js +1 -2
- package/build/components/visual-editor/block-inspector-button.js.map +1 -1
- package/build/components/visual-editor/header.native.js +1 -2
- package/build/components/visual-editor/header.native.js.map +1 -1
- package/build/editor.js +32 -21
- package/build/editor.js.map +1 -1
- package/build/editor.native.js +1 -2
- package/build/editor.native.js.map +1 -1
- package/build/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +20 -26
- package/build/hooks/use-navigate-to-entity-record.js.map +1 -0
- package/build/hooks/validate-multiple-use/index.js +25 -4
- package/build/hooks/validate-multiple-use/index.js.map +1 -1
- package/build/plugins/keyboard-shortcuts-help-menu-item/index.js +1 -2
- package/build/plugins/keyboard-shortcuts-help-menu-item/index.js.map +1 -1
- package/build/store/actions.js +7 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/constants.js +3 -6
- package/build/store/constants.js.map +1 -1
- package/build/store/index.js +3 -4
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +1 -2
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +21 -42
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/header/fullscreen-mode-close/index.js +10 -6
- package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
- package/build-module/components/header/index.js +5 -3
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/writing-menu/index.js +4 -17
- package/build-module/components/header/writing-menu/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +0 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/layout/index.js +6 -3
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/sidebar/post-visibility/index.js +1 -0
- package/build-module/components/sidebar/post-visibility/index.js.map +1 -1
- package/build-module/components/sidebar/settings-header/index.js +12 -3
- package/build-module/components/sidebar/settings-header/index.js.map +1 -1
- package/build-module/components/sidebar/settings-sidebar/index.js +27 -3
- package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build-module/editor.js +31 -19
- package/build-module/editor.js.map +1 -1
- package/build-module/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +20 -26
- package/build-module/hooks/use-navigate-to-entity-record.js.map +1 -0
- package/build-module/hooks/validate-multiple-use/index.js +26 -4
- package/build-module/hooks/validate-multiple-use/index.js.map +1 -1
- package/build-module/store/actions.js +7 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-style/style-rtl.css +29 -22
- package/build-style/style.css +29 -22
- package/package.json +32 -32
- package/src/components/header/fullscreen-mode-close/index.js +13 -10
- package/src/components/header/fullscreen-mode-close/test/index.js +31 -5
- package/src/components/header/index.js +8 -3
- package/src/components/header/style.scss +40 -26
- package/src/components/header/writing-menu/index.js +3 -16
- package/src/components/layout/index.js +3 -2
- package/src/components/sidebar/post-visibility/index.js +1 -0
- package/src/components/sidebar/settings-header/index.js +16 -5
- package/src/components/sidebar/settings-sidebar/index.js +37 -2
- package/src/components/visual-editor/style.scss +1 -1
- package/src/editor.js +34 -21
- package/src/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +23 -27
- package/src/hooks/validate-multiple-use/index.js +28 -3
- package/src/store/actions.js +20 -3
- package/src/style.scss +0 -1
- package/src/test/editor.native.js +8 -5
- package/build/hooks/use-post-history.js.map +0 -1
- package/build-module/hooks/use-post-history.js.map +0 -1
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// Gray preview overlay (desktop/tablet/mobile) is intentionally not set on an element with scrolling content like
|
|
12
12
|
// interface-interface-skeleton__content. This causes graphical glitches (flashes of the background color)
|
|
13
13
|
// when scrolling in Safari due to incorrect ordering of large compositing layers (GPU acceleration).
|
|
14
|
-
background-color: $gray-
|
|
14
|
+
background-color: $gray-300;
|
|
15
15
|
|
|
16
16
|
// The button element easily inherits styles that are meant for the editor style.
|
|
17
17
|
// These rules enhance the specificity to reduce that inheritance.
|
package/src/editor.js
CHANGED
|
@@ -13,6 +13,8 @@ import { SlotFillProvider } from '@wordpress/components';
|
|
|
13
13
|
import { store as coreStore } from '@wordpress/core-data';
|
|
14
14
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
15
15
|
import { CommandMenu } from '@wordpress/commands';
|
|
16
|
+
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
17
|
+
import { __ } from '@wordpress/i18n';
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Internal dependencies
|
|
@@ -21,9 +23,17 @@ import Layout from './components/layout';
|
|
|
21
23
|
import EditorInitialization from './components/editor-initialization';
|
|
22
24
|
import { store as editPostStore } from './store';
|
|
23
25
|
import { unlock } from './lock-unlock';
|
|
24
|
-
import
|
|
26
|
+
import useNavigateToEntityRecord from './hooks/use-navigate-to-entity-record';
|
|
25
27
|
|
|
26
28
|
const { ExperimentalEditorProvider } = unlock( editorPrivateApis );
|
|
29
|
+
const { BlockRemovalWarningModal } = unlock( blockEditorPrivateApis );
|
|
30
|
+
// Prevent accidental removal of certain blocks, asking the user for
|
|
31
|
+
// confirmation.
|
|
32
|
+
const blockRemovalRules = {
|
|
33
|
+
'bindings/core/pattern-overrides': __(
|
|
34
|
+
'Blocks from synced patterns that can have overriden content.'
|
|
35
|
+
),
|
|
36
|
+
};
|
|
27
37
|
|
|
28
38
|
function Editor( {
|
|
29
39
|
postId: initialPostId,
|
|
@@ -32,10 +42,12 @@ function Editor( {
|
|
|
32
42
|
initialEdits,
|
|
33
43
|
...props
|
|
34
44
|
} ) {
|
|
35
|
-
const {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
const {
|
|
46
|
+
initialPost,
|
|
47
|
+
currentPost,
|
|
48
|
+
onNavigateToEntityRecord,
|
|
49
|
+
onNavigateToPreviousEntityRecord,
|
|
50
|
+
} = useNavigateToEntityRecord( initialPostId, initialPostType );
|
|
39
51
|
|
|
40
52
|
const { hasInlineToolbar, post, preferredStyleVariations, template } =
|
|
41
53
|
useSelect(
|
|
@@ -80,28 +92,28 @@ function Editor( {
|
|
|
80
92
|
const defaultRenderingMode =
|
|
81
93
|
currentPost.postType === 'wp_template' ? 'all' : 'post-only';
|
|
82
94
|
|
|
83
|
-
const editorSettings = useMemo(
|
|
84
|
-
|
|
95
|
+
const editorSettings = useMemo(
|
|
96
|
+
() => ( {
|
|
85
97
|
...settings,
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
onNavigateToEntityRecord,
|
|
99
|
+
onNavigateToPreviousEntityRecord,
|
|
88
100
|
defaultRenderingMode,
|
|
89
101
|
__experimentalPreferredStyleVariations: {
|
|
90
102
|
value: preferredStyleVariations,
|
|
91
103
|
onChange: updatePreferredStyleVariations,
|
|
92
104
|
},
|
|
93
105
|
hasInlineToolbar,
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
} ),
|
|
107
|
+
[
|
|
108
|
+
settings,
|
|
109
|
+
hasInlineToolbar,
|
|
110
|
+
preferredStyleVariations,
|
|
111
|
+
updatePreferredStyleVariations,
|
|
112
|
+
onNavigateToEntityRecord,
|
|
113
|
+
onNavigateToPreviousEntityRecord,
|
|
114
|
+
defaultRenderingMode,
|
|
115
|
+
]
|
|
116
|
+
);
|
|
105
117
|
|
|
106
118
|
if ( ! post ) {
|
|
107
119
|
return null;
|
|
@@ -120,7 +132,8 @@ function Editor( {
|
|
|
120
132
|
<ErrorBoundary>
|
|
121
133
|
<CommandMenu />
|
|
122
134
|
<EditorInitialization postId={ currentPost.postId } />
|
|
123
|
-
<Layout />
|
|
135
|
+
<Layout initialPost={ initialPost } />
|
|
136
|
+
<BlockRemovalWarningModal rules={ blockRemovalRules } />
|
|
124
137
|
</ErrorBoundary>
|
|
125
138
|
<PostLockedModal />
|
|
126
139
|
</ExperimentalEditorProvider>
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { useCallback, useReducer } from '@wordpress/element';
|
|
5
|
-
import { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';
|
|
4
|
+
import { useCallback, useReducer, useMemo } from '@wordpress/element';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* A hook that records the 'entity' history in the post editor as a user
|
|
@@ -16,9 +15,12 @@ import { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';
|
|
|
16
15
|
* @param {string} initialPostType The post type of the post when the editor loaded.
|
|
17
16
|
*
|
|
18
17
|
* @return {Object} An object containing the `currentPost` variable and
|
|
19
|
-
* `
|
|
18
|
+
* `onNavigateToEntityRecord` and `onNavigateToPreviousEntityRecord` functions.
|
|
20
19
|
*/
|
|
21
|
-
export default function
|
|
20
|
+
export default function useNavigateToEntityRecord(
|
|
21
|
+
initialPostId,
|
|
22
|
+
initialPostType
|
|
23
|
+
) {
|
|
22
24
|
const [ postHistory, dispatch ] = useReducer(
|
|
23
25
|
( historyState, { type, post } ) => {
|
|
24
26
|
if ( type === 'push' ) {
|
|
@@ -35,31 +37,21 @@ export default function usePostHistory( initialPostId, initialPostType ) {
|
|
|
35
37
|
[ { postId: initialPostId, postType: initialPostType } ]
|
|
36
38
|
);
|
|
37
39
|
|
|
38
|
-
const
|
|
39
|
-
const currentArgs = getQueryArgs( window.location.href );
|
|
40
|
-
const currentUrlWithoutArgs = removeQueryArgs(
|
|
41
|
-
window.location.href,
|
|
42
|
-
...Object.keys( currentArgs )
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const newUrl = addQueryArgs( currentUrlWithoutArgs, {
|
|
46
|
-
post: params.postId,
|
|
47
|
-
action: 'edit',
|
|
48
|
-
} );
|
|
49
|
-
|
|
40
|
+
const initialPost = useMemo( () => {
|
|
50
41
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
event?.preventDefault();
|
|
54
|
-
dispatch( {
|
|
55
|
-
type: 'push',
|
|
56
|
-
post: { postId: params.postId, postType: params.postType },
|
|
57
|
-
} );
|
|
58
|
-
},
|
|
42
|
+
type: initialPostType,
|
|
43
|
+
id: initialPostId,
|
|
59
44
|
};
|
|
45
|
+
}, [ initialPostType, initialPostId ] );
|
|
46
|
+
|
|
47
|
+
const onNavigateToEntityRecord = useCallback( ( params ) => {
|
|
48
|
+
dispatch( {
|
|
49
|
+
type: 'push',
|
|
50
|
+
post: { postId: params.postId, postType: params.postType },
|
|
51
|
+
} );
|
|
60
52
|
}, [] );
|
|
61
53
|
|
|
62
|
-
const
|
|
54
|
+
const onNavigateToPreviousEntityRecord = useCallback( () => {
|
|
63
55
|
dispatch( { type: 'pop' } );
|
|
64
56
|
}, [] );
|
|
65
57
|
|
|
@@ -67,7 +59,11 @@ export default function usePostHistory( initialPostId, initialPostType ) {
|
|
|
67
59
|
|
|
68
60
|
return {
|
|
69
61
|
currentPost,
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
initialPost,
|
|
63
|
+
onNavigateToEntityRecord,
|
|
64
|
+
onNavigateToPreviousEntityRecord:
|
|
65
|
+
postHistory.length > 1
|
|
66
|
+
? onNavigateToPreviousEntityRecord
|
|
67
|
+
: undefined,
|
|
72
68
|
};
|
|
73
69
|
}
|
|
@@ -15,6 +15,33 @@ import { addFilter } from '@wordpress/hooks';
|
|
|
15
15
|
import { __ } from '@wordpress/i18n';
|
|
16
16
|
import { compose, createHigherOrderComponent } from '@wordpress/compose';
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Recursively find very first block of an specific block type.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object[]} blocks List of blocks.
|
|
22
|
+
* @param {string} name Block name to search.
|
|
23
|
+
*
|
|
24
|
+
* @return {Object|undefined} Return block object or undefined.
|
|
25
|
+
*/
|
|
26
|
+
function findFirstOfSameType( blocks, name ) {
|
|
27
|
+
if ( ! Array.isArray( blocks ) || ! blocks.length ) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for ( const block of blocks ) {
|
|
32
|
+
if ( block.name === name ) {
|
|
33
|
+
return block;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Search inside innerBlocks.
|
|
37
|
+
const firstBlock = findFirstOfSameType( block.innerBlocks, name );
|
|
38
|
+
|
|
39
|
+
if ( firstBlock ) {
|
|
40
|
+
return firstBlock;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
18
45
|
const enhance = compose(
|
|
19
46
|
/**
|
|
20
47
|
* For blocks whose block type doesn't support `multiple`, provides the
|
|
@@ -39,9 +66,7 @@ const enhance = compose(
|
|
|
39
66
|
// Otherwise, only pass `originalBlockClientId` if it refers to a different
|
|
40
67
|
// block from the current one.
|
|
41
68
|
const blocks = select( blockEditorStore ).getBlocks();
|
|
42
|
-
const firstOfSameType = blocks.
|
|
43
|
-
( { name } ) => block.name === name
|
|
44
|
-
);
|
|
69
|
+
const firstOfSameType = findFirstOfSameType( blocks, block.name );
|
|
45
70
|
const isInvalid =
|
|
46
71
|
firstOfSameType && firstOfSameType.clientId !== block.clientId;
|
|
47
72
|
return {
|
package/src/store/actions.js
CHANGED
|
@@ -541,6 +541,11 @@ export const toggleDistractionFree =
|
|
|
541
541
|
const isDistractionFree = registry
|
|
542
542
|
.select( preferencesStore )
|
|
543
543
|
.get( 'core', 'distractionFree' );
|
|
544
|
+
if ( isDistractionFree ) {
|
|
545
|
+
registry
|
|
546
|
+
.dispatch( preferencesStore )
|
|
547
|
+
.set( 'core', 'fixedToolbar', false );
|
|
548
|
+
}
|
|
544
549
|
if ( ! isDistractionFree ) {
|
|
545
550
|
registry.batch( () => {
|
|
546
551
|
registry
|
|
@@ -568,9 +573,21 @@ export const toggleDistractionFree =
|
|
|
568
573
|
{
|
|
569
574
|
label: __( 'Undo' ),
|
|
570
575
|
onClick: () => {
|
|
571
|
-
registry
|
|
572
|
-
|
|
573
|
-
|
|
576
|
+
registry.batch( () => {
|
|
577
|
+
registry
|
|
578
|
+
.dispatch( preferencesStore )
|
|
579
|
+
.set(
|
|
580
|
+
'core',
|
|
581
|
+
'fixedToolbar',
|
|
582
|
+
isDistractionFree ? true : false
|
|
583
|
+
);
|
|
584
|
+
registry
|
|
585
|
+
.dispatch( preferencesStore )
|
|
586
|
+
.toggle(
|
|
587
|
+
'core',
|
|
588
|
+
'distractionFree'
|
|
589
|
+
);
|
|
590
|
+
} );
|
|
574
591
|
},
|
|
575
592
|
},
|
|
576
593
|
],
|
package/src/style.scss
CHANGED
|
@@ -103,8 +103,10 @@ describe( 'Editor', () => {
|
|
|
103
103
|
await initializeEditor();
|
|
104
104
|
|
|
105
105
|
// Act
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
|
|
107
|
+
act( () => mediaAppendCallback( MEDIA[ 2 ] ) );
|
|
108
|
+
await screen.findByTestId( `network-image-${ MEDIA[ 0 ].serverUrl }` );
|
|
109
|
+
await screen.findByTestId( `network-image-${ MEDIA[ 2 ].serverUrl }` );
|
|
108
110
|
|
|
109
111
|
// Assert
|
|
110
112
|
expect( getEditorHtml() ).toMatchSnapshot();
|
|
@@ -122,10 +124,11 @@ describe( 'Editor', () => {
|
|
|
122
124
|
await initializeEditor();
|
|
123
125
|
|
|
124
126
|
// Act
|
|
125
|
-
|
|
127
|
+
act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
|
|
126
128
|
// Unsupported type (PDF file)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
act( () => mediaAppendCallback( MEDIA[ 1 ] ) );
|
|
130
|
+
act( () => mediaAppendCallback( MEDIA[ 3 ] ) );
|
|
131
|
+
await screen.findByTestId( `network-image-${ MEDIA[ 0 ].serverUrl }` );
|
|
129
132
|
|
|
130
133
|
// Assert
|
|
131
134
|
expect( getEditorHtml() ).toMatchSnapshot();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_url","usePostHistory","initialPostId","initialPostType","postHistory","dispatch","useReducer","historyState","type","post","length","slice","postId","postType","getPostLinkProps","useCallback","params","currentArgs","getQueryArgs","window","location","href","currentUrlWithoutArgs","removeQueryArgs","Object","keys","newUrl","addQueryArgs","action","onClick","event","preventDefault","goBack","currentPost","undefined"],"sources":["@wordpress/edit-post/src/hooks/use-post-history.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useReducer } from '@wordpress/element';\nimport { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';\n\n/**\n * A hook that records the 'entity' history in the post editor as a user\n * navigates between editing a post and editing the post template or patterns.\n *\n * Implemented as a stack, so a little similar to the browser history API.\n *\n * Used to control displaying UI elements like the back button.\n *\n * @param {number} initialPostId The post id of the post when the editor loaded.\n * @param {string} initialPostType The post type of the post when the editor loaded.\n *\n * @return {Object} An object containing the `currentPost` variable and\n * `getPostLinkProps` and `goBack` functions.\n */\nexport default function usePostHistory( initialPostId, initialPostType ) {\n\tconst [ postHistory, dispatch ] = useReducer(\n\t\t( historyState, { type, post } ) => {\n\t\t\tif ( type === 'push' ) {\n\t\t\t\treturn [ ...historyState, post ];\n\t\t\t}\n\t\t\tif ( type === 'pop' ) {\n\t\t\t\t// Try to leave one item in the history.\n\t\t\t\tif ( historyState.length > 1 ) {\n\t\t\t\t\treturn historyState.slice( 0, -1 );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn historyState;\n\t\t},\n\t\t[ { postId: initialPostId, postType: initialPostType } ]\n\t);\n\n\tconst getPostLinkProps = useCallback( ( params ) => {\n\t\tconst currentArgs = getQueryArgs( window.location.href );\n\t\tconst currentUrlWithoutArgs = removeQueryArgs(\n\t\t\twindow.location.href,\n\t\t\t...Object.keys( currentArgs )\n\t\t);\n\n\t\tconst newUrl = addQueryArgs( currentUrlWithoutArgs, {\n\t\t\tpost: params.postId,\n\t\t\taction: 'edit',\n\t\t} );\n\n\t\treturn {\n\t\t\thref: newUrl,\n\t\t\tonClick: ( event ) => {\n\t\t\t\tevent?.preventDefault();\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'push',\n\t\t\t\t\tpost: { postId: params.postId, postType: params.postType },\n\t\t\t\t} );\n\t\t\t},\n\t\t};\n\t}, [] );\n\n\tconst goBack = useCallback( () => {\n\t\tdispatch( { type: 'pop' } );\n\t}, [] );\n\n\tconst currentPost = postHistory[ postHistory.length - 1 ];\n\n\treturn {\n\t\tcurrentPost,\n\t\tgetPostLinkProps,\n\t\tgoBack: postHistory.length > 1 ? goBack : undefined,\n\t};\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASE,cAAcA,CAAEC,aAAa,EAAEC,eAAe,EAAG;EACxE,MAAM,CAAEC,WAAW,EAAEC,QAAQ,CAAE,GAAG,IAAAC,mBAAU,EAC3C,CAAEC,YAAY,EAAE;IAAEC,IAAI;IAAEC;EAAK,CAAC,KAAM;IACnC,IAAKD,IAAI,KAAK,MAAM,EAAG;MACtB,OAAO,CAAE,GAAGD,YAAY,EAAEE,IAAI,CAAE;IACjC;IACA,IAAKD,IAAI,KAAK,KAAK,EAAG;MACrB;MACA,IAAKD,YAAY,CAACG,MAAM,GAAG,CAAC,EAA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MAAM,GAAG,CAAC,GAAGsB,MAAM,GAAGE;EAC3C,CAAC;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useReducer","addQueryArgs","getQueryArgs","removeQueryArgs","usePostHistory","initialPostId","initialPostType","postHistory","dispatch","historyState","type","post","length","slice","postId","postType","getPostLinkProps","params","currentArgs","window","location","href","currentUrlWithoutArgs","Object","keys","newUrl","action","onClick","event","preventDefault","goBack","currentPost","undefined"],"sources":["@wordpress/edit-post/src/hooks/use-post-history.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useReducer } from '@wordpress/element';\nimport { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';\n\n/**\n * A hook that records the 'entity' history in the post editor as a user\n * navigates between editing a post and editing the post template or patterns.\n *\n * Implemented as a stack, so a little similar to the browser history API.\n *\n * Used to control displaying UI elements like the back button.\n *\n * @param {number} initialPostId The post id of the post when the editor loaded.\n * @param {string} initialPostType The post type of the post when the editor loaded.\n *\n * @return {Object} An object containing the `currentPost` variable and\n * `getPostLinkProps` and `goBack` functions.\n */\nexport default function usePostHistory( initialPostId, initialPostType ) {\n\tconst [ postHistory, dispatch ] = useReducer(\n\t\t( historyState, { type, post } ) => {\n\t\t\tif ( type === 'push' ) {\n\t\t\t\treturn [ ...historyState, post ];\n\t\t\t}\n\t\t\tif ( type === 'pop' ) {\n\t\t\t\t// Try to leave one item in the history.\n\t\t\t\tif ( historyState.length > 1 ) {\n\t\t\t\t\treturn historyState.slice( 0, -1 );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn historyState;\n\t\t},\n\t\t[ { postId: initialPostId, postType: initialPostType } ]\n\t);\n\n\tconst getPostLinkProps = useCallback( ( params ) => {\n\t\tconst currentArgs = getQueryArgs( window.location.href );\n\t\tconst currentUrlWithoutArgs = removeQueryArgs(\n\t\t\twindow.location.href,\n\t\t\t...Object.keys( currentArgs )\n\t\t);\n\n\t\tconst newUrl = addQueryArgs( currentUrlWithoutArgs, {\n\t\t\tpost: params.postId,\n\t\t\taction: 'edit',\n\t\t} );\n\n\t\treturn {\n\t\t\thref: newUrl,\n\t\t\tonClick: ( event ) => {\n\t\t\t\tevent?.preventDefault();\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'push',\n\t\t\t\t\tpost: { postId: params.postId, postType: params.postType },\n\t\t\t\t} );\n\t\t\t},\n\t\t};\n\t}, [] );\n\n\tconst goBack = useCallback( () => {\n\t\tdispatch( { type: 'pop' } );\n\t}, [] );\n\n\tconst currentPost = postHistory[ postHistory.length - 1 ];\n\n\treturn {\n\t\tcurrentPost,\n\t\tgetPostLinkProps,\n\t\tgoBack: postHistory.length > 1 ? goBack : undefined,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,UAAU,QAAQ,oBAAoB;AAC5D,SAASC,YAAY,EAAEC,YAAY,EAAEC,eAAe,QAAQ,gBAAgB;;AAE5E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,cAAcA,CAAEC,aAAa,EAAEC,eAAe,EAAG;EACxE,MAAM,CAAEC,WAAW,EAAEC,QAAQ,CAAE,GAAGR,UAAU,CAC3C,CAAES,YAAY,EAAE;IAAEC,IAAI;IAAEC;EAAK,CAAC,KAAM;IACnC,IAAKD,IAAI,KAAK,MAAM,EAAG;MACtB,OAAO,CAAE,GAAGD,YAAY,EAAEE,IAAI,CAAE;IACjC;IACA,IAAKD,IAAI,KAAK,KAAK,EAAG;MACrB;MACA,IAAKD,YAAY,CAACG,MAAM,GAAG,CAAC,EAAG;QAC9B,OAAOH,YAAY,CAACI,KAAK,CAAE,CAAC,EAAE,CAAC,CAAE,CAAC;MACnC;IACD;IACA,OAAOJ,YAAY;EACpB,CAAC,EACD,CAAE;IAAEK,MAAM,EAAET,aAAa;IAAEU,QAAQ,EAAET;EAAgB,CAAC,CACvD,CAAC;EAED,MAAMU,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