Skip to content

0.3.0 - Simplified API for matchers

Pre-release
Pre-release

Choose a tag to compare

@octet-stream octet-stream released this 10 Mar 00:45
· 121 commits to main since this release

Update

  • Matchers API is simplified: No need to pass LeafProps or ElementProps. Predicates now should return node type itself:

Before v0.3.0:

import {createLeafNodeMatcher, createElementNodeMatcher} from "slate-to-react"

import type {Node, Replace, LeafProps, ElementProps} from "slate-to-react"
import type {Text} from "slate"

type Link = Replace<Node<"a">, {
  children: Text[]
}>

export const isText = createLeafNodeMatcher<Text>(
  (node): node is LeafProps<Text> => typeof node.leaf.text === "string"
)

export const isLink = createElementNodeMatcher<Link>(
  (node): node is ElementProps<Link> => node.element.type === "a"
    && typeof node.element.url === "string"
)

Since v0.3.0:

import {createLeafNodeMatcher, createElementNodeMatcher} from "slate-to-react"

import type {Node, Replace} from "slate-to-react"
import type {Text} from "slate"

type Link = Replace<Node<"a">, {
  children: Text[]
}>

export const isText = createLeafNodeMatcher<Text>(
  (node): node is Text => typeof node.text === "string"
)

export const isLink = createElementNodeMatcher<Link>(
  (node): node is Link => node.type === "a" && typeof node.url === "string"
)

Remove

  • ref attribute from ElementProps attributes, as it's unnecessary for slate-to-react;
  • LeafProps and ElementProps no longer available for public usage, as they not necessary for matchers anymore.

All changes: v0.2.1...v0.3.0