From 410401ddbd5f378854f81dd38eb60ed3cab02658 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Fri, 24 May 2024 10:33:00 +0200 Subject: [PATCH] fix: resolve Issue #4704 by reverting PR #4191 --- .../CodeBlockLanguage/React/index.jsx | 15 ++++++- packages/core/src/Extension.ts | 16 +++----- packages/core/src/ExtensionManager.ts | 2 +- packages/core/src/Mark.ts | 36 +++------------- packages/core/src/Node.ts | 41 ++++--------------- .../helpers/getSchemaByResolvedExtensions.ts | 1 + 6 files changed, 35 insertions(+), 76 deletions(-) diff --git a/demos/src/Examples/CodeBlockLanguage/React/index.jsx b/demos/src/Examples/CodeBlockLanguage/React/index.jsx index cdb1d35de4a..b85202fb641 100644 --- a/demos/src/Examples/CodeBlockLanguage/React/index.jsx +++ b/demos/src/Examples/CodeBlockLanguage/React/index.jsx @@ -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: `

diff --git a/packages/core/src/Extension.ts b/packages/core/src/Extension.ts index 966121318ab..1b294c83775 100644 --- a/packages/core/src/Extension.ts +++ b/packages/core/src/Extension.ts @@ -20,7 +20,7 @@ import { mergeDeep } from './utilities/mergeDeep.js' declare module '@tiptap/core' { interface ExtensionConfig { - // @ts-ignore - this is a dynamic key + // @ts-ignore allow index signature [key: string]: any /** @@ -457,17 +457,13 @@ export class Extension { configure(options: Partial = {}) { // 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, options) as Options - - extension.storage = callOrReturn( - getExtensionField(extension, 'addStorage', { - name: extension.name, - options: extension.options, - }), - ) return extension } diff --git a/packages/core/src/ExtensionManager.ts b/packages/core/src/ExtensionManager.ts index 54ccbdc372f..e222430a9dd 100644 --- a/packages/core/src/ExtensionManager.ts +++ b/packages/core/src/ExtensionManager.ts @@ -181,7 +181,7 @@ export class ExtensionManager { let defaultBindings: Record boolean> = {} // bind exit handling - if (extension.type === 'mark' && extension.config.exitable) { + if (extension.type === 'mark' && getExtensionField(extension, 'exitable')) { defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension as Mark }) } diff --git a/packages/core/src/Mark.ts b/packages/core/src/Mark.ts index 9ec52977412..da15600bf79 100644 --- a/packages/core/src/Mark.ts +++ b/packages/core/src/Mark.ts @@ -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, @@ -23,7 +22,7 @@ import { mergeDeep } from './utilities/mergeDeep.js' declare module '@tiptap/core' { export interface MarkConfig { - // @ts-ignore - this is a dynamic key + // @ts-ignore allow index signature [key: string]: any /** @@ -238,28 +237,6 @@ declare module '@tiptap/core' { parent: ParentConfig>['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>['extendNodeSchema'] - }, - extension: Node, - ) => Record) - | null - /** * This function extends the schema of the mark. * @example @@ -591,7 +568,6 @@ export class Mark { // with different calls of `configure` const extension = this.extend() - extension.parent = this.parent extension.options = mergeDeep(this.options as Record, options) as Options extension.storage = callOrReturn( @@ -607,7 +583,7 @@ export class Mark { extend( extendedConfig: Partial> = {}, ) { - const extension = new Mark({ ...this.config, ...extendedConfig }) + const extension = new Mark(extendedConfig) extension.parent = this @@ -621,18 +597,18 @@ export class Mark { ) } - extension.options = callOrReturn( + extension.options = mergeDeep(this.options as Record, callOrReturn( getExtensionField(extension, 'addOptions', { name: extension.name, }), - ) + )) as ExtendedOptions - extension.storage = callOrReturn( + extension.storage = mergeDeep(this.storage as Record, callOrReturn( getExtensionField(extension, 'addStorage', { name: extension.name, options: extension.options, }), - ) + )) as ExtendedStorage return extension } diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index b1c8c8f44af..46e46ace8ad 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -24,7 +24,7 @@ import { mergeDeep } from './utilities/mergeDeep.js' declare module '@tiptap/core' { interface NodeConfig { - // @ts-ignore - this is a dynamic key + // @ts-ignore allow index signature [key: string]: any /** @@ -261,29 +261,6 @@ declare module '@tiptap/core' { ) => Record) | 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>['extendMarkSchema'] - editor?: Editor - }, - extension: Node, - ) => Record) - | null - /** * The editor is not ready yet. */ @@ -780,17 +757,13 @@ export class Node { configure(options: Partial = {}) { // 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, options) as Options - - extension.storage = callOrReturn( - getExtensionField(extension, 'addStorage', { - name: extension.name, - options: extension.options, - }), - ) return extension } @@ -798,7 +771,7 @@ export class Node { extend( extendedConfig: Partial> = {}, ) { - const extension = new Node({ ...this.config, ...extendedConfig }) + const extension = new Node(extendedConfig) extension.parent = this diff --git a/packages/core/src/helpers/getSchemaByResolvedExtensions.ts b/packages/core/src/helpers/getSchemaByResolvedExtensions.ts index d896192475e..25b856140f3 100644 --- a/packages/core/src/helpers/getSchemaByResolvedExtensions.ts +++ b/packages/core/src/helpers/getSchemaByResolvedExtensions.ts @@ -77,6 +77,7 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E getExtensionField(extension, 'draggable', context), ), code: callOrReturn(getExtensionField(extension, 'code', context)), + whitespace: callOrReturn(getExtensionField(extension, 'whitespace', context)), defining: callOrReturn( getExtensionField(extension, 'defining', context), ),