Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return detect(Element.fromDom(editor.selection.getNode())).getOrThunk(() => {
// Create a wrapper
const wrapper = Element.fromHtml('<span data-mce-bogus="1" data-mce-autocompleter="1"></span>', editor.getDoc());
// Wrap the content
Insert.append(wrapper, Element.fromDom(range.extractContents()));
range.insertNode(wrapper.dom());
Traverse.parent(wrapper).each((elm) => elm.dom().normalize());
// Update the cursor position
CursorPosition.last(wrapper).map((last) => {
editor.selection.setCursorLocation(last.dom(), Awareness.getEnd(last));
});
return wrapper;
});
};
editor.undoManager.transact(() => {
const element = SugarElement.fromTag(forcedRootBlock);
Attr.setAll(element, Settings.getForcedRootBlockAttrs(editor));
Insert.append(element, SugarElement.fromTag('br'));
if (down) {
Insert.after(SugarElement.fromDom(table), element);
} else {
Insert.before(SugarElement.fromDom(table), element);
}
const rng = editor.dom.createRng();
rng.setStart(element.dom(), 0);
rng.setEnd(element.dom(), 0);
moveToRange(editor, rng);
});
} else {
const appendItem = (segment: Segment, item: Element): void => {
Insert.append(segment.list, item);
segment.item = item;
};
const insertElement = (root: Element, elm: Element, forward: boolean) => {
if (forward) {
Insert.append(root, elm);
} else {
Insert.prepend(root, elm);
}
};
const joinSegment = (parent: Segment, child: Segment): void => {
Insert.append(parent.item, child.list);
};
const createSegment = (scope: Document, listType: ListType): Segment => {
const segment: Segment = {
list: Element.fromTag(listType, scope),
item: Element.fromTag('li', scope)
};
Insert.append(segment.list, segment.item);
return segment;
};
const insertBlock = (root: Element, forward: boolean, blockName: string, attrs: Record) => {
const block = Element.fromTag(blockName);
const br = Element.fromTag('br');
Attr.setAll(block, attrs);
Insert.append(block, br);
insertElement(root, block, forward);
return rangeBefore(br);
};