Skip to content

Commit

Permalink
fix: update typings for node view decorations (ueberdosis#3783)
Browse files Browse the repository at this point in the history
* fix: update typings for node view decorations

* fix(core): update types for NodeView

* fix(core): declare props.decorations as decorationWithType
  • Loading branch information
bdbch authored and aliasliao committed May 24, 2023
1 parent 99a73ef commit 388df45
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/NodeView.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
import { NodeSelection } from '@tiptap/pm/state'
import { Decoration, NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'
import { NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'

import { Editor as CoreEditor } from './Editor'
import { Node } from './Node'
import { NodeViewRendererOptions, NodeViewRendererProps } from './types'
import { DecorationWithType, NodeViewRendererOptions, NodeViewRendererProps } from './types'
import { isiOS } from './utilities/isiOS'

export class NodeView<
Expand All @@ -22,7 +22,7 @@ export class NodeView<

node: ProseMirrorNode

decorations: Decoration[]
decorations: DecorationWithType[]

getPos: any

Expand All @@ -38,7 +38,7 @@ export class NodeView<
} as Options
this.extension = props.extension
this.node = props.node
this.decorations = props.decorations
this.decorations = props.decorations as DecorationWithType[]
this.getPos = props.getPos
this.mount()
}
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Mark as ProseMirrorMark, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'
import {
Mark as ProseMirrorMark, Node as ProseMirrorNode, NodeType, ParseOptions,
} from '@tiptap/pm/model'
import { EditorState, Transaction } from '@tiptap/pm/state'
import {
Decoration, EditorProps, EditorView, NodeView,
Expand Down Expand Up @@ -148,10 +150,14 @@ export type ValuesOf<T> = T[keyof T]

export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T]

export type DecorationWithType = Decoration & {
type: NodeType
}

export type NodeViewProps = {
editor: Editor
node: ProseMirrorNode
decorations: Decoration[]
decorations: DecorationWithType[]
selected: boolean
extension: Node
getPos: () => number
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/ReactNodeViewRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DecorationWithType,
NodeView,
NodeViewProps,
NodeViewRenderer,
Expand Down Expand Up @@ -124,7 +125,7 @@ class ReactNodeView extends NodeView<
return this.contentDOMElement
}

update(node: ProseMirrorNode, decorations: Decoration[]) {
update(node: ProseMirrorNode, decorations: DecorationWithType[]) {
const updateProps = (props?: Record<string, any>) => {
this.renderer.updateProps(props)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-2/src/VueNodeViewRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DecorationWithType,
NodeView,
NodeViewProps,
NodeViewRenderer,
Expand Down Expand Up @@ -122,7 +123,7 @@ class VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRend
return (contentElement || this.dom) as HTMLElement | null
}

update(node: ProseMirrorNode, decorations: Decoration[]) {
update(node: ProseMirrorNode, decorations: DecorationWithType[]) {
const updateProps = (props?: Record<string, any>) => {
this.decorationClasses.value = this.getDecorationClasses()
this.renderer.updateProps(props)
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-3/src/VueNodeViewRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DecorationWithType,
NodeView,
NodeViewProps,
NodeViewRenderer,
Expand Down Expand Up @@ -133,7 +134,7 @@ class VueNodeView extends NodeView<Component, Editor, VueNodeViewRendererOptions
return (contentElement || this.dom) as HTMLElement | null
}

update(node: ProseMirrorNode, decorations: Decoration[]) {
update(node: ProseMirrorNode, decorations: DecorationWithType[]) {
const updateProps = (props?: Record<string, any>) => {
this.decorationClasses.value = this.getDecorationClasses()
this.renderer.updateProps(props)
Expand Down

0 comments on commit 388df45

Please sign in to comment.