@atlaskit/editor-plugin-collab-edit 2.0.2 → 2.1.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 +14 -0
- package/dist/cjs/pm-plugins/main/plugin-state.js +13 -4
- package/dist/cjs/pm-plugins/utils.js +16 -18
- package/dist/es2019/pm-plugins/main/plugin-state.js +10 -4
- package/dist/es2019/pm-plugins/utils.js +18 -20
- package/dist/esm/pm-plugins/main/plugin-state.js +13 -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 +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-collab-edit
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#98820](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98820)
|
|
8
|
+
[`9f7dc3ba5d256`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9f7dc3ba5d256) -
|
|
9
|
+
[ux] Update the potential list of colors for avatar badges and telepointers within the editor.
|
|
10
|
+
Also add support for using presenceId over sessionId, when presenceId exists, in order to make the
|
|
11
|
+
avatar badge and telepointer color selection.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 2.0.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -66,6 +66,13 @@ 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) {
|
|
@@ -106,7 +113,7 @@ var PluginState = exports.PluginState = /*#__PURE__*/function () {
|
|
|
106
113
|
if (telepointerData) {
|
|
107
114
|
var sessionId = telepointerData.sessionId;
|
|
108
115
|
if (participants.get(sessionId) && sessionId !== sid) {
|
|
109
|
-
var oldPointers = (0, _utils.findPointers)(
|
|
116
|
+
var oldPointers = (0, _utils.findPointers)(sessionId, this.decorationSet);
|
|
110
117
|
if (oldPointers) {
|
|
111
118
|
remove = remove.concat(oldPointers);
|
|
112
119
|
}
|
|
@@ -130,7 +137,7 @@ var PluginState = exports.PluginState = /*#__PURE__*/function () {
|
|
|
130
137
|
} catch (err) {
|
|
131
138
|
this.onError(err);
|
|
132
139
|
}
|
|
133
|
-
add = add.concat((0, _utils.createTelepointers)(from, to, sessionId, isSelection, this.getInitial(sessionId)));
|
|
140
|
+
add = add.concat((0, _utils.createTelepointers)(from, to, sessionId, isSelection, this.getInitial(sessionId), this.getPresenceId(sessionId)));
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
143
|
if (tr.docChanged) {
|
|
@@ -142,12 +149,14 @@ var PluginState = exports.PluginState = /*#__PURE__*/function () {
|
|
|
142
149
|
if (spec.pointer && spec.pointer.sessionId && spec.key === "telepointer-".concat(spec.pointer.sessionId)) {
|
|
143
150
|
var step = tr.steps.filter(_utils.isReplaceStep)[0];
|
|
144
151
|
if (step) {
|
|
145
|
-
var
|
|
152
|
+
var _spec$pointer = spec.pointer,
|
|
153
|
+
_sessionId = _spec$pointer.sessionId,
|
|
154
|
+
presenceId = _spec$pointer.presenceId;
|
|
146
155
|
var _ref = step,
|
|
147
156
|
size = _ref.slice.content.size,
|
|
148
157
|
_from = _ref.from;
|
|
149
158
|
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)));
|
|
159
|
+
add = add.concat((0, _utils.createTelepointers)(pos, pos, _sessionId, false, _this.getInitial(_sessionId), presenceId));
|
|
151
160
|
}
|
|
152
161
|
}
|
|
153
162
|
}
|
|
@@ -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
|
}));
|
|
@@ -46,6 +46,11 @@ 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) {
|
|
50
55
|
let {
|
|
51
56
|
participants,
|
|
@@ -85,7 +90,7 @@ export class PluginState {
|
|
|
85
90
|
sessionId
|
|
86
91
|
} = telepointerData;
|
|
87
92
|
if (participants.get(sessionId) && sessionId !== sid) {
|
|
88
|
-
const oldPointers = findPointers(
|
|
93
|
+
const oldPointers = findPointers(sessionId, this.decorationSet);
|
|
89
94
|
if (oldPointers) {
|
|
90
95
|
remove = remove.concat(oldPointers);
|
|
91
96
|
}
|
|
@@ -109,7 +114,7 @@ export class PluginState {
|
|
|
109
114
|
} catch (err) {
|
|
110
115
|
this.onError(err);
|
|
111
116
|
}
|
|
112
|
-
add = add.concat(createTelepointers(from, to, sessionId, isSelection, this.getInitial(sessionId)));
|
|
117
|
+
add = add.concat(createTelepointers(from, to, sessionId, isSelection, this.getInitial(sessionId), this.getPresenceId(sessionId)));
|
|
113
118
|
}
|
|
114
119
|
}
|
|
115
120
|
if (tr.docChanged) {
|
|
@@ -122,7 +127,8 @@ export class PluginState {
|
|
|
122
127
|
const step = tr.steps.filter(isReplaceStep)[0];
|
|
123
128
|
if (step) {
|
|
124
129
|
const {
|
|
125
|
-
sessionId
|
|
130
|
+
sessionId,
|
|
131
|
+
presenceId
|
|
126
132
|
} = spec.pointer;
|
|
127
133
|
const {
|
|
128
134
|
slice: {
|
|
@@ -135,7 +141,7 @@ export class PluginState {
|
|
|
135
141
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
142
|
} = step;
|
|
137
143
|
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)));
|
|
144
|
+
add = add.concat(createTelepointers(pos, pos, sessionId, false, this.getInitial(sessionId), presenceId));
|
|
139
145
|
}
|
|
140
146
|
}
|
|
141
147
|
}
|
|
@@ -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,
|
|
@@ -60,6 +60,13 @@ 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) {
|
|
@@ -100,7 +107,7 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
100
107
|
if (telepointerData) {
|
|
101
108
|
var sessionId = telepointerData.sessionId;
|
|
102
109
|
if (participants.get(sessionId) && sessionId !== sid) {
|
|
103
|
-
var oldPointers = findPointers(
|
|
110
|
+
var oldPointers = findPointers(sessionId, this.decorationSet);
|
|
104
111
|
if (oldPointers) {
|
|
105
112
|
remove = remove.concat(oldPointers);
|
|
106
113
|
}
|
|
@@ -124,7 +131,7 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
124
131
|
} catch (err) {
|
|
125
132
|
this.onError(err);
|
|
126
133
|
}
|
|
127
|
-
add = add.concat(createTelepointers(from, to, sessionId, isSelection, this.getInitial(sessionId)));
|
|
134
|
+
add = add.concat(createTelepointers(from, to, sessionId, isSelection, this.getInitial(sessionId), this.getPresenceId(sessionId)));
|
|
128
135
|
}
|
|
129
136
|
}
|
|
130
137
|
if (tr.docChanged) {
|
|
@@ -136,12 +143,14 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
136
143
|
if (spec.pointer && spec.pointer.sessionId && spec.key === "telepointer-".concat(spec.pointer.sessionId)) {
|
|
137
144
|
var step = tr.steps.filter(isReplaceStep)[0];
|
|
138
145
|
if (step) {
|
|
139
|
-
var
|
|
146
|
+
var _spec$pointer = spec.pointer,
|
|
147
|
+
_sessionId = _spec$pointer.sessionId,
|
|
148
|
+
presenceId = _spec$pointer.presenceId;
|
|
140
149
|
var _ref = step,
|
|
141
150
|
size = _ref.slice.content.size,
|
|
142
151
|
_from = _ref.from;
|
|
143
152
|
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)));
|
|
153
|
+
add = add.concat(createTelepointers(pos, pos, _sessionId, false, _this.getInitial(_sessionId), presenceId));
|
|
145
154
|
}
|
|
146
155
|
}
|
|
147
156
|
}
|
|
@@ -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.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Collab Edit plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/adf-schema": "^46.1.0",
|
|
35
35
|
"@atlaskit/custom-steps": "^0.9.0",
|
|
36
|
-
"@atlaskit/editor-common": "^97.
|
|
36
|
+
"@atlaskit/editor-common": "^97.3.0",
|
|
37
37
|
"@atlaskit/editor-json-transformer": "^8.21.0",
|
|
38
38
|
"@atlaskit/editor-plugin-analytics": "1.10.9",
|
|
39
39
|
"@atlaskit/editor-plugin-editor-viewmode": "^2.1.0",
|