forked from steemit/slate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmark.js
82 lines (64 loc) · 1.26 KB
/
mark.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
import Data from './data'
import memoize from '../utils/memoize'
import { Map, Record, Set } from 'immutable'
/**
* Record.
*/
const DEFAULTS = {
data: new Map(),
type: null
}
/**
* Mark.
*/
class Mark extends new Record(DEFAULTS) {
/**
* Create a new `Mark` with `properties`.
*
* @param {Object} properties
* @return {Mark} mark
*/
static create(properties = {}) {
if (properties instanceof Mark) return properties
if (!properties.type) throw new Error('You must provide a `type` for the mark.')
properties.data = Data.create(properties.data)
return new Mark(properties)
}
/**
* Create a marks set from an array of marks.
*
* @param {Array} array
* @return {Set} marks
*/
static createSet(array = []) {
if (Set.isSet(array)) return array
return new Set(array.map(Mark.create))
}
/**
* Get the kind.
*
* @return {String} kind
*/
get kind() {
return 'mark'
}
/**
* Get the component for the node from a `schema`.
*
* @param {Schema} schema
* @return {Component || Void}
*/
getComponent(schema) {
return schema.__getComponent(this)
}
}
/**
* Memoize read methods.
*/
memoize(Mark.prototype, [
'getComponent',
])
/**
* Export.
*/
export default Mark