A Slate plugin to handle table edition.
Demo: gitbookio.github.io/slate-edit-table/
npm install slate-edit-table
- Pressing Up and Down, move the cursor to next/previous row
- Pressing Enter, insert a new row
- Pressing Cmd+Enter (Ctrl+Enter on Windows/Linux) exits the table, into a new default block.
- Pressing Tab, move the select to next cell
- Pressing Shift+Tab, move the select to previous cell
import EditTable from 'slate-edit-table'
const plugins = [
EditTable()
]
[typeTable: String]
— type for table[typeRow: String]
— type for the rows.[typeCell: String]
— type for the cells.[exitBlockType: String]
— Mod+Enter will exit the table, into the given block type. Passnull
to disable this behavior.
slate-edit-table
exports utilities and changes:
plugin.utils.isSelectionInTable(value: Slate.Value) => boolean
Return true if selection is inside a table cell.
plugin.utils.getPosition(value: Slate.Value) => TablePosition
Returns the detailed position in the current table. Throws if not in a table.
plugin.changes.insertTable(change: Change, columns: ?number, rows: ?number) => Change
Insert a new empty table.
plugin.changes.insertRow(change: Change, at: ?number) => Change
Insert a new row after the current one or at the specific index (at
).
plugin.changes.insertColumn(change: Change, at: ?number) => Change
Insert a new column after the current one or at the specific index (at
).
plugin.changes.removeTable(change: Change) => Change
Remove current table.
plugin.changes.removeRow(change: Change, at: Number?) => Change
Remove current row or the one at a specific index (at
).
plugin.changes.removeColumn(change: Change, at: ?number) => Change
Remove current column or the one at a specific index (at
).
plugin.changes.moveSelection(change: Change, column: number, row: number) => Change
Move the selection to a specific position in the table.
plugin.changes.moveSelectionBy(change: Change, column: number, row: number) => Change
Move the selection by the given amount of columns and rows.
plugin.changes.setColumnAlign(change: Change, align: string, at: number) => Change
Sets column alignment for a given column (at
), in the current table. align
defaults to center, at
is optional and defaults to current cursor position.
The
align
values are stored in the table node's data.table.node.data.get('align')
should be an array of aligns string, corresponding to each column.
An instance of TablePosition
represents a position within a table (row and column).
You can get your current position in a table by using plugin.utils.getPosition(value)
.
Returns the number of columns in the current table.
Returns the number of rows in the current table.
Returns the index of the current row in the table.
Return the index of the current column in the table.
True if on first row and first column of the table
True if on last row and last column of the table
True if on first row
True if on last row
True if on first column
True if on last column