fix type issue

This commit is contained in:
Philipp Kühn
2020-09-09 12:57:50 +02:00
parent 22109170b3
commit f56fae49a1
6 changed files with 38 additions and 61 deletions

View File

@@ -66,7 +66,7 @@ export interface ExtensionCallback {
options: any
}
export interface ExtensionExtends<Callback = ExtensionCallback> {
export interface ExtensionExtends<Callback> {
name: string
options: AnyObject
commands: (params: Callback) => CommandSpec
@@ -78,7 +78,7 @@ export interface ExtensionExtends<Callback = ExtensionCallback> {
plugins: (params: Callback) => Plugin[]
}
export default class Extension<Options = {}, Extends extends ExtensionExtends = ExtensionExtends> {
export default class Extension<Options = {}, Callback = ExtensionCallback, Extends extends ExtensionExtends<Callback> = ExtensionExtends<Callback>> {
type = 'extension'
config: any = {}
configs: {

View File

@@ -36,6 +36,7 @@ export default class ExtensionManager {
: {
editor,
options: deepmerge(extension.config.defaults, extension.usedOptions),
// TODO: type is not available here
// get type() {
// console.log('called', editor.schema)

View File

@@ -1,33 +1,20 @@
import { MarkSpec, MarkType } from 'prosemirror-model'
import Extension, { ExtensionCallback, ExtensionExtends } from './Extension'
import { Editor } from './Editor'
// export default abstract class Mark extends Extension {
// constructor(options = {}) {
// super(options)
// }
// public extensionType = 'mark'
// abstract schema(): MarkSpec
// get type() {
// return this.editor.schema.marks[this.name]
// }
// }
export interface MarkCallback extends ExtensionCallback {
// TODO: fix optional
type?: MarkType
interface Callback {
name: string
editor: Editor
options: any
type: MarkType
}
export interface MarkExtends<Callback = MarkCallback> extends ExtensionExtends<Callback> {
export interface MarkExtends extends ExtensionExtends<Callback> {
topMark: boolean
schema: (params: Callback) => MarkSpec
}
export default class Mark<Options = {}> extends Extension<Options, MarkExtends> {
export default class Mark<Options = {}> extends Extension<Options, Callback, MarkExtends> {
type = 'mark'
public schema(value: MarkExtends['schema']) {

View File

@@ -1,35 +1,20 @@
import { NodeSpec, NodeType } from 'prosemirror-model'
import Extension, { ExtensionCallback, ExtensionExtends } from './Extension'
import { Editor } from './Editor'
// export default abstract class Node extends Extension {
// constructor(options = {}) {
// super(options)
// }
// public extensionType = 'node'
// public topNode = false
// abstract schema(): NodeSpec
// get type() {
// return this.editor.schema.nodes[this.name]
// }
// }
export interface NodeCallback extends ExtensionCallback {
// TODO: fix optional
type?: NodeType
interface Callback {
name: string
editor: Editor
options: any
type: NodeType
}
export interface NodeExtends<Callback = NodeCallback> extends ExtensionExtends<Callback> {
export interface NodeExtends extends ExtensionExtends<Callback> {
topNode: boolean
schema: (params: Callback) => NodeSpec
}
export default class Node<Options = {}> extends Extension<Options, NodeExtends> {
export default class Node<Options = {}> extends Extension<Options, Callback, NodeExtends> {
type = 'node'
public topNode(value: NodeExtends['topNode'] = true) {