2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-06-27 13:11:01 -06:00

295 lines
9.1 KiB
TypeScript
Raw Permalink Normal View History

2019-01-16 22:07:52 +08:00
// This file is based on https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/simplemde/index.d.ts,
// which is written by Scalesoft <https://github.com/Scalesoft> and licensed under the MIT license:
2019-07-15 11:37:22 +02:00
//
2019-01-16 22:07:52 +08:00
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
2019-07-15 11:37:22 +02:00
//
2019-01-16 22:07:52 +08:00
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
2019-07-15 11:37:22 +02:00
//
2019-01-16 22:07:52 +08:00
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
2019-01-16 21:32:41 +08:00
/// <reference types="codemirror"/>
import { marked } from 'marked';
2019-01-16 21:32:41 +08:00
2020-01-29 15:57:28 +01:00
interface ArrayOneOrMore<T> extends Array<T> {
0: T;
2020-01-29 15:57:28 +01:00
}
type ToolbarButton =
'bold'
| 'italic'
| 'quote'
| 'unordered-list'
| 'ordered-list'
| 'link'
| 'image'
| 'upload-image'
| 'strikethrough'
2020-01-29 15:57:28 +01:00
| 'code'
| 'table'
| 'redo'
| 'heading'
| 'undo'
| 'heading-bigger'
| 'heading-smaller'
| 'heading-1'
| 'heading-2'
| 'heading-3'
| 'clean-block'
| 'horizontal-rule'
| 'preview'
| 'side-by-side'
| 'fullscreen'
| 'guide';
2019-01-16 21:32:41 +08:00
declare namespace EasyMDE {
interface TimeFormatOptions {
locale?: string | string[];
format?: Intl.DateTimeFormatOptions;
}
2019-01-16 21:32:41 +08:00
interface AutoSaveOptions {
enabled?: boolean;
delay?: number;
submit_delay?: number;
2019-01-16 21:32:41 +08:00
uniqueId: string;
timeFormat?: TimeFormatOptions;
text?: string;
2019-01-16 21:32:41 +08:00
}
interface BlockStyleOptions {
bold?: string;
code?: string;
italic?: string;
}
interface CustomAttributes {
[key: string]: string;
}
2019-01-16 21:32:41 +08:00
interface InsertTextOptions {
2019-01-16 22:07:52 +08:00
horizontalRule?: ReadonlyArray<string>;
image?: ReadonlyArray<string>;
link?: ReadonlyArray<string>;
table?: ReadonlyArray<string>;
2019-01-16 21:32:41 +08:00
}
interface ParsingOptions {
allowAtxHeaderWithoutSpace?: boolean;
strikethrough?: boolean;
underscoresBreakWords?: boolean;
}
interface PromptTexts {
image?: string;
link?: string;
}
2019-01-16 21:32:41 +08:00
interface RenderingOptions {
codeSyntaxHighlighting?: boolean;
hljs?: any;
markedOptions?: marked.MarkedExtension;
2020-03-06 00:43:08 +01:00
sanitizerFunction?: (html: string) => string;
2019-01-16 21:32:41 +08:00
singleLineBreaks?: boolean;
}
2019-01-16 22:07:52 +08:00
interface Shortcuts {
2019-01-16 21:32:41 +08:00
[action: string]: string | undefined | null;
2019-02-27 13:54:57 +01:00
2019-01-16 21:32:41 +08:00
toggleBlockquote?: string | null;
toggleBold?: string | null;
cleanBlock?: string | null;
toggleHeadingSmaller?: string | null;
toggleItalic?: string | null;
drawLink?: string | null;
toggleUnorderedList?: string | null;
togglePreview?: string | null;
toggleCodeBlock?: string | null;
drawImage?: string | null;
toggleOrderedList?: string | null;
toggleHeadingBigger?: string | null;
toggleSideBySide?: string | null;
toggleFullScreen?: string | null;
}
interface StatusBarItem {
className: string;
defaultValue: (element: HTMLElement) => void;
onUpdate: (element: HTMLElement) => void;
}
2020-01-29 15:57:28 +01:00
interface ToolbarDropdownIcon {
name: string;
children: ArrayOneOrMore<ToolbarIcon | ToolbarButton>;
className: string;
title: string;
noDisable?: boolean;
noMobile?: boolean;
}
2019-01-16 21:32:41 +08:00
interface ToolbarIcon {
name: string;
2019-02-27 13:54:57 +01:00
action: string | ((editor: EasyMDE) => void);
2019-01-16 21:32:41 +08:00
className: string;
title: string;
noDisable?: boolean;
noMobile?: boolean;
icon?: string;
attributes?: CustomAttributes;
2019-01-16 21:32:41 +08:00
}
2019-07-18 12:35:14 +02:00
interface ImageTextsOptions {
sbInit?: string;
sbOnDragEnter?: string;
sbOnDrop?: string;
sbProgress?: string;
sbOnUploaded?: string;
sizeUnits?: string;
}
interface ImageErrorTextsOptions {
noFileGiven?: string;
2019-07-18 12:56:51 +02:00
typeNotAllowed?: string;
fileTooLarge?: string;
importError?: string;
2019-07-18 12:35:14 +02:00
}
interface OverlayModeOptions {
mode: CodeMirror.Mode<any>;
combine?: boolean;
}
interface SpellCheckerOptions {
codeMirrorInstance: CodeMirror.Editor;
}
2019-01-16 21:32:41 +08:00
interface Options {
autoDownloadFontAwesome?: boolean;
autofocus?: boolean;
autosave?: AutoSaveOptions;
autoRefresh?: boolean | { delay: number; };
2019-01-16 21:32:41 +08:00
blockStyles?: BlockStyleOptions;
element?: HTMLElement;
forceSync?: boolean;
2022-07-27 17:58:51 +01:00
hideIcons?: ReadonlyArray<ToolbarButton>;
2019-01-16 21:32:41 +08:00
indentWithTabs?: boolean;
initialValue?: string;
insertTexts?: InsertTextOptions;
2020-11-11 22:40:51 +01:00
lineNumbers?: boolean;
2019-01-16 21:32:41 +08:00
lineWrapping?: boolean;
minHeight?: string;
2020-06-03 22:45:59 +03:00
maxHeight?: string;
2019-01-16 21:32:41 +08:00
parsingConfig?: ParsingOptions;
placeholder?: string;
2019-07-15 11:37:22 +02:00
previewClass?: string | ReadonlyArray<string>;
previewImagesInEditor?: boolean;
imagesPreviewHandler?: (src: string) => string,
previewRender?: (markdownPlaintext: string, previewElement: HTMLElement) => string | null;
2019-01-16 21:32:41 +08:00
promptURLs?: boolean;
renderingConfig?: RenderingOptions;
2019-01-16 22:07:52 +08:00
shortcuts?: Shortcuts;
showIcons?: ReadonlyArray<ToolbarButton>;
spellChecker?: boolean | ((options: SpellCheckerOptions) => void);
inputStyle?: 'textarea' | 'contenteditable';
nativeSpellcheck?: boolean;
sideBySideFullscreen?: boolean;
2019-02-27 13:54:57 +01:00
status?: boolean | ReadonlyArray<string | StatusBarItem>;
2019-01-16 21:32:41 +08:00
styleSelectedText?: boolean;
tabSize?: number;
2020-01-29 15:57:28 +01:00
toolbar?: boolean | ReadonlyArray<'|' | ToolbarButton | ToolbarIcon | ToolbarDropdownIcon>;
2019-01-16 21:32:41 +08:00
toolbarTips?: boolean;
toolbarButtonClassPrefix?: string;
onToggleFullScreen?: (goingIntoFullScreen: boolean) => void;
theme?: string;
2020-10-04 06:38:01 +00:00
scrollbarStyle?: string;
unorderedListStyle?: '*' | '-' | '+';
2019-07-18 12:35:14 +02:00
uploadImage?: boolean;
imageMaxSize?: number;
imageAccept?: string;
imageUploadFunction?: (file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => void;
2019-07-18 12:35:14 +02:00
imageUploadEndpoint?: string;
2021-03-11 12:09:09 -07:00
imagePathAbsolute?: boolean;
2019-07-18 12:35:14 +02:00
imageCSRFToken?: string;
imageCSRFName?: string;
imageCSRFHeader?: boolean;
2019-07-18 12:35:14 +02:00
imageTexts?: ImageTextsOptions;
imageInputName?: string
2019-07-18 12:35:14 +02:00
errorMessages?: ImageErrorTextsOptions;
errorCallback?: (errorMessage: string) => void;
promptTexts?: PromptTexts;
syncSideBySidePreviewScroll?: boolean;
overlayMode?: OverlayModeOptions;
direction?: 'ltr' | 'rtl';
2019-01-16 21:32:41 +08:00
}
}
declare class EasyMDE {
constructor(options?: EasyMDE.Options);
2019-02-27 13:54:57 +01:00
2019-01-16 21:32:41 +08:00
value(): string;
value(val: string): void;
2019-02-27 13:54:57 +01:00
2019-01-16 21:32:41 +08:00
codemirror: CodeMirror.Editor;
2019-02-27 13:54:57 +01:00
cleanup(): void;
2019-01-16 21:32:41 +08:00
toTextArea(): void;
2019-02-27 13:54:57 +01:00
2019-01-16 21:32:41 +08:00
isPreviewActive(): boolean;
2019-02-27 13:54:57 +01:00
2019-01-16 21:32:41 +08:00
isSideBySideActive(): boolean;
2019-02-27 13:54:57 +01:00
2019-01-16 21:32:41 +08:00
isFullscreenActive(): boolean;
2019-02-27 13:54:57 +01:00
2019-01-16 21:32:41 +08:00
clearAutosavedValue(): void;
2023-01-12 14:38:17 +02:00
updateStatusBar(itemName: string, content: string): void;
2019-01-16 21:32:41 +08:00
static toggleBold: (editor: EasyMDE) => void;
static toggleItalic: (editor: EasyMDE) => void;
static toggleStrikethrough: (editor: EasyMDE) => void;
static toggleHeadingSmaller: (editor: EasyMDE) => void;
static toggleHeadingBigger: (editor: EasyMDE) => void;
static toggleHeading1: (editor: EasyMDE) => void;
static toggleHeading2: (editor: EasyMDE) => void;
static toggleHeading3: (editor: EasyMDE) => void;
2022-05-17 23:17:04 +02:00
static toggleHeading4: (editor: EasyMDE) => void;
static toggleHeading5: (editor: EasyMDE) => void;
static toggleHeading6: (editor: EasyMDE) => void;
2019-01-16 21:32:41 +08:00
static toggleCodeBlock: (editor: EasyMDE) => void;
static toggleBlockquote: (editor: EasyMDE) => void;
static toggleUnorderedList: (editor: EasyMDE) => void;
static toggleOrderedList: (editor: EasyMDE) => void;
static cleanBlock: (editor: EasyMDE) => void;
static drawLink: (editor: EasyMDE) => void;
static drawImage: (editor: EasyMDE) => void;
2020-08-16 19:30:31 +02:00
static drawUploadedImage: (editor: EasyMDE) => void;
2019-01-16 21:32:41 +08:00
static drawTable: (editor: EasyMDE) => void;
static drawHorizontalRule: (editor: EasyMDE) => void;
static togglePreview: (editor: EasyMDE) => void;
static toggleSideBySide: (editor: EasyMDE) => void;
static toggleFullScreen: (editor: EasyMDE) => void;
static undo: (editor: EasyMDE) => void;
static redo: (editor: EasyMDE) => void;
}
export as namespace EasyMDE;
export = EasyMDE;