@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.
@@ -1,174 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- 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; } } }; }
4
- 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; } }
5
- 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; }
6
- import { EVENT_ACTION, EVENT_STATUS } from '../helpers/const';
7
- import { createLogger } from '../helpers/utils';
8
- import { StepMap, Mapping } from '@atlaskit/editor-prosemirror/transform';
9
- var logger = createLogger('Catchup', 'red');
10
-
11
- /**
12
- * Rebase the steps based on the mapping pipeline.
13
- * Some steps could be lost, if they are no longer
14
- * invalid after rebased.
15
- */
16
- export function rebaseSteps(steps, mapping) {
17
- var newSteps = [];
18
- var _iterator = _createForOfIteratorHelper(steps),
19
- _step;
20
- try {
21
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
22
- var step = _step.value;
23
- var newStep = step.map(mapping);
24
- // newStep could be null(means invalid after rebase) when can't rebase.
25
- if (newStep) {
26
- newSteps.push(newStep);
27
- }
28
- }
29
- } catch (err) {
30
- _iterator.e(err);
31
- } finally {
32
- _iterator.f();
33
- }
34
- return newSteps;
35
- }
36
-
37
- /**
38
- * Check if clientId is in list of StepMaps returned by server, to avoid duplicating content
39
- * Each time a StepMap contains the clientId, we should drop an unconfirmedStep
40
- */
41
- export function removeConfirmedSteps() {
42
- var unconfirmedSteps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
43
- var serverStepMaps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
44
- var clientId = arguments.length > 2 ? arguments[2] : undefined;
45
- var newUnconfirmedSteps = Array.from(unconfirmedSteps);
46
- for (var i = 0; i < serverStepMaps.length; i++) {
47
- if (serverStepMaps[i].clientId === clientId) {
48
- newUnconfirmedSteps.shift();
49
- }
50
- }
51
- return newUnconfirmedSteps;
52
- }
53
- export var catchup = /*#__PURE__*/function () {
54
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(opt) {
55
- var doc, serverStepMaps, serverVersion, metadata, _yield$opt$fetchCatch, _opt$analyticsHelper, currentPmVersion, unconfirmedSteps, _unconfirmedSteps2, _unconfirmedSteps, stepMaps, mapping, newUnconfirmedSteps, _opt$analyticsHelper2, _opt$analyticsHelper3;
56
- return _regeneratorRuntime.wrap(function _callee$(_context) {
57
- while (1) switch (_context.prev = _context.next) {
58
- case 0:
59
- _context.prev = 0;
60
- _context.next = 3;
61
- return opt.fetchCatchup(opt.getCurrentPmVersion(), opt.clientId);
62
- case 3:
63
- _yield$opt$fetchCatch = _context.sent;
64
- doc = _yield$opt$fetchCatch.doc;
65
- serverStepMaps = _yield$opt$fetchCatch.stepMaps;
66
- serverVersion = _yield$opt$fetchCatch.version;
67
- metadata = _yield$opt$fetchCatch.metadata;
68
- _context.next = 15;
69
- break;
70
- case 10:
71
- _context.prev = 10;
72
- _context.t0 = _context["catch"](0);
73
- (_opt$analyticsHelper = opt.analyticsHelper) === null || _opt$analyticsHelper === void 0 || _opt$analyticsHelper.sendErrorEvent(_context.t0, 'Error while fetching catchup from server');
74
- logger("Fetch catchup from server failed:", _context.t0.message);
75
- throw _context.t0;
76
- case 15:
77
- _context.prev = 15;
78
- if (doc) {
79
- currentPmVersion = opt.getCurrentPmVersion();
80
- if (typeof serverVersion === 'undefined') {
81
- logger("Could not determine server version");
82
- } else if (serverVersion <= currentPmVersion) {
83
- // there are no step maps in this case after page recovery
84
- unconfirmedSteps = opt.getUnconfirmedSteps(); // replace the entire document
85
- logger("Replacing document: ".concat(doc));
86
- logger("getting metadata: ".concat(metadata));
87
- // Replace local document and version number
88
- opt.updateDocument({
89
- doc: JSON.parse(doc),
90
- version: serverVersion,
91
- metadata: metadata,
92
- reserveCursor: true
93
- });
94
- opt.updateMetadata(metadata);
95
- if (unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length) {
96
- opt.applyLocalSteps(unconfirmedSteps);
97
- }
98
- } else {
99
- // Please, do not use those steps inside of async
100
- // method. That will lead to outdated steps
101
- _unconfirmedSteps = opt.getUnconfirmedSteps();
102
- logger("Too far behind[current: v".concat(currentPmVersion, ", server: v").concat(serverVersion, ". ").concat(serverStepMaps.length, " steps need to catchup]"));
103
- /**
104
- * Remove steps from queue where the version is older than
105
- * the version we received from service. Keep steps that might be
106
- * newer.
107
- */
108
- opt.filterQueue(function (data) {
109
- return data.version > serverVersion;
110
- });
111
-
112
- // We are too far behind - replace the entire document
113
- logger("Replacing document: ".concat(doc));
114
- logger("getting metadata: ".concat(metadata));
115
-
116
- // Replace local document and version number
117
- opt.updateDocument({
118
- doc: JSON.parse(doc),
119
- version: serverVersion,
120
- metadata: metadata,
121
- reserveCursor: true
122
- });
123
- opt.updateMetadata(metadata);
124
-
125
- // After replacing the whole document in the editor, we need to reapply the unconfirmed
126
- // steps back into the editor, so we don't lose any data. But before that, we need to rebase
127
- // those steps since their position could be changed after replacing.
128
- // https://prosemirror.net/docs/guide/#transform.rebasing
129
- if ((_unconfirmedSteps2 = _unconfirmedSteps) !== null && _unconfirmedSteps2 !== void 0 && _unconfirmedSteps2.length) {
130
- // Create StepMap from StepMap JSON
131
- // eslint-disable-next-line no-unused-vars
132
- _unconfirmedSteps = removeConfirmedSteps(_unconfirmedSteps, serverStepMaps, opt.clientId);
133
- stepMaps = serverStepMaps.map(function (_ref2) {
134
- var ranges = _ref2.ranges,
135
- inverted = _ref2.inverted;
136
- // Due to @types/prosemirror-transform mismatch with the actual
137
- // constructor, hack to set the `inverted`.
138
- var stepMap = new StepMap(ranges);
139
- stepMap.inverted = inverted;
140
- return stepMap;
141
- }); // create Mapping used for Step.map
142
- mapping = new Mapping(stepMaps);
143
- logger("".concat(_unconfirmedSteps.length, " unconfirmed steps before rebased: ").concat(JSON.stringify(_unconfirmedSteps)));
144
- newUnconfirmedSteps = rebaseSteps(_unconfirmedSteps, mapping);
145
- if ((newUnconfirmedSteps === null || newUnconfirmedSteps === void 0 ? void 0 : newUnconfirmedSteps.length) < _unconfirmedSteps.length) {
146
- // Log the dropped steps after rebase
147
- (_opt$analyticsHelper2 = opt.analyticsHelper) === null || _opt$analyticsHelper2 === void 0 || _opt$analyticsHelper2.sendActionEvent(EVENT_ACTION.DROPPED_STEPS, EVENT_STATUS.SUCCESS, {
148
- numOfDroppedSteps: _unconfirmedSteps.length - (newUnconfirmedSteps === null || newUnconfirmedSteps === void 0 ? void 0 : newUnconfirmedSteps.length)
149
- });
150
- }
151
- logger("Re-aply ".concat(newUnconfirmedSteps.length, " mapped unconfirmed steps: ").concat(JSON.stringify(newUnconfirmedSteps)));
152
- // Re-apply local steps
153
- opt.applyLocalSteps(newUnconfirmedSteps);
154
- }
155
- }
156
- }
157
- _context.next = 24;
158
- break;
159
- case 19:
160
- _context.prev = 19;
161
- _context.t1 = _context["catch"](15);
162
- (_opt$analyticsHelper3 = opt.analyticsHelper) === null || _opt$analyticsHelper3 === void 0 || _opt$analyticsHelper3.sendErrorEvent(_context.t1, 'Failed to apply catchup result in the editor');
163
- logger("Apply catchup steps failed:", _context.t1.message);
164
- throw _context.t1;
165
- case 24:
166
- case "end":
167
- return _context.stop();
168
- }
169
- }, _callee, null, [[0, 10], [15, 19]]);
170
- }));
171
- return function catchup(_x) {
172
- return _ref.apply(this, arguments);
173
- };
174
- }();
@@ -1,15 +0,0 @@
1
- import type { CatchupOptions } from '../types';
2
- import type { Step } from '@atlaskit/editor-prosemirror/transform';
3
- import { Mapping } from '@atlaskit/editor-prosemirror/transform';
4
- /**
5
- * Rebase the steps based on the mapping pipeline.
6
- * Some steps could be lost, if they are no longer
7
- * invalid after rebased.
8
- */
9
- export declare function rebaseSteps(steps: readonly Step[], mapping: Mapping): Step[];
10
- /**
11
- * Check if clientId is in list of StepMaps returned by server, to avoid duplicating content
12
- * Each time a StepMap contains the clientId, we should drop an unconfirmedStep
13
- */
14
- export declare function removeConfirmedSteps(unconfirmedSteps: readonly Step[] | undefined, serverStepMaps: any[] | undefined, clientId: string | number | undefined): Step[];
15
- export declare const catchup: (opt: CatchupOptions) => Promise<void>;
@@ -1,15 +0,0 @@
1
- import type { CatchupOptions } from '../types';
2
- import type { Step } from '@atlaskit/editor-prosemirror/transform';
3
- import { Mapping } from '@atlaskit/editor-prosemirror/transform';
4
- /**
5
- * Rebase the steps based on the mapping pipeline.
6
- * Some steps could be lost, if they are no longer
7
- * invalid after rebased.
8
- */
9
- export declare function rebaseSteps(steps: readonly Step[], mapping: Mapping): Step[];
10
- /**
11
- * Check if clientId is in list of StepMaps returned by server, to avoid duplicating content
12
- * Each time a StepMap contains the clientId, we should drop an unconfirmedStep
13
- */
14
- export declare function removeConfirmedSteps(unconfirmedSteps: readonly Step[] | undefined, serverStepMaps: any[] | undefined, clientId: string | number | undefined): Step[];
15
- export declare const catchup: (opt: CatchupOptions) => Promise<void>;