Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// There is already list node, setIndentation() will increase/decrease the list level,
// so we need to process the list when change indentation
newNode = processList(editor, command);
} else {
// No existing list node, browser will create <blockquote> node for indentation.
// We need to set top and bottom margin to 0 to avoid unnecessary spaces
editor.getDocument().execCommand(command, false, null);
editor.queryElements('BLOCKQUOTE', QueryScope.OnSelection, node => {
newNode = newNode || node;
node.style.marginTop = '0px';
node.style.marginBottom = '0px';
});
}
return newNode;
}, ChangeSource.Format);
}
</blockquote>
editor.focus();
editor.addUndoSnapshot(() => {
let vtable = new VTable(table);
vtable.applyFormat(
format || {
bgColorEven: '#FFF',
bgColorOdd: '#FFF',
topBorderColor: '#ABABAB',
bottomBorderColor: '#ABABAB',
verticalBorderColor: '#ABABAB',
}
);
vtable.writeBack();
editor.insertNode(fragment);
editor.runAsync(() => editor.select(new Position(table, PositionType.Begin).normalize()));
}, ChangeSource.Format);
}
if (alignment == Alignment.Center) {
command = DocumentCommand.JustifyCenter;
align = 'center';
} else if (alignment == Alignment.Right) {
command = DocumentCommand.JustifyRight;
align = 'right';
}
editor.addUndoSnapshot(() => {
execCommand(editor, command);
editor.queryElements(
'[align]',
QueryScope.OnSelection,
node => (node.style.textAlign = align)
);
}, ChangeSource.Format);
}
let lastNode: Node;
let contentTraverser = editor.getSelectionTraverser();
let inlineElement = contentTraverser && contentTraverser.currentInlineElement;
while (inlineElement) {
let nextInlineElement = contentTraverser.getNextInlineElement();
inlineElement.applyStyle((element, isInnerNode) => {
callback(element, isInnerNode);
firstNode = firstNode || element;
lastNode = element;
});
inlineElement = nextInlineElement;
}
if (firstNode && lastNode) {
editor.select(firstNode, PositionType.Before, lastNode, PositionType.After);
}
}, ChangeSource.Format);
}
}
export default function toggleNumbering(editor: Editor) {
editor.focus();
editor.addUndoSnapshot(
() => processList(editor, DocumentCommand.InsertOrderedList),
ChangeSource.Format
);
}
export default function formatTable(
editor: Editor,
format: Partial,
table?: HTMLTableElement
) {
table = table || (editor.getElementAtCursor('TABLE') as HTMLTableElement);
if (table) {
editor.addUndoSnapshot((start, end) => {
let vtable = new VTable(table);
vtable.applyFormat(format);
vtable.writeBack();
editor.focus();
editor.select(start, end);
}, ChangeSource.Format);
}
}
export default function removeLink(editor: Editor) {
editor.focus();
editor.addUndoSnapshot((start, end) => {
editor.queryElements('a[href]', QueryScope.OnSelection, unwrap);
editor.select(start, end);
}, ChangeSource.Format);
}
nodes.some(node => UNWRAPPABLE_NODES.indexOf(getTagOfNode(node)) >= 0)
) {
nodes = [splitBalancedNodeRange(nodes)];
}
}
result = wrapFunction(nodes);
(styler || DEFAULT_STYLER)(result);
}
if (!editor.select(start, end) && result) {
editor.select(result);
}
return result;
}, ChangeSource.Format);
}
reader.onload = (event: ProgressEvent) => {
if (!editor.isDisposed()) {
editor.addUndoSnapshot(() => {
let image = editor.getDocument().createElement('img');
image.src = (event.target as FileReader).result as string;
image.style.maxWidth = '100%';
editor.insertNode(image);
}, ChangeSource.Format);
}
};
reader.readAsDataURL(imageFile);
private _fileInputOnChange = (): void => {
const { roosterCommandBarPlugin, imageManager } = this.props;
const editor: Editor = roosterCommandBarPlugin.getEditor();
const file = this._fileInput.files[0];
if (editor && !editor.isDisposed() && file) {
if (imageManager) {
const placeholder = imageManager.upload(editor, file);
editor.insertNode(placeholder);
editor.triggerContentChangedEvent(ChangeSource.Format);
editor.addUndoSnapshot();
} else {
insertImage(editor, file);
}
this._fileInput.value = "";
}
};