A Slate plugin to handle a simple table.
Demo: gitbookio.github.io/slate-edit-table/
npm install slate-simple-table
- Pressing Up and Down, move the cursor to next/previous row
- Pressing Tab, move the select to next cell
- Pressing Shift+Tab, move the select to previous cell
- Pressing Enter, move the select to the cell below
- Pressing Shift+Enter, move the select to the cell above
import SimpleTable from 'slate-simple-table'
const plugins = [
SimpleTable()
]
[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-simple-table
exports utilities and changes:
plugin.utils.isSelectionInTable(state: State) => Boolean
Return true if selection is inside a table cell.
plugin.utils.isSelectionOutOfTable(value: Slate.Value) => boolean
Return true if selection starts and ends both outside any table. (Notice: it is NOT the opposite value of isSelectionInTable
)
plugin.changes.insertTable(change: Change, columns: Number?, rows: Number?, cellGetter: Function?, widths: List?) => 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.
plugin.changes.setColumnWidth(change: Change, width: Number, at: Number) => Change
Sets column width for a given column (at
), in the current table. width
has a
configurable minimum of 5. at
is optional and defaults to current cursor position.
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
Bug reports and pull requests are welcome on GitHub at https://github.com/cdd/slate-simple-table
- Verify that all desired changes have been merged & pushed to master.
- Verify that the changelog is up to date (it should be kept up to date as changes are made, so this should just be a quick check).
- Verify that the current master has passed on Travis.
- Run
yarn publish
. You will be prompted for the version. Remove the .pre from the version and continue. This packages the plugin and submits it to npmjs.com. - Run
yarn version
and update to the next patch-level release, plus .pre. E.g. if you just released 0.6.10, update the version in version.rb to "0.6.11.pre". - Add a heading for the new version number to CHANGELOG.md. E.g., if you just released 0.6.10, add "# 0.6.11" to the top of the changelog.
- Save and commit the changes from steps 5 and 6.