/
types.d.ts
313 lines (258 loc) · 5.84 KB
/
types.d.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
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2024 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module types
*/
import type { IViewBased } from './view';
import type { IAsync } from './async';
export type IDictionary<T = any, K extends string = string> = {
[key in K]: T;
};
export type Prettify<T> = {
[P in keyof T]: T[P];
};
export type CanPromise<T> = T | Promise<T>;
export type CanUndef<T> = T | undefined;
export type CanArray<T> = T | Array<T>;
export type Nullable<T> = T | null;
export interface IInitable {
init(jodit: IViewBased): any;
}
export interface IDestructible {
destruct(jodit?: IViewBased): any;
}
export type ComponentStatus =
| 'beforeInit'
| 'ready'
| 'beforeDestruct'
| 'destructed';
export interface IContainer {
container: HTMLElement;
}
interface IComponent<T extends IViewBased = IViewBased> extends IDestructible {
readonly async: IAsync;
readonly ownerDocument: Document;
readonly od: this['ownerDocument'];
readonly ownerWindow: Window;
readonly ow: this['ownerWindow'];
get<T>(chain: string, obj?: IDictionary): Nullable<T>;
readonly componentName: string;
className(): string;
getFullElName(elementName: string): string;
getFullElName(elementName: string, mod: string): string;
getFullElName(
elementName: string,
mod?: string,
modValue?: boolean | string
): string;
readonly uid: string;
readonly isDestructed: boolean;
readonly isInDestruct: boolean;
readonly isReady: boolean;
readonly componentStatus: ComponentStatus;
setStatus(componentStatus: ComponentStatus): void;
hookStatus(
status: ComponentStatus,
callback: (component: this) => void
): void;
bindDestruct(component: IComponent): this;
}
interface IViewComponent<T extends IViewBased = IViewBased> extends IComponent {
jodit: T;
readonly j: T;
setParentView(jodit: T): this;
readonly i18n: T['i18n'];
readonly defaultTimeout: number;
}
export type NodeCondition<T extends Node = Node> = (
node: Nullable<T>
) => boolean | null | false | void | '';
/**
* Bound interface
*/
export interface IBound {
top: number;
left: number;
width: number;
height: number;
}
export interface IBoundP {
top: number;
left: number;
width?: number;
height?: number;
}
export interface IPoint {
x: number;
y: number;
}
export interface IPointBound extends IPoint {
w: number;
h: number;
}
export interface ISelectionRange {
startContainer: Text;
startOffset: number;
endContainer: Text;
endOffset: number;
}
export interface IRGB {
r: number;
g: number;
b: number;
}
export interface IPermissions {
allowFiles: boolean;
allowFileMove: boolean;
allowFileUpload: boolean;
allowFileUploadRemote: boolean;
allowFileRemove: boolean;
allowFileRename: boolean;
allowFolders: boolean;
allowFolderCreate: boolean;
allowFolderMove: boolean;
allowFolderRemove: boolean;
allowFolderRename: boolean;
allowImageResize: boolean;
allowImageCrop: boolean;
[key: string]: boolean;
}
export interface CallbackFunction<T = any> {
(this: T, ...args: any[]): any | void;
}
interface CallbackFunction {
options?: unknown;
}
export type BooleanFunction<T = any> = (this: T, ...args: any[]) => boolean;
export type ExecCommandCallback<T, C extends string> =
| ((
this: T,
command: C,
value?: string,
next?: any,
...args: unknown[]
) => void | boolean | Promise<void | boolean>)
| ((
this: T,
command: C,
value: string,
next: string,
...args: unknown[]
) => void | boolean | Promise<void | boolean>);
export interface ICommandType<T, C extends string> {
exec: ExecCommandCallback<T, C>;
hotkeys?: string | string[];
}
export type CustomCommand<T, C extends string> =
| ICommandType<T, C>
| ExecCommandCallback<T, C>;
export interface IHasScroll {
clientTop: number;
clientLeft: number;
scrollTop: number;
scrollLeft: number;
}
export interface RangeType {
startContainer: number[];
startOffset: number;
endContainer: number[];
endOffset: number;
}
export interface SnapshotType {
html: string;
range: RangeType;
}
export interface ImageEditorOptions {
min_width: number;
min_height: number;
/**
* Close editor after save image
*/
closeAfterSave: boolean;
/**
* Default dialog width by screen
*/
width: string | number;
/**
* Default dialog height by screen
*/
height: string | number;
/**
* Show tab cropping
*/
crop: boolean;
/**
* Show tab resizing
*/
resize: boolean;
/**
* Keep aspect ratio on resize
*/
resizeUseRatio: boolean;
/**
* Minimal width on resize
*/
resizeMinWidth: number;
/**
* Minimal height on resize
*/
resizeMinHeight: number;
/**
* Keep aspect ratio on crop
*/
cropUseRatio: boolean;
/**
* In the tab, crop the image is displayed not in real size
*/
cropDefaultWidth: string | number;
cropDefaultHeight: string | number;
}
export type InsertMode =
| 'insert_as_html'
| 'insert_as_text'
| 'insert_clear_html'
| 'insert_only_text';
export type ImageAction = 'resize' | 'crop';
export type ImageHAlign = 'normal' | 'left' | 'right' | 'center' | '';
export interface ImageBox {
w: number;
h: number;
x?: number;
y?: number;
}
export interface ImageEditorActionBox {
action: ImageAction;
box: ImageBox;
}
export interface EventHandlerBlock {
event: string;
originalCallback: CallbackFunction;
syntheticCallback: CallbackFunction;
}
declare global {
interface HTMLElementTagNameMap {
jodit: HTMLDivElement;
svg: HTMLElement;
path: HTMLElement;
font: HTMLElement;
'jodit-media': HTMLElement;
}
}
export type HTMLTagNames = Prettify<keyof HTMLElementTagNameMap>;
export type Modes = 1 | 2 | 3;
declare global {
interface MouseEvent {
buffer?: IDictionary;
}
}
export interface FuzzySearch {
(
needle: string,
haystack: string,
offset?: number,
maxDistance?: number
): [number, number];
}