mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-02 23:54:28 -06:00
Added typings for image upload
This commit is contained in:
parent
917ea336c4
commit
11963829fc
@ -154,7 +154,7 @@ easyMDE.value('New input for **EasyMDE**');
|
|||||||
- **imageAccept**: A comma-separated list of mime-types used to check image type before upload (note: never trust client, always check file types at server-side). Defaults to `image/png, image/jpeg`.
|
- **imageAccept**: A comma-separated list of mime-types used to check image type before upload (note: never trust client, always check file types at server-side). Defaults to `image/png, image/jpeg`.
|
||||||
- **imageUploadEndpoint**: The endpoint where the images data will be sent, via an asynchronous *POST* request. The server is supposed to save this image, and return a json response.
|
- **imageUploadEndpoint**: The endpoint where the images data will be sent, via an asynchronous *POST* request. The server is supposed to save this image, and return a json response.
|
||||||
- if the request was successfully processed (HTTP 200-OK): `{"data": {"filePath": "<filePath>"}}` where *filePath* is the relative path of the image;
|
- if the request was successfully processed (HTTP 200-OK): `{"data": {"filePath": "<filePath>"}}` where *filePath* is the relative path of the image;
|
||||||
- otherwise: `{"error": "<errorCode>"}`, where *errorCode* can be `noFileGiven` (HTTP 400), `typeNotAllowed` (HTTP 415), `fileTooLarge` (HTTP 413) or `importError` (see *errorMessages* below). If *errorCode* is not one of the *errorMessages*, it is alerted unchanged to the user. This allows for server side error messages.
|
- otherwise: `{"error": "<errorCode>"}`, where *errorCode* can be `noFileGiven` (HTTP 400), `typeNotAllowed` (HTTP 415), `fileTooLarge` (HTTP 413) or `importError` (see *errorMessages* below). If *errorCode* is not one of the *errorMessages*, it is alerted unchanged to the user. This allows for server side error messages.
|
||||||
No default value.
|
No default value.
|
||||||
- **imageCSRFToken**: CSRF token to include with AJAX call to upload image. For instance used with Django backend.
|
- **imageCSRFToken**: CSRF token to include with AJAX call to upload image. For instance used with Django backend.
|
||||||
- **imageTexts**: Texts displayed to the user (mainly on the status bar) for the import image feature, where `#image_name#`, `#image_size#` and `#image_max_size#` will replaced by their respective values, that can be used for customization or internationalization:
|
- **imageTexts**: Texts displayed to the user (mainly on the status bar) for the import image feature, where `#image_name#`, `#image_size#` and `#image_max_size#` will replaced by their respective values, that can be used for customization or internationalization:
|
||||||
|
@ -59,3 +59,28 @@ const editor2 = new EasyMDE({
|
|||||||
});
|
});
|
||||||
|
|
||||||
editor2.clearAutosavedValue();
|
editor2.clearAutosavedValue();
|
||||||
|
|
||||||
|
const editorImages = new EasyMDE({
|
||||||
|
uploadImage: true,
|
||||||
|
imageAccept: 'image/png, image/bmp',
|
||||||
|
imageCSRFToken: undefined,
|
||||||
|
imageMaxSize: 10485760,
|
||||||
|
imageUploadEndpoint: 'https://my.domain/image-upload/',
|
||||||
|
imageTexts: {
|
||||||
|
sbInit: 'Drag & drop images!',
|
||||||
|
sbOnDragEnter: 'Let it go, let it go',
|
||||||
|
sbOnDrop: 'Uploading...',
|
||||||
|
sbProgress: 'Uploading... (#progress#)',
|
||||||
|
sbOnUploaded: 'Upload complete!',
|
||||||
|
sizeUnits: 'b,Kb,Mb'
|
||||||
|
},
|
||||||
|
errorMessages: {
|
||||||
|
noFileGiven: 'Please select a file',
|
||||||
|
imageTypeNotAllowed: 'This file type is not allowed!',
|
||||||
|
imageTooLarge: 'Image too big',
|
||||||
|
imageImportError: 'Something went oops!',
|
||||||
|
},
|
||||||
|
errorCallback: (errorMessage) => {
|
||||||
|
console.error(errorMessage);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
25
types/easymde.d.ts
vendored
25
types/easymde.d.ts
vendored
@ -86,6 +86,22 @@ declare namespace EasyMDE {
|
|||||||
noMobile?: boolean;
|
noMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ImageTextsOptions {
|
||||||
|
sbInit?: string;
|
||||||
|
sbOnDragEnter?: string;
|
||||||
|
sbOnDrop?: string;
|
||||||
|
sbProgress?: string;
|
||||||
|
sbOnUploaded?: string;
|
||||||
|
sizeUnits?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImageErrorTextsOptions {
|
||||||
|
noFileGiven?: string;
|
||||||
|
imageTypeNotAllowed?: string;
|
||||||
|
imageTooLarge?: string;
|
||||||
|
imageImportError?: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
autoDownloadFontAwesome?: boolean;
|
autoDownloadFontAwesome?: boolean;
|
||||||
autofocus?: boolean;
|
autofocus?: boolean;
|
||||||
@ -114,6 +130,15 @@ declare namespace EasyMDE {
|
|||||||
toolbarTips?: boolean;
|
toolbarTips?: boolean;
|
||||||
onToggleFullScreen?: (goingIntoFullScreen: boolean) => void;
|
onToggleFullScreen?: (goingIntoFullScreen: boolean) => void;
|
||||||
theme?: string;
|
theme?: string;
|
||||||
|
|
||||||
|
uploadImage?: boolean;
|
||||||
|
imageMaxSize?: number;
|
||||||
|
imageAccept?: string;
|
||||||
|
imageUploadEndpoint?: string;
|
||||||
|
imageCSRFToken?: string;
|
||||||
|
imageTexts?: ImageTextsOptions;
|
||||||
|
errorMessages?: ImageErrorTextsOptions;
|
||||||
|
errorCallback?: (errorMessage: string) => void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user