mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-11 20:08:59 +08:00
docs: update DecorationWithType
typings for accuracy (#5692)
This commit is contained in:
parent
7a7376c5f7
commit
e606c06502
5
.changeset/slow-peaches-film.md
Normal file
5
.changeset/slow-peaches-film.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@tiptap/core": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Updates the typings of `DecorationsWithTypes` to be more accurate to the prosemirror implementation even though it is not completely exposed as an API
|
@ -1,13 +1,14 @@
|
|||||||
import {
|
import {
|
||||||
Mark as ProseMirrorMark,
|
Mark as ProseMirrorMark,
|
||||||
Node as ProseMirrorNode,
|
Node as ProseMirrorNode,
|
||||||
NodeType,
|
|
||||||
ParseOptions,
|
ParseOptions,
|
||||||
Slice,
|
Slice,
|
||||||
} from '@tiptap/pm/model'
|
} from '@tiptap/pm/model'
|
||||||
import { EditorState, Transaction } from '@tiptap/pm/state'
|
import { EditorState, Transaction } from '@tiptap/pm/state'
|
||||||
|
import { Mappable } from '@tiptap/pm/transform'
|
||||||
import {
|
import {
|
||||||
Decoration,
|
Decoration,
|
||||||
|
DecorationAttrs,
|
||||||
EditorProps,
|
EditorProps,
|
||||||
EditorView,
|
EditorView,
|
||||||
NodeView,
|
NodeView,
|
||||||
@ -224,8 +225,27 @@ 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 KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T];
|
||||||
|
|
||||||
|
export type DOMNode = InstanceType<typeof window.Node>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prosemirror-view does not export the `type` property of `Decoration`.
|
||||||
|
* So, this defines the `DecorationType` interface to include the `type` property.
|
||||||
|
*/
|
||||||
|
export interface DecorationType {
|
||||||
|
spec: any
|
||||||
|
map(mapping: Mappable, span: Decoration, offset: number, oldOffset: number): Decoration | null
|
||||||
|
valid(node: Node, span: Decoration): boolean
|
||||||
|
eq(other: DecorationType): boolean
|
||||||
|
destroy(dom: DOMNode): void
|
||||||
|
readonly attrs: DecorationAttrs
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prosemirror-view does not export the `type` property of `Decoration`.
|
||||||
|
* This adds the `type` property to the `Decoration` type.
|
||||||
|
*/
|
||||||
export type DecorationWithType = Decoration & {
|
export type DecorationWithType = Decoration & {
|
||||||
type: NodeType;
|
type: DecorationType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface NodeViewProps extends NodeViewRendererProps {
|
export interface NodeViewProps extends NodeViewRendererProps {
|
||||||
@ -246,14 +266,40 @@ export interface NodeViewRendererOptions {
|
|||||||
|
|
||||||
export interface NodeViewRendererProps {
|
export interface NodeViewRendererProps {
|
||||||
// pass-through from prosemirror
|
// pass-through from prosemirror
|
||||||
|
/**
|
||||||
|
* The node that is being rendered.
|
||||||
|
*/
|
||||||
node: Parameters<NodeViewConstructor>[0];
|
node: Parameters<NodeViewConstructor>[0];
|
||||||
|
/**
|
||||||
|
* The editor's view.
|
||||||
|
*/
|
||||||
view: Parameters<NodeViewConstructor>[1];
|
view: Parameters<NodeViewConstructor>[1];
|
||||||
|
/**
|
||||||
|
* A function that can be called to get the node's current position in the document.
|
||||||
|
*/
|
||||||
getPos: () => number; // TODO getPos was incorrectly typed before, change to `Parameters<NodeViewConstructor>[2];` in the next major version
|
getPos: () => number; // TODO getPos was incorrectly typed before, change to `Parameters<NodeViewConstructor>[2];` in the next major version
|
||||||
|
/**
|
||||||
|
* is an array of node or inline decorations that are active around the node.
|
||||||
|
* They are automatically drawn in the normal way, and you will usually just want to ignore this, but they can also be used as a way to provide context information to the node view without adding it to the document itself.
|
||||||
|
*/
|
||||||
decorations: Parameters<NodeViewConstructor>[3];
|
decorations: Parameters<NodeViewConstructor>[3];
|
||||||
|
/**
|
||||||
|
* holds the decorations for the node's content. You can safely ignore this if your view has no content or a contentDOM property, since the editor will draw the decorations on the content.
|
||||||
|
* But if you, for example, want to create a nested editor with the content, it may make sense to provide it with the inner decorations.
|
||||||
|
*/
|
||||||
innerDecorations: Parameters<NodeViewConstructor>[4];
|
innerDecorations: Parameters<NodeViewConstructor>[4];
|
||||||
// tiptap-specific
|
// tiptap-specific
|
||||||
|
/**
|
||||||
|
* The editor instance.
|
||||||
|
*/
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
|
/**
|
||||||
|
* The extension that is responsible for the node.
|
||||||
|
*/
|
||||||
extension: Node;
|
extension: Node;
|
||||||
|
/**
|
||||||
|
* The HTML attributes that should be added to the node's DOM element.
|
||||||
|
*/
|
||||||
HTMLAttributes: Record<string, any>;
|
HTMLAttributes: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user