@atlaskit/editor-plugin-collab-edit 2.0.2 → 2.1.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 +20 -0
- package/dist/cjs/pm-plugins/events/initialize.js +1 -0
- package/dist/cjs/pm-plugins/main/plugin-state.js +15 -4
- package/dist/cjs/pm-plugins/utils.js +16 -18
- package/dist/es2019/pm-plugins/events/initialize.js +1 -0
- package/dist/es2019/pm-plugins/main/index.js +1 -1
- package/dist/es2019/pm-plugins/main/plugin-state.js +12 -4
- package/dist/es2019/pm-plugins/track-steps.js +1 -1
- package/dist/es2019/pm-plugins/utils.js +18 -20
- package/dist/esm/pm-plugins/events/initialize.js +1 -0
- package/dist/esm/pm-plugins/main/plugin-state.js +15 -4
- package/dist/esm/pm-plugins/utils.js +16 -18
- package/dist/types/collabEditPluginType.d.ts +2 -2
- package/dist/types/pm-plugins/main/plugin-state.d.ts +1 -0
- package/dist/types/pm-plugins/utils.d.ts +3 -2
- package/dist/types-ts4.5/collabEditPluginType.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/main/plugin-state.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +3 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-collab-edit
|
|
2
2
|
|
|
3
|
+
## 2.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 2.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#98820](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98820)
|
|
14
|
+
[`9f7dc3ba5d256`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9f7dc3ba5d256) -
|
|
15
|
+
[ux] Update the potential list of colors for avatar badges and telepointers within the editor.
|
|
16
|
+
Also add support for using presenceId over sessionId, when presenceId exists, in order to make the
|
|
17
|
+
avatar badge and telepointer color selection.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
|
|
3
23
|
## 2.0.2
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -39,6 +39,7 @@ var initialize = exports.initialize = function initialize(_ref) {
|
|
|
39
39
|
editorAnalyticsApi = _ref.editorAnalyticsApi,
|
|
40
40
|
pluginInjectionApi = _ref.pluginInjectionApi;
|
|
41
41
|
return function (provider) {
|
|
42
|
+
// eslint-disable-next-line prefer-const
|
|
42
43
|
var cleanup;
|
|
43
44
|
var pluginState = _pluginKey.pluginKey.getState(view.state);
|
|
44
45
|
if (pluginState !== null && pluginState !== void 0 && pluginState.isReady && cleanup) {
|
|
@@ -66,10 +66,19 @@ var PluginState = exports.PluginState = /*#__PURE__*/function () {
|
|
|
66
66
|
var participant = this.participants.get(sessionId);
|
|
67
67
|
return participant ? participant.name.substring(0, 1).toUpperCase() : 'X';
|
|
68
68
|
}
|
|
69
|
+
}, {
|
|
70
|
+
key: "getPresenceId",
|
|
71
|
+
value: function getPresenceId(sessionId) {
|
|
72
|
+
var _participant$presence;
|
|
73
|
+
var participant = this.participants.get(sessionId);
|
|
74
|
+
return (_participant$presence = participant === null || participant === void 0 ? void 0 : participant.presenceId) !== null && _participant$presence !== void 0 ? _participant$presence : sessionId;
|
|
75
|
+
}
|
|
69
76
|
}, {
|
|
70
77
|
key: "apply",
|
|
71
78
|
value: function apply(tr) {
|
|
72
79
|
var _this = this;
|
|
80
|
+
// Ignored via go/ees005
|
|
81
|
+
// eslint-disable-next-line prefer-const
|
|
73
82
|
var participants = this.participants,
|
|
74
83
|
sid = this.sid,
|
|
75
84
|
isReady = this.isReady;
|
|
@@ -106,7 +115,7 @@ var PluginState = exports.PluginState = /*#__PURE__*/function () {
|
|
|
106
115
|
if (telepointerData) {
|
|
107
116
|
var sessionId = telepointerData.sessionId;
|
|
108
117
|
if (participants.get(sessionId) && sessionId !== sid) {
|
|
109
|
-
var oldPointers = (0, _utils.findPointers)(
|
|
118
|
+
var oldPointers = (0, _utils.findPointers)(sessionId, this.decorationSet);
|
|
110
119
|
if (oldPointers) {
|
|
111
120
|
remove = remove.concat(oldPointers);
|
|
112
121
|
}
|
|
@@ -130,7 +139,7 @@ var PluginState = exports.PluginState = /*#__PURE__*/function () {
|
|
|
130
139
|
} catch (err) {
|
|
131
140
|
this.onError(err);
|
|
132
141
|
}
|
|
133
|
-
add = add.concat((0, _utils.createTelepointers)(from, to, sessionId, isSelection, this.getInitial(sessionId)));
|
|
142
|
+
add = add.concat((0, _utils.createTelepointers)(from, to, sessionId, isSelection, this.getInitial(sessionId), this.getPresenceId(sessionId)));
|
|
134
143
|
}
|
|
135
144
|
}
|
|
136
145
|
if (tr.docChanged) {
|
|
@@ -142,12 +151,14 @@ var PluginState = exports.PluginState = /*#__PURE__*/function () {
|
|
|
142
151
|
if (spec.pointer && spec.pointer.sessionId && spec.key === "telepointer-".concat(spec.pointer.sessionId)) {
|
|
143
152
|
var step = tr.steps.filter(_utils.isReplaceStep)[0];
|
|
144
153
|
if (step) {
|
|
145
|
-
var
|
|
154
|
+
var _spec$pointer = spec.pointer,
|
|
155
|
+
_sessionId = _spec$pointer.sessionId,
|
|
156
|
+
presenceId = _spec$pointer.presenceId;
|
|
146
157
|
var _ref = step,
|
|
147
158
|
size = _ref.slice.content.size,
|
|
148
159
|
_from = _ref.from;
|
|
149
160
|
var pos = getValidPos(tr, size ? Math.min(_from + size, tr.doc.nodeSize - 3) : Math.max(_from, 1));
|
|
150
|
-
add = add.concat((0, _utils.createTelepointers)(pos, pos, _sessionId, false, _this.getInitial(_sessionId)));
|
|
161
|
+
add = add.concat((0, _utils.createTelepointers)(pos, pos, _sessionId, false, _this.getInitial(_sessionId), presenceId));
|
|
151
162
|
}
|
|
152
163
|
}
|
|
153
164
|
}
|
|
@@ -15,7 +15,7 @@ var _whitespace = require("@atlaskit/editor-common/whitespace");
|
|
|
15
15
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
16
16
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
17
17
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
18
|
-
var
|
|
18
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
19
19
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
20
20
|
var findPointers = exports.findPointers = function findPointers(id, decorations) {
|
|
21
21
|
return decorations.find()
|
|
@@ -30,25 +30,19 @@ function style(options) {
|
|
|
30
30
|
return "border-right: 2px solid ".concat(color, "; margin-right: -2px;");
|
|
31
31
|
}
|
|
32
32
|
function getAvatarColor(str) {
|
|
33
|
-
var
|
|
34
|
-
for (var i = 0; i < str.length; i++) {
|
|
35
|
-
/* eslint-disable no-bitwise */
|
|
36
|
-
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
37
|
-
hash = hash & hash;
|
|
38
|
-
/* eslint-enable no-bitwise */
|
|
39
|
-
}
|
|
40
|
-
var index = Math.abs(hash) % _consts.avatarColors.length;
|
|
33
|
+
var participantColor = (0, _editorSharedStyles.getParticipantColor)(str);
|
|
41
34
|
return {
|
|
42
|
-
index: index,
|
|
43
|
-
|
|
35
|
+
index: participantColor.index,
|
|
36
|
+
backgroundColor: participantColor.color.backgroundColor,
|
|
37
|
+
textColor: participantColor.color.textColor
|
|
44
38
|
};
|
|
45
39
|
}
|
|
46
|
-
var createTelepointers = exports.createTelepointers = function createTelepointers(from, to, sessionId, isSelection, initial
|
|
40
|
+
var createTelepointers = exports.createTelepointers = function createTelepointers(from, to, sessionId, isSelection, initial, presenceId
|
|
47
41
|
// Ignored via go/ees005
|
|
48
42
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
49
43
|
) {
|
|
50
44
|
var decorations = [];
|
|
51
|
-
var avatarColor = getAvatarColor(
|
|
45
|
+
var avatarColor = getAvatarColor(presenceId);
|
|
52
46
|
var color = avatarColor.index.toString();
|
|
53
47
|
if (isSelection) {
|
|
54
48
|
var className = "telepointer color-".concat(color, " telepointer-selection");
|
|
@@ -60,7 +54,8 @@ var createTelepointers = exports.createTelepointers = function createTelepointer
|
|
|
60
54
|
'data-initial': initial
|
|
61
55
|
}, {
|
|
62
56
|
pointer: {
|
|
63
|
-
sessionId: sessionId
|
|
57
|
+
sessionId: sessionId,
|
|
58
|
+
presenceId: presenceId
|
|
64
59
|
}
|
|
65
60
|
}));
|
|
66
61
|
}
|
|
@@ -72,7 +67,7 @@ var createTelepointers = exports.createTelepointers = function createTelepointer
|
|
|
72
67
|
cursor.textContent = _whitespace.ZERO_WIDTH_JOINER;
|
|
73
68
|
cursor.className = "telepointer color-".concat(color, " telepointer-selection-badge");
|
|
74
69
|
cursor.style.cssText = "".concat(style({
|
|
75
|
-
color: avatarColor.
|
|
70
|
+
color: avatarColor.backgroundColor
|
|
76
71
|
}), ";");
|
|
77
72
|
cursor.setAttribute('data-initial', initial);
|
|
78
73
|
return decorations.concat(
|
|
@@ -80,7 +75,8 @@ var createTelepointers = exports.createTelepointers = function createTelepointer
|
|
|
80
75
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
76
|
_view.Decoration.widget(to, spaceJoinerAfter, {
|
|
82
77
|
pointer: {
|
|
83
|
-
sessionId: sessionId
|
|
78
|
+
sessionId: sessionId,
|
|
79
|
+
presenceId: presenceId
|
|
84
80
|
},
|
|
85
81
|
key: "telepointer-".concat(sessionId, "-zero")
|
|
86
82
|
})).concat(
|
|
@@ -88,7 +84,8 @@ var createTelepointers = exports.createTelepointers = function createTelepointer
|
|
|
88
84
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
85
|
_view.Decoration.widget(to, cursor, {
|
|
90
86
|
pointer: {
|
|
91
|
-
sessionId: sessionId
|
|
87
|
+
sessionId: sessionId,
|
|
88
|
+
presenceId: presenceId
|
|
92
89
|
},
|
|
93
90
|
key: "telepointer-".concat(sessionId)
|
|
94
91
|
})).concat(
|
|
@@ -96,7 +93,8 @@ var createTelepointers = exports.createTelepointers = function createTelepointer
|
|
|
96
93
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
94
|
_view.Decoration.widget(to, spaceJoinerBefore, {
|
|
98
95
|
pointer: {
|
|
99
|
-
sessionId: sessionId
|
|
96
|
+
sessionId: sessionId,
|
|
97
|
+
presenceId: presenceId
|
|
100
98
|
},
|
|
101
99
|
key: "telepointer-".concat(sessionId, "-zero")
|
|
102
100
|
}));
|
|
@@ -26,6 +26,7 @@ export const initialize = ({
|
|
|
26
26
|
editorAnalyticsApi,
|
|
27
27
|
pluginInjectionApi
|
|
28
28
|
}) => provider => {
|
|
29
|
+
// eslint-disable-next-line prefer-const
|
|
29
30
|
let cleanup;
|
|
30
31
|
const pluginState = pluginKey.getState(view.state);
|
|
31
32
|
if (pluginState !== null && pluginState !== void 0 && pluginState.isReady && cleanup) {
|
|
@@ -16,7 +16,7 @@ import { pluginKey } from './plugin-key';
|
|
|
16
16
|
import { PluginState } from './plugin-state';
|
|
17
17
|
const enforceCustomStepRegisters = () => {
|
|
18
18
|
const tryToRegisterStep = obj => {
|
|
19
|
-
for (
|
|
19
|
+
for (const customStep of Object.values(obj)) {
|
|
20
20
|
var _customStep$prototype;
|
|
21
21
|
// I know this seems awful
|
|
22
22
|
// But unfortunate ProseMirror does not expose the jsonID property p
|
|
@@ -46,7 +46,14 @@ export class PluginState {
|
|
|
46
46
|
const participant = this.participants.get(sessionId);
|
|
47
47
|
return participant ? participant.name.substring(0, 1).toUpperCase() : 'X';
|
|
48
48
|
}
|
|
49
|
+
getPresenceId(sessionId) {
|
|
50
|
+
var _participant$presence;
|
|
51
|
+
const participant = this.participants.get(sessionId);
|
|
52
|
+
return (_participant$presence = participant === null || participant === void 0 ? void 0 : participant.presenceId) !== null && _participant$presence !== void 0 ? _participant$presence : sessionId;
|
|
53
|
+
}
|
|
49
54
|
apply(tr) {
|
|
55
|
+
// Ignored via go/ees005
|
|
56
|
+
// eslint-disable-next-line prefer-const
|
|
50
57
|
let {
|
|
51
58
|
participants,
|
|
52
59
|
sid,
|
|
@@ -85,7 +92,7 @@ export class PluginState {
|
|
|
85
92
|
sessionId
|
|
86
93
|
} = telepointerData;
|
|
87
94
|
if (participants.get(sessionId) && sessionId !== sid) {
|
|
88
|
-
const oldPointers = findPointers(
|
|
95
|
+
const oldPointers = findPointers(sessionId, this.decorationSet);
|
|
89
96
|
if (oldPointers) {
|
|
90
97
|
remove = remove.concat(oldPointers);
|
|
91
98
|
}
|
|
@@ -109,7 +116,7 @@ export class PluginState {
|
|
|
109
116
|
} catch (err) {
|
|
110
117
|
this.onError(err);
|
|
111
118
|
}
|
|
112
|
-
add = add.concat(createTelepointers(from, to, sessionId, isSelection, this.getInitial(sessionId)));
|
|
119
|
+
add = add.concat(createTelepointers(from, to, sessionId, isSelection, this.getInitial(sessionId), this.getPresenceId(sessionId)));
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
122
|
if (tr.docChanged) {
|
|
@@ -122,7 +129,8 @@ export class PluginState {
|
|
|
122
129
|
const step = tr.steps.filter(isReplaceStep)[0];
|
|
123
130
|
if (step) {
|
|
124
131
|
const {
|
|
125
|
-
sessionId
|
|
132
|
+
sessionId,
|
|
133
|
+
presenceId
|
|
126
134
|
} = spec.pointer;
|
|
127
135
|
const {
|
|
128
136
|
slice: {
|
|
@@ -135,7 +143,7 @@ export class PluginState {
|
|
|
135
143
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
144
|
} = step;
|
|
137
145
|
const pos = getValidPos(tr, size ? Math.min(from + size, tr.doc.nodeSize - 3) : Math.max(from, 1));
|
|
138
|
-
add = add.concat(createTelepointers(pos, pos, sessionId, false, this.getInitial(sessionId)));
|
|
146
|
+
add = add.concat(createTelepointers(pos, pos, sessionId, false, this.getInitial(sessionId), presenceId));
|
|
139
147
|
}
|
|
140
148
|
}
|
|
141
149
|
}
|
|
@@ -5,7 +5,7 @@ import { ZERO_WIDTH_JOINER } from '@atlaskit/editor-common/whitespace';
|
|
|
5
5
|
import { Transaction, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
6
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
7
7
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
-
import {
|
|
8
|
+
import { getParticipantColor } from '@atlaskit/editor-shared-styles';
|
|
9
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
10
|
export const findPointers = (id, decorations) => decorations.find()
|
|
11
11
|
// Ignored via go/ees005
|
|
@@ -16,25 +16,19 @@ function style(options) {
|
|
|
16
16
|
return `border-right: 2px solid ${color}; margin-right: -2px;`;
|
|
17
17
|
}
|
|
18
18
|
export function getAvatarColor(str) {
|
|
19
|
-
|
|
20
|
-
for (let i = 0; i < str.length; i++) {
|
|
21
|
-
/* eslint-disable no-bitwise */
|
|
22
|
-
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
23
|
-
hash = hash & hash;
|
|
24
|
-
/* eslint-enable no-bitwise */
|
|
25
|
-
}
|
|
26
|
-
const index = Math.abs(hash) % avatarColors.length;
|
|
19
|
+
const participantColor = getParticipantColor(str);
|
|
27
20
|
return {
|
|
28
|
-
index,
|
|
29
|
-
|
|
21
|
+
index: participantColor.index,
|
|
22
|
+
backgroundColor: participantColor.color.backgroundColor,
|
|
23
|
+
textColor: participantColor.color.textColor
|
|
30
24
|
};
|
|
31
25
|
}
|
|
32
|
-
export const createTelepointers = (from, to, sessionId, isSelection, initial
|
|
26
|
+
export const createTelepointers = (from, to, sessionId, isSelection, initial, presenceId
|
|
33
27
|
// Ignored via go/ees005
|
|
34
28
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
35
29
|
) => {
|
|
36
|
-
|
|
37
|
-
const avatarColor = getAvatarColor(
|
|
30
|
+
const decorations = [];
|
|
31
|
+
const avatarColor = getAvatarColor(presenceId);
|
|
38
32
|
const color = avatarColor.index.toString();
|
|
39
33
|
if (isSelection) {
|
|
40
34
|
const className = `telepointer color-${color} telepointer-selection`;
|
|
@@ -46,7 +40,8 @@ export const createTelepointers = (from, to, sessionId, isSelection, initial
|
|
|
46
40
|
'data-initial': initial
|
|
47
41
|
}, {
|
|
48
42
|
pointer: {
|
|
49
|
-
sessionId
|
|
43
|
+
sessionId,
|
|
44
|
+
presenceId
|
|
50
45
|
}
|
|
51
46
|
}));
|
|
52
47
|
}
|
|
@@ -58,7 +53,7 @@ export const createTelepointers = (from, to, sessionId, isSelection, initial
|
|
|
58
53
|
cursor.textContent = ZERO_WIDTH_JOINER;
|
|
59
54
|
cursor.className = `telepointer color-${color} telepointer-selection-badge`;
|
|
60
55
|
cursor.style.cssText = `${style({
|
|
61
|
-
color: avatarColor.
|
|
56
|
+
color: avatarColor.backgroundColor
|
|
62
57
|
})};`;
|
|
63
58
|
cursor.setAttribute('data-initial', initial);
|
|
64
59
|
return decorations.concat(
|
|
@@ -66,7 +61,8 @@ export const createTelepointers = (from, to, sessionId, isSelection, initial
|
|
|
66
61
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
62
|
Decoration.widget(to, spaceJoinerAfter, {
|
|
68
63
|
pointer: {
|
|
69
|
-
sessionId
|
|
64
|
+
sessionId,
|
|
65
|
+
presenceId
|
|
70
66
|
},
|
|
71
67
|
key: `telepointer-${sessionId}-zero`
|
|
72
68
|
})).concat(
|
|
@@ -74,7 +70,8 @@ export const createTelepointers = (from, to, sessionId, isSelection, initial
|
|
|
74
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
71
|
Decoration.widget(to, cursor, {
|
|
76
72
|
pointer: {
|
|
77
|
-
sessionId
|
|
73
|
+
sessionId,
|
|
74
|
+
presenceId
|
|
78
75
|
},
|
|
79
76
|
key: `telepointer-${sessionId}`
|
|
80
77
|
})).concat(
|
|
@@ -82,7 +79,8 @@ export const createTelepointers = (from, to, sessionId, isSelection, initial
|
|
|
82
79
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
80
|
Decoration.widget(to, spaceJoinerBefore, {
|
|
84
81
|
pointer: {
|
|
85
|
-
sessionId
|
|
82
|
+
sessionId,
|
|
83
|
+
presenceId
|
|
86
84
|
},
|
|
87
85
|
key: `telepointer-${sessionId}-zero`
|
|
88
86
|
}));
|
|
@@ -145,7 +143,7 @@ export const scrollToCollabCursor = (editorView, participants, sessionId, index,
|
|
|
145
143
|
const {
|
|
146
144
|
state
|
|
147
145
|
} = editorView;
|
|
148
|
-
|
|
146
|
+
const tr = state.tr;
|
|
149
147
|
const analyticsPayload = {
|
|
150
148
|
action: ACTION.MATCHED,
|
|
151
149
|
actionSubject: ACTION_SUBJECT.SELECTION,
|
|
@@ -32,6 +32,7 @@ export var initialize = function initialize(_ref) {
|
|
|
32
32
|
editorAnalyticsApi = _ref.editorAnalyticsApi,
|
|
33
33
|
pluginInjectionApi = _ref.pluginInjectionApi;
|
|
34
34
|
return function (provider) {
|
|
35
|
+
// eslint-disable-next-line prefer-const
|
|
35
36
|
var cleanup;
|
|
36
37
|
var pluginState = pluginKey.getState(view.state);
|
|
37
38
|
if (pluginState !== null && pluginState !== void 0 && pluginState.isReady && cleanup) {
|
|
@@ -60,10 +60,19 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
60
60
|
var participant = this.participants.get(sessionId);
|
|
61
61
|
return participant ? participant.name.substring(0, 1).toUpperCase() : 'X';
|
|
62
62
|
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "getPresenceId",
|
|
65
|
+
value: function getPresenceId(sessionId) {
|
|
66
|
+
var _participant$presence;
|
|
67
|
+
var participant = this.participants.get(sessionId);
|
|
68
|
+
return (_participant$presence = participant === null || participant === void 0 ? void 0 : participant.presenceId) !== null && _participant$presence !== void 0 ? _participant$presence : sessionId;
|
|
69
|
+
}
|
|
63
70
|
}, {
|
|
64
71
|
key: "apply",
|
|
65
72
|
value: function apply(tr) {
|
|
66
73
|
var _this = this;
|
|
74
|
+
// Ignored via go/ees005
|
|
75
|
+
// eslint-disable-next-line prefer-const
|
|
67
76
|
var participants = this.participants,
|
|
68
77
|
sid = this.sid,
|
|
69
78
|
isReady = this.isReady;
|
|
@@ -100,7 +109,7 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
100
109
|
if (telepointerData) {
|
|
101
110
|
var sessionId = telepointerData.sessionId;
|
|
102
111
|
if (participants.get(sessionId) && sessionId !== sid) {
|
|
103
|
-
var oldPointers = findPointers(
|
|
112
|
+
var oldPointers = findPointers(sessionId, this.decorationSet);
|
|
104
113
|
if (oldPointers) {
|
|
105
114
|
remove = remove.concat(oldPointers);
|
|
106
115
|
}
|
|
@@ -124,7 +133,7 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
124
133
|
} catch (err) {
|
|
125
134
|
this.onError(err);
|
|
126
135
|
}
|
|
127
|
-
add = add.concat(createTelepointers(from, to, sessionId, isSelection, this.getInitial(sessionId)));
|
|
136
|
+
add = add.concat(createTelepointers(from, to, sessionId, isSelection, this.getInitial(sessionId), this.getPresenceId(sessionId)));
|
|
128
137
|
}
|
|
129
138
|
}
|
|
130
139
|
if (tr.docChanged) {
|
|
@@ -136,12 +145,14 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
136
145
|
if (spec.pointer && spec.pointer.sessionId && spec.key === "telepointer-".concat(spec.pointer.sessionId)) {
|
|
137
146
|
var step = tr.steps.filter(isReplaceStep)[0];
|
|
138
147
|
if (step) {
|
|
139
|
-
var
|
|
148
|
+
var _spec$pointer = spec.pointer,
|
|
149
|
+
_sessionId = _spec$pointer.sessionId,
|
|
150
|
+
presenceId = _spec$pointer.presenceId;
|
|
140
151
|
var _ref = step,
|
|
141
152
|
size = _ref.slice.content.size,
|
|
142
153
|
_from = _ref.from;
|
|
143
154
|
var pos = getValidPos(tr, size ? Math.min(_from + size, tr.doc.nodeSize - 3) : Math.max(_from, 1));
|
|
144
|
-
add = add.concat(createTelepointers(pos, pos, _sessionId, false, _this.getInitial(_sessionId)));
|
|
155
|
+
add = add.concat(createTelepointers(pos, pos, _sessionId, false, _this.getInitial(_sessionId), presenceId));
|
|
145
156
|
}
|
|
146
157
|
}
|
|
147
158
|
}
|
|
@@ -6,7 +6,7 @@ import { ZERO_WIDTH_JOINER } from '@atlaskit/editor-common/whitespace';
|
|
|
6
6
|
import { Transaction, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
7
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
8
8
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
9
|
-
import {
|
|
9
|
+
import { getParticipantColor } from '@atlaskit/editor-shared-styles';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
11
|
export var findPointers = function findPointers(id, decorations) {
|
|
12
12
|
return decorations.find()
|
|
@@ -21,25 +21,19 @@ function style(options) {
|
|
|
21
21
|
return "border-right: 2px solid ".concat(color, "; margin-right: -2px;");
|
|
22
22
|
}
|
|
23
23
|
export function getAvatarColor(str) {
|
|
24
|
-
var
|
|
25
|
-
for (var i = 0; i < str.length; i++) {
|
|
26
|
-
/* eslint-disable no-bitwise */
|
|
27
|
-
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
28
|
-
hash = hash & hash;
|
|
29
|
-
/* eslint-enable no-bitwise */
|
|
30
|
-
}
|
|
31
|
-
var index = Math.abs(hash) % avatarColors.length;
|
|
24
|
+
var participantColor = getParticipantColor(str);
|
|
32
25
|
return {
|
|
33
|
-
index: index,
|
|
34
|
-
|
|
26
|
+
index: participantColor.index,
|
|
27
|
+
backgroundColor: participantColor.color.backgroundColor,
|
|
28
|
+
textColor: participantColor.color.textColor
|
|
35
29
|
};
|
|
36
30
|
}
|
|
37
|
-
export var createTelepointers = function createTelepointers(from, to, sessionId, isSelection, initial
|
|
31
|
+
export var createTelepointers = function createTelepointers(from, to, sessionId, isSelection, initial, presenceId
|
|
38
32
|
// Ignored via go/ees005
|
|
39
33
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
40
34
|
) {
|
|
41
35
|
var decorations = [];
|
|
42
|
-
var avatarColor = getAvatarColor(
|
|
36
|
+
var avatarColor = getAvatarColor(presenceId);
|
|
43
37
|
var color = avatarColor.index.toString();
|
|
44
38
|
if (isSelection) {
|
|
45
39
|
var className = "telepointer color-".concat(color, " telepointer-selection");
|
|
@@ -51,7 +45,8 @@ export var createTelepointers = function createTelepointers(from, to, sessionId,
|
|
|
51
45
|
'data-initial': initial
|
|
52
46
|
}, {
|
|
53
47
|
pointer: {
|
|
54
|
-
sessionId: sessionId
|
|
48
|
+
sessionId: sessionId,
|
|
49
|
+
presenceId: presenceId
|
|
55
50
|
}
|
|
56
51
|
}));
|
|
57
52
|
}
|
|
@@ -63,7 +58,7 @@ export var createTelepointers = function createTelepointers(from, to, sessionId,
|
|
|
63
58
|
cursor.textContent = ZERO_WIDTH_JOINER;
|
|
64
59
|
cursor.className = "telepointer color-".concat(color, " telepointer-selection-badge");
|
|
65
60
|
cursor.style.cssText = "".concat(style({
|
|
66
|
-
color: avatarColor.
|
|
61
|
+
color: avatarColor.backgroundColor
|
|
67
62
|
}), ";");
|
|
68
63
|
cursor.setAttribute('data-initial', initial);
|
|
69
64
|
return decorations.concat(
|
|
@@ -71,7 +66,8 @@ export var createTelepointers = function createTelepointers(from, to, sessionId,
|
|
|
71
66
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
67
|
Decoration.widget(to, spaceJoinerAfter, {
|
|
73
68
|
pointer: {
|
|
74
|
-
sessionId: sessionId
|
|
69
|
+
sessionId: sessionId,
|
|
70
|
+
presenceId: presenceId
|
|
75
71
|
},
|
|
76
72
|
key: "telepointer-".concat(sessionId, "-zero")
|
|
77
73
|
})).concat(
|
|
@@ -79,7 +75,8 @@ export var createTelepointers = function createTelepointers(from, to, sessionId,
|
|
|
79
75
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
76
|
Decoration.widget(to, cursor, {
|
|
81
77
|
pointer: {
|
|
82
|
-
sessionId: sessionId
|
|
78
|
+
sessionId: sessionId,
|
|
79
|
+
presenceId: presenceId
|
|
83
80
|
},
|
|
84
81
|
key: "telepointer-".concat(sessionId)
|
|
85
82
|
})).concat(
|
|
@@ -87,7 +84,8 @@ export var createTelepointers = function createTelepointers(from, to, sessionId,
|
|
|
87
84
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
85
|
Decoration.widget(to, spaceJoinerBefore, {
|
|
89
86
|
pointer: {
|
|
90
|
-
sessionId: sessionId
|
|
87
|
+
sessionId: sessionId,
|
|
88
|
+
presenceId: presenceId
|
|
91
89
|
},
|
|
92
90
|
key: "telepointer-".concat(sessionId, "-zero")
|
|
93
91
|
}));
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Color } from '@atlaskit/editor-common/collab';
|
|
2
1
|
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
2
|
import type { JSONNode } from '@atlaskit/editor-json-transformer';
|
|
4
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
@@ -18,7 +17,8 @@ export type CollabEditPlugin = NextEditorPlugin<'collabEdit', {
|
|
|
18
17
|
actions: {
|
|
19
18
|
getAvatarColor: (str: string) => {
|
|
20
19
|
index: number;
|
|
21
|
-
|
|
20
|
+
backgroundColor: string;
|
|
21
|
+
textColor: string;
|
|
22
22
|
};
|
|
23
23
|
addInlineCommentMark: (props: {
|
|
24
24
|
from: number;
|
|
@@ -17,6 +17,7 @@ export declare class PluginState {
|
|
|
17
17
|
get sessionId(): string | undefined;
|
|
18
18
|
constructor(decorations: DecorationSet, participants: Participants, sessionId?: string, collabInitalised?: boolean, onError?: (err: Error) => void);
|
|
19
19
|
getInitial(sessionId: string): string;
|
|
20
|
+
getPresenceId(sessionId: string): string;
|
|
20
21
|
apply(tr: ReadonlyTransaction): PluginState;
|
|
21
22
|
static eq(a: PluginState, b: PluginState): boolean;
|
|
22
23
|
static init(config: any): PluginState;
|
|
@@ -7,9 +7,10 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
|
7
7
|
export declare const findPointers: (id: string, decorations: DecorationSet) => Decoration[];
|
|
8
8
|
export declare function getAvatarColor(str: string): {
|
|
9
9
|
index: number;
|
|
10
|
-
|
|
10
|
+
backgroundColor: string;
|
|
11
|
+
textColor: string;
|
|
11
12
|
};
|
|
12
|
-
export declare const createTelepointers: (from: number, to: number, sessionId: string, isSelection: boolean, initial: string) => Decoration[];
|
|
13
|
+
export declare const createTelepointers: (from: number, to: number, sessionId: string, isSelection: boolean, initial: string, presenceId: string) => Decoration[];
|
|
13
14
|
export declare const replaceDocument: (doc: any, state: EditorState, version?: number, options?: CollabEditOptions, reserveCursor?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => Transaction;
|
|
14
15
|
export declare const scrollToCollabCursor: (editorView: EditorView, participants: CollabParticipant[], sessionId: string | undefined, index: number, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => void;
|
|
15
16
|
export declare const getPositionOfTelepointer: (sessionId: string, decorationSet: DecorationSet) => undefined | number;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Color } from '@atlaskit/editor-common/collab';
|
|
2
1
|
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
2
|
import type { JSONNode } from '@atlaskit/editor-json-transformer';
|
|
4
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
@@ -18,7 +17,8 @@ export type CollabEditPlugin = NextEditorPlugin<'collabEdit', {
|
|
|
18
17
|
actions: {
|
|
19
18
|
getAvatarColor: (str: string) => {
|
|
20
19
|
index: number;
|
|
21
|
-
|
|
20
|
+
backgroundColor: string;
|
|
21
|
+
textColor: string;
|
|
22
22
|
};
|
|
23
23
|
addInlineCommentMark: (props: {
|
|
24
24
|
from: number;
|
|
@@ -17,6 +17,7 @@ export declare class PluginState {
|
|
|
17
17
|
get sessionId(): string | undefined;
|
|
18
18
|
constructor(decorations: DecorationSet, participants: Participants, sessionId?: string, collabInitalised?: boolean, onError?: (err: Error) => void);
|
|
19
19
|
getInitial(sessionId: string): string;
|
|
20
|
+
getPresenceId(sessionId: string): string;
|
|
20
21
|
apply(tr: ReadonlyTransaction): PluginState;
|
|
21
22
|
static eq(a: PluginState, b: PluginState): boolean;
|
|
22
23
|
static init(config: any): PluginState;
|
|
@@ -7,9 +7,10 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
|
7
7
|
export declare const findPointers: (id: string, decorations: DecorationSet) => Decoration[];
|
|
8
8
|
export declare function getAvatarColor(str: string): {
|
|
9
9
|
index: number;
|
|
10
|
-
|
|
10
|
+
backgroundColor: string;
|
|
11
|
+
textColor: string;
|
|
11
12
|
};
|
|
12
|
-
export declare const createTelepointers: (from: number, to: number, sessionId: string, isSelection: boolean, initial: string) => Decoration[];
|
|
13
|
+
export declare const createTelepointers: (from: number, to: number, sessionId: string, isSelection: boolean, initial: string, presenceId: string) => Decoration[];
|
|
13
14
|
export declare const replaceDocument: (doc: any, state: EditorState, version?: number, options?: CollabEditOptions, reserveCursor?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => Transaction;
|
|
14
15
|
export declare const scrollToCollabCursor: (editorView: EditorView, participants: CollabParticipant[], sessionId: string | undefined, index: number, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => void;
|
|
15
16
|
export declare const getPositionOfTelepointer: (sessionId: string, decorationSet: DecorationSet) => undefined | number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-collab-edit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Collab Edit plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/adf-schema": "^46.1.0",
|
|
35
35
|
"@atlaskit/custom-steps": "^0.9.0",
|
|
36
|
-
"@atlaskit/editor-common": "^
|
|
36
|
+
"@atlaskit/editor-common": "^98.0.0",
|
|
37
37
|
"@atlaskit/editor-json-transformer": "^8.21.0",
|
|
38
|
-
"@atlaskit/editor-plugin-analytics": "1.10.
|
|
38
|
+
"@atlaskit/editor-plugin-analytics": "1.10.10",
|
|
39
39
|
"@atlaskit/editor-plugin-editor-viewmode": "^2.1.0",
|
|
40
40
|
"@atlaskit/editor-plugin-feature-flags": "^1.2.0",
|
|
41
41
|
"@atlaskit/editor-prosemirror": "6.2.1",
|