@wordpress/editor 14.41.2-next.v.202603161435.0 → 14.42.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 +1 -1
- package/build/components/collaborators-overlay/compute-selection.cjs +10 -10
- package/build/components/collaborators-overlay/compute-selection.cjs.map +2 -2
- package/build/components/collaborators-overlay/overlay.cjs +11 -0
- package/build/components/collaborators-overlay/overlay.cjs.map +2 -2
- package/build/components/collaborators-overlay/timing-utils.cjs +46 -0
- package/build/components/collaborators-overlay/timing-utils.cjs.map +7 -0
- package/build/components/collaborators-overlay/use-render-cursors.cjs +1 -1
- package/build/components/collaborators-overlay/use-render-cursors.cjs.map +2 -2
- package/build/components/post-locked-modal/index.cjs +16 -3
- package/build/components/post-locked-modal/index.cjs.map +2 -2
- package/build/components/post-revisions-preview/block-diff.cjs +39 -11
- package/build/components/post-revisions-preview/block-diff.cjs.map +2 -2
- package/build/components/post-revisions-preview/diff-markers.cjs +2 -2
- package/build/components/post-revisions-preview/diff-markers.cjs.map +2 -2
- package/build/components/post-revisions-preview/revisions-canvas.cjs +1 -1
- package/build/components/post-revisions-preview/revisions-canvas.cjs.map +2 -2
- package/build/components/post-template/block-theme.cjs +7 -4
- package/build/components/post-template/block-theme.cjs.map +2 -2
- package/build/components/post-template/hooks.cjs +39 -2
- package/build/components/post-template/hooks.cjs.map +2 -2
- package/build/components/post-template/panel.cjs +5 -42
- package/build/components/post-template/panel.cjs.map +3 -3
- package/build/components/provider/use-block-editor-settings.cjs +2 -0
- package/build/components/provider/use-block-editor-settings.cjs.map +3 -3
- package/build/components/revision-block-diff/index.cjs +84 -0
- package/build/components/revision-block-diff/index.cjs.map +7 -0
- package/build/components/sidebar/dataform-post-summary.cjs +17 -2
- package/build/components/sidebar/dataform-post-summary.cjs.map +2 -2
- package/build/components/sidebar/index.cjs +5 -1
- package/build/components/sidebar/index.cjs.map +3 -3
- package/build/components/{sync-connection-modal → sync-connection-error-modal}/index.cjs +87 -78
- package/build/components/sync-connection-error-modal/index.cjs.map +7 -0
- package/build/components/{sync-connection-modal → sync-connection-error-modal}/use-retry-countdown.cjs +14 -27
- package/build/components/sync-connection-error-modal/use-retry-countdown.cjs.map +7 -0
- package/build/components/visual-editor/index.cjs +2 -2
- package/build/components/visual-editor/index.cjs.map +2 -2
- package/build/store/actions.cjs +1 -3
- package/build/store/actions.cjs.map +2 -2
- package/build/utils/media-finalize/index.cjs +43 -0
- package/build/utils/media-finalize/index.cjs.map +7 -0
- package/build/utils/sync-error-messages.cjs +29 -16
- package/build/utils/sync-error-messages.cjs.map +3 -3
- package/build-module/components/collaborators-overlay/compute-selection.mjs +10 -10
- package/build-module/components/collaborators-overlay/compute-selection.mjs.map +2 -2
- package/build-module/components/collaborators-overlay/overlay.mjs +11 -0
- package/build-module/components/collaborators-overlay/overlay.mjs.map +2 -2
- package/build-module/components/collaborators-overlay/timing-utils.mjs +21 -0
- package/build-module/components/collaborators-overlay/timing-utils.mjs.map +7 -0
- package/build-module/components/collaborators-overlay/use-render-cursors.mjs +1 -1
- package/build-module/components/collaborators-overlay/use-render-cursors.mjs.map +2 -2
- package/build-module/components/post-locked-modal/index.mjs +16 -3
- package/build-module/components/post-locked-modal/index.mjs.map +2 -2
- package/build-module/components/post-revisions-preview/block-diff.mjs +39 -11
- package/build-module/components/post-revisions-preview/block-diff.mjs.map +2 -2
- package/build-module/components/post-revisions-preview/diff-markers.mjs +2 -2
- package/build-module/components/post-revisions-preview/diff-markers.mjs.map +2 -2
- package/build-module/components/post-revisions-preview/revisions-canvas.mjs +1 -1
- package/build-module/components/post-revisions-preview/revisions-canvas.mjs.map +2 -2
- package/build-module/components/post-template/block-theme.mjs +7 -4
- package/build-module/components/post-template/block-theme.mjs.map +2 -2
- package/build-module/components/post-template/hooks.mjs +37 -1
- package/build-module/components/post-template/hooks.mjs.map +2 -2
- package/build-module/components/post-template/panel.mjs +5 -42
- package/build-module/components/post-template/panel.mjs.map +2 -2
- package/build-module/components/provider/use-block-editor-settings.mjs +2 -0
- package/build-module/components/provider/use-block-editor-settings.mjs.map +2 -2
- package/build-module/components/revision-block-diff/index.mjs +53 -0
- package/build-module/components/revision-block-diff/index.mjs.map +7 -0
- package/build-module/components/sidebar/dataform-post-summary.mjs +17 -2
- package/build-module/components/sidebar/dataform-post-summary.mjs.map +2 -2
- package/build-module/components/sidebar/index.mjs +5 -1
- package/build-module/components/sidebar/index.mjs.map +2 -2
- package/build-module/components/sync-connection-error-modal/index.mjs +177 -0
- package/build-module/components/sync-connection-error-modal/index.mjs.map +7 -0
- package/build-module/components/sync-connection-error-modal/use-retry-countdown.mjs +36 -0
- package/build-module/components/sync-connection-error-modal/use-retry-countdown.mjs.map +7 -0
- package/build-module/components/visual-editor/index.mjs +2 -2
- package/build-module/components/visual-editor/index.mjs.map +2 -2
- package/build-module/store/actions.mjs +1 -3
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/utils/media-finalize/index.mjs +12 -0
- package/build-module/utils/media-finalize/index.mjs.map +7 -0
- package/build-module/utils/sync-error-messages.mjs +24 -16
- package/build-module/utils/sync-error-messages.mjs.map +3 -3
- package/build-style/style-rtl.css +24 -8
- package/build-style/style.css +24 -8
- package/build-types/components/collaborators-overlay/overlay.d.ts.map +1 -1
- package/build-types/components/collaborators-overlay/timing-utils.d.ts +11 -0
- package/build-types/components/collaborators-overlay/timing-utils.d.ts.map +1 -0
- package/build-types/components/post-locked-modal/index.d.ts +2 -2
- package/build-types/components/post-locked-modal/index.d.ts.map +1 -1
- package/build-types/components/post-revisions-preview/block-diff.d.ts.map +1 -1
- package/build-types/components/post-template/block-theme.d.ts +1 -3
- package/build-types/components/post-template/block-theme.d.ts.map +1 -1
- package/build-types/components/post-template/hooks.d.ts +1 -0
- package/build-types/components/post-template/hooks.d.ts.map +1 -1
- package/build-types/components/post-template/panel.d.ts.map +1 -1
- package/build-types/components/provider/use-block-editor-settings.d.ts.map +1 -1
- package/build-types/components/revision-block-diff/index.d.ts +6 -0
- package/build-types/components/revision-block-diff/index.d.ts.map +1 -0
- package/build-types/components/sidebar/dataform-post-summary.d.ts.map +1 -1
- package/build-types/components/sidebar/index.d.ts.map +1 -1
- package/build-types/components/sync-connection-error-modal/index.d.ts +22 -0
- package/build-types/components/sync-connection-error-modal/index.d.ts.map +1 -0
- package/build-types/components/sync-connection-error-modal/use-retry-countdown.d.ts +11 -0
- package/build-types/components/sync-connection-error-modal/use-retry-countdown.d.ts.map +1 -0
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/utils/media-finalize/index.d.ts +2 -0
- package/build-types/utils/media-finalize/index.d.ts.map +1 -0
- package/build-types/utils/sync-error-messages.d.ts +17 -3
- package/build-types/utils/sync-error-messages.d.ts.map +1 -1
- package/package.json +44 -44
- package/src/components/collaborators-overlay/compute-selection.ts +13 -13
- package/src/components/collaborators-overlay/overlay.tsx +19 -0
- package/src/components/collaborators-overlay/timing-utils.ts +30 -0
- package/src/components/collaborators-overlay/use-render-cursors.ts +1 -1
- package/src/components/post-locked-modal/index.js +21 -3
- package/src/components/post-revisions-preview/block-diff.js +59 -20
- package/src/components/post-revisions-preview/diff-markers.js +2 -2
- package/src/components/post-revisions-preview/revisions-canvas.js +1 -1
- package/src/components/post-revisions-preview/test/block-diff.js +69 -31
- package/src/components/post-template/block-theme.js +4 -1
- package/src/components/post-template/hooks.js +42 -0
- package/src/components/post-template/panel.js +5 -59
- package/src/components/provider/use-block-editor-settings.js +2 -0
- package/src/components/revision-block-diff/index.js +74 -0
- package/src/components/revision-block-diff/style.scss +13 -0
- package/src/components/sidebar/dataform-post-summary.js +37 -13
- package/src/components/sidebar/index.js +2 -0
- package/src/components/sync-connection-error-modal/index.tsx +265 -0
- package/src/components/sync-connection-error-modal/style.scss +14 -0
- package/src/components/sync-connection-error-modal/use-retry-countdown.ts +57 -0
- package/src/components/visual-editor/index.js +2 -2
- package/src/store/actions.js +1 -4
- package/src/style.scss +2 -1
- package/src/utils/media-finalize/index.js +11 -0
- package/src/utils/media-finalize/test/index.js +34 -0
- package/src/utils/sync-error-messages.ts +72 -0
- package/src/utils/test/sync-error-messages.js +9 -32
- package/build/components/sync-connection-modal/index.cjs.map +0 -7
- package/build/components/sync-connection-modal/use-retry-countdown.cjs.map +0 -7
- package/build-module/components/sync-connection-modal/index.mjs +0 -170
- package/build-module/components/sync-connection-modal/index.mjs.map +0 -7
- package/build-module/components/sync-connection-modal/use-retry-countdown.mjs +0 -49
- package/build-module/components/sync-connection-modal/use-retry-countdown.mjs.map +0 -7
- package/build-types/components/sync-connection-modal/index.d.ts +0 -8
- package/build-types/components/sync-connection-modal/index.d.ts.map +0 -1
- package/build-types/components/sync-connection-modal/use-retry-countdown.d.ts +0 -9
- package/build-types/components/sync-connection-modal/use-retry-countdown.d.ts.map +0 -1
- package/src/components/sync-connection-modal/index.js +0 -206
- package/src/components/sync-connection-modal/style.scss +0 -14
- package/src/components/sync-connection-modal/use-retry-countdown.js +0 -70
- package/src/utils/sync-error-messages.js +0 -58
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect, select } from '@wordpress/data';
|
|
5
|
-
import { useCopyToClipboard } from '@wordpress/compose';
|
|
6
|
-
import { serialize } from '@wordpress/blocks';
|
|
7
|
-
import {
|
|
8
|
-
store as coreDataStore,
|
|
9
|
-
privateApis as coreDataPrivateApis,
|
|
10
|
-
} from '@wordpress/core-data';
|
|
11
|
-
import {
|
|
12
|
-
privateApis,
|
|
13
|
-
store as blockEditorStore,
|
|
14
|
-
} from '@wordpress/block-editor';
|
|
15
|
-
import {
|
|
16
|
-
Button,
|
|
17
|
-
Modal,
|
|
18
|
-
__experimentalHStack as HStack,
|
|
19
|
-
__experimentalVStack as VStack,
|
|
20
|
-
} from '@wordpress/components';
|
|
21
|
-
import { useState, useEffect, useRef } from '@wordpress/element';
|
|
22
|
-
import { __, sprintf, _n } from '@wordpress/i18n';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Internal dependencies
|
|
26
|
-
*/
|
|
27
|
-
import { getSyncErrorMessages } from '../../utils/sync-error-messages';
|
|
28
|
-
import { store as editorStore } from '../../store';
|
|
29
|
-
import { unlock } from '../../lock-unlock';
|
|
30
|
-
import { useRetryCountdown } from './use-retry-countdown';
|
|
31
|
-
|
|
32
|
-
const { BlockCanvasCover } = unlock( privateApis );
|
|
33
|
-
const { retrySyncConnection } = unlock( coreDataPrivateApis );
|
|
34
|
-
|
|
35
|
-
// Debounce time for initial disconnected status to allow connection to establish.
|
|
36
|
-
const INITIAL_DISCONNECTED_DEBOUNCE_MS = 5000;
|
|
37
|
-
|
|
38
|
-
// Debounce time for showing the disconnect dialog after the intial connection,
|
|
39
|
-
// allowing brief network interruptions to resolve.
|
|
40
|
-
const DISCONNECTED_DEBOUNCE_MS = 2000;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Sync connection modal that displays when any entity reports a disconnection.
|
|
44
|
-
* Uses BlockCanvasCover.Fill to render in the block canvas.
|
|
45
|
-
*
|
|
46
|
-
* @return {Element|null} The modal component or null if not disconnected.
|
|
47
|
-
*/
|
|
48
|
-
export function SyncConnectionModal() {
|
|
49
|
-
const { connectionState, postType } = useSelect( ( selectFn ) => {
|
|
50
|
-
const currentPostType = selectFn( editorStore ).getCurrentPostType();
|
|
51
|
-
return {
|
|
52
|
-
connectionState:
|
|
53
|
-
selectFn( coreDataStore ).getSyncConnectionStatus() || null,
|
|
54
|
-
postType: currentPostType
|
|
55
|
-
? selectFn( coreDataStore ).getPostType( currentPostType )
|
|
56
|
-
: null,
|
|
57
|
-
};
|
|
58
|
-
}, [] );
|
|
59
|
-
|
|
60
|
-
const { secondsRemaining, markRetrying } = useRetryCountdown(
|
|
61
|
-
connectionState?.retryInMs,
|
|
62
|
-
connectionState?.status
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const copyButtonRef = useCopyToClipboard( () => {
|
|
66
|
-
const blocks = select( blockEditorStore ).getBlocks();
|
|
67
|
-
return serialize( blocks );
|
|
68
|
-
} );
|
|
69
|
-
const [ syncConnectionMessage, setSyncConnectionMessage ] =
|
|
70
|
-
useState( null );
|
|
71
|
-
const debounceTimerRef = useRef( null );
|
|
72
|
-
// Track whether we've passed the initial load phase.
|
|
73
|
-
const hasInitializedRef = useRef( false );
|
|
74
|
-
|
|
75
|
-
const connectionStatus = connectionState?.status;
|
|
76
|
-
const connectionErrorCode = connectionState?.error?.code;
|
|
77
|
-
|
|
78
|
-
useEffect( () => {
|
|
79
|
-
// Clear any pending debounce timer when status changes.
|
|
80
|
-
if ( debounceTimerRef.current ) {
|
|
81
|
-
clearTimeout( debounceTimerRef.current );
|
|
82
|
-
debounceTimerRef.current = null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if ( connectionStatus === 'connected' ) {
|
|
86
|
-
hasInitializedRef.current = true;
|
|
87
|
-
setSyncConnectionMessage( null );
|
|
88
|
-
} else if ( connectionStatus === 'disconnected' ) {
|
|
89
|
-
const showModal = () => {
|
|
90
|
-
hasInitializedRef.current = true;
|
|
91
|
-
setSyncConnectionMessage(
|
|
92
|
-
getSyncErrorMessages( { code: connectionErrorCode } )
|
|
93
|
-
);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// Debounce on first load and after connection is established to allow
|
|
97
|
-
// brief network interruptions to resolve.
|
|
98
|
-
if ( hasInitializedRef.current ) {
|
|
99
|
-
debounceTimerRef.current = setTimeout(
|
|
100
|
-
showModal,
|
|
101
|
-
DISCONNECTED_DEBOUNCE_MS
|
|
102
|
-
);
|
|
103
|
-
} else {
|
|
104
|
-
debounceTimerRef.current = setTimeout(
|
|
105
|
-
showModal,
|
|
106
|
-
INITIAL_DISCONNECTED_DEBOUNCE_MS
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return () => {
|
|
112
|
-
if ( debounceTimerRef.current ) {
|
|
113
|
-
clearTimeout( debounceTimerRef.current );
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}, [ connectionStatus, connectionErrorCode ] );
|
|
117
|
-
|
|
118
|
-
if ( ! syncConnectionMessage ) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const { title, description, canRetry } = syncConnectionMessage;
|
|
123
|
-
|
|
124
|
-
let retryCountdownText;
|
|
125
|
-
if ( secondsRemaining > 0 ) {
|
|
126
|
-
retryCountdownText = sprintf(
|
|
127
|
-
/* translators: %d: number of seconds until retry */
|
|
128
|
-
_n(
|
|
129
|
-
'Retrying connection in %d second\u2026',
|
|
130
|
-
'Retrying connection in %d seconds\u2026',
|
|
131
|
-
secondsRemaining
|
|
132
|
-
),
|
|
133
|
-
secondsRemaining
|
|
134
|
-
);
|
|
135
|
-
} else if ( secondsRemaining === 0 ) {
|
|
136
|
-
retryCountdownText = __( 'Retrying\u2026' );
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
let editPostHref = 'edit.php';
|
|
140
|
-
if ( postType?.slug ) {
|
|
141
|
-
editPostHref = `edit.php?post_type=${ postType.slug }`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const isRetrying = secondsRemaining === 0;
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<BlockCanvasCover.Fill>
|
|
148
|
-
<Modal
|
|
149
|
-
overlayClassName="editor-sync-connection-modal"
|
|
150
|
-
isDismissible={ false }
|
|
151
|
-
onRequestClose={ () => {} }
|
|
152
|
-
shouldCloseOnClickOutside={ false }
|
|
153
|
-
shouldCloseOnEsc={ false }
|
|
154
|
-
size="medium"
|
|
155
|
-
title={ title }
|
|
156
|
-
>
|
|
157
|
-
<VStack spacing={ 6 }>
|
|
158
|
-
<p>{ description }</p>
|
|
159
|
-
{ retryCountdownText && (
|
|
160
|
-
<p className="editor-sync-connection-modal__retry-countdown">
|
|
161
|
-
{ retryCountdownText }
|
|
162
|
-
</p>
|
|
163
|
-
) }
|
|
164
|
-
<HStack justify="right">
|
|
165
|
-
<Button
|
|
166
|
-
__next40pxDefaultSize
|
|
167
|
-
href={ editPostHref }
|
|
168
|
-
isDestructive
|
|
169
|
-
variant="tertiary"
|
|
170
|
-
>
|
|
171
|
-
{ sprintf(
|
|
172
|
-
/* translators: %s: Post type name (e.g., "Posts", "Pages"). */
|
|
173
|
-
__( 'Back to %s' ),
|
|
174
|
-
postType?.labels?.name ?? __( 'Posts' )
|
|
175
|
-
) }
|
|
176
|
-
</Button>
|
|
177
|
-
<Button
|
|
178
|
-
__next40pxDefaultSize
|
|
179
|
-
ref={ copyButtonRef }
|
|
180
|
-
variant={ canRetry ? 'secondary' : 'primary' }
|
|
181
|
-
>
|
|
182
|
-
{ __( 'Copy Post Content' ) }
|
|
183
|
-
</Button>
|
|
184
|
-
{ canRetry && (
|
|
185
|
-
<Button
|
|
186
|
-
__next40pxDefaultSize
|
|
187
|
-
aria-disabled={ isRetrying }
|
|
188
|
-
isBusy={ isRetrying }
|
|
189
|
-
variant="primary"
|
|
190
|
-
onClick={ () => {
|
|
191
|
-
if ( isRetrying ) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
markRetrying();
|
|
195
|
-
retrySyncConnection();
|
|
196
|
-
} }
|
|
197
|
-
>
|
|
198
|
-
{ __( 'Retry' ) }
|
|
199
|
-
</Button>
|
|
200
|
-
) }
|
|
201
|
-
</HStack>
|
|
202
|
-
</VStack>
|
|
203
|
-
</Modal>
|
|
204
|
-
</BlockCanvasCover.Fill>
|
|
205
|
-
);
|
|
206
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
@use "@wordpress/base-styles/colors" as *;
|
|
2
|
-
@use "@wordpress/base-styles/z-index" as *;
|
|
3
|
-
|
|
4
|
-
.editor-sync-connection-modal {
|
|
5
|
-
z-index: z-index(".editor-sync-connection-modal");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.editor-sync-connection-modal p {
|
|
9
|
-
margin: 0;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.editor-sync-connection-modal__retry-countdown {
|
|
13
|
-
color: $gray-700;
|
|
14
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useState, useEffect, useRef } from '@wordpress/element';
|
|
5
|
-
|
|
6
|
-
const MIN_RETRYING_DISPLAY_MS = 600;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Hook that computes a countdown in seconds from a retryInMs value.
|
|
10
|
-
*
|
|
11
|
-
* @param {number|undefined} retryInMs Milliseconds until next retry.
|
|
12
|
-
* @param {string|undefined} status Current connection status.
|
|
13
|
-
* @return {Object} Object with `secondsRemaining` (number|null) and `markRetrying` callback.
|
|
14
|
-
*/
|
|
15
|
-
export function useRetryCountdown( retryInMs, status ) {
|
|
16
|
-
const [ secondsRemaining, setSecondsRemaining ] = useState( null );
|
|
17
|
-
const [ isRetrying, setIsRetrying ] = useState( false );
|
|
18
|
-
const retryAtRef = useRef( null );
|
|
19
|
-
|
|
20
|
-
// Show "Retrying…" for a minimum duration when manually triggered.
|
|
21
|
-
const markRetrying = () => setIsRetrying( true );
|
|
22
|
-
|
|
23
|
-
useEffect( () => {
|
|
24
|
-
if ( ! isRetrying ) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const id = setTimeout(
|
|
28
|
-
() => setIsRetrying( false ),
|
|
29
|
-
MIN_RETRYING_DISPLAY_MS
|
|
30
|
-
);
|
|
31
|
-
return () => clearTimeout( id );
|
|
32
|
-
}, [ isRetrying ] );
|
|
33
|
-
|
|
34
|
-
useEffect( () => {
|
|
35
|
-
// Only clear countdown when explicitly connected.
|
|
36
|
-
if ( status === 'connected' ) {
|
|
37
|
-
setSecondsRemaining( null );
|
|
38
|
-
retryAtRef.current = null;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// For transient states (e.g. 'connecting' during a retry attempt)
|
|
43
|
-
// or when retryInMs is not yet available, keep the previous
|
|
44
|
-
// countdown value to avoid a brief flash.
|
|
45
|
-
if ( status !== 'disconnected' || ! retryInMs ) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const retryAt = Date.now() + retryInMs;
|
|
50
|
-
retryAtRef.current = retryAt;
|
|
51
|
-
setSecondsRemaining( Math.ceil( retryInMs / 1000 ) );
|
|
52
|
-
|
|
53
|
-
const intervalId = setInterval( () => {
|
|
54
|
-
const remaining = Math.ceil(
|
|
55
|
-
( retryAtRef.current - Date.now() ) / 1000
|
|
56
|
-
);
|
|
57
|
-
setSecondsRemaining( Math.max( 0, remaining ) );
|
|
58
|
-
if ( remaining <= 0 ) {
|
|
59
|
-
clearInterval( intervalId );
|
|
60
|
-
setIsRetrying( true );
|
|
61
|
-
}
|
|
62
|
-
}, 1000 );
|
|
63
|
-
|
|
64
|
-
return () => clearInterval( intervalId );
|
|
65
|
-
}, [ retryInMs, status ] );
|
|
66
|
-
|
|
67
|
-
const displaySeconds = isRetrying ? 0 : secondsRemaining;
|
|
68
|
-
|
|
69
|
-
return { secondsRemaining: displaySeconds, markRetrying };
|
|
70
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Default error messages for known error codes.
|
|
8
|
-
*/
|
|
9
|
-
const ERROR_MESSAGES = {
|
|
10
|
-
'authentication-failed': {
|
|
11
|
-
title: __( 'Unable to connect' ),
|
|
12
|
-
description: __(
|
|
13
|
-
"Real-time collaboration couldn't verify your permissions. " +
|
|
14
|
-
'Check that you have access to edit this post, or contact your site administrator.'
|
|
15
|
-
),
|
|
16
|
-
canRetry: false,
|
|
17
|
-
},
|
|
18
|
-
'connection-expired': {
|
|
19
|
-
title: __( 'Connection expired' ),
|
|
20
|
-
description: __(
|
|
21
|
-
'Your connection to real-time collaboration has timed out. ' +
|
|
22
|
-
'Editing is paused to prevent conflicts with other editors.'
|
|
23
|
-
),
|
|
24
|
-
canRetry: true,
|
|
25
|
-
},
|
|
26
|
-
'connection-limit-exceeded': {
|
|
27
|
-
title: __( 'Too many editors connected' ),
|
|
28
|
-
description: __(
|
|
29
|
-
'Real-time collaboration has reached its connection limit. ' +
|
|
30
|
-
'Try again later or contact your site administrator.'
|
|
31
|
-
),
|
|
32
|
-
canRetry: true,
|
|
33
|
-
},
|
|
34
|
-
'unknown-error': {
|
|
35
|
-
title: __( 'Connection lost' ),
|
|
36
|
-
description: __(
|
|
37
|
-
'The connection to real-time collaboration was interrupted. ' +
|
|
38
|
-
'Editing is paused to prevent conflicts with other editors.'
|
|
39
|
-
),
|
|
40
|
-
canRetry: true,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Get user-facing title and description from a sync connection error.
|
|
46
|
-
*
|
|
47
|
-
* Provides default messages based on error.code.
|
|
48
|
-
*
|
|
49
|
-
* @param {Object} error - Connection error object.
|
|
50
|
-
* @return {Object} Object with title, description, and canRetry flag.
|
|
51
|
-
*/
|
|
52
|
-
export function getSyncErrorMessages( error ) {
|
|
53
|
-
if ( ERROR_MESSAGES[ error?.code ] ) {
|
|
54
|
-
return ERROR_MESSAGES[ error.code ];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return ERROR_MESSAGES[ 'unknown-error' ];
|
|
58
|
-
}
|