jodit 4.19.7 → 4.19.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/es2015/jodit.css +1 -1
- package/es2015/jodit.fat.min.js +8 -8
- package/es2015/jodit.js +295 -100
- package/es2015/jodit.min.js +4 -4
- package/es2015/plugins/debug/debug.css +1 -1
- package/es2015/plugins/debug/debug.js +1 -1
- package/es2015/plugins/debug/debug.min.js +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es2018/jodit.fat.min.js +8 -8
- package/es2018/jodit.min.js +4 -4
- package/es2018/plugins/debug/debug.min.js +1 -1
- package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es2021/jodit.css +1 -1
- package/es2021/jodit.fat.min.js +9 -9
- package/es2021/jodit.js +229 -44
- package/es2021/jodit.min.js +57 -57
- package/es2021/plugins/debug/debug.css +1 -1
- package/es2021/plugins/debug/debug.js +1 -1
- package/es2021/plugins/debug/debug.min.js +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es2021.en/jodit.css +1 -1
- package/es2021.en/jodit.fat.min.js +5 -5
- package/es2021.en/jodit.js +229 -44
- package/es2021.en/jodit.min.js +5 -5
- package/es2021.en/plugins/debug/debug.css +1 -1
- package/es2021.en/plugins/debug/debug.js +1 -1
- package/es2021.en/plugins/debug/debug.min.js +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es5/jodit.css +2 -2
- package/es5/jodit.fat.min.js +2 -2
- package/es5/jodit.js +371 -103
- package/es5/jodit.min.css +2 -2
- package/es5/jodit.min.js +2 -2
- package/es5/plugins/debug/debug.css +1 -1
- package/es5/plugins/debug/debug.js +1 -1
- package/es5/plugins/debug/debug.min.js +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es5/polyfills.fat.min.js +1 -1
- package/es5/polyfills.js +1 -1
- package/es5/polyfills.min.js +1 -1
- package/esm/core/constants.d.ts +1 -0
- package/esm/core/constants.js +3 -1
- package/esm/core/helpers/utils/error/error.d.ts +1 -0
- package/esm/core/helpers/utils/error/error.js +4 -1
- package/esm/core/helpers/utils/error/errors/answer-error.d.ts +13 -0
- package/esm/core/helpers/utils/error/errors/answer-error.js +17 -0
- package/esm/core/helpers/utils/error/errors/index.d.ts +1 -0
- package/esm/core/helpers/utils/error/errors/index.js +1 -0
- package/esm/core/request/ajax.d.ts +1 -0
- package/esm/core/request/ajax.js +20 -1
- package/esm/modules/file-browser/data-provider.js +5 -3
- package/esm/modules/uploader/config.js +4 -0
- package/esm/modules/uploader/helpers/send-files.d.ts +2 -2
- package/esm/modules/uploader/helpers/send-files.js +76 -9
- package/esm/modules/uploader/helpers/upload-error.d.ts +15 -0
- package/esm/modules/uploader/helpers/upload-error.js +16 -0
- package/esm/modules/uploader/uploader.js +15 -3
- package/esm/types/uploader.d.ts +117 -11
- package/package.json +2 -2
- package/types/core/constants.d.ts +1 -0
- package/types/core/helpers/utils/error/error.d.ts +1 -0
- package/types/core/helpers/utils/error/errors/answer-error.d.ts +13 -0
- package/types/core/helpers/utils/error/errors/index.d.ts +1 -0
- package/types/core/request/ajax.d.ts +1 -0
- package/types/modules/uploader/helpers/send-files.d.ts +2 -2
- package/types/modules/uploader/helpers/upload-error.d.ts +15 -0
- package/types/types/uploader.d.ts +117 -11
package/esm/types/uploader.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { CanPromise, IDictionary, IViewComponent } from "./types";
|
|
|
10
10
|
import type { IViewBased } from "./view";
|
|
11
11
|
import type { IAjax } from "./ajax";
|
|
12
12
|
interface IUploaderData {
|
|
13
|
+
code?: number;
|
|
13
14
|
messages?: string[];
|
|
14
15
|
files: string[];
|
|
15
16
|
isImages?: boolean[];
|
|
@@ -29,6 +30,23 @@ interface IUploaderAnswer {
|
|
|
29
30
|
data: IUploaderData;
|
|
30
31
|
}
|
|
31
32
|
export type HandlerSuccess = (resp: IUploaderData) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Error the handler gets when the connector refused an upload: the answer,
|
|
35
|
+
* its `code`, the sent `files` and `retry` to send them again, changed
|
|
36
|
+
*/
|
|
37
|
+
export interface IUploadError extends Error {
|
|
38
|
+
code?: number;
|
|
39
|
+
answer: IUploaderAnswer;
|
|
40
|
+
files: File[];
|
|
41
|
+
retry(plan?: Partial<IUploadPlan>): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* What `beforeUpload` decided: the files to send and extra fields of the request
|
|
45
|
+
*/
|
|
46
|
+
export interface IUploadPlan {
|
|
47
|
+
files: File[];
|
|
48
|
+
data?: IDictionary<string>;
|
|
49
|
+
}
|
|
32
50
|
export type HandlerError = (e: Error) => void;
|
|
33
51
|
export type BuildDataResult = FormData | IDictionary<string> | Promise<FormData | IDictionary<string>> | string;
|
|
34
52
|
export interface IUploaderOptions<T> {
|
|
@@ -103,28 +121,56 @@ export interface IUploaderOptions<T> {
|
|
|
103
121
|
pathVariableName: string;
|
|
104
122
|
withCredentials: boolean;
|
|
105
123
|
/**
|
|
106
|
-
* Called with the
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
124
|
+
* Called with the files right before they are sent (or read as base64).
|
|
125
|
+
* What it returns decides what happens:
|
|
126
|
+
*
|
|
127
|
+
* - `false` cancels the upload, the error handler gets `Upload canceled`
|
|
128
|
+
* - `undefined` (or `true`) sends the files as they are
|
|
129
|
+
* - an array of `File` sends those files instead, so files can be renamed
|
|
130
|
+
* with `new File([file], 'other.png', { type: file.type })` or left out
|
|
131
|
+
* - an object `{ files, data }` ({@link IUploadPlan}) sends those files
|
|
132
|
+
* and adds the fields of `data` to the request
|
|
133
|
+
* - a promise of any of the above is awaited, so the user can be asked first
|
|
134
|
+
*
|
|
135
|
+
* Throwing an error cancels the upload and routes the message through
|
|
136
|
+
* the error handler.
|
|
137
|
+
*
|
|
138
|
+
* Client-side validation (size, type, count):
|
|
110
139
|
*
|
|
111
140
|
* ```javascript
|
|
112
141
|
* Jodit.make('#editor', {
|
|
113
142
|
* uploader: {
|
|
114
|
-
* url: '
|
|
143
|
+
* url: 'https://example.com/connector/?action=fileUpload',
|
|
115
144
|
* beforeUpload(files) {
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* return false;
|
|
120
|
-
* }
|
|
145
|
+
* if (files.some(file => file.size > 2 * 1024 * 1024)) {
|
|
146
|
+
* this.j.message.error('Max 2MB');
|
|
147
|
+
* return false;
|
|
121
148
|
* }
|
|
122
149
|
* }
|
|
123
150
|
* }
|
|
124
151
|
* });
|
|
125
152
|
* ```
|
|
153
|
+
*
|
|
154
|
+
* Ask the user, say for a target folder the connector takes as a field:
|
|
155
|
+
*
|
|
156
|
+
* ```javascript
|
|
157
|
+
* Jodit.make('#editor', {
|
|
158
|
+
* uploader: {
|
|
159
|
+
* url: 'https://example.com/connector/?action=fileUpload',
|
|
160
|
+
* beforeUpload(files) {
|
|
161
|
+
* return new Promise(resolve =>
|
|
162
|
+
* this.j.prompt('Folder', 'Upload to', folder =>
|
|
163
|
+
* resolve({ files, data: { path: folder } })
|
|
164
|
+
* )
|
|
165
|
+
* );
|
|
166
|
+
* }
|
|
167
|
+
* }
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* A name that is already taken is not this hook's job: see `promptOnExists`.
|
|
126
172
|
*/
|
|
127
|
-
beforeUpload?: (this: T, files: File[]) => boolean | void
|
|
173
|
+
beforeUpload?: (this: T, files: File[]) => CanPromise<boolean | void | File[] | IUploadPlan>;
|
|
128
174
|
prepareData: (this: T, formData: FormData) => any;
|
|
129
175
|
buildData?: (this: T, formData: any) => BuildDataResult;
|
|
130
176
|
queryBuild?: (obj: string | IDictionary<string | object> | FormData, prefix?: string) => string | FormData;
|
|
@@ -133,7 +179,67 @@ export interface IUploaderOptions<T> {
|
|
|
133
179
|
process: (this: T, resp: IUploaderAnswer) => IUploaderData;
|
|
134
180
|
error: (this: T, e: Error) => void;
|
|
135
181
|
defaultHandlerSuccess: HandlerSuccess;
|
|
182
|
+
/**
|
|
183
|
+
* Shows a failed upload. When the connector refused it, the error is an
|
|
184
|
+
* {@link IUploadError}: `message` is the connector's text (`getMessage`),
|
|
185
|
+
* `answer` the whole answer, `code` its `data.code`, `files` the files
|
|
186
|
+
* that were sent and `retry(plan)` sends them again with other files or
|
|
187
|
+
* extra request fields, without running `beforeUpload` a second time.
|
|
188
|
+
*
|
|
189
|
+
* Connectors answer `409` when an uploaded name is already taken and
|
|
190
|
+
* `saveSameFileNameStrategy` is `error` (jodit-nodejs 2.1.1, PHP 3.0.61,
|
|
191
|
+
* jodit-python). With `promptOnExists` off, ask the user here:
|
|
192
|
+
*
|
|
193
|
+
* ```javascript
|
|
194
|
+
* Jodit.make('#editor', {
|
|
195
|
+
* uploader: {
|
|
196
|
+
* url: 'https://example.com/connector/?action=fileUpload',
|
|
197
|
+
* promptOnExists: false,
|
|
198
|
+
* defaultHandlerError(e) {
|
|
199
|
+
* if (e.code === 409) {
|
|
200
|
+
* this.j.confirm('Replace?', yes => yes && e.retry({ data: { onExists: 'replace' } }));
|
|
201
|
+
* return;
|
|
202
|
+
* }
|
|
203
|
+
*
|
|
204
|
+
* this.j.message.error(e.message);
|
|
205
|
+
* }
|
|
206
|
+
* }
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* Or keep both files under another name:
|
|
211
|
+
*
|
|
212
|
+
* ```javascript
|
|
213
|
+
* e.retry({
|
|
214
|
+
* files: e.files.map(file => new File([file], 'copy-' + file.name, { type: file.type }))
|
|
215
|
+
* });
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
136
218
|
defaultHandlerError: HandlerError;
|
|
219
|
+
/**
|
|
220
|
+
* When the connector answers `409` (the name is already taken), ask the
|
|
221
|
+
* user for another name in a prompt and send the file again under it,
|
|
222
|
+
* before the error handler gets a say: this is part of the upload, not a
|
|
223
|
+
* failure. The prompt comes with `promptOnExistsSuggestName(name)` filled
|
|
224
|
+
* in; Cancel drops the file. A refused batch (the connector stores nothing
|
|
225
|
+
* and does not say which name is taken) is sent again one file at a time,
|
|
226
|
+
* so the free ones are stored and only the taken ones ask.
|
|
227
|
+
*
|
|
228
|
+
* ```javascript
|
|
229
|
+
* Jodit.make('#editor', {
|
|
230
|
+
* uploader: {
|
|
231
|
+
* url: 'https://example.com/connector/?action=fileUpload',
|
|
232
|
+
* promptOnExists: true,
|
|
233
|
+
* promptOnExistsSuggestName: name => name.replace(/(\.\w+)?$/, '-copy$1')
|
|
234
|
+
* }
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
promptOnExists: boolean;
|
|
239
|
+
/**
|
|
240
|
+
* The name the `promptOnExists` prompt offers for a taken name. Default: the same name
|
|
241
|
+
*/
|
|
242
|
+
promptOnExistsSuggestName: (this: T, name: string) => string;
|
|
137
243
|
contentType: (this: T, requestData: any) => string | false;
|
|
138
244
|
/**
|
|
139
245
|
* This method can be used to replace the function of uploading files
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jodit",
|
|
3
|
-
"version": "4.19.
|
|
3
|
+
"version": "4.19.8",
|
|
4
4
|
"description": "Jodit is an awesome and useful wysiwyg editor with filebrowser",
|
|
5
5
|
"main": "esm/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {},
|
|
39
39
|
"overrides": {
|
|
40
|
-
"qs": "6.16.
|
|
40
|
+
"qs": "6.16.1"
|
|
41
41
|
},
|
|
42
42
|
"module": "esm/index.js",
|
|
43
43
|
"dependencies": {}
|
|
@@ -130,6 +130,7 @@ export declare const INSERT_AS_TEXT = "insert_as_text";
|
|
|
130
130
|
*/
|
|
131
131
|
export declare const INSERT_ONLY_TEXT = "insert_only_text";
|
|
132
132
|
export declare const SAFE_COUNT_CHANGE_CALL = 10;
|
|
133
|
+
export declare const ERROR_CODE_CONFLICT = 409;
|
|
133
134
|
export declare const IS_MAC: boolean;
|
|
134
135
|
export declare const KEY_ALIASES: IDictionary<string>;
|
|
135
136
|
/**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Jodit Editor (https://xdsoft.net/jodit/)
|
|
3
|
+
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
|
+
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @module helpers/utils
|
|
8
|
+
*/
|
|
9
|
+
export declare class AnswerError<T = unknown> extends Error {
|
|
10
|
+
readonly answer: T;
|
|
11
|
+
readonly code?: number | undefined;
|
|
12
|
+
constructor(message: string, answer: T, code?: number | undefined);
|
|
13
|
+
}
|
|
@@ -21,6 +21,7 @@ export declare class Ajax<T extends object = any> implements IAjax<T> {
|
|
|
21
21
|
get o(): this['options'];
|
|
22
22
|
abort(): Ajax;
|
|
23
23
|
private __isFulfilled;
|
|
24
|
+
private __hasAnswerEnvelope;
|
|
24
25
|
private __activated;
|
|
25
26
|
send(): RejectablePromise<IResponse<T>>;
|
|
26
27
|
stream(): AsyncGenerator<string>;
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* @module modules/uploader
|
|
8
8
|
*/
|
|
9
|
-
import type { HandlerError, HandlerSuccess, IUploader } from "../../../types/index";
|
|
9
|
+
import type { HandlerError, HandlerSuccess, IUploader, IUploadPlan } from "../../../types/index";
|
|
10
10
|
/**
|
|
11
11
|
* Send files to server
|
|
12
12
|
*/
|
|
13
|
-
export declare function sendFiles(uploader: IUploader, files: FileList | File[] | null, handlerSuccess?: HandlerSuccess, handlerError?: HandlerError, process?: (form: FormData) => void): Promise<any>;
|
|
13
|
+
export declare function sendFiles(uploader: IUploader, files: FileList | File[] | null, handlerSuccess?: HandlerSuccess, handlerError?: HandlerError, process?: (form: FormData) => void, retryOf?: Partial<IUploadPlan>): Promise<any>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Jodit Editor (https://xdsoft.net/jodit/)
|
|
3
|
+
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
|
+
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @module modules/uploader
|
|
8
|
+
*/
|
|
9
|
+
import type { IUploaderAnswer, IUploadError, IUploadPlan } from "../../../types/index";
|
|
10
|
+
import { AnswerError } from "../../../core/helpers/utils/error/index";
|
|
11
|
+
export declare class UploadError extends AnswerError<IUploaderAnswer> implements IUploadError {
|
|
12
|
+
readonly files: File[];
|
|
13
|
+
readonly retry: (plan?: Partial<IUploadPlan>) => Promise<unknown>;
|
|
14
|
+
constructor(message: string, answer: IUploaderAnswer, files: File[], retry: (plan?: Partial<IUploadPlan>) => Promise<unknown>);
|
|
15
|
+
}
|
|
@@ -10,6 +10,7 @@ import type { CanPromise, IDictionary, IViewComponent } from "./types";
|
|
|
10
10
|
import type { IViewBased } from "./view";
|
|
11
11
|
import type { IAjax } from "./ajax";
|
|
12
12
|
interface IUploaderData {
|
|
13
|
+
code?: number;
|
|
13
14
|
messages?: string[];
|
|
14
15
|
files: string[];
|
|
15
16
|
isImages?: boolean[];
|
|
@@ -29,6 +30,23 @@ interface IUploaderAnswer {
|
|
|
29
30
|
data: IUploaderData;
|
|
30
31
|
}
|
|
31
32
|
export type HandlerSuccess = (resp: IUploaderData) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Error the handler gets when the connector refused an upload: the answer,
|
|
35
|
+
* its `code`, the sent `files` and `retry` to send them again, changed
|
|
36
|
+
*/
|
|
37
|
+
export interface IUploadError extends Error {
|
|
38
|
+
code?: number;
|
|
39
|
+
answer: IUploaderAnswer;
|
|
40
|
+
files: File[];
|
|
41
|
+
retry(plan?: Partial<IUploadPlan>): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* What `beforeUpload` decided: the files to send and extra fields of the request
|
|
45
|
+
*/
|
|
46
|
+
export interface IUploadPlan {
|
|
47
|
+
files: File[];
|
|
48
|
+
data?: IDictionary<string>;
|
|
49
|
+
}
|
|
32
50
|
export type HandlerError = (e: Error) => void;
|
|
33
51
|
export type BuildDataResult = FormData | IDictionary<string> | Promise<FormData | IDictionary<string>> | string;
|
|
34
52
|
export interface IUploaderOptions<T> {
|
|
@@ -103,28 +121,56 @@ export interface IUploaderOptions<T> {
|
|
|
103
121
|
pathVariableName: string;
|
|
104
122
|
withCredentials: boolean;
|
|
105
123
|
/**
|
|
106
|
-
* Called with the
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
124
|
+
* Called with the files right before they are sent (or read as base64).
|
|
125
|
+
* What it returns decides what happens:
|
|
126
|
+
*
|
|
127
|
+
* - `false` cancels the upload, the error handler gets `Upload canceled`
|
|
128
|
+
* - `undefined` (or `true`) sends the files as they are
|
|
129
|
+
* - an array of `File` sends those files instead, so files can be renamed
|
|
130
|
+
* with `new File([file], 'other.png', { type: file.type })` or left out
|
|
131
|
+
* - an object `{ files, data }` ({@link IUploadPlan}) sends those files
|
|
132
|
+
* and adds the fields of `data` to the request
|
|
133
|
+
* - a promise of any of the above is awaited, so the user can be asked first
|
|
134
|
+
*
|
|
135
|
+
* Throwing an error cancels the upload and routes the message through
|
|
136
|
+
* the error handler.
|
|
137
|
+
*
|
|
138
|
+
* Client-side validation (size, type, count):
|
|
110
139
|
*
|
|
111
140
|
* ```javascript
|
|
112
141
|
* Jodit.make('#editor', {
|
|
113
142
|
* uploader: {
|
|
114
|
-
* url: '
|
|
143
|
+
* url: 'https://example.com/connector/?action=fileUpload',
|
|
115
144
|
* beforeUpload(files) {
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* return false;
|
|
120
|
-
* }
|
|
145
|
+
* if (files.some(file => file.size > 2 * 1024 * 1024)) {
|
|
146
|
+
* this.j.message.error('Max 2MB');
|
|
147
|
+
* return false;
|
|
121
148
|
* }
|
|
122
149
|
* }
|
|
123
150
|
* }
|
|
124
151
|
* });
|
|
125
152
|
* ```
|
|
153
|
+
*
|
|
154
|
+
* Ask the user, say for a target folder the connector takes as a field:
|
|
155
|
+
*
|
|
156
|
+
* ```javascript
|
|
157
|
+
* Jodit.make('#editor', {
|
|
158
|
+
* uploader: {
|
|
159
|
+
* url: 'https://example.com/connector/?action=fileUpload',
|
|
160
|
+
* beforeUpload(files) {
|
|
161
|
+
* return new Promise(resolve =>
|
|
162
|
+
* this.j.prompt('Folder', 'Upload to', folder =>
|
|
163
|
+
* resolve({ files, data: { path: folder } })
|
|
164
|
+
* )
|
|
165
|
+
* );
|
|
166
|
+
* }
|
|
167
|
+
* }
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* A name that is already taken is not this hook's job: see `promptOnExists`.
|
|
126
172
|
*/
|
|
127
|
-
beforeUpload?: (this: T, files: File[]) => boolean | void
|
|
173
|
+
beforeUpload?: (this: T, files: File[]) => CanPromise<boolean | void | File[] | IUploadPlan>;
|
|
128
174
|
prepareData: (this: T, formData: FormData) => any;
|
|
129
175
|
buildData?: (this: T, formData: any) => BuildDataResult;
|
|
130
176
|
queryBuild?: (obj: string | IDictionary<string | object> | FormData, prefix?: string) => string | FormData;
|
|
@@ -133,7 +179,67 @@ export interface IUploaderOptions<T> {
|
|
|
133
179
|
process: (this: T, resp: IUploaderAnswer) => IUploaderData;
|
|
134
180
|
error: (this: T, e: Error) => void;
|
|
135
181
|
defaultHandlerSuccess: HandlerSuccess;
|
|
182
|
+
/**
|
|
183
|
+
* Shows a failed upload. When the connector refused it, the error is an
|
|
184
|
+
* {@link IUploadError}: `message` is the connector's text (`getMessage`),
|
|
185
|
+
* `answer` the whole answer, `code` its `data.code`, `files` the files
|
|
186
|
+
* that were sent and `retry(plan)` sends them again with other files or
|
|
187
|
+
* extra request fields, without running `beforeUpload` a second time.
|
|
188
|
+
*
|
|
189
|
+
* Connectors answer `409` when an uploaded name is already taken and
|
|
190
|
+
* `saveSameFileNameStrategy` is `error` (jodit-nodejs 2.1.1, PHP 3.0.61,
|
|
191
|
+
* jodit-python). With `promptOnExists` off, ask the user here:
|
|
192
|
+
*
|
|
193
|
+
* ```javascript
|
|
194
|
+
* Jodit.make('#editor', {
|
|
195
|
+
* uploader: {
|
|
196
|
+
* url: 'https://example.com/connector/?action=fileUpload',
|
|
197
|
+
* promptOnExists: false,
|
|
198
|
+
* defaultHandlerError(e) {
|
|
199
|
+
* if (e.code === 409) {
|
|
200
|
+
* this.j.confirm('Replace?', yes => yes && e.retry({ data: { onExists: 'replace' } }));
|
|
201
|
+
* return;
|
|
202
|
+
* }
|
|
203
|
+
*
|
|
204
|
+
* this.j.message.error(e.message);
|
|
205
|
+
* }
|
|
206
|
+
* }
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* Or keep both files under another name:
|
|
211
|
+
*
|
|
212
|
+
* ```javascript
|
|
213
|
+
* e.retry({
|
|
214
|
+
* files: e.files.map(file => new File([file], 'copy-' + file.name, { type: file.type }))
|
|
215
|
+
* });
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
136
218
|
defaultHandlerError: HandlerError;
|
|
219
|
+
/**
|
|
220
|
+
* When the connector answers `409` (the name is already taken), ask the
|
|
221
|
+
* user for another name in a prompt and send the file again under it,
|
|
222
|
+
* before the error handler gets a say: this is part of the upload, not a
|
|
223
|
+
* failure. The prompt comes with `promptOnExistsSuggestName(name)` filled
|
|
224
|
+
* in; Cancel drops the file. A refused batch (the connector stores nothing
|
|
225
|
+
* and does not say which name is taken) is sent again one file at a time,
|
|
226
|
+
* so the free ones are stored and only the taken ones ask.
|
|
227
|
+
*
|
|
228
|
+
* ```javascript
|
|
229
|
+
* Jodit.make('#editor', {
|
|
230
|
+
* uploader: {
|
|
231
|
+
* url: 'https://example.com/connector/?action=fileUpload',
|
|
232
|
+
* promptOnExists: true,
|
|
233
|
+
* promptOnExistsSuggestName: name => name.replace(/(\.\w+)?$/, '-copy$1')
|
|
234
|
+
* }
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
promptOnExists: boolean;
|
|
239
|
+
/**
|
|
240
|
+
* The name the `promptOnExists` prompt offers for a taken name. Default: the same name
|
|
241
|
+
*/
|
|
242
|
+
promptOnExistsSuggestName: (this: T, name: string) => string;
|
|
137
243
|
contentType: (this: T, requestData: any) => string | false;
|
|
138
244
|
/**
|
|
139
245
|
* This method can be used to replace the function of uploading files
|