@cocreate/selection 1.2.20 → 1.3.2
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 +33 -0
- package/package.json +4 -4
- package/src/index.js +20 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
## [1.3.2](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.3.1...v1.3.2) (2021-12-15)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* update dependencies ([4204d0b](https://github.com/CoCreate-app/CoCreate-selection/commit/4204d0b9d2848c11b832b556fd184bf1da1610d4))
|
7
|
+
|
8
|
+
## [1.3.1](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.3.0...v1.3.1) (2021-12-14)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* update dependencies ([584a23c](https://github.com/CoCreate-app/CoCreate-selection/commit/584a23c2fafbc2410356f7ac5bff3f9149f5152f))
|
14
|
+
|
15
|
+
# [1.3.0](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.21...v1.3.0) (2021-12-14)
|
16
|
+
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
* update dependencies ([4fa877a](https://github.com/CoCreate-app/CoCreate-selection/commit/4fa877ad1df7ec4a58f050a7132aa3f071ccfd5d))
|
21
|
+
|
22
|
+
|
23
|
+
### Features
|
24
|
+
|
25
|
+
* support nested contenteditable and selections for cursor positions ([8efc22d](https://github.com/CoCreate-app/CoCreate-selection/commit/8efc22d303ba88dbb6fdbf4d65cb2988afec73ca))
|
26
|
+
|
27
|
+
## [1.2.21](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.20...v1.2.21) (2021-12-08)
|
28
|
+
|
29
|
+
|
30
|
+
### Bug Fixes
|
31
|
+
|
32
|
+
* check parent for closest contenteditable, return range.element ([dbe5d32](https://github.com/CoCreate-app/CoCreate-selection/commit/dbe5d32fbfdb3912ddcbe005f24c315fc444f17b))
|
33
|
+
|
1
34
|
## [1.2.20](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.19...v1.2.20) (2021-11-27)
|
2
35
|
|
3
36
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocreate/selection",
|
3
|
-
"version": "1.2
|
3
|
+
"version": "1.3.2",
|
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.
|
64
|
+
"@cocreate/docs": "^1.2.62",
|
65
|
+
"@cocreate/hosting": "^1.2.58",
|
66
|
+
"@cocreate/utils": "^1.4.0"
|
67
67
|
}
|
68
68
|
}
|
package/src/index.js
CHANGED
@@ -33,6 +33,10 @@ export function getSelection(element) {
|
|
33
33
|
if(range.startContainer != range.endContainer) {
|
34
34
|
// toDo: replace common ancestor value
|
35
35
|
}
|
36
|
+
let contenteditable = range.startContainer.parentElement.closest('[contenteditable][collection][document_id][name]');
|
37
|
+
if (contenteditable){
|
38
|
+
element = contenteditable;
|
39
|
+
}
|
36
40
|
let domTextEditor = element;
|
37
41
|
if (!domTextEditor.htmlString){
|
38
42
|
domTextEditor = element.closest('[contenteditable]');
|
@@ -57,6 +61,8 @@ export function getSelection(element) {
|
|
57
61
|
endContainer = range.endContainer.parentElement;
|
58
62
|
|
59
63
|
let rangeObj = {
|
64
|
+
element: contenteditable,
|
65
|
+
// domTextEditor,
|
60
66
|
startOffset: range.startOffset,
|
61
67
|
endOffset: range.endOffset,
|
62
68
|
startContainer,
|
@@ -283,9 +289,17 @@ function getInsertPosition(element){
|
|
283
289
|
|
284
290
|
export function getStringPosition({string, target, position, attribute, property, value}) {
|
285
291
|
try {
|
292
|
+
let element;
|
286
293
|
let selector = cssPath(target, '[contenteditable]');
|
287
294
|
let dom = domParser(string);
|
288
|
-
|
295
|
+
if (!selector.includes('[eid=') && dom.tagName == "DOM-PARSER"){
|
296
|
+
let containerEl = document.createElement('div');
|
297
|
+
containerEl.appendChild(dom)
|
298
|
+
selector = `dom-parser > ${selector}`
|
299
|
+
element = containerEl.querySelector(selector);
|
300
|
+
}
|
301
|
+
else
|
302
|
+
element = dom.querySelector(selector);
|
289
303
|
if (!element){
|
290
304
|
console.log('element could not be found using selector:', selector);
|
291
305
|
return;
|
@@ -418,7 +432,11 @@ function getElFromString(dom, string, element, position, isAttribute) {
|
|
418
432
|
}
|
419
433
|
|
420
434
|
function getPosition(string, subString, index) {
|
421
|
-
|
435
|
+
let angleArray = string.split(subString, index);
|
436
|
+
let startstring = angleArray.join(subString);
|
437
|
+
let start = startstring.length;
|
438
|
+
return start;
|
439
|
+
// return string.split(subString, index).join(subString).length;
|
422
440
|
}
|
423
441
|
|
424
442
|
export default {getSelection, setSelection, hasSelection, processSelection, getStringPosition, getElementPosition};
|