@cocreate/selection
Advanced tools
Comparing version 1.1.7 to 1.2.0
@@ -0,1 +1,8 @@ | ||
# [1.2.0](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.1.7...v1.2.0) (2021-11-05) | ||
### Features | ||
* support for singleton/no-endTag elements ([2be4a89](https://github.com/CoCreate-app/CoCreate-selection/commit/2be4a8965666e9dd24a9804d718432fcff71ffca)) | ||
## [1.1.7](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.1.6...v1.1.7) (2021-11-04) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@cocreate/selection", | ||
"version": "1.1.7", | ||
"version": "1.2.0", | ||
"description": "A simple selection component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,2 +0,1 @@ | ||
/*globals Node*/ | ||
import {cssPath, domParser} from '@cocreate/utils'; | ||
@@ -23,3 +22,3 @@ | ||
let end = range.endOffset; | ||
let previousSibling = range.startContainer.previousSibling | ||
let previousSibling = range.startContainer.previousSibling; | ||
if(previousSibling && previousSibling.nodeType == 3) { | ||
@@ -31,7 +30,7 @@ let length = 0; | ||
} while (previousSibling); | ||
start += length | ||
end += length | ||
start += length; | ||
end += length; | ||
} | ||
if(range.startContainer != range.endContainer) { | ||
// toDo: replace common ancestor value | ||
// toDo: replace common ancestor value | ||
} | ||
@@ -46,4 +45,4 @@ let domTextEditor = element; | ||
if (nodePos){ | ||
elementStart = nodePos.start | ||
elementEnd = nodePos.end | ||
elementStart = nodePos.start; | ||
elementEnd = nodePos.end; | ||
start = start + nodePos.start; | ||
@@ -293,3 +292,3 @@ end = end + nodePos.end; | ||
if (!element.hasAttribute(attribute)){ | ||
start = getElFromString(dom, string, element, 'afterbegin') - 1; | ||
start = getElFromString(dom, string, element, 'afterbegin', true) - 1; | ||
end = start; | ||
@@ -323,3 +322,3 @@ } | ||
else { | ||
element.setAttribute(attribute, value) | ||
element.setAttribute(attribute, value); | ||
value = element.getAttribute(attribute); | ||
@@ -347,3 +346,3 @@ } | ||
function getElFromString(dom, string, element, position, wholeEl) { | ||
function getElFromString(dom, string, element, position, isAttribute) { | ||
let findEl = document.createElement('findelement'); | ||
@@ -372,2 +371,12 @@ let start, angle, documentTypeAngles; | ||
if (start == -1){ | ||
position = 'singleton'; | ||
element.insertAdjacentElement('afterend', findEl); | ||
angle = '>'; | ||
if (dom.tagName == 'HTML') | ||
start = dom.outerHTML.indexOf("<findelement></findelement>"); | ||
else | ||
start = dom.innerHTML.indexOf("<findelement></findelement>"); | ||
} | ||
findEl.remove(); | ||
@@ -384,12 +393,2 @@ | ||
let angleLength = angles.length - 1; | ||
// if (position == 'afterend' && angles[angles.length - 1] === '') | ||
// angleLength -= 1; | ||
// else if (position == 'afterend' && angles[angles.length - 1] !== '') | ||
// angleLength += 1; | ||
// if (wholeEl && position == 'afterend') { | ||
// angleLength += 1; | ||
// } | ||
// if (wholeEl && position == 'beforebegin') { | ||
// angleLength += 1; | ||
// } | ||
if (documentTypeAngles) | ||
@@ -399,11 +398,15 @@ angleLength += documentTypeAngles; | ||
// if (position == 'beforebegin') | ||
// elStart += 1 | ||
if (position == 'afterbegin') | ||
elStart += 1 | ||
elStart += 1; | ||
else if (position == 'beforeend') | ||
elStart += 1 | ||
elStart += 1; | ||
else if (position == 'afterend') | ||
elStart += 1 | ||
elStart += 1; | ||
else if (position == 'singleton'){ | ||
let newString = string.substring(0, elStart); | ||
if (newString.lastIndexOf('/') == newString.length - 1 && isAttribute) | ||
elStart; | ||
else | ||
elStart += 1; | ||
} | ||
return elStart; | ||
@@ -410,0 +413,0 @@ } |
78861
521