forked from steemit/slate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrange.js
More file actions
69 lines (55 loc) · 1.05 KB
/
range.js
File metadata and controls
69 lines (55 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import Character from './character'
import Mark from './mark'
import { Record, Set } from 'immutable'
/**
* Default properties.
*/
const DEFAULTS = {
marks: new Set(),
text: ''
}
/**
* Range.
*/
class Range extends new Record(DEFAULTS) {
/**
* Create a new `Range` with `properties`.
*
* @param {Object} properties
* @return {Range}
*/
static create(properties = {}) {
if (properties instanceof Range) return properties
properties.text = properties.text
properties.marks = Mark.createSet(properties.marks)
return new Range(properties)
}
/**
* Get the node's kind.
*
* @return {String} kind
*/
get kind() {
return 'range'
}
/**
* Return range as a list of characters
*
* @return {List<Character>} characters
*/
getCharacters() {
const { marks } = this
return Character.createList(this.text
.split('')
.map((char) => {
return Character.create({
text: char,
marks
})
}))
}
}
/**
* Export.
*/
export default Range