tiptap/packages/core/src/Node.ts

34 lines
925 B
TypeScript
Raw Normal View History

2020-09-09 05:44:45 +08:00
import { NodeSpec, NodeType } from 'prosemirror-model'
import Extension, { ExtensionCallback, ExtensionExtends } from './Extension'
2020-09-09 18:57:50 +08:00
import { Editor } from './Editor'
2019-12-17 06:20:05 +08:00
2020-09-09 23:10:29 +08:00
interface NodeCallback<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-09 23:10:29 +08:00
export interface NodeExtends<Callback, Options> extends ExtensionExtends<Callback, Options> {
2020-09-09 05:44:45 +08:00
topNode: boolean
schema: (params: Omit<Callback, 'type' | 'editor'>) => NodeSpec
2020-09-09 05:44:45 +08:00
}
2020-09-09 23:10:29 +08:00
export default class Node<
Options = {},
Callback = NodeCallback<Options>,
Extends extends NodeExtends<Callback, Options> = NodeExtends<Callback, Options>
> extends Extension<Options, Callback, Extends> {
2020-09-09 05:44:45 +08:00
type = 'node'
2020-09-09 23:10:29 +08:00
public topNode(value: Extends['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-09 23:10:29 +08:00
public schema(value: Extends['schema']) {
2020-09-09 05:44:45 +08:00
this.storeConfig('schema', value, 'overwrite')
return this
}
2019-12-17 06:20:05 +08:00
}