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 in value.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 includes add_annotation, remove_annotation and set_annotation. They are similar to the existing *_mark operations.

    Introducing "iterable" model methods. This introduces several iteratable-producing methods on the Element interface, which Document, Block and Inline 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 easily break or return out of the loops directly—a much nicer DX than remembering to return false.

    BREAKING

    The value.decorations property is now value.annotations. Following with the split of decorations into annotations, this property was also renamed. They must now contain unique key properties, as they are stored as a Map instead of a List. This allows for much more performant updates.

    The Decoration model no longer has a nested mark property. Previously a real Mark object was used as a property on decorations, but now the type and data properties are first class properties instead.

    {
      object: 'decoration',
      type: String,
      data: Map,
      anchor: Point,
      focus: Point,
    }