refactoring
This commit is contained in:
@@ -17,28 +17,28 @@ type Configs = {
|
||||
}[]
|
||||
}
|
||||
|
||||
export interface ExtensionCallback<Options> {
|
||||
export interface ExtensionProps<Options> {
|
||||
name: string
|
||||
editor: Editor
|
||||
options: Options
|
||||
}
|
||||
|
||||
export interface ExtensionExtends<Callback, Options> {
|
||||
export interface ExtensionMethods<Props, Options> {
|
||||
name: string
|
||||
options: Options
|
||||
commands: (params: Callback) => CommandSpec
|
||||
inputRules: (params: Callback) => any[]
|
||||
pasteRules: (params: Callback) => any[]
|
||||
keys: (params: Callback) => {
|
||||
commands: (params: Props) => CommandSpec
|
||||
inputRules: (params: Props) => any[]
|
||||
pasteRules: (params: Props) => any[]
|
||||
keys: (params: Props) => {
|
||||
[key: string]: Function
|
||||
}
|
||||
plugins: (params: Callback) => Plugin[]
|
||||
plugins: (params: Props) => Plugin[]
|
||||
}
|
||||
|
||||
export default class Extension<
|
||||
Options = {},
|
||||
Callback = ExtensionCallback<Options>,
|
||||
Extends extends ExtensionExtends<Callback, Options> = ExtensionExtends<Callback, Options>
|
||||
Props = ExtensionProps<Options>,
|
||||
Methods extends ExtensionMethods<Props, Options> = ExtensionMethods<Props, Options>
|
||||
> {
|
||||
type = 'extension'
|
||||
config: AnyObject = {}
|
||||
@@ -63,7 +63,7 @@ export default class Extension<
|
||||
return this
|
||||
}
|
||||
|
||||
public name(value: Extends['name']) {
|
||||
public name(value: Methods['name']) {
|
||||
this.storeConfig('name', value, 'overwrite')
|
||||
return this
|
||||
}
|
||||
@@ -73,32 +73,32 @@ export default class Extension<
|
||||
return this
|
||||
}
|
||||
|
||||
public commands(value: Extends['commands']) {
|
||||
public commands(value: Methods['commands']) {
|
||||
this.storeConfig('commands', value, 'overwrite')
|
||||
return this
|
||||
}
|
||||
|
||||
public keys(value: Extends['keys']) {
|
||||
public keys(value: Methods['keys']) {
|
||||
this.storeConfig('keys', value, 'overwrite')
|
||||
return this
|
||||
}
|
||||
|
||||
public inputRules(value: Extends['inputRules']) {
|
||||
public inputRules(value: Methods['inputRules']) {
|
||||
this.storeConfig('inputRules', value, 'overwrite')
|
||||
return this
|
||||
}
|
||||
|
||||
public pasteRules(value: Extends['pasteRules']) {
|
||||
public pasteRules(value: Methods['pasteRules']) {
|
||||
this.storeConfig('pasteRules', value, 'overwrite')
|
||||
return this
|
||||
}
|
||||
|
||||
public plugins(value: Extends['plugins']) {
|
||||
public plugins(value: Methods['plugins']) {
|
||||
this.storeConfig('plugins', value, 'overwrite')
|
||||
return this
|
||||
}
|
||||
|
||||
public extend<T extends Extract<keyof Extends, string>>(key: T, value: Extends[T]) {
|
||||
public extend<T extends Extract<keyof Methods, string>>(key: T, value: Methods[T]) {
|
||||
this.storeConfig(key, value, 'extend')
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { MarkSpec, MarkType } from 'prosemirror-model'
|
||||
import Extension, { ExtensionCallback, ExtensionExtends } from './Extension'
|
||||
import Extension, { ExtensionMethods } from './Extension'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
export interface MarkCallback<Options> {
|
||||
export interface MarkProps<Options> {
|
||||
name: string
|
||||
editor: Editor
|
||||
options: Options
|
||||
type: MarkType
|
||||
}
|
||||
|
||||
export interface MarkExtends<Callback, Options> extends ExtensionExtends<Callback, Options> {
|
||||
export interface MarkMethods<Props, Options> extends ExtensionMethods<Props, Options> {
|
||||
topMark: boolean
|
||||
schema: (params: Omit<Callback, 'type' | 'editor'>) => MarkSpec
|
||||
schema: (params: Omit<Props, 'type' | 'editor'>) => MarkSpec
|
||||
}
|
||||
|
||||
export default class Mark<
|
||||
Options = {},
|
||||
Callback = MarkCallback<Options>,
|
||||
Extends extends MarkExtends<Callback, Options> = MarkExtends<Callback, Options>
|
||||
> extends Extension<Options, Callback, Extends> {
|
||||
Props = MarkProps<Options>,
|
||||
Methods extends MarkMethods<Props, Options> = MarkMethods<Props, Options>
|
||||
> extends Extension<Options, Props, Methods> {
|
||||
type = 'mark'
|
||||
|
||||
public schema(value: Extends['schema']) {
|
||||
public schema(value: Methods['schema']) {
|
||||
this.storeConfig('schema', value, 'overwrite')
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import { NodeSpec, NodeType } from 'prosemirror-model'
|
||||
import Extension, { ExtensionCallback, ExtensionExtends } from './Extension'
|
||||
import Extension, { ExtensionMethods } from './Extension'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
export interface NodeCallback<Options> {
|
||||
export interface NodeProps<Options> {
|
||||
name: string
|
||||
editor: Editor
|
||||
options: Options
|
||||
type: NodeType
|
||||
}
|
||||
|
||||
export interface NodeExtends<Callback, Options> extends ExtensionExtends<Callback, Options> {
|
||||
export interface NodeMethods<Props, Options> extends ExtensionMethods<Props, Options> {
|
||||
topNode: boolean
|
||||
schema: (params: Omit<Callback, 'type' | 'editor'>) => NodeSpec
|
||||
schema: (params: Omit<Props, 'type' | 'editor'>) => NodeSpec
|
||||
}
|
||||
|
||||
export default class Node<
|
||||
Options = {},
|
||||
Callback = NodeCallback<Options>,
|
||||
Extends extends NodeExtends<Callback, Options> = NodeExtends<Callback, Options>
|
||||
> extends Extension<Options, Callback, Extends> {
|
||||
Props = NodeProps<Options>,
|
||||
Methods extends NodeMethods<Props, Options> = NodeMethods<Props, Options>
|
||||
> extends Extension<Options, Props, Methods> {
|
||||
type = 'node'
|
||||
|
||||
public topNode(value: Extends['topNode'] = true) {
|
||||
public topNode(value: Methods['topNode'] = true) {
|
||||
this.storeConfig('topNode', value, 'overwrite')
|
||||
return this
|
||||
}
|
||||
|
||||
public schema(value: Extends['schema']) {
|
||||
public schema(value: Methods['schema']) {
|
||||
this.storeConfig('schema', value, 'overwrite')
|
||||
return this
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user