slate v0.47.0 Release Notes
Release Date: 2019-05-08 // almost 5 years ago-
NEW
Introducing the
Annotation
model. This is very similar to what used to be stored invalue.decorations
, except they also contain a unique "key" to be identified by. They can be used for things like comments, suggestions, collaborative cursors, etc.{ object: 'annotation', key: String, type: String, data: Map, anchor: Point, focus: Point, }
There are three new
*_annotation
operations. The set of operations now includesadd_annotation
,remove_annotation
andset_annotation
. They are similar to the existing*_mark
operations.Introducing "iterable" model methods. This introduces several iteratable-producing methods on the
Element
interface, whichDocument
,Block
andInline
all implement. There are iterables for traversing the entire tree:element.blocks(options) element.descendants(options) element.inlines(options) element.texts(options) element.ancestors(path, options) element.siblings(path, options)
You can use them just like the native JavaScript iterables. For example, you can loop through the text nodes after a specific node:
for (const next of document.texts({ path: start.path })) { const [node, path] = next // do something with the text node or its path }
Or you can traverse all of the "leaf" blocks:
for (const [block] of document.blocks({ onlyLeaves: true })) { // ... }
And because these iterations use native
for/of
loops, you can easilybreak
orreturn
out of the loops directly—a much nicer DX than remembering toreturn false
.BREAKING
The
value.decorations
property is nowvalue.annotations
. Following with the split of decorations into annotations, this property was also renamed. They must now contain uniquekey
properties, as they are stored as aMap
instead of aList
. This allows for much more performant updates.The
Decoration
model no longer has a nestedmark
property. Previously a realMark
object was used as a property on decorations, but now thetype
anddata
properties are first class properties instead.{ object: 'decoration', type: String, data: Map, anchor: Point, focus: Point, }