@cocreate/selection 1.2.18 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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.0](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.21...v1.3.0) (2021-12-14)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* update dependencies ([4fa877a](https://github.com/CoCreate-app/CoCreate-selection/commit/4fa877ad1df7ec4a58f050a7132aa3f071ccfd5d))
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* support nested contenteditable and selections for cursor positions ([8efc22d](https://github.com/CoCreate-app/CoCreate-selection/commit/8efc22d303ba88dbb6fdbf4d65cb2988afec73ca))
|
12
|
+
|
13
|
+
## [1.2.21](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.20...v1.2.21) (2021-12-08)
|
14
|
+
|
15
|
+
|
16
|
+
### Bug Fixes
|
17
|
+
|
18
|
+
* check parent for closest contenteditable, return range.element ([dbe5d32](https://github.com/CoCreate-app/CoCreate-selection/commit/dbe5d32fbfdb3912ddcbe005f24c315fc444f17b))
|
19
|
+
|
20
|
+
## [1.2.20](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.19...v1.2.20) (2021-11-27)
|
21
|
+
|
22
|
+
|
23
|
+
### Bug Fixes
|
24
|
+
|
25
|
+
* update dependencies ([d0921e7](https://github.com/CoCreate-app/CoCreate-selection/commit/d0921e7174f556203ceb3f5c3bcd3bfdae2abb02))
|
26
|
+
|
27
|
+
## [1.2.19](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.18...v1.2.19) (2021-11-27)
|
28
|
+
|
29
|
+
|
30
|
+
### Bug Fixes
|
31
|
+
|
32
|
+
* update dependencies ([f89acc8](https://github.com/CoCreate-app/CoCreate-selection/commit/f89acc8329f26470a755758756d3dcf225ad84d8))
|
33
|
+
|
1
34
|
## [1.2.18](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.17...v1.2.18) (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.
|
3
|
+
"version": "1.3.0",
|
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.61",
|
65
|
+
"@cocreate/hosting": "^1.2.57",
|
66
|
+
"@cocreate/utils": "^1.3.18"
|
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};
|