mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-10-03 18:34:43 +08:00
Updated custom Squire 2.3.2
This commit is contained in:
parent
18452cc53c
commit
05812c6be1
1 changed files with 115 additions and 190 deletions
305
vendors/squire/build/squire-raw.js
vendored
305
vendors/squire/build/squire-raw.js
vendored
|
@ -6,26 +6,39 @@
|
||||||
var SHOW_ELEMENT_OR_TEXT = 5;
|
var SHOW_ELEMENT_OR_TEXT = 5;
|
||||||
|
|
||||||
// source/node/TreeWalker.ts
|
// source/node/TreeWalker.ts
|
||||||
|
var FILTER_ACCEPT = NodeFilter.FILTER_ACCEPT;
|
||||||
TreeWalker.prototype.previousPONode = function() {
|
TreeWalker.prototype.previousPONode = function() {
|
||||||
|
const root = this.root;
|
||||||
let current = this.currentNode;
|
let current = this.currentNode;
|
||||||
let node = current.lastChild;
|
let node;
|
||||||
while (!node && current) {
|
while (true) {
|
||||||
if (current === this.root) {
|
node = current.lastChild;
|
||||||
break;
|
while (!node && current) {
|
||||||
|
if (current === root) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
node = current.previousSibling;
|
||||||
|
if (!node) {
|
||||||
|
current = current.parentNode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
node = this.previousSibling();
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
current = this.parentNode();
|
return null;
|
||||||
}
|
}
|
||||||
|
const nodeType = node.nodeType;
|
||||||
|
const nodeFilterType = nodeType === Node.ELEMENT_NODE ? NodeFilter.SHOW_ELEMENT : nodeType === Node.TEXT_NODE ? NodeFilter.SHOW_TEXT : 0;
|
||||||
|
if (!!(nodeFilterType & this.whatToShow) && FILTER_ACCEPT === this.filter.acceptNode(node)) {
|
||||||
|
this.currentNode = node;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
current = node;
|
||||||
}
|
}
|
||||||
node && (this.currentNode = node);
|
|
||||||
return node;
|
|
||||||
};
|
};
|
||||||
var createTreeWalker = (root, whatToShow, filter) => document.createTreeWalker(
|
var createTreeWalker = (root, whatToShow, filter) => document.createTreeWalker(
|
||||||
root,
|
root,
|
||||||
whatToShow,
|
whatToShow,
|
||||||
{
|
{
|
||||||
acceptNode: (node) => !filter || filter(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
acceptNode: (node) => !filter || filter(node) ? FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -46,7 +59,7 @@
|
||||||
|
|
||||||
// source/node/Category.ts
|
// source/node/Category.ts
|
||||||
var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/;
|
var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/;
|
||||||
var leafNodeNames = /* @__PURE__ */ new Set(["BR", "HR", "IFRAME", "IMG", "INPUT"]);
|
var leafNodeNames = /* @__PURE__ */ new Set(["BR", "HR", "IMG"]);
|
||||||
var UNKNOWN = 0;
|
var UNKNOWN = 0;
|
||||||
var INLINE = 1;
|
var INLINE = 1;
|
||||||
var BLOCK = 2;
|
var BLOCK = 2;
|
||||||
|
@ -55,9 +68,7 @@
|
||||||
var resetNodeCategoryCache = () => {
|
var resetNodeCategoryCache = () => {
|
||||||
cache = /* @__PURE__ */ new WeakMap();
|
cache = /* @__PURE__ */ new WeakMap();
|
||||||
};
|
};
|
||||||
var isLeaf = (node) => {
|
var isLeaf = (node) => leafNodeNames.has(node.nodeName);
|
||||||
return leafNodeNames.has(node.nodeName);
|
|
||||||
};
|
|
||||||
var getNodeCategory = (node) => {
|
var getNodeCategory = (node) => {
|
||||||
switch (node.nodeType) {
|
switch (node.nodeType) {
|
||||||
case TEXT_NODE:
|
case TEXT_NODE:
|
||||||
|
@ -82,15 +93,9 @@
|
||||||
cache.set(node, nodeCategory);
|
cache.set(node, nodeCategory);
|
||||||
return nodeCategory;
|
return nodeCategory;
|
||||||
};
|
};
|
||||||
var isInline = (node) => {
|
var isInline = (node) => getNodeCategory(node) === INLINE;
|
||||||
return getNodeCategory(node) === INLINE;
|
var isBlock = (node) => getNodeCategory(node) === BLOCK;
|
||||||
};
|
var isContainer = (node) => getNodeCategory(node) === CONTAINER;
|
||||||
var isBlock = (node) => {
|
|
||||||
return getNodeCategory(node) === BLOCK;
|
|
||||||
};
|
|
||||||
var isContainer = (node) => {
|
|
||||||
return getNodeCategory(node) === CONTAINER;
|
|
||||||
};
|
|
||||||
|
|
||||||
// source/node/Node.ts
|
// source/node/Node.ts
|
||||||
var createElement = (tag, props, children) => {
|
var createElement = (tag, props, children) => {
|
||||||
|
@ -161,31 +166,17 @@
|
||||||
}
|
}
|
||||||
return returnNode;
|
return returnNode;
|
||||||
};
|
};
|
||||||
var getLength = (node) => {
|
var getLength = (node) => node instanceof Element || node instanceof DocumentFragment ? node.childNodes.length : node instanceof CharacterData ? node.length : 0;
|
||||||
return node instanceof Element || node instanceof DocumentFragment ? node.childNodes.length : node instanceof CharacterData ? node.length : 0;
|
|
||||||
};
|
|
||||||
var empty = (node) => {
|
var empty = (node) => {
|
||||||
const frag = document.createDocumentFragment();
|
const frag = document.createDocumentFragment();
|
||||||
let child = node.firstChild;
|
frag.append(...node.childNodes);
|
||||||
while (child) {
|
|
||||||
frag.append(child);
|
|
||||||
child = node.firstChild;
|
|
||||||
}
|
|
||||||
return frag;
|
return frag;
|
||||||
};
|
};
|
||||||
var detach = (node) => {
|
var detach = (node) => {
|
||||||
const parent = node.parentNode;
|
node.parentNode?.removeChild(node);
|
||||||
if (parent) {
|
|
||||||
parent.removeChild(node);
|
|
||||||
}
|
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
var replaceWith = (node, node2) => {
|
var replaceWith = (node, node2) => node.parentNode?.replaceChild(node2, node);
|
||||||
const parent = node.parentNode;
|
|
||||||
if (parent) {
|
|
||||||
parent.replaceChild(node2, node);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var getClosest = (node, root, selector) => {
|
var getClosest = (node, root, selector) => {
|
||||||
node = (node && !node.closest ? node.parentElement : node)?.closest(selector);
|
node = (node && !node.closest ? node.parentElement : node)?.closest(selector);
|
||||||
return node && root.contains(node) ? node : null;
|
return node && root.contains(node) ? node : null;
|
||||||
|
@ -203,12 +194,10 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// source/node/Whitespace.ts
|
// source/node/Whitespace.ts
|
||||||
var notWSTextNode = (node) => {
|
var notWSTextNode = (node) => node instanceof Element ? node.nodeName === "BR" : (
|
||||||
return node instanceof Element ? node.nodeName === "BR" : (
|
// okay if data is 'undefined' here.
|
||||||
// okay if data is 'undefined' here.
|
notWS.test(node.data)
|
||||||
notWS.test(node.data)
|
);
|
||||||
);
|
|
||||||
};
|
|
||||||
var isLineBreak = (br, isLBIfEmptyBlock) => {
|
var isLineBreak = (br, isLBIfEmptyBlock) => {
|
||||||
let block = br.parentNode;
|
let block = br.parentNode;
|
||||||
while (isInline(block)) {
|
while (isInline(block)) {
|
||||||
|
@ -291,7 +280,7 @@
|
||||||
const child = endContainer.childNodes[endOffset - 1];
|
const child = endContainer.childNodes[endOffset - 1];
|
||||||
if (!child || isLeaf(child)) {
|
if (!child || isLeaf(child)) {
|
||||||
if (child && child.nodeName === "BR" && !isLineBreak(child, false)) {
|
if (child && child.nodeName === "BR" && !isLineBreak(child, false)) {
|
||||||
endOffset -= 1;
|
--endOffset;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -335,7 +324,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (endContainer.nodeType !== TEXT_NODE && endContainer.childNodes[endOffset] && endContainer.childNodes[endOffset].nodeName === "BR" && !isLineBreak(endContainer.childNodes[endOffset], false)) {
|
if (endContainer.nodeType !== TEXT_NODE && endContainer.childNodes[endOffset] && endContainer.childNodes[endOffset].nodeName === "BR" && !isLineBreak(endContainer.childNodes[endOffset], false)) {
|
||||||
endOffset += 1;
|
++endOffset;
|
||||||
}
|
}
|
||||||
if (endOffset !== getLength(endContainer)) {
|
if (endOffset !== getLength(endContainer)) {
|
||||||
break;
|
break;
|
||||||
|
@ -400,32 +389,24 @@
|
||||||
};
|
};
|
||||||
var fixContainer = (container, root) => {
|
var fixContainer = (container, root) => {
|
||||||
let wrapper = null;
|
let wrapper = null;
|
||||||
Array.from(container.childNodes).forEach((child) => {
|
[...container.childNodes].forEach((child) => {
|
||||||
const isBR = child.nodeName === "BR";
|
const isBR = child.nodeName === "BR";
|
||||||
if (!isBR && isInline(child)) {
|
if (!isBR && child.parentNode == root && isInline(child)) {
|
||||||
if (!wrapper) {
|
wrapper || (wrapper = createElement("DIV"));
|
||||||
wrapper = createElement("DIV");
|
|
||||||
}
|
|
||||||
wrapper.append(child);
|
wrapper.append(child);
|
||||||
} else if (isBR || wrapper) {
|
} else if (isBR || wrapper) {
|
||||||
if (!wrapper) {
|
wrapper || (wrapper = createElement("DIV"));
|
||||||
wrapper = createElement("DIV");
|
|
||||||
}
|
|
||||||
fixCursor(wrapper);
|
fixCursor(wrapper);
|
||||||
if (isBR) {
|
if (isBR) {
|
||||||
container.replaceChild(wrapper, child);
|
child.replaceWith(wrapper);
|
||||||
} else {
|
} else {
|
||||||
container.insertBefore(wrapper, child);
|
container.insertBefore(wrapper, child);
|
||||||
}
|
}
|
||||||
wrapper = null;
|
wrapper = null;
|
||||||
}
|
}
|
||||||
if (isContainer(child)) {
|
isContainer(child) && fixContainer(child, root);
|
||||||
fixContainer(child, root);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (wrapper) {
|
wrapper && container.append(fixCursor(wrapper));
|
||||||
container.append(fixCursor(wrapper));
|
|
||||||
}
|
|
||||||
return container;
|
return container;
|
||||||
};
|
};
|
||||||
var split = (node, offset, stopNode, root) => {
|
var split = (node, offset, stopNode, root) => {
|
||||||
|
@ -454,7 +435,7 @@
|
||||||
}
|
}
|
||||||
fixCursor(node);
|
fixCursor(node);
|
||||||
fixCursor(clone);
|
fixCursor(clone);
|
||||||
parent.insertBefore(clone, node.nextSibling);
|
node.after(clone);
|
||||||
return split(parent, clone, stopNode, root);
|
return split(parent, clone, stopNode, root);
|
||||||
};
|
};
|
||||||
var _mergeInlines = (node, fakeRange) => {
|
var _mergeInlines = (node, fakeRange) => {
|
||||||
|
@ -475,7 +456,7 @@
|
||||||
}
|
}
|
||||||
if (fakeRange.startContainer === node) {
|
if (fakeRange.startContainer === node) {
|
||||||
if (fakeRange.startOffset > l) {
|
if (fakeRange.startOffset > l) {
|
||||||
fakeRange.startOffset -= 1;
|
--fakeRange.startOffset;
|
||||||
} else if (fakeRange.startOffset === l) {
|
} else if (fakeRange.startOffset === l) {
|
||||||
fakeRange.startContainer = prev;
|
fakeRange.startContainer = prev;
|
||||||
fakeRange.startOffset = getLength(prev);
|
fakeRange.startOffset = getLength(prev);
|
||||||
|
@ -483,7 +464,7 @@
|
||||||
}
|
}
|
||||||
if (fakeRange.endContainer === node) {
|
if (fakeRange.endContainer === node) {
|
||||||
if (fakeRange.endOffset > l) {
|
if (fakeRange.endOffset > l) {
|
||||||
fakeRange.endOffset -= 1;
|
--fakeRange.endOffset;
|
||||||
} else if (fakeRange.endOffset === l) {
|
} else if (fakeRange.endOffset === l) {
|
||||||
fakeRange.endContainer = prev;
|
fakeRange.endContainer = prev;
|
||||||
fakeRange.endOffset = getLength(prev);
|
fakeRange.endOffset = getLength(prev);
|
||||||
|
@ -529,8 +510,8 @@
|
||||||
offset = block.childNodes.length;
|
offset = block.childNodes.length;
|
||||||
const last = block.lastChild;
|
const last = block.lastChild;
|
||||||
if (last && last.nodeName === "BR") {
|
if (last && last.nodeName === "BR") {
|
||||||
block.removeChild(last);
|
last.remove();
|
||||||
offset -= 1;
|
--offset;
|
||||||
}
|
}
|
||||||
block.append(empty(next));
|
block.append(empty(next));
|
||||||
range.setStart(block, offset);
|
range.setStart(block, offset);
|
||||||
|
@ -546,23 +527,18 @@
|
||||||
}
|
}
|
||||||
if (prev && areAlike(prev, node)) {
|
if (prev && areAlike(prev, node)) {
|
||||||
if (!isContainer(prev)) {
|
if (!isContainer(prev)) {
|
||||||
if (isListItem) {
|
if (!isListItem) {
|
||||||
const block = createElement("DIV");
|
|
||||||
block.append(empty(prev));
|
|
||||||
prev.append(block);
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const block = createElement("DIV");
|
||||||
|
block.append(empty(prev));
|
||||||
|
prev.append(block);
|
||||||
}
|
}
|
||||||
detach(node);
|
detach(node);
|
||||||
const needsFix = !isContainer(node);
|
const needsFix = !isContainer(node);
|
||||||
prev.append(empty(node));
|
prev.append(empty(node));
|
||||||
if (needsFix) {
|
needsFix && fixContainer(prev, root);
|
||||||
fixContainer(prev, root);
|
first && mergeContainers(first, root);
|
||||||
}
|
|
||||||
if (first) {
|
|
||||||
mergeContainers(first, root);
|
|
||||||
}
|
|
||||||
} else if (isListItem) {
|
} else if (isListItem) {
|
||||||
const block = createElement("DIV");
|
const block = createElement("DIV");
|
||||||
node.insertBefore(block, first);
|
node.insertBefore(block, first);
|
||||||
|
@ -645,7 +621,7 @@
|
||||||
return (node, parent) => {
|
return (node, parent) => {
|
||||||
const el = createElement(tag);
|
const el = createElement(tag);
|
||||||
const attributes = node.attributes;
|
const attributes = node.attributes;
|
||||||
for (let i = 0, l = attributes.length; i < l; i += 1) {
|
for (let i = 0, l = attributes.length; i < l; ++i) {
|
||||||
const attribute = attributes[i];
|
const attribute = attributes[i];
|
||||||
el.setAttribute(attribute.name, attribute.value);
|
el.setAttribute(attribute.name, attribute.value);
|
||||||
}
|
}
|
||||||
|
@ -655,13 +631,15 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
var fontSizes = {
|
var fontSizes = {
|
||||||
"1": "10",
|
"1": "x-small",
|
||||||
"2": "13",
|
"2": "small",
|
||||||
"3": "16",
|
"3": "medium",
|
||||||
"4": "18",
|
"4": "large",
|
||||||
"5": "24",
|
"5": "x-large",
|
||||||
"6": "32",
|
"6": "xx-large",
|
||||||
"7": "48"
|
"7": "xxx-large",
|
||||||
|
"-1": "smaller",
|
||||||
|
"+1": "larger"
|
||||||
};
|
};
|
||||||
var stylesRewriters = {
|
var stylesRewriters = {
|
||||||
STRONG: replaceWithTag("B"),
|
STRONG: replaceWithTag("B"),
|
||||||
|
@ -674,62 +652,31 @@
|
||||||
const face = font.face;
|
const face = font.face;
|
||||||
const size = font.size;
|
const size = font.size;
|
||||||
let color = font.color;
|
let color = font.color;
|
||||||
const classNames = config.classNames;
|
let newTag = createElement("SPAN");
|
||||||
let fontSpan;
|
let css = newTag.style;
|
||||||
let sizeSpan;
|
newTag.style.cssText = node.style.cssText;
|
||||||
let colorSpan;
|
|
||||||
let newTreeBottom;
|
|
||||||
let newTreeTop;
|
|
||||||
if (face) {
|
if (face) {
|
||||||
fontSpan = createElement("SPAN", {
|
css.fontFamily = face;
|
||||||
class: classNames.fontFamily,
|
|
||||||
style: "font-family:" + face
|
|
||||||
});
|
|
||||||
newTreeTop = fontSpan;
|
|
||||||
newTreeBottom = fontSpan;
|
|
||||||
}
|
}
|
||||||
if (size) {
|
if (size) {
|
||||||
sizeSpan = createElement("SPAN", {
|
css.fontSize = fontSizes[size];
|
||||||
class: classNames.fontSize,
|
|
||||||
style: "font-size:" + fontSizes[size] + "px"
|
|
||||||
});
|
|
||||||
if (!newTreeTop) {
|
|
||||||
newTreeTop = sizeSpan;
|
|
||||||
}
|
|
||||||
if (newTreeBottom) {
|
|
||||||
newTreeBottom.append(sizeSpan);
|
|
||||||
}
|
|
||||||
newTreeBottom = sizeSpan;
|
|
||||||
}
|
}
|
||||||
if (color && /^#?([\dA-F]{3}){1,2}$/i.test(color)) {
|
if (color && /^#?([\dA-F]{3}){1,2}$/i.test(color)) {
|
||||||
if (color.charAt(0) !== "#") {
|
if (color.charAt(0) !== "#") {
|
||||||
color = "#" + color;
|
color = "#" + color;
|
||||||
}
|
}
|
||||||
colorSpan = createElement("SPAN", {
|
css.color = color;
|
||||||
class: classNames.color,
|
|
||||||
style: "color:" + color
|
|
||||||
});
|
|
||||||
if (!newTreeTop) {
|
|
||||||
newTreeTop = colorSpan;
|
|
||||||
}
|
|
||||||
if (newTreeBottom) {
|
|
||||||
newTreeBottom.append(colorSpan);
|
|
||||||
}
|
|
||||||
newTreeBottom = colorSpan;
|
|
||||||
}
|
}
|
||||||
if (!newTreeTop || !newTreeBottom) {
|
replaceWith(node, newTag);
|
||||||
newTreeTop = newTreeBottom = createElement("SPAN");
|
newTag.append(empty(node));
|
||||||
}
|
return newTag;
|
||||||
parent.replaceChild(newTreeTop, font);
|
|
||||||
newTreeBottom.append(empty(font));
|
|
||||||
return newTreeBottom;
|
|
||||||
},
|
},
|
||||||
TT: (node, parent, config) => {
|
TT: (node, parent, config) => {
|
||||||
const el = createElement("SPAN", {
|
const el = createElement("SPAN", {
|
||||||
class: config.classNames.fontFamily,
|
class: config.classNames.fontFamily,
|
||||||
style: 'font-family:menlo,consolas,"courier new",monospace'
|
style: 'font-family:menlo,consolas,"courier new",monospace'
|
||||||
});
|
});
|
||||||
parent.replaceChild(el, node);
|
replaceWith(node, el);
|
||||||
el.append(empty(node));
|
el.append(empty(node));
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
@ -788,7 +735,7 @@
|
||||||
const brs = node.querySelectorAll("BR");
|
const brs = node.querySelectorAll("BR");
|
||||||
const brBreaksLine = [];
|
const brBreaksLine = [];
|
||||||
let l = brs.length;
|
let l = brs.length;
|
||||||
for (let i = 0; i < l; i += 1) {
|
for (let i = 0; i < l; ++i) {
|
||||||
brBreaksLine[i] = isLineBreak(brs[i], keepForBlankLine);
|
brBreaksLine[i] = isLineBreak(brs[i], keepForBlankLine);
|
||||||
}
|
}
|
||||||
while (l--) {
|
while (l--) {
|
||||||
|
@ -869,7 +816,7 @@
|
||||||
let nodeAfterCursor;
|
let nodeAfterCursor;
|
||||||
if (startContainer instanceof Text) {
|
if (startContainer instanceof Text) {
|
||||||
const text = startContainer.data;
|
const text = startContainer.data;
|
||||||
for (let i = startOffset; i > 0; i -= 1) {
|
for (let i = startOffset; i > 0; --i) {
|
||||||
if (text.charAt(i - 1) !== ZWS) {
|
if (text.charAt(i - 1) !== ZWS) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -906,7 +853,7 @@
|
||||||
if (endContainer instanceof Text) {
|
if (endContainer instanceof Text) {
|
||||||
const text = endContainer.data;
|
const text = endContainer.data;
|
||||||
const length = text.length;
|
const length = text.length;
|
||||||
for (let i = endOffset; i < length; i += 1) {
|
for (let i = endOffset; i < length; ++i) {
|
||||||
if (text.charAt(i) !== ZWS) {
|
if (text.charAt(i) !== ZWS) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -969,7 +916,7 @@
|
||||||
endOffset -= startOffset;
|
endOffset -= startOffset;
|
||||||
endContainer = afterSplit;
|
endContainer = afterSplit;
|
||||||
} else if (endContainer === parent) {
|
} else if (endContainer === parent) {
|
||||||
endOffset += 1;
|
++endOffset;
|
||||||
}
|
}
|
||||||
startContainer = afterSplit;
|
startContainer = afterSplit;
|
||||||
}
|
}
|
||||||
|
@ -1223,7 +1170,7 @@
|
||||||
let textContent = "";
|
let textContent = "";
|
||||||
let addedTextInBlock = false;
|
let addedTextInBlock = false;
|
||||||
let value;
|
let value;
|
||||||
if (!(node instanceof Element) && !(node instanceof Text) || NodeFilter.FILTER_ACCEPT !== walker.filter.acceptNode(node)) {
|
if (!(node instanceof Element) && !(node instanceof Text) || FILTER_ACCEPT !== walker.filter.acceptNode(node)) {
|
||||||
node = walker.nextNode();
|
node = walker.nextNode();
|
||||||
}
|
}
|
||||||
while (node) {
|
while (node) {
|
||||||
|
@ -2271,7 +2218,7 @@
|
||||||
);
|
);
|
||||||
let endOffset = Array.from(endContainer.childNodes).indexOf(end);
|
let endOffset = Array.from(endContainer.childNodes).indexOf(end);
|
||||||
if (startContainer === endContainer) {
|
if (startContainer === endContainer) {
|
||||||
endOffset -= 1;
|
--endOffset;
|
||||||
}
|
}
|
||||||
start.remove();
|
start.remove();
|
||||||
end.remove();
|
end.remove();
|
||||||
|
@ -2509,7 +2456,7 @@
|
||||||
}
|
}
|
||||||
const html = this._getRawHTML();
|
const html = this._getRawHTML();
|
||||||
if (replace) {
|
if (replace) {
|
||||||
undoIndex -= 1;
|
--undoIndex;
|
||||||
}
|
}
|
||||||
if (undoThreshold > -1 && html.length * 2 > undoThreshold) {
|
if (undoThreshold > -1 && html.length * 2 > undoThreshold) {
|
||||||
if (undoLimit > -1 && undoIndex > undoLimit) {
|
if (undoLimit > -1 && undoIndex > undoLimit) {
|
||||||
|
@ -2520,15 +2467,13 @@
|
||||||
}
|
}
|
||||||
undoStack[undoIndex] = html;
|
undoStack[undoIndex] = html;
|
||||||
this._undoIndex = undoIndex;
|
this._undoIndex = undoIndex;
|
||||||
this._undoStackLength += 1;
|
++this._undoStackLength;
|
||||||
this._isInUndoState = true;
|
this._isInUndoState = true;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
saveUndoState(range) {
|
saveUndoState(range) {
|
||||||
if (!range) {
|
range || (range = this.getSelection());
|
||||||
range = this.getSelection();
|
|
||||||
}
|
|
||||||
this._recordUndoState(range, this._isInUndoState);
|
this._recordUndoState(range, this._isInUndoState);
|
||||||
this._getRangeAndRemoveBookmark(range);
|
this._getRangeAndRemoveBookmark(range);
|
||||||
return this;
|
return this;
|
||||||
|
@ -2536,7 +2481,7 @@
|
||||||
undo() {
|
undo() {
|
||||||
if (this._undoIndex !== 0 || !this._isInUndoState) {
|
if (this._undoIndex !== 0 || !this._isInUndoState) {
|
||||||
this._recordUndoState(this.getSelection(), false);
|
this._recordUndoState(this.getSelection(), false);
|
||||||
this._undoIndex -= 1;
|
--this._undoIndex;
|
||||||
this._setRawHTML(this._undoStack[this._undoIndex]);
|
this._setRawHTML(this._undoStack[this._undoIndex]);
|
||||||
const range = this._getRangeAndRemoveBookmark();
|
const range = this._getRangeAndRemoveBookmark();
|
||||||
if (range) {
|
if (range) {
|
||||||
|
@ -2555,7 +2500,7 @@
|
||||||
const undoIndex = this._undoIndex;
|
const undoIndex = this._undoIndex;
|
||||||
const undoStackLength = this._undoStackLength;
|
const undoStackLength = this._undoStackLength;
|
||||||
if (undoIndex + 1 < undoStackLength && this._isInUndoState) {
|
if (undoIndex + 1 < undoStackLength && this._isInUndoState) {
|
||||||
this._undoIndex += 1;
|
++this._undoIndex;
|
||||||
this._setRawHTML(this._undoStack[this._undoIndex]);
|
this._setRawHTML(this._undoStack[this._undoIndex]);
|
||||||
const range = this._getRangeAndRemoveBookmark();
|
const range = this._getRangeAndRemoveBookmark();
|
||||||
if (range) {
|
if (range) {
|
||||||
|
@ -2577,23 +2522,15 @@
|
||||||
return this._root.innerHTML;
|
return this._root.innerHTML;
|
||||||
}
|
}
|
||||||
_setRawHTML(html) {
|
_setRawHTML(html) {
|
||||||
const root = this._root;
|
if (html !== void 0) {
|
||||||
root.innerHTML = html;
|
const root = this._root;
|
||||||
let node = root;
|
let node = root;
|
||||||
const child = node.firstChild;
|
root.innerHTML = html;
|
||||||
if (!child || child.nodeName === "BR") {
|
do {
|
||||||
const block = this.createDefaultBlock();
|
|
||||||
if (child) {
|
|
||||||
node.replaceChild(block, child);
|
|
||||||
} else {
|
|
||||||
node.append(block);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (node = getNextBlock(node, root)) {
|
|
||||||
fixCursor(node);
|
fixCursor(node);
|
||||||
}
|
} while (node = getNextBlock(node, root));
|
||||||
|
this._ignoreChange = true;
|
||||||
}
|
}
|
||||||
this._ignoreChange = true;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
getHTML(withBookmark) {
|
getHTML(withBookmark) {
|
||||||
|
@ -2798,7 +2735,7 @@
|
||||||
openBlock += " " + attr + '="' + escapeHTML(attributes[attr]) + '"';
|
openBlock += " " + attr + '="' + escapeHTML(attributes[attr]) + '"';
|
||||||
}
|
}
|
||||||
openBlock += ">";
|
openBlock += ">";
|
||||||
for (let i = 0, l = lines.length; i < l; i += 1) {
|
for (let i = 0, l = lines.length; i < l; ++i) {
|
||||||
let line = lines[i];
|
let line = lines[i];
|
||||||
line = escapeHTML(line).replace(/ (?=(?: |$))/g, " ");
|
line = escapeHTML(line).replace(/ (?=(?: |$))/g, " ");
|
||||||
if (i) {
|
if (i) {
|
||||||
|
@ -2839,22 +2776,22 @@
|
||||||
const color = style.color;
|
const color = style.color;
|
||||||
if (!fontInfo.color && color) {
|
if (!fontInfo.color && color) {
|
||||||
fontInfo.color = color;
|
fontInfo.color = color;
|
||||||
seenAttributes += 1;
|
++seenAttributes;
|
||||||
}
|
}
|
||||||
const backgroundColor = style.backgroundColor;
|
const backgroundColor = style.backgroundColor;
|
||||||
if (!fontInfo.backgroundColor && backgroundColor) {
|
if (!fontInfo.backgroundColor && backgroundColor) {
|
||||||
fontInfo.backgroundColor = backgroundColor;
|
fontInfo.backgroundColor = backgroundColor;
|
||||||
seenAttributes += 1;
|
++seenAttributes;
|
||||||
}
|
}
|
||||||
const fontFamily = style.fontFamily;
|
const fontFamily = style.fontFamily;
|
||||||
if (!fontInfo.fontFamily && fontFamily) {
|
if (!fontInfo.fontFamily && fontFamily) {
|
||||||
fontInfo.fontFamily = fontFamily;
|
fontInfo.fontFamily = fontFamily;
|
||||||
seenAttributes += 1;
|
++seenAttributes;
|
||||||
}
|
}
|
||||||
const fontSize = style.fontSize;
|
const fontSize = style.fontSize;
|
||||||
if (!fontInfo.fontSize && fontSize) {
|
if (!fontInfo.fontSize && fontSize) {
|
||||||
fontInfo.fontSize = fontSize;
|
fontInfo.fontSize = fontSize;
|
||||||
seenAttributes += 1;
|
++seenAttributes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
element = element.parentNode;
|
element = element.parentNode;
|
||||||
|
@ -2868,12 +2805,8 @@
|
||||||
*/
|
*/
|
||||||
hasFormat(tag, attributes, range) {
|
hasFormat(tag, attributes, range) {
|
||||||
tag = tag.toUpperCase();
|
tag = tag.toUpperCase();
|
||||||
if (!attributes) {
|
attributes || (attributes = {});
|
||||||
attributes = {};
|
range || (range = this.getSelection());
|
||||||
}
|
|
||||||
if (!range) {
|
|
||||||
range = this.getSelection();
|
|
||||||
}
|
|
||||||
if (!range.collapsed && range.startContainer instanceof Text && range.startOffset === range.startContainer.length && range.startContainer.nextSibling) {
|
if (!range.collapsed && range.startContainer instanceof Text && range.startOffset === range.startContainer.length && range.startContainer.nextSibling) {
|
||||||
range.setStartBefore(range.startContainer.nextSibling);
|
range.setStartBefore(range.startContainer.nextSibling);
|
||||||
}
|
}
|
||||||
|
@ -2888,9 +2821,11 @@
|
||||||
if (common instanceof Text) {
|
if (common instanceof Text) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const walker = createTreeWalker(common, SHOW_TEXT, (node2) => {
|
const walker = createTreeWalker(
|
||||||
return isNodeContainedInRange(range, node2, true);
|
common,
|
||||||
});
|
SHOW_TEXT,
|
||||||
|
(node2) => isNodeContainedInRange(range, node2, true)
|
||||||
|
);
|
||||||
let seenNode = false;
|
let seenNode = false;
|
||||||
let node;
|
let node;
|
||||||
while (node = walker.nextNode()) {
|
while (node = walker.nextNode()) {
|
||||||
|
@ -2949,7 +2884,7 @@
|
||||||
);
|
);
|
||||||
let { startContainer, startOffset, endContainer, endOffset } = range;
|
let { startContainer, startOffset, endContainer, endOffset } = range;
|
||||||
walker.currentNode = startContainer;
|
walker.currentNode = startContainer;
|
||||||
if (!(startContainer instanceof Element) && !(startContainer instanceof Text) || NodeFilter.FILTER_ACCEPT !== walker.filter.acceptNode(startContainer)) {
|
if (!(startContainer instanceof Element) && !(startContainer instanceof Text) || FILTER_ACCEPT !== walker.filter.acceptNode(startContainer)) {
|
||||||
const next = walker.nextNode();
|
const next = walker.nextNode();
|
||||||
if (!next) {
|
if (!next) {
|
||||||
return range;
|
return range;
|
||||||
|
@ -2970,7 +2905,7 @@
|
||||||
endContainer = node;
|
endContainer = node;
|
||||||
endOffset -= startOffset;
|
endOffset -= startOffset;
|
||||||
} else if (endContainer === startContainer.parentNode) {
|
} else if (endContainer === startContainer.parentNode) {
|
||||||
endOffset += 1;
|
++endOffset;
|
||||||
}
|
}
|
||||||
startContainer = node;
|
startContainer = node;
|
||||||
startOffset = 0;
|
startOffset = 0;
|
||||||
|
@ -3041,33 +2976,23 @@
|
||||||
).filter((el) => {
|
).filter((el) => {
|
||||||
return isNodeContainedInRange(range, el, true) && hasTagAttributes(el, tag, attributes);
|
return isNodeContainedInRange(range, el, true) && hasTagAttributes(el, tag, attributes);
|
||||||
});
|
});
|
||||||
if (!partial) {
|
partial || formatTags.forEach((node) => examineNode(node, node));
|
||||||
formatTags.forEach((node) => {
|
|
||||||
examineNode(node, node);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
toWrap.forEach(([el, node]) => {
|
toWrap.forEach(([el, node]) => {
|
||||||
el = el.cloneNode(false);
|
el = el.cloneNode(false);
|
||||||
replaceWith(node, el);
|
replaceWith(node, el);
|
||||||
el.append(node);
|
el.append(node);
|
||||||
});
|
});
|
||||||
formatTags.forEach((el) => {
|
formatTags.forEach((el) => replaceWith(el, empty(el)));
|
||||||
replaceWith(el, empty(el));
|
|
||||||
});
|
|
||||||
if (cantFocusEmptyTextNodes && fixer) {
|
if (cantFocusEmptyTextNodes && fixer) {
|
||||||
fixer = fixer.parentNode;
|
fixer = fixer.parentNode;
|
||||||
let block = fixer;
|
let block = fixer;
|
||||||
while (block && isInline(block)) {
|
while (block && isInline(block)) {
|
||||||
block = block.parentNode;
|
block = block.parentNode;
|
||||||
}
|
}
|
||||||
if (block) {
|
block && removeZWS(block, fixer);
|
||||||
removeZWS(block, fixer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this._getRangeAndRemoveBookmark(range);
|
this._getRangeAndRemoveBookmark(range);
|
||||||
if (fixer) {
|
fixer && range.collapse(false);
|
||||||
range.collapse(false);
|
|
||||||
}
|
|
||||||
mergeInlines(root, range);
|
mergeInlines(root, range);
|
||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
@ -3097,7 +3022,7 @@
|
||||||
let protocolEnd = url.indexOf(":") + 1;
|
let protocolEnd = url.indexOf(":") + 1;
|
||||||
if (protocolEnd) {
|
if (protocolEnd) {
|
||||||
while (url[protocolEnd] === "/") {
|
while (url[protocolEnd] === "/") {
|
||||||
protocolEnd += 1;
|
++protocolEnd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insertNodeInRange(
|
insertNodeInRange(
|
||||||
|
@ -3574,13 +3499,13 @@
|
||||||
const lists = frag.querySelectorAll("UL, OL");
|
const lists = frag.querySelectorAll("UL, OL");
|
||||||
const items = frag.querySelectorAll("LI");
|
const items = frag.querySelectorAll("LI");
|
||||||
const root = this._root;
|
const root = this._root;
|
||||||
for (let i = 0, l = lists.length; i < l; i += 1) {
|
for (let i = 0, l = lists.length; i < l; ++i) {
|
||||||
const list = lists[i];
|
const list = lists[i];
|
||||||
const listFrag = empty(list);
|
const listFrag = empty(list);
|
||||||
fixContainer(listFrag, root);
|
fixContainer(listFrag, root);
|
||||||
replaceWith(list, listFrag);
|
replaceWith(list, listFrag);
|
||||||
}
|
}
|
||||||
for (let i = 0, l = items.length; i < l; i += 1) {
|
for (let i = 0, l = items.length; i < l; ++i) {
|
||||||
const item = items[i];
|
const item = items[i];
|
||||||
if (isBlock(item)) {
|
if (isBlock(item)) {
|
||||||
replaceWith(item, this.createDefaultBlock([empty(item)]));
|
replaceWith(item, this.createDefaultBlock([empty(item)]));
|
||||||
|
@ -3656,7 +3581,7 @@
|
||||||
let nodes = node.querySelectorAll("BR");
|
let nodes = node.querySelectorAll("BR");
|
||||||
const brBreaksLine = [];
|
const brBreaksLine = [];
|
||||||
let l = nodes.length;
|
let l = nodes.length;
|
||||||
for (let i = 0; i < l; i += 1) {
|
for (let i = 0; i < l; ++i) {
|
||||||
brBreaksLine[i] = isLineBreak(nodes[i], false);
|
brBreaksLine[i] = isLineBreak(nodes[i], false);
|
||||||
}
|
}
|
||||||
while (l--) {
|
while (l--) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue