/
editor.js
87 lines (74 loc) · 1.61 KB
/
editor.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
/**
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/
/**
* Mock of class that representing a basic, generic editor.
*
* @see: https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html
*/
export default class Editor {
constructor() {
this.initializeProperties();
}
initializeProperties() {
this.model = Editor._model;
this.editing = Editor._editing;
this.data = {
get() {
return '';
},
set() {
}
};
this._readOnlyLocks = new Set();
}
get isReadOnly() {
return this._readOnlyLocks.size > 0;
}
set isReadOnly( value ) {
throw new Error( 'Cannot use this setter anymore' );
}
enableReadOnlyMode( lockId, value ) {
if ( value ) {
this._readOnlyLocks.add( lockId );
} else {
this.disableReadOnlyMode( lockId );
}
}
disableReadOnlyMode( lockId ) {
this._readOnlyLocks.delete( lockId );
}
destroy() {
return Promise.resolve();
}
// Implements the `DataApi` interface.
// See: https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_utils_dataapimixin-DataApi.html
setData( ...args ) {
return this.data.set.call( this, ...args );
}
getData( ...args ) {
return this.data.get.call( this, ...args );
}
static create() {
return Promise.resolve( new this() );
}
}
// In order to tests events, we need to somehow mock those properties.
Editor._model = {
document: createDocument()
};
Editor._editing = {
view: {
document: createDocument()
}
};
function createDocument() {
return {
on() {},
off() {},
getRootNames() {
return [ 'main' ];
}
};
}