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