slate-edit-table
Version:
A Slate plugin to handle keyboard events in tables.
28 lines (21 loc) • 600 B
Flow
// @flow
import { type Change, type Node } from 'slate';
import { createTable } from '../utils';
import type Options from '../options';
/**
* Insert a new table
*/
function insertTable(
opts: Options,
change: Change,
columns?: number = 2,
rows?: number = 2,
getCellContent?: (column: number, row: number) => Node[]
): Change {
const { value } = change;
if (!value.selection.startKey) return change;
// Create the table node
const table = createTable(opts, columns, rows, getCellContent);
return change.insertBlock(table);
}
export default insertTable;