mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-15 12:44:38 +01:00
parent
cd0e577023
commit
e14d8b18d0
@ -179,16 +179,15 @@ class Block extends Record(DEFAULTS) {
|
||||
|
||||
toJSON(options = {}) {
|
||||
const object = {
|
||||
data: this.data.toJSON(),
|
||||
key: this.key,
|
||||
kind: this.kind,
|
||||
isVoid: this.isVoid,
|
||||
type: this.type,
|
||||
isVoid: this.isVoid,
|
||||
data: this.data.toJSON(),
|
||||
nodes: this.nodes.toArray().map(n => n.toJSON(options)),
|
||||
}
|
||||
|
||||
if (!options.preserveKeys) {
|
||||
delete object.key
|
||||
if (options.preserveKeys) {
|
||||
object.key = this.key
|
||||
}
|
||||
|
||||
return object
|
||||
|
@ -148,8 +148,8 @@ class Character extends Record(DEFAULTS) {
|
||||
toJSON() {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
marks: this.marks.toArray().map(m => m.toJSON()),
|
||||
text: this.text,
|
||||
marks: this.marks.toArray().map(m => m.toJSON()),
|
||||
}
|
||||
|
||||
return object
|
||||
|
@ -143,14 +143,13 @@ class Document extends Record(DEFAULTS) {
|
||||
|
||||
toJSON(options = {}) {
|
||||
const object = {
|
||||
data: this.data.toJSON(),
|
||||
key: this.key,
|
||||
kind: this.kind,
|
||||
data: this.data.toJSON(),
|
||||
nodes: this.nodes.toArray().map(n => n.toJSON(options)),
|
||||
}
|
||||
|
||||
if (!options.preserveKeys) {
|
||||
delete object.key
|
||||
if (options.preserveKeys) {
|
||||
object.key = this.key
|
||||
}
|
||||
|
||||
return object
|
||||
|
@ -179,16 +179,15 @@ class Inline extends Record(DEFAULTS) {
|
||||
|
||||
toJSON(options = {}) {
|
||||
const object = {
|
||||
data: this.data.toJSON(),
|
||||
key: this.key,
|
||||
kind: this.kind,
|
||||
isVoid: this.isVoid,
|
||||
type: this.type,
|
||||
isVoid: this.isVoid,
|
||||
data: this.data.toJSON(),
|
||||
nodes: this.nodes.toArray().map(n => n.toJSON(options)),
|
||||
}
|
||||
|
||||
if (!options.preserveKeys) {
|
||||
delete object.key
|
||||
if (options.preserveKeys) {
|
||||
object.key = this.key
|
||||
}
|
||||
|
||||
return object
|
||||
|
@ -152,8 +152,8 @@ class Leaf extends Record(DEFAULTS) {
|
||||
toJSON() {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
marks: this.marks.toArray().map(m => m.toJSON()),
|
||||
text: this.text,
|
||||
marks: this.marks.toArray().map(m => m.toJSON()),
|
||||
}
|
||||
|
||||
return object
|
||||
|
@ -177,9 +177,9 @@ class Mark extends Record(DEFAULTS) {
|
||||
|
||||
toJSON() {
|
||||
const object = {
|
||||
data: this.data.toJSON(),
|
||||
kind: this.kind,
|
||||
type: this.type,
|
||||
data: this.data.toJSON(),
|
||||
}
|
||||
|
||||
return object
|
||||
|
@ -740,13 +740,13 @@ class Range extends Record(DEFAULTS) {
|
||||
|
||||
toJSON() {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
anchorKey: this.anchorKey,
|
||||
anchorOffset: this.anchorOffset,
|
||||
focusKey: this.focusKey,
|
||||
focusOffset: this.focusOffset,
|
||||
isBackward: this.isBackward,
|
||||
isFocused: this.isFocused,
|
||||
kind: this.kind,
|
||||
marks: this.marks == null ? null : this.marks.toArray().map(m => m.toJSON()),
|
||||
}
|
||||
|
||||
|
@ -641,12 +641,7 @@ class State extends Record(DEFAULTS) {
|
||||
toJSON(options = {}) {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
data: this.data.toJSON(),
|
||||
decorations: this.decorations ? this.decorations.toArray().map(d => d.toJSON()) : null,
|
||||
document: this.document.toJSON(options),
|
||||
history: this.history.toJSON(),
|
||||
selection: this.selection.toJSON(),
|
||||
schema: this.schema.toJSON(),
|
||||
}
|
||||
|
||||
if ('preserveStateData' in options) {
|
||||
@ -654,24 +649,24 @@ class State extends Record(DEFAULTS) {
|
||||
options.preserveData = options.preserveStateData
|
||||
}
|
||||
|
||||
if (!options.preserveData) {
|
||||
delete object.data
|
||||
if (options.preserveData) {
|
||||
object.data = this.data.toJSON()
|
||||
}
|
||||
|
||||
if (!options.preserveDecorations) {
|
||||
delete object.decorations
|
||||
if (options.preserveDecorations) {
|
||||
object.decorations = this.decorations ? this.decorations.toArray().map(d => d.toJSON()) : null
|
||||
}
|
||||
|
||||
if (!options.preserveHistory) {
|
||||
delete object.history
|
||||
if (options.preserveHistory) {
|
||||
object.history = this.history.toJSON()
|
||||
}
|
||||
|
||||
if (!options.preserveSelection) {
|
||||
delete object.selection
|
||||
if (options.preserveSelection) {
|
||||
object.selection = this.selection.toJSON()
|
||||
}
|
||||
|
||||
if (!options.preserveSchema) {
|
||||
delete object.schema
|
||||
if (options.preserveSchema) {
|
||||
object.schema = this.schema.toJSON()
|
||||
}
|
||||
|
||||
if (options.preserveSelection && !options.preserveKeys) {
|
||||
|
@ -459,13 +459,12 @@ class Text extends Record(DEFAULTS) {
|
||||
|
||||
toJSON(options = {}) {
|
||||
const object = {
|
||||
key: this.key,
|
||||
kind: this.kind,
|
||||
leaves: this.getLeaves().toArray().map(r => r.toJSON()),
|
||||
}
|
||||
|
||||
if (!options.preserveKeys) {
|
||||
delete object.key
|
||||
if (options.preserveKeys) {
|
||||
object.key = this.key
|
||||
}
|
||||
|
||||
return object
|
||||
|
Loading…
x
Reference in New Issue
Block a user