@atlaskit/collab-provider 10.14.3 → 10.15.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 (38) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/document/document-service.js +4 -1
  3. package/dist/cjs/document/getConflictChanges.js +23 -24
  4. package/dist/cjs/participants/participants-helper.js +79 -2
  5. package/dist/cjs/participants/participants-service.js +281 -24
  6. package/dist/cjs/participants/participants-state.js +35 -0
  7. package/dist/cjs/provider/commit-step.js +1 -1
  8. package/dist/cjs/provider/index.js +56 -11
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/es2019/document/document-service.js +4 -1
  11. package/dist/es2019/document/getConflictChanges.js +23 -24
  12. package/dist/es2019/participants/participants-helper.js +60 -1
  13. package/dist/es2019/participants/participants-service.js +207 -21
  14. package/dist/es2019/participants/participants-state.js +34 -0
  15. package/dist/es2019/provider/commit-step.js +1 -1
  16. package/dist/es2019/provider/index.js +34 -7
  17. package/dist/es2019/version-wrapper.js +1 -1
  18. package/dist/esm/document/document-service.js +4 -1
  19. package/dist/esm/document/getConflictChanges.js +23 -24
  20. package/dist/esm/participants/participants-helper.js +78 -1
  21. package/dist/esm/participants/participants-service.js +282 -25
  22. package/dist/esm/participants/participants-state.js +35 -0
  23. package/dist/esm/provider/commit-step.js +1 -1
  24. package/dist/esm/provider/index.js +56 -11
  25. package/dist/esm/version-wrapper.js +1 -1
  26. package/dist/types/document/getConflictChanges.d.ts +2 -4
  27. package/dist/types/participants/participants-helper.d.ts +28 -1
  28. package/dist/types/participants/participants-service.d.ts +76 -7
  29. package/dist/types/participants/participants-state.d.ts +12 -0
  30. package/dist/types/provider/index.d.ts +9 -6
  31. package/dist/types/types.d.ts +9 -1
  32. package/dist/types-ts4.5/document/getConflictChanges.d.ts +2 -4
  33. package/dist/types-ts4.5/participants/participants-helper.d.ts +28 -1
  34. package/dist/types-ts4.5/participants/participants-service.d.ts +76 -7
  35. package/dist/types-ts4.5/participants/participants-state.d.ts +12 -0
  36. package/dist/types-ts4.5/provider/index.d.ts +9 -6
  37. package/dist/types-ts4.5/types.d.ts +9 -1
  38. package/package.json +4 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @atlaskit/collab-provider
2
2
 
