@cocreate/selection 1.2.12 → 1.2.16
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +28 -0
- package/package.json +4 -4
- package/src/index.js +23 -8
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
## [1.2.16](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.15...v1.2.16) (2021-11-26)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* update dependencies ([754df39](https://github.com/CoCreate-app/CoCreate-selection/commit/754df39e8831d33c4cdaaea4e1ff804a687faabf))
|
7
|
+
|
8
|
+
## [1.2.15](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.14...v1.2.15) (2021-11-24)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* processSelection when at position 0 ([2143e31](https://github.com/CoCreate-app/CoCreate-selection/commit/2143e313e1dcf744980df298790f13442e5715bd))
|
14
|
+
|
15
|
+
## [1.2.14](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.13...v1.2.14) (2021-11-23)
|
16
|
+
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
* update dependencies ([8fd30ea](https://github.com/CoCreate-app/CoCreate-selection/commit/8fd30ea76af01c89e46f7c4e3f97ba0f4101f7e1))
|
21
|
+
|
22
|
+
## [1.2.13](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.12...v1.2.13) (2021-11-23)
|
23
|
+
|
24
|
+
|
25
|
+
### Bug Fixes
|
26
|
+
|
27
|
+
* if node begins with a textNode ([0be3739](https://github.com/CoCreate-app/CoCreate-selection/commit/0be373961d2da5c79b9abc2311133621a163c350))
|
28
|
+
|
1
29
|
## [1.2.12](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.11...v1.2.12) (2021-11-20)
|
2
30
|
|
3
31
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocreate/selection",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.16",
|
4
4
|
"description": "A simple selection component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
5
5
|
"keywords": [
|
6
6
|
"selection",
|
@@ -61,8 +61,8 @@
|
|
61
61
|
"webpack-log": "^3.0.1"
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
|
-
"@cocreate/docs": "^1.2.
|
65
|
-
"@cocreate/hosting": "^1.2.
|
66
|
-
"@cocreate/utils": "^1.3.
|
64
|
+
"@cocreate/docs": "^1.2.56",
|
65
|
+
"@cocreate/hosting": "^1.2.52",
|
66
|
+
"@cocreate/utils": "^1.3.12"
|
67
67
|
}
|
68
68
|
}
|
package/src/index.js
CHANGED
@@ -20,7 +20,7 @@ export function getSelection(element) {
|
|
20
20
|
let start = range.startOffset;
|
21
21
|
let end = range.endOffset;
|
22
22
|
let previousSibling = range.startContainer.previousSibling;
|
23
|
-
if(previousSibling && previousSibling.nodeType == 3) {
|
23
|
+
if(element.innerHTML && previousSibling && previousSibling.nodeType == 3) {
|
24
24
|
let length = 0;
|
25
25
|
do {
|
26
26
|
length += previousSibling.length;
|
@@ -29,6 +29,7 @@ export function getSelection(element) {
|
|
29
29
|
start += length;
|
30
30
|
end += length;
|
31
31
|
}
|
32
|
+
|
32
33
|
if(range.startContainer != range.endContainer) {
|
33
34
|
// toDo: replace common ancestor value
|
34
35
|
}
|
@@ -37,7 +38,7 @@ export function getSelection(element) {
|
|
37
38
|
domTextEditor = element.closest('[contenteditable]');
|
38
39
|
}
|
39
40
|
let elementStart = start, elementEnd = end;
|
40
|
-
if (domTextEditor){
|
41
|
+
if (domTextEditor && domTextEditor.htmlString){
|
41
42
|
let nodePos = getStringPosition({ string: domTextEditor.htmlString, target: range.startContainer.parentElement, position: 'afterbegin'});
|
42
43
|
if (nodePos){
|
43
44
|
elementStart = nodePos.start;
|
@@ -46,11 +47,20 @@ export function getSelection(element) {
|
|
46
47
|
end = end + nodePos.end;
|
47
48
|
}
|
48
49
|
}
|
50
|
+
|
51
|
+
let startContainer = range.startContainer;
|
52
|
+
if (startContainer.nodeType == 3)
|
53
|
+
startContainer = range.startContainer.parentElement;
|
54
|
+
|
55
|
+
let endContainer = range.endContainer;
|
56
|
+
if (endContainer.nodeType == 3)
|
57
|
+
endContainer = range.endContainer.parentElement;
|
58
|
+
|
49
59
|
let rangeObj = {
|
50
60
|
startOffset: range.startOffset,
|
51
61
|
endOffset: range.endOffset,
|
52
|
-
startContainer
|
53
|
-
endContainer
|
62
|
+
startContainer,
|
63
|
+
endContainer,
|
54
64
|
elementStart,
|
55
65
|
elementEnd
|
56
66
|
};
|
@@ -85,8 +95,9 @@ export function processSelection(element, value = "", prev_start, prev_end, star
|
|
85
95
|
}
|
86
96
|
else if (prevStart < prev_start){
|
87
97
|
let length = prev_start - prevStart;
|
88
|
-
if(Math.sign(length) === 1
|
89
|
-
range.startOffset
|
98
|
+
if(Math.sign(length) === 1)
|
99
|
+
if (range.startOffset == 0 || range.startOffset >= length)
|
100
|
+
range.startOffset += length;
|
90
101
|
}
|
91
102
|
if (prevEnd > prev_end){
|
92
103
|
let length = prevEnd - prev_end;
|
@@ -95,8 +106,9 @@ export function processSelection(element, value = "", prev_start, prev_end, star
|
|
95
106
|
}
|
96
107
|
else if (prevEnd < prev_end){
|
97
108
|
let length = prev_end - prevEnd;
|
98
|
-
if(Math.sign(length) === 1
|
99
|
-
range.endOffset
|
109
|
+
if(Math.sign(length) === 1)
|
110
|
+
if (range.endOffset == 0 || range.endOffset >= length)
|
111
|
+
range.endOffset += length;
|
100
112
|
}
|
101
113
|
}
|
102
114
|
|
@@ -177,6 +189,9 @@ export function getElementPosition(str, start, end) {
|
|
177
189
|
findEl.remove();
|
178
190
|
}
|
179
191
|
}
|
192
|
+
else if (angleStart == -1) {
|
193
|
+
type = 'textNode';
|
194
|
+
}
|
180
195
|
else {
|
181
196
|
let node = str.slice(angleStart, startString.length + endStringAngleEnd + 1);
|
182
197
|
if (node.startsWith("</")) {
|