-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcreate-default-events.js
210 lines (193 loc) · 6.81 KB
/
create-default-events.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import createDefaultBehavior from './create-default-behavior.js'
export default function createDefaultEvents (editable) {
const behavior = createDefaultBehavior(editable)
return {
/**
* The focus event is triggered when an element gains focus.
* The default behavior is to... TODO
*
* @event focus
* @param {HTMLElement} element The element triggering the event.
*/
focus (element) {
behavior.focus(element)
},
/**
* The blur event is triggered when an element looses focus.
* The default behavior is to... TODO
*
* @event blur
* @param {HTMLElement} element The element triggering the event.
*/
blur (element) {
behavior.blur(element)
},
/**
* The flow event is triggered when the user starts typing or pause typing.
* The default behavior is to... TODO
*
* @event flow
* @param {HTMLElement} element The element triggering the event.
* @param {String} action The flow action: "start" or "pause".
*/
flow (element, action) {
behavior.flow(element, action)
},
/**
* The selection event is triggered after the user has selected some
* content.
* The default behavior is to... TODO
*
* @event selection
* @param {HTMLElement} element The element triggering the event.
* @param {Selection} selection The actual Selection object.
*/
selection (element, selection) {
behavior.selection(element, selection)
},
/**
* The cursor event is triggered after cursor position has changed.
* The default behavior is to... TODO
*
* @event cursor
* @param {HTMLElement} element The element triggering the event.
* @param {Cursor} cursor The actual Cursor object.
*/
cursor (element, cursor) {
behavior.cursor(element, cursor)
},
/**
* The newline event is triggered when a newline should be inserted. This
* happens when SHIFT+ENTER key is pressed.
* The default behavior is to add a <br />
*
* @event newline
* @param {HTMLElement} element The element triggering the event.
* @param {Cursor} cursor The actual cursor object.
*/
newline (element, cursor) {
behavior.newline(element, cursor)
},
/**
* The split event is triggered when a block should be split into two
* blocks. This happens when ENTER is pressed within a non-empty block.
* The default behavior is to... TODO
*
* @event split
* @param {HTMLElement} element The element triggering the event.
* @param {String} before The HTML string before the split.
* @param {String} after The HTML string after the split.
* @param {Cursor} cursor The actual cursor object.
*/
split (element, before, after, cursor) {
behavior.split(element, before, after, cursor)
},
/**
* The insert event is triggered when a new block should be inserted. This
* happens when ENTER key is pressed at the beginning of a block (should
* insert before) or at the end of a block (should insert after).
* The default behavior is to... TODO
*
* @event insert
* @param {HTMLElement} element The element triggering the event.
* @param {String} direction The insert direction: "before" or "after".
* @param {Cursor} cursor The actual cursor object.
*/
insert (element, direction, cursor) {
behavior.insert(element, direction, cursor)
},
/**
* The merge event is triggered when two needs to be merged. This happens
* when BACKSPACE is pressed at the beginning of a block (should merge with
* the preceding block) or DEL is pressed at the end of a block (should
* merge with the following block).
* The default behavior is to... TODO
*
* @event merge
* @param {HTMLElement} element The element triggering the event.
* @param {String} direction The merge direction: "before" or "after".
* @param {Cursor} cursor The actual cursor object.
*/
merge (element, direction, cursor) {
behavior.merge(element, direction, cursor)
},
/**
* The empty event is triggered when a block is emptied.
* The default behavior is to... TODO
*
* @event empty
* @param {HTMLElement} element The element triggering the event.
*/
empty (element) {
behavior.empty(element)
},
/**
* The switch event is triggered when the user switches to another block.
* This happens when an ARROW key is pressed near the boundaries of a block.
* The default behavior is to... TODO
*
* @event switch
* @param {HTMLElement} element The element triggering the event.
* @param {String} direction The switch direction: "before" or "after".
* @param {Cursor} cursor The actual cursor object.*
*/
switch (element, direction, cursor) {
behavior.switch(element, direction, cursor)
},
/**
* The move event is triggered when the user moves a selection in a block.
* This happens when the user selects some (or all) content in a block and
* an ARROW key is pressed (up: drag before, down: drag after).
* The default behavior is to... TODO
*
* @event move
* @param {HTMLElement} element The element triggering the event.
* @param {Selection} selection The actual Selection object.
* @param {String} direction The move direction: "before" or "after".
*/
move (element, selection, direction) {
behavior.move(element, selection, direction)
},
/**
* The clipboard event is triggered when the user copies or cuts
* a selection within a block.
*
* @event clipboard
* @param {HTMLElement} element The element triggering the event.
* @param {String} action The clipboard action: "copy" or "cut".
* @param {Selection} selection A selection object around the copied content.
*/
clipboard (element, action, selection) {
behavior.clipboard(element, action, selection)
},
/**
* The paste event is triggered when the user pastes text
*
* @event paste
* @param {HTMLElement} The element triggering the event.
* @param {Array of String} The pasted blocks
* @param {Cursor} The cursor object.
*/
paste (element, blocks, cursor) {
behavior.paste(element, blocks, cursor)
},
/**
* The toggleBold event is triggered when the bold keyboard shortcut is used
*
* @event toggleBold
* @param {Selection} The selection object.
*/
toggleBold (selection) {
behavior.toggleBold(selection)
},
/**
* The toggleEmphasis event is triggered when the italic keyboard shortcut is used
*
* @event toggleEmphasis
* @param {Selection} The selection object.
*/
toggleEmphasis (selection) {
behavior.toggleEmphasis(selection)
}
}
}