Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
node = toElm.lastChild;
if (node && NodeType.isBr(node) && fromElm.hasChildNodes()) {
dom.remove(node);
}
if (NodeType.isEmpty(dom, toElm, true)) {
dom.$(toElm).empty();
}
moveChildren(dom, fromElm, toElm);
if (listNode) {
toElm.appendChild(listNode);
}
const contains = Compare.contains(SugarElement.fromDom(toElm), SugarElement.fromDom(fromElm));
const nestedLists = contains ? dom.getParents(fromElm, NodeType.isListNode, toElm) : [];
dom.remove(fromElm);
Arr.each(nestedLists, (list) => {
if (NodeType.isEmpty(dom, list) && list !== dom.getRoot()) {
dom.remove(list);
}
});
};
export const getNodeAnchor = (editor: Editor): NodeAnchorSpec => {
return {
anchor: 'node',
node: Option.some(Element.fromDom(editor.selection.getNode())),
root: Element.fromDom(editor.getBody())
};
};
const findBr = (forward: boolean, root: Element, pos: CaretPosition) => {
const parentBlocks = Arr.filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), ElementType.isBlock);
const scope = Arr.head(parentBlocks).getOr(root);
return CaretFinder.fromPosition(forward, scope.dom(), pos).filter(isBr);
};
const nativeRangeToSelectionRange = function (r) {
return Selection.range(Element.fromDom(r.startContainer), r.startOffset, Element.fromDom(r.endContainer), r.endOffset);
};
const getClosestBlock = (root: Element, pos: CaretPosition): Element => {
const parentBlocks = Arr.filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), ElementType.isBlock);
return Arr.head(parentBlocks).getOr(root);
};
lazyContext: () => Option.some(Boxes.box(Element.fromDom(editor.getContentAreaContainer()))),
fadeInClass: 'tox-dialog-dock-fadein',
getSelection: () => {
const rng = editor.selection.getRng();
return Option.some(
Selection.range(Element.fromDom(rng.startContainer), rng.startOffset, Element.fromDom(rng.endContainer), rng.endOffset)
);
}
};
const show = (editor: Editor, rootElm: Node) => {
const nodeList = Nodes.filterDescendants(SugarElement.fromDom(rootElm), Nodes.isMatch);
Arr.each(nodeList, (n) => {
const parent = n.dom().parentNode;
if (isWrappedNbsp(parent)) {
Class.add(SugarElement.fromDom(parent), Data.nbspClass);
} else {
const withSpans = Nodes.replaceWithSpans(editor.dom.encode(SugarNode.value(n)));
const div = editor.dom.create('div', null, withSpans);
let node: any;
while ((node = div.lastChild)) {
editor.dom.insertAfter(node, n.dom());
}
editor.dom.remove(n.dom());
}