add basic extension classes

This commit is contained in:
Philipp Kühn
2020-10-09 22:59:25 +02:00
parent a4ccb36e10
commit 8324f57528
13 changed files with 421 additions and 266 deletions

View File

@@ -1,33 +1,59 @@
import { NodeSpec, NodeType } from 'prosemirror-model'
import Extension, { ExtensionMethods } from './Extension'
import { Editor } from './Editor'
// import { NodeSpec, NodeType } from 'prosemirror-model'
// import Extension, { ExtensionMethods } from './Extension'
// import { Editor } from './Editor'
export interface NodeProps<Options> {
name: string
editor: Editor
options: Options
type: NodeType
}
// export interface NodeProps<Options> {
// name: string
// editor: Editor
// options: Options
// type: NodeType
// }
export interface NodeMethods<Props, Options> extends ExtensionMethods<Props, Options> {
topNode: boolean
schema: (params: Omit<Props, 'type' | 'editor'>) => NodeSpec
}
// export interface NodeMethods<Props, Options> extends ExtensionMethods<Props, Options> {
// topNode: boolean
// schema: (params: Omit<Props, 'type' | 'editor'>) => NodeSpec
// }
// export default class Node<
// Options = {},
// Props = NodeProps<Options>,
// Methods extends NodeMethods<Props, Options> = NodeMethods<Props, Options>,
// > extends Extension<Options, Props, Methods> {
// type = 'node'
// public topNode(value: Methods['topNode'] = true) {
// this.storeConfig('topNode', value, 'overwrite')
// return this
// }
// public schema(value: Methods['schema']) {
// this.storeConfig('schema', value, 'overwrite')
// return this
// }
// }
import Extension from './Extension'
export default class Node<Options = {}> extends Extension<Options> {
export default class Node<
Options = {},
Props = NodeProps<Options>,
Methods extends NodeMethods<Props, Options> = NodeMethods<Props, Options>,
> extends Extension<Options, Props, Methods> {
type = 'node'
public topNode(value: Methods['topNode'] = true) {
this.storeConfig('topNode', value, 'overwrite')
return this
topNode = false
group = ''
content = ''
createAttributes() {
return {}
}
public schema(value: Methods['schema']) {
this.storeConfig('schema', value, 'overwrite')
return this
parseHTML() {
return []
}
renderHTML() {
return []
}
}