0.3.0 - Simplified API for matchers
Pre-release
Pre-release
Update
- Matchers API is simplified: No need to pass
LeafProps
orElementProps
. 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 fromElementProps
attributes, as it's unnecessary forslate-to-react
;LeafProps
andElementProps
no longer available for public usage, as they not necessary for matchers anymore.
All changes: v0.2.1...v0.3.0