@cocreate/selection 1.2.13 → 1.2.17
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 +28 -0
- package/docs/index.html +8 -2
- package/package.json +4 -4
- package/src/index.js +20 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [1.2.17](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.16...v1.2.17) (2021-11-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add nav and sidenav to docs ([eb6f6f1](https://github.com/CoCreate-app/CoCreate-selection/commit/eb6f6f1d7459a57abea30a3976ce6488a36cbc25))
|
|
7
|
+
|
|
8
|
+
## [1.2.16](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.15...v1.2.16) (2021-11-26)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update dependencies ([754df39](https://github.com/CoCreate-app/CoCreate-selection/commit/754df39e8831d33c4cdaaea4e1ff804a687faabf))
|
|
14
|
+
|
|
15
|
+
## [1.2.15](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.14...v1.2.15) (2021-11-24)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* processSelection when at position 0 ([2143e31](https://github.com/CoCreate-app/CoCreate-selection/commit/2143e313e1dcf744980df298790f13442e5715bd))
|
|
21
|
+
|
|
22
|
+
## [1.2.14](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.13...v1.2.14) (2021-11-23)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* update dependencies ([8fd30ea](https://github.com/CoCreate-app/CoCreate-selection/commit/8fd30ea76af01c89e46f7c4e3f97ba0f4101f7e1))
|
|
28
|
+
|
|
1
29
|
## [1.2.13](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.12...v1.2.13) (2021-11-23)
|
|
2
30
|
|
|
3
31
|
|
package/docs/index.html
CHANGED
|
@@ -15,7 +15,13 @@
|
|
|
15
15
|
</head>
|
|
16
16
|
|
|
17
17
|
<body>
|
|
18
|
-
|
|
18
|
+
<nav class="nav display:flex align-items:center left:0px background:whitesmoke padding-top:10px padding-bottom:10px" content_id="content" scroll="sticky-nav,hide-nav" scroll-up="10" scroll-down="10" collection="files" document_id="60395ef42b3ac232657040fd" name="src">
|
|
19
|
+
</nav>
|
|
20
|
+
<sidenav id="menuL" class="position:fixed top:0px left:0px overflow:hidden background:whitesmoke height:100vh width:0px width:300px@xl" resizable resize-target="[content_id='content']" resize-property="margin-left" resize-value="width">
|
|
21
|
+
<menu collection="files" document_id="603717b07de7fb350ae9fec8" name="src"></menu>
|
|
22
|
+
<div resize="right"></div>
|
|
23
|
+
</sidenav>
|
|
24
|
+
<main class="padding-top:15px padding:15px@lg@xl" content_id="content" id="cocreate-selection">
|
|
19
25
|
<div class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
|
|
20
26
|
<div class="display:flex align-items:center">
|
|
21
27
|
<h2>CoCreate-selection</h2>
|
|
@@ -110,7 +116,7 @@
|
|
|
110
116
|
</div>
|
|
111
117
|
|
|
112
118
|
</div>
|
|
113
|
-
</
|
|
119
|
+
</main>
|
|
114
120
|
<script src="/apikey.js"></script>
|
|
115
121
|
<script src="https://cdn.cocreate.app/latest/CoCreate.min.js" ></script>
|
|
116
122
|
</body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/selection",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.17",
|
|
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
|
|