mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Cleanup some squire code
This commit is contained in:
parent
e9770e17f6
commit
6b42620ad3
1 changed files with 42 additions and 65 deletions
73
vendors/squire/build/squire-raw.js
vendored
73
vendors/squire/build/squire-raw.js
vendored
|
|
@ -220,52 +220,36 @@ const
|
||||||
},
|
},
|
||||||
|
|
||||||
fixCursor = (node, root) => {
|
fixCursor = (node, root) => {
|
||||||
// In Webkit and Gecko, block level elements are collapsed and
|
let fixer = null;
|
||||||
// unfocusable if they have no content (:empty). To remedy this, a <BR> must be
|
if (node instanceof Text) {
|
||||||
// inserted. In Opera and IE, we just need a textnode in order for the
|
return node;
|
||||||
// cursor to appear.
|
|
||||||
let self = root.__squire__;
|
|
||||||
let originalNode = node;
|
|
||||||
let fixer, child;
|
|
||||||
|
|
||||||
if (node === root) {
|
|
||||||
if (!(child = node.firstChild) || child.nodeName === 'BR') {
|
|
||||||
fixer = self.createDefaultBlock();
|
|
||||||
if (child) {
|
|
||||||
child.replaceWith(fixer);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
node.append(fixer);
|
|
||||||
}
|
|
||||||
node = fixer;
|
|
||||||
fixer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.nodeType === TEXT_NODE) {
|
|
||||||
return originalNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isInline(node)) {
|
if (isInline(node)) {
|
||||||
|
let child = node.firstChild;
|
||||||
|
if (cantFocusEmptyTextNodes) {
|
||||||
|
while (child && child instanceof Text && !child.data) {
|
||||||
|
node.removeChild(child);
|
||||||
child = node.firstChild;
|
child = node.firstChild;
|
||||||
while (isWebKit && child?.nodeType === TEXT_NODE && !child.data) {
|
}
|
||||||
child.remove();
|
|
||||||
child = node.firstChild;
|
|
||||||
}
|
}
|
||||||
if (!child) {
|
if (!child) {
|
||||||
fixer = self._addZWS();
|
if (cantFocusEmptyTextNodes) {
|
||||||
|
fixer = document.createTextNode(ZWS);
|
||||||
|
} else {
|
||||||
|
fixer = document.createTextNode("");
|
||||||
}
|
}
|
||||||
// } else if (!node.querySelector('BR')) {
|
}
|
||||||
// } else if (!node.innerText.trim().length) {
|
} else if (node instanceof Element && !node.querySelector("BR")) {
|
||||||
} else if (node.matches(':empty')) {
|
fixer = createElement("BR");
|
||||||
fixer = createElement('BR');
|
let parent = node;
|
||||||
while ((child = node.lastElementChild) && !isInline(child)) {
|
let child;
|
||||||
node = child;
|
while ((child = parent.lastElementChild) && !isInline(child)) {
|
||||||
|
parent = child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fixer) {
|
if (fixer) {
|
||||||
try {
|
try {
|
||||||
node.append(fixer);
|
node.appendChild(fixer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
didError({
|
didError({
|
||||||
name: 'Squire: fixCursor – ' + error,
|
name: 'Squire: fixCursor – ' + error,
|
||||||
|
|
@ -274,8 +258,7 @@ const
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return node;
|
||||||
return originalNode;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Recursively examine container nodes and wrap any inline children.
|
// Recursively examine container nodes and wrap any inline children.
|
||||||
|
|
@ -959,10 +942,7 @@ const
|
||||||
let startBlock = getStartBlockOfRange(range, root);
|
let startBlock = getStartBlockOfRange(range, root);
|
||||||
let nodeAfterCursor;
|
let nodeAfterCursor;
|
||||||
|
|
||||||
if (!startBlock) {
|
if (startBlock) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If in the middle or end of a text node, we're not at the boundary.
|
// If in the middle or end of a text node, we're not at the boundary.
|
||||||
if (startContainer.nodeType === TEXT_NODE) {
|
if (startContainer.nodeType === TEXT_NODE) {
|
||||||
if (startOffset) {
|
if (startOffset) {
|
||||||
|
|
@ -971,14 +951,10 @@ const
|
||||||
nodeAfterCursor = startContainer;
|
nodeAfterCursor = startContainer;
|
||||||
} else {
|
} else {
|
||||||
nodeAfterCursor = getNodeAfter(startContainer, startOffset);
|
nodeAfterCursor = getNodeAfter(startContainer, startOffset);
|
||||||
if (nodeAfterCursor && !root.contains(nodeAfterCursor)) {
|
|
||||||
nodeAfterCursor = null;
|
|
||||||
}
|
|
||||||
// The cursor was right at the end of the document
|
// The cursor was right at the end of the document
|
||||||
if (!nodeAfterCursor) {
|
if (!nodeAfterCursor || !root.contains(nodeAfterCursor)) {
|
||||||
nodeAfterCursor = getNodeBefore(startContainer, startOffset);
|
nodeAfterCursor = getNodeBefore(startContainer, startOffset);
|
||||||
if (nodeAfterCursor.nodeType === TEXT_NODE &&
|
if (nodeAfterCursor.nodeType === TEXT_NODE && nodeAfterCursor.length) {
|
||||||
nodeAfterCursor.length) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -989,6 +965,7 @@ const
|
||||||
contentWalker.currentNode = nodeAfterCursor;
|
contentWalker.currentNode = nodeAfterCursor;
|
||||||
|
|
||||||
return !contentWalker.previousNode();
|
return !contentWalker.previousNode();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
rangeDoesEndAtBlockBoundary = (range, root) => {
|
rangeDoesEndAtBlockBoundary = (range, root) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue