forked from laurent22/joplin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
177 lines (141 loc) · 4.37 KB
/
types.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
import type { Theme } from '@joplin/lib/themes/type';
import type { EditorEvent } from './events';
// Editor commands. For compatibility, the string values of these commands
// should correspond with the CodeMirror 5 commands:
// https://codemirror.net/5/doc/manual.html#commands
export enum EditorCommandType {
Undo = 'undo',
Redo = 'redo',
SelectAll = 'selectAll',
Focus = 'focus',
// Formatting editor commands
ToggleBolded = 'textBold',
ToggleItalicized = 'textItalic',
ToggleCode = 'textCode',
ToggleMath = 'textMath',
ToggleComment = 'toggleComment',
DuplicateLine = 'duplicateLine',
SortSelectedLines = 'sortSelectedLines',
ToggleNumberedList = 'textNumberedList',
ToggleBulletedList = 'textBulletedList',
ToggleCheckList = 'textCheckbox',
ToggleHeading = 'textHeading',
ToggleHeading1 = 'textHeading1',
ToggleHeading2 = 'textHeading2',
ToggleHeading3 = 'textHeading3',
ToggleHeading4 = 'textHeading4',
ToggleHeading5 = 'textHeading5',
// Find commands
ShowSearch = 'find',
HideSearch = 'hideSearchDialog',
FindNext = 'findNext',
FindPrevious = 'findPrev',
ReplaceNext = 'replace',
ReplaceAll = 'replaceAll',
// Editing and navigation commands
ScrollSelectionIntoView = 'scrollSelectionIntoView',
DeleteLine = 'deleteLine',
DeleteToLineEnd = 'killLine',
DeleteToLineStart = 'delLineLeft',
IndentMore = 'indentMore',
IndentLess = 'indentLess',
IndentAuto = 'indentAuto',
InsertNewlineAndIndent = 'newlineAndIndent',
SwapLineUp = 'swapLineUp',
SwapLineDown = 'swapLineDown',
GoDocEnd = 'goDocEnd',
GoDocStart = 'goDocStart',
GoLineStart = 'goLineStart',
GoLineEnd = 'goLineEnd',
GoLineUp = 'goLineUp',
GoLineDown = 'goLineDown',
GoPageUp = 'goPageUp',
GoPageDown = 'goPageDown',
GoCharLeft = 'goCharLeft',
GoCharRight = 'goCharRight',
UndoSelection = 'undoSelection',
RedoSelection = 'redoSelection',
}
// Because the editor package can run in a WebView, plugin content scripts
// need to be provided as text, rather than as file paths.
export interface ContentScriptData {
pluginId: string;
contentScriptId: string;
contentScriptJs: ()=> Promise<string>;
loadCssAsset: (name: string)=> Promise<string>;
postMessageHandler: (message: any)=> any;
}
export interface EditorControl {
supportsCommand(name: EditorCommandType|string): boolean;
execCommand(name: EditorCommandType|string): void;
undo(): void;
redo(): void;
select(anchor: number, head: number): void;
// 0 corresponds to the top, 1 corresponds to the bottom.
setScrollPercent(fraction: number): void;
insertText(text: string): void;
updateBody(newBody: string): void;
updateSettings(newSettings: EditorSettings): void;
// Create a new link or update the currently selected link with
// the given [label] and [url].
updateLink(label: string, url: string): void;
setSearchState(state: SearchState): void;
setContentScripts(plugins: ContentScriptData[]): Promise<void>;
}
export enum EditorLanguageType {
Markdown = 'markdown',
Html = 'html',
}
export enum EditorKeymap {
Default = 'default',
Vim = 'vim',
Emacs = 'emacs',
}
export interface EditorTheme extends Theme {
fontFamily: string;
fontSize?: number;
fontSizeUnits?: number;
isDesktop?: boolean;
monospaceFont?: string;
contentMaxWidth?: number;
}
export interface EditorSettings {
// EditorSettings objects are deserialized within WebViews, where
// [themeStyle(themeId: number)] doesn't work. As such, we need both
// a Theme must be provided.
themeData: EditorTheme;
// True if the search panel is implemented outside of the editor (e.g. with
// React Native).
useExternalSearch: boolean;
automatchBraces: boolean;
// True if internal command keyboard shortcuts should be ignored (thus
// allowing Joplin shortcuts to run).
ignoreModifiers: boolean;
language: EditorLanguageType;
keymap: EditorKeymap;
katexEnabled: boolean;
spellcheckEnabled: boolean;
readOnly: boolean;
indentWithTabs: boolean;
}
export type LogMessageCallback = (message: string)=> void;
export type OnEventCallback = (event: EditorEvent)=> void;
export interface EditorProps {
settings: EditorSettings;
initialText: string;
onEvent: OnEventCallback;
onLogMessage: LogMessageCallback;
}
export interface SearchState {
useRegex: boolean;
caseSensitive: boolean;
searchText: string;
replaceText: string;
dialogVisible: boolean;
}
// Possible types of lists in the editor
export enum ListType {
CheckList,
OrderedList,
UnorderedList,
}