@cocreate/selection 1.4.29 → 1.4.31
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/package.json +4 -4
- package/src/index.js +8 -8
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [1.4.31](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.4.30...v1.4.31) (2022-11-24)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* bump depenedencies ([d3d841e](https://github.com/CoCreate-app/CoCreate-selection/commit/d3d841ec01e348abd78874b5b8a35843145937fd))
|
7
|
+
|
8
|
+
## [1.4.30](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.4.29...v1.4.30) (2022-11-23)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* bumped [@cocreate](https://github.com/cocreate) dependencies ([e3c9588](https://github.com/CoCreate-app/CoCreate-selection/commit/e3c9588409ffde1ff777d7908e6404cb84a54917))
|
14
|
+
|
1
15
|
## [1.4.29](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.4.28...v1.4.29) (2022-11-22)
|
2
16
|
|
3
17
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocreate/selection",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.31",
|
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.4.
|
65
|
-
"@cocreate/hosting": "^1.6.
|
66
|
-
"@cocreate/utils": "^1.10.
|
64
|
+
"@cocreate/docs": "^1.4.3",
|
65
|
+
"@cocreate/hosting": "^1.6.2",
|
66
|
+
"@cocreate/utils": "^1.10.22"
|
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(element.innerHTML && 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;
|
@@ -30,7 +30,7 @@ export function getSelection(element) {
|
|
30
30
|
end += length;
|
31
31
|
}
|
32
32
|
|
33
|
-
if(range.startContainer != range.endContainer) {
|
33
|
+
if (range.startContainer != range.endContainer) {
|
34
34
|
// toDo: replace common ancestor value
|
35
35
|
}
|
36
36
|
let contenteditable = range.startContainer.parentElement.closest('[contenteditable][collection][document_id][name]');
|
@@ -96,23 +96,23 @@ export function processSelection(element, value = "", prev_start, prev_end, star
|
|
96
96
|
if (range) {
|
97
97
|
if (prevStart > prev_start){
|
98
98
|
let length = prevStart - prev_start;
|
99
|
-
if(Math.sign(length) === 1 && range.startOffset >= length)
|
99
|
+
if (Math.sign(length) === 1 && range.startOffset >= length)
|
100
100
|
range.startOffset -= length;
|
101
101
|
}
|
102
102
|
else if (prevStart < prev_start){
|
103
103
|
let length = prev_start - prevStart;
|
104
|
-
if(Math.sign(length) === 1)
|
104
|
+
if (Math.sign(length) === 1)
|
105
105
|
if (range.startOffset == 0 || range.startOffset >= length)
|
106
106
|
range.startOffset += length;
|
107
107
|
}
|
108
108
|
if (prevEnd > prev_end){
|
109
109
|
let length = prevEnd - prev_end;
|
110
|
-
if(Math.sign(length) === 1 && range.endOffset >= length)
|
110
|
+
if (Math.sign(length) === 1 && range.endOffset >= length)
|
111
111
|
range.endOffset -= length;
|
112
112
|
}
|
113
113
|
else if (prevEnd < prev_end){
|
114
114
|
let length = prev_end - prevEnd;
|
115
|
-
if(Math.sign(length) === 1)
|
115
|
+
if (Math.sign(length) === 1)
|
116
116
|
if (range.endOffset == 0 || range.endOffset >= length)
|
117
117
|
range.endOffset += length;
|
118
118
|
}
|
@@ -163,7 +163,7 @@ function getContainer(element, offset){
|
|
163
163
|
|
164
164
|
export function hasSelection(el) {
|
165
165
|
let { start, end } = getSelection(el);
|
166
|
-
if(start != end) {
|
166
|
+
if (start != end) {
|
167
167
|
return true;
|
168
168
|
}
|
169
169
|
}
|
@@ -236,7 +236,7 @@ export function getElementPosition(str, start, end) {
|
|
236
236
|
let insert = getInsertPosition(element);
|
237
237
|
element = insert.target.parentElement;
|
238
238
|
position = insert.position;
|
239
|
-
if(position == 'afterend')
|
239
|
+
if (position == 'afterend')
|
240
240
|
element = element.parentElement;
|
241
241
|
type = 'innerHTML';
|
242
242
|
}
|