mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
fix(core): configuring extensions should add to the parent's options not replace them (#5357)
* fix(core): configuring extensions should add to the parent's options not replace them * fix: order of tests
This commit is contained in:
parent
a21a122759
commit
07f4c03315
5
.changeset/clean-bugs-rush.md
Normal file
5
.changeset/clean-bugs-rush.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/core": patch
|
||||
---
|
||||
|
||||
There was a bug where doing a `.configure` on an extension, node or mark would overwrite the extensions options instead of being merged with the default options.
|
@ -459,8 +459,8 @@ export class Extension<Options = any, Storage = any> {
|
||||
// with different calls of `configure`
|
||||
const extension = this.extend({
|
||||
...this.config,
|
||||
addOptions() {
|
||||
return mergeDeep(this.parent?.() || {}, options) as Options
|
||||
addOptions: () => {
|
||||
return mergeDeep(this.options as Record<string, any>, options) as Options
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -591,8 +591,8 @@ export class Mark<Options = any, Storage = any> {
|
||||
// with different calls of `configure`
|
||||
const extension = this.extend({
|
||||
...this.config,
|
||||
addOptions() {
|
||||
return mergeDeep(this.parent?.() || {}, options) as Options
|
||||
addOptions: () => {
|
||||
return mergeDeep(this.options as Record<string, any>, options) as Options
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -782,8 +782,8 @@ export class Node<Options = any, Storage = any> {
|
||||
// with different calls of `configure`
|
||||
const extension = this.extend({
|
||||
...this.config,
|
||||
addOptions() {
|
||||
return mergeDeep(this.parent?.() || {}, options) as Options
|
||||
addOptions: () => {
|
||||
return mergeDeep(this.options as Record<string, any>, options) as Options
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -393,26 +393,47 @@ describe('extend extensions', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should configure to be in addition to the parent options', () => {
|
||||
const parentExtension = Extendable
|
||||
.create({
|
||||
name: 'parentExtension',
|
||||
addOptions() {
|
||||
return { parent: 'exists', overwrite: 'parent' }
|
||||
},
|
||||
})
|
||||
|
||||
const childExtension = parentExtension
|
||||
.configure({ child: 'exists-too', overwrite: 'child' })
|
||||
|
||||
expect(childExtension.options).to.deep.eq({
|
||||
parent: 'exists',
|
||||
child: 'exists-too',
|
||||
overwrite: 'child',
|
||||
})
|
||||
})
|
||||
|
||||
it('should deeply merge options when extending a configured extension', () => {
|
||||
const parentExtension = Extendable
|
||||
.create({
|
||||
name: 'parentExtension',
|
||||
addOptions() {
|
||||
return { defaultOptions: 'is-overwritten' }
|
||||
return { defaultOptions: 'exists', overwrite: 'parent' }
|
||||
},
|
||||
})
|
||||
|
||||
const childExtension = parentExtension
|
||||
.configure({ configuredOptions: 'exists-too' }).extend({
|
||||
.configure({ configuredOptions: 'exists-too', overwrite: 'configure' }).extend({
|
||||
name: 'childExtension',
|
||||
addOptions() {
|
||||
return { ...this.parent?.(), additionalOptions: 'exist-too' }
|
||||
return { ...this.parent?.(), additionalOptions: 'exist-too', overwrite: 'child' }
|
||||
},
|
||||
})
|
||||
|
||||
expect(childExtension.options).to.deep.eq({
|
||||
defaultOptions: 'exists',
|
||||
configuredOptions: 'exists-too',
|
||||
additionalOptions: 'exist-too',
|
||||
overwrite: 'child',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user