mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
This commit is contained in:
parent
cac2da16c4
commit
97ea55fe4c
5
.changeset/chatty-pumas-cross.md
Normal file
5
.changeset/chatty-pumas-cross.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/core": minor
|
||||
---
|
||||
|
||||
Fixes #5490. The `preventClearDocument` meta tag can now be used to prevent the `clearDocument` plugin in the core keymap extension from modifying transactions that appear to clear the document (but might be clearing it for other reasons).
|
5
.changeset/rich-waves-study.md
Normal file
5
.changeset/rich-waves-study.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/core": minor
|
||||
---
|
||||
|
||||
An object can now be passed to `enableCoreExtensions` to allow disabling only specific core extensions.
|
@ -261,7 +261,12 @@ export class Editor extends EventEmitter<EditorEvents> {
|
||||
FocusEvents,
|
||||
Keymap,
|
||||
Tabindex,
|
||||
] : []
|
||||
].filter(ext => {
|
||||
if (typeof this.options.enableCoreExtensions === 'object') {
|
||||
return this.options.enableCoreExtensions[ext.name as keyof typeof this.options.enableCoreExtensions] !== false
|
||||
}
|
||||
return true
|
||||
}) : []
|
||||
const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => {
|
||||
return ['extension', 'node', 'mark'].includes(extension?.type)
|
||||
})
|
||||
|
@ -3,6 +3,7 @@ import { Plugin, PluginKey, Selection } from '@tiptap/pm/state'
|
||||
import { CommandManager } from '../CommandManager.js'
|
||||
import { Extension } from '../Extension.js'
|
||||
import { createChainableState } from '../helpers/createChainableState.js'
|
||||
import { isNodeEmpty } from '../helpers/isNodeEmpty.js'
|
||||
import { isiOS } from '../utilities/isiOS.js'
|
||||
import { isMacOS } from '../utilities/isMacOS.js'
|
||||
|
||||
@ -106,7 +107,9 @@ export const Keymap = Extension.create({
|
||||
const docChanges = transactions.some(transaction => transaction.docChanged)
|
||||
&& !oldState.doc.eq(newState.doc)
|
||||
|
||||
if (!docChanges) {
|
||||
const ignoreTr = transactions.some(transaction => transaction.getMeta('preventClearDocument'))
|
||||
|
||||
if (!docChanges || ignoreTr) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -119,7 +122,7 @@ export const Keymap = Extension.create({
|
||||
return
|
||||
}
|
||||
|
||||
const isEmpty = newState.doc.textBetween(0, newState.doc.content.size, ' ', ' ').length === 0
|
||||
const isEmpty = isNodeEmpty(newState.doc)
|
||||
|
||||
if (!isEmpty) {
|
||||
return
|
||||
|
@ -83,7 +83,24 @@ export interface EditorOptions {
|
||||
};
|
||||
enableInputRules: EnableRules;
|
||||
enablePasteRules: EnableRules;
|
||||
enableCoreExtensions: boolean;
|
||||
/**
|
||||
* Determines whether core extensions are enabled.
|
||||
*
|
||||
* If set to `false`, all core extensions will be disabled.
|
||||
* To disable specific core extensions, provide an object where the keys are the extension names and the values are `false`.
|
||||
* Extensions not listed in the object will remain enabled.
|
||||
*
|
||||
* @example
|
||||
* // Disable all core extensions
|
||||
* enabledCoreExtensions: false
|
||||
*
|
||||
* @example
|
||||
* // Disable only the keymap core extension
|
||||
* enabledCoreExtensions: { keymap: false }
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
enableCoreExtensions: boolean | Record<'editable' | 'clipboardTextSerializer' | 'commands' | 'focusEvents' | 'keymap' | 'tabindex', false>;
|
||||
/**
|
||||
* If `true`, the editor will check the content for errors on initialization.
|
||||
* Emitting the `contentError` event if the content is invalid.
|
||||
|
Loading…
Reference in New Issue
Block a user