File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed
packages/slate/src/interfaces Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' slate ' : patch
3+ ---
4+
5+ Use generics for the return type of ` Node.fragment `
Original file line number Diff line number Diff line change @@ -127,7 +127,10 @@ export interface NodeInterface {
127127 /**
128128 * Get the sliced fragment represented by a range inside a root node.
129129 */
130- fragment : ( root : Node , range : Range ) => Descendant [ ]
130+ fragment : < T extends Ancestor = Editor > (
131+ root : T ,
132+ range : Range
133+ ) => T [ 'children' ]
131134
132135 /**
133136 * Get the descendant node referred to by a specific path. If the path is an
@@ -353,15 +356,7 @@ export const Node: NodeInterface = {
353356 return [ n , p ]
354357 } ,
355358
356- fragment ( root : Node , range : Range ) : Descendant [ ] {
357- if ( Text . isText ( root ) ) {
358- throw new Error (
359- `Cannot get a fragment starting from a root text node: ${ Scrubber . stringify (
360- root
361- ) } `
362- )
363- }
364-
359+ fragment < T extends Ancestor = Editor > ( root : T , range : Range ) : T [ 'children' ] {
365360 const newRoot = produce ( { children : root . children } , r => {
366361 const [ start , end ] = Range . edges ( range )
367362 const nodeEntries = Node . nodes ( r , {
You can’t perform that action at this time.
0 commit comments