mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-28 17:39:57 +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) {
|
||||
let v = object[key]
|
||||
|
||||
// Default `data` to an empty object.
|
||||
if (key === 'data' && v === undefined) {
|
||||
v = {}
|
||||
}
|
||||
|
||||
if (v === undefined) {
|
||||
// Skip keys for objects that should not be serialized, and are only used
|
||||
// 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 == 'node' && type != 'insert_node') continue
|
||||
|
||||
// Skip optional user defined data
|
||||
if (key == 'data') continue
|
||||
|
||||
throw new Error(
|
||||
`\`Operation.fromJSON\` was passed a "${type}" operation without the required "${key}" attribute.`
|
||||
)
|
||||
@@ -311,7 +313,7 @@ class Operation extends Record(DEFAULTS) {
|
||||
value = v
|
||||
}
|
||||
|
||||
if (key === 'data' && value) {
|
||||
if (key === 'data') {
|
||||
value = value.toJSON()
|
||||
}
|
||||
|
||||
|
@@ -23,5 +23,5 @@ export const output = {
|
||||
object: 'mark',
|
||||
type: 'b',
|
||||
},
|
||||
data: undefined,
|
||||
data: {},
|
||||
}
|
||||
|
Reference in New Issue
Block a user