mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 03:11:44 +02:00
Implement type predicate for operationCanTransformPath
(#5318)
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
import { Operation } from '..'
|
import {
|
||||||
|
InsertNodeOperation,
|
||||||
|
MergeNodeOperation,
|
||||||
|
MoveNodeOperation,
|
||||||
|
RemoveNodeOperation,
|
||||||
|
SplitNodeOperation,
|
||||||
|
Operation,
|
||||||
|
} from '..'
|
||||||
import { TextDirection } from './types'
|
import { TextDirection } from './types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,7 +48,14 @@ export interface PathInterface {
|
|||||||
isSibling: (path: Path, another: Path) => boolean
|
isSibling: (path: Path, another: Path) => boolean
|
||||||
levels: (path: Path, options?: PathLevelsOptions) => Path[]
|
levels: (path: Path, options?: PathLevelsOptions) => Path[]
|
||||||
next: (path: Path) => Path
|
next: (path: Path) => Path
|
||||||
operationCanTransformPath: (operation: Operation) => boolean
|
operationCanTransformPath: (
|
||||||
|
operation: Operation
|
||||||
|
) => operation is
|
||||||
|
| InsertNodeOperation
|
||||||
|
| RemoveNodeOperation
|
||||||
|
| MergeNodeOperation
|
||||||
|
| SplitNodeOperation
|
||||||
|
| MoveNodeOperation
|
||||||
parent: (path: Path) => Path
|
parent: (path: Path) => Path
|
||||||
previous: (path: Path) => Path
|
previous: (path: Path) => Path
|
||||||
relative: (path: Path, ancestor: Path) => Path
|
relative: (path: Path, ancestor: Path) => Path
|
||||||
@@ -302,7 +316,14 @@ export const Path: PathInterface = {
|
|||||||
* NOTE: This *must* be kept in sync with the implementation of 'transform'
|
* NOTE: This *must* be kept in sync with the implementation of 'transform'
|
||||||
* below
|
* below
|
||||||
*/
|
*/
|
||||||
operationCanTransformPath(operation: Operation): boolean {
|
operationCanTransformPath(
|
||||||
|
operation: Operation
|
||||||
|
): operation is
|
||||||
|
| InsertNodeOperation
|
||||||
|
| RemoveNodeOperation
|
||||||
|
| MergeNodeOperation
|
||||||
|
| SplitNodeOperation
|
||||||
|
| MoveNodeOperation {
|
||||||
switch (operation.type) {
|
switch (operation.type) {
|
||||||
case 'insert_node':
|
case 'insert_node':
|
||||||
case 'remove_node':
|
case 'remove_node':
|
||||||
|
Reference in New Issue
Block a user