Extends
Constructor
new ve.dm.ElementLinearData(store, [data])
#
Element linear data storage
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
store |
ve.dm.HashValueStore | Hash-value store |
|
data |
Array |
optional |
Linear data |
Methods
batchSplice(offset, remove, data) → {Array}
#
batchSpliceObject(offset, remove, data) → {ve.dm.LinearData}
#
Returns ve.batchSplice of linear data, wrapped in a LinearData object
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | |
remove |
number | |
data |
Array |
- Inherited from:
- Source:
- See:
Returns:
- Type
- ve.dm.LinearData
canTakeAnnotationAtOffset(offset, annotation, [ignoreClose]) → {boolean}
#
Check if an annotation can be applied at a specific offset
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number | ||
annotation |
ve.dm.Annotation | ||
ignoreClose |
boolean |
optional |
Ignore close elements, otherwise check if their open element is annotatable |
Returns:
Annotation can be applied at this offset
- Type
- boolean
cloneElements(preserveGenerated)
#
Run all elements through getClonedElement(). This should be done if you intend to insert the sliced data back into the document as a copy of the original data (e.g. for copy and paste).
Parameters:
Name | Type | Description |
---|---|---|
preserveGenerated |
boolean | Preserve internal.generated properties of elements |
containsElementData() → {boolean}
#
Check for elements in data.
This method assumes that any value that has a type property that's a string is an element object. Elements are discovered by iterating through the entire data array (backwards).
- Inherited from:
- Source:
Returns:
At least one elements exists in data
- Type
- boolean
countNonInternalElements([limit]) → {number}
#
Counts all elements that aren't between internalList and /internalList
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
limit |
number |
optional |
Number of elements after which to stop counting |
Returns:
Number of elements that aren't in an internalList
- Type
- number
forEachRunOfContent(range, callback)
#
Execute a callback function for each group of consecutive content data (text or content element).
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
range |
ve.Range | Range in which to search |
|||||||||
callback |
function | Function called with the following parameters: Properties:
|
getAnnotatedRangeFromOffset(offset, annotation) → {ve.Range|null
}
#
null
}
#
Gets the range of content surrounding a given offset that's covered by a given annotation.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Offset to begin looking forward and backward from |
annotation |
Object | Annotation to test for coverage with |
Returns:
Range of content covered by annotation, or null if offset is not covered
- Type
-
ve.Range
|
null
getAnnotatedRangeFromSelection(range, annotation) → {ve.Range|null
}
#
null
}
#
Get the range of an annotation found within a range.
Parameters:
Name | Type | Description |
---|---|---|
range |
ve.Range | Range to begin looking forward and backward from |
annotation |
ve.dm.Annotation | Annotation to test for coverage with |
Returns:
Range of content covered by annotation, or a copy of the range
- Type
-
ve.Range
|
null
getAnnotationHashesFromOffset(offset, [ignoreClose]) → {Array.<string>}
#
Get annotations' store hashes covered by an offset.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number | Offset to get annotations for |
|
ignoreClose |
boolean |
optional |
Ignore annotations on close elements |
Returns:
An array of annotation store hashes the offset is covered by
- Type
- Array.<string>
Throws:
-
offset out of bounds
- Type
- Error
getAnnotationRanges(range) → {Array.<ve.dm.ElementLinearData.AnnotationRange>}
#
Get contiguous ranges covered by annotations
Parameters:
Name | Type | Description |
---|---|---|
range |
ve.Range | Range to search |
Returns:
Contiguous annotation ranges, ordered by start then end
getAnnotationsFromOffset(offset, [ignoreClose]) → {ve.dm.AnnotationSet}
#
Get annotations covered by an offset.
The returned AnnotationSet is a clone of the one in the data.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number | Offset to get annotations for |
|
ignoreClose |
boolean |
optional |
Ignore annotations on close elements |
Returns:
A set of all annotation objects offset is covered by
- Type
- ve.dm.AnnotationSet
Throws:
-
offset out of bounds
- Type
- Error
getAnnotationsFromRange(range, [all], [nullIfContentEmpty]) → {ve.dm.AnnotationSet|null
}
#
null
}
#
Get annotations common to all content in a range.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
range |
ve.Range | Range to get annotations for |
||
all |
boolean |
optional |
false | Get all annotations found within the range, not just those that cover it |
nullIfContentEmpty |
boolean |
optional |
false | Returns null (instead of an empty |
Returns:
All annotation objects range is covered by.
- Type
-
ve.dm.AnnotationSet
|
null
getCharacterData(offset) → {string}
#
Get character data at a specified offset
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Offset to get character data from |
Returns:
Character data
- Type
- string
getCommonAnnotationArrayLength(range) → {number}
#
Get the length of the common start sequence of annotations that applies to a whole range
Parameters:
Name | Type | Description |
---|---|---|
range |
ve.Range | The document range |
Returns:
Common start sequence length (0 if the range is empty)
- Type
- number
getData([offset]) → {Object|Array}
#
Gets linear data from a specified index, or all data if no index specified
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number |
optional |
Offset to get data from |
- Inherited from:
- Source:
Returns:
Data from index, or all data (by reference)
getDataSlice([range], [deep]) → {Array}
#
Get a slice or copy of the provided data.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
range |
ve.Range |
optional |
Range of data to get, all data will be given by default |
|
deep |
boolean |
optional |
false | Whether to return a deep copy (WARNING! This may be very slow) |
- Inherited from:
- Source:
Returns:
Slice or copy of data
- Type
- Array
getInsertionAnnotationsFromRange(range, [startAfterAnnotations]) → {ve.dm.AnnotationSet}
#
Get the insertion annotations that should apply to a range.
The semantics are intended to match Chromium's behaviour. TODO: This cannot match Firefox behaviour, which depends on the cursor's annotation boundary side, and performs a union of the annotations at each end of the selection; see https://phabricator.wikimedia.org/T113869 T113869} .
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
range |
ve.Range | The range into which text would be inserted |
|
startAfterAnnotations |
boolean |
optional |
Use annotations after cursor if collapsed |
Returns:
The insertion annotations that should apply
- Type
- ve.dm.AnnotationSet
getLength() → {number}
#
Gets length of the linear data
- Inherited from:
- Source:
Returns:
Length of the linear data
- Type
- number
getNearestContentOffset(offset, [direction]) → {number}
#
Get the nearest content offset to an offset.
If the offset is already a valid offset, it will be returned unchanged. This method differs from calling {getRelativeContentOffset} with a zero length difference because the direction can be controlled without necessarily moving the offset if it's already valid. Also, if the direction is 0 or undefined than nearest offsets will be found to the left and right and the one with the shortest distance will be used.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number | Offset to start from |
|
direction |
number |
optional |
Direction to prefer matching offset in, -1 for left and 1 for right |
Returns:
Nearest content offset or -1 if there are no valid offsets in data
- Type
- number
getNearestStructuralOffset(offset, [direction], [unrestricted]) → {number}
#
Get the nearest structural offset to an offset.
If the offset is already a valid offset, it will be returned unchanged. This method differs from calling {getRelativeStructuralOffset} with a zero length difference because the direction can be controlled without necessarily moving the offset if it's already valid. Also, if the direction is 0 or undefined than nearest offsets will be found to the left and right and the one with the shortest distance will be used.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number | Offset to start from |
|
direction |
number |
optional |
Direction to prefer matching offset in, -1 for left and 1 for right |
unrestricted |
boolean |
optional |
Only consider offsets where any kind of element can be inserted |
Returns:
Nearest structural offset
- Type
- number
getRelativeContentOffset(offset, distance) → {number}
#
Get a content offset at a distance from an offset.
This method is a wrapper around {getRelativeOffset}, using {isContentOffset} as the offset validation callback.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Offset to start from |
distance |
number | Number of content offsets to move |
Returns:
Relative content offset or -1 if there are no valid offsets in data
- Type
- number
getRelativeOffset(offset, distance, callback, […args]) → {number}
#
Get an offset at a distance to an offset that passes a validity test.
- If {offset} is not already valid, one step will be used to move it to a valid one.
- If {offset} is already valid and cannot be moved in the direction of {distance} and still be valid, it will be left where it is
- If {distance} is zero the result will either be {offset} if it's already valid or the nearest valid offset to the right if possible and to the left otherwise.
- If {offset} is after the last valid offset and {distance} is >= 1, or if {offset} if before the first valid offset and {distance} <= 1 than the result will be the nearest valid offset in the opposite direction.
- If the data does not contain a single valid offset the result will be -1
Nodes that want their children to be ignored (see ve.dm
.Node#static-ignoreChildren) are not
descended into. Giving a starting offset inside an ignoreChildren node will give unpredictable
results.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number | Offset to start from |
|
distance |
number | Number of valid offsets to move |
|
callback |
function | Function to call to check if an offset is valid which will be given initial argument of offset |
|
args |
any |
optional repeatable |
Additional arguments to pass to the callback |
Returns:
Relative valid offset or -1 if there are no valid offsets in data
- Type
- number
getRelativeStructuralOffset(offset, distance, [unrestricted]) → {number}
#
Get a structural offset at a distance from an offset.
This method is a wrapper around {getRelativeOffset}, using {this.isStructuralOffset} as the offset validation callback.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number | Offset to start from |
|
distance |
number | Number of structural offsets to move |
|
unrestricted |
boolean |
optional |
Only consider offsets where any kind of element can be inserted |
Returns:
Relative structural offset
- Type
- number
getSourceText([range]) → {string}
#
Get the data as original source text (source mode only)
Split paragraphs are converted to single line breaks. It is assumed the document contains nothing but plain text and paragraph elements.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
range |
ve.Range |
optional |
Range to get the data for. The whole data set if not specified. |
Returns:
Data as original source text
- Type
- string
Get the data as original source text (source mode only)
Split paragraphs are converted to single line breaks.
getStore() → {ve.dm.HashValueStore}
#
Gets the hash-value store
- Inherited from:
- Source:
Returns:
The hash-value store
- Type
- ve.dm.HashValueStore
getText([maintainIndices], [range]) → {string}
#
Get the data as plain text
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
maintainIndices |
boolean |
optional |
Maintain data offset to string index alignment by replacing elements with line breaks |
range |
ve.Range |
optional |
Range to get the data for. The whole data set if not specified. |
Returns:
Data as plain text
- Type
- string
getType(offset) → {string}
#
Get the type of the element at a specified offset.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Data offset |
- Inherited from:
- Source:
Returns:
Type of the element
- Type
- string
getUsedStoreValues([range]) → {Object}
#
Finds all instances of items being stored in the hash-value store for this data store
Currently this is just all annotations still in use.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
range |
ve.Range |
optional |
Optional range to get store values for |
Returns:
Object containing all store values, keyed by store hash
- Type
- Object
Finds all instances of items being stored in the hash-value store for this data store
Currently this is just all annotations still in use.
getWordRange(offset) → {ve.Range}
#
Get the range of the word at offset (else a collapsed range)
First, if the offset is not a content offset then it will be moved to the nearest one. Then, if the offset is inside a word, it will be expanded to that word; else if the offset is at the end of a word, it will be expanded to that word; else if the offset is at the start of a word, it will be expanded to that word; else the offset is not adjacent to any word and is returned as a collapsed range.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Offset to start from; must not be inside a surrogate pair |
Returns:
Boundaries of the adjacent word (else offset as collapsed range)
- Type
- ve.Range
Get the range of the word at offset (else a collapsed range)
First, if the offset is not a content offset then it will be moved to the nearest one.
hasAnnotationsInRange(range) → {boolean}
#
Check if the range has any annotations
Parameters:
Name | Type | Description |
---|---|---|
range |
ve.Range | Range to check for annotations |
Returns:
The range contains at least one annotation
- Type
- boolean
hasContent() → {boolean}
#
Checks if the document has content that's not part of an internalList.
Returns:
The document has content
- Type
- boolean
isCloseElementData(offset) → {boolean}
#
Checks if data at a given offset is a close element.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Data offset |
- Inherited from:
- Source:
Returns:
Data at offset is a close element
- Type
- boolean
isContentData() → {boolean}
#
Check for non-content elements in data.
This method assumes that any value that has a type property that's a string is an element object. Elements are discovered by iterating through the entire data array.
Returns:
True if all elements in data are content elements
- Type
- boolean
isContentOffset(offset) → {boolean}
#
Check if content can be inserted at an offset in document data.
This method assumes that any value that has a type property that's a string is an element object.
Content offsets:
<heading> a </heading> <paragraph> b c <img> </img> </paragraph>
. ^ ^ . ^ ^ ^ . ^ .
Content offsets:
<list> <listItem> </listItem> <list>
. . . . .
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Document offset |
Returns:
Content can be inserted at offset
- Type
- boolean
isElementData(offset) → {boolean}
#
Check if data at a given offset is an element.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Data offset |
- Inherited from:
- Source:
Returns:
Data at offset is an element
- Type
- boolean
isOpenElementData(offset) → {boolean}
#
Checks if data at a given offset is an open element.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Data offset |
- Inherited from:
- Source:
Returns:
Data at offset is an open element
- Type
- boolean
isPlainText([range], [ignoreNonContentNodes], [ignoredTypes], [ignoreCoveringAnnotations], [ignoreAllAnnotations]) → {boolean}
#
Check if the data is just text
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
range |
ve.Range |
optional |
Range to get the data for. The whole data set if not specified. |
ignoreNonContentNodes |
boolean |
optional |
Ignore all non-content nodes, e.g. paragraphs, headings, lists |
ignoredTypes |
Array.<string> |
optional |
Only ignore specific non-content types |
ignoreCoveringAnnotations |
boolean |
optional |
Ignore covering annotations |
ignoreAllAnnotations |
boolean |
optional |
Ignore all annotations |
Returns:
The data is plain text
- Type
- boolean
isStructuralOffset(offset, [unrestricted]) → {boolean}
#
Check if structure can be inserted at an offset in document data.
If the {unrestricted} param is true than only offsets where any kind of element can be inserted will return true. This can be used to detect the difference between a location that a paragraph can be inserted, such as between two tables but not directly inside a table.
This method assumes that any value that has a type property that's a string is an element object.
Structural offsets (unrestricted = false):
<heading> a </heading> <paragraph> b c <img> </img> </paragraph>
^ . . ^ . . . . . ^
Structural offsets (unrestricted = true):
<heading> a </heading> <paragraph> b c <img> </img> </paragraph>
^ . . ^ . . . . . ^
Structural offsets (unrestricted = false):
<list> <listItem> </listItem> <list>
^ ^ ^ ^ ^
Content branch offsets (unrestricted = true):
<list> <listItem> </listItem> <list>
^ . ^ . ^
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number | Document offset |
|
unrestricted |
boolean |
optional |
Only return true if any kind of element can be inserted at offset |
Returns:
Structure can be inserted at offset
- Type
- boolean
modifyData(offset, modify)
#
Modify an existing object in the linear model
As objects in the model and immutable, this creates a clone which is passed to a callback function for modification, then the clone is inserted into the model.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Offset to modify data at |
modify |
function | Modification function. First argument is the data element to modify. |
- Inherited from:
- Source:
Modify an existing object in the linear model
As objects in the model and immutable, this creates a clone which is passed to a callback function for modification, then the clone is inserted into the model.
push([…values]) → {number}
#
Push data to the end of the array
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
values |
Object |
optional repeatable |
Values to store |
- Inherited from:
- Source:
Returns:
The new length of the linear data
- Type
- number
remapAnnotationHash(oldHash, newHash)
#
Remap an annotation hash when it changes
Parameters:
Name | Type | Description |
---|---|---|
oldHash |
string | Old hash to replace |
newHash |
string | New hash to replace it with |
remapInternalListIndexes(mapping, internalList)
#
Remap the internal list indexes used in this linear data.
Calls remapInternalListIndexes() for each node.
Parameters:
Name | Type | Description |
---|---|---|
mapping |
Object | Mapping from internal list indexes to internal list indexes |
internalList |
ve.dm.InternalList | Internal list the indexes are being mapped into. Used for refreshing attribute values that were computed with getNextUniqueNumber(). |
remapInternalListKeys(internalList)
#
Remap the internal list keys used in this linear data.
Calls remapInternalListKeys() for each node.
Parameters:
Name | Type | Description |
---|---|---|
internalList |
ve.dm.InternalList | Internal list the keys are being mapped into. |
sanitize(rules)
#
Sanitize data according to a set of rules.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
rules |
Object | Sanitization rules Properties:
|
setAnnotationHashesAtOffset(offset, hashes)
#
Set annotations' store hashes at a specified offset.
Cleans up data structure if hashes array is empty.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Offset to set annotation hashes at |
hashes |
Array.<string> | Annotations' store hashes |
setAnnotationsAtOffset(offset, annotations)
#
Set annotations of data at a specified offset.
Cleans up data structure if annotation set is empty.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Offset to set annotations at |
annotations |
ve.dm.AnnotationSet | Annotations to set |
setAttributeAtOffset(offset, key, value)
#
Set or unset an attribute at a specified offset.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Offset to set/unset attribute at |
key |
string | Attribute name |
value |
any | Value to set, or undefined to unset |
setData(offset, value)
#
Sets linear data at a specified index
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Offset to set data at |
value |
Object | string | Value to store |
- Inherited from:
- Source:
slice(begin, [end]) → {Array}
#
Slice linear data
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
begin |
number | Index to begin at |
|
end |
number |
optional |
Index to end at |
- Inherited from:
- Source:
Returns:
One-level deep copy of sliced range
- Type
- Array
sliceObject(begin, [end]) → {ve.dm.LinearData}
#
Slice linear data and return new LinearData object containing result
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
begin |
number | Index to begin at |
|
end |
number |
optional |
Index to end at |
- Inherited from:
- Source:
Returns:
LinearData object containing one-level deep copy of sliced range
- Type
- ve.dm.LinearData
splice(index, deleteCount, […elements]) → {Array}
#
spliceObject(index, deleteCount, […elements]) → {ve.dm.LinearData}
#
Splice linear data and return new LinearData object containing result
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
index |
number | Splice from |
|
deleteCount |
number | Items to be removed |
|
elements |
Object |
optional repeatable |
Items to be inserted |
- Inherited from:
- Source:
Returns:
LinearData object containing elements removed
- Type
- ve.dm.LinearData
trimOuterSpaceFromRange(range) → {Object}
#
compareElements(a, b, aStore, [bStore]) → {boolean}static
#
Compare two elements' basic properties and annotations
Elements are comparable if they have the same type, attributes,
text data and annotations, as determined by
ve.dm
.AnnotationSet#compareTo .
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a |
Object | Array | string | First element |
|
b |
Object | Array | string | Second element |
|
aStore |
ve.dm.HashValueStore | First element's store |
|
bStore |
ve.dm.HashValueStore |
optional |
Second element's store, if different |
Returns:
Elements are comparable
- Type
- boolean
Compare two elements' basic properties and annotations
Elements are comparable if they have the same type, attributes,
text data and annotations, as determined by
ve.dm
.AnnotationSet#compareTo .
compareElementsUnannotated(a, b) → {boolean}static
#
Compare two elements' basic properties
Elements are comparable if they have the same type and attributes, or have the same text data. Anything semantically irrelevant is filtered out first.
When changing, ensure that ve.dm
.Transaction.static.compareElementsForTranslate
is also updated.
Parameters:
Name | Type | Description |
---|---|---|
a |
Object | Array | string | First element |
b |
Object | Array | string | Second element |
Returns:
Elements are comparable
- Type
- boolean
Compare two elements' basic properties
Elements are comparable if they have the same type and attributes, or have the same text data.
getAnnotationHashesFromItem(item) → {Array.<string>}static
#
Read the array of annotation store hashes from an item of linear data
Parameters:
Returns:
An array of annotation store hashes
- Type
- Array.<string>
getCharacterDataFromItem(item) → {string}static
#
Get character data from an item
Parameters:
Returns:
Character data, or '' if no character data
- Type
- string