MCPcopy Create free account
hub / github.com/editablejs/editable / withTable

Function withTable

packages/plugins/table/src/table/plugin/with-table.tsx:12–51  ·  view source on GitHub ↗
(editor: T, options: TableOptions = {})

Source from the content-addressed store, hash-verified

10import { withShortcuts } from './with-shortcuts'
11
12export 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}

Callers 1

withPluginsFunction · 0.85

Calls 6

setOptionsFunction · 0.90
withTableCellFunction · 0.90
withTableRowFunction · 0.90
withShortcutsFunction · 0.90
isGridFunction · 0.85
focusMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…