3
+ ## 10.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#157909](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/157909)
8
+ [`384136c930190`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/384136c930190) -
9
+ Add support for initializing collab-provider with presenceActivity
10
+
11
+ ## 10.14.4
12
+
13
+ ### Patch Changes
14
+
15
+ - [#144227](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/144227)
16
+ [`6da190d8e3a24`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6da190d8e3a24) -
17
+ Add ability to rebase drag and drop content
18
+ - [#155123](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/155123)
19
+ [`51d32b995a851`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/51d32b995a851) -
20
+ ED-27636 Offline Editing: Add catchup reason and other metadata to catchup failure error log in
21
+ collab provider.
22
+ - Updated dependencies
23
+
3
24
  ## 10.14.3
4
25
 
5
26
  ### Patch Changes
@@ -151,7 +151,10 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
151
151
  _context.t0 = _context["catch"](8);
152
152
  _latency = new Date().getTime() - start;
153
153
  (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 || _this$analyticsHelper3.sendActionEvent(_const.EVENT_ACTION.CATCHUP, _const.EVENT_STATUS.FAILURE, {
154
- latency: _latency
154
+ latency: _latency,
155
+ reason: reason,
156
+ unconfirmedStepsLength: reconnectionMetadata === null || reconnectionMetadata === void 0 ? void 0 : reconnectionMetadata.unconfirmedStepsLength,
157
+ disconnectionPeriodSeconds: reconnectionMetadata === null || reconnectionMetadata === void 0 ? void 0 : reconnectionMetadata.disconnectionPeriodSeconds
155
158
  });
156
159
  case 20:
157
160
  _context.prev = 20;
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.getConflictChanges = getConflictChanges;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _prosemirrorChangeset = require("prosemirror-changeset");
10
+ var _prosemirrorCollab = require("@atlaskit/prosemirror-collab");
10
11
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
12
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
13
  var simplifySteps = function simplifySteps(steps) {
@@ -77,36 +78,34 @@ var getConflicts = function getConflicts(_ref) {
77
78
  };
78
79
 
79
80
  /**
80
- * Almost a copy of the rebaseSteps in the collab algorithm (which gets called
81
- * synchronously after this).
82
- *
83
- * This also tracks the intermediate documents so we can generate the changesets
84
- * to use for finding any overlapping regions.
81
+ * This runs a collab rebase (that is run synchronously after this)
82
+ * and extracts the local doc (before changes), remote doc and the
83
+ * mapping to determine any conflicts.
85
84
  * See: `packages/editor/prosemirror-collab/src/index.ts`
86
85
  */
87
86
  var rebaseSteps = function rebaseSteps(_ref2) {
88
- var _tr$mapping$maps;
87
+ var _tr$mapping$maps, _tr$docs, _tr$docs2;
89
88
  var localSteps = _ref2.localSteps,
90
89
  remoteSteps = _ref2.remoteSteps,
91
90
  tr = _ref2.tr;
92
- for (var i = (localSteps === null || localSteps === void 0 ? void 0 : localSteps.length) - 1; i >= 0; i--) {
93
- tr.step(localSteps[i].inverted);
94
- }
95
- var originalDoc = tr.doc;
96
- var mapStart = (_tr$mapping$maps = tr.mapping.maps) === null || _tr$mapping$maps === void 0 ? void 0 : _tr$mapping$maps.length;
97
- for (var _i = 0; _i < remoteSteps.length; _i++) {
98
- tr.step(remoteSteps[_i]);
99
- }
100
- var remoteDoc = tr.doc;
101
- for (var _i2 = 0, mapFrom = localSteps.length; _i2 < localSteps.length; _i2++) {
102
- var mapped = localSteps[_i2].step.map(tr.mapping.slice(mapFrom));
103
- mapFrom--;
104
- if (mapped && !tr.maybeStep(mapped).failed) {
105
- // Open ticket for setMirror https://github.com/ProseMirror/prosemirror/issues/869
106
- // @ts-expect-error
107
- tr.mapping.setMirror(mapFrom, tr.steps.length - 1);
108
- }
109
- }
91
+ var originalMapsLength = (_tr$mapping$maps = tr.mapping.maps) === null || _tr$mapping$maps === void 0 ? void 0 : _tr$mapping$maps.length;
92
+ var originalDocsLength = tr.docs.length;
93
+ (0, _prosemirrorCollab.rebaseSteps)(localSteps, remoteSteps, tr);
94
+ /**
95
+ * `tr.docs` contains the documents before each change.
96
+ *
97
+ * To get "originalDoc" we need to get the document immediately after the local steps are inverted
98
+ * which is the equal to the number of local steps. If there are no remote steps this will be undefined and
99
+ * the most current document is appropriate
100
+ *
101
+ * To get the "remoteDoc" we need to get the document immediately after the local steps have been inverted
102
+ * and the remote steps re-applied. If there are no local steps or they are all lost in rebase this will be
103
+ * undefined and the most current document is appropriate
104
+ *
105
+ */
106
+ var originalDoc = (_tr$docs = tr.docs[originalDocsLength + localSteps.length]) !== null && _tr$docs !== void 0 ? _tr$docs : tr.doc;
107
+ var remoteDoc = (_tr$docs2 = tr.docs[originalDocsLength + localSteps.length + remoteSteps.length]) !== null && _tr$docs2 !== void 0 ? _tr$docs2 : tr.doc;
108
+ var mapStart = originalMapsLength + localSteps.length;
110
109
  return {
111
110
  mapStart: mapStart,
112
111
  originalDoc: originalDoc,
@@ -4,13 +4,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.createParticipantFromPayload = exports.PARTICIPANT_UPDATE_INTERVAL = void 0;
7
+ exports.fetchParticipants = exports.createParticipantFromPayload = exports.PARTICIPANT_UPDATE_INTERVAL = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
11
  var PARTICIPANT_UPDATE_INTERVAL = exports.PARTICIPANT_UPDATE_INTERVAL = 300 * 1000; // 300 seconds
11
12
 
12
13
  // Names are hard
13
14
 
15
+ var DEFAULT_BATCH_FETCH_SIZE = 25;
14
16
  var createParticipantFromPayload = exports.createParticipantFromPayload = /*#__PURE__*/function () {
15
17
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(payload, getUser) {
16
18
  var sessionId, timestamp, clientId, userId, permit, presenceId, presenceActivity, user, participant;
@@ -33,7 +35,8 @@ var createParticipantFromPayload = exports.createParticipantFromPayload = /*#__P
33
35
  permit: permit,
34
36
  isGuest: user === null || user === void 0 ? void 0 : user.isGuest,
35
37
  presenceId: presenceId,
36
- presenceActivity: presenceActivity
38
+ presenceActivity: presenceActivity,
39
+ isHydrated: !!user
37
40
  };
38
41
  return _context.abrupt("return", participant);
39
42
  case 6:
@@ -45,4 +48,78 @@ var createParticipantFromPayload = exports.createParticipantFromPayload = /*#__P
45
48
  return function createParticipantFromPayload(_x, _x2) {
46
49
  return _ref.apply(this, arguments);
47
50
  };
51
+ }();
52
+
53
+ /**
54
+ * Will use the getUsers callback from batchProps to fetch users
55
+ *
56
+ * 1. Determine all the participants that need to be hydrated
57
+ * 2. Only fetch a subset of those participants based on batchSize
58
+ * 3. Of the users fetched, find all of those users' sessions and mark those entries as hydrated
59
+ *
60
+ * @param participantsState
61
+ * @param batchProps
62
+ * @returns
63
+ * @example
64
+ */
65
+ var fetchParticipants = exports.fetchParticipants = /*#__PURE__*/function () {
66
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(participantsState, batchProps) {
67
+ var _batchProps$batchSize, batchSize, getUsers, participantsToHydrate, participants, aaids, users, hydratedParticipants;
68
+ return _regenerator.default.wrap(function _callee2$(_context2) {
69
+ while (1) switch (_context2.prev = _context2.next) {
70
+ case 0:
71
+ _batchProps$batchSize = batchProps.batchSize, batchSize = _batchProps$batchSize === void 0 ? DEFAULT_BATCH_FETCH_SIZE : _batchProps$batchSize, getUsers = batchProps.getUsers;
72
+ participantsToHydrate = participantsState.getUniqueParticipants({
73
+ isHydrated: false
74
+ });
75
+ participants = participantsToHydrate.splice(0, batchSize);
76
+ if (participants.length) {
77
+ _context2.next = 5;
78
+ break;
79
+ }
80
+ return _context2.abrupt("return", []);
81
+ case 5:
82
+ aaids = new Set();
83
+ participants.forEach(function (p) {
84
+ aaids.add(p.userId);
85
+ });
86
+ _context2.next = 9;
87
+ return getUsers === null || getUsers === void 0 ? void 0 : getUsers((0, _toConsumableArray2.default)(aaids.values()));
88
+ case 9:
89
+ users = _context2.sent;
90
+ hydratedParticipants = [];
91
+ users === null || users === void 0 || users.forEach(function (user) {
92
+ // find all sessions of the user we just hydrated and populate data
93
+ participantsState.getParticipants().filter(function (p) {
94
+ return p.userId === user.userId;
95
+ }).forEach(function (participant) {
96
+ var sessionId = participant.sessionId;
97
+ var hydratedParticipant = {
98
+ name: user.name,
99
+ avatar: user.avatar,
100
+ email: user.email,
101
+ userId: user.userId,
102
+ isGuest: user.isGuest,
103
+ sessionId: sessionId,
104
+ lastActive: participant.lastActive,
105
+ clientId: participant.clientId,
106
+ permit: participant.permit,
107
+ presenceId: participant.presenceId,
108
+ presenceActivity: participant.presenceActivity,
109
+ isHydrated: true
110
+ };
111
+ participantsState.setBySessionId(sessionId, hydratedParticipant);
112
+ hydratedParticipants.push(hydratedParticipant);
113
+ });
114
+ });
115
+ return _context2.abrupt("return", hydratedParticipants);
116
+ case 13:
117
+ case "end":
118
+ return _context2.stop();
119
+ }
120
+ }, _callee2);
121
+ }));
122
+ return function fetchParticipants(_x3, _x4) {
123
+ return _ref2.apply(this, arguments);
124
+ };
48
125
  }();