-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
63 lines (50 loc) · 1.61 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
/** main class */
export default class jmarkd {
public config: Config
constructor(config: Config)
/** remove events etc */
public destroy(): void
/** get text from textarea */
public save(): string
}
/** jmarkd uses this names for elements */
export enum DomName {
container = 'jmarkd',
toolbar = 'jmarkd__toolbar',
ToolbarElement = 'jmarkd__toolbar__element',
textarea = 'jmarkd__textarea',
preview = 'jmarkd__preview'
}
/** main config */
export type Config = {
/** jmarkd container */
container: HTMLDivElement
/** textarea placeholder */
placeholder?: string
/** toolbar */
toolbar?: ToolbarConfig
/** initial data */
input?: string
}
/** if you want to see default elements and configs see './src/factory' dir */
export type ToolbarConfig = {
/** names of elements displayed in toolbar. Like: ['heading', 'bold', 'link'] */
displayed?: string[]
/** toolbar elements */
elements: {
/** load this elements. {'element name': element} */
boot?: Record<string, ToolbarElement>,
/** elements config. {'element name': element config} */
config?: { [name: string]: any }
}
}
export interface ToolbarElement {
/** item icon. SVG (prefer)/HTML/etc */
get icon(): string
/** set config to element */
setConfig?: (config: any) => void
/** get shortcut (KeyboardEvent.code). Returns array like ['ControlLeft', 'KeyA'] */
getShortcut?: () => string[]
/** when click on item */
onClick(textarea: HTMLTextAreaElement): void
}