mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 14:41:23 +02:00
Add way to prevent data loss in normalizeNode
(#5878)
* fix(docs): Consider passed options when overriding normalizeNode * feat: Allow to prevent data-loss on normalizeNode When overriding normalizeNode, you can specify a `wrapperElement` that is used to wrap text & inline nodes which would otherwise be deleted in the normalization path if they are not allowed. * changeset
This commit is contained in:
@@ -145,11 +145,11 @@ const SlateEditor = ({ sharedType, provider }) => {
|
||||
|
||||
// Ensure editor always has at least 1 valid child
|
||||
const { normalizeNode } = e
|
||||
e.normalizeNode = entry => {
|
||||
e.normalizeNode = (entry, options) => {
|
||||
const [node] = entry
|
||||
|
||||
if (!Editor.isEditor(node) || node.children.length > 0) {
|
||||
return normalizeNode(entry)
|
||||
return normalizeNode(entry, options)
|
||||
}
|
||||
|
||||
Transforms.insertNodes(editor, initialValue, { at: [0] })
|
||||
@@ -369,11 +369,11 @@ const SlateEditor = ({ sharedType, provider }) => {
|
||||
|
||||
// Ensure editor always has at least 1 valid child
|
||||
const { normalizeNode } = e
|
||||
e.normalizeNode = entry => {
|
||||
e.normalizeNode = (entry, options) => {
|
||||
const [node] = entry
|
||||
|
||||
if (!Editor.isEditor(node) || node.children.length > 0) {
|
||||
return normalizeNode(entry)
|
||||
return normalizeNode(entry, options)
|
||||
}
|
||||
|
||||
Transforms.insertNodes(editor, initialValue, { at: [0] })
|
||||
|
Reference in New Issue
Block a user