@wordpress/editor 14.43.0 → 14.43.1-next.v.202604091042.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 (103) hide show
  1. package/README.md +8 -0
  2. package/build/components/autocompleters/index.cjs +3 -0
  3. package/build/components/autocompleters/index.cjs.map +2 -2
  4. package/build/components/autocompleters/link.cjs +71 -0
  5. package/build/components/autocompleters/link.cjs.map +7 -0
  6. package/build/components/collaborators-overlay/cursor-dom-utils.cjs +1 -1
  7. package/build/components/collaborators-overlay/cursor-dom-utils.cjs.map +2 -2
  8. package/build/components/collaborators-overlay/timing-utils.cjs +1 -1
  9. package/build/components/collaborators-overlay/timing-utils.cjs.map +2 -2
  10. package/build/components/collaborators-overlay/use-render-cursors.cjs.map +2 -2
  11. package/build/components/error-boundary/index.cjs +1 -1
  12. package/build/components/error-boundary/index.cjs.map +2 -2
  13. package/build/components/post-revisions-preview/revisions-slider.cjs +9 -17
  14. package/build/components/post-revisions-preview/revisions-slider.cjs.map +2 -2
  15. package/build/components/post-title/index.cjs +2 -2
  16. package/build/components/post-title/index.cjs.map +2 -2
  17. package/build/components/styles-canvas/revisions.cjs +2 -2
  18. package/build/components/styles-canvas/revisions.cjs.map +1 -1
  19. package/build/components/sync-connection-error-modal/index.cjs +57 -74
  20. package/build/components/sync-connection-error-modal/index.cjs.map +3 -3
  21. package/build/components/sync-connection-error-modal/use-retry-countdown.cjs +32 -9
  22. package/build/components/sync-connection-error-modal/use-retry-countdown.cjs.map +2 -2
  23. package/build/hooks/default-autocompleters.cjs +1 -1
  24. package/build/hooks/default-autocompleters.cjs.map +2 -2
  25. package/build/store/private-actions.cjs +1 -6
  26. package/build/store/private-actions.cjs.map +2 -2
  27. package/build/store/private-selectors.cjs +4 -6
  28. package/build/store/private-selectors.cjs.map +2 -2
  29. package/build/store/reducer.cjs +1 -1
  30. package/build/store/reducer.cjs.map +2 -2
  31. package/build-module/components/autocompleters/index.mjs +4 -2
  32. package/build-module/components/autocompleters/index.mjs.map +2 -2
  33. package/build-module/components/autocompleters/link.mjs +40 -0
  34. package/build-module/components/autocompleters/link.mjs.map +7 -0
  35. package/build-module/components/collaborators-overlay/cursor-dom-utils.mjs +1 -1
  36. package/build-module/components/collaborators-overlay/cursor-dom-utils.mjs.map +2 -2
  37. package/build-module/components/collaborators-overlay/timing-utils.mjs +1 -1
  38. package/build-module/components/collaborators-overlay/timing-utils.mjs.map +2 -2
  39. package/build-module/components/collaborators-overlay/use-render-cursors.mjs.map +2 -2
  40. package/build-module/components/error-boundary/index.mjs +1 -1
  41. package/build-module/components/error-boundary/index.mjs.map +2 -2
  42. package/build-module/components/post-revisions-preview/revisions-slider.mjs +9 -17
  43. package/build-module/components/post-revisions-preview/revisions-slider.mjs.map +2 -2
  44. package/build-module/components/post-title/index.mjs +2 -2
  45. package/build-module/components/post-title/index.mjs.map +2 -2
  46. package/build-module/components/styles-canvas/revisions.mjs +2 -2
  47. package/build-module/components/styles-canvas/revisions.mjs.map +1 -1
  48. package/build-module/components/sync-connection-error-modal/index.mjs +57 -75
  49. package/build-module/components/sync-connection-error-modal/index.mjs.map +2 -2
  50. package/build-module/components/sync-connection-error-modal/use-retry-countdown.mjs +33 -10
  51. package/build-module/components/sync-connection-error-modal/use-retry-countdown.mjs.map +2 -2
  52. package/build-module/hooks/default-autocompleters.mjs +2 -2
  53. package/build-module/hooks/default-autocompleters.mjs.map +2 -2
  54. package/build-module/store/private-actions.mjs +1 -6
  55. package/build-module/store/private-actions.mjs.map +2 -2
  56. package/build-module/store/private-selectors.mjs +4 -6
  57. package/build-module/store/private-selectors.mjs.map +2 -2
  58. package/build-module/store/reducer.mjs +1 -1
  59. package/build-module/store/reducer.mjs.map +2 -2
  60. package/build-style/style-rtl.css +13 -2
  61. package/build-style/style.css +13 -2
  62. package/build-types/bindings/post-data.d.ts +3 -3
  63. package/build-types/bindings/term-data.d.ts +14 -14
  64. package/build-types/components/autocompleters/index.d.ts +1 -0
  65. package/build-types/components/autocompleters/link.d.ts +12 -0
  66. package/build-types/components/autocompleters/link.d.ts.map +1 -0
  67. package/build-types/components/collaborators-overlay/use-render-cursors.d.ts.map +1 -1
  68. package/build-types/components/keyboard-shortcut-help-modal/config.d.ts +11 -11
  69. package/build-types/components/post-actions/set-as-homepage.d.ts +1 -1
  70. package/build-types/components/post-actions/set-as-posts-page.d.ts +1 -1
  71. package/build-types/components/post-format/index.d.ts +10 -10
  72. package/build-types/components/post-locked-modal/index.d.ts +2 -2
  73. package/build-types/components/post-revisions-preview/revisions-slider.d.ts.map +1 -1
  74. package/build-types/components/post-status/index.d.ts +10 -10
  75. package/build-types/components/post-visibility/utils.d.ts +6 -6
  76. package/build-types/components/sync-connection-error-modal/index.d.ts +0 -14
  77. package/build-types/components/sync-connection-error-modal/index.d.ts.map +1 -1
  78. package/build-types/components/sync-connection-error-modal/use-retry-countdown.d.ts.map +1 -1
  79. package/build-types/store/private-actions.d.ts.map +1 -1
  80. package/build-types/store/private-selectors.d.ts.map +1 -1
  81. package/build-types/store/reducer.d.ts +10 -10
  82. package/build-types/store/reducer.d.ts.map +1 -1
  83. package/build-types/utils/pageTypeBadge.d.ts +1 -1
  84. package/build-types/utils/pageTypeBadge.d.ts.map +1 -1
  85. package/package.json +45 -45
  86. package/src/components/autocompleters/index.js +1 -0
  87. package/src/components/autocompleters/link.js +47 -0
  88. package/src/components/autocompleters/style.scss +6 -0
  89. package/src/components/collaborators-overlay/cursor-dom-utils.ts +1 -1
  90. package/src/components/collaborators-overlay/timing-utils.ts +1 -1
  91. package/src/components/collaborators-overlay/use-render-cursors.ts +4 -2
  92. package/src/components/error-boundary/index.js +1 -1
  93. package/src/components/error-boundary/index.native.js +1 -1
  94. package/src/components/post-revisions-preview/revisions-slider.js +9 -27
  95. package/src/components/post-title/index.js +3 -3
  96. package/src/components/styles-canvas/revisions.js +2 -2
  97. package/src/components/sync-connection-error-modal/index.tsx +127 -154
  98. package/src/components/sync-connection-error-modal/use-retry-countdown.ts +46 -10
  99. package/src/hooks/default-autocompleters.js +2 -2
  100. package/src/hooks/test/default-autocompleters.js +2 -2
  101. package/src/store/private-actions.js +1 -6
  102. package/src/store/private-selectors.js +4 -13
  103. package/src/store/reducer.js +9 -8
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useMemo } from '@wordpress/element';
5
4
  import { useSelect, useDispatch } from '@wordpress/data';
