forked from codex-team/editor.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
213 lines (177 loc) · 3.81 KB
/
api.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
import IInputOutputData from './input-output-data';
/**
* CodeX Editor Public API
*
* @copyright <CodeX Team> 2018
*/
export interface IAPI {
blocks: IBlocksAPI;
caret: ICaretAPI;
events: IEventsAPI;
listener: IListenerAPI;
sanitizer: ISanitizerAPI;
saver: ISaverAPI;
selection: ISelectionAPI;
styles: IStylesAPI;
toolbar: IToolbarAPI;
}
/**
* Working with Blocks list: moving, removing, etc
*/
export interface IBlocksAPI {
/**
* Clears Blocks list
*/
clear: () => void;
/**
* Fills editor with Blocks data
*/
render: (data: IInputOutputData) => void;
/**
* Removes block
*/
delete: (blockIndex?: number) => void;
/**
* Swap two Blocks by positions
* @param {number} fromIndex - position of first Block
* @param {number} toIndex - position of second Block
*/
swap: (fromIndex: number, toIndex: number) => void;
/**
* Returns block by passed index
*
* @param {Number} index - needed block with index
* @return {object}
*/
getBlockByIndex: (index: number) => object;
/**
* Returns current block index
* @return {number}
*/
getCurrentBlockIndex: () => number;
/**
* Returns Block's count
* @return {number}
*/
getBlocksCount: () => number;
/**
* Stretch Block's content
* @param {number} index - index of Block
* @param {boolean} [status] - true to enable, false to disable
*/
stretchBlock: (index: number, status: boolean) => void;
/**
* Insert new initial typed Block
*/
insertNewBlock: () => void;
}
/**
* Methods for working with Caret
*/
export interface ICaretAPI {
/**
* @todo Add caret methods
*/
}
/**
* Events Module API methods
*/
export interface IEventsAPI {
/**
* Subsribe on events
*/
on: (eventName: string, callback: () => void) => void;
/**
* Trigger subsribed callbacks
*/
emit: (eventName: string, data: object) => void;
/**
* Unsubsribe callback
*/
off: (eventName: string, callback: () => void) => void;
}
/**
* DOM Listener API
*/
export interface IListenerAPI {
/**
* Adds event listener
* @param {HTMLElement} element
* @param {string} eventType
* @param {() => void} handler
* @param useCapture
* @return {boolean}
*/
on: (element: HTMLElement, eventType: string, handler: () => void, useCapture: boolean) => void;
/**
* Remove event listener
* @param {HTMLElement} element
* @param {string} eventType
* @param {() => void} handler
*/
off: (element: HTMLElement, eventType: string, handler: () => void) => void;
}
/**
* Sanitizer's methods
*/
export interface ISanitizerAPI {
/**
* Clean taint string from disallowed tags and attributes
*
* @param taintString
* @param config
*/
clean: (taintString, config?) => string;
}
/**
* Saver's methods
*/
export interface ISaverAPI {
/**
* Return current blocks
*
* @return {IInputOutputData}
*/
save: () => IInputOutputData;
}
/**
* SelectionUtils's methods
*/
export interface ISelectionAPI {
/**
* Looks ahead to find passed tag from current selection
*
* @param {String} tagName
* @param {String} className
*/
findParentTag: (tagName: string, className: string) => HTMLElement|null;
/**
* Expands selection range to the passed parent node
*
* @param {HTMLElement} node
*/
expandToTag: (node: HTMLElement) => void;
}
export interface IStylesAPI {
block: string;
inlineToolButton: string;
inlineToolButtonActive: string;
input: string;
loader: string;
settingsButton: string;
settingsButtonActive: string;
}
/**
* Toolbar's methods
* Basic toolbar methods
*/
export interface IToolbarAPI {
/**
* Opens only toolbar
*/
open: () => void;
/**
* Closes toolbar. If toolbox or toolbar-blockSettings are opened then they will be closed too
*/
close: () => void;
}