wip: save hierachy within extension classes

This commit is contained in:
Philipp Kühn 2021-04-15 14:40:28 +02:00
parent c40ce34eec
commit d194b90a61
3 changed files with 118 additions and 129 deletions

View File

@ -31,7 +31,7 @@ declare module '@tiptap/core' {
*/
addGlobalAttributes?: (this: {
options: Options,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['addGlobalAttributes'],
}) => GlobalAttributes | {},
/**
@ -40,7 +40,7 @@ declare module '@tiptap/core' {
addCommands?: (this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['addCommands'],
}) => Partial<RawCommands>,
/**
@ -49,7 +49,7 @@ declare module '@tiptap/core' {
addKeyboardShortcuts?: (this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['addKeyboardShortcuts'],
}) => {
[key: string]: ProseMirrorCommand,
},
@ -60,7 +60,7 @@ declare module '@tiptap/core' {
addInputRules?: (this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['addInputRules'],
}) => InputRule[],
/**
@ -69,7 +69,7 @@ declare module '@tiptap/core' {
addPasteRules?: (this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['addPasteRules'],
}) => Plugin[],
/**
@ -78,7 +78,7 @@ declare module '@tiptap/core' {
addProseMirrorPlugins?: (this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['addProseMirrorPlugins'],
}) => Plugin[],
/**
@ -87,7 +87,7 @@ declare module '@tiptap/core' {
extendNodeSchema?: ((
this: {
options: Options,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['extendNodeSchema'],
},
extension: Node,
) => {
@ -100,7 +100,7 @@ declare module '@tiptap/core' {
extendMarkSchema?: ((
this: {
options: Options,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['extendMarkSchema'],
},
extension: Node,
) => {
@ -113,7 +113,7 @@ declare module '@tiptap/core' {
onBeforeCreate?: ((this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['onBeforeCreate'],
}) => void) | null,
/**
@ -122,7 +122,7 @@ declare module '@tiptap/core' {
onCreate?: ((this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['onCreate'],
}) => void) | null,
/**
@ -131,7 +131,7 @@ declare module '@tiptap/core' {
onUpdate?: ((this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['onUpdate'],
}) => void) | null,
/**
@ -140,7 +140,7 @@ declare module '@tiptap/core' {
onSelectionUpdate?: ((this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['onSelectionUpdate'],
}) => void) | null,
/**
@ -150,7 +150,7 @@ declare module '@tiptap/core' {
this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['onTransaction'],
},
props: {
transaction: Transaction,
@ -164,7 +164,7 @@ declare module '@tiptap/core' {
this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['onFocus'],
},
props: {
event: FocusEvent,
@ -178,7 +178,7 @@ declare module '@tiptap/core' {
this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['onBlur'],
},
props: {
event: FocusEvent,
@ -191,7 +191,7 @@ declare module '@tiptap/core' {
onDestroy?: ((this: {
options: Options,
editor: Editor,
parentConfig: ParentConfig<ExtensionConfig<Options>>,
parent: ParentConfig<ExtensionConfig<Options>>['onDestroy'],
}) => void) | null,
}
}
@ -205,12 +205,13 @@ export class Extension<Options = any> {
defaultOptions: {},
}
// parentConfig: Partial<ExtensionConfig> = {}
parent: any
options: Options
options!: Options
parent: Extension | null = null
constructor(config: ExtensionConfig<Options>) {
child: Extension | null = null
constructor(config: Partial<ExtensionConfig<Options>> = {}) {
this.config = {
...this.config,
...config,
@ -219,33 +220,26 @@ export class Extension<Options = any> {
this.options = this.config.defaultOptions
}
static create<O>(config: ExtensionConfig<O>) {
static create<O>(config: Partial<ExtensionConfig<O>> = {}) {
return new Extension<O>(config)
}
configure(options: Partial<Options> = {}) {
return Extension
.create<Options>(this.config as ExtensionConfig<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<ExtensionConfig<ExtendedOptions>> = {}) {
const extension = new Extension<ExtendedOptions>({
// ...this.config,
...extendedConfig,
} as ExtensionConfig<ExtendedOptions>)
const extension = new Extension<ExtendedOptions>(extendedConfig)
// extension.parentConfig = this.config
extension.parent = this
this.child = extension
extension.options = {
...(this.config.defaultOptions ?? {}),
...(extendedConfig.defaultOptions ?? {}),
...extension.parent.options,
...extension.options,
}
return extension

View File

@ -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
}

View File

@ -42,7 +42,7 @@ declare module '@tiptap/core' {
*/
addGlobalAttributes?: (this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['addGlobalAttributes'],
}) => GlobalAttributes | {},
/**
@ -52,7 +52,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['addCommands'],
}) => Partial<RawCommands>,
/**
@ -62,7 +62,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['addKeyboardShortcuts'],
}) => {
[key: string]: ProseMirrorCommand,
},
@ -74,7 +74,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['addInputRules'],
}) => InputRule[],
/**
@ -84,7 +84,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['addPasteRules'],
}) => Plugin[],
/**
@ -94,7 +94,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['addProseMirrorPlugins'],
}) => Plugin[],
/**
@ -103,7 +103,7 @@ declare module '@tiptap/core' {
extendNodeSchema?: ((
this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['extendNodeSchema'],
},
extension: Node,
) => {
@ -116,7 +116,7 @@ declare module '@tiptap/core' {
extendMarkSchema?: ((
this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['extendMarkSchema'],
},
extension: Node,
) => {
@ -130,7 +130,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['onBeforeCreate'],
}) => void) | null,
/**
@ -140,7 +140,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['onCreate'],
}) => void) | null,
/**
@ -150,7 +150,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['onUpdate'],
}) => void) | null,
/**
@ -160,7 +160,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['onSelectionUpdate'],
}) => void) | null,
/**
@ -171,7 +171,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['onTransaction'],
},
props: {
transaction: Transaction,
@ -186,7 +186,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['onFocus'],
},
props: {
event: FocusEvent,
@ -201,7 +201,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['onBlur'],
},
props: {
event: FocusEvent,
@ -215,7 +215,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['onDestroy'],
}) => void) | null,
/**
@ -225,7 +225,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['addNodeView'],
}) => NodeViewRenderer) | null,
/**
@ -238,7 +238,7 @@ declare module '@tiptap/core' {
*/
content?: NodeSpec['content'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['content'],
}) => NodeSpec['content']),
/**
@ -246,7 +246,7 @@ declare module '@tiptap/core' {
*/
marks?: NodeSpec['marks'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['marks'],
}) => NodeSpec['marks']),
/**
@ -254,7 +254,7 @@ declare module '@tiptap/core' {
*/
group?: NodeSpec['group'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['group'],
}) => NodeSpec['group']),
/**
@ -262,7 +262,7 @@ declare module '@tiptap/core' {
*/
inline?: NodeSpec['inline'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['inline'],
}) => NodeSpec['inline']),
/**
@ -270,7 +270,7 @@ declare module '@tiptap/core' {
*/
atom?: NodeSpec['atom'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['atom'],
}) => NodeSpec['atom']),
/**
@ -278,7 +278,7 @@ declare module '@tiptap/core' {
*/
selectable?: NodeSpec['selectable'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['selectable'],
}) => NodeSpec['selectable']),
/**
@ -286,7 +286,7 @@ declare module '@tiptap/core' {
*/
draggable?: NodeSpec['draggable'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['draggable'],
}) => NodeSpec['draggable']),
/**
@ -294,7 +294,7 @@ declare module '@tiptap/core' {
*/
code?: NodeSpec['code'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['code'],
}) => NodeSpec['code']),
/**
@ -302,7 +302,7 @@ declare module '@tiptap/core' {
*/
defining?: NodeSpec['defining'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['defining'],
}) => NodeSpec['defining']),
/**
@ -310,7 +310,7 @@ declare module '@tiptap/core' {
*/
isolating?: NodeSpec['isolating'] | ((this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['isolating'],
}) => NodeSpec['isolating']),
/**
@ -319,7 +319,7 @@ declare module '@tiptap/core' {
parseHTML?: (
this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['parseHTML'],
},
) => NodeSpec['parseDOM'],
@ -329,7 +329,7 @@ declare module '@tiptap/core' {
renderHTML?: ((
this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['renderHTML'],
},
props: {
node: ProseMirrorNode,
@ -345,7 +345,7 @@ declare module '@tiptap/core' {
options: Options,
editor: Editor,
type: NodeType,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['renderText'],
},
props: {
node: ProseMirrorNode,
@ -358,7 +358,7 @@ declare module '@tiptap/core' {
addAttributes?: (
this: {
options: Options,
parentConfig: ParentConfig<NodeConfig<Options>>,
parent: ParentConfig<NodeConfig<Options>>['addAttributes'],
},
) => Attributes | {},
}
@ -373,12 +373,13 @@ export class Node<Options = any> {
defaultOptions: {},
}
// parentConfig: Partial<NodeConfig> = {}
parent: any
options: Options
options!: Options
parent: Node | null = null
constructor(config: NodeConfig<Options>) {
child: Node | null = null
constructor(config: Partial<NodeConfig<Options>> = {}) {
this.config = {
...this.config,
...config,
@ -387,30 +388,27 @@ export class Node<Options = any> {
this.options = this.config.defaultOptions
}
static create<O>(config: NodeConfig<O>) {
static create<O>(config: Partial<NodeConfig<O>> = {}) {
return new Node<O>(config)
}
configure(options: Partial<Options> = {}) {
return Node
.create<Options>(this.config as NodeConfig<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<NodeConfig<ExtendedOptions>>) {
const extension = new Node<ExtendedOptions>({
...this.config,
...extendedConfig,
} as NodeConfig<ExtendedOptions>)
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>> = {}) {
const extension = new Node<ExtendedOptions>(extendedConfig)
extension.parent = this
// extension.parentConfig = this.config
this.child = extension
extension.options = {
...extension.parent.options,
...extension.options,
}
return extension
}