Skip to content

Commit

Permalink
fix: resolve Issue #4704 by reverting PR #4191
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 committed Jun 18, 2024
1 parent 9ca6b65 commit 410401d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 76 deletions.
15 changes: 14 additions & 1 deletion demos/src/Examples/CodeBlockLanguage/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,21 @@ export default () => {
addNodeView() {
return ReactNodeViewRenderer(CodeBlockComponent)
},
// addProseMirrorPlugins() {
// console.log('custom', this, this.parent)
// return [
// ...this.parent(),
// ]
// },
})
.configure({ lowlight }),
.configure({ lowlight })
.extend({
addProseMirrorPlugins() {
return [
...this.parent(),
]
},
}),
],
content: `
<p>
Expand Down
16 changes: 6 additions & 10 deletions packages/core/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { mergeDeep } from './utilities/mergeDeep.js'

declare module '@tiptap/core' {
interface ExtensionConfig<Options = any, Storage = any> {
// @ts-ignore - this is a dynamic key
// @ts-ignore allow index signature
[key: string]: any

/**
Expand Down Expand Up @@ -457,17 +457,13 @@ 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({
addOptions() {
return mergeDeep(this.parent?.() || {}, options) as Options
},
})

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 Down
2 changes: 1 addition & 1 deletion packages/core/src/ExtensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class ExtensionManager {
let defaultBindings: Record<string, () => boolean> = {}

// bind exit handling
if (extension.type === 'mark' && extension.config.exitable) {
if (extension.type === 'mark' && getExtensionField<AnyConfig['exitable']>(extension, 'exitable')) {
defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension as Mark })
}

Expand Down
36 changes: 6 additions & 30 deletions packages/core/src/Mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Editor } from './Editor.js'
import { getExtensionField } from './helpers/getExtensionField.js'
import { MarkConfig } from './index.js'
import { InputRule } from './InputRule.js'
import { Node } from './Node.js'
import { PasteRule } from './PasteRule.js'
import {
AnyConfig,
Expand All @@ -23,7 +22,7 @@ import { mergeDeep } from './utilities/mergeDeep.js'

declare module '@tiptap/core' {
export interface MarkConfig<Options = any, Storage = any> {
// @ts-ignore - this is a dynamic key
// @ts-ignore allow index signature
[key: string]: any

/**
Expand Down Expand Up @@ -238,28 +237,6 @@ declare module '@tiptap/core' {
parent: ParentConfig<MarkConfig<Options, Storage>>['addExtensions']
}) => Extensions

/**
* This function extends the schema of the node.
* @example
* extendNodeSchema() {
* return {
* group: 'inline',
* selectable: false,
* }
* }
*/
extendNodeSchema?:
| ((
this: {
name: string
options: Options
storage: Storage
parent: ParentConfig<MarkConfig<Options, Storage>>['extendNodeSchema']
},
extension: Node,
) => Record<string, any>)
| null

/**
* This function extends the schema of the mark.
* @example
Expand Down Expand Up @@ -591,7 +568,6 @@ export class Mark<Options = any, Storage = any> {
// with different calls of `configure`
const extension = this.extend()

extension.parent = this.parent
extension.options = mergeDeep(this.options as Record<string, any>, options) as Options

extension.storage = callOrReturn(
Expand All @@ -607,7 +583,7 @@ export class Mark<Options = any, Storage = any> {
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

Expand All @@ -621,18 +597,18 @@ export class Mark<Options = any, Storage = any> {
)
}

extension.options = callOrReturn(
extension.options = mergeDeep(this.options as Record<string, any>, callOrReturn(
getExtensionField<AnyConfig['addOptions']>(extension, 'addOptions', {
name: extension.name,
}),
)
)) as ExtendedOptions

extension.storage = callOrReturn(
extension.storage = mergeDeep(this.storage as Record<string, any>, callOrReturn(
getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
name: extension.name,
options: extension.options,
}),
)
)) as ExtendedStorage

return extension
}
Expand Down
41 changes: 7 additions & 34 deletions packages/core/src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { mergeDeep } from './utilities/mergeDeep.js'

declare module '@tiptap/core' {
interface NodeConfig<Options = any, Storage = any> {
// @ts-ignore - this is a dynamic key
// @ts-ignore allow index signature
[key: string]: any

/**
Expand Down Expand Up @@ -261,29 +261,6 @@ declare module '@tiptap/core' {
) => Record<string, any>)
| null

/**
* This function extends the schema of the mark.
* @example
* extendMarkSchema() {
* return {
* group: 'inline',
* selectable: false,
* }
* }
*/
extendMarkSchema?:
| ((
this: {
name: string
options: Options
storage: Storage
parent: ParentConfig<NodeConfig<Options, Storage>>['extendMarkSchema']
editor?: Editor
},
extension: Node,
) => Record<string, any>)
| null

/**
* The editor is not ready yet.
*/
Expand Down Expand Up @@ -780,25 +757,21 @@ 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()
const extension = this.extend({
addOptions() {
return mergeDeep(this.parent?.() || {}, options) as Options
},
})

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
}

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

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/helpers/getSchemaByResolvedExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E
getExtensionField<NodeConfig['draggable']>(extension, 'draggable', context),
),
code: callOrReturn(getExtensionField<NodeConfig['code']>(extension, 'code', context)),
whitespace: callOrReturn(getExtensionField<NodeConfig['whitespace']>(extension, 'whitespace', context)),
defining: callOrReturn(
getExtensionField<NodeConfig['defining']>(extension, 'defining', context),
),
Expand Down

0 comments on commit 410401d

Please sign in to comment.