tiptap/packages/core/src/Mark.ts

28 lines
798 B
TypeScript
Raw Normal View History

2020-09-09 05:44:45 +08:00
import { MarkSpec, MarkType } from 'prosemirror-model'
import Extension, { ExtensionCallback, ExtensionExtends } from './Extension'
2020-09-09 18:57:50 +08:00
import { Editor } from './Editor'
2020-03-30 18:40:25 +08:00
2020-09-09 23:10:29 +08:00
interface MarkCallback<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: MarkType
2020-09-09 05:44:45 +08:00
}
2020-03-30 18:40:25 +08:00
2020-09-09 23:10:29 +08:00
export interface MarkExtends<Callback, Options> extends ExtensionExtends<Callback, Options> {
2020-09-09 05:44:45 +08:00
topMark: boolean
schema: (params: Omit<Callback, 'type' | 'editor'>) => MarkSpec
2020-03-30 18:40:25 +08:00
}
2020-09-09 05:44:45 +08:00
2020-09-09 23:10:29 +08:00
export default class Mark<
Options = {},
Callback = MarkCallback<Options>,
Extends extends MarkExtends<Callback, Options> = MarkExtends<Callback, Options>
> extends Extension<Options, Callback, Extends> {
2020-09-09 17:23:24 +08:00
type = 'mark'
2020-09-09 05:44:45 +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
}
}