forked from JiHong88/suneditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.js
More file actions
307 lines (269 loc) · 10 KB
/
base.js
File metadata and controls
307 lines (269 loc) · 10 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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/**
* @fileoverview Editor interface definitions for SunEditor.
* These types define callback methods that Editor core calls on plugin instances.
*/
// ================================================================
// EDITOR METHOD TYPES - Methods called by Editor core on plugins
// ================================================================
export const Event = {
/**
* Executes the method that is called whenever the cursor position changes.
* @description Executes the method that is called whenever the cursor position changes.
* @param {?HTMLElement} element - Node element where the cursor is currently located
* @param {?HTMLElement} target - The plugin's toolbar button element
* @returns {boolean|void} - Whether the plugin is active
* - If it returns `undefined`, it will no longer be called in this scope.
*/
Active(element, target) {},
/**
* Executes the event function of `focus`.
* @param {SunEditor.HookParams.FocusBlur} params - Event parameters
* @returns {void}
*/
OnFocus(params) {},
/**
* Executes the event function of `blur`.
* @param {SunEditor.HookParams.FocusBlur} params - Event parameters
* @returns {void}
*/
OnBlur(params) {},
/**
* Executes the event function of `mousemove`.
* @param {SunEditor.HookParams.MouseEvent} params - Mouse event information
* @returns {void}
*/
OnMouseMove(params) {},
/**
* Executes the event function of `scroll`.
* @param {SunEditor.HookParams.Scroll} params - Event parameters
* @returns {void}
*/
OnScroll(params) {},
// ====== Sync / Async Event Methods ======
// ------- Interruptible events (returning boolean stops event processing) ---
/**
* Executes the event function of `keydown` (sync).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* @param {SunEditor.HookParams.KeyEvent} params - Key event information
* @returns {void|boolean} - Return `false` to prevent the editor's `keydown` processing (shortcuts, actions)
*/
OnKeyDown(params) {},
/**
* Executes the event function of `keydown` (async).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* @param {SunEditor.HookParams.KeyEvent} params - Key event information
* @returns {Promise<void|boolean>} - Return `false` to prevent the editor's `keydown` processing (shortcuts, actions)
*/
async OnKeyDownAsync(params) {
return;
},
/**
* Executes the event function of `keyup` (sync).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* @param {SunEditor.HookParams.KeyEvent} params - Key event information
* @returns {void|boolean} - Return `false` to prevent adding to history
*/
OnKeyUp(params) {},
/**
* Executes the event function of `keyup` (async).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* @param {SunEditor.HookParams.KeyEvent} params - Key event information
* @returns {Promise<void|boolean>} - Return `false` to prevent adding to history
*/
async OnKeyUpAsync(params) {
return;
},
/**
* Executes the event function of `mousedown` (sync).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* @param {SunEditor.HookParams.MouseEvent} params - Mouse event information
* @returns {void|boolean} - Return `false` to prevent the editor's `mousedown` processing
*/
OnMouseDown(params) {},
/**
* Executes the event function of `mousedown` (async).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* @param {SunEditor.HookParams.MouseEvent} params - Mouse event information
* @returns {Promise<void|boolean>} - Return `false` to prevent the editor's `mousedown` processing
*/
async OnMouseDownAsync(params) {
return;
},
/**
* Executes the event function of `click` (sync).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* @param {SunEditor.HookParams.MouseEvent} params - Mouse event information
* @returns {void|boolean} - Return `false` to prevent the editor's `click` processing (component selection)
*/
OnClick(params) {},
/**
* Executes the event function of `click` (async).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* @param {SunEditor.HookParams.MouseEvent} params - Mouse event information
* @returns {Promise<void|boolean>} - Return `false` to prevent the editor's `click` processing (component selection)
*/
async OnClickAsync(params) {
return;
},
/**
* Executes the event function of `paste` (sync).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* Returning `false` will stop event propagation and cancel the paste.
* @param {SunEditor.HookParams.Paste} params - Paste event information
* @returns {void|boolean}
*/
OnPaste(params) {},
/**
* Executes the event function of `paste` (async).
* Called sequentially on all plugins. Returning a boolean stops the loop.
* Returning `false` will stop event propagation and cancel the paste.
* @param {SunEditor.HookParams.Paste} params - Paste event information
* @returns {Promise<void|boolean>}
*/
async OnPasteAsync(params) {
return;
},
// ------- Observation events (non-interruptible) ------
/**
* Executes the event function of `beforeinput` (sync).
* Called after validation but before the input is processed.
* @param {SunEditor.HookParams.InputWithData} params - Event parameters
* @returns {void}
*/
OnBeforeInput(params) {},
/**
* Executes the event function of `beforeinput` (async).
* Called after validation but before the input is processed.
* @param {SunEditor.HookParams.InputWithData} params - Event parameters
* @returns {Promise<void>}
*/
async OnBeforeInputAsync(params) {
return;
},
/**
* Executes the event function of `input` (sync).
* Called after the input has been processed.
* @param {SunEditor.HookParams.InputWithData} params - Event parameters
* @returns {void}
*/
OnInput(params) {},
/**
* Executes the event function of `input` (async).
* Called after the input has been processed.
* @param {SunEditor.HookParams.InputWithData} params - Event parameters
* @returns {Promise<void>}
*/
async OnInputAsync(params) {
return;
},
/**
* Executes the event function of `mouseup` (sync).
* @param {SunEditor.HookParams.MouseEvent} params - Mouse event information
* @returns {void}
*/
OnMouseUp(params) {},
/**
* Executes the event function of `mouseup` (async).
* @param {SunEditor.HookParams.MouseEvent} params - Mouse event information
* @returns {Promise<void>}
*/
async OnMouseUpAsync(params) {
return;
},
/**
* Executes the event function of `mouseleave` (sync).
* @param {SunEditor.HookParams.MouseEvent} params - Mouse event information
* @returns {void}
*/
OnMouseLeave(params) {},
/**
* Executes the event function of `mouseleave` (async).
* @param {SunEditor.HookParams.MouseEvent} params - Mouse event information
* @returns {Promise<void>}
*/
async OnMouseLeaveAsync(params) {
return;
},
/**
* Executes when files are pasted or dropped into the editor (sync).
* This event is called for each file. The paste/drop process is automatically stopped after processing all files.
* @param {SunEditor.HookParams.FilePasteDrop} params - File paste/drop event information
* @returns {void}
*/
OnFilePasteAndDrop(params) {},
/**
* Executes when files are pasted or dropped into the editor (async).
* This event is called for each file. The paste/drop process is automatically stopped after processing all files.
* @param {SunEditor.HookParams.FilePasteDrop} params - File paste/drop event information
* @returns {Promise<void>}
*/
async OnFilePasteAndDropAsync(params) {
return;
},
};
export const Component = {
/**
* Executes the method that is called when a component of a plugin is selected.
* @param {HTMLElement} target - Target component element
* @returns {void|boolean} - If return `true`, Special components that are not wrapping as `figure`
*/
Select(target) {},
/**
* Called when a container is deselected.
* @param {HTMLElement} target Target element
* @returns {void}
*/
Deselect(target) {},
/**
* Executes the method that is called when a component is being edited.
* @param {HTMLElement} target - Target element
* @returns {void}
*/
Edit(target) {},
/**
* Method to delete a component of a plugin, called by the `FileManager`, `Controller` module.
* @param {HTMLElement} target - Target element
* @returns {Promise<void>}
*/
async Destroy(target) {
return;
},
/**
* Executes the method that is called when a component copy is requested.
* @param {SunEditor.HookParams.CopyComponent} params - Copy component event information
* @returns {boolean | void} - If return `false`, the copy will be canceled
*/
Copy(params) {},
};
export const Core = {
/**
* This method is used to validate and preserve the format of the component within the editor.
* - It ensures that the structure and attributes of the element are maintained and secure.
* - The method checks if the element is already wrapped in a valid container and updates its attributes if necessary.
* - If the element isn't properly contained, a new container is created to retain the format.
* @returns {{query: string, method: (element: HTMLElement) => void}} The format retention object containing the query and method to process the element.
* - query: The selector query to identify the relevant elements.
* - method: The function to execute on the element to validate and preserve its format.
*/
RetainFormat() {
return { query: '', method: () => {} };
},
/**
* Executes methods called by shortcut keys.
* @param {SunEditor.HookParams.Shortcut} params - Information of the `shortcut` plugin
* @returns {void}
*/
Shortcut(params) {},
/**
* Executes the method called when the rtl, ltr mode changes. (`editor.ui.setDir`)
* @param {string} dir - Direction (`rtl` or `ltr`)
* @returns {void}
*/
SetDir(dir) {},
/**
* Executes when the editor or plugin is initialized.
* Called during editor initialization and when `resetOptions` is called.
* @returns {void}
*/
Init() {},
};