suneditor-react-yoptatech 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +924 -0
- package/dist/buttons/buttonList.d.ts +3 -0
- package/dist/buttons/buttonList.js +31 -0
- package/dist/components/SunEditor.d.ts +4 -0
- package/dist/components/SunEditor.js +180 -0
- package/dist/data/events.d.ts +2 -0
- package/dist/data/events.js +34 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +32 -0
- package/dist/lang/getLanguage.d.ts +3 -0
- package/dist/lang/getLanguage.js +13 -0
- package/dist/types/SunEditorReactProps.d.ts +69 -0
- package/dist/types/SunEditorReactProps.js +2 -0
- package/dist/types/lang.d.ts +3 -0
- package/dist/types/lang.js +2 -0
- package/dist/types/upload.d.ts +26 -0
- package/dist/types/upload.js +2 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
# suneditor-react
|
|
2
|
+
|
|
3
|
+
> A React Component for [SunEditor](http://suneditor.com)
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/suneditor-react) [](https://standardjs.com)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
#### npm
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
$ npm install --save suneditor suneditor-react # make sure to install suneditor yourself
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Getting Started
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import React from 'react';
|
|
21
|
+
import SunEditor from 'suneditor-react';
|
|
22
|
+
import 'suneditor/dist/css/suneditor.min.css'; // Import Sun Editor's CSS File
|
|
23
|
+
|
|
24
|
+
const MyComponent = props => {
|
|
25
|
+
return (
|
|
26
|
+
<div>
|
|
27
|
+
<p> My Other Contents </p>
|
|
28
|
+
<SunEditor />
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
export default MyComponent;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### [Next.js](https://nextjs.org/)
|
|
37
|
+
|
|
38
|
+
To use suneditor-react with Next.js, please use the dynamic import syntax like below:
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
import React from 'react';
|
|
42
|
+
import dynamic from "next/dynamic";
|
|
43
|
+
import 'suneditor/dist/css/suneditor.min.css'; // Import Sun Editor's CSS File
|
|
44
|
+
|
|
45
|
+
const SunEditor = dynamic(() => import("suneditor-react"), {
|
|
46
|
+
ssr: false,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const MyComponent = props => {
|
|
50
|
+
return (
|
|
51
|
+
<div>
|
|
52
|
+
<p> My Other Contents </p>
|
|
53
|
+
<SunEditor />
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
export default MyComponent;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
# Props
|
|
61
|
+
|
|
62
|
+
## About Core
|
|
63
|
+
|
|
64
|
+
**Note:** `suneditor-react` doesn't expose the core object in the callback functions such as `onScroll` etc. This is because it can be easily retrieved by using the `getSunEditorInstance` like below.
|
|
65
|
+
|
|
66
|
+
```jsx
|
|
67
|
+
// Javascript Version
|
|
68
|
+
|
|
69
|
+
import React, { useRef, useEffect } from "react";
|
|
70
|
+
import SunEditor from 'suneditor-react';
|
|
71
|
+
import 'suneditor/dist/css/suneditor.min.css'; // Import Sun Editor's CSS File
|
|
72
|
+
|
|
73
|
+
const MyComponent = props => {
|
|
74
|
+
/**
|
|
75
|
+
* @type {React.MutableRefObject<SunEditor>} get type definitions for editor
|
|
76
|
+
*/
|
|
77
|
+
const editor = useRef();
|
|
78
|
+
|
|
79
|
+
// The sunEditor parameter will be set to the core suneditor instance when this function is called
|
|
80
|
+
const getSunEditorInstance = (sunEditor) => {
|
|
81
|
+
editor.current = sunEditor;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<div>
|
|
86
|
+
<p> My Other Contents </p>
|
|
87
|
+
<SunEditor getSunEditorInstance={getSunEditorInstance} />
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
export default MyComponent;
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
// Typescript Version
|
|
97
|
+
|
|
98
|
+
import React, { useRef, useEffect } from "react";
|
|
99
|
+
import SunEditor from 'suneditor-react';
|
|
100
|
+
import SunEditorCore from "suneditor/src/lib/core";
|
|
101
|
+
import 'suneditor/dist/css/suneditor.min.css'; // Import Sun Editor's CSS File
|
|
102
|
+
|
|
103
|
+
const MyComponent = props => {
|
|
104
|
+
const editor = useRef<SunEditorCore>();
|
|
105
|
+
|
|
106
|
+
// The sunEditor parameter will be set to the core suneditor instance when this function is called
|
|
107
|
+
const getSunEditorInstance = (sunEditor: SunEditorCore) => {
|
|
108
|
+
editor.current = sunEditor;
|
|
109
|
+
};
|
|
110
|
+
return (
|
|
111
|
+
<div>
|
|
112
|
+
<p> My Other Contents </p>
|
|
113
|
+
<SunEditor getSunEditorInstance={getSunEditorInstance} />
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
export default MyComponent;
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Basic Settings
|
|
122
|
+
|
|
123
|
+
**lang**
|
|
124
|
+
|
|
125
|
+
**_Language of editor_**
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
//...
|
|
129
|
+
render() {
|
|
130
|
+
return <SunEditor lang="en" />
|
|
131
|
+
// Default is en
|
|
132
|
+
// lang prop can be one of the strings provided in this array ["en", "da", "de", "es", "fr", "ja", "ko", "pt_br", "ru", "zh_cn", "ro", "pl", "ckb", "lv", "se", "ua", "he", "it"]
|
|
133
|
+
// Alternatively, an object of your language can be passed to this prop. To learn how to do it refer to the bottom of the page
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
**name**
|
|
139
|
+
|
|
140
|
+
**_HTML form name of editor_**
|
|
141
|
+
|
|
142
|
+
This is used to set the HTML form name of the editor. This means on HTML form submission, it will be submitted together with contents of the editor by the name provided.
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
//...
|
|
147
|
+
render() {
|
|
148
|
+
return <SunEditor name="my-editor" />
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**defaultValue**
|
|
153
|
+
|
|
154
|
+
**_Set Editor's default value_**
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
//...
|
|
158
|
+
// Sets the default value of the editor.
|
|
159
|
+
// This is useful if you don't want the onChange method to be called on render.
|
|
160
|
+
// If you want the onChange method to be called on render please use the setContents prop
|
|
161
|
+
render() {
|
|
162
|
+
return <SunEditor defaultValue="<p>The editor's default value</p>" />
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**width**
|
|
167
|
+
|
|
168
|
+
**_Set Editor's width_**
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
//...
|
|
172
|
+
// px and percentage values are accepted
|
|
173
|
+
// eg width="100%" or width="500px"
|
|
174
|
+
// default is 100%
|
|
175
|
+
render() {
|
|
176
|
+
return <SunEditor width="100%" />
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**height**
|
|
181
|
+
|
|
182
|
+
**_Set Editor's height_**
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
//...
|
|
186
|
+
// px and percentage values are accepted
|
|
187
|
+
// eg height="100%" or height="100px"
|
|
188
|
+
render() {
|
|
189
|
+
return <SunEditor height="100%" />
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
**placeholder**
|
|
195
|
+
|
|
196
|
+
**_Set Editor's placeholder_**
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
//...
|
|
200
|
+
render() {
|
|
201
|
+
return <SunEditor placeholder="Please type here..." />
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
**autoFocus**
|
|
207
|
+
|
|
208
|
+
**_Should editor focus when initialized_**
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
//...
|
|
212
|
+
render() {
|
|
213
|
+
return <SunEditor autoFocus={true} />
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**setOptions**
|
|
218
|
+
|
|
219
|
+
**_Set Options (Settings) for the editor_**
|
|
220
|
+
[Click to see all options available](https://github.com/JiHong88/SunEditor/blob/master/README.md#options)
|
|
221
|
+
|
|
222
|
+
**Important Note:** Some toolbar buttons in `suneditor` require specific plugins to make them work properly. For example when you specify 'font' in the button list, you will need to import the required plugin from `suneditor`. `suneditor-react` by default loads all plugins. To change this behaviour, you can pass a plugin list of only the plugins you would like to load to the plugin option. This will override the default behaviour. To disable the loading of all plugins, set the `setAllPlugins` prop to false. Read More by clicking [this](https://github.com/JiHong88/SunEditor/#1-load-only-what-you-want).
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
|
|
226
|
+
import SunEditor, { buttonList } from "suneditor-react";
|
|
227
|
+
/*
|
|
228
|
+
buttonList.basic = basic buttons for wordprocessing
|
|
229
|
+
buttonList.formatting = most tools used for formatting - This is the default option
|
|
230
|
+
buttonList.complex = contains most of the buttons
|
|
231
|
+
*/
|
|
232
|
+
//...
|
|
233
|
+
render() {
|
|
234
|
+
return <SunEditor setOptions={{
|
|
235
|
+
height: 200,
|
|
236
|
+
buttonList: buttonList.formatting // Or Array of button list, eg. [['font', 'align'], ['image']]
|
|
237
|
+
// plugins: [font] set plugins, all plugins are set by default
|
|
238
|
+
// Other option
|
|
239
|
+
}} />
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
**setAllPlugins**
|
|
244
|
+
|
|
245
|
+
Sets all plugins used by buttons. Default value is true
|
|
246
|
+
|
|
247
|
+
```javascript
|
|
248
|
+
import SunEditor, { buttonList } from "suneditor-react";
|
|
249
|
+
|
|
250
|
+
//...
|
|
251
|
+
render() {
|
|
252
|
+
return <SunEditor setAllPlugins={false} /> // When set to false, you must explicitly set required plugins
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**setContents**
|
|
258
|
+
|
|
259
|
+
**_Set Editor's Content_**
|
|
260
|
+
|
|
261
|
+
**Note:** To set the initial contents of the editor without calling the ``onChange`` event please use the ``defaultValue`` prop.
|
|
262
|
+
``setContents`` is used to set the contents of the editor programmatically. You must be aware that, when the `setContents`'s prop changes, the `onChange` event is triggered.
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
```javascript
|
|
266
|
+
//...
|
|
267
|
+
render() {
|
|
268
|
+
return <SunEditor setContents="My contents" />
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
**appendContents**
|
|
273
|
+
|
|
274
|
+
**_Append Editor Content_**
|
|
275
|
+
|
|
276
|
+
```javascript
|
|
277
|
+
//...
|
|
278
|
+
render() {
|
|
279
|
+
return <SunEditor appendContents="My contents" />
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
**setDefaultStyle**
|
|
285
|
+
|
|
286
|
+
**_Set the default style of the editor's edit area_**
|
|
287
|
+
|
|
288
|
+
```javascript
|
|
289
|
+
//...
|
|
290
|
+
render() {
|
|
291
|
+
return <SunEditor setDefaultStyle="font-family: cursive; font-size: 10px;" />
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Editor Status
|
|
296
|
+
|
|
297
|
+
**disable**
|
|
298
|
+
|
|
299
|
+
**_Disable Editor_**
|
|
300
|
+
|
|
301
|
+
```javascript
|
|
302
|
+
//...
|
|
303
|
+
render() {
|
|
304
|
+
// set to false to enable, default value is false
|
|
305
|
+
return <SunEditor disable={true} />
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**hide**
|
|
310
|
+
|
|
311
|
+
**_Hide Editor_**
|
|
312
|
+
|
|
313
|
+
```javascript
|
|
314
|
+
//...
|
|
315
|
+
render() {
|
|
316
|
+
// set to false to hide, default value is false
|
|
317
|
+
return <SunEditor hide={true} />
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**hideToolbar**
|
|
322
|
+
|
|
323
|
+
**_Hide Editor Toolbar_**
|
|
324
|
+
|
|
325
|
+
```javascript
|
|
326
|
+
//...
|
|
327
|
+
render() {
|
|
328
|
+
|
|
329
|
+
// set to false to hide toolbar, default value is false
|
|
330
|
+
return <SunEditor hideToolbar={true} />
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
**disableToolbar**
|
|
334
|
+
|
|
335
|
+
**_Disable Editor Toolbar_**
|
|
336
|
+
|
|
337
|
+
```javascript
|
|
338
|
+
//...
|
|
339
|
+
render() {
|
|
340
|
+
// set to false to enable toolbar, default value is false
|
|
341
|
+
return <SunEditor disableToolbar={true} />
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Events
|
|
346
|
+
|
|
347
|
+
**Note** that you need to bind the function passed to the event in the constructor if you are using a _class Component_, or use arrow functions instead. This is just how react works. Otherwise it won't work. This documentation assumes you bind all your class component methods to the constructor. Eg below:
|
|
348
|
+
|
|
349
|
+
```javascript
|
|
350
|
+
|
|
351
|
+
constructor(props) {
|
|
352
|
+
super(props);
|
|
353
|
+
this.handleChange = this.handleChange.bind(this)
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
**onChange**
|
|
358
|
+
|
|
359
|
+
**_Has the content inside the editor been changed?_**
|
|
360
|
+
|
|
361
|
+
```javascript
|
|
362
|
+
|
|
363
|
+
handleChange(content){
|
|
364
|
+
console.log(content); //Get Content Inside Editor
|
|
365
|
+
}
|
|
366
|
+
render() {
|
|
367
|
+
return <SunEditor onChange={handleChange} />
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
**onScroll**
|
|
372
|
+
|
|
373
|
+
**_Has the editor been scrolled?_**
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
handleScroll(event){
|
|
377
|
+
console.log(event); //Get the scroll event
|
|
378
|
+
}
|
|
379
|
+
render() {
|
|
380
|
+
return <SunEditor onScroll={handleScroll} />
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
**onClick**
|
|
385
|
+
|
|
386
|
+
**_Has the editor been clicked?_**
|
|
387
|
+
|
|
388
|
+
```javascript
|
|
389
|
+
handleClick(event){
|
|
390
|
+
console.log(event); //Get the click event
|
|
391
|
+
}
|
|
392
|
+
render() {
|
|
393
|
+
return <SunEditor onClick={handleClick} />
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
**onMouseDown**
|
|
399
|
+
|
|
400
|
+
**_Has the mouse is pressed and not yet released?_**
|
|
401
|
+
|
|
402
|
+
```javascript
|
|
403
|
+
handleMouseDown(event){
|
|
404
|
+
console.log(event); //Get the click event
|
|
405
|
+
}
|
|
406
|
+
render() {
|
|
407
|
+
return <SunEditor onMouseDown={handleMouseDown} />
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
**onInput**
|
|
412
|
+
|
|
413
|
+
**_Has the editor received input?_**
|
|
414
|
+
|
|
415
|
+
```javascript
|
|
416
|
+
handleInput(event){
|
|
417
|
+
console.log(event); //Get the click event
|
|
418
|
+
}
|
|
419
|
+
render() {
|
|
420
|
+
return <SunEditor onInput={handleInput} />
|
|
421
|
+
}
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
**onKeyUp**
|
|
426
|
+
|
|
427
|
+
**_Has the key been released up in the editor?_**
|
|
428
|
+
|
|
429
|
+
```javascript
|
|
430
|
+
handleKeyUp(event){
|
|
431
|
+
console.log(event); //Get the keyup event
|
|
432
|
+
}
|
|
433
|
+
render() {
|
|
434
|
+
return <SunEditor onKeyUp={handleKeyUp} />
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
**onFocus**
|
|
441
|
+
|
|
442
|
+
**_Has the editor been focused?_**
|
|
443
|
+
|
|
444
|
+
```javascript
|
|
445
|
+
handleFocus(event){
|
|
446
|
+
console.log(event); //Get the focus event
|
|
447
|
+
}
|
|
448
|
+
render() {
|
|
449
|
+
return <SunEditor onFocus={handleFocus} />
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
**onBlur**
|
|
456
|
+
|
|
457
|
+
**_Has the editor been blurred?_**
|
|
458
|
+
|
|
459
|
+
From the second parameter you can get the contents of the editor.
|
|
460
|
+
|
|
461
|
+
```javascript
|
|
462
|
+
handleBlur(event, editorContents){
|
|
463
|
+
console.log(event, editorContents); //Get the blur event
|
|
464
|
+
}
|
|
465
|
+
render() {
|
|
466
|
+
return <SunEditor onBlur={handleBlur} />
|
|
467
|
+
}
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
**onLoad**
|
|
472
|
+
|
|
473
|
+
**_Has the editor been reloaded with setOptions?_**
|
|
474
|
+
|
|
475
|
+
```javascript
|
|
476
|
+
handleLoad(reload){
|
|
477
|
+
console.log(reload); //Boolean
|
|
478
|
+
}
|
|
479
|
+
render() {
|
|
480
|
+
return <SunEditor onLoad={handleLoad} />
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
**onKeyDown**
|
|
486
|
+
|
|
487
|
+
**_Has the key been pressed down in the editor?_**
|
|
488
|
+
|
|
489
|
+
```javascript
|
|
490
|
+
handleKeyDown(event){
|
|
491
|
+
console.log(event); //Get the keydown event
|
|
492
|
+
}
|
|
493
|
+
render() {
|
|
494
|
+
return <SunEditor onKeyDown={handleKeyDown} />
|
|
495
|
+
}
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
**onDrop**
|
|
499
|
+
|
|
500
|
+
**_Has something been dropped into the editor?_**
|
|
501
|
+
|
|
502
|
+
```javascript
|
|
503
|
+
handleDrop(event){
|
|
504
|
+
console.log(event); //Get the drop event
|
|
505
|
+
}
|
|
506
|
+
render() {
|
|
507
|
+
return <SunEditor onDrop={handleDrop} />
|
|
508
|
+
}
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
**onImageUploadBefore**
|
|
513
|
+
|
|
514
|
+
**_Before an image is uploaded into the editor_**
|
|
515
|
+
|
|
516
|
+
```javascript
|
|
517
|
+
handleImageUploadBefore(files, info, uploadHandler){
|
|
518
|
+
// uploadHandler is a function
|
|
519
|
+
console.log(files, info)
|
|
520
|
+
}
|
|
521
|
+
render() {
|
|
522
|
+
return <SunEditor onImageUploadBefore={handleImageUploadBefore} />
|
|
523
|
+
}
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
**onImageUpload**
|
|
528
|
+
|
|
529
|
+
**_Has an image been uploaded into the editor?_**
|
|
530
|
+
|
|
531
|
+
```javascript
|
|
532
|
+
handleImageUpload(targetImgElement, index, state, imageInfo, remainingFilesCount){
|
|
533
|
+
console.log(targetImgElement, index, state, imageInfo, remainingFilesCount)
|
|
534
|
+
}
|
|
535
|
+
render() {
|
|
536
|
+
return <SunEditor onImageUpload={handleImageUpload} />
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
**onImageUploadError**
|
|
541
|
+
|
|
542
|
+
**_Has an image uploaded to the editor resulted in an error?_**
|
|
543
|
+
|
|
544
|
+
```javascript
|
|
545
|
+
handleImageUploadError(errorMessage, result){
|
|
546
|
+
console.log(errorMessage, result)
|
|
547
|
+
}
|
|
548
|
+
render() {
|
|
549
|
+
return <SunEditor onImageUploadError={handleImageUploadError} />
|
|
550
|
+
}
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
**onVideoUploadBefore**
|
|
555
|
+
|
|
556
|
+
**_Before a video is uploaded to the editor_**
|
|
557
|
+
|
|
558
|
+
```javascript
|
|
559
|
+
handleVideoUploadBefore(files, info, uploadHandler){
|
|
560
|
+
// uploadHandler is a function
|
|
561
|
+
console.log(files, info)
|
|
562
|
+
}
|
|
563
|
+
render() {
|
|
564
|
+
return <SunEditor onVideoUploadBefore={handleVideoUploadBefore} />
|
|
565
|
+
}
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
**onVideoUpload**
|
|
570
|
+
|
|
571
|
+
**_Has an image been uploaded into the editor?_**
|
|
572
|
+
|
|
573
|
+
```javascript
|
|
574
|
+
handleVideoUpload(targetElement, index, state, info, remainingFilesCount){
|
|
575
|
+
console.log(targetElement, index, state, info, remainingFilesCount)
|
|
576
|
+
}
|
|
577
|
+
render() {
|
|
578
|
+
return <SunEditor onVideoUpload={handleVideoUpload} />
|
|
579
|
+
}
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
**onVideoUploadError**
|
|
583
|
+
|
|
584
|
+
**_Has a video uploaded to the editor resulted in an error?_**
|
|
585
|
+
|
|
586
|
+
```javascript
|
|
587
|
+
handleVideoUploadError(errorMessage, result){
|
|
588
|
+
console.log(errorMessage, result)
|
|
589
|
+
}
|
|
590
|
+
render() {
|
|
591
|
+
return <SunEditor onVideoUploadError={handleVideoUploadError} />
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
**onAudioUploadBefore**
|
|
597
|
+
|
|
598
|
+
**_Before an audio is uploaded to the editor_**
|
|
599
|
+
|
|
600
|
+
```javascript
|
|
601
|
+
handleAudioUploadBefore(files, info, uploadHandler){
|
|
602
|
+
// uploadHandler is a function
|
|
603
|
+
console.log(files, info)
|
|
604
|
+
}
|
|
605
|
+
render() {
|
|
606
|
+
return <SunEditor onAudioUploadBefore={handleAudioUploadBefore} />
|
|
607
|
+
}
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
**onAudioUpload**
|
|
612
|
+
|
|
613
|
+
**_Has an audio been uploaded into the editor?_**
|
|
614
|
+
|
|
615
|
+
```javascript
|
|
616
|
+
handleAudioUpload(targetElement, index, state, info, remainingFilesCount){
|
|
617
|
+
console.log(targetElement, index, state, info, remainingFilesCount)
|
|
618
|
+
}
|
|
619
|
+
render() {
|
|
620
|
+
return <SunEditor onAudioUpload={handleAudioUpload} />
|
|
621
|
+
}
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
**onAudioUploadError**
|
|
625
|
+
|
|
626
|
+
**_Has an audio uploaded to the editor resulted in an error?_**
|
|
627
|
+
|
|
628
|
+
```javascript
|
|
629
|
+
handleAudioUploadError(errorMessage, result){
|
|
630
|
+
console.log(errorMessage, result)
|
|
631
|
+
}
|
|
632
|
+
render() {
|
|
633
|
+
return <SunEditor onAudioUploadError={handleAudioUploadError} />
|
|
634
|
+
}
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
**onResizeEditor**
|
|
639
|
+
|
|
640
|
+
**_Has the editor been resized?_**
|
|
641
|
+
|
|
642
|
+
```javascript
|
|
643
|
+
handleOnResizeEditor(height, prevHeight){
|
|
644
|
+
console.log(height, prevHeight)
|
|
645
|
+
}
|
|
646
|
+
render() {
|
|
647
|
+
return <SunEditor onResizeEditor={handleOnResizeEditor} />
|
|
648
|
+
}
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
**onCopy**
|
|
653
|
+
|
|
654
|
+
**_Has something been copied from the suneditor?_**
|
|
655
|
+
|
|
656
|
+
```javascript
|
|
657
|
+
handleCopy(e, clipboardData){
|
|
658
|
+
console.log(e, clipboardData)
|
|
659
|
+
}
|
|
660
|
+
render() {
|
|
661
|
+
return <SunEditor onCopy={handleCopy} />
|
|
662
|
+
}
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
**onCut**
|
|
667
|
+
|
|
668
|
+
**_Has something been cut from the suneditor?_**
|
|
669
|
+
|
|
670
|
+
```javascript
|
|
671
|
+
handleCut(e, clipboardData){
|
|
672
|
+
console.log(e, clipboardData)
|
|
673
|
+
}
|
|
674
|
+
render() {
|
|
675
|
+
return <SunEditor onCut={handleCut} />
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
**onPaste**
|
|
680
|
+
|
|
681
|
+
**_Has something been pasted into the suneditor?_**
|
|
682
|
+
|
|
683
|
+
```javascript
|
|
684
|
+
handlePaste(e, cleanData, maxCharCount){
|
|
685
|
+
console.log(e, cleanData, maxCharCount)
|
|
686
|
+
}
|
|
687
|
+
render() {
|
|
688
|
+
return <SunEditor onPaste={handlePaste} />
|
|
689
|
+
}
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
**imageUploadHandler**
|
|
694
|
+
|
|
695
|
+
**_Replaces the default callback function of the image upload_**
|
|
696
|
+
|
|
697
|
+
```javascript
|
|
698
|
+
imageUploadHandler(xmlHttpRequest, info, core){
|
|
699
|
+
console.log(xmlHttpRequest, info, core)
|
|
700
|
+
}
|
|
701
|
+
render() {
|
|
702
|
+
return <SunEditor imageUploadHandler={imageUploadHandler} />
|
|
703
|
+
}
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
**toggleCodeView**
|
|
708
|
+
|
|
709
|
+
**_An event when toggling between code view and wysiwyg view_**
|
|
710
|
+
|
|
711
|
+
```javascript
|
|
712
|
+
toggleCodeView(isCodeView){
|
|
713
|
+
console.log(isCodeView)
|
|
714
|
+
}
|
|
715
|
+
render() {
|
|
716
|
+
return <SunEditor toggleCodeView={toggleCodeView} />
|
|
717
|
+
}
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
**toggleFullScreen**
|
|
721
|
+
|
|
722
|
+
**_An event when toggling full screen_**
|
|
723
|
+
|
|
724
|
+
```javascript
|
|
725
|
+
toggleFullScreen(isFullScreen){
|
|
726
|
+
console.log(isFullScreen)
|
|
727
|
+
}
|
|
728
|
+
render() {
|
|
729
|
+
return <SunEditor toggleFullScreen={toggleFullScreen} />
|
|
730
|
+
}
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
**showInline**
|
|
734
|
+
|
|
735
|
+
**_Called just before the inline toolbar is positioned and displayed on the screen._**
|
|
736
|
+
|
|
737
|
+
```javascript
|
|
738
|
+
showInline(toolbar, context){
|
|
739
|
+
console.log(toolbar, context)
|
|
740
|
+
}
|
|
741
|
+
render() {
|
|
742
|
+
return <SunEditor showInline={showInline} />
|
|
743
|
+
}
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
**showController**
|
|
747
|
+
|
|
748
|
+
**_Called just after the controller is positioned and displayed on the screen._**
|
|
749
|
+
|
|
750
|
+
```javascript
|
|
751
|
+
showController(name, controllers){
|
|
752
|
+
console.log(name, controllers)
|
|
753
|
+
}
|
|
754
|
+
render() {
|
|
755
|
+
return <SunEditor showController={showController} />
|
|
756
|
+
}
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
## Editor Language Object
|
|
760
|
+
|
|
761
|
+
You can translate the object below to any other language and pass it to the lang prop to set your locale language if it is not part of the strings of array above.
|
|
762
|
+
Note: You will be aided by your editor's intellisense.
|
|
763
|
+
**Note** If you are using an object like below, you need to make sure that you memoize it so that it doesn't run setOptions every time the editor re-renders. You can do this using `useRef` or `useMemo`
|
|
764
|
+
|
|
765
|
+
```javascript
|
|
766
|
+
|
|
767
|
+
{
|
|
768
|
+
code: 'en',
|
|
769
|
+
toolbar: {
|
|
770
|
+
default: 'Default',
|
|
771
|
+
save: 'Save',
|
|
772
|
+
font: 'Font',
|
|
773
|
+
formats: 'Formats',
|
|
774
|
+
fontSize: 'Size',
|
|
775
|
+
bold: 'Bold',
|
|
776
|
+
underline: 'Underline',
|
|
777
|
+
italic: 'Italic',
|
|
778
|
+
strike: 'Strike',
|
|
779
|
+
subscript: 'Subscript',
|
|
780
|
+
superscript: 'Superscript',
|
|
781
|
+
removeFormat: 'Remove Format',
|
|
782
|
+
fontColor: 'Font Color',
|
|
783
|
+
hiliteColor: 'Highlight Color',
|
|
784
|
+
indent: 'Indent',
|
|
785
|
+
outdent: 'Outdent',
|
|
786
|
+
align: 'Align',
|
|
787
|
+
alignLeft: 'Align left',
|
|
788
|
+
alignRight: 'Align right',
|
|
789
|
+
alignCenter: 'Align center',
|
|
790
|
+
alignJustify: 'Align justify',
|
|
791
|
+
list: 'List',
|
|
792
|
+
orderList: 'Ordered list',
|
|
793
|
+
unorderList: 'Unordered list',
|
|
794
|
+
horizontalRule: 'Horizontal line',
|
|
795
|
+
hr_solid: 'Solid',
|
|
796
|
+
hr_dotted: 'Dotted',
|
|
797
|
+
hr_dashed: 'Dashed',
|
|
798
|
+
table: 'Table',
|
|
799
|
+
link: 'Link',
|
|
800
|
+
math: 'Math',
|
|
801
|
+
image: 'Image',
|
|
802
|
+
video: 'Video',
|
|
803
|
+
audio: 'Audio',
|
|
804
|
+
fullScreen: 'Full screen',
|
|
805
|
+
showBlocks: 'Show blocks',
|
|
806
|
+
codeView: 'Code view',
|
|
807
|
+
undo: 'Undo',
|
|
808
|
+
redo: 'Redo',
|
|
809
|
+
preview: 'Preview',
|
|
810
|
+
print: 'print',
|
|
811
|
+
tag_p: 'Paragraph',
|
|
812
|
+
tag_div: 'Normal (DIV)',
|
|
813
|
+
tag_h: 'Header',
|
|
814
|
+
tag_blockquote: 'Quote',
|
|
815
|
+
tag_pre: 'Code',
|
|
816
|
+
template: 'Template',
|
|
817
|
+
lineHeight: 'Line height',
|
|
818
|
+
paragraphStyle: 'Paragraph style',
|
|
819
|
+
textStyle: 'Text style',
|
|
820
|
+
imageGallery: 'Image gallery',
|
|
821
|
+
dir_ltr: 'Left to right',
|
|
822
|
+
dir_rtl: 'Right to left',
|
|
823
|
+
mention: 'Mention'
|
|
824
|
+
},
|
|
825
|
+
dialogBox: {
|
|
826
|
+
linkBox: {
|
|
827
|
+
title: 'Insert Link',
|
|
828
|
+
url: 'URL to link',
|
|
829
|
+
text: 'Text to display',
|
|
830
|
+
newWindowCheck: 'Open in new window',
|
|
831
|
+
downloadLinkCheck: 'Download link',
|
|
832
|
+
bookmark: 'Bookmark'
|
|
833
|
+
},
|
|
834
|
+
mathBox: {
|
|
835
|
+
title: 'Math',
|
|
836
|
+
inputLabel: 'Mathematical Notation',
|
|
837
|
+
fontSizeLabel: 'Font Size',
|
|
838
|
+
previewLabel: 'Preview'
|
|
839
|
+
},
|
|
840
|
+
imageBox: {
|
|
841
|
+
title: 'Insert image',
|
|
842
|
+
file: 'Select from files',
|
|
843
|
+
url: 'Image URL',
|
|
844
|
+
altText: 'Alternative text'
|
|
845
|
+
},
|
|
846
|
+
videoBox: {
|
|
847
|
+
title: 'Insert Video',
|
|
848
|
+
file: 'Select from files',
|
|
849
|
+
url: 'Media embed URL, YouTube/Vimeo'
|
|
850
|
+
},
|
|
851
|
+
audioBox: {
|
|
852
|
+
title: 'Insert Audio',
|
|
853
|
+
file: 'Select from files',
|
|
854
|
+
url: 'Audio URL'
|
|
855
|
+
},
|
|
856
|
+
browser: {
|
|
857
|
+
tags: 'Tags',
|
|
858
|
+
search: 'Search',
|
|
859
|
+
},
|
|
860
|
+
caption: 'Insert description',
|
|
861
|
+
close: 'Close',
|
|
862
|
+
submitButton: 'Submit',
|
|
863
|
+
revertButton: 'Revert',
|
|
864
|
+
proportion: 'Constrain proportions',
|
|
865
|
+
basic: 'Basic',
|
|
866
|
+
left: 'Left',
|
|
867
|
+
right: 'Right',
|
|
868
|
+
center: 'Center',
|
|
869
|
+
width: 'Width',
|
|
870
|
+
height: 'Height',
|
|
871
|
+
size: 'Size',
|
|
872
|
+
ratio: 'Ratio'
|
|
873
|
+
},
|
|
874
|
+
controller: {
|
|
875
|
+
edit: 'Edit',
|
|
876
|
+
unlink: 'Unlink',
|
|
877
|
+
remove: 'Remove',
|
|
878
|
+
insertRowAbove: 'Insert row above',
|
|
879
|
+
insertRowBelow: 'Insert row below',
|
|
880
|
+
deleteRow: 'Delete row',
|
|
881
|
+
insertColumnBefore: 'Insert column before',
|
|
882
|
+
insertColumnAfter: 'Insert column after',
|
|
883
|
+
deleteColumn: 'Delete column',
|
|
884
|
+
fixedColumnWidth: 'Fixed column width',
|
|
885
|
+
resize100: 'Resize 100%',
|
|
886
|
+
resize75: 'Resize 75%',
|
|
887
|
+
resize50: 'Resize 50%',
|
|
888
|
+
resize25: 'Resize 25%',
|
|
889
|
+
autoSize: 'Auto size',
|
|
890
|
+
mirrorHorizontal: 'Mirror, Horizontal',
|
|
891
|
+
mirrorVertical: 'Mirror, Vertical',
|
|
892
|
+
rotateLeft: 'Rotate left',
|
|
893
|
+
rotateRight: 'Rotate right',
|
|
894
|
+
maxSize: 'Max size',
|
|
895
|
+
minSize: 'Min size',
|
|
896
|
+
tableHeader: 'Table header',
|
|
897
|
+
mergeCells: 'Merge cells',
|
|
898
|
+
splitCells: 'Split Cells',
|
|
899
|
+
HorizontalSplit: 'Horizontal split',
|
|
900
|
+
VerticalSplit: 'Vertical split'
|
|
901
|
+
},
|
|
902
|
+
menu: {
|
|
903
|
+
spaced: 'Spaced',
|
|
904
|
+
bordered: 'Bordered',
|
|
905
|
+
neon: 'Neon',
|
|
906
|
+
translucent: 'Translucent',
|
|
907
|
+
shadow: 'Shadow',
|
|
908
|
+
code: 'Code'
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
```
|
|
913
|
+
|
|
914
|
+
### Appreciation
|
|
915
|
+
|
|
916
|
+
Special Thanks to [JiHong88](https://www.github.com/JiHong88) for the suneditor package.
|
|
917
|
+
|
|
918
|
+
### Pull Requests
|
|
919
|
+
|
|
920
|
+
Pull requests are welcome
|
|
921
|
+
|
|
922
|
+
### License
|
|
923
|
+
|
|
924
|
+
Suneditor React may be freely distributed under the MIT license.
|