mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 20:24:01 +02:00
Generic return type for Node.fragment
(#5926)
This commit is contained in:
5
.changeset/pretty-cobras-sleep.md
Normal file
5
.changeset/pretty-cobras-sleep.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate': patch
|
||||
---
|
||||
|
||||
Use generics for the return type of `Node.fragment`
|
@@ -127,7 +127,10 @@ export interface NodeInterface {
|
||||
/**
|
||||
* Get the sliced fragment represented by a range inside a root node.
|
||||
*/
|
||||
fragment: (root: Node, range: Range) => Descendant[]
|
||||
fragment: <T extends Ancestor = Editor>(
|
||||
root: T,
|
||||
range: Range
|
||||
) => T['children']
|
||||
|
||||
/**
|
||||
* Get the descendant node referred to by a specific path. If the path is an
|
||||
@@ -353,15 +356,7 @@ export const Node: NodeInterface = {
|
||||
return [n, p]
|
||||
},
|
||||
|
||||
fragment(root: Node, range: Range): Descendant[] {
|
||||
if (Text.isText(root)) {
|
||||
throw new Error(
|
||||
`Cannot get a fragment starting from a root text node: ${Scrubber.stringify(
|
||||
root
|
||||
)}`
|
||||
)
|
||||
}
|
||||
|
||||
fragment<T extends Ancestor = Editor>(root: T, range: Range): T['children'] {
|
||||
const newRoot = produce({ children: root.children }, r => {
|
||||
const [start, end] = Range.edges(range)
|
||||
const nodeEntries = Node.nodes(r, {
|
||||
|
Reference in New Issue
Block a user