Skip to content

Commit

Permalink
fix: remove defaultOptions fallback, fix #2219
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kühn authored and Philipp Kühn committed Dec 2, 2021
1 parent 2705439 commit 20b6d79
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 190 deletions.
21 changes: 7 additions & 14 deletions packages/core/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 7 additions & 14 deletions packages/core/src/Mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 7 additions & 14 deletions packages/core/src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
148 changes: 0 additions & 148 deletions tests/cypress/integration/core/extensionOptions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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() {
Expand All @@ -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({
Expand All @@ -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<{
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 20b6d79

Please sign in to comment.