-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
index.d.ts
864 lines (624 loc) · 21 KB
/
index.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
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
// Type definitions for TOAST UI Editor v2.1.1
// TypeScript Version: 3.2.2
/// <reference types="codemirror" />
declare namespace toastui {
type SquireExt = any;
type HandlerFunc = (...args: any[]) => void;
type ReplacerFunc = (inputString: string) => string;
type CodeMirrorType = CodeMirror.EditorFromTextArea;
type CommandManagerExecFunc = (name: string, ...args: any[]) => any;
type PopupTableUtils = LayerPopup;
type AddImageBlobHook = (fileOrBlob: File | Blob, callback: Function, source: string) => void;
type Plugin = (editor: Editor | Viewer, options: any) => void;
type PreviewStyle = 'tab' | 'vertical';
type CustomHTMLSanitizer = (content: string) => string | DocumentFragment;
type LinkAttribute = Partial<{
rel: string;
target: string;
contenteditable: boolean | 'true' | 'false';
hreflang: string;
type: string;
}>;
type AutolinkParser = (
content: string
) => {
url: string;
text: string;
range: [number, number];
}[];
type ExtendedAutolinks = boolean | AutolinkParser;
type Sanitizer = (content: string) => string | DocumentFragment;
// @TODO: change toastMark type definition to @toast-ui/toastmark type file through importing
// Toastmark custom renderer type
type BlockNodeType =
| 'document'
| 'list'
| 'blockQuote'
| 'item'
| 'heading'
| 'thematicBreak'
| 'paragraph'
| 'codeBlock'
| 'htmlBlock'
| 'table'
| 'tableHead'
| 'tableBody'
| 'tableRow'
| 'tableCell'
| 'tableDelimRow'
| 'tableDelimCell'
| 'refDef';
type InlineNodeType =
| 'code'
| 'text'
| 'emph'
| 'strong'
| 'strike'
| 'link'
| 'image'
| 'htmlInline'
| 'linebreak'
| 'softbreak';
type NodeType = BlockNodeType | InlineNodeType;
type SourcePos = [[number, number], [number, number]];
interface NodeWalker {
current: MdNode | null;
root: MdNode;
entering: boolean;
next(): { entering: boolean; node: MdNode } | null;
resumeAt(node: MdNode, entering: boolean): void;
}
interface MdNode {
type: NodeType;
id: number;
parent: MdNode | null;
prev: MdNode | null;
next: MdNode | null;
sourcepos?: SourcePos;
firstChild: MdNode | null;
lastChild: MdNode | null;
literal: string | null;
isContainer(): boolean;
unlink(): void;
replaceWith(node: MdNode): void;
insertAfter(node: MdNode): void;
insertBefore(node: MdNode): void;
appendChild(child: MdNode): void;
prependChild(child: MdNode): void;
walker(): NodeWalker;
}
interface TagToken {
tagName: string;
outerNewLine?: boolean;
innerNewLine?: boolean;
}
interface OpenTagToken extends TagToken {
type: 'openTag';
classNames?: string[];
attributes?: Record<string, string>;
selfClose?: boolean;
}
interface CloseTagToken extends TagToken {
type: 'closeTag';
}
interface TextToken {
type: 'text';
content: string;
}
interface RawHTMLToken {
type: 'html';
content: string;
outerNewLine?: boolean;
}
type HTMLToken = OpenTagToken | CloseTagToken | TextToken | RawHTMLToken;
interface ContextOptions {
gfm: boolean;
softbreak: string;
nodeId: boolean;
tagFilter: boolean;
convertors?: CustomHTMLRendererMap;
}
interface Context {
entering: boolean;
leaf: boolean;
options: Omit<ContextOptions, 'gfm' | 'convertors'>;
getChildrenText: (node: MdNode) => string;
skipChildren: () => void;
origin?: () => ReturnType<CustomHTMLRenderer>;
}
export type CustomHTMLRenderer = (node: MdNode, context: Context) => HTMLToken | HTMLToken[] | null;
type CustomHTMLRendererMap = Partial<Record<NodeType, CustomHTMLRenderer>>;
// Toastmark custom renderer type end
interface SelectionRange {
from: {
row: number;
cell: number;
};
to: {
row: number;
cell: number;
};
}
interface ToolbarState {
strong: boolean;
emph: boolean;
strike: boolean;
code: boolean;
codeBlock: boolean;
blockQuote: boolean;
table: boolean;
heading: boolean;
list: boolean;
orderedList: boolean;
taskList: boolean;
}
type WysiwygToolbarState = ToolbarState & {
source: 'wysiwyg';
};
type MarkdownToolbarState = ToolbarState & {
thematicBreak: boolean;
source: 'markdown';
};
type SourceType = 'wysiwyg' | 'markdown';
interface EventMap {
load?: (param: Editor) => void;
change?: (param: { source: SourceType | 'viewer'; data: MouseEvent }) => void;
stateChange?: (param: MarkdownToolbarState | WysiwygToolbarState) => void;
focus?: (param: { source: SourceType }) => void;
blur?: (param: { source: SourceType }) => void;
}
interface ViewerHookMap {
previewBeforeHook?: (html: string) => void | string;
}
type EditorHookMap = ViewerHookMap & {
addImageBlobHook?: (
blob: Blob | File,
callback: (url: string, altText: string) => void
) => void;
};
interface ToMarkOptions {
gfm?: boolean;
renderer?: any;
}
export interface Convertor {
initHtmlSanitizer(sanitizer: Sanitizer): void;
toHTML(makrdown: string): string;
toHTMLWithCodeHighlight(markdown: string): string;
toMarkdown(html: string, toMarkdownOptions: ToMarkOptions): string;
}
export interface ConvertorClass {
new (em: EventManager, options: ConvertorOptions): Convertor;
}
export interface ConvertorOptions {
linkAttribute: LinkAttribute;
customHTMLRenderer: CustomHTMLRenderer;
extendedAutolinks: boolean | AutolinkParser;
referenceDefinition: boolean;
}
export interface EditorOptions {
el: HTMLElement;
height?: string;
minHeight?: string;
initialValue?: string;
previewStyle?: PreviewStyle;
initialEditType?: string;
events?: EventMap;
hooks?: EditorHookMap;
language?: string;
useCommandShortcut?: boolean;
useDefaultHTMLSanitizer?: boolean;
usageStatistics?: boolean;
toolbarItems?: (string | ToolbarButton)[];
hideModeSwitch?: boolean;
plugins?: Plugin[];
extendedAutolinks?: ExtendedAutolinks;
customConvertor?: ConvertorClass;
placeholder?: string;
linkAttribute?: LinkAttribute;
customHTMLRenderer?: CustomHTMLRenderer;
referenceDefinition?: boolean;
customHTMLSanitizer?: CustomHTMLSanitizer;
previewHighlight?: boolean;
}
export interface ViewerOptions {
el: HTMLElement;
initialValue?: string;
events?: EventMap;
hooks?: ViewerHookMap;
plugins?: Plugin[];
useDefaultHTMLSanitizer?: boolean;
extendedAutolinks?: ExtendedAutolinks;
customConvertor?: ConvertorClass;
linkAttribute?: LinkAttribute;
customHTMLRenderer?: CustomHTMLRenderer;
referenceDefinition?: boolean;
customHTMLSanitizer?: CustomHTMLSanitizer;
}
interface MarkdownEditorOptions {
height?: string;
}
interface WysiwygEditorOptions {
useDefaultHTMLSanitizer?: boolean;
linkAttribute?: LinkAttribute;
}
interface LanguageData {
[propType: string]: string;
}
interface ToolbarButton {
type: string;
options: ButtonOptions;
}
interface ButtonOptions {
el?: HTMLElement;
className?: string;
command?: string;
event?: string;
text?: string;
tooltip?: string;
style?: string;
state?: string;
}
class UIController {
public tagName: string;
public className: string;
public el: HTMLElement;
public on(aType: string | object, aFn: (...args: any[]) => void): void;
public off(type: string, fn: (...args: any[]) => void): void;
public remove(): void;
public trigger(eventTypeEvent: string, eventData?: any): void;
public destroy(): void;
}
class ToolbarItem extends UIController {
public static name: string;
public static className: string;
public getName(): string;
}
interface CommandType {
MD: 0;
WW: 1;
GB: 2;
}
interface CommandProps {
name: string;
type: number;
}
class Command {
public static TYPE: CommandType;
public static factory(typeStr: string, props: CommandProps): Command;
constructor(name: string, type: number, keyMap?: string[]);
public getName(): string;
public getType(): number;
public isGlobalType(): boolean;
public isMDType(): boolean;
public isWWType(): boolean;
public setKeyMap(win: string, mac: string): void;
}
interface LayerPopupOptions {
openerCssQuery?: string[];
closerCssQuery?: string[];
el: HTMLElement;
content?: HTMLElement | string;
textContent?: string;
title: string;
header?: boolean;
target?: HTMLElement;
modal: boolean;
headerButtons?: string;
}
interface LayerPopup extends UIController {
setContent(content: HTMLElement): void;
setTitle(title: string): void;
getTitleElement(): HTMLElement;
hide(): void;
show(): void;
isShow(): boolean;
remove(): void;
setFitToWindow(fit: boolean): void;
isFitToWindow(): boolean;
toggleFitToWindow(): boolean;
}
interface ModeSwitchType {
MARKDOWN: 'markdown';
WYSIWYG: 'wysiwyg';
}
interface ModeSwitch extends UIController {
TYPE: ModeSwitchType;
isShown(): boolean;
show(): void;
hide(): void;
}
class Toolbar extends UIController {
public disableAllButton(): void;
public enableAllButton(): void;
public getItems(): ToolbarItem[];
public getItem(index: number): ToolbarItem;
public setItems(items: ToolbarItem[]): void;
public addItem(item: ToolbarItem | ToolbarButton | string): void;
public insertItem(index: number, item: ToolbarItem | ToolbarButton | string): void;
public indexOfItem(item: ToolbarItem): number;
public removeItem(item: ToolbarItem | number, destroy?: boolean): ToolbarItem | undefined;
public removeAllItems(): void;
}
interface UI {
createPopup(options: LayerPopupOptions): LayerPopup;
getEditorHeight(): number;
getEditorSectionHeight(): number;
getModeSwitch(): ModeSwitch;
getPopupTableUtils(): PopupTableUtils;
getToolbar(): Toolbar;
hide(): void;
remove(): void;
setToolbar(toolbar: Toolbar): void;
show(): void;
}
interface CommandManagerOptions {
useCommandShortcut?: boolean;
}
interface CommandPropsOptions {
name: string;
keyMap?: string[];
exec?: CommandManagerExecFunc;
}
class CommandManager {
public static command(type: string, props: CommandPropsOptions): Command;
constructor(base: Editor, options?: CommandManagerOptions);
public addCommand(command: Command): Command;
public exec(name: string, ...args: any[]): any;
}
class CodeBlockManager {
public createCodeBlockHtml(language: string, codeText: string): string;
public getReplacer(language: string): ReplacerFunc;
public setReplacer(language: string, replacer: ReplacerFunc): void;
}
interface RangeType {
start: {
line: number;
ch: number;
};
end: {
line: number;
ch: number;
};
}
interface MdTextObject {
setRange(range: RangeType): void;
setEndBeforeRange(range: RangeType): void;
expandStartOffset(): void;
expandEndOffset(): void;
getTextContent(): RangeType;
replaceContent(content: string): void;
deleteContent(): void;
peekStartBeforeOffset(offset: number): RangeType;
}
interface WwTextObject {
deleteContent(): void;
expandEndOffset(): void;
expandStartOffset(): void;
getTextContent(): string;
peekStartBeforeOffset(offset: number): string;
replaceContent(content: string): void;
setEndBeforeRange(range: Range): void;
setRange(range: Range): void;
}
interface FindOffsetNodeInfo {
container: Node;
offsetInContainer: number;
offset: number;
}
interface NodeInfo {
id?: string;
tagName: string;
className?: string;
}
class WwCodeBlockManager {
constructor(wwe: WysiwygEditor);
public destroy(): void;
public convertNodesToText(nodes: Node[]): string;
public isInCodeBlock(range: Range): boolean;
public prepareToPasteOnCodeblock(nodes: Node[]): DocumentFragment;
public modifyCodeBlockForWysiwyg(node: HTMLElement): void;
}
class WwTableManager {
constructor(wwe: WysiwygEditor);
public destroy(): void;
public getTableIDClassName(): string;
public isInTable(range: Range): boolean;
public isNonTextDeleting(range: Range): boolean;
public isTableOrSubTableElement(pastingNodeName: string): boolean;
public pasteClipboardData(clipboardTable: Node): boolean;
public prepareToTableCellStuffing(
trs: HTMLElement
): { maximumCellLength: number; needTableCellStuffingAid: boolean };
public resetLastCellNode(): void;
public setLastCellNode(node: HTMLElement): void;
public tableCellAppendAidForTableElement(node: HTMLElement): void;
public updateTableHtmlOfClipboardIfNeed(clipboardContainer: HTMLElement): void;
public wrapDanglingTableCellsIntoTrIfNeed(container: HTMLElement): HTMLElement | null;
public wrapTheadAndTbodyIntoTableIfNeed(container: HTMLElement): HTMLElement | null;
public wrapTrsIntoTbodyIfNeed(container: HTMLElement): HTMLElement | null;
}
class WwTableSelectionManager {
constructor(wwe: WysiwygEditor);
public createRangeBySelectedCells(): void;
public destroy(): void;
public getSelectedCells(): HTMLElement;
public getSelectionRangeFromTable(
selectionStart: HTMLElement,
selectionEnd: HTMLElement
): SelectionRange;
public highlightTableCellsBy(selectionStart: HTMLElement, selectionEnd: HTMLElement): void;
public removeClassAttrbuteFromAllCellsIfNeed(): void;
public setTableSelectionTimerIfNeed(selectionStart: HTMLElement): void;
public styleToSelectedCells(onStyle: SquireExt, options?: object): void;
}
// @TODO: change toastMark type definition to @toast-ui/toastmark type file through importing
class MarkdownEditor {
static factory(
el: HTMLElement,
eventManager: EventManager,
toastMark: any,
options: MarkdownEditorOptions
): MarkdownEditor;
constructor(
el: HTMLElement,
eventManager: EventManager,
toastMark: any,
options: MarkdownEditorOptions
);
public getTextObject(range: Range | RangeType): MdTextObject;
public setValue(markdown: string, cursorToEnd?: boolean): void;
public resetState(): void;
public getMdDocument(): any;
}
class WysiwygEditor {
static factory(
el: HTMLElement,
eventManager: EventManager,
options: WysiwygEditorOptions
): WysiwygEditor;
constructor(el: HTMLElement, eventManager: EventManager, options: WysiwygEditorOptions);
public addKeyEventHandler(keyMap: string | string[], handler: HandlerFunc): void;
public addWidget(range: Range, node: Node, style: string, offset?: number): void;
public blur(): void;
public breakToNewDefaultBlock(range: Range, where?: string): void;
public changeBlockFormatTo(targetTagName: string): void;
public findTextNodeFilter(): boolean;
public fixIMERange(): void;
public focus(): void;
public getEditor(): SquireExt;
public getIMERange(): Range;
public getRange(): Range;
public getTextObject(range: Range): WwTextObject;
public getValue(): string;
public hasFormatWithRx(rx: RegExp): boolean;
public init(useDefaultHTMLSanitizer: boolean): void;
public insertText(text: string): void;
public makeEmptyBlockCurrentSelection(): void;
public moveCursorToEnd(): void;
public moveCursorToStart(): void;
public postProcessForChange(): void;
public readySilentChange(): void;
public remove(): void;
public removeKeyEventHandler(keyMap: string, handler: HandlerFunc): void;
public replaceContentText(container: Node, from: string, to: string): void;
public replaceRelativeOffset(content: string, offset: number, overwriteLength: number): void;
public replaceSelection(content: string, range: Range): void;
public reset(): void;
public restoreSavedSelection(): void;
public saveSelection(range: Range): void;
public scrollTop(value: number): boolean;
public setHeight(height: number | string): void;
public setPlaceholder(placeholder: string): void;
public setMinHeight(minHeight: number): void;
public setRange(range: Range): void;
public getLinkAttribute(): LinkAttribute;
public setSelectionByContainerAndOffset(
startContainer: Node,
startOffset: number,
endContainer: Node,
endOffset: number
): Range;
public setValue(html: string, cursorToEnd?: boolean): void;
public unwrapBlockTag(condition?: (tagName: string) => boolean): void;
public getBody(): HTMLElement;
public scrollIntoCursor(): void;
public isInTable(range: Range): boolean;
}
class EventManager {
public addEventType(type: string): void;
public emit(eventName: string): any[];
public emitReduce(eventName: string, sourceText: string): string;
public listen(typeStr: string, handler: HandlerFunc): void;
public removeEventHandler(typeStr: string, handler?: HandlerFunc): void;
}
export class Editor {
public static codeBlockManager: CodeBlockManager;
public static CommandManager: CommandManager;
public static isViewer: boolean;
public static WwCodeBlockManager: WwCodeBlockManager;
public static WwTableManager: WwTableManager;
public static WwTableSelectionManager: WwTableSelectionManager;
public static factory(options: EditorOptions): Editor | Viewer;
public static getInstances(): Editor[];
public static setLanguage(code: string, data: LanguageData): void;
constructor(options: EditorOptions);
public addHook(type: string, handler: HandlerFunc): void;
public addWidget(selection: Range, node: Node, style: string, offset?: number): void;
public afterAddedCommand(): void;
public blur(): void;
public changeMode(mode: string, isWithoutFocus?: boolean): void;
public changePreviewStyle(style: PreviewStyle): void;
public exec(name: string, ...args: any[]): void;
public focus(): void;
public getCodeMirror(): CodeMirrorType;
public getCurrentModeEditor(): MarkdownEditor | WysiwygEditor;
public getCurrentPreviewStyle(): PreviewStyle;
public getHtml(): string;
public getMarkdown(): string;
public getRange(): Range | RangeType;
public getSelectedText(): string;
public getSquire(): SquireExt;
public getTextObject(range: Range | RangeType): MdTextObject | WwTextObject;
public getUI(): UI;
public getValue(): string;
public height(height: string): string;
public hide(): void;
public insertText(text: string): void;
public isMarkdownMode(): boolean;
public isViewer(): boolean;
public isWysiwygMode(): boolean;
public minHeight(minHeight: string): string;
public moveCursorToEnd(): void;
public moveCursorToStart(): void;
public off(type: string): void;
public on(type: string, handler: HandlerFunc): void;
public remove(): void;
public removeHook(type: string): void;
public reset(): void;
public scrollTop(value: number): number;
public setHtml(html: string, cursorToEnd?: boolean): void;
public setMarkdown(markdown: string, cursorToEnd?: boolean): void;
public setUI(UI: UI): void;
public setValue(value: string, cursorToEnd?: boolean): void;
public show(): void;
public setCodeBlockLanguages(languages?: string[]): void;
}
export class Viewer {
public static isViewer: boolean;
public static codeBlockManager: CodeBlockManager;
public static WwCodeBlockManager: null;
public static WwTableManager: null;
public static WwTableSelectionManager: null;
constructor(options: ViewerOptions);
public addHook(type: string, handler: HandlerFunc): void;
public isMarkdownMode(): boolean;
public isViewer(): boolean;
public isWysiwygMode(): boolean;
public off(type: string): void;
public on(type: string, handler: HandlerFunc): void;
public remove(): void;
public setMarkdown(markdown: string): void;
public setValue(markdown: string): void;
public setCodeBlockLanguages(languages?: string[]): void;
}
}
declare module '@toast-ui/editor' {
export type EditorOptions = toastui.EditorOptions;
export type CustomConvertor = toastui.ConvertorClass;
export type EventMap = toastui.EventMap;
export type EditorHookMap = toastui.EditorHookMap;
export type CustomHTMLRenderer = toastui.CustomHTMLRenderer;
export type ExtendedAutolinks = toastui.ExtendedAutolinks;
export type LinkAttribute = toastui.LinkAttribute;
export default toastui.Editor;
}
declare module '@toast-ui/editor/dist/toastui-editor-viewer' {
export type ViewerOptions = toastui.ViewerOptions;
export type CustomConvertor = toastui.ConvertorClass;
export type EventMap = toastui.EventMap;
export type ViewerHookMap = toastui.ViewerHookMap;
export type CustomHTMLRenderer = toastui.CustomHTMLRenderer;
export type ExtendedAutolinks = toastui.ExtendedAutolinks;
export type LinkAttribute = toastui.LinkAttribute;
export default toastui.Viewer;
}