@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.
Files changed (169) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-settings-menu/plugin-block-settings-menu-item.js +1 -2
  3. package/build/components/block-settings-menu/plugin-block-settings-menu-item.js.map +1 -1
  4. package/build/components/browser-url/index.js +1 -2
  5. package/build/components/browser-url/index.js.map +1 -1
  6. package/build/components/header/fullscreen-mode-close/index.js +11 -8
  7. package/build/components/header/fullscreen-mode-close/index.js.map +1 -1
  8. package/build/components/header/header-toolbar/index.native.js +1 -2
  9. package/build/components/header/header-toolbar/index.native.js.map +1 -1
  10. package/build/components/header/index.js +8 -9
  11. package/build/components/header/index.js.map +1 -1
  12. package/build/components/header/main-dashboard-button/index.js +1 -2
  13. package/build/components/header/main-dashboard-button/index.js.map +1 -1
  14. package/build/components/header/mode-switcher/index.js +1 -7
  15. package/build/components/header/mode-switcher/index.js.map +1 -1
  16. package/build/components/header/more-menu/index.js +1 -2
  17. package/build/components/header/more-menu/index.js.map +1 -1
  18. package/build/components/header/plugin-more-menu-item/index.js +1 -2
  19. package/build/components/header/plugin-more-menu-item/index.js.map +1 -1
  20. package/build/components/header/post-publish-button-or-toggle.js +1 -2
  21. package/build/components/header/post-publish-button-or-toggle.js.map +1 -1
  22. package/build/components/header/tools-more-menu-group/index.js +1 -2
  23. package/build/components/header/tools-more-menu-group/index.js.map +1 -1
  24. package/build/components/header/writing-menu/index.js +4 -18
  25. package/build/components/header/writing-menu/index.js.map +1 -1
  26. package/build/components/keyboard-shortcut-help-modal/config.js +1 -2
  27. package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  28. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -2
  29. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
  30. package/build/components/keyboard-shortcut-help-modal/index.js +2 -5
  31. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  32. package/build/components/keyboard-shortcut-help-modal/shortcut.js +1 -2
  33. package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
  34. package/build/components/keyboard-shortcuts/index.js +1 -2
  35. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  36. package/build/components/layout/actions-panel.js +1 -2
  37. package/build/components/layout/actions-panel.js.map +1 -1
  38. package/build/components/layout/index.js +7 -5
  39. package/build/components/layout/index.js.map +1 -1
  40. package/build/components/layout/index.native.js +1 -2
  41. package/build/components/layout/index.native.js.map +1 -1
  42. package/build/components/meta-boxes/meta-box-visibility.js +1 -2
  43. package/build/components/meta-boxes/meta-box-visibility.js.map +1 -1
  44. package/build/components/meta-boxes/meta-boxes-area/index.js +1 -2
  45. package/build/components/meta-boxes/meta-boxes-area/index.js.map +1 -1
  46. package/build/components/preferences-modal/enable-custom-fields.js +1 -2
  47. package/build/components/preferences-modal/enable-custom-fields.js.map +1 -1
  48. package/build/components/preferences-modal/enable-panel.js +1 -2
  49. package/build/components/preferences-modal/enable-panel.js.map +1 -1
  50. package/build/components/preferences-modal/enable-publish-sidebar.js +1 -2
  51. package/build/components/preferences-modal/enable-publish-sidebar.js.map +1 -1
  52. package/build/components/preferences-modal/index.js +1 -2
  53. package/build/components/preferences-modal/index.js.map +1 -1
  54. package/build/components/preferences-modal/meta-boxes-section.js +1 -2
  55. package/build/components/preferences-modal/meta-boxes-section.js.map +1 -1
  56. package/build/components/sidebar/plugin-document-setting-panel/index.js +1 -2
  57. package/build/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
  58. package/build/components/sidebar/plugin-post-publish-panel/index.js +1 -2
  59. package/build/components/sidebar/plugin-post-publish-panel/index.js.map +1 -1
  60. package/build/components/sidebar/plugin-post-status-info/index.js +1 -2
  61. package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  62. package/build/components/sidebar/plugin-pre-publish-panel/index.js +1 -2
  63. package/build/components/sidebar/plugin-pre-publish-panel/index.js.map +1 -1
  64. package/build/components/sidebar/post-format/index.js +1 -2
  65. package/build/components/sidebar/post-format/index.js.map +1 -1
  66. package/build/components/sidebar/post-pending-status/index.js +1 -2
  67. package/build/components/sidebar/post-pending-status/index.js.map +1 -1
  68. package/build/components/sidebar/post-slug/index.js +1 -2
  69. package/build/components/sidebar/post-slug/index.js.map +1 -1
  70. package/build/components/sidebar/post-sticky/index.js +1 -2
  71. package/build/components/sidebar/post-sticky/index.js.map +1 -1
  72. package/build/components/sidebar/post-visibility/index.js +2 -2
  73. package/build/components/sidebar/post-visibility/index.js.map +1 -1
  74. package/build/components/sidebar/settings-header/index.js +16 -11
  75. package/build/components/sidebar/settings-header/index.js.map +1 -1
  76. package/build/components/sidebar/settings-sidebar/index.js +34 -12
  77. package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
  78. package/build/components/sidebar/template-summary/index.js +5 -10
  79. package/build/components/sidebar/template-summary/index.js.map +1 -1
  80. package/build/components/visual-editor/block-inspector-button.js +1 -2
  81. package/build/components/visual-editor/block-inspector-button.js.map +1 -1
  82. package/build/components/visual-editor/header.native.js +1 -2
  83. package/build/components/visual-editor/header.native.js.map +1 -1
  84. package/build/components/visual-editor/index.js +5 -4
  85. package/build/components/visual-editor/index.js.map +1 -1
  86. package/build/components/welcome-guide/index.js +6 -6
  87. package/build/components/welcome-guide/index.js.map +1 -1
  88. package/build/editor.js +35 -34
  89. package/build/editor.js.map +1 -1
  90. package/build/editor.native.js +1 -2
  91. package/build/editor.native.js.map +1 -1
  92. package/build/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +20 -26
  93. package/build/hooks/use-navigate-to-entity-record.js.map +1 -0
  94. package/build/hooks/validate-multiple-use/index.js +25 -4
  95. package/build/hooks/validate-multiple-use/index.js.map +1 -1
  96. package/build/plugins/keyboard-shortcuts-help-menu-item/index.js +1 -2
  97. package/build/plugins/keyboard-shortcuts-help-menu-item/index.js.map +1 -1
  98. package/build/plugins/welcome-guide-menu-item/index.js +2 -2
  99. package/build/plugins/welcome-guide-menu-item/index.js.map +1 -1
  100. package/build/store/actions.js +8 -12
  101. package/build/store/actions.js.map +1 -1
  102. package/build/store/constants.js +3 -6
  103. package/build/store/constants.js.map +1 -1
  104. package/build/store/index.js +3 -4
  105. package/build/store/index.js.map +1 -1
  106. package/build/store/reducer.js +1 -2
  107. package/build/store/reducer.js.map +1 -1
  108. package/build/store/selectors.js +21 -42
  109. package/build/store/selectors.js.map +1 -1
  110. package/build-module/components/header/fullscreen-mode-close/index.js +10 -6
  111. package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
  112. package/build-module/components/header/index.js +7 -7
  113. package/build-module/components/header/index.js.map +1 -1
  114. package/build-module/components/header/mode-switcher/index.js +0 -5
  115. package/build-module/components/header/mode-switcher/index.js.map +1 -1
  116. package/build-module/components/header/writing-menu/index.js +4 -17
  117. package/build-module/components/header/writing-menu/index.js.map +1 -1
  118. package/build-module/components/keyboard-shortcut-help-modal/index.js +0 -1
  119. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  120. package/build-module/components/layout/index.js +6 -3
  121. package/build-module/components/layout/index.js.map +1 -1
  122. package/build-module/components/sidebar/post-visibility/index.js +1 -0
  123. package/build-module/components/sidebar/post-visibility/index.js.map +1 -1
  124. package/build-module/components/sidebar/settings-header/index.js +16 -10
  125. package/build-module/components/sidebar/settings-header/index.js.map +1 -1
  126. package/build-module/components/sidebar/settings-sidebar/index.js +33 -9
  127. package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
  128. package/build-module/components/sidebar/template-summary/index.js +4 -8
  129. package/build-module/components/sidebar/template-summary/index.js.map +1 -1
  130. package/build-module/components/visual-editor/index.js +5 -4
  131. package/build-module/components/visual-editor/index.js.map +1 -1
  132. package/build-module/components/welcome-guide/index.js +6 -6
  133. package/build-module/components/welcome-guide/index.js.map +1 -1
  134. package/build-module/editor.js +34 -32
  135. package/build-module/editor.js.map +1 -1
  136. package/build-module/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +20 -26
  137. package/build-module/hooks/use-navigate-to-entity-record.js.map +1 -0
  138. package/build-module/hooks/validate-multiple-use/index.js +26 -4
  139. package/build-module/hooks/validate-multiple-use/index.js.map +1 -1
  140. package/build-module/plugins/welcome-guide-menu-item/index.js +2 -2
  141. package/build-module/plugins/welcome-guide-menu-item/index.js.map +1 -1
  142. package/build-module/store/actions.js +7 -10
  143. package/build-module/store/actions.js.map +1 -1
  144. package/build-style/style-rtl.css +29 -22
  145. package/build-style/style.css +29 -22
  146. package/package.json +32 -32
  147. package/src/components/header/fullscreen-mode-close/index.js +13 -10
  148. package/src/components/header/fullscreen-mode-close/test/index.js +31 -5
  149. package/src/components/header/index.js +10 -8
  150. package/src/components/header/mode-switcher/index.js +16 -25
  151. package/src/components/header/style.scss +40 -26
  152. package/src/components/header/writing-menu/index.js +3 -16
  153. package/src/components/layout/index.js +3 -2
  154. package/src/components/sidebar/post-visibility/index.js +1 -0
  155. package/src/components/sidebar/settings-header/index.js +17 -9
  156. package/src/components/sidebar/settings-sidebar/index.js +44 -9
  157. package/src/components/sidebar/template-summary/index.js +3 -7
  158. package/src/components/visual-editor/index.js +4 -2
  159. package/src/components/visual-editor/style.scss +1 -1
  160. package/src/components/welcome-guide/index.js +11 -6
  161. package/src/editor.js +50 -50
  162. package/src/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +23 -27
  163. package/src/hooks/validate-multiple-use/index.js +28 -3
  164. package/src/plugins/welcome-guide-menu-item/index.js +3 -3
  165. package/src/store/actions.js +20 -12
  166. package/src/style.scss +0 -1
  167. package/src/test/editor.native.js +8 -5
  168. package/build/hooks/use-post-history.js.map +0 -1
  169. 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
