Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const extractSelected = function (cells) {
// Assume for now that we only have one table (also handles the case where we multi select outside a table)
return TableLookup.table(cells[0]).map(Replication.deep).map(function (replica) {
return [ CopySelected.extract(replica, Ephemera.attributeSelector()) ];
});
};
return TableSelection.getSelectionStartCellOrCaption(editor).bind((cellOrCaption) => {
const table = TableLookup.table(cellOrCaption);
return table.map((table) => {
if (Node.name(cellOrCaption) === 'caption') {
return TableTargets.notCell(cellOrCaption);
} else {
return TableTargets.forMenu(selections, table, cellOrCaption);
}
});
});
};
cellOpt.each(function (domCell) {
const cell = Element.fromDom(domCell);
TableLookup.table(cell).each((table) => {
const elements = Arr.filter(Elements.fromHtml(e.content), function (content) {
return Node.name(content) !== 'meta';
});
if (elements.length === 1 && Node.name(elements[0]) === 'table') {
e.preventDefault();
const doc = Element.fromDom(editor.getDoc());
const generators = TableFill.paste(doc);
const targets = TableTargets.paste(cell, elements[0], generators);
actions.pasteCells(table, targets).each(function (rng) {
editor.selection.setRng(rng);
editor.focus();
cellSelection.clear(table);
});
}, function (current) {
return TableLookup.table(current, isRoot).bind(function (table) {
const targets = TableTargets.noMenu(current);
editor.undoManager.transact(function () {
actions.insertRowsAfter(table, targets);
});
return getNewRowCursorPosition(editor, table);
});
});
};
const forward = function (editor: Editor, isRoot, cell, lazyWire) {
return go(editor, isRoot, CellNavigation.next(cell), lazyWire);
};
const backward = function (editor: Editor, isRoot, cell, lazyWire) {
return go(editor, isRoot, CellNavigation.prev(cell), lazyWire);
};
return TableLookup.table(cells[0]).map(Replication.deep).map(function (replica) {
return [ CopySelected.extract(replica, Ephemera.attributeSelector()) ];
});
};
const lazyWire = function () {
return wire.getOr(ResizeWire.only(SugarElement.fromDom(editor.getBody())));
};
editor.on('init', function () {
const direction = TableDirection(Direction.directionAt);
const rawWire = TableWire.get(editor);
wire = Option.some(rawWire);
if (hasObjectResizing(editor) && hasTableResizeBars(editor)) {
const sz = TableResize.create(rawWire, direction);
sz.on();
sz.events.startDrag.bind(function (event) {
selectionRng = Option.some(editor.selection.getRng());
});
sz.events.beforeResize.bind(function (event) {
const rawTable = event.table().dom();
Events.fireObjectResizeStart(editor, rawTable, Util.getPixelWidth(rawTable), Util.getPixelHeight(rawTable));
});
sz.events.afterResize.bind(function (event) {
const table = event.table();
TableLookup.table(cell).each((table) => {
const elements = Arr.filter(Elements.fromHtml(e.content), function (content) {
return Node.name(content) !== 'meta';
});
if (elements.length === 1 && Node.name(elements[0]) === 'table') {
e.preventDefault();
const doc = Element.fromDom(editor.getDoc());
const generators = TableFill.paste(doc);
const targets = TableTargets.paste(cell, elements[0], generators);
actions.pasteCells(table, targets).each(function (rng) {
editor.selection.setRng(rng);
editor.focus();
cellSelection.clear(table);
});
}
});
});