Point
A point in a Slate Document
. Points in Slate are inspired by the DOM Range API, with terms like "offset".
Properties
key
key
String
The key of the text node at the point's point.
path
path
List
The path to the text node at the point's point.
object
object
String
A string with a value of 'point'
.
offset
offset
Number
The number of characters from the start of the text node at the point's point.
Computed Properties
isSet
isSet
Boolean
Whether the key, path and offset of a point is not null
.
isUnset
isUnset
Boolean
Whether any of the key, path or offset of a point is null
.
Static Methods
Point.create
Point.create
Point.create(properties: Object|Point) => Point
Create a new Point
with properties
.
Point.createProperties
Point.createProperties
Point.createProperties(object: Object|Point) => Object
Create a new dictionary of point properties from an object
.
Point.fromJSON
Point.fromJSON
Point.fromJSON(object: Object) => Point
Create a point from a JSON object
.
Point.isPoint
Point.isPoint
Point.isPoint(value: Any) => Boolean
Check whether a value
is a Point
.
Instance Methods
toJSON
toJSON
toJSON() => Object
Return a JSON representation of the point.
Checking Methods
isAfterRange
isAfterRange
isAfterRange(range: Range) => Boolean
Determine whether the point is after a range
.
isAtEndOfRange
isAtEndOfRange
isAtEndOfRange(range: Range) => Boolean
Determine whether the point is at the end of a range
.
isAtStartOfRange
isAtStartOfRange
isAtStartOfRange(range: Range) => Boolean
Determine whether the point is at the start of a range
.
isBeforeRange
isBeforeRange
isBeforeRange(range: Range) => Boolean
Determine whether the point is before a range
.
isInRange
isInRange
isInRange(range: Range) => Boolean
Determine whether the point is inside a range
.
isAtEndOfNode
isAtEndOfNode
isAtEndOfNode(node: Node) => Boolean
Determine whether the point is at the end of a node
.
isAtStartOfNode
isAtStartOfNode
isAtStartOfNode(node: Node) => Boolean
Determine whether the point is at the start of a node
.
isInNode
isInNode
isInNode(node: Node) => Boolean
Determine whether a point is inside a node
.
Mutating Methods
moveBackward
moveBackward
moveBackward(n: Number) => Point
Return a new point with its offset moved backwards by n
characters.
moveForward
moveForward
moveForward(n: Number) => Point
Return a new point with its offset moved forwards by n
characters.
moveTo
moveTo
moveTo(path: List, offset: Number) => Point
moveTo(key: String, offset: Number) => Point
moveTo(offset: Number) => Point
Return a new point with its path
, key
and offset
set to new values.
🤖 When using
point.moveTo
, since the point isn't aware of the document, it's possible it will become "unset" if the path or key changes and need to be re-normalized relative to the document usingpoint.normalize(document)
.
moveToEndOfNode
moveToEndOfNode
moveToEndOfNode(node: Node) => Point
Return a new point at the end of a node
.
🤖 This method may need to be followed by
point.normalize(document)
, likemoveTo
.
moveToStartOfNode
moveToStartOfNode
moveToStartOfNode(node: Node) => Point
Return a new point at the start of a node
.
🤖 This method may need to be followed by
point.normalize(document)
, likemoveTo
.
normalize
normalize
normalize(node: Node) => Point
Normalize the point relative to a node
, ensuring that its key and path are in sync, that its offset is valid, and that it references a leaf text node.
setKey
setKey
setKey(key: String|Null) => Point
Return a new point with a new key
.
setOffset
setOffset
setOffset(offset: Number|Null) => Point
Return a new point with a new offset
.
setPath
setPath
setPath(path: List|Array|Null) => Point
Return a new point with a new path
.
unset
unset
unset() => Point
Return a new point with the key, path, and offset all set to null
.
Last updated