fix: remove defaultOptions fallback, fix #2219

This commit is contained in:
Philipp Kühn 2021-12-02 20:04:45 +01:00
parent 270543995c
commit 20b6d79f33
4 changed files with 21 additions and 190 deletions

View File

@ -352,20 +352,13 @@ export class Extension<Options = any, Storage = any> {
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.options = callOrReturn(getExtensionField<AnyConfig['addOptions']>(
extension,
'addOptions',
{
name: extension.name,
},
))
extension.storage = callOrReturn(getExtensionField<AnyConfig['addStorage']>(
extension,

View File

@ -466,20 +466,13 @@ export class Mark<Options = any, Storage = any> {
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.options = callOrReturn(getExtensionField<AnyConfig['addOptions']>(
extension,
'addOptions',
{
name: extension.name,
},
))
extension.storage = callOrReturn(getExtensionField<AnyConfig['addStorage']>(
extension,

View File

@ -546,20 +546,13 @@ export class Node<Options = any, Storage = any> {
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.options = callOrReturn(getExtensionField<AnyConfig['addOptions']>(
extension,
'addOptions',
{
name: extension.name,
},
))
extension.storage = callOrReturn(getExtensionField<AnyConfig['addStorage']>(
extension,

View File

@ -3,20 +3,6 @@
import { Extension } from '@tiptap/core/src/Extension'
describe('extension options', () => {
it('should set options (deprecated)', () => {
const extension = Extension.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
expect(extension.options).to.deep.eq({
foo: 1,
bar: 1,
})
})
it('should set options', () => {
const extension = Extension.create({
addOptions() {
@ -33,23 +19,6 @@ describe('extension options', () => {
})
})
it('should pass through (deprecated)', () => {
const extension = Extension
.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
.extend()
.configure()
expect(extension.options).to.deep.eq({
foo: 1,
bar: 1,
})
})
it('should pass through', () => {
const extension = Extension
.create({
@ -69,24 +38,6 @@ describe('extension options', () => {
})
})
it('should be configurable (deprecated)', () => {
const extension = Extension
.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
.configure({
bar: 2,
})
expect(extension.options).to.deep.eq({
foo: 1,
bar: 2,
})
})
it('should be configurable', () => {
const extension = Extension
.create({
@ -107,28 +58,6 @@ describe('extension options', () => {
})
})
it('should be extendable (deprecated)', () => {
const extension = Extension.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
const newExtension = extension.extend({
defaultOptions: {
...extension.options,
baz: 1,
},
})
expect(newExtension.options).to.deep.eq({
foo: 1,
bar: 1,
baz: 1,
})
})
it('should be extendable', () => {
const extension = Extension.create({
addOptions() {
@ -155,25 +84,6 @@ describe('extension options', () => {
})
})
it('should be overwritable (deprecated)', () => {
const extension = Extension
.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
.extend({
defaultOptions: {
baz: 1,
},
})
expect(extension.options).to.deep.eq({
baz: 1,
})
})
it('should be overwritable', () => {
const extension = Extension
.create({
@ -197,35 +107,6 @@ describe('extension options', () => {
})
})
it('should configure nested objects (deprecated)', () => {
const extension = Extension
.create<{
foo: number[],
HTMLAttributes: Record<string, any>,
}>({
defaultOptions: {
foo: [1, 2, 3],
HTMLAttributes: {
class: 'foo',
},
},
})
.configure({
foo: [1],
HTMLAttributes: {
id: 'bar',
},
})
expect(extension.options).to.deep.eq({
foo: [1],
HTMLAttributes: {
class: 'foo',
id: 'bar',
},
})
})
it('should configure nested objects', () => {
const extension = Extension
.create<{
@ -257,35 +138,6 @@ describe('extension options', () => {
})
})
it('should create its own instance on configure (deprecated)', () => {
const extension = Extension
.create({
defaultOptions: {
foo: 1,
bar: 2,
},
})
const extension1 = extension.configure({
foo: 2,
bar: 4,
})
const extension2 = extension.configure({
foo: 3,
})
expect(extension1.options).to.deep.eq({
foo: 2,
bar: 4,
})
expect(extension2.options).to.deep.eq({
foo: 3,
bar: 2,
})
})
it('should create its own instance on configure', () => {
const extension = Extension
.create({