Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply #5147 fix to marks and nodes #5156

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions packages/core/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,17 @@ export class Extension<Options = any, Storage = any> {
configure(options: Partial<Options> = {}) {
// return a new instance so we can use the same extension
// with different calls of `configure`
const extension = this.extend()

const extension = this.extend({
...this.config,
addOptions() {
return mergeDeep(this.parent?.() || {}, options) as Options
},
})

// Always preserve the current name
extension.name = this.name
// Set the parent to be our parent
extension.parent = this.parent
extension.options = mergeDeep(this.options as Record<string, any>, options) as Options

extension.storage = callOrReturn(
getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
name: extension.name,
options: extension.options,
}),
)

return extension
}
Expand All @@ -483,7 +483,7 @@ export class Extension<Options = any, Storage = any> {

extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name

if (extendedConfig.defaultOptions) {
if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
console.warn(
`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
)
Expand Down
23 changes: 12 additions & 11 deletions packages/core/src/Mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,32 +589,33 @@ export class Mark<Options = any, Storage = any> {
configure(options: Partial<Options> = {}) {
// return a new instance so we can use the same extension
// with different calls of `configure`
const extension = this.extend()

extension.options = mergeDeep(this.options as Record<string, any>, options) as Options
const extension = this.extend({
...this.config,
addOptions() {
return mergeDeep(this.parent?.() || {}, options) as Options
},
})

extension.storage = callOrReturn(
getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
name: extension.name,
options: extension.options,
}),
)
// Always preserve the current name
extension.name = this.name
// Set the parent to be our parent
extension.parent = this.parent

return extension
}

extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
extendedConfig: Partial<MarkConfig<ExtendedOptions, ExtendedStorage>> = {},
) {
const extension = new Mark<ExtendedOptions, ExtendedStorage>({ ...this.config, ...extendedConfig })
const extension = new Mark<ExtendedOptions, ExtendedStorage>(extendedConfig)

extension.parent = this

this.child = extension

extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name

if (extendedConfig.defaultOptions) {
if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
console.warn(
`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
)
Expand Down
23 changes: 12 additions & 11 deletions packages/core/src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,32 +780,33 @@ export class Node<Options = any, Storage = any> {
configure(options: Partial<Options> = {}) {
// return a new instance so we can use the same extension
// with different calls of `configure`
const extension = this.extend()

extension.options = mergeDeep(this.options as Record<string, any>, options) as Options
const extension = this.extend({
...this.config,
addOptions() {
return mergeDeep(this.parent?.() || {}, options) as Options
},
})

extension.storage = callOrReturn(
getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
name: extension.name,
options: extension.options,
}),
)
// Always preserve the current name
extension.name = this.name
// Set the parent to be our parent
extension.parent = this.parent

return extension
}

extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
extendedConfig: Partial<NodeConfig<ExtendedOptions, ExtendedStorage>> = {},
) {
const extension = new Node<ExtendedOptions, ExtendedStorage>({ ...this.config, ...extendedConfig })
const extension = new Node<ExtendedOptions, ExtendedStorage>(extendedConfig)

extension.parent = this

this.child = extension

extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name

if (extendedConfig.defaultOptions) {
if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
console.warn(
`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
)
Expand Down
Loading