diff --git a/.changeset/large-cars-itch.md b/.changeset/large-cars-itch.md new file mode 100644 index 000000000..059ffdc2c --- /dev/null +++ b/.changeset/large-cars-itch.md @@ -0,0 +1,5 @@ +--- +'slate': patch +--- + +Keep data in normalization when blocks are not allowed diff --git a/packages/slate/src/core/normalize-node.ts b/packages/slate/src/core/normalize-node.ts index 467f96b3b..ba704d9a1 100644 --- a/packages/slate/src/core/normalize-node.ts +++ b/packages/slate/src/core/normalize-node.ts @@ -53,7 +53,11 @@ export const normalizeNode: WithEditorFirstArg = ( // other inline nodes, or parent blocks that only contain inlines and // text. if (isInlineOrText !== shouldHaveInlines) { - Transforms.removeNodes(editor, { at: path.concat(n), voids: true }) + if (isInlineOrText) { + Transforms.removeNodes(editor, { at: path.concat(n), voids: true }) + } else { + Transforms.unwrapNodes(editor, { at: path.concat(n), voids: true }) + } n-- } else if (Element.isElement(child)) { // Ensure that inline nodes are surrounded by text nodes. diff --git a/packages/slate/test/normalization/block/remove-block.tsx b/packages/slate/test/normalization/block/remove-block.tsx index cc5d1e27d..717ee448d 100644 --- a/packages/slate/test/normalization/block/remove-block.tsx +++ b/packages/slate/test/normalization/block/remove-block.tsx @@ -12,7 +12,7 @@ export const input = ( export const output = ( - one + onetwo ) diff --git a/packages/slate/test/normalization/inline/remove-block.tsx b/packages/slate/test/normalization/inline/remove-block.tsx index ad0e8a622..f2c806442 100644 --- a/packages/slate/test/normalization/inline/remove-block.tsx +++ b/packages/slate/test/normalization/inline/remove-block.tsx @@ -20,7 +20,7 @@ export const output = ( - twofour + onetwothreefour