feat!: Replace defaultOptions with addOptions (#2088)
* add new addOptions option * replace defaultOptions with addOptions for all extensions * replace defaultOptions with addOptions for all demos * replace defaultOptions with addOptions in docs * refactoring * refactoring * drop object support for addOptions * fix optional options * fix tests
This commit is contained in:
@@ -42,13 +42,21 @@ declare module '@tiptap/core' {
|
||||
*/
|
||||
defaultOptions?: Options,
|
||||
|
||||
/**
|
||||
* Default Options
|
||||
*/
|
||||
addOptions?: (this: {
|
||||
name: string,
|
||||
parent: Exclude<ParentConfig<NodeConfig<Options, Storage>>['addOptions'], undefined>,
|
||||
}) => Options,
|
||||
|
||||
/**
|
||||
* Default Storage
|
||||
*/
|
||||
addStorage?: (this: {
|
||||
name: string,
|
||||
options: Options,
|
||||
parent: ParentConfig<NodeConfig<Options, Storage>>['addGlobalAttributes'],
|
||||
parent: Exclude<ParentConfig<NodeConfig<Options, Storage>>['addStorage'], undefined>,
|
||||
}) => Storage,
|
||||
|
||||
/**
|
||||
@@ -472,7 +480,24 @@ export class Node<Options = any, Storage = any> {
|
||||
}
|
||||
|
||||
this.name = this.config.name
|
||||
|
||||
if (config.defaultOptions) {
|
||||
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`)
|
||||
}
|
||||
|
||||
// TODO: remove `addOptions` fallback
|
||||
this.options = this.config.defaultOptions
|
||||
|
||||
if (this.config.addOptions) {
|
||||
this.options = callOrReturn(getExtensionField<AnyConfig['addOptions']>(
|
||||
this,
|
||||
'addOptions',
|
||||
{
|
||||
name: this.name,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
this.storage = callOrReturn(getExtensionField<AnyConfig['addStorage']>(
|
||||
this,
|
||||
'addStorage',
|
||||
@@ -480,7 +505,7 @@ export class Node<Options = any, Storage = any> {
|
||||
name: this.name,
|
||||
options: this.options,
|
||||
},
|
||||
))
|
||||
)) || {}
|
||||
}
|
||||
|
||||
static create<O = any, S = any>(config: Partial<NodeConfig<O, S>> = {}) {
|
||||
@@ -517,10 +542,25 @@ export class Node<Options = any, Storage = any> {
|
||||
? extendedConfig.name
|
||||
: extension.parent.name
|
||||
|
||||
if (extendedConfig.defaultOptions) {
|
||||
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`)
|
||||
}
|
||||
|
||||
// TODO: remove `addOptions` fallback
|
||||
extension.options = extendedConfig.defaultOptions
|
||||
? extendedConfig.defaultOptions
|
||||
: extension.parent.options
|
||||
|
||||
if (extendedConfig.addOptions) {
|
||||
extension.options = callOrReturn(getExtensionField<AnyConfig['addOptions']>(
|
||||
extension,
|
||||
'addOptions',
|
||||
{
|
||||
name: extension.name,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
extension.storage = callOrReturn(getExtensionField<AnyConfig['addStorage']>(
|
||||
extension,
|
||||
'addStorage',
|
||||
|
||||
Reference in New Issue
Block a user