Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
optimize() {
super.optimize();
// Add parent TR and TABLE when missing
let parent = this.parent;
if (parent != null && parent.statics.blotName != 'tr') {
// we will mark td position, put in table and replace mark
let mark = Parchment.create('block');
this.parent.insertBefore(mark, this.next);
let table = Parchment.create('table', this.domNode.getAttribute('table_id'));
let tr = Parchment.create('tr', this.domNode.getAttribute('row_id'));
table.appendChild(tr);
tr.appendChild(this);
table.replace(mark)
}
// merge same TD id
let next = this.next;
if (next != null && next.prev === this &&
next.statics.blotName === this.statics.blotName &&
next.domNode.tagName === this.domNode.tagName &&
next.domNode.getAttribute('cell_id') === this.domNode.getAttribute('cell_id')) {
next.moveChildren(this);
next.remove();
}
}
it('insert into empty', function() {
let block = Parchment.create('block');
block.insertAt(0, 'Test');
expect(block.domNode).toEqualHTML('Test');
});
public split(index: number, force?: boolean) {
if (!force && (index === this.length() - 1 || index === 0)) {
return this;
}
const ownItem = this.getListContent();
const ownGroup = this.getListGroup();
if (ownItem && index < ownItem.length()) {
const after = ownItem.split(index, force) as ListItem;
if (after instanceof ListItem) {
const wrapper = Parchment.create(ListItemWrapper.blotName, this.getValue()) as ListItemWrapper;
after.insertInto(wrapper);
wrapper.insertInto(this.parent, this.next);
if (ownGroup) {
ownGroup.insertInto(wrapper);
}
return wrapper;
}
return this;
} else {
return super.split(index, force);
}
}
restore(node) {
let range, textNode;
let text = node.data.split(GUARD_TEXT).join('');
if (node === this.leftGuard) {
if (this.prev instanceof TextBlot) {
let prevLength = this.prev.length();
this.prev.insertAt(prevLength, text);
range = {
startNode: this.prev.domNode,
startOffset: prevLength + text.length
};
} else {
textNode = document.createTextNode(text);
this.parent.insertBefore(Parchment.create(textNode), this);
range = {
startNode: textNode,
startOffset: text.length
};
}
} else if (node === this.rightGuard) {
if (this.next instanceof TextBlot) {
this.next.insertAt(0, text);
range = {
startNode: this.next.domNode,
startOffset: text.length
}
} else {
textNode = document.createTextNode(text);
this.parent.insertBefore(Parchment.create(textNode), this.next);
range = {
constructor(container, options = {}) {
this.options = expandConfig(container, options);
this.container = this.options.container;
if (this.container == null) {
return debug.error('Invalid Quill container', container);
}
if (this.options.debug) {
Quill.debug(this.options.debug);
}
let html = this.container.innerHTML.trim();
this.container.classList.add('ql-container');
this.container.innerHTML = '';
this.root = this.addContainer('ql-editor');
this.root.classList.add('ql-blank');
this.emitter = new Emitter();
this.scroll = Parchment.create(this.root, {
emitter: this.emitter,
whitelist: this.options.formats
});
this.editor = new Editor(this.scroll);
this.selection = new Selection(this.scroll, this.emitter);
this.theme = new this.options.theme(this, this.options);
this.keyboard = this.theme.addModule('keyboard');
this.clipboard = this.theme.addModule('clipboard');
this.history = this.theme.addModule('history');
this.theme.init();
this.emitter.on(Emitter.events.EDITOR_CHANGE, (type) => {
if (type === Emitter.events.TEXT_CHANGE) {
this.root.classList.toggle('ql-blank', this.editor.isBlank());
}
});
this.emitter.on(Emitter.events.SCROLL_UPDATE, (source, mutations) => {
protected createWrapper() {
const value = this.getValue();
return Parchment.create(ListItemWrapper.blotName, value) as WrapperBlot;
}
private ensureListContent() {
if (!this.getListContent()) {
const listContent = (Parchment.create(ListItem.blotName, this.getValue()) as any) as ListItem;
this.children.forEach(child => {
if (!(child instanceof ListGroup)) {
child.insertInto(listContent);
}
});
this.insertBefore(listContent, this.children.head);
}
}
format(name, value) {
if (name === List.blotName && !value) {
this.replaceWith(Parchment.create(this.statics.scope));
} else {
super.format(name, value);
}
}
appendRow() {
let td = this.findTd('td');
if(td) {
let colCount = td.parent.children.length;
let table = td.parent.parent;
let newRow = td.parent.clone();
let tableId = table.domNode.getAttribute('table_id');
let rowId = this.randomId();
newRow.domNode.setAttribute('row_id', rowId);
for (var i = colCount - 1; i >= 0; i--) {
let cellId = this.randomId();
let td = Parchment.create('td', tableId + '|' + rowId + '|' + cellId);
newRow.appendChild(td);
}
table.appendChild(newRow);
}
}