@cocreate/cursors 1.10.17 → 1.10.18
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/package.json +1 -1
- package/src/index.css +1 -9
- package/src/index.js +28 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [1.10.18](https://github.com/CoCreate-app/CoCreate-cursors/compare/v1.10.17...v1.10.18) (2021-12-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* check contenteditable element then iframe ([29bd7b4](https://github.com/CoCreate-app/CoCreate-cursors/commit/29bd7b4e7460c478cec37916fe9bb7439d2b8805))
|
|
7
|
+
* use attribute for socket_id instead of id ([db901da](https://github.com/CoCreate-app/CoCreate-cursors/commit/db901daa270551cd6b1b6b95124d785ed81643c9))
|
|
8
|
+
|
|
1
9
|
## [1.10.17](https://github.com/CoCreate-app/CoCreate-cursors/compare/v1.10.16...v1.10.17) (2021-11-27)
|
|
2
10
|
|
|
3
11
|
|
package/package.json
CHANGED
package/src/index.css
CHANGED
|
@@ -27,13 +27,9 @@
|
|
|
27
27
|
white-space: nowrap;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
.selection {
|
|
31
|
-
background-color: #ecd44;
|
|
32
|
-
opacity: 0.6;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
30
|
.cursor-selection {
|
|
36
31
|
position: absolute;
|
|
32
|
+
opacity: 0.4;
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
.mirror {
|
|
@@ -49,7 +45,3 @@
|
|
|
49
45
|
background: rgba(0, 0, 0, 0.00);
|
|
50
46
|
width: 0px;
|
|
51
47
|
}
|
|
52
|
-
|
|
53
|
-
.users_selections {
|
|
54
|
-
opacity: 0.4;
|
|
55
|
-
}
|
package/src/index.js
CHANGED
|
@@ -94,7 +94,7 @@ var getCoordinates = function(element, position_start, position_end) {
|
|
|
94
94
|
|
|
95
95
|
|
|
96
96
|
let cursor_container = mirrorDiv.querySelectorAll('.cursor-container');
|
|
97
|
-
let users_selections = mirrorDiv.querySelectorAll('.
|
|
97
|
+
let users_selections = mirrorDiv.querySelectorAll('.cursor-selection');
|
|
98
98
|
|
|
99
99
|
let value_element = (['TEXTAREA', 'INPUT'].indexOf(element.nodeName) == -1) ? element.innerHTML : element.value;
|
|
100
100
|
mirrorDiv.textContent = value_element.substring(0, position_start);
|
|
@@ -165,8 +165,10 @@ function drawCursors(selection) {
|
|
|
165
165
|
let realtime = element.getAttribute('realtime');
|
|
166
166
|
let cursors = element.getAttribute('cursors');
|
|
167
167
|
if (realtime == 'false' || cursors == 'false') continue;
|
|
168
|
-
if (element.
|
|
169
|
-
let domTextEditor = element
|
|
168
|
+
if (element.hasAttribute('contenteditable')) {
|
|
169
|
+
let domTextEditor = element;
|
|
170
|
+
if (element.tagName == 'IFRAME')
|
|
171
|
+
domTextEditor = element.contentDocument.documentElement;
|
|
170
172
|
let pos = getElementPosition(domTextEditor.htmlString, start, end);
|
|
171
173
|
element = domTextEditor.querySelector(pos.path);
|
|
172
174
|
let endPos = end - start;
|
|
@@ -187,20 +189,18 @@ function drawCursors(selection) {
|
|
|
187
189
|
|
|
188
190
|
let elementMirror = document.getElementById(id_mirror);
|
|
189
191
|
let cursor;
|
|
190
|
-
|
|
191
|
-
// let user = (typeof(selection) != 'undefined' && selection.hasOwnProperty('user')) ? selection.user : false;
|
|
192
|
-
// let user_id = (typeof(selection) != 'undefined' && selection.hasOwnProperty('user_id')) ? user.user_id : false;
|
|
192
|
+
let details = {collection, document_id, name};
|
|
193
193
|
if (socket_id) {
|
|
194
|
-
|
|
195
|
-
cursores_other_elements
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
let cursores_other_elements = document.querySelectorAll(`.cursor-container[socket_id="${socket_id}"]`);
|
|
195
|
+
if (cursores_other_elements) {
|
|
196
|
+
for (cursor of cursores_other_elements){
|
|
197
|
+
if (cursor.details != details)
|
|
198
|
+
cursor.remove();
|
|
198
199
|
}
|
|
199
|
-
}
|
|
200
|
-
cursor = elementMirror.querySelector(
|
|
200
|
+
}
|
|
201
|
+
cursor = elementMirror.querySelector(`.cursor-container[socket_id="${socket_id}"]`);
|
|
201
202
|
if (!cursor) {
|
|
202
|
-
let cursor_template = '<div class="cursor-container" \
|
|
203
|
-
id="socket_' + socket_id + '" \
|
|
203
|
+
let cursor_template = '<div class="cursor-container" socket_id="' + socket_id + '" \
|
|
204
204
|
style="background-color:' + selection.background + '"> \
|
|
205
205
|
<div class="cursor-flag" \
|
|
206
206
|
collection="users" \
|
|
@@ -210,16 +210,14 @@ function drawCursors(selection) {
|
|
|
210
210
|
elementMirror.innerHTML = cursor_template + elementMirror.innerHTML;
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
cursor = elementMirror.querySelector(
|
|
213
|
+
cursor = elementMirror.querySelector(`.cursor-container[socket_id="${socket_id}"]`);
|
|
214
214
|
if (cursor) {
|
|
215
215
|
let font_size = getStyle(element, 'font-size');
|
|
216
216
|
font_size = parseFloat(font_size.substring(0, font_size.length - 2));
|
|
217
217
|
let cursor_height = ((font_size * 112.5) / 100);
|
|
218
|
-
// let my_cursor = cursor.querySelector('.cursor');
|
|
219
218
|
let cursorFlag = cursor.querySelector('.cursor-flag');
|
|
220
219
|
cursor.dataset.start = start;
|
|
221
220
|
cursor.dataset.end = end;
|
|
222
|
-
cursor.setAttribute('socket_id', socket_id);
|
|
223
221
|
cursor.setAttribute('user-name', selection.userName);
|
|
224
222
|
cursor.setAttribute('user-background', selection.background);
|
|
225
223
|
cursor.setAttribute('user-color', selection.color);
|
|
@@ -228,26 +226,32 @@ function drawCursors(selection) {
|
|
|
228
226
|
cursorFlag.style["background"] = selection.background;
|
|
229
227
|
cursorFlag.innerHTML = selection.userName;
|
|
230
228
|
cursor.style["left"] = coordinates.end.left + "px";
|
|
229
|
+
cursor.details = {collection, document_id, name};
|
|
231
230
|
|
|
232
|
-
let
|
|
233
|
-
if (
|
|
234
|
-
|
|
231
|
+
let userSelections = document.querySelectorAll(`.cursor-selection[socket_id="${socket_id}"]`);
|
|
232
|
+
if (userSelections) {
|
|
233
|
+
for (selection of userSelections){
|
|
234
|
+
if (selection.details != details)
|
|
235
|
+
selection.remove();
|
|
236
|
+
}
|
|
235
237
|
}
|
|
236
238
|
if ((start != end)) {
|
|
237
239
|
var scrollwidth = element.offsetWidth - element.scrollWidth;
|
|
238
240
|
var padding_right = parseInt(getComputedStyle(element)["paddingRight"]);
|
|
239
241
|
|
|
240
|
-
selection_user = document.createElement('span');
|
|
242
|
+
let selection_user = document.createElement('span');
|
|
241
243
|
selection_user.id = 'sel-' + socket_id;
|
|
242
|
-
selection_user.
|
|
244
|
+
selection_user.setAttribute('socket_id', socket_id);
|
|
245
|
+
selection_user.className = 'cursor-selection';
|
|
243
246
|
let style_mirror = getComputedStyle(elementMirror);
|
|
244
247
|
selection_user.style["position"] = "absolute";
|
|
245
248
|
selection_user.style["top"] = style_mirror.paddingTop;
|
|
246
249
|
selection_user.style["left"] = style_mirror.paddingLeft;
|
|
247
250
|
selection_user.style["padding-right"] = scrollwidth + padding_right + "px";
|
|
251
|
+
selection_user.details = {collection, document_id, name};
|
|
248
252
|
elementMirror.insertBefore(selection_user, elementMirror.firstChild);
|
|
253
|
+
|
|
249
254
|
let selection_span_by_user = document.createElement('span');
|
|
250
|
-
selection_span_by_user.id = 'selection-' + socket_id;
|
|
251
255
|
selection_span_by_user.style.backgroundColor = selection.background;
|
|
252
256
|
let value_element = (['TEXTAREA', 'INPUT'].indexOf(element.nodeName) == -1) ? element.innerHTML : element.value;
|
|
253
257
|
selection_user.textContent = value_element.substring(0, start);
|
|
@@ -297,7 +301,7 @@ function updateCursors(element) {
|
|
|
297
301
|
}
|
|
298
302
|
|
|
299
303
|
function removeCursor(clientId) {
|
|
300
|
-
let elements = document.querySelectorAll(
|
|
304
|
+
let elements = document.querySelectorAll(`.cursor-container[socket_id="${clientId}"]`);
|
|
301
305
|
elements.forEach(function(element, index, array) {
|
|
302
306
|
element.parentNode.removeChild(element);
|
|
303
307
|
});
|