forked from xdan/jodit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jodit.ts
1666 lines (1374 loc) · 35.1 KB
/
jodit.ts
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2022 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* [[include:README.md]]
* @packageDocumentation
* @module jodit
*/
import type {
CustomCommand,
ExecCommandCallback,
IDictionary,
IPluginSystem,
IStatusBar,
IViewOptions,
IWorkPlace,
MarkerInfo,
Modes,
IFileBrowser,
IJodit,
IUploader,
ICreate,
IFileBrowserCallBackData,
IStorage,
CanPromise,
IHistory
} from './types';
import { Config } from './config';
import * as constants from './core/constants';
import {
Create,
Dom,
History,
Plugin,
Select,
StatusBar,
STATUSES
} from './modules/';
import {
asArray,
css,
isPromise,
normalizeKeyAliases,
error,
isString,
attr,
isFunction,
resolveElement,
isVoid,
callPromise,
toArray,
markAsAtomic,
ConfigProto,
kebabCase,
isJoditObject,
isNumber
} from './core/helpers/';
import { Storage } from './core/storage/';
import { ViewWithToolbar } from './core/view/view-with-toolbar';
import { lang } from 'jodit/core/constants';
import { instances, pluginSystem, modules } from './core/global';
import { autobind, cache, throttle, watch } from './core/decorators';
const __defaultStyleDisplayKey = 'data-jodit-default-style-display';
const __defaultClassesKey = 'data-jodit-default-classes';
/**
* Class Jodit. Main class
*/
export class Jodit extends ViewWithToolbar implements IJodit {
/** @override */
override className(): string {
return 'Jodit';
}
/**
* Return promise for ready actions
* @example
* ```js
* const jodit = Jodit.make('#editor');
* await jodit.waitForReady();
* jodit.e.fire('someAsyncLoadedPluginEvent', (test) => {
* alert(test);
* });
* ```
*/
waitForReady(): Promise<IJodit> {
if (this.isReady) {
return Promise.resolve(this);
}
return this.async.promise(resolve => {
this.hookStatus('ready', () => resolve(this));
});
}
/**
* Define if object is Jodit
*/
override readonly isJodit: true = true;
/**
* Plain text editor's value
*/
get text(): string {
if (this.editor) {
return this.editor.innerText || '';
}
const div = this.createInside.div();
div.innerHTML = this.getElementValue();
return div.innerText || '';
}
/**
* Return default timeout period in milliseconds for some debounce or throttle functions.
* By default, `{history.timeout}` options
*/
override get defaultTimeout(): number {
return isNumber(this.o.defaultTimeout)
? this.o.defaultTimeout
: Config.defaultOptions.defaultTimeout;
}
/**
* Method wrap usual Has Object in Object helper for prevent deep object merging in options*
*/
static atom<T>(object: T): T {
return markAsAtomic(object);
}
/**
* Factory for creating Jodit instance
*/
static make(element: HTMLElement | string, options?: object): Jodit {
return new Jodit(element, options);
}
/**
* Checks if the element has already been initialized when for Jodit
*/
static isJoditAssigned(
element: HTMLElement
): element is HTMLElement & { component: Jodit } {
return (
element &&
isJoditObject(element.component) &&
!element.component.isInDestruct
);
}
/**
* Default settings
*/
static override get defaultOptions(): Config {
return Config.defaultOptions;
}
static fatMode: boolean = false;
static readonly plugins: IPluginSystem = pluginSystem;
static readonly modules: IDictionary<Function> = modules;
static readonly ns: IDictionary<Function> = modules;
static readonly decorators: IDictionary<Function> = {};
static readonly constants: typeof constants = constants;
static readonly instances: IDictionary<IJodit> = instances;
static readonly lang: any = lang;
static readonly core = {
Plugin
};
private readonly commands: Map<string, Array<CustomCommand<IJodit>>> =
new Map();
private __selectionLocked: MarkerInfo[] | null = null;
private __wasReadOnly = false;
/**
* Container for set/get value
*/
override readonly storage!: IStorage;
readonly createInside: ICreate = new Create(
() => this.ed,
this.o.createAttributes
);
/**
* Editor has focus in this time
*/
editorIsActive = false;
private setPlaceField(field: keyof IWorkPlace, value: any): void {
if (!this.currentPlace) {
this.currentPlace = {} as any;
this.places = [this.currentPlace];
}
this.currentPlace[field] = value;
}
/**
* element It contains source element
*/
get element(): HTMLElement {
return this.currentPlace.element;
}
/**
* editor It contains the root element editor
*/
get editor(): HTMLDivElement | HTMLBodyElement {
return this.currentPlace.editor;
}
set editor(editor: HTMLDivElement | HTMLBodyElement) {
this.setPlaceField('editor', editor);
}
/**
* Container for all staff
*/
override get container(): HTMLDivElement {
return this.currentPlace.container;
}
override set container(container: HTMLDivElement) {
this.setPlaceField('container', container);
}
/**
* workplace It contains source and wysiwyg editors
*/
get workplace(): HTMLDivElement {
return this.currentPlace.workplace;
}
/**
* Statusbar module
*/
get statusbar(): IStatusBar {
return this.currentPlace.statusbar;
}
/**
* iframe Iframe for iframe mode
*/
get iframe(): HTMLIFrameElement | void {
return this.currentPlace.iframe;
}
set iframe(iframe: HTMLIFrameElement | void) {
this.setPlaceField('iframe', iframe);
}
get history(): IHistory {
return this.currentPlace.history;
}
/**
* @deprecated Instead use `Jodit.history`
*/
get observer(): IHistory {
return this.history;
}
/**
* In iframe mode editor's window can be different by owner
*/
get editorWindow(): Window {
return this.currentPlace.editorWindow;
}
set editorWindow(win: Window) {
this.setPlaceField('editorWindow', win);
}
/**
* Alias for this.ew
*/
get ew(): this['editorWindow'] {
return this.editorWindow;
}
/**
* In iframe mode editor's window can be different by owner
*/
get editorDocument(): Document {
return this.currentPlace.editorWindow.document;
}
/**
* Alias for this.ew
*/
get ed(): this['editorDocument'] {
return this.editorDocument;
}
/**
* options All Jodit settings default + second arguments of constructor
*/
override get options(): Config {
return this.currentPlace.options as Config;
}
override set options(opt: Config) {
this.setPlaceField('options', opt);
}
readonly selection!: Select;
/**
* Alias for this.selection
*/
get s(): this['selection'] {
return this.selection;
}
@cache
get uploader(): IUploader {
return this.getInstance('Uploader', this.o.uploader);
}
@cache
get filebrowser(): IFileBrowser {
const jodit = this;
const options = ConfigProto(
{
defaultTimeout: jodit.defaultTimeout,
uploader: jodit.o.uploader,
language: jodit.o.language,
license: jodit.o.license,
theme: jodit.o.theme,
defaultCallback(data: IFileBrowserCallBackData): void {
if (data.files && data.files.length) {
data.files.forEach((file, i) => {
const url = data.baseurl + file;
const isImage = data.isImages
? data.isImages[i]
: false;
if (isImage) {
jodit.s.insertImage(
url,
null,
jodit.o.imageDefaultWidth
);
} else {
jodit.s.insertNode(
jodit.createInside.fromHTML(
`<a href='${url}' title='${url}'>${url}</a>`
)
);
}
});
}
}
},
this.o.filebrowser
);
return jodit.getInstance<IFileBrowser>('FileBrowser', options);
}
private __mode: Modes = constants.MODE_WYSIWYG;
/**
* Editor's mode
*/
get mode(): Modes {
return this.__mode;
}
set mode(mode: Modes) {
this.setMode(mode);
}
/**
* Return real HTML value from WYSIWYG editor.
*/
getNativeEditorValue(): string {
const value: string = this.e.fire('beforeGetNativeEditorValue');
if (isString(value)) {
return value;
}
if (this.editor) {
return this.editor.innerHTML;
}
return this.getElementValue();
}
/**
* Set value to native editor
*/
setNativeEditorValue(value: string): void {
const data = {
value
};
if (this.e.fire('beforeSetNativeEditorValue', data)) {
return;
}
if (this.editor) {
this.editor.innerHTML = data.value;
}
}
/**
* HTML value
*/
get value(): string {
return this.getEditorValue();
}
set value(html: string) {
this.setEditorValue(html);
this.history.processChanges();
}
@throttle()
synchronizeValues(): void {
this.setEditorValue();
}
/**
* Return editor value
*/
getEditorValue(
removeSelectionMarkers: boolean = true,
consumer?: string
): string {
/**
* Triggered before getEditorValue executed.
* If returned not undefined getEditorValue will return this value
* @example
* ```javascript
* var editor = Jodit.make("#redactor");
* editor.e.on('beforeGetValueFromEditor', function () {
* return editor.editor.innerHTML.replace(/a/g, 'b');
* });
* ```
*/
let value: string;
value = this.e.fire('beforeGetValueFromEditor', consumer);
if (value !== undefined) {
return value;
}
value = this.getNativeEditorValue().replace(
constants.INVISIBLE_SPACE_REG_EXP(),
''
);
if (removeSelectionMarkers) {
value = value.replace(
/<span[^>]+id="jodit-selection_marker_[^>]+><\/span>/g,
''
);
}
if (value === '<br>') {
value = '';
}
/**
* Triggered after getEditorValue got value from wysiwyg.
* It can change new_value.value
*
* @example
* ```javascript
* var editor = Jodit.make("#redactor");
* editor.e.on('afterGetValueFromEditor', function (new_value) {
* new_value.value = new_value.value.replace('a', 'b');
* });
* ```
*/
const new_value: { value: string } = { value };
this.e.fire('afterGetValueFromEditor', new_value, consumer);
return new_value.value;
}
private __callChangeCount = 0;
/**
* Set editor html value and if set sync fill source element value
* When method was called without arguments - it is simple way to synchronize editor to element
*/
setEditorValue(value?: string): void {
/**
* Triggered before getEditorValue set value to wysiwyg.
* @example
* ```javascript
* var editor = Jodit.make("#redactor");
* editor.e.on('beforeSetValueToEditor', function (old_value) {
* return old_value.value.replace('a', 'b');
* });
* editor.e.on('beforeSetValueToEditor', function () {
* return false; // disable setEditorValue method
* });
* ```
*/
const newValue: string | undefined | false = this.e.fire(
'beforeSetValueToEditor',
value
);
if (newValue === false) {
return;
}
if (isString(newValue)) {
value = newValue;
}
if (!this.editor) {
if (value !== undefined) {
this.__setElementValue(value);
}
return; // try change value before init or after destruct
}
if (!isString(value) && !isVoid(value)) {
throw error('value must be string');
}
if (value !== undefined && this.getNativeEditorValue() !== value) {
this.setNativeEditorValue(value);
}
this.e.fire('postProcessSetEditorValue');
const old_value = this.getElementValue(),
new_value = this.getEditorValue();
if (
!this.isSilentChange &&
old_value !== new_value &&
this.__callChangeCount < constants.SAFE_COUNT_CHANGE_CALL
) {
this.__setElementValue(new_value);
this.__callChangeCount += 1;
if (!isProd && this.__callChangeCount > 4) {
console.warn(
'Too many recursive changes',
new_value,
old_value
);
}
try {
this.history.upTick();
this.e.fire('change', new_value, old_value);
this.e.fire(this.history, 'change', new_value, old_value);
} finally {
this.__callChangeCount = 0;
}
}
}
/**
* If some plugin changes the DOM directly, then you need to update the content of the original element
*/
@watch(':internalChange')
protected updateElementValue(): void {
this.__setElementValue(this.getEditorValue());
}
/**
* Return source element value
*/
getElementValue(): string {
return (this.element as HTMLInputElement).value !== undefined
? (this.element as HTMLInputElement).value
: this.element.innerHTML;
}
/**
* @deprecated Use `Jodit.value` instead
*/
setElementValue(value?: string): CanPromise<void> {
const oldValue = this.getElementValue();
if (value === undefined || (isString(value) && value !== oldValue)) {
value ??= oldValue;
if (value !== this.getEditorValue()) {
this.setEditorValue(value);
}
}
return this.__setElementValue(value);
}
private __setElementValue(value: string): CanPromise<void> {
if (!isString(value)) {
throw error('value must be string');
}
if (
this.element !== this.container &&
value !== this.getElementValue()
) {
const data = { value };
const res = this.e.fire('beforeSetElementValue', data);
callPromise(res, () => {
if ((this.element as HTMLInputElement).value !== undefined) {
(this.element as HTMLInputElement).value = data.value;
} else {
this.element.innerHTML = data.value;
}
this.e.fire('afterSetElementValue', data);
});
}
}
/**
* Register custom handler for command
*
* @example
* ```javascript
* var jodit = Jodit.make('#editor);
*
* jodit.setEditorValue('test test test');
*
* jodit.registerCommand('replaceString', function (command, needle, replace) {
* var value = this.getEditorValue();
* this.setEditorValue(value.replace(needle, replace));
* return false; // stop execute native command
* });
*
* jodit.execCommand('replaceString', 'test', 'stop');
*
* console.log(jodit.value); // stop test test
*
* // and you can add hotkeys for command
* jodit.registerCommand('replaceString', {
* hotkeys: 'ctrl+r',
* exec: function (command, needle, replace) {
* var value = this.getEditorValue();
* this.setEditorValue(value.replace(needle, replace));
* }
* });
*
* ```
*/
registerCommand(
commandNameOriginal: string,
command: CustomCommand<IJodit>,
options?: {
stopPropagation: boolean;
}
): IJodit {
const commandName: string = commandNameOriginal.toLowerCase();
let commands = this.commands.get(commandName);
if (commands === undefined) {
commands = [];
this.commands.set(commandName, commands);
}
commands.push(command);
if (!isFunction(command)) {
const hotkeys: string | string[] | void =
this.o.commandToHotkeys[commandName] ||
this.o.commandToHotkeys[commandNameOriginal] ||
command.hotkeys;
if (hotkeys) {
this.registerHotkeyToCommand(
hotkeys,
commandName,
options?.stopPropagation
);
}
}
return this;
}
/**
* Register hotkey for command
*/
registerHotkeyToCommand(
hotkeys: string | string[],
commandName: string,
shouldStop: boolean = true
): void {
const shortcuts: string = asArray(hotkeys)
.map(normalizeKeyAliases)
.map(hotkey => hotkey + '.hotkey')
.join(' ');
this.e
.off(shortcuts)
.on(shortcuts, (type: string, stop: { shouldStop: boolean }) => {
if (stop) {
stop.shouldStop = shouldStop ?? true;
}
return this.execCommand(commandName); // because need `beforeCommand`
});
}
/**
* Execute command editor
*
* @param command - command. It supports all the
* {@link https://developer.mozilla.org/ru/docs/Web/API/Document/execCommand#commands} and a number of its own
* for example applyStyleProperty. Comand fontSize receives the second parameter px,
* formatBlock and can take several options
* @example
* ```javascript
* this.execCommand('fontSize', 12); // sets the size of 12 px
* this.execCommand('underline');
* this.execCommand('formatBlock', 'p'); // will be inserted paragraph
* ```
*/
execCommand(
command: string,
showUI: boolean = false,
value: null | any = null
): void {
if (!this.s.isFocused()) {
this.s.focus();
}
if (this.o.readonly && command !== 'selectall') {
return;
}
let result: any;
command = command.toLowerCase();
/**
* Called before any command
* @param command - Command name in lowercase
* @param second - The second parameter for the command
* @param third - The third option is for the team
* @example
* ```javascript
* parent.e.on('beforeCommand', function (command) {
* if (command === 'justifyCenter') {
* var p = parent.c.element('p')
* parent.s.insertNode(p)
* parent.s.setCursorIn(p);
* p.style.textAlign = 'justyfy';
* return false; // break execute native command
* }
* })
* ```
*/
result = this.e.fire('beforeCommand', command, showUI, value);
if (result !== false) {
result = this.execCustomCommands(command, showUI, value);
}
if (result !== false) {
this.s.focus();
if (command === 'selectall') {
this.s.select(this.editor, true);
this.s.expandSelection();
} else {
try {
result = this.nativeExecCommand(command, showUI, value);
} catch (e) {
if (!isProd) {
throw e;
}
}
}
}
/**
* It called after any command
* @param command - name command
* @param second - The second parameter for the command
* @param third - The third option is for the team
*/
this.e.fire('afterCommand', command, showUI, value);
this.setEditorValue(); // synchrony
return result;
}
/**
* Don't raise a change event
*/
private isSilentChange: boolean = false;
/**
* Exec native command
*/
nativeExecCommand(
command: string,
showUI: boolean = false,
value: null | any = null
): boolean {
this.isSilentChange = true;
try {
return this.ed.execCommand(command, showUI, value);
} finally {
this.isSilentChange = false;
}
}
private execCustomCommands(
commandName: string,
second: any = false,
third: null | any = null
): false | void {
commandName = commandName.toLowerCase();
const commands = this.commands.get(commandName);
if (commands !== undefined) {
let result: any;
commands.forEach((command: CustomCommand<Jodit>) => {
let callback: ExecCommandCallback<Jodit>;
if (isFunction(command)) {
callback = command;
} else {
callback = command.exec;
}
const resultCurrent: any = (callback as any).call(
this,
commandName,
second,
third
);
if (resultCurrent !== undefined) {
result = resultCurrent;
}
});
return result;
}
}
/**
* Disable selecting
*/
override lock(name = 'any'): boolean {
if (super.lock(name)) {
this.__selectionLocked = this.s.save();
this.s.clear();
this.editor.classList.add('jodit_lock');
this.e.fire('lock', true);
return true;
}
return false;
}
/**
* Enable selecting
*/
override unlock(): boolean {
if (super.unlock()) {
this.editor.classList.remove('jodit_lock');
if (this.__selectionLocked) {
this.s.restore();
}
this.e.fire('lock', false);
return true;
}
return false;
}
/**
* Return current editor mode: Jodit.MODE_WYSIWYG, Jodit.MODE_SOURCE or Jodit.MODE_SPLIT
*/
getMode(): Modes {
return this.mode;
}
isEditorMode(): boolean {
return this.getRealMode() === constants.MODE_WYSIWYG;
}
/**
* Return current real work mode. When editor in MODE_SOURCE or MODE_WYSIWYG it will
* return them, but then editor in MODE_SPLIT it will return MODE_SOURCE if
* Textarea(CodeMirror) focused or MODE_WYSIWYG otherwise
*
* @example
* ```javascript
* var editor = Jodit.make('#editor');
* console.log(editor.getRealMode());
* ```
*/
getRealMode(): Modes {
if (this.getMode() !== constants.MODE_SPLIT) {
return this.getMode();
}
const active = this.od.activeElement;
if (
active &&
(active === this.iframe ||
Dom.isOrContains(this.editor, active) ||
Dom.isOrContains(this.toolbar.container, active))
) {
return constants.MODE_WYSIWYG;
}
return constants.MODE_SOURCE;
}
/**
* Set current mode
*/
setMode(mode: number | string): void {
const oldMode: Modes = this.getMode();
const data = {
mode: parseInt(mode.toString(), 10) as Modes
},
modeClasses = [
'jodit-wysiwyg_mode',
'jodit-source__mode',
'jodit_split_mode'
];
/**
* Triggered before setMode executed. If returned false method stopped
* @param data - PlainObject `{mode: {string}}` In handler you can change data.mode
* @example
* ```javascript
* var editor = Jodit.make("#redactor");
* editor.e.on('beforeSetMode', function (data) {
* data.mode = Jodit.MODE_SOURCE; // not respond to the mode change. Always make the source code mode
* });
* ```
*/
if (this.e.fire('beforeSetMode', data) === false) {
return;
}
this.__mode = [
constants.MODE_SOURCE,
constants.MODE_WYSIWYG,
constants.MODE_SPLIT
].includes(data.mode)
? data.mode
: constants.MODE_WYSIWYG;
if (this.o.saveModeInStorage) {
this.storage.set('jodit_default_mode', this.mode);
}
modeClasses.forEach(className => {
this.container.classList.remove(className);
});
this.container.classList.add(modeClasses[this.mode - 1]);
/**
* Triggered after setMode executed