wip: save hierachy within extension classes
This commit is contained in:
@@ -41,7 +41,7 @@ declare module '@tiptap/core' {
|
||||
*/
|
||||
addGlobalAttributes?: (this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['addGlobalAttributes'],
|
||||
}) => GlobalAttributes | {},
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['addCommands'],
|
||||
}) => Partial<RawCommands>,
|
||||
|
||||
/**
|
||||
@@ -61,7 +61,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['addKeyboardShortcuts'],
|
||||
}) => {
|
||||
[key: string]: ProseMirrorCommand,
|
||||
},
|
||||
@@ -73,7 +73,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['addInputRules'],
|
||||
}) => InputRule[],
|
||||
|
||||
/**
|
||||
@@ -83,7 +83,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['addPasteRules'],
|
||||
}) => Plugin[],
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['addProseMirrorPlugins'],
|
||||
}) => Plugin[],
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,7 @@ declare module '@tiptap/core' {
|
||||
extendNodeSchema?: ((
|
||||
this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['extendNodeSchema'],
|
||||
},
|
||||
extension: Node,
|
||||
) => {
|
||||
@@ -115,7 +115,7 @@ declare module '@tiptap/core' {
|
||||
extendMarkSchema?: ((
|
||||
this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['extendMarkSchema'],
|
||||
},
|
||||
extension: Node,
|
||||
) => {
|
||||
@@ -125,11 +125,11 @@ declare module '@tiptap/core' {
|
||||
/**
|
||||
* The editor is not ready yet.
|
||||
*/
|
||||
onBeforeCreate?: ((this: {
|
||||
onBeforeCreate?: ((this: {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['onBeforeCreate'],
|
||||
}) => void) | null,
|
||||
|
||||
/**
|
||||
@@ -139,7 +139,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['onCreate'],
|
||||
}) => void) | null,
|
||||
|
||||
/**
|
||||
@@ -149,7 +149,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['onUpdate'],
|
||||
}) => void) | null,
|
||||
|
||||
/**
|
||||
@@ -159,7 +159,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['onSelectionUpdate'],
|
||||
}) => void) | null,
|
||||
|
||||
/**
|
||||
@@ -170,7 +170,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['onTransaction'],
|
||||
},
|
||||
props: {
|
||||
transaction: Transaction,
|
||||
@@ -185,7 +185,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['onFocus'],
|
||||
},
|
||||
props: {
|
||||
event: FocusEvent,
|
||||
@@ -200,7 +200,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['onBlur'],
|
||||
},
|
||||
props: {
|
||||
event: FocusEvent,
|
||||
@@ -214,7 +214,7 @@ declare module '@tiptap/core' {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['onDestroy'],
|
||||
}) => void) | null,
|
||||
|
||||
/**
|
||||
@@ -227,7 +227,7 @@ declare module '@tiptap/core' {
|
||||
*/
|
||||
inclusive?: MarkSpec['inclusive'] | ((this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['inclusive'],
|
||||
}) => MarkSpec['inclusive']),
|
||||
|
||||
/**
|
||||
@@ -235,7 +235,7 @@ declare module '@tiptap/core' {
|
||||
*/
|
||||
excludes?: MarkSpec['excludes'] | ((this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['excludes'],
|
||||
}) => MarkSpec['excludes']),
|
||||
|
||||
/**
|
||||
@@ -243,7 +243,7 @@ declare module '@tiptap/core' {
|
||||
*/
|
||||
group?: MarkSpec['group'] | ((this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['group'],
|
||||
}) => MarkSpec['group']),
|
||||
|
||||
/**
|
||||
@@ -251,7 +251,7 @@ declare module '@tiptap/core' {
|
||||
*/
|
||||
spanning?: MarkSpec['spanning'] | ((this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['spanning'],
|
||||
}) => MarkSpec['spanning']),
|
||||
|
||||
/**
|
||||
@@ -260,7 +260,7 @@ declare module '@tiptap/core' {
|
||||
parseHTML?: (
|
||||
this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['parseHTML'],
|
||||
},
|
||||
) => MarkSpec['parseDOM'],
|
||||
|
||||
@@ -270,12 +270,12 @@ declare module '@tiptap/core' {
|
||||
renderHTML?: ((
|
||||
this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['renderHTML'],
|
||||
},
|
||||
props: {
|
||||
mark: ProseMirrorMark,
|
||||
HTMLAttributes: { [key: string]: any },
|
||||
}
|
||||
},
|
||||
) => DOMOutputSpec) | null,
|
||||
|
||||
/**
|
||||
@@ -284,27 +284,28 @@ declare module '@tiptap/core' {
|
||||
addAttributes?: (
|
||||
this: {
|
||||
options: Options,
|
||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
||||
parent: ParentConfig<MarkConfig<Options>>['addAttributes'],
|
||||
},
|
||||
) => Attributes | {},
|
||||
}
|
||||
}
|
||||
|
||||
export class Mark<Options = any> {
|
||||
type = 'mark'
|
||||
type = 'node'
|
||||
|
||||
config: MarkConfig = {
|
||||
name: 'mark',
|
||||
name: 'node',
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
// parentConfig: Partial<MarkConfig> = {}
|
||||
parent: any
|
||||
options: Options
|
||||
|
||||
options!: Options
|
||||
parent: Mark | null = null
|
||||
|
||||
constructor(config: MarkConfig<Options>) {
|
||||
child: Mark | null = null
|
||||
|
||||
constructor(config: Partial<MarkConfig<Options>> = {}) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
@@ -313,31 +314,27 @@ export class Mark<Options = any> {
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
static create<O>(config: MarkConfig<O>) {
|
||||
static create<O>(config: Partial<MarkConfig<O>> = {}) {
|
||||
return new Mark<O>(config)
|
||||
}
|
||||
|
||||
configure(options: Partial<Options> = {}) {
|
||||
return Mark
|
||||
.create<Options>(this.config as MarkConfig<Options>)
|
||||
.#configure(options)
|
||||
}
|
||||
|
||||
#configure = (options: Partial<Options>) => {
|
||||
this.options = mergeDeep(this.config.defaultOptions, options) as Options
|
||||
this.options = mergeDeep(this.options, options) as Options
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>>) {
|
||||
const extension = new Mark<ExtendedOptions>({
|
||||
...this.config,
|
||||
...extendedConfig,
|
||||
} as MarkConfig<ExtendedOptions>)
|
||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>> = {}) {
|
||||
const extension = new Mark<ExtendedOptions>(extendedConfig)
|
||||
|
||||
extension.parent = this
|
||||
|
||||
// extension.parentConfig = this.config
|
||||
this.child = extension
|
||||
|
||||
extension.options = {
|
||||
...extension.parent.options,
|
||||
...extension.options,
|
||||
}
|
||||
|
||||
return extension
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user