add basic schema extender

This commit is contained in:
Philipp Kühn
2021-02-19 09:54:39 +01:00
parent 85eceb32b8
commit 6f9557294e
7 changed files with 88 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ import {
mergeAttributes,
isCellSelection,
findParentNodeClosestToPos,
callOrReturn,
} from '@tiptap/core'
import {
tableEditing,
@@ -64,6 +65,13 @@ declare module '@tiptap/core' {
fixTables: () => Command,
}
}
interface NodeConfig<Options> {
/**
* Table Role
*/
tableRole?: string | ((this: { options: Options }) => string),
}
}
export const Table = Node.create<TableOptions>({
@@ -81,6 +89,14 @@ export const Table = Node.create<TableOptions>({
allowTableNodeSelection: false,
},
extendNodeSchema(extension) {
const context = { options: extension.options }
return {
tableRole: callOrReturn(extension.config.tableRole, context),
}
},
content: 'tableRow+',
tableRole: 'table',