]> BookStack Code Mirror - bookstack/blob - resources/js/markdown/inputs/interface.ts
Deps: Updated PHP composer dependancy versions, fixed test namespaces
[bookstack] / resources / js / markdown / inputs / interface.ts
1
2 export interface MarkdownEditorInputSelection {
3     from: number;
4     to: number;
5 }
6
7 export interface MarkdownEditorInput {
8     /**
9      * Focus on the editor.
10      */
11     focus(): void;
12
13     /**
14      * Get the current selection range.
15      */
16     getSelection(): MarkdownEditorInputSelection;
17
18     /**
19      * Get the text of the given (or current) selection range.
20      */
21     getSelectionText(selection?: MarkdownEditorInputSelection): string;
22
23     /**
24      * Set the selection range of the editor.
25      */
26     setSelection(selection: MarkdownEditorInputSelection, scrollIntoView: boolean): void;
27
28     /**
29      * Get the full text of the input.
30      */
31     getText(): string;
32
33     /**
34      * Get just the text which is above (out) the current view range.
35      * This is used for position estimation.
36      */
37     getTextAboveView(): string;
38
39     /**
40      * Set the full text of the input.
41      * Optionally can provide a selection to restore after setting text.
42      */
43     setText(text: string, selection?: MarkdownEditorInputSelection): void;
44
45     /**
46      * Splice in/out text within the input.
47      * Optionally can provide a selection to restore after setting text.
48      */
49     spliceText(from: number, to: number, newText: string, selection: Partial<MarkdownEditorInputSelection>|null): void;
50
51     /**
52      * Append text to the end of the editor.
53      */
54     appendText(text: string): void;
55
56     /**
57      * Get the text of the given line number otherwise the text
58      * of the current selected line.
59      */
60     getLineText(lineIndex:number): string;
61
62     /**
63      * Get a selection representing the line range from the given position.
64      */
65     getLineRangeFromPosition(position: number): MarkdownEditorInputSelection;
66
67     /**
68      * Convert the given event position to a selection position within the input.
69      */
70     eventToPosition(event: MouseEvent): MarkdownEditorInputSelection;
71
72     /**
73      * Search and return a line range which includes the provided text.
74      */
75     searchForLineContaining(text: string): MarkdownEditorInputSelection|null;
76
77     /**
78      * Tear down the input.
79      */
80     teardown(): void;
81 }