1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-01 05:16:10 +01:00

Accept legacy "ranges" additionally to "leaves" (#1990)

* Accept ranges additionally to leaves

For compatibility with older slate JSON documents, additionally to
the new "leaves" property, also accept "ranges" with a deprecation
warning.

* Fix accepting JSON arrays for "ranges" compatibility
This commit is contained in:
Germán Méndez Bravo 2018-07-27 17:13:32 -05:00 committed by Ian Storm Taylor
parent c64c2ff025
commit d01c441f68

View File

@ -86,7 +86,20 @@ class Text extends Record(DEFAULTS) {
}
const { key = KeyUtils.create() } = object
let { leaves = List() } = object
let { leaves } = object
if (!leaves) {
if (object.ranges) {
logger.deprecate(
'slate@0.27.0',
'The `ranges` property of Slate objects has been renamed to `leaves`.'
)
leaves = object.ranges
} else {
leaves = List()
}
}
if (Array.isArray(leaves)) {
leaves = List(leaves.map(x => Leaf.create(x)))