(editor: T, options: TableOptions = {})
| 10 | import { withShortcuts } from './with-shortcuts' |
| 11 | |
| 12 | export const withTable = <T extends Editable>(editor: T, options: TableOptions = {}) => { |
| 13 | let newEditor = editor as T & TableEditor |
| 14 | |
| 15 | setOptions(newEditor, options) |
| 16 | |
| 17 | const { locale: localeOptions = {} } = options |
| 18 | Locale.setLocale(newEditor, locale, localeOptions) |
| 19 | |
| 20 | newEditor = withTableCell(newEditor) |
| 21 | newEditor = withTableRow(newEditor) |
| 22 | |
| 23 | const { isGrid } = editor |
| 24 | |
| 25 | newEditor.isGrid = (node: Node): node is Table => { |
| 26 | return TableEditor.isTable(newEditor, node) || isGrid(node) |
| 27 | } |
| 28 | |
| 29 | newEditor.insertTable = options => { |
| 30 | const table = Table.isTable(options) ? options : TableEditor.create(newEditor, options) |
| 31 | Transforms.insertNodes(newEditor, table) |
| 32 | Grid.focus(newEditor, { |
| 33 | point: [0, 0], |
| 34 | }) |
| 35 | } |
| 36 | |
| 37 | const { renderElement } = newEditor |
| 38 | |
| 39 | newEditor.renderElement = props => { |
| 40 | if (TableEditor.isTable(newEditor, props.element)) { |
| 41 | return <TableComponent editor={newEditor} {...(props as RenderElementProps<Table>)} /> |
| 42 | } |
| 43 | return renderElement(props) |
| 44 | } |
| 45 | |
| 46 | const { shortcuts } = options |
| 47 | if (shortcuts !== false) { |
| 48 | withShortcuts(newEditor) |
| 49 | } |
| 50 | return newEditor |
| 51 | } |
no test coverage detected
searching dependent graphs…