Explorar o código

:sparkles: https://github.com/Vanessa219/vditor/issues/1808

Vanessa hai 5 meses
pai
achega
17d8d2c9e2
Modificáronse 5 ficheiros con 11 adicións e 4 borrados
  1. 2 0
      CHANGELOG.md
  2. 1 0
      README.md
  3. 1 0
      README_en_US.md
  4. 6 4
      src/ts/upload/index.ts
  5. 1 0
      types/index.d.ts

+ 2 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@
 ### 升级
 
 * 3.11
+  * 添加 options.upload.xhr
   * 添加 options.upload.cancel
 * 3.10
   * 添加 options.unSelect
@@ -27,6 +28,7 @@
 
 ### v3.11.1 / 2025-05
 
+* [添加 `options.upload.xhr` 回调](https://github.com/Vanessa219/vditor/issues/1808) `引入特性`
 * [待办列表回车换行错误](https://github.com/Vanessa219/vditor/issues/1789) `修复缺陷`
 
 ### v3.11.0 / 2025-04-09

+ 1 - 0
README.md

@@ -465,6 +465,7 @@ if (xhr.status === 200) {
 
 |   | 说明 | 默认值 |
 | - | - | - |
+| xhr | 上传时使用的 XMLHttpRequest | - |
 | url | 上传 url,为空则不会触发上传相关事件 | '' |
 | max | 上传文件最大 Byte | 10 * 1024 * 1024 |
 | linkToImgUrl | 剪切板中包含图片地址时,使用此 url 重新上传 | '' |

+ 1 - 0
README_en_US.md

@@ -418,6 +418,7 @@ xhr.send(JSON.stringify({url: src})); // src is the address of the image outside
 
 |   | Explanation | Default |
 | - | - | - |
+| xhr | XMLHttpRequest used when uploading | - |
 | url | Upload url, empty will not trigger upload related events | '' |
 | max | The largest upload file Byte | 10 * 1024 * 1024 |
 | linkToImgUrl | When the clipboard contains the image address, use this url to re-upload | '' |

+ 6 - 4
src/ts/upload/index.ts

@@ -1,6 +1,6 @@
-import {getEditorRange, setSelectionFocus} from "../util/selection";
-import {getElement} from "./getElement";
-import {setHeaders} from "./setHeaders";
+import { getEditorRange, setSelectionFocus } from "../util/selection";
+import { getElement } from "./getElement";
+import { setHeaders } from "./setHeaders";
 
 class Upload {
     public element: HTMLElement;
@@ -219,6 +219,7 @@ const uploadFiles =
         }
 
         const xhr = new XMLHttpRequest();
+        vditor.upload.xhr = xhr;
         xhr.open("POST", vditor.options.upload.url);
         if (vditor.options.upload.token) {
             xhr.setRequestHeader("X-Upload-Token", vditor.options.upload.token);
@@ -254,6 +255,7 @@ const uploadFiles =
                     element.value = "";
                 }
                 vditor.upload.element.style.display = "none";
+                vditor.upload.xhr = undefined;
             }
         };
         xhr.upload.onprogress = (event: ProgressEvent) => {
@@ -268,4 +270,4 @@ const uploadFiles =
         xhr.send(formData);
     };
 
-export {Upload, uploadFiles};
+export { Upload, uploadFiles };

+ 1 - 0
types/index.d.ts

@@ -841,6 +841,7 @@ interface IVditor {
         element: HTMLElement
         isUploading: boolean
         range: Range,
+        xhr: XMLHttpRequest,
     };
     undo?: {
         clearStack(vditor: IVditor): void,