@atlaskit/collab-provider 9.41.0 → 9.41.1
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 +8 -0
- package/dist/cjs/channel.js +115 -192
- package/dist/cjs/document/document-service.js +149 -221
- package/dist/cjs/provider/index.js +1 -1
- package/dist/cjs/types.js +0 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/channel.js +0 -47
- package/dist/es2019/document/document-service.js +57 -111
- package/dist/es2019/provider/index.js +1 -1
- package/dist/es2019/types.js +0 -2
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/channel.js +115 -192
- package/dist/esm/document/document-service.js +149 -221
- package/dist/esm/provider/index.js +1 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/channel.d.ts +1 -2
- package/dist/types/document/document-service.d.ts +2 -14
- package/dist/types/types.d.ts +1 -18
- package/dist/types-ts4.5/channel.d.ts +1 -2
- package/dist/types-ts4.5/document/document-service.d.ts +2 -14
- package/dist/types-ts4.5/types.d.ts +1 -18
- package/package.json +1 -1
- package/dist/cjs/document/catchup.js +0 -183
- package/dist/es2019/document/catchup.js +0 -141
- package/dist/esm/document/catchup.js +0 -174
- package/dist/types/document/catchup.d.ts +0 -15
- package/dist/types-ts4.5/document/catchup.d.ts +0 -15
|
@@ -291,7 +291,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
291
291
|
_this.documentService = new NullDocumentService();
|
|
292
292
|
_this.api = new NullApi();
|
|
293
293
|
} else {
|
|
294
|
-
_this.documentService = new DocumentService(_this.participantsService, _this.analyticsHelper, _this.channel.
|
|
294
|
+
_this.documentService = new DocumentService(_this.participantsService, _this.analyticsHelper, _this.channel.fetchCatchupv2, _this.channel.fetchReconcile, _this.emitCallback, _this.channel.broadcast, function () {
|
|
295
295
|
return _this.userId;
|
|
296
296
|
}, _this.onErrorHandled, _this.metadataService, _this.namespaceService.getIsNamespaceLocked.bind(_this.namespaceService), _this.config.enableErrorOnFailedDocumentApply, {
|
|
297
297
|
__livePage: _this.config.__livePage || false
|
package/dist/esm/types.js
CHANGED
package/dist/types/channel.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Emitter } from './emitter';
|
|
2
|
-
import type { Config, ChannelEvent,
|
|
2
|
+
import type { Config, ChannelEvent, Catchupv2Response, ReconcileResponse } from './types';
|
|
3
3
|
import { type CatchupEventReason } from './helpers/const';
|
|
4
4
|
import type { Socket } from 'socket.io-client';
|
|
5
5
|
import type AnalyticsHelper from './analytics/analytics-helper';
|
|
@@ -40,7 +40,6 @@ export declare class Channel extends Emitter<ChannelEvent> {
|
|
|
40
40
|
private onReconnectError;
|
|
41
41
|
private onConnect;
|
|
42
42
|
private onReceiveData;
|
|
43
|
-
fetchCatchup: (fromVersion: number, clientId: number | string | undefined) => Promise<CatchupResponse>;
|
|
44
43
|
fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean | undefined, reason?: CatchupEventReason) => Promise<Catchupv2Response>;
|
|
45
44
|
fetchReconcile: (currentStateDoc: string, reason: string) => Promise<ReconcileResponse>;
|
|
46
45
|
/**
|
|
@@ -3,7 +3,7 @@ import type { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/trans
|
|
|
3
3
|
import type AnalyticsHelper from '../analytics/analytics-helper';
|
|
4
4
|
import { CatchupEventReason } from '../helpers/const';
|
|
5
5
|
import type { MetadataService } from '../metadata/metadata-service';
|
|
6
|
-
import type {
|
|
6
|
+
import type { Catchupv2Response, ChannelEvent, ReconcileResponse, StepsPayload } from '../types';
|
|
7
7
|
import type { CollabEvents, CollabInitPayload } from '@atlaskit/editor-common/collab';
|
|
8
8
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
9
9
|
import type { InternalError } from '../errors/internal-errors';
|
|
@@ -12,7 +12,6 @@ import { type DocumentServiceInterface } from './interface-document-service';
|
|
|
12
12
|
export declare class DocumentService implements DocumentServiceInterface {
|
|
13
13
|
private participantsService;
|
|
14
14
|
private analyticsHelper;
|
|
15
|
-
private fetchCatchup;
|
|
16
15
|
private fetchCatchupv2;
|
|
17
16
|
private fetchReconcile;
|
|
18
17
|
private providerEmitCallback;
|
|
@@ -35,7 +34,6 @@ export declare class DocumentService implements DocumentServiceInterface {
|
|
|
35
34
|
* @param participantsService - The participants service, used when users are detected active when making changes to the document
|
|
36
35
|
* and to emit their telepointers from steps they add
|
|
37
36
|
* @param analyticsHelper - Helper for analytics events
|
|
38
|
-
* @param fetchCatchup - StepMap based - Function to fetch "catchup" data, data required to rebase current steps to the latest version.
|
|
39
37
|
* @param fetchCatchupv2 - Step based - Function to fetch "catchupv2" data, data required to rebase current steps to the latest version.
|
|
40
38
|
* @param fetchReconcile - Function to call "reconcile" from NCS backend
|
|
41
39
|
* @param providerEmitCallback - Callback for emitting events to listeners on the provider
|
|
@@ -45,19 +43,9 @@ export declare class DocumentService implements DocumentServiceInterface {
|
|
|
45
43
|
* @param metadataService
|
|
46
44
|
* @param enableErrorOnFailedDocumentApply - Enable failed document update exceptions.
|
|
47
45
|
*/
|
|
48
|
-
constructor(participantsService: ParticipantsService, analyticsHelper: AnalyticsHelper | undefined,
|
|
46
|
+
constructor(participantsService: ParticipantsService, analyticsHelper: AnalyticsHelper | undefined, fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean) => Promise<Catchupv2Response>, fetchReconcile: (currentStateDoc: string, reason: string) => Promise<ReconcileResponse>, providerEmitCallback: (evt: keyof CollabEvents, data: any) => void, broadcast: <K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], 'timestamp'>, callback?: Function) => void, getUserId: () => string | undefined, onErrorHandled: (error: InternalError) => void, metadataService: MetadataService, isNameSpaceLocked: () => boolean, enableErrorOnFailedDocumentApply?: boolean, options?: {
|
|
49
47
|
__livePage: boolean;
|
|
50
48
|
});
|
|
51
|
-
/**
|
|
52
|
-
* To prevent calling catchup to often, use lodash throttle to reduce the frequency
|
|
53
|
-
*/
|
|
54
|
-
throttledCatchup: import("lodash").DebouncedFunc<() => Promise<void>>;
|
|
55
|
-
/**
|
|
56
|
-
* Called when:
|
|
57
|
-
* * session established(offline -> online)
|
|
58
|
-
* * try to accept steps but version is behind.
|
|
59
|
-
*/
|
|
60
|
-
private catchup;
|
|
61
49
|
/**
|
|
62
50
|
* To prevent calling catchup to often, use lodash throttle to reduce the frequency
|
|
63
51
|
* @param reason - optional reason to attach.
|
package/dist/types/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { InternalError } from './errors/internal-errors';
|
|
|
5
5
|
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
6
6
|
import type { GetUserType } from './participants/participants-helper';
|
|
7
7
|
import type AnalyticsHelper from './analytics/analytics-helper';
|
|
8
|
-
import type {
|
|
8
|
+
import type { StepJson, CollabSendableSelection, Metadata, UserPermitType, Activity } from '@atlaskit/editor-common/collab';
|
|
9
9
|
import { type CatchupEventReason } from './helpers/const';
|
|
10
10
|
export type { CollabParticipant, CollabEventInitData, CollabEventRemoteData, CollabEventConnectionData, CollabEventConnectingData, CollabEventPresenceData, ResolvedEditorState, CollabConnectedPayload, CollabConnectingPayload, CollabDisconnectedPayload, CollabInitPayload, CollabDataPayload, CollabTelepointerPayload, CollabPresencePayload, CollabMetadataPayload, CollabLocalStepsPayload, CollabCommitStatusEventPayload, CollabPermissionEventPayload, UserPermitType, CollabEvents, Metadata, StepJson, CollabEventTelepointerData, CollabSendableSelection, CollabEditProvider, NewCollabSyncUpErrorAttributes, SyncUpErrorFunction, CollabEventLocalStepData, } from '@atlaskit/editor-common/collab';
|
|
11
11
|
export interface CollabEventDisconnectedData {
|
|
@@ -190,12 +190,6 @@ export type ChannelEvent = {
|
|
|
190
190
|
};
|
|
191
191
|
status: NamespaceStatus;
|
|
192
192
|
};
|
|
193
|
-
export interface CatchupResponse {
|
|
194
|
-
doc?: string;
|
|
195
|
-
version?: number;
|
|
196
|
-
stepMaps?: any[];
|
|
197
|
-
metadata?: Metadata;
|
|
198
|
-
}
|
|
199
193
|
export interface Catchupv2Response {
|
|
200
194
|
steps?: Step[];
|
|
201
195
|
metadata?: Metadata;
|
|
@@ -206,17 +200,6 @@ export interface ReconcileResponse {
|
|
|
206
200
|
ari?: string;
|
|
207
201
|
metadata?: Metadata;
|
|
208
202
|
}
|
|
209
|
-
export interface CatchupOptions {
|
|
210
|
-
getCurrentPmVersion: () => number;
|
|
211
|
-
fetchCatchup: (fromVersion: number, clientId: number | string | undefined) => Promise<CatchupResponse>;
|
|
212
|
-
filterQueue: (condition: (stepsPayload: StepsPayload) => boolean) => void;
|
|
213
|
-
getUnconfirmedSteps: () => readonly Step[] | undefined;
|
|
214
|
-
applyLocalSteps: (steps: Step[]) => void;
|
|
215
|
-
updateDocument: ({ doc, version, metadata, reserveCursor }: CollabInitPayload) => void;
|
|
216
|
-
updateMetadata: (metadata: Metadata | undefined) => void;
|
|
217
|
-
analyticsHelper: AnalyticsHelper | undefined;
|
|
218
|
-
clientId: number | string | undefined;
|
|
219
|
-
}
|
|
220
203
|
export interface Catchupv2Options {
|
|
221
204
|
getCurrentPmVersion: () => number;
|
|
222
205
|
fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean, reason?: CatchupEventReason) => Promise<Catchupv2Response>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Emitter } from './emitter';
|
|
2
|
-
import type { Config, ChannelEvent,
|
|
2
|
+
import type { Config, ChannelEvent, Catchupv2Response, ReconcileResponse } from './types';
|
|
3
3
|
import { type CatchupEventReason } from './helpers/const';
|
|
4
4
|
import type { Socket } from 'socket.io-client';
|
|
5
5
|
import type AnalyticsHelper from './analytics/analytics-helper';
|
|
@@ -40,7 +40,6 @@ export declare class Channel extends Emitter<ChannelEvent> {
|
|
|
40
40
|
private onReconnectError;
|
|
41
41
|
private onConnect;
|
|
42
42
|
private onReceiveData;
|
|
43
|
-
fetchCatchup: (fromVersion: number, clientId: number | string | undefined) => Promise<CatchupResponse>;
|
|
44
43
|
fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean | undefined, reason?: CatchupEventReason) => Promise<Catchupv2Response>;
|
|
45
44
|
fetchReconcile: (currentStateDoc: string, reason: string) => Promise<ReconcileResponse>;
|
|
46
45
|
/**
|
|
@@ -3,7 +3,7 @@ import type { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/trans
|
|
|
3
3
|
import type AnalyticsHelper from '../analytics/analytics-helper';
|
|
4
4
|
import { CatchupEventReason } from '../helpers/const';
|
|
5
5
|
import type { MetadataService } from '../metadata/metadata-service';
|
|
6
|
-
import type {
|
|
6
|
+
import type { Catchupv2Response, ChannelEvent, ReconcileResponse, StepsPayload } from '../types';
|
|
7
7
|
import type { CollabEvents, CollabInitPayload } from '@atlaskit/editor-common/collab';
|
|
8
8
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
9
9
|
import type { InternalError } from '../errors/internal-errors';
|
|
@@ -12,7 +12,6 @@ import { type DocumentServiceInterface } from './interface-document-service';
|
|
|
12
12
|
export declare class DocumentService implements DocumentServiceInterface {
|
|
13
13
|
private participantsService;
|
|
14
14
|
private analyticsHelper;
|
|
15
|
-
private fetchCatchup;
|
|
16
15
|
private fetchCatchupv2;
|
|
17
16
|
private fetchReconcile;
|
|
18
17
|
private providerEmitCallback;
|
|
@@ -35,7 +34,6 @@ export declare class DocumentService implements DocumentServiceInterface {
|
|
|
35
34
|
* @param participantsService - The participants service, used when users are detected active when making changes to the document
|
|
36
35
|
* and to emit their telepointers from steps they add
|
|
37
36
|
* @param analyticsHelper - Helper for analytics events
|
|
38
|
-
* @param fetchCatchup - StepMap based - Function to fetch "catchup" data, data required to rebase current steps to the latest version.
|
|
39
37
|
* @param fetchCatchupv2 - Step based - Function to fetch "catchupv2" data, data required to rebase current steps to the latest version.
|
|
40
38
|
* @param fetchReconcile - Function to call "reconcile" from NCS backend
|
|
41
39
|
* @param providerEmitCallback - Callback for emitting events to listeners on the provider
|
|
@@ -45,19 +43,9 @@ export declare class DocumentService implements DocumentServiceInterface {
|
|
|
45
43
|
* @param metadataService
|
|
46
44
|
* @param enableErrorOnFailedDocumentApply - Enable failed document update exceptions.
|
|
47
45
|
*/
|
|
48
|
-
constructor(participantsService: ParticipantsService, analyticsHelper: AnalyticsHelper | undefined,
|
|
46
|
+
constructor(participantsService: ParticipantsService, analyticsHelper: AnalyticsHelper | undefined, fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean) => Promise<Catchupv2Response>, fetchReconcile: (currentStateDoc: string, reason: string) => Promise<ReconcileResponse>, providerEmitCallback: (evt: keyof CollabEvents, data: any) => void, broadcast: <K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], 'timestamp'>, callback?: Function) => void, getUserId: () => string | undefined, onErrorHandled: (error: InternalError) => void, metadataService: MetadataService, isNameSpaceLocked: () => boolean, enableErrorOnFailedDocumentApply?: boolean, options?: {
|
|
49
47
|
__livePage: boolean;
|
|
50
48
|
});
|
|
51
|
-
/**
|
|
52
|
-
* To prevent calling catchup to often, use lodash throttle to reduce the frequency
|
|
53
|
-
*/
|
|
54
|
-
throttledCatchup: import("lodash").DebouncedFunc<() => Promise<void>>;
|
|
55
|
-
/**
|
|
56
|
-
* Called when:
|
|
57
|
-
* * session established(offline -> online)
|
|
58
|
-
* * try to accept steps but version is behind.
|
|
59
|
-
*/
|
|
60
|
-
private catchup;
|
|
61
49
|
/**
|
|
62
50
|
* To prevent calling catchup to often, use lodash throttle to reduce the frequency
|
|
63
51
|
* @param reason - optional reason to attach.
|
|
@@ -5,7 +5,7 @@ import type { InternalError } from './errors/internal-errors';
|
|
|
5
5
|
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
6
6
|
import type { GetUserType } from './participants/participants-helper';
|
|
7
7
|
import type AnalyticsHelper from './analytics/analytics-helper';
|
|
8
|
-
import type {
|
|
8
|
+
import type { StepJson, CollabSendableSelection, Metadata, UserPermitType, Activity } from '@atlaskit/editor-common/collab';
|
|
9
9
|
import { type CatchupEventReason } from './helpers/const';
|
|
10
10
|
export type { CollabParticipant, CollabEventInitData, CollabEventRemoteData, CollabEventConnectionData, CollabEventConnectingData, CollabEventPresenceData, ResolvedEditorState, CollabConnectedPayload, CollabConnectingPayload, CollabDisconnectedPayload, CollabInitPayload, CollabDataPayload, CollabTelepointerPayload, CollabPresencePayload, CollabMetadataPayload, CollabLocalStepsPayload, CollabCommitStatusEventPayload, CollabPermissionEventPayload, UserPermitType, CollabEvents, Metadata, StepJson, CollabEventTelepointerData, CollabSendableSelection, CollabEditProvider, NewCollabSyncUpErrorAttributes, SyncUpErrorFunction, CollabEventLocalStepData, } from '@atlaskit/editor-common/collab';
|
|
11
11
|
export interface CollabEventDisconnectedData {
|
|
@@ -190,12 +190,6 @@ export type ChannelEvent = {
|
|
|
190
190
|
};
|
|
191
191
|
status: NamespaceStatus;
|
|
192
192
|
};
|
|
193
|
-
export interface CatchupResponse {
|
|
194
|
-
doc?: string;
|
|
195
|
-
version?: number;
|
|
196
|
-
stepMaps?: any[];
|
|
197
|
-
metadata?: Metadata;
|
|
198
|
-
}
|
|
199
193
|
export interface Catchupv2Response {
|
|
200
194
|
steps?: Step[];
|
|
201
195
|
metadata?: Metadata;
|
|
@@ -206,17 +200,6 @@ export interface ReconcileResponse {
|
|
|
206
200
|
ari?: string;
|
|
207
201
|
metadata?: Metadata;
|
|
208
202
|
}
|
|
209
|
-
export interface CatchupOptions {
|
|
210
|
-
getCurrentPmVersion: () => number;
|
|
211
|
-
fetchCatchup: (fromVersion: number, clientId: number | string | undefined) => Promise<CatchupResponse>;
|
|
212
|
-
filterQueue: (condition: (stepsPayload: StepsPayload) => boolean) => void;
|
|
213
|
-
getUnconfirmedSteps: () => readonly Step[] | undefined;
|
|
214
|
-
applyLocalSteps: (steps: Step[]) => void;
|
|
215
|
-
updateDocument: ({ doc, version, metadata, reserveCursor }: CollabInitPayload) => void;
|
|
216
|
-
updateMetadata: (metadata: Metadata | undefined) => void;
|
|
217
|
-
analyticsHelper: AnalyticsHelper | undefined;
|
|
218
|
-
clientId: number | string | undefined;
|
|
219
|
-
}
|
|
220
203
|
export interface Catchupv2Options {
|
|
221
204
|
getCurrentPmVersion: () => number;
|
|
222
205
|
fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean, reason?: CatchupEventReason) => Promise<Catchupv2Response>;
|
package/package.json
CHANGED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.catchup = void 0;
|
|
8
|
-
exports.rebaseSteps = rebaseSteps;
|
|
9
|
-
exports.removeConfirmedSteps = removeConfirmedSteps;
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
-
var _const = require("../helpers/const");
|
|
13
|
-
var _utils = require("../helpers/utils");
|
|
14
|
-
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
15
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
16
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
18
|
-
var logger = (0, _utils.createLogger)('Catchup', 'red');
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Rebase the steps based on the mapping pipeline.
|
|
22
|
-
* Some steps could be lost, if they are no longer
|
|
23
|
-
* invalid after rebased.
|
|
24
|
-
*/
|
|
25
|
-
function rebaseSteps(steps, mapping) {
|
|
26
|
-
var newSteps = [];
|
|
27
|
-
var _iterator = _createForOfIteratorHelper(steps),
|
|
28
|
-
_step;
|
|
29
|
-
try {
|
|
30
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
31
|
-
var step = _step.value;
|
|
32
|
-
var newStep = step.map(mapping);
|
|
33
|
-
// newStep could be null(means invalid after rebase) when can't rebase.
|
|
34
|
-
if (newStep) {
|
|
35
|
-
newSteps.push(newStep);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
} catch (err) {
|
|
39
|
-
_iterator.e(err);
|
|
40
|
-
} finally {
|
|
41
|
-
_iterator.f();
|
|
42
|
-
}
|
|
43
|
-
return newSteps;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Check if clientId is in list of StepMaps returned by server, to avoid duplicating content
|
|
48
|
-
* Each time a StepMap contains the clientId, we should drop an unconfirmedStep
|
|
49
|
-
*/
|
|
50
|
-
function removeConfirmedSteps() {
|
|
51
|
-
var unconfirmedSteps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
52
|
-
var serverStepMaps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
53
|
-
var clientId = arguments.length > 2 ? arguments[2] : undefined;
|
|
54
|
-
var newUnconfirmedSteps = Array.from(unconfirmedSteps);
|
|
55
|
-
for (var i = 0; i < serverStepMaps.length; i++) {
|
|
56
|
-
if (serverStepMaps[i].clientId === clientId) {
|
|
57
|
-
newUnconfirmedSteps.shift();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return newUnconfirmedSteps;
|
|
61
|
-
}
|
|
62
|
-
var catchup = exports.catchup = /*#__PURE__*/function () {
|
|
63
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(opt) {
|
|
64
|
-
var doc, serverStepMaps, serverVersion, metadata, _yield$opt$fetchCatch, _opt$analyticsHelper, currentPmVersion, unconfirmedSteps, _unconfirmedSteps2, _unconfirmedSteps, stepMaps, mapping, newUnconfirmedSteps, _opt$analyticsHelper2, _opt$analyticsHelper3;
|
|
65
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
66
|
-
while (1) switch (_context.prev = _context.next) {
|
|
67
|
-
case 0:
|
|
68
|
-
_context.prev = 0;
|
|
69
|
-
_context.next = 3;
|
|
70
|
-
return opt.fetchCatchup(opt.getCurrentPmVersion(), opt.clientId);
|
|
71
|
-
case 3:
|
|
72
|
-
_yield$opt$fetchCatch = _context.sent;
|
|
73
|
-
doc = _yield$opt$fetchCatch.doc;
|
|
74
|
-
serverStepMaps = _yield$opt$fetchCatch.stepMaps;
|
|
75
|
-
serverVersion = _yield$opt$fetchCatch.version;
|
|
76
|
-
metadata = _yield$opt$fetchCatch.metadata;
|
|
77
|
-
_context.next = 15;
|
|
78
|
-
break;
|
|
79
|
-
case 10:
|
|
80
|
-
_context.prev = 10;
|
|
81
|
-
_context.t0 = _context["catch"](0);
|
|
82
|
-
(_opt$analyticsHelper = opt.analyticsHelper) === null || _opt$analyticsHelper === void 0 || _opt$analyticsHelper.sendErrorEvent(_context.t0, 'Error while fetching catchup from server');
|
|
83
|
-
logger("Fetch catchup from server failed:", _context.t0.message);
|
|
84
|
-
throw _context.t0;
|
|
85
|
-
case 15:
|
|
86
|
-
_context.prev = 15;
|
|
87
|
-
if (doc) {
|
|
88
|
-
currentPmVersion = opt.getCurrentPmVersion();
|
|
89
|
-
if (typeof serverVersion === 'undefined') {
|
|
90
|
-
logger("Could not determine server version");
|
|
91
|
-
} else if (serverVersion <= currentPmVersion) {
|
|
92
|
-
// there are no step maps in this case after page recovery
|
|
93
|
-
unconfirmedSteps = opt.getUnconfirmedSteps(); // replace the entire document
|
|
94
|
-
logger("Replacing document: ".concat(doc));
|
|
95
|
-
logger("getting metadata: ".concat(metadata));
|
|
96
|
-
// Replace local document and version number
|
|
97
|
-
opt.updateDocument({
|
|
98
|
-
doc: JSON.parse(doc),
|
|
99
|
-
version: serverVersion,
|
|
100
|
-
metadata: metadata,
|
|
101
|
-
reserveCursor: true
|
|
102
|
-
});
|
|
103
|
-
opt.updateMetadata(metadata);
|
|
104
|
-
if (unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length) {
|
|
105
|
-
opt.applyLocalSteps(unconfirmedSteps);
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
// Please, do not use those steps inside of async
|
|
109
|
-
// method. That will lead to outdated steps
|
|
110
|
-
_unconfirmedSteps = opt.getUnconfirmedSteps();
|
|
111
|
-
logger("Too far behind[current: v".concat(currentPmVersion, ", server: v").concat(serverVersion, ". ").concat(serverStepMaps.length, " steps need to catchup]"));
|
|
112
|
-
/**
|
|
113
|
-
* Remove steps from queue where the version is older than
|
|
114
|
-
* the version we received from service. Keep steps that might be
|
|
115
|
-
* newer.
|
|
116
|
-
*/
|
|
117
|
-
opt.filterQueue(function (data) {
|
|
118
|
-
return data.version > serverVersion;
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// We are too far behind - replace the entire document
|
|
122
|
-
logger("Replacing document: ".concat(doc));
|
|
123
|
-
logger("getting metadata: ".concat(metadata));
|
|
124
|
-
|
|
125
|
-
// Replace local document and version number
|
|
126
|
-
opt.updateDocument({
|
|
127
|
-
doc: JSON.parse(doc),
|
|
128
|
-
version: serverVersion,
|
|
129
|
-
metadata: metadata,
|
|
130
|
-
reserveCursor: true
|
|
131
|
-
});
|
|
132
|
-
opt.updateMetadata(metadata);
|
|
133
|
-
|
|
134
|
-
// After replacing the whole document in the editor, we need to reapply the unconfirmed
|
|
135
|
-
// steps back into the editor, so we don't lose any data. But before that, we need to rebase
|
|
136
|
-
// those steps since their position could be changed after replacing.
|
|
137
|
-
// https://prosemirror.net/docs/guide/#transform.rebasing
|
|
138
|
-
if ((_unconfirmedSteps2 = _unconfirmedSteps) !== null && _unconfirmedSteps2 !== void 0 && _unconfirmedSteps2.length) {
|
|
139
|
-
// Create StepMap from StepMap JSON
|
|
140
|
-
// eslint-disable-next-line no-unused-vars
|
|
141
|
-
_unconfirmedSteps = removeConfirmedSteps(_unconfirmedSteps, serverStepMaps, opt.clientId);
|
|
142
|
-
stepMaps = serverStepMaps.map(function (_ref2) {
|
|
143
|
-
var ranges = _ref2.ranges,
|
|
144
|
-
inverted = _ref2.inverted;
|
|
145
|
-
// Due to @types/prosemirror-transform mismatch with the actual
|
|
146
|
-
// constructor, hack to set the `inverted`.
|
|
147
|
-
var stepMap = new _transform.StepMap(ranges);
|
|
148
|
-
stepMap.inverted = inverted;
|
|
149
|
-
return stepMap;
|
|
150
|
-
}); // create Mapping used for Step.map
|
|
151
|
-
mapping = new _transform.Mapping(stepMaps);
|
|
152
|
-
logger("".concat(_unconfirmedSteps.length, " unconfirmed steps before rebased: ").concat(JSON.stringify(_unconfirmedSteps)));
|
|
153
|
-
newUnconfirmedSteps = rebaseSteps(_unconfirmedSteps, mapping);
|
|
154
|
-
if ((newUnconfirmedSteps === null || newUnconfirmedSteps === void 0 ? void 0 : newUnconfirmedSteps.length) < _unconfirmedSteps.length) {
|
|
155
|
-
// Log the dropped steps after rebase
|
|
156
|
-
(_opt$analyticsHelper2 = opt.analyticsHelper) === null || _opt$analyticsHelper2 === void 0 || _opt$analyticsHelper2.sendActionEvent(_const.EVENT_ACTION.DROPPED_STEPS, _const.EVENT_STATUS.SUCCESS, {
|
|
157
|
-
numOfDroppedSteps: _unconfirmedSteps.length - (newUnconfirmedSteps === null || newUnconfirmedSteps === void 0 ? void 0 : newUnconfirmedSteps.length)
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
logger("Re-aply ".concat(newUnconfirmedSteps.length, " mapped unconfirmed steps: ").concat(JSON.stringify(newUnconfirmedSteps)));
|
|
161
|
-
// Re-apply local steps
|
|
162
|
-
opt.applyLocalSteps(newUnconfirmedSteps);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
_context.next = 24;
|
|
167
|
-
break;
|
|
168
|
-
case 19:
|
|
169
|
-
_context.prev = 19;
|
|
170
|
-
_context.t1 = _context["catch"](15);
|
|
171
|
-
(_opt$analyticsHelper3 = opt.analyticsHelper) === null || _opt$analyticsHelper3 === void 0 || _opt$analyticsHelper3.sendErrorEvent(_context.t1, 'Failed to apply catchup result in the editor');
|
|
172
|
-
logger("Apply catchup steps failed:", _context.t1.message);
|
|
173
|
-
throw _context.t1;
|
|
174
|
-
case 24:
|
|
175
|
-
case "end":
|
|
176
|
-
return _context.stop();
|
|
177
|
-
}
|
|
178
|
-
}, _callee, null, [[0, 10], [15, 19]]);
|
|
179
|
-
}));
|
|
180
|
-
return function catchup(_x) {
|
|
181
|
-
return _ref.apply(this, arguments);
|
|
182
|
-
};
|
|
183
|
-
}();
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { EVENT_ACTION, EVENT_STATUS } from '../helpers/const';
|
|
2
|
-
import { createLogger } from '../helpers/utils';
|
|
3
|
-
import { StepMap, Mapping } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
-
const logger = createLogger('Catchup', 'red');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Rebase the steps based on the mapping pipeline.
|
|
8
|
-
* Some steps could be lost, if they are no longer
|
|
9
|
-
* invalid after rebased.
|
|
10
|
-
*/
|
|
11
|
-
export function rebaseSteps(steps, mapping) {
|
|
12
|
-
const newSteps = [];
|
|
13
|
-
for (const step of steps) {
|
|
14
|
-
const newStep = step.map(mapping);
|
|
15
|
-
// newStep could be null(means invalid after rebase) when can't rebase.
|
|
16
|
-
if (newStep) {
|
|
17
|
-
newSteps.push(newStep);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return newSteps;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Check if clientId is in list of StepMaps returned by server, to avoid duplicating content
|
|
25
|
-
* Each time a StepMap contains the clientId, we should drop an unconfirmedStep
|
|
26
|
-
*/
|
|
27
|
-
export function removeConfirmedSteps(unconfirmedSteps = [], serverStepMaps = [], clientId) {
|
|
28
|
-
let newUnconfirmedSteps = Array.from(unconfirmedSteps);
|
|
29
|
-
for (let i = 0; i < serverStepMaps.length; i++) {
|
|
30
|
-
if (serverStepMaps[i].clientId === clientId) {
|
|
31
|
-
newUnconfirmedSteps.shift();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return newUnconfirmedSteps;
|
|
35
|
-
}
|
|
36
|
-
export const catchup = async opt => {
|
|
37
|
-
let doc, serverStepMaps, serverVersion, metadata;
|
|
38
|
-
try {
|
|
39
|
-
({
|
|
40
|
-
doc,
|
|
41
|
-
stepMaps: serverStepMaps,
|
|
42
|
-
version: serverVersion,
|
|
43
|
-
metadata
|
|
44
|
-
} = await opt.fetchCatchup(opt.getCurrentPmVersion(), opt.clientId));
|
|
45
|
-
} catch (error) {
|
|
46
|
-
var _opt$analyticsHelper;
|
|
47
|
-
(_opt$analyticsHelper = opt.analyticsHelper) === null || _opt$analyticsHelper === void 0 ? void 0 : _opt$analyticsHelper.sendErrorEvent(error, 'Error while fetching catchup from server');
|
|
48
|
-
logger(`Fetch catchup from server failed:`, error.message);
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
if (doc) {
|
|
53
|
-
const currentPmVersion = opt.getCurrentPmVersion();
|
|
54
|
-
if (typeof serverVersion === 'undefined') {
|
|
55
|
-
logger(`Could not determine server version`);
|
|
56
|
-
} else if (serverVersion <= currentPmVersion) {
|
|
57
|
-
// there are no step maps in this case after page recovery
|
|
58
|
-
const unconfirmedSteps = opt.getUnconfirmedSteps();
|
|
59
|
-
|
|
60
|
-
// replace the entire document
|
|
61
|
-
logger(`Replacing document: ${doc}`);
|
|
62
|
-
logger(`getting metadata: ${metadata}`);
|
|
63
|
-
// Replace local document and version number
|
|
64
|
-
opt.updateDocument({
|
|
65
|
-
doc: JSON.parse(doc),
|
|
66
|
-
version: serverVersion,
|
|
67
|
-
metadata,
|
|
68
|
-
reserveCursor: true
|
|
69
|
-
});
|
|
70
|
-
opt.updateMetadata(metadata);
|
|
71
|
-
if (unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length) {
|
|
72
|
-
opt.applyLocalSteps(unconfirmedSteps);
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
var _unconfirmedSteps;
|
|
76
|
-
// Please, do not use those steps inside of async
|
|
77
|
-
// method. That will lead to outdated steps
|
|
78
|
-
let unconfirmedSteps = opt.getUnconfirmedSteps();
|
|
79
|
-
logger(`Too far behind[current: v${currentPmVersion}, server: v${serverVersion}. ${serverStepMaps.length} steps need to catchup]`);
|
|
80
|
-
/**
|
|
81
|
-
* Remove steps from queue where the version is older than
|
|
82
|
-
* the version we received from service. Keep steps that might be
|
|
83
|
-
* newer.
|
|
84
|
-
*/
|
|
85
|
-
opt.filterQueue(data => data.version > serverVersion);
|
|
86
|
-
|
|
87
|
-
// We are too far behind - replace the entire document
|
|
88
|
-
logger(`Replacing document: ${doc}`);
|
|
89
|
-
logger(`getting metadata: ${metadata}`);
|
|
90
|
-
|
|
91
|
-
// Replace local document and version number
|
|
92
|
-
opt.updateDocument({
|
|
93
|
-
doc: JSON.parse(doc),
|
|
94
|
-
version: serverVersion,
|
|
95
|
-
metadata,
|
|
96
|
-
reserveCursor: true
|
|
97
|
-
});
|
|
98
|
-
opt.updateMetadata(metadata);
|
|
99
|
-
|
|
100
|
-
// After replacing the whole document in the editor, we need to reapply the unconfirmed
|
|
101
|
-
// steps back into the editor, so we don't lose any data. But before that, we need to rebase
|
|
102
|
-
// those steps since their position could be changed after replacing.
|
|
103
|
-
// https://prosemirror.net/docs/guide/#transform.rebasing
|
|
104
|
-
if ((_unconfirmedSteps = unconfirmedSteps) !== null && _unconfirmedSteps !== void 0 && _unconfirmedSteps.length) {
|
|
105
|
-
// Create StepMap from StepMap JSON
|
|
106
|
-
// eslint-disable-next-line no-unused-vars
|
|
107
|
-
unconfirmedSteps = removeConfirmedSteps(unconfirmedSteps, serverStepMaps, opt.clientId);
|
|
108
|
-
const stepMaps = serverStepMaps.map(({
|
|
109
|
-
ranges,
|
|
110
|
-
inverted
|
|
111
|
-
}) => {
|
|
112
|
-
// Due to @types/prosemirror-transform mismatch with the actual
|
|
113
|
-
// constructor, hack to set the `inverted`.
|
|
114
|
-
const stepMap = new StepMap(ranges);
|
|
115
|
-
stepMap.inverted = inverted;
|
|
116
|
-
return stepMap;
|
|
117
|
-
});
|
|
118
|
-
// create Mapping used for Step.map
|
|
119
|
-
const mapping = new Mapping(stepMaps);
|
|
120
|
-
logger(`${unconfirmedSteps.length} unconfirmed steps before rebased: ${JSON.stringify(unconfirmedSteps)}`);
|
|
121
|
-
const newUnconfirmedSteps = rebaseSteps(unconfirmedSteps, mapping);
|
|
122
|
-
if ((newUnconfirmedSteps === null || newUnconfirmedSteps === void 0 ? void 0 : newUnconfirmedSteps.length) < unconfirmedSteps.length) {
|
|
123
|
-
var _opt$analyticsHelper2;
|
|
124
|
-
// Log the dropped steps after rebase
|
|
125
|
-
(_opt$analyticsHelper2 = opt.analyticsHelper) === null || _opt$analyticsHelper2 === void 0 ? void 0 : _opt$analyticsHelper2.sendActionEvent(EVENT_ACTION.DROPPED_STEPS, EVENT_STATUS.SUCCESS, {
|
|
126
|
-
numOfDroppedSteps: unconfirmedSteps.length - (newUnconfirmedSteps === null || newUnconfirmedSteps === void 0 ? void 0 : newUnconfirmedSteps.length)
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
logger(`Re-aply ${newUnconfirmedSteps.length} mapped unconfirmed steps: ${JSON.stringify(newUnconfirmedSteps)}`);
|
|
130
|
-
// Re-apply local steps
|
|
131
|
-
opt.applyLocalSteps(newUnconfirmedSteps);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
} catch (error) {
|
|
136
|
-
var _opt$analyticsHelper3;
|
|
137
|
-
(_opt$analyticsHelper3 = opt.analyticsHelper) === null || _opt$analyticsHelper3 === void 0 ? void 0 : _opt$analyticsHelper3.sendErrorEvent(error, 'Failed to apply catchup result in the editor');
|
|
138
|
-
logger(`Apply catchup steps failed:`, error.message);
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
};
|