@wordpress/edit-post 7.27.1 → 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 +8 -9
- 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 -7
- 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 +16 -11
- package/build/components/sidebar/settings-header/index.js.map +1 -1
- package/build/components/sidebar/settings-sidebar/index.js +34 -12
- package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build/components/sidebar/template-summary/index.js +5 -10
- 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/components/visual-editor/index.js +5 -4
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/components/welcome-guide/index.js +6 -6
- package/build/components/welcome-guide/index.js.map +1 -1
- package/build/editor.js +35 -34
- 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/plugins/welcome-guide-menu-item/index.js +2 -2
- package/build/plugins/welcome-guide-menu-item/index.js.map +1 -1
- package/build/store/actions.js +8 -12
- 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 +7 -7
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/mode-switcher/index.js +0 -5
- package/build-module/components/header/mode-switcher/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 +16 -10
- package/build-module/components/sidebar/settings-header/index.js.map +1 -1
- package/build-module/components/sidebar/settings-sidebar/index.js +33 -9
- package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/template-summary/index.js +4 -8
- package/build-module/components/sidebar/template-summary/index.js.map +1 -1
- package/build-module/components/visual-editor/index.js +5 -4
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/components/welcome-guide/index.js +6 -6
- package/build-module/components/welcome-guide/index.js.map +1 -1
- package/build-module/editor.js +34 -32
- 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/plugins/welcome-guide-menu-item/index.js +2 -2
- package/build-module/plugins/welcome-guide-menu-item/index.js.map +1 -1
- package/build-module/store/actions.js +7 -10
- 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 +10 -8
- package/src/components/header/mode-switcher/index.js +16 -25
- 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 +17 -9
- package/src/components/sidebar/settings-sidebar/index.js +44 -9
- package/src/components/sidebar/template-summary/index.js +3 -7
- package/src/components/visual-editor/index.js +4 -2
- package/src/components/visual-editor/style.scss +1 -1
- package/src/components/welcome-guide/index.js +11 -6
- package/src/editor.js +50 -50
- 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/plugins/welcome-guide-menu-item/index.js +3 -3
- package/src/store/actions.js +20 -12
- 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
|
@@ -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 {
|
|
@@ -7,16 +7,16 @@ import { __ } from '@wordpress/i18n';
|
|
|
7
7
|
import { store as editorStore } from '@wordpress/editor';
|
|
8
8
|
|
|
9
9
|
export default function WelcomeGuideMenuItem() {
|
|
10
|
-
const
|
|
10
|
+
const isEditingTemplate = useSelect(
|
|
11
11
|
( select ) =>
|
|
12
|
-
select( editorStore ).
|
|
12
|
+
select( editorStore ).getCurrentPostType() === 'wp_template',
|
|
13
13
|
[]
|
|
14
14
|
);
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
17
|
<PreferenceToggleMenuItem
|
|
18
18
|
scope="core/edit-post"
|
|
19
|
-
name={
|
|
19
|
+
name={ isEditingTemplate ? 'welcomeGuideTemplate' : 'welcomeGuide' }
|
|
20
20
|
label={ __( 'Welcome Guide' ) }
|
|
21
21
|
/>
|
|
22
22
|
);
|
package/src/store/actions.js
CHANGED
|
@@ -469,15 +469,6 @@ export function setIsEditingTemplate() {
|
|
|
469
469
|
return { type: 'NOTHING' };
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
-
/**
|
|
473
|
-
* Switches to the template mode.
|
|
474
|
-
*/
|
|
475
|
-
export const __unstableSwitchToTemplateMode =
|
|
476
|
-
() =>
|
|
477
|
-
( { registry } ) => {
|
|
478
|
-
registry.dispatch( editorStore ).setRenderingMode( 'template-only' );
|
|
479
|
-
};
|
|
480
|
-
|
|
481
472
|
/**
|
|
482
473
|
* Create a block based template.
|
|
483
474
|
*
|
|
@@ -550,6 +541,11 @@ export const toggleDistractionFree =
|
|
|
550
541
|
const isDistractionFree = registry
|
|
551
542
|
.select( preferencesStore )
|
|
552
543
|
.get( 'core', 'distractionFree' );
|
|
544
|
+
if ( isDistractionFree ) {
|
|
545
|
+
registry
|
|
546
|
+
.dispatch( preferencesStore )
|
|
547
|
+
.set( 'core', 'fixedToolbar', false );
|
|
548
|
+
}
|
|
553
549
|
if ( ! isDistractionFree ) {
|
|
554
550
|
registry.batch( () => {
|
|
555
551
|
registry
|
|
@@ -577,9 +573,21 @@ export const toggleDistractionFree =
|
|
|
577
573
|
{
|
|
578
574
|
label: __( 'Undo' ),
|
|
579
575
|
onClick: () => {
|
|
580
|
-
registry
|
|
581
|
-
|
|
582
|
-
|
|
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
|
+
} );
|
|
583
591
|
},
|
|
584
592
|
},
|
|
585
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,EAAG;QAC9B,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,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,gBAAgB,GAA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