6
5
  import { RangeControl, Spinner } from '@wordpress/components';
7
6
  import { store as coreStore } from '@wordpress/core-data';
@@ -39,6 +38,8 @@ function RevisionsSlider() {
39
38
  const query = {
40
39
  per_page: -1,
41
40
  context: 'edit',
41
+ orderby: 'date',
42
+ order: 'asc',
42
43
  _fields: [
43
44
  ...new Set( [
44
45
  'id',
@@ -72,28 +73,12 @@ function RevisionsSlider() {
72
73
 
73
74
  const { setCurrentRevisionId } = unlock( useDispatch( editorStore ) );
74
75
 
75
- // Template revisions use the template REST API format, which exposes
76
- // 'modified' instead of 'date'.
77
- const revisionDateField = revisionKey === 'wp_id' ? 'modified' : 'date';
78
-
79
- const sortedRevisions = useMemo( () => {
80
- return (
81
- revisions
82
- ?.slice()
83
- .sort(
84
- ( a, b ) =>
85
- new Date( a[ revisionDateField ] ) -
86
- new Date( b[ revisionDateField ] )
87
- ) ?? []
88
- );
89
- }, [ revisions, revisionDateField ] );
90
-
91
- const selectedIndex = sortedRevisions.findIndex(
76
+ const selectedIndex = revisions?.findIndex(
92
77
  ( r ) => r[ revisionKey ] === currentRevisionId
93
78
  );
94
79
 
95
80
  const handleSliderChange = ( index ) => {
96
- const revision = sortedRevisions[ index ];
81
+ const revision = revisions?.[ index ];
97
82
  if ( revision ) {
98
83
  setCurrentRevisionId( revision[ revisionKey ] );
99
84
  }
@@ -102,21 +87,18 @@ function RevisionsSlider() {
102
87
  // Format date for tooltip.
103
88
  const dateSettings = getDateSettings();
104
89
  const renderTooltipContent = ( index ) => {
105
- const revision = sortedRevisions[ index ];
90
+ const revision = revisions?.[ index ];
106
91
  if ( ! revision ) {
107
92
  return index;
108
93
  }
109
- return dateI18n(
110
- dateSettings.formats.datetime,
111
- revision[ revisionDateField ]
112
- );
94
+ return dateI18n( dateSettings.formats.datetime, revision.date );
113
95
  };
114
96
 
115
97
  if ( isLoading ) {
116
98
  return <Spinner />;
117
99
  }
118
100
 
119
- if ( ! sortedRevisions.length ) {
101
+ if ( ! revisions?.length ) {
120
102
  return (
121
103
  <span className="editor-revisions-header__no-revisions">
122
104
  { __( 'No revisions found.' ) }
@@ -124,7 +106,7 @@ function RevisionsSlider() {
124
106
  );
125
107
  }
126
108
 
127
- if ( sortedRevisions.length === 1 ) {
109
+ if ( revisions?.length === 1 ) {
128
110
  return (
129
111
  <span className="editor-revisions-header__no-revisions">
130
112
  { __( 'Only one revision found.' ) }
@@ -138,7 +120,7 @@ function RevisionsSlider() {
138
120
  className="editor-revisions-header__slider"
139
121
  hideLabelFromVision
140
122
  label={ __( 'Revision' ) }
141
- max={ sortedRevisions.length - 1 }
123
+ max={ revisions?.length - 1 }
142
124
  min={ 0 }
143
125
  marks
144
126
  onChange={ handleSliderChange }
@@ -124,7 +124,7 @@ const PostTitle = forwardRef( ( _, forwardedRef ) => {
124
124
  try {
125
125
  plainText = clipboardData.getData( 'text/plain' );
126
126
  html = clipboardData.getData( 'text/html' );
127
- } catch ( error ) {
127
+ } catch {
128
128
  // Some browsers like UC Browser paste plain text by default and
129
129
  // don't support clipboardData at all, so allow default
130
130
  // behaviour.
@@ -181,7 +181,7 @@ const PostTitle = forwardRef( ( _, forwardedRef ) => {
181
181
  const style = isEditingContentOnlySection ? { opacity: 0.2 } : undefined;
182
182
 
183
183
  return (
184
- /* eslint-disable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
184
+ /* eslint-disable jsx-a11y/no-noninteractive-element-to-interactive-role */
185
185
  <h1
186
186
  ref={ useMergeRefs( [ richTextRef, focusRef ] ) }
187
187
  contentEditable={ ! isEditingContentOnlySection && ! isPreview }
@@ -195,7 +195,7 @@ const PostTitle = forwardRef( ( _, forwardedRef ) => {
195
195
  onPaste={ onPaste }
196
196
  style={ style }
197
197
  />
198
- /* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
198
+ /* eslint-enable jsx-a11y/no-noninteractive-element-to-interactive-role */
199
199
  );
200
200
  } );
201
201
 
@@ -23,7 +23,7 @@ import { unlock } from '../../lock-unlock';
23
23
 
24
24
  const {
25
25
  ExperimentalBlockEditorProvider,
26
- __unstableBlockStyleVariationOverridesWithConfig,
26
+ BlockStyleVariationOverridesWithConfig,
27
27
  } = unlock( blockEditorPrivateApis );
28
28
 
29
29
  function isObjectEmpty( object ) {
@@ -133,7 +133,7 @@ function StylesCanvasRevisions( { path }, ref ) {
133
133
  * so they can access any registered style overrides.
134
134
  */ }
135
135
  <EditorStyles styles={ editorStyles } />
136
- <__unstableBlockStyleVariationOverridesWithConfig
136
+ <BlockStyleVariationOverridesWithConfig
137
137
  config={ mergedConfig }
138
138
  />
139
139
  </ExperimentalBlockEditorProvider>
@@ -8,7 +8,6 @@ import { serialize } from '@wordpress/blocks';
8
8
  import {
9
9
  store as coreDataStore,
10
10
  privateApis as coreDataPrivateApis,
11
- type ConnectionError,
12
11
  } from '@wordpress/core-data';
13
12
  // @ts-expect-error - No type declarations available for @wordpress/block-editor
14
13
  // prettier-ignore
@@ -16,10 +15,10 @@ import { privateApis, store as blockEditorStore } from '@wordpress/block-editor'
16
15
  import {
17
16
  Button,
18
17
  Modal,
19
- withFilters,
20
18
  __experimentalHStack as HStack,
21
19
  __experimentalVStack as VStack,
22
20
  } from '@wordpress/components';
21
+ import { applyFilters } from '@wordpress/hooks';
23
22
  import { useState, useEffect } from '@wordpress/element';
24
23
  import { __, sprintf, _n } from '@wordpress/i18n';
25
24
 
@@ -37,144 +36,6 @@ const { retrySyncConnection } = unlock( coreDataPrivateApis );
37
36
  // Debounce time for initial disconnected status to allow connection to establish.
38
37
  const INITIAL_DISCONNECTED_DEBOUNCE_MS = 20000;
39
38
 
40
- // Debounce time for showing the disconnect dialog after the intial connection,
41
- // allowing brief network interruptions to resolve.
42
- const DISCONNECTED_DEBOUNCE_MS = 8000;
43
-
44
- export interface SyncConnectionErrorModalProps {
45
- description: string; // Modal description.
46
- error?: ConnectionError; // Error object with a `code` property.
47
- manualRetry?: () => void; // Callback for when the retry button is clicked.
48
- postType?: { slug?: string; labels?: { name?: string } } | null; // Current post type object.
49
- secondsRemainingUntilAutoRetry?: number; // Seconds remaining until the next automatic retry attempt, if applicable.
50
- title: string; // Modal title.
51
- }
52
-
53
- /**
54
- * Default sync connection modal component.
55
- *
56
- * Can be replaced or wrapped via the `editor.SyncConnectionErrorModal` filter.
57
- *
58
- * @param props - SyncConnectionErrorModalProps.
59
- */
60
- function DefaultSyncConnectionErrorModal(
61
- props: SyncConnectionErrorModalProps
62
- ) {
63
- const {
64
- description,
65
- manualRetry,
66
- postType,
67
- secondsRemainingUntilAutoRetry,
68
- title,
69
- } = props;
70
- const copyButtonRef = useCopyToClipboard( () => {
71
- const blocks = select( blockEditorStore ).getBlocks();
72
- return serialize( blocks );
73
- } );
74
-
75
- let retryCountdownText: string = '';
76
- let isRetrying = false;
77
- if (
78
- secondsRemainingUntilAutoRetry &&
79
- secondsRemainingUntilAutoRetry > 0
80
- ) {
81
- retryCountdownText = sprintf(
82
- /* translators: %d: number of seconds until retry */
83
- _n(
84
- 'Retrying connection in %d second\u2026',
85
- 'Retrying connection in %d seconds\u2026',
86
- secondsRemainingUntilAutoRetry
87
- ),
88
- secondsRemainingUntilAutoRetry
89
- );
90
- } else if ( 0 === secondsRemainingUntilAutoRetry ) {
91
- isRetrying = true;
92
- retryCountdownText = __( 'Retrying\u2026' );
93
- }
94
-
95
- let editPostHref = 'edit.php';
96
- if ( postType?.slug ) {
97
- editPostHref = `edit.php?post_type=${ postType.slug }`;
98
- }
99
-
100
- return (
101
- <Modal
102
- overlayClassName="editor-sync-connection-error-modal"
103
- isDismissible={ false }
104
- onRequestClose={ () => {} }
105
- shouldCloseOnClickOutside={ false }
106
- shouldCloseOnEsc={ false }
107
- size="medium"
108
- title={ title }
109
- >
110
- <VStack spacing={ 6 }>
111
- <p>{ description }</p>
112
- { retryCountdownText && (
113
- <p className="editor-sync-connection-error-modal__retry-countdown">
114
- { retryCountdownText }
115
- </p>
116
- ) }
117
- <HStack justify="right">
118
- <Button
119
- __next40pxDefaultSize
120
- href={ editPostHref }
121
- isDestructive
122
- variant="tertiary"
123
- >
124
- { sprintf(
125
- /* translators: %s: Post type name (e.g., "Posts", "Pages"). */
126
- __( 'Back to %s' ),
127
- postType?.labels?.name ?? __( 'Posts' )
128
- ) }
129
- </Button>
130
- <Button
131
- __next40pxDefaultSize
132
- ref={ copyButtonRef }
133
- variant={ manualRetry ? 'secondary' : 'primary' }
134
- >
135
- { __( 'Copy Post Content' ) }
136
- </Button>
137
- { manualRetry && (
138
- <Button
139
- __next40pxDefaultSize
140
- accessibleWhenDisabled
141
- aria-disabled={ isRetrying }
142
- disabled={ isRetrying }
143
- isBusy={ isRetrying }
144
- variant="primary"
145
- onClick={ manualRetry }
146
- >
147
- { __( 'Retry' ) }
148
- </Button>
149
- ) }
150
- </HStack>
151
- </VStack>
152
- </Modal>
153
- );
154
- }
155
-
156
- /**
157
- * Filtered version of the sync connection modal, allowing third-party
158
- * plugins to replace the default modal via:
159
- *
160
- * ```js
161
- * wp.hooks.addFilter(
162
- * 'editor.SyncConnectionErrorModal',
163
- * 'my-plugin/custom-sync-connection-error-modal',
164
- * ( OriginalComponent ) => ( props ) => {
165
- * // Return a custom component or wrap the original.
166
- * return <OriginalComponent { ...props } />;
167
- * }
168
- * );
169
- * ```
170
- */
171
- // @ts-ignore
172
- const FilteredSyncConnectionErrorModal = globalThis.IS_GUTENBERG_PLUGIN
173
- ? withFilters( 'editor.SyncConnectionErrorModal' )(
174
- DefaultSyncConnectionErrorModal
175
- )
176
- : DefaultSyncConnectionErrorModal;
177
-
178
39
  /**
179
40
  * Sync connection modal that displays when any entity reports a disconnection.
180
41
  * Uses BlockCanvasCover.Fill to render in the block canvas.
@@ -207,7 +68,10 @@ export function SyncConnectionErrorModal() {
207
68
  const { onManualRetry, secondsRemaining } =
208
69
  useRetryCountdown( connectionStatus );
209
70
 
210
- const isConnected = 'connected' === connectionStatus?.status;
71
+ const copyButtonRef = useCopyToClipboard( () => {
72
+ const blocks = select( blockEditorStore ).getBlocks();
73
+ return serialize( blocks );
74
+ } );
211
75
 
212
76
  // Set hasInitialized after a debounce to give extra time on initial load.
213
77
  useEffect( () => {
@@ -218,18 +82,30 @@ export function SyncConnectionErrorModal() {
218
82
  return () => clearTimeout( timeout );
219
83
  }, [] );
220
84
 
85
+ // Show the modal when disconnected and either retries are exhausted or
86
+ // no retry is available (unrecoverable error). Hide on reconnect.
87
+ // The 'connecting' state is ignored so the modal preserves its current
88
+ // visibility during active retry attempts.
89
+ const canRetry =
90
+ connectionStatus &&
91
+ 'disconnected' === connectionStatus.status &&
92
+ ( connectionStatus.canManuallyRetry ||
93
+ connectionStatus.willAutoRetryInMs );
94
+
221
95
  useEffect( () => {
222
- if ( isConnected ) {
96
+ if ( 'connected' === connectionStatus?.status ) {
223
97
  setShowModal( false );
224
98
  return;
225
99
  }
226
100
 
227
- const timeout = setTimeout( () => {
101
+ if (
102
+ connectionStatus?.status &&
103
+ 'connecting' !== connectionStatus.status &&
104
+ ( ! canRetry || connectionStatus.backgroundRetriesFailed )
105
+ ) {
228
106
  setShowModal( true );
229
- }, DISCONNECTED_DEBOUNCE_MS );
230
-
231
- return () => clearTimeout( timeout );
232
- }, [ isConnected ] );
107
+ }
108
+ }, [ connectionStatus, canRetry ] );
233
109
 
234
110
  if ( ! isCollaborationEnabled || ! hasInitialized || ! showModal ) {
235
111
  return null;
@@ -239,6 +115,36 @@ export function SyncConnectionErrorModal() {
239
115
  connectionStatus && 'error' in connectionStatus
240
116
  ? connectionStatus?.error
241
117
  : undefined;
118
+
119
+ // For unrecoverable errors (no retry available), allow plugins to handle
120
+ // the error themselves. If a plugin returns a value other than false, it
121
+ // signals that it has taken over error display and the default modal is
122
+ // suppressed.
123
+ //
124
+ // @example
125
+ // ```js
126
+ // wp.hooks.addFilter(
127
+ // 'editor.isSyncConnectionErrorHandled',
128
+ // 'my-plugin/handle-sync-error',
129
+ // ( isHandled, errorCode ) => {
130
+ // if ( errorCode === 'connection-limit-exceeded' ) {
131
+ // return true; // Plugin handles this error via its own UI.
132
+ // }
133
+ // return isHandled;
134
+ // }
135
+ // );
136
+ // ```
137
+ if (
138
+ ! canRetry &&
139
+ applyFilters(
140
+ 'editor.isSyncConnectionErrorHandled',
141
+ false,
142
+ error?.code
143
+ ) !== false
144
+ ) {
145
+ return null;
146
+ }
147
+
242
148
  const manualRetry =
243
149
  connectionStatus &&
244
150
  'canManuallyRetry' in connectionStatus &&
@@ -248,18 +154,85 @@ export function SyncConnectionErrorModal() {
248
154
  retrySyncConnection();
249
155
  }
250
156
  : undefined;
157
+
251
158
  const messages = getSyncErrorMessages( error );
252
159
 
160
+ let retryCountdownText: string = '';
161
+ let isRetrying = false;
162
+ if ( secondsRemaining && secondsRemaining > 0 ) {
163
+ retryCountdownText = sprintf(
164
+ /* translators: %d: number of seconds until retry */
165
+ _n(
166
+ 'Retrying connection in %d second\u2026',
167
+ 'Retrying connection in %d seconds\u2026',
168
+ secondsRemaining
169
+ ),
170
+ secondsRemaining
171
+ );
172
+ } else if ( 0 === secondsRemaining ) {
173
+ isRetrying = true;
174
+ retryCountdownText = __( 'Retrying\u2026' );
175
+ }
176
+
177
+ let editPostHref = 'edit.php';
178
+ if ( postType?.slug ) {
179
+ editPostHref = `edit.php?post_type=${ postType.slug }`;
180
+ }
181
+
253
182
  return (
254
183
  <BlockCanvasCover.Fill>
255
- <FilteredSyncConnectionErrorModal
256
- description={ messages.description }
257
- error={ error }
258
- manualRetry={ manualRetry }
259
- postType={ postType }
260
- secondsRemainingUntilAutoRetry={ secondsRemaining }
184
+ <Modal
185
+ overlayClassName="editor-sync-connection-error-modal"
186
+ isDismissible={ false }
187
+ onRequestClose={ () => {} }
188
+ shouldCloseOnClickOutside={ false }
189
+ shouldCloseOnEsc={ false }
190
+ size="medium"
261
191
  title={ messages.title }
262
- />
192
+ >
193
+ <VStack spacing={ 6 }>
194
+ <p>{ messages.description }</p>
195
+ { retryCountdownText && (
196
+ <p className="editor-sync-connection-error-modal__retry-countdown">
197
+ { retryCountdownText }
198
+ </p>
199
+ ) }
200
+ <HStack justify="right">
201
+ <Button
202
+ __next40pxDefaultSize
203
+ href={ editPostHref }
204
+ isDestructive
205
+ variant="tertiary"
206
+ >
207
+ { sprintf(
208
+ /* translators: %s: Post type name (e.g., "Posts", "Pages"). */
209
+ __( 'Back to %s' ),
210
+ postType?.labels?.name ?? __( 'Posts' )
211
+ ) }
212
+ </Button>
213
+ <Button
214
+ __next40pxDefaultSize
215
+ ref={ copyButtonRef }
216
+ variant={ manualRetry ? 'secondary' : 'primary' }
217
+ >
218
+ { __( 'Copy Post Content' ) }
219
+ </Button>
220
+ { manualRetry && (
221
+ <Button
222
+ __next40pxDefaultSize
223
+ accessibleWhenDisabled
224
+ aria-disabled={ isRetrying }
225
+ disabled={ isRetrying }
226
+ isBusy={ isRetrying }
227
+ variant="primary"
228
+ onClick={ manualRetry }
229
+ >
230
+ { __( 'Retry' ) }
231
+ </Button>
232
+ ) }
233
+ </HStack>
234
+ </VStack>
235
+ </Modal>
263
236
  </BlockCanvasCover.Fill>
264
237
  );
265
238
  }
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import type { ConnectionStatus } from '@wordpress/core-data';
5
- import { useState, useEffect } from '@wordpress/element';
5
+ import { useState, useEffect, useRef } from '@wordpress/element';
6
6
 
7
7
  interface UseRetryCountdownResult {
8
8
  onManualRetry: () => void;
@@ -13,6 +13,7 @@ export function useRetryCountdown(
13
13
  connectionStatus?: ConnectionStatus | null
14
14
  ): UseRetryCountdownResult {
15
15
  const [ secondsRemaining, setSecondsRemaining ] = useState< number >();
16
+ const hasRetriedRef = useRef( false );
16
17
 
17
18
  useEffect( () => {
18
19
  if ( ! connectionStatus ) {
@@ -22,6 +23,7 @@ export function useRetryCountdown(
22
23
  // Only clear countdown when explicitly connected.
23
24
  if ( 'connected' === connectionStatus.status ) {
24
25
  setSecondsRemaining( undefined );
26
+ hasRetriedRef.current = false;
25
27
  return;
26
28
  }
27
29
 
@@ -37,21 +39,55 @@ export function useRetryCountdown(
37
39
 
38
40
  const { willAutoRetryInMs: retryInMs } = connectionStatus;
39
41
  const retryAt = Date.now() + retryInMs;
40
- setSecondsRemaining( Math.ceil( retryInMs / 1000 ) );
41
42
 
42
- const intervalId = setInterval( () => {
43
- const remaining = Math.ceil( ( retryAt - Date.now() ) / 1000 );
44
- setSecondsRemaining( Math.max( 0, remaining ) );
45
- if ( remaining <= 0 ) {
46
- clearInterval( intervalId );
43
+ // After a retry attempt (manual or automatic), show "Retrying..."
44
+ // for 500ms before starting the next countdown. Skip the delay on
45
+ // the very first disconnect so the countdown starts immediately.
46
+ const hasRetried = hasRetriedRef.current;
47
+ hasRetriedRef.current = true;
48
+
49
+ if ( hasRetried ) {
50
+ setSecondsRemaining( 0 );
51
+ }
52
+
53
+ let countdownIntervalId: ReturnType< typeof setInterval > | null = null;
54
+
55
+ const startCountdown = () => {
56
+ setSecondsRemaining( Math.ceil( ( retryAt - Date.now() ) / 1000 ) );
57
+
58
+ countdownIntervalId = setInterval( () => {
59
+ const remaining = Math.ceil( ( retryAt - Date.now() ) / 1000 );
60
+ setSecondsRemaining( Math.max( 0, remaining ) );
61
+
62
+ if ( remaining <= 0 && countdownIntervalId ) {
63
+ clearInterval( countdownIntervalId );
64
+ }
65
+ }, 1000 );
66
+ };
67
+
68
+ const retryingDelayId = hasRetried
69
+ ? setTimeout( startCountdown, 500 )
70
+ : null;
71
+
72
+ if ( ! retryingDelayId ) {
73
+ startCountdown();
74
+ }
75
+
76
+ return () => {
77
+ if ( retryingDelayId ) {
78
+ clearTimeout( retryingDelayId );
47
79
  }
48
- }, 1000 );
49
80
 
50
- return () => clearInterval( intervalId );
81
+ if ( countdownIntervalId ) {
82
+ clearInterval( countdownIntervalId );
83
+ }
84
+ };
51
85
  }, [ connectionStatus ] );
52
86
 
53
87
  return {
54
- onManualRetry: () => setSecondsRemaining( 0 ),
88
+ onManualRetry: () => {
89
+ setSecondsRemaining( 0 );
90
+ },
55
91
  secondsRemaining,
56
92
  };
57
93
  }
@@ -6,11 +6,11 @@ import { addFilter } from '@wordpress/hooks';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import { userAutocompleter } from '../components';
9
+ import { linkAutocompleter, userAutocompleter } from '../components';
10
10
 
11
11
  function setDefaultCompleters( completers = [] ) {
12
12
  // Provide copies so filters may directly modify them.
13
- completers.push( { ...userAutocompleter } );
13
+ completers.push( { ...linkAutocompleter }, { ...userAutocompleter } );
14
14
 
15
15
  return completers;
16
16
  }
@@ -7,11 +7,11 @@ import { applyFilters } from '@wordpress/hooks';
7
7
  * Internal dependencies
8
8
  */
9
9
  import '../default-autocompleters';
10
- import { userAutocompleter } from '../../components';
10
+ import { linkAutocompleter, userAutocompleter } from '../../components';
11
11
 
12
12
  describe( 'default-autocompleters', () => {
13
13
  const BLOCK_NAME = 'core/foo';
14
- const defaultAutocompleters = [ userAutocompleter ];
14
+ const defaultAutocompleters = [ linkAutocompleter, userAutocompleter ];
15
15
 
16
16
  it( 'provides default completers if none are provided', () => {
17
17
  const result = applyFilters(
@@ -688,12 +688,7 @@ export const restoreRevision =
688
688
  sprintf(
689
689
  /* translators: %s: Date and time of the revision. */
690
690
  __( 'Restored to revision from %s.' ),
691
- dateI18n(
692
- getDateSettings().formats.datetime,
693
- // Template revisions use the template REST API format, which
694
- // exposes 'modified' instead of 'date'.
695
- revisionKey === 'wp_id' ? revision.modified : revision.date
696
- )
691
+ dateI18n( getDateSettings().formats.datetime, revision.date )
697
692
  ),
698
693
  {
699
694
  type: 'snackbar',
@@ -482,6 +482,8 @@ export const getPreviousRevision = createRegistrySelector(
482
482
  {
483
483
  per_page: -1,
484
484
  context: 'edit',
485
+ orderby: 'date',
486
+ order: 'asc',
485
487
  _fields: [
486
488
  ...new Set( [
487
489
  'id',
@@ -501,25 +503,14 @@ export const getPreviousRevision = createRegistrySelector(
501
503
  return null;
502
504
  }
503
505
 
504
- // Template revisions use the template REST API format, which exposes
505
- // 'modified' instead of 'date'. Regular post revisions use 'date'.
506
- const revisionDateField = revisionKey === 'wp_id' ? 'modified' : 'date';
507
-
508
- // Sort by date ascending (oldest first).
509
- const sortedRevisions = [ ...revisions ].sort(
510
- ( a, b ) =>
511
- new Date( a[ revisionDateField ] ) -
512
- new Date( b[ revisionDateField ] )
513
- );
514
-
515
506
  // Find current revision index.
516
- const currentIndex = sortedRevisions.findIndex(
507
+ const currentIndex = revisions.findIndex(
517
508
  ( r ) => r[ revisionKey ] === currentRevisionId
518
509
  );
519
510
 
520
511
  // Return the previous revision (older one) if it exists.
521
512
  if ( currentIndex > 0 ) {
522
- return sortedRevisions[ currentIndex - 1 ];
513
+ return revisions[ currentIndex - 1 ];
523
514
  }
524
515
 
525
516
  return null;
@@ -449,13 +449,6 @@ export function revisionId( state = null, action ) {
449
449
  return state;
450
450
  }
451
451
 
452
- /**
453
- * Reducer returning the currently selected note and its options.
454
- *
455
- * @param {Object} state Current state.
456
- * @param {Object} action Dispatched action.
457
- * @return {Object} Updated state.
458
- */
459
452
  /**
460
453
  * Reducer for whether the revision diff is shown.
461
454
  * Resets to true when entering/exiting revisions mode.
@@ -469,11 +462,19 @@ export function showRevisionDiff( state = true, action ) {
469
462
  case 'SET_SHOW_REVISION_DIFF':
470
463
  return action.showDiff;
471
464
  case 'SET_CURRENT_REVISION_ID':
472
- return true; // reset on enter/exit revisions
465
+ // Reset during the exit.
466
+ return ! action.revisionId ? true : state;
473
467
  }
474
468
  return state;
475
469
  }
476
470
 
471
+ /**
472
+ * Reducer returning the currently selected note and its options.
473
+ *
474
+ * @param {Object} state Current state.
475
+ * @param {Object} action Dispatched action.
476
+ * @return {Object} Updated state.
477
+ */
477
478
  export function selectedNote( state = {}, action ) {
478
479
  switch ( action.type ) {
479
480
  case 'SELECT_NOTE':