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

@ -30,6 +30,7 @@
"@types/prosemirror-model": "^1.11.2",
"@types/prosemirror-schema-list": "^1.0.2",
"@types/prosemirror-state": "^1.2.6",
"@types/prosemirror-tables": "^0.9.1",
"@types/prosemirror-transform": "^1.1.2",
"@types/prosemirror-view": "^1.17.1",
"prosemirror-commands": "^1.1.3",

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,

View File

@ -2486,6 +2486,13 @@
"@types/prosemirror-transform" "*"
"@types/prosemirror-view" "*"
"@types/prosemirror-tables@^0.9.1":
version "0.9.1"
resolved "https://registry.yarnpkg.com/@types/prosemirror-tables/-/prosemirror-tables-0.9.1.tgz#d2203330f0fa1161c04152bf02c39e152082d408"
integrity sha512-zoY1qcAC6kG4UjnaQQXuoyYQdDJMQmY9uzRKdyUppP8rWRR5/kXBHOd84CD9ZvrYUBo3uDmS20qQnc3knr2j9A==
dependencies:
prosemirror-tables "*"
"@types/prosemirror-transform@*":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/prosemirror-transform/-/prosemirror-transform-1.1.1.tgz#5a0de16e8e0123b4c3d9559235e19f39cee85e5c"
@ -11842,7 +11849,7 @@ prosemirror-state@^1.3.4:
prosemirror-model "^1.0.0"
prosemirror-transform "^1.0.0"
prosemirror-tables@^1.1.1:
prosemirror-tables@*, prosemirror-tables@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/prosemirror-tables/-/prosemirror-tables-1.1.1.tgz#ad66300cc49500455cf1243bb129c9e7d883321e"
integrity sha512-LmCz4jrlqQZRsYRDzCRYf/pQ5CUcSOyqZlAj5kv67ZWBH1SVLP2U9WJEvQfimWgeRlIz0y0PQVqO1arRm1+woA==