mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 01:50:06 +02:00
fix to always default operation.data to an object
This commit is contained in:
@@ -126,6 +126,11 @@ class Operation extends Record(DEFAULTS) {
|
|||||||
for (const key of ATTRIBUTES) {
|
for (const key of ATTRIBUTES) {
|
||||||
let v = object[key]
|
let v = object[key]
|
||||||
|
|
||||||
|
// Default `data` to an empty object.
|
||||||
|
if (key === 'data' && v === undefined) {
|
||||||
|
v = {}
|
||||||
|
}
|
||||||
|
|
||||||
if (v === undefined) {
|
if (v === undefined) {
|
||||||
// Skip keys for objects that should not be serialized, and are only used
|
// Skip keys for objects that should not be serialized, and are only used
|
||||||
// for providing the local-only invert behavior for the history stack.
|
// for providing the local-only invert behavior for the history stack.
|
||||||
@@ -134,9 +139,6 @@ class Operation extends Record(DEFAULTS) {
|
|||||||
if (key == 'value') continue
|
if (key == 'value') continue
|
||||||
if (key == 'node' && type != 'insert_node') continue
|
if (key == 'node' && type != 'insert_node') continue
|
||||||
|
|
||||||
// Skip optional user defined data
|
|
||||||
if (key == 'data') continue
|
|
||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`\`Operation.fromJSON\` was passed a "${type}" operation without the required "${key}" attribute.`
|
`\`Operation.fromJSON\` was passed a "${type}" operation without the required "${key}" attribute.`
|
||||||
)
|
)
|
||||||
@@ -311,7 +313,7 @@ class Operation extends Record(DEFAULTS) {
|
|||||||
value = v
|
value = v
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key === 'data' && value) {
|
if (key === 'data') {
|
||||||
value = value.toJSON()
|
value = value.toJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,5 +23,5 @@ export const output = {
|
|||||||
object: 'mark',
|
object: 'mark',
|
||||||
type: 'b',
|
type: 'b',
|
||||||
},
|
},
|
||||||
data: undefined,
|
data: {},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user