Merge branch 'feature/tables' of github.com:ueberdosis/tiptap-next into feature/tables
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
"@tiptap/core": "^2.0.0-alpha.6"
|
"@tiptap/core": "^2.0.0-alpha.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"prosemirror-tables": "^1.1.1"
|
"prosemirror-tables": "^1.1.1",
|
||||||
|
"prosemirror-view": "^1.16.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
import { NodeView } from 'prosemirror-view'
|
||||||
|
|
||||||
export function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
|
export function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
|
||||||
let totalWidth = 0
|
let totalWidth = 0
|
||||||
let fixedWidth = true
|
let fixedWidth = true
|
||||||
@@ -44,7 +46,7 @@ export function updateColumns(node, colgroup, table, cellMinWidth, overrideCol,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TableView {
|
export class TableView implements NodeView {
|
||||||
constructor(node, cellMinWidth) {
|
constructor(node, cellMinWidth) {
|
||||||
this.node = node
|
this.node = node
|
||||||
this.cellMinWidth = cellMinWidth
|
this.cellMinWidth = cellMinWidth
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
setCellAttr,
|
setCellAttr,
|
||||||
fixTables,
|
fixTables,
|
||||||
} from 'prosemirror-tables'
|
} from 'prosemirror-tables'
|
||||||
|
import { NodeView } from 'prosemirror-view'
|
||||||
import { TextSelection } from 'prosemirror-state'
|
import { TextSelection } from 'prosemirror-state'
|
||||||
import { createTable } from './utilities/createTable'
|
import { createTable } from './utilities/createTable'
|
||||||
import { TableView } from './TableView'
|
import { TableView } from './TableView'
|
||||||
@@ -30,7 +31,7 @@ export interface TableOptions {
|
|||||||
resizable: boolean,
|
resizable: boolean,
|
||||||
handleWidth: number,
|
handleWidth: number,
|
||||||
cellMinWidth: number,
|
cellMinWidth: number,
|
||||||
View: TableView,
|
View: NodeView,
|
||||||
lastColumnResizable: boolean,
|
lastColumnResizable: boolean,
|
||||||
allowTableNodeSelection: boolean,
|
allowTableNodeSelection: boolean,
|
||||||
}
|
}
|
||||||
@@ -66,16 +67,17 @@ export const Table = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
insertTable: ({ rows, cols, withHeaderRow }): Command => ({ state, dispatch }) => {
|
insertTable: ({ rows = 3, cols = 3, withHeaderRow = true }): Command => ({ state, dispatch }) => {
|
||||||
const offset = state.tr.selection.anchor + 1
|
const offset = state.tr.selection.anchor + 1
|
||||||
|
|
||||||
const nodes = createTable(this.editor.schema, rows, cols, withHeaderRow)
|
const nodes = createTable(this.editor.schema, rows, cols, withHeaderRow)
|
||||||
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView()
|
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView()
|
||||||
const resolvedPos = tr.doc.resolve(offset)
|
const resolvedPos = tr.doc.resolve(offset)
|
||||||
|
|
||||||
tr.setSelection(TextSelection.near(resolvedPos))
|
if (dispatch) {
|
||||||
|
tr.setSelection(TextSelection.near(resolvedPos))
|
||||||
|
}
|
||||||
|
|
||||||
return dispatch(tr)
|
return true
|
||||||
},
|
},
|
||||||
addColumnBefore: (): Command => ({ state, dispatch }) => {
|
addColumnBefore: (): Command => ({ state, dispatch }) => {
|
||||||
return addColumnBefore(state, dispatch)
|
return addColumnBefore(state, dispatch)
|
||||||
@@ -148,11 +150,15 @@ export const Table = Node.create({
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.editor.commands.addRowAfter()) {
|
if (!this.editor.can().addRowAfter()) {
|
||||||
return this.editor.commands.goToNextCell()
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return this.editor
|
||||||
|
.chain()
|
||||||
|
.addRowAfter()
|
||||||
|
.goToNextCell()
|
||||||
|
.run()
|
||||||
},
|
},
|
||||||
'Shift-Tab': () => this.editor.commands.goToPreviousCell(),
|
'Shift-Tab': () => this.editor.commands.goToPreviousCell(),
|
||||||
}
|
}
|
||||||
@@ -164,9 +170,11 @@ export const Table = Node.create({
|
|||||||
handleWidth: this.options.handleWidth,
|
handleWidth: this.options.handleWidth,
|
||||||
cellMinWidth: this.options.cellMinWidth,
|
cellMinWidth: this.options.cellMinWidth,
|
||||||
View: this.options.View,
|
View: this.options.View,
|
||||||
lastColumnResizable: this.options.lastColumnResizable,
|
// lastColumnResizable: this.options.lastColumnResizable,
|
||||||
})] : []),
|
})] : []),
|
||||||
tableEditing(this.options.allowTableNodeSelection),
|
tableEditing({
|
||||||
|
allowTableNodeSelection: this.options.allowTableNodeSelection,
|
||||||
|
}),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { createCell } from './createCell'
|
|||||||
|
|
||||||
import { getTableNodeTypes } from './getTableNodeTypes'
|
import { getTableNodeTypes } from './getTableNodeTypes'
|
||||||
|
|
||||||
export function createTable(schema: Schema, rowsCount: 3, colsCount: 3, withHeaderRow: true, cellContent?: Fragment<Schema> | ProsemirrorNode<Schema> | Array<ProsemirrorNode<Schema>>) {
|
export function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment<Schema> | ProsemirrorNode<Schema> | Array<ProsemirrorNode<Schema>>) {
|
||||||
const types = getTableNodeTypes(schema)
|
const types = getTableNodeTypes(schema)
|
||||||
|
|
||||||
const headerCells = []
|
const headerCells = []
|
||||||
|
|||||||
Reference in New Issue
Block a user