wip: save hierachy within extension classes
This commit is contained in:
@@ -31,7 +31,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
addGlobalAttributes?: (this: {
|
addGlobalAttributes?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['addGlobalAttributes'],
|
||||||
}) => GlobalAttributes | {},
|
}) => GlobalAttributes | {},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +40,7 @@ declare module '@tiptap/core' {
|
|||||||
addCommands?: (this: {
|
addCommands?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['addCommands'],
|
||||||
}) => Partial<RawCommands>,
|
}) => Partial<RawCommands>,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +49,7 @@ declare module '@tiptap/core' {
|
|||||||
addKeyboardShortcuts?: (this: {
|
addKeyboardShortcuts?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['addKeyboardShortcuts'],
|
||||||
}) => {
|
}) => {
|
||||||
[key: string]: ProseMirrorCommand,
|
[key: string]: ProseMirrorCommand,
|
||||||
},
|
},
|
||||||
@@ -60,7 +60,7 @@ declare module '@tiptap/core' {
|
|||||||
addInputRules?: (this: {
|
addInputRules?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['addInputRules'],
|
||||||
}) => InputRule[],
|
}) => InputRule[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +69,7 @@ declare module '@tiptap/core' {
|
|||||||
addPasteRules?: (this: {
|
addPasteRules?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['addPasteRules'],
|
||||||
}) => Plugin[],
|
}) => Plugin[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,7 +78,7 @@ declare module '@tiptap/core' {
|
|||||||
addProseMirrorPlugins?: (this: {
|
addProseMirrorPlugins?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['addProseMirrorPlugins'],
|
||||||
}) => Plugin[],
|
}) => Plugin[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +87,7 @@ declare module '@tiptap/core' {
|
|||||||
extendNodeSchema?: ((
|
extendNodeSchema?: ((
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['extendNodeSchema'],
|
||||||
},
|
},
|
||||||
extension: Node,
|
extension: Node,
|
||||||
) => {
|
) => {
|
||||||
@@ -100,7 +100,7 @@ declare module '@tiptap/core' {
|
|||||||
extendMarkSchema?: ((
|
extendMarkSchema?: ((
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['extendMarkSchema'],
|
||||||
},
|
},
|
||||||
extension: Node,
|
extension: Node,
|
||||||
) => {
|
) => {
|
||||||
@@ -113,7 +113,7 @@ declare module '@tiptap/core' {
|
|||||||
onBeforeCreate?: ((this: {
|
onBeforeCreate?: ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['onBeforeCreate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,7 +122,7 @@ declare module '@tiptap/core' {
|
|||||||
onCreate?: ((this: {
|
onCreate?: ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['onCreate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,7 +131,7 @@ declare module '@tiptap/core' {
|
|||||||
onUpdate?: ((this: {
|
onUpdate?: ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['onUpdate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,7 +140,7 @@ declare module '@tiptap/core' {
|
|||||||
onSelectionUpdate?: ((this: {
|
onSelectionUpdate?: ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['onSelectionUpdate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,7 +150,7 @@ declare module '@tiptap/core' {
|
|||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['onTransaction'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
@@ -164,7 +164,7 @@ declare module '@tiptap/core' {
|
|||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['onFocus'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
event: FocusEvent,
|
event: FocusEvent,
|
||||||
@@ -178,7 +178,7 @@ declare module '@tiptap/core' {
|
|||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['onBlur'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
event: FocusEvent,
|
event: FocusEvent,
|
||||||
@@ -191,7 +191,7 @@ declare module '@tiptap/core' {
|
|||||||
onDestroy?: ((this: {
|
onDestroy?: ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
parentConfig: ParentConfig<ExtensionConfig<Options>>,
|
parent: ParentConfig<ExtensionConfig<Options>>['onDestroy'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,12 +205,13 @@ export class Extension<Options = any> {
|
|||||||
defaultOptions: {},
|
defaultOptions: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// parentConfig: Partial<ExtensionConfig> = {}
|
options: Options
|
||||||
parent: any
|
|
||||||
|
|
||||||
options!: Options
|
parent: Extension | null = null
|
||||||
|
|
||||||
constructor(config: ExtensionConfig<Options>) {
|
child: Extension | null = null
|
||||||
|
|
||||||
|
constructor(config: Partial<ExtensionConfig<Options>> = {}) {
|
||||||
this.config = {
|
this.config = {
|
||||||
...this.config,
|
...this.config,
|
||||||
...config,
|
...config,
|
||||||
@@ -219,33 +220,26 @@ export class Extension<Options = any> {
|
|||||||
this.options = this.config.defaultOptions
|
this.options = this.config.defaultOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
static create<O>(config: ExtensionConfig<O>) {
|
static create<O>(config: Partial<ExtensionConfig<O>> = {}) {
|
||||||
return new Extension<O>(config)
|
return new Extension<O>(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
configure(options: Partial<Options> = {}) {
|
configure(options: Partial<Options> = {}) {
|
||||||
return Extension
|
this.options = mergeDeep(this.options, options) as Options
|
||||||
.create<Options>(this.config as ExtensionConfig<Options>)
|
|
||||||
.#configure(options)
|
|
||||||
}
|
|
||||||
|
|
||||||
#configure = (options: Partial<Options>) => {
|
|
||||||
this.options = mergeDeep(this.config.defaultOptions, options) as Options
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions>> = {}) {
|
extend<ExtendedOptions = Options>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions>> = {}) {
|
||||||
const extension = new Extension<ExtendedOptions>({
|
const extension = new Extension<ExtendedOptions>(extendedConfig)
|
||||||
// ...this.config,
|
|
||||||
...extendedConfig,
|
|
||||||
} as ExtensionConfig<ExtendedOptions>)
|
|
||||||
|
|
||||||
// extension.parentConfig = this.config
|
|
||||||
extension.parent = this
|
extension.parent = this
|
||||||
|
|
||||||
|
this.child = extension
|
||||||
|
|
||||||
extension.options = {
|
extension.options = {
|
||||||
...(this.config.defaultOptions ?? {}),
|
...extension.parent.options,
|
||||||
...(extendedConfig.defaultOptions ?? {}),
|
...extension.options,
|
||||||
}
|
}
|
||||||
|
|
||||||
return extension
|
return extension
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
addGlobalAttributes?: (this: {
|
addGlobalAttributes?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['addGlobalAttributes'],
|
||||||
}) => GlobalAttributes | {},
|
}) => GlobalAttributes | {},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +51,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['addCommands'],
|
||||||
}) => Partial<RawCommands>,
|
}) => Partial<RawCommands>,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,7 +61,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['addKeyboardShortcuts'],
|
||||||
}) => {
|
}) => {
|
||||||
[key: string]: ProseMirrorCommand,
|
[key: string]: ProseMirrorCommand,
|
||||||
},
|
},
|
||||||
@@ -73,7 +73,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['addInputRules'],
|
||||||
}) => InputRule[],
|
}) => InputRule[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +83,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['addPasteRules'],
|
||||||
}) => Plugin[],
|
}) => Plugin[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +93,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['addProseMirrorPlugins'],
|
||||||
}) => Plugin[],
|
}) => Plugin[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,7 +102,7 @@ declare module '@tiptap/core' {
|
|||||||
extendNodeSchema?: ((
|
extendNodeSchema?: ((
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['extendNodeSchema'],
|
||||||
},
|
},
|
||||||
extension: Node,
|
extension: Node,
|
||||||
) => {
|
) => {
|
||||||
@@ -115,7 +115,7 @@ declare module '@tiptap/core' {
|
|||||||
extendMarkSchema?: ((
|
extendMarkSchema?: ((
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['extendMarkSchema'],
|
||||||
},
|
},
|
||||||
extension: Node,
|
extension: Node,
|
||||||
) => {
|
) => {
|
||||||
@@ -129,7 +129,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['onBeforeCreate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,7 +139,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['onCreate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,7 +149,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['onUpdate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +159,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['onSelectionUpdate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,7 +170,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['onTransaction'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
@@ -185,7 +185,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['onFocus'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
event: FocusEvent,
|
event: FocusEvent,
|
||||||
@@ -200,7 +200,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['onBlur'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
event: FocusEvent,
|
event: FocusEvent,
|
||||||
@@ -214,7 +214,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['onDestroy'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,7 +227,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
inclusive?: MarkSpec['inclusive'] | ((this: {
|
inclusive?: MarkSpec['inclusive'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['inclusive'],
|
||||||
}) => MarkSpec['inclusive']),
|
}) => MarkSpec['inclusive']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -235,7 +235,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
excludes?: MarkSpec['excludes'] | ((this: {
|
excludes?: MarkSpec['excludes'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['excludes'],
|
||||||
}) => MarkSpec['excludes']),
|
}) => MarkSpec['excludes']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -243,7 +243,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
group?: MarkSpec['group'] | ((this: {
|
group?: MarkSpec['group'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['group'],
|
||||||
}) => MarkSpec['group']),
|
}) => MarkSpec['group']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -251,7 +251,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
spanning?: MarkSpec['spanning'] | ((this: {
|
spanning?: MarkSpec['spanning'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['spanning'],
|
||||||
}) => MarkSpec['spanning']),
|
}) => MarkSpec['spanning']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -260,7 +260,7 @@ declare module '@tiptap/core' {
|
|||||||
parseHTML?: (
|
parseHTML?: (
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['parseHTML'],
|
||||||
},
|
},
|
||||||
) => MarkSpec['parseDOM'],
|
) => MarkSpec['parseDOM'],
|
||||||
|
|
||||||
@@ -270,12 +270,12 @@ declare module '@tiptap/core' {
|
|||||||
renderHTML?: ((
|
renderHTML?: ((
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['renderHTML'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
mark: ProseMirrorMark,
|
mark: ProseMirrorMark,
|
||||||
HTMLAttributes: { [key: string]: any },
|
HTMLAttributes: { [key: string]: any },
|
||||||
}
|
},
|
||||||
) => DOMOutputSpec) | null,
|
) => DOMOutputSpec) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -284,27 +284,28 @@ declare module '@tiptap/core' {
|
|||||||
addAttributes?: (
|
addAttributes?: (
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<MarkConfig<Options>>,
|
parent: ParentConfig<MarkConfig<Options>>['addAttributes'],
|
||||||
},
|
},
|
||||||
) => Attributes | {},
|
) => Attributes | {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Mark<Options = any> {
|
export class Mark<Options = any> {
|
||||||
type = 'mark'
|
type = 'node'
|
||||||
|
|
||||||
config: MarkConfig = {
|
config: MarkConfig = {
|
||||||
name: 'mark',
|
name: 'node',
|
||||||
priority: 100,
|
priority: 100,
|
||||||
defaultOptions: {},
|
defaultOptions: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// parentConfig: Partial<MarkConfig> = {}
|
options: Options
|
||||||
parent: any
|
|
||||||
|
|
||||||
options!: Options
|
parent: Mark | null = null
|
||||||
|
|
||||||
constructor(config: MarkConfig<Options>) {
|
child: Mark | null = null
|
||||||
|
|
||||||
|
constructor(config: Partial<MarkConfig<Options>> = {}) {
|
||||||
this.config = {
|
this.config = {
|
||||||
...this.config,
|
...this.config,
|
||||||
...config,
|
...config,
|
||||||
@@ -313,31 +314,27 @@ export class Mark<Options = any> {
|
|||||||
this.options = this.config.defaultOptions
|
this.options = this.config.defaultOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
static create<O>(config: MarkConfig<O>) {
|
static create<O>(config: Partial<MarkConfig<O>> = {}) {
|
||||||
return new Mark<O>(config)
|
return new Mark<O>(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
configure(options: Partial<Options> = {}) {
|
configure(options: Partial<Options> = {}) {
|
||||||
return Mark
|
this.options = mergeDeep(this.options, options) as Options
|
||||||
.create<Options>(this.config as MarkConfig<Options>)
|
|
||||||
.#configure(options)
|
|
||||||
}
|
|
||||||
|
|
||||||
#configure = (options: Partial<Options>) => {
|
|
||||||
this.options = mergeDeep(this.config.defaultOptions, options) as Options
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>>) {
|
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>> = {}) {
|
||||||
const extension = new Mark<ExtendedOptions>({
|
const extension = new Mark<ExtendedOptions>(extendedConfig)
|
||||||
...this.config,
|
|
||||||
...extendedConfig,
|
|
||||||
} as MarkConfig<ExtendedOptions>)
|
|
||||||
|
|
||||||
extension.parent = this
|
extension.parent = this
|
||||||
|
|
||||||
// extension.parentConfig = this.config
|
this.child = extension
|
||||||
|
|
||||||
|
extension.options = {
|
||||||
|
...extension.parent.options,
|
||||||
|
...extension.options,
|
||||||
|
}
|
||||||
|
|
||||||
return extension
|
return extension
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
addGlobalAttributes?: (this: {
|
addGlobalAttributes?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['addGlobalAttributes'],
|
||||||
}) => GlobalAttributes | {},
|
}) => GlobalAttributes | {},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +52,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['addCommands'],
|
||||||
}) => Partial<RawCommands>,
|
}) => Partial<RawCommands>,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +62,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['addKeyboardShortcuts'],
|
||||||
}) => {
|
}) => {
|
||||||
[key: string]: ProseMirrorCommand,
|
[key: string]: ProseMirrorCommand,
|
||||||
},
|
},
|
||||||
@@ -74,7 +74,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['addInputRules'],
|
||||||
}) => InputRule[],
|
}) => InputRule[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +84,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['addPasteRules'],
|
||||||
}) => Plugin[],
|
}) => Plugin[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,7 +94,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['addProseMirrorPlugins'],
|
||||||
}) => Plugin[],
|
}) => Plugin[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,7 +103,7 @@ declare module '@tiptap/core' {
|
|||||||
extendNodeSchema?: ((
|
extendNodeSchema?: ((
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['extendNodeSchema'],
|
||||||
},
|
},
|
||||||
extension: Node,
|
extension: Node,
|
||||||
) => {
|
) => {
|
||||||
@@ -116,7 +116,7 @@ declare module '@tiptap/core' {
|
|||||||
extendMarkSchema?: ((
|
extendMarkSchema?: ((
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['extendMarkSchema'],
|
||||||
},
|
},
|
||||||
extension: Node,
|
extension: Node,
|
||||||
) => {
|
) => {
|
||||||
@@ -130,7 +130,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['onBeforeCreate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,7 +140,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['onCreate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,7 +150,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['onUpdate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,7 +160,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['onSelectionUpdate'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,7 +171,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['onTransaction'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
@@ -186,7 +186,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['onFocus'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
event: FocusEvent,
|
event: FocusEvent,
|
||||||
@@ -201,7 +201,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['onBlur'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
event: FocusEvent,
|
event: FocusEvent,
|
||||||
@@ -215,7 +215,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['onDestroy'],
|
||||||
}) => void) | null,
|
}) => void) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -225,7 +225,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['addNodeView'],
|
||||||
}) => NodeViewRenderer) | null,
|
}) => NodeViewRenderer) | null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,7 +238,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
content?: NodeSpec['content'] | ((this: {
|
content?: NodeSpec['content'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['content'],
|
||||||
}) => NodeSpec['content']),
|
}) => NodeSpec['content']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,7 +246,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
marks?: NodeSpec['marks'] | ((this: {
|
marks?: NodeSpec['marks'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['marks'],
|
||||||
}) => NodeSpec['marks']),
|
}) => NodeSpec['marks']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,7 +254,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
group?: NodeSpec['group'] | ((this: {
|
group?: NodeSpec['group'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['group'],
|
||||||
}) => NodeSpec['group']),
|
}) => NodeSpec['group']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -262,7 +262,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
inline?: NodeSpec['inline'] | ((this: {
|
inline?: NodeSpec['inline'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['inline'],
|
||||||
}) => NodeSpec['inline']),
|
}) => NodeSpec['inline']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -270,7 +270,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
atom?: NodeSpec['atom'] | ((this: {
|
atom?: NodeSpec['atom'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['atom'],
|
||||||
}) => NodeSpec['atom']),
|
}) => NodeSpec['atom']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -278,7 +278,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
selectable?: NodeSpec['selectable'] | ((this: {
|
selectable?: NodeSpec['selectable'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['selectable'],
|
||||||
}) => NodeSpec['selectable']),
|
}) => NodeSpec['selectable']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -286,7 +286,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
draggable?: NodeSpec['draggable'] | ((this: {
|
draggable?: NodeSpec['draggable'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['draggable'],
|
||||||
}) => NodeSpec['draggable']),
|
}) => NodeSpec['draggable']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -294,7 +294,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
code?: NodeSpec['code'] | ((this: {
|
code?: NodeSpec['code'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['code'],
|
||||||
}) => NodeSpec['code']),
|
}) => NodeSpec['code']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -302,7 +302,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
defining?: NodeSpec['defining'] | ((this: {
|
defining?: NodeSpec['defining'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['defining'],
|
||||||
}) => NodeSpec['defining']),
|
}) => NodeSpec['defining']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -310,7 +310,7 @@ declare module '@tiptap/core' {
|
|||||||
*/
|
*/
|
||||||
isolating?: NodeSpec['isolating'] | ((this: {
|
isolating?: NodeSpec['isolating'] | ((this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['isolating'],
|
||||||
}) => NodeSpec['isolating']),
|
}) => NodeSpec['isolating']),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -319,7 +319,7 @@ declare module '@tiptap/core' {
|
|||||||
parseHTML?: (
|
parseHTML?: (
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['parseHTML'],
|
||||||
},
|
},
|
||||||
) => NodeSpec['parseDOM'],
|
) => NodeSpec['parseDOM'],
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ declare module '@tiptap/core' {
|
|||||||
renderHTML?: ((
|
renderHTML?: ((
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['renderHTML'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
node: ProseMirrorNode,
|
node: ProseMirrorNode,
|
||||||
@@ -345,7 +345,7 @@ declare module '@tiptap/core' {
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['renderText'],
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
node: ProseMirrorNode,
|
node: ProseMirrorNode,
|
||||||
@@ -358,7 +358,7 @@ declare module '@tiptap/core' {
|
|||||||
addAttributes?: (
|
addAttributes?: (
|
||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
parentConfig: ParentConfig<NodeConfig<Options>>,
|
parent: ParentConfig<NodeConfig<Options>>['addAttributes'],
|
||||||
},
|
},
|
||||||
) => Attributes | {},
|
) => Attributes | {},
|
||||||
}
|
}
|
||||||
@@ -373,12 +373,13 @@ export class Node<Options = any> {
|
|||||||
defaultOptions: {},
|
defaultOptions: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// parentConfig: Partial<NodeConfig> = {}
|
options: Options
|
||||||
parent: any
|
|
||||||
|
|
||||||
options!: Options
|
parent: Node | null = null
|
||||||
|
|
||||||
constructor(config: NodeConfig<Options>) {
|
child: Node | null = null
|
||||||
|
|
||||||
|
constructor(config: Partial<NodeConfig<Options>> = {}) {
|
||||||
this.config = {
|
this.config = {
|
||||||
...this.config,
|
...this.config,
|
||||||
...config,
|
...config,
|
||||||
@@ -387,30 +388,27 @@ export class Node<Options = any> {
|
|||||||
this.options = this.config.defaultOptions
|
this.options = this.config.defaultOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
static create<O>(config: NodeConfig<O>) {
|
static create<O>(config: Partial<NodeConfig<O>> = {}) {
|
||||||
return new Node<O>(config)
|
return new Node<O>(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
configure(options: Partial<Options> = {}) {
|
configure(options: Partial<Options> = {}) {
|
||||||
return Node
|
this.options = mergeDeep(this.options, options) as Options
|
||||||
.create<Options>(this.config as NodeConfig<Options>)
|
|
||||||
.#configure(options)
|
|
||||||
}
|
|
||||||
|
|
||||||
#configure = (options: Partial<Options>) => {
|
|
||||||
this.options = mergeDeep(this.config.defaultOptions, options) as Options
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>>) {
|
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>> = {}) {
|
||||||
const extension = new Node<ExtendedOptions>({
|
const extension = new Node<ExtendedOptions>(extendedConfig)
|
||||||
...this.config,
|
|
||||||
...extendedConfig,
|
|
||||||
} as NodeConfig<ExtendedOptions>)
|
|
||||||
|
|
||||||
extension.parent = this
|
extension.parent = this
|
||||||
// extension.parentConfig = this.config
|
|
||||||
|
this.child = extension
|
||||||
|
|
||||||
|
extension.options = {
|
||||||
|
...extension.parent.options,
|
||||||
|
...extension.options,
|
||||||
|
}
|
||||||
|
|
||||||
return extension
|
return extension
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user