tiptap/packages/core/src/Node.ts

34 lines
887 B
TypeScript
Raw Normal View History

2020-09-09 05:44:45 +08:00
import { NodeSpec, NodeType } from 'prosemirror-model'
2020-09-19 06:20:34 +08:00
import Extension, { ExtensionMethods } from './Extension'
2020-09-09 18:57:50 +08:00
import { Editor } from './Editor'
2019-12-17 06:20:05 +08:00
2020-09-19 06:20:34 +08:00
export interface NodeProps<Options> {
2020-09-09 18:57:50 +08:00
name: string
editor: Editor
2020-09-09 23:10:29 +08:00
options: Options
2020-09-09 18:57:50 +08:00
type: NodeType
2020-09-09 05:44:45 +08:00
}
2019-12-17 06:20:05 +08:00
2020-09-19 06:20:34 +08:00
export interface NodeMethods<Props, Options> extends ExtensionMethods<Props, Options> {
2020-09-09 05:44:45 +08:00
topNode: boolean
2020-09-19 06:20:34 +08:00
schema: (params: Omit<Props, 'type' | 'editor'>) => NodeSpec
2020-09-09 05:44:45 +08:00
}
2020-09-09 23:10:29 +08:00
export default class Node<
Options = {},
2020-09-19 06:20:34 +08:00
Props = NodeProps<Options>,
2020-09-25 19:56:31 +08:00
Methods extends NodeMethods<Props, Options> = NodeMethods<Props, Options>,
2020-09-19 06:20:34 +08:00
> extends Extension<Options, Props, Methods> {
2020-09-09 05:44:45 +08:00
type = 'node'
2020-09-19 06:20:34 +08:00
public topNode(value: Methods['topNode'] = true) {
2020-09-09 05:44:45 +08:00
this.storeConfig('topNode', value, 'overwrite')
return this
2020-03-30 18:40:25 +08:00
}
2020-09-19 06:20:34 +08:00
public schema(value: Methods['schema']) {
2020-09-09 05:44:45 +08:00
this.storeConfig('schema', value, 'overwrite')
return this
}
2019-12-17 06:20:05 +08:00
}