Registry / testing / prosemirror-schema-table

prosemirror-schema-table

JSON →
library0.22.0jsnpmunverified

Provides table-related schema elements (nodes like table, table_row, table_cell, table_header) and editing commands (addRowBefore, addRowAfter, addColBefore, addColAfter, toggleHeaderRow, toggleHeaderColumn, toggleHeaderCell, deleteRow, deleteCol, mergeCells, splitCell, setCellAttr, goToNextCell) for the ProseMirror rich text editor. Current stable version is 0.22.0, released under a beta lifecycle with semver 0.x meaning API may change across minor versions. Key differentiator: tightly integrated with ProseMirror's schema and state management, unlike alternative table implementations. Supports row/column operations, cell merging, header toggling, and keyboard navigation. Requires prosemirror-model, prosemirror-transform, prosemirror-state, prosemirror-view, prosemirror-keymap, prosemirror-commands as peer dependencies.

npm install prosemirror-schema-table
INSTALL
IMPORT
SIG · PROSEMIRROR-SCHEMA
P
prosemirror-schema-table
testingjavascriptv0.22.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tableEditing
import { tableEditing } from 'prosemirror-schema-table'
const { tableEditing } = require('prosemirror-schema-table');
ESM-only; CommonJS require() works only with default import or named exports via .default; prefer ESM imports.
addRowAfter
import { addRowAfter } from 'prosemirror-schema-table'
import { addRowAfter } from 'prosemirror-tables';
Symbols are scoped to this package; prosemirror-tables is a different fork. Check package name.
tableSchema
import { tableSchema } from 'prosemirror-schema-table'
import { schema } from 'prosemirror-schema-table';
The schema object is named tableSchema, not schema. For custom nodes, use individual node specs: table, table_row, table_cell, table_header.

Sets up a ProseMirror editor with table schema and tableEditing plugin, then inserts a 2x2 table and adds a row after the first row.

import { schema } from 'prosemirror-model'; import { tableSchema, tableEditing, addRowAfter } from 'prosemirror-schema-table'; import { EditorState } from 'prosemirror-state'; import { EditorView } from 'prosemirror-view'; import { keymap } from 'prosemirror-keymap'; import { baseKeymap } from 'prosemirror-commands'; // Merge schemas (simplified: using tableSchema as base) const mySchema = new Schema({ nodes: schema.spec.nodes.append(tableSchema.spec.nodes), marks: schema.spec.marks }); const state = EditorState.create({ schema: mySchema, plugins: [ tableEditing(), keymap(baseKeymap) ] }); const view = new EditorView(document.body, { state }); // Insert a 2x2 table const tr = state.tr; const tableNode = mySchema.nodes.table.create(null, [ mySchema.nodes.table_row.create(null, [ mySchema.nodes.table_cell.create(null, mySchema.text('A')), mySchema.nodes.table_cell.create(null, mySchema.text('B')) ]), mySchema.nodes.table_row.create(null, [ mySchema.nodes.table_cell.create(null, mySchema.text('C')), mySchema.nodes.table_cell.create(null, mySchema.text('D')) ]) ]); tr.replaceSelectionWith(tableNode); view.dispatch(tr); // Add a row after the first row setTimeout(() => { view.focus(); addRowAfter(state, view.dispatch, view); }, 1000);
Debug
Known issues
breakingVersion 0.x API instability: minor version bumps may break code without deprecation.
fix
Pin exact version in package.json (e.g., "0.22.0") and test upgrades manually. Follow changelog at https://github.com/ProseMirror/prosemirror/blob/master/CHANGELOG.md
affects: 0.x
deprecated`fixTables()` function was removed in v0.22.0; use `tableEditing()` plugin instead.
fix
Replace `fixTables` with the `tableEditing` plugin: import { tableEditing } from 'prosemirror-schema-table';
affects: >=0.22.0
gotchaCell merging commands `mergeCells` and `splitCell` require a cell selection (not node selection). Using them without proper selection throws silently.
fix
Ensure the editor has a cell selection (use `goToNextCell` or mouse click inside a cell) before calling mergeCells/splitCell.
affects: >=0.1.0
gotchaThe `tableSchema` includes node specs but not marks; you must append marks from your own schema separately.
fix
Use `Schema({ nodes: schema.spec.nodes.append(tableSchema.spec.nodes), marks: schema.spec.marks })`
affects: >=0.1.0
gotchaIn Node.js environments (e.g., server-side rendering), `tableEditing()` may crash because it expects a DOM. Use `nodeView` or check `typeof document !== 'undefined'`.
fix
Wrap `tableEditing()` in a condition: `typeof document !== 'undefined' ? tableEditing() : []`
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'nodes')
tableSchema is not imported correctly or schema is not passed to EditorState.
fix
Ensure tableSchema is imported: import { tableSchema } from 'prosemirror-schema-table'; and use it when creating Schema.
Uncaught Error: Invalid schema: no 'table' node type found
table node spec not included in the schema due to missed import or incorrect schema composition.
fix
Include tableSchema nodes: `const mySchema = new Schema({ nodes: baseSchema.spec.nodes.append(tableSchema.spec.nodes), marks: baseSchema.spec.marks })`
addRowAfter is not a function
Import symbol name mismatch: common confusion with addRowBefore or typos.
fix
Use the exact named import: `import { addRowAfter } from 'prosemirror-schema-table';`
Upgrade
Version history
0.22.0latest on npm
Audit
Dependencies
prosemirror-modelrequiredPeer dependency: defines the table schema nodes (table, table_row, table_cell, table_header)
prosemirror-transformrequiredPeer dependency: used for document transformations (add/remove rows/columns, merge/split cells)
prosemirror-staterequiredPeer dependency: provides EditorState and Transaction classes
prosemirror-viewrequiredPeer dependency: needed for run-time cell selection and editing interactions
prosemirror-keymaprequiredPeer dependency: used for keyboard navigation commands (Tab, Shift-Tab)
prosemirror-commandsrequiredPeer dependency: provides base editing commands used by table commands
Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources
prosemirror-schema-table — npm install prosemirror-schema-table · libregistry