- * `getPostLinkProps` and `goBack` functions.
18
+ * `onNavigateToEntityRecord` and `onNavigateToPreviousEntityRecord` functions.
20
19
  */
21
- export default function usePostHistory( initialPostId, initialPostType ) {
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 getPostLinkProps = useCallback( ( params ) => {
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
- href: newUrl,
52
- onClick: ( event ) => {
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 goBack = useCallback( () => {
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
- getPostLinkProps,
71
- goBack: postHistory.length > 1 ? goBack : undefined,
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.find(
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 isTemplateMode = useSelect(
10
+ const isEditingTemplate = useSelect(
11
11
  ( select ) =>
12
- select( editorStore ).getRenderingMode() === 'template-only',
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={ isTemplateMode ? 'welcomeGuideTemplate' : 'welcomeGuide' }
19
+ name={ isEditingTemplate ? 'welcomeGuideTemplate' : 'welcomeGuide' }
20
20
  label={ __( 'Welcome Guide' ) }
21
21
  />
22
22
  );
@@ -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
- .dispatch( preferencesStore )
582
- .toggle( 'core', 'distractionFree' );
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
@@ -47,7 +47,6 @@ body.js.block-editor-page {
47
47
  .edit-post-text-editor,
48
48
  .edit-post-sidebar,
49
49
  .editor-post-publish-panel,
50
- .components-popover,
51
50
  .components-modal__frame {
52
51
  @include reset;
53
52
  }
@@ -103,8 +103,10 @@ describe( 'Editor', () => {
103
103
  await initializeEditor();
104
104
 
105
105
  // Act
106
- await act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
107
- await act( () => mediaAppendCallback( MEDIA[ 2 ] ) );
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
- await act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
127
+ act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
126
128
  // Unsupported type (PDF file)
127
- await act( () => mediaAppendCallback( MEDIA[ 1 ] ) );
128
- await act( () => mediaAppendCallback( MEDIA[ 3 ] ) );
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,OAAOH,YAAY,CAACI,KAAK,CAAE,CAAC,EAAE,CAAC,CAAE,CAAC;MACnC;IACD;IACA,OAAOJ,YAAY;EACpB,CAAC,EACD,CAAE;IAAEK,MAAM,EAAEV,aAAa;IAAEW,QAAQ,EAAEV;EAAgB,CAAC,CACvD,CAAC;EAED,MAAMW,gBAAgB,GAAG,IAAAC,oBAAW,EAAIC,MAAM,IAAM;IACnD,MAAMC,WAAW,GAAG,IAAAC,iBAAY,EAAEC,MAAM,CAACC,QAAQ,CAACC,IAAK,CAAC;IACxD,MAAMC,qBAAqB,GAAG,IAAAC,oBAAe,EAC5CJ,MAAM,CAACC,QAAQ,CAACC,IAAI,EACpB,GAAGG,MAAM,CAACC,IAAI,CAAER,WAAY,CAC7B,CAAC;IAED,MAAMS,MAAM,GAAG,IAAAC,iBAAY,EAAEL,qBAAqB,EAAE;MACnDb,IAAI,EAAEO,MAAM,CAACJ,MAAM;MACnBgB,MAAM,EAAE;IACT,CAAE,CAAC;IAEH,OAAO;MACNP,IAAI,EAAEK,MAAM;MACZG,OAAO,EAAIC,KAAK,IAAM;QACrBA,KAAK,CAACC,cAAc,CAAC,CAAC;QACtB1B,QAAQ,CAAE;UACTG,IAAI,EAAE,MAAM;UACZC,IAAI,EAAE;YAAEG,MAAM,EAAEI,MAAM,CAACJ,MAAM;YAAEC,QAAQ,EAAEG,MAAM,CAACH;UAAS;QAC1D,CAAE,CAAC;MACJ;IACD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMmB,MAAM,GAAG,IAAAjB,oBAAW,EAAE,MAAM;IACjCV,QAAQ,CAAE;MAAEG,IAAI,EAAE;IAAM,CAAE,CAAC;EAC5B,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMyB,WAAW,GAAG7B,WAAW,CAAEA,WAAW,CAACM,MAAM,GAAG,CAAC,CAAE;EAEzD,OAAO;IACNuB,WAAW;IACXnB,gBAAgB;IAChBkB,MAAM,EAAE5B,WAAW,CAACM,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,gBAAgB,GAAGjB,WAAW,CAAIkB,MAAM,IAAM;IACnD,MAAMC,WAAW,GAAGhB,YAAY,CAAEiB,MAAM,CAACC,QAAQ,CAACC,IAAK,CAAC;IACxD,MAAMC,qBAAqB,GAAGnB,eAAe,CAC5CgB,MAAM,CAACC,QAAQ,CAACC,IAAI,EACpB,GAAGE,MAAM,CAACC,IAAI,CAAEN,WAAY,CAC7B,CAAC;IAED,MAAMO,MAAM,GAAGxB,YAAY,CAAEqB,qBAAqB,EAAE;MACnDX,IAAI,EAAEM,MAAM,CAACH,MAAM;MACnBY,MAAM,EAAE;IACT,CAAE,CAAC;IAEH,OAAO;MACNL,IAAI,EAAEI,MAAM;MACZE,OAAO,EAAIC,KAAK,IAAM;QACrBA,KAAK,CAACC,cAAc,CAAC,CAAC;QACtBrB,QAAQ,CAAE;UACTE,IAAI,EAAE,MAAM;UACZC,IAAI,EAAE;YAAEG,MAAM,EAAEG,MAAM,CAACH,MAAM;YAAEC,QAAQ,EAAEE,MAAM,CAACF;UAAS;QAC1D,CAAE,CAAC;MACJ;IACD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMe,MAAM,GAAG/B,WAAW,CAAE,MAAM;IACjCS,QAAQ,CAAE;MAAEE,IAAI,EAAE;IAAM,CAAE,CAAC;EAC5B,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMqB,WAAW,GAAGxB,WAAW,CAAEA,WAAW,CAACK,MAAM,GAAG,CAAC,CAAE;EAEzD,OAAO;IACNmB,WAAW;IACXf,gBAAgB;IAChBc,MAAM,EAAEvB,WAAW,CAACK,MAAM,GAAG,CAAC,GAAGkB,MAAM,GAAGE;EAC3C,CAAC;AACF"}