improve types

This commit is contained in:
Philipp Kühn
2021-01-23 20:59:19 +01:00
parent 4fd884d38d
commit 3f30b69f37
4 changed files with 33 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
// @ts-nocheck
import { NodeView } from 'prosemirror-view'
import { Node as ProseMirrorNode } from 'prosemirror-model'
export function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
export function updateColumns(node: ProseMirrorNode, colgroup: Element, table: Element, cellMinWidth: number, overrideCol?: number, overrideValue?: any) {
let totalWidth = 0
let fixedWidth = true
let nextDOM = colgroup.firstChild
@@ -47,7 +48,20 @@ export function updateColumns(node, colgroup, table, cellMinWidth, overrideCol,
}
export class TableView implements NodeView {
constructor(node, cellMinWidth) {
node: ProseMirrorNode
cellMinWidth: number
dom: Element
table: Element
colgroup: Element
contentDOM: Element
constructor(node: ProseMirrorNode, cellMinWidth: number) {
this.node = node
this.cellMinWidth = cellMinWidth
this.dom = document.createElement('div')
@@ -58,7 +72,7 @@ export class TableView implements NodeView {
this.contentDOM = this.table.appendChild(document.createElement('tbody'))
}
update(node) {
update(node: ProseMirrorNode) {
if (node.type !== this.node.type) {
return false
}
@@ -69,7 +83,7 @@ export class TableView implements NodeView {
return true
}
ignoreMutation(record) {
return record.type === 'attributes' && (record.target === this.table || this.colgroup.contains(record.target))
ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {
return mutation.type === 'attributes' && (mutation.target === this.table || this.colgroup.contains(mutation.target))
}
}

View File

@@ -1,4 +1,3 @@
// @ts-nocheck
import { Command, Node, mergeAttributes } from '@tiptap/core'
import {
tableEditing,
@@ -122,7 +121,7 @@ export const Table = Node.create({
return splitCell(state, dispatch)
},
setCellAttributes: ({ name, value }): Command => ({ state, dispatch }) => {
setCellAttributes: ({ name, value }: { name: string, value: any }): Command => ({ state, dispatch }) => {
return setCellAttr(name, value)(state, dispatch)
},
goToNextCell: (): Command => ({ state, dispatch }) => {
@@ -135,7 +134,7 @@ export const Table = Node.create({
const transaction = fixTables(state)
if (transaction) {
return dispatch(transaction)
return dispatch?.(transaction)
}
return false
@@ -170,7 +169,9 @@ export const Table = Node.create({
handleWidth: this.options.handleWidth,
cellMinWidth: this.options.cellMinWidth,
View: this.options.View,
// lastColumnResizable: this.options.lastColumnResizable,
// TODO: PR for @types/prosemirror-tables
// @ts-ignore (incorrect type)
lastColumnResizable: this.options.lastColumnResizable,
})] : []),
tableEditing({
allowTableNodeSelection: this.options.allowTableNodeSelection,