mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 17:53:59 +02:00
Don't set null in set_node newProperties when using unsetNodes (#4428)
This commit is contained in:
5
.changeset/spotty-squids-walk.md
Normal file
5
.changeset/spotty-squids-walk.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Don't set `null` in `set_node`'s `newProperties` object when using `Transforms.unsetNodes()`
|
@@ -632,19 +632,23 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let hasChanges = false
|
||||||
|
|
||||||
for (const k in props) {
|
for (const k in props) {
|
||||||
if (k === 'children' || k === 'text') {
|
if (k === 'children' || k === 'text') {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props[k] !== node[k]) {
|
if (props[k] !== node[k]) {
|
||||||
// Omit new properties from the old property list rather than set them to undefined
|
hasChanges = true
|
||||||
|
// Omit new properties from the old properties list
|
||||||
if (node.hasOwnProperty(k)) properties[k] = node[k]
|
if (node.hasOwnProperty(k)) properties[k] = node[k]
|
||||||
newProperties[k] = props[k]
|
// Omit properties that have been removed from the new properties list
|
||||||
|
if (props[k] != null) newProperties[k] = props[k]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(newProperties).length !== 0) {
|
if (hasChanges) {
|
||||||
editor.apply({
|
editor.apply({
|
||||||
type: 'set_node',
|
type: 'set_node',
|
||||||
path,
|
path,
|
||||||
|
@@ -10,6 +10,7 @@ export const input = (
|
|||||||
</editor>
|
</editor>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// this is supported for backwards compatibility only; newProperties should omit removed values.
|
||||||
export const operations = [
|
export const operations = [
|
||||||
{
|
{
|
||||||
type: 'set_node',
|
type: 'set_node',
|
||||||
|
@@ -10,6 +10,7 @@ export const input = (
|
|||||||
</editor>
|
</editor>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// this is supported for backwards compatibility only; newProperties should omit removed values.
|
||||||
export const operations = [
|
export const operations = [
|
||||||
{
|
{
|
||||||
type: 'set_node',
|
type: 'set_node',
|
||||||
|
@@ -0,0 +1,35 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import assert from 'assert'
|
||||||
|
import { Transforms, Text, Editor } from 'slate'
|
||||||
|
import { jsx } from '../..'
|
||||||
|
|
||||||
|
export const run = (editor: Editor) => {
|
||||||
|
Transforms.unsetNodes(editor, 'key', { at: [0] })
|
||||||
|
|
||||||
|
// unsetNodes uses null to remove properties, but that should not
|
||||||
|
// flow through to the operation
|
||||||
|
const [setNode] = editor.operations
|
||||||
|
|
||||||
|
if (setNode.type === 'set_node') {
|
||||||
|
assert.deepStrictEqual(setNode, {
|
||||||
|
type: 'set_node',
|
||||||
|
path: [0],
|
||||||
|
properties: { key: true },
|
||||||
|
newProperties: {},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error('operations:', editor.operations)
|
||||||
|
assert.fail('operation was not a set node')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<block key>word</block>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<block>word</block>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -1,6 +1,6 @@
|
|||||||
/** @jsx jsx */
|
/** @jsx jsx */
|
||||||
import { Transforms, Text } from 'slate'
|
import { Transforms, Text } from 'slate'
|
||||||
import { jsx } from '../../..'
|
import { jsx } from '../..'
|
||||||
|
|
||||||
export const run = editor => {
|
export const run = editor => {
|
||||||
Transforms.unsetNodes(editor, 'key', { match: Text.isText })
|
Transforms.unsetNodes(editor, 'key', { match: Text.isText })
|
Reference in New Issue
Block a user