jodit 4.19.6 → 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 +34 -0
- package/es2015/jodit.css +1 -1
- package/es2015/jodit.fat.min.js +10 -10
- package/es2015/jodit.js +787 -200
- package/es2015/jodit.min.js +10 -10
- 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 +10 -10
- package/es2018/jodit.min.js +10 -10
- 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 +12 -12
- package/es2021/jodit.js +709 -143
- package/es2021/jodit.min.js +12 -12
- 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 +18 -18
- package/es2021.en/jodit.js +709 -143
- package/es2021.en/jodit.min.js +18 -18
- 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 +947 -208
- 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/core/selection/style/apply-style.js +31 -2
- package/esm/jodit.js +14 -2
- 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/plugins/backspace/cases/check-join-neighbors.js +36 -7
- package/esm/plugins/backspace/cases/check-remove-empty-parent.js +3 -1
- package/esm/plugins/bold/bold.js +4 -1
- package/esm/plugins/delete/delete.d.ts +12 -0
- package/esm/plugins/delete/delete.js +50 -1
- package/esm/plugins/resize-cells/resize-cells.d.ts +25 -1
- package/esm/plugins/resize-cells/resize-cells.js +84 -15
- package/esm/plugins/select/select.d.ts +35 -0
- package/esm/plugins/select/select.js +153 -1
- package/esm/plugins/select-cells/select-cells.d.ts +24 -0
- package/esm/plugins/select-cells/select-cells.js +81 -18
- package/esm/types/style.d.ts +5 -0
- 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/plugins/delete/delete.d.ts +12 -0
- package/types/plugins/resize-cells/resize-cells.d.ts +25 -1
- package/types/plugins/select/select.d.ts +35 -0
- package/types/plugins/select-cells/select-cells.d.ts +24 -0
- package/types/types/style.d.ts +5 -0
- package/types/types/uploader.d.ts +117 -11
package/es5/polyfills.fat.min.js
CHANGED
package/es5/polyfills.js
CHANGED
package/es5/polyfills.min.js
CHANGED
package/esm/core/constants.d.ts
CHANGED
|
@@ -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
|
/**
|
package/esm/core/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
4
|
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
5
|
*/
|
|
6
|
-
export const APP_VERSION = "4.19.
|
|
6
|
+
export const APP_VERSION = "4.19.8";
|
|
7
7
|
// prettier-ignore
|
|
8
8
|
export const ES = "es2020";
|
|
9
9
|
export const IS_ES_MODERN = true;
|
|
@@ -152,6 +152,8 @@ export const INSERT_AS_TEXT = 'insert_as_text';
|
|
|
152
152
|
*/
|
|
153
153
|
export const INSERT_ONLY_TEXT = 'insert_only_text';
|
|
154
154
|
export const SAFE_COUNT_CHANGE_CALL = 10;
|
|
155
|
+
// Connector answer code for a file name that is already taken (same as the HTTP status)
|
|
156
|
+
export const ERROR_CODE_CONFLICT = 409;
|
|
155
157
|
export const IS_MAC = typeof globalWindow !== 'undefined' &&
|
|
156
158
|
/Mac|iPod|iPhone|iPad/.test(globalWindow.navigator.platform);
|
|
157
159
|
export const KEY_ALIASES = {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* @module helpers/utils
|
|
8
8
|
*/
|
|
9
|
-
import { ConnectionError, OptionsError } from "./errors/index.js";
|
|
9
|
+
import { AnswerError, ConnectionError, OptionsError } from "./errors/index.js";
|
|
10
10
|
/**
|
|
11
11
|
* Helper for create Error object
|
|
12
12
|
*/
|
|
@@ -19,3 +19,6 @@ export function connection(message) {
|
|
|
19
19
|
export function options(message) {
|
|
20
20
|
return new OptionsError(message);
|
|
21
21
|
}
|
|
22
|
+
export function answer(message, resp, code) {
|
|
23
|
+
return new AnswerError(message, resp, code);
|
|
24
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
// A connector refused the request: the answer and its `data.code` stay reachable for the handler
|
|
10
|
+
export class AnswerError extends Error {
|
|
11
|
+
constructor(message, answer, code) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.answer = answer;
|
|
14
|
+
this.code = code;
|
|
15
|
+
Object.setPrototypeOf(this, AnswerError.prototype);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -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>;
|
package/esm/core/request/ajax.js
CHANGED
|
@@ -63,6 +63,24 @@ export class Ajax {
|
|
|
63
63
|
catch (_a) { }
|
|
64
64
|
return this;
|
|
65
65
|
}
|
|
66
|
+
// A connector answers an error with its JSON envelope and a real HTTP status (403, 409): the body says why, the reason phrase does not
|
|
67
|
+
__hasAnswerEnvelope() {
|
|
68
|
+
const { xhr } = this;
|
|
69
|
+
if (xhr.responseType && xhr.responseType !== 'text') {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const text = xhr.responseText;
|
|
73
|
+
if (!text || text[0] !== '{') {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const answer = JSON.parse(text);
|
|
78
|
+
return isPlainObject(answer) && 'success' in answer;
|
|
79
|
+
}
|
|
80
|
+
catch (_a) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
66
84
|
send() {
|
|
67
85
|
this.__activated = true;
|
|
68
86
|
const { xhr, o } = this;
|
|
@@ -99,7 +117,8 @@ export class Ajax {
|
|
|
99
117
|
var _a, _b;
|
|
100
118
|
(_b = (_a = this.options).onProgress) === null || _b === void 0 ? void 0 : _b.call(_a, 10);
|
|
101
119
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
102
|
-
if (o.successStatuses.includes(xhr.status)
|
|
120
|
+
if (o.successStatuses.includes(xhr.status) ||
|
|
121
|
+
this.__hasAnswerEnvelope()) {
|
|
103
122
|
onResolve();
|
|
104
123
|
}
|
|
105
124
|
else if (xhr.statusText) {
|
|
@@ -3,12 +3,38 @@
|
|
|
3
3
|
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
4
|
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { Dom } from "../../dom/dom.js";
|
|
7
|
+
import { $$ } from "../../helpers/utils/selector.js";
|
|
8
|
+
import { extractSelectedPart, FiniteStateMachine } from "./api/index.js";
|
|
7
9
|
import { INITIAL } from "./constants.js";
|
|
8
10
|
import { states, transactions } from "./transactions.js";
|
|
11
|
+
/**
|
|
12
|
+
* Take a selected fragment out of the elements its style takes the place
|
|
13
|
+
* of: one around it is split, so the fragment leaves it, and one in it is
|
|
14
|
+
* unwrapped
|
|
15
|
+
*/
|
|
16
|
+
function takeOutOf(jodit, font, tags) {
|
|
17
|
+
const range = jodit.s.createRange();
|
|
18
|
+
let outer = Dom.closest(font.parentNode, tags, jodit.editor);
|
|
19
|
+
while (outer) {
|
|
20
|
+
range.selectNodeContents(outer);
|
|
21
|
+
range.setEndBefore(font);
|
|
22
|
+
const before = range.cloneContents();
|
|
23
|
+
range.selectNodeContents(outer);
|
|
24
|
+
range.setStartAfter(font);
|
|
25
|
+
// Split only when there's more in it, as a split leaves empty copies
|
|
26
|
+
// of the elements between
|
|
27
|
+
if (!Dom.isEmpty(before) || !Dom.isEmpty(range.cloneContents())) {
|
|
28
|
+
extractSelectedPart(outer, font, jodit);
|
|
29
|
+
}
|
|
30
|
+
Dom.unwrap(outer);
|
|
31
|
+
outer = Dom.closest(font.parentNode, tags, jodit.editor);
|
|
32
|
+
}
|
|
33
|
+
$$(tags.join(','), font).forEach(inner => Dom.unwrap(inner));
|
|
34
|
+
}
|
|
9
35
|
/** @internal */
|
|
10
36
|
export function ApplyStyle(jodit, cs) {
|
|
11
|
-
var _a;
|
|
37
|
+
var _a, _b;
|
|
12
38
|
const { s: sel, editor } = jodit;
|
|
13
39
|
(_a = editor.firstChild) === null || _a === void 0 ? void 0 : _a.normalize(); // FF fix for test "commandsTest - Exec command "bold"
|
|
14
40
|
const fakes = sel.fakes();
|
|
@@ -18,6 +44,9 @@ export function ApplyStyle(jodit, cs) {
|
|
|
18
44
|
// for...of closes the generator on an exception, releasing every
|
|
19
45
|
// temporary wrapper before the selection is restored in finally.
|
|
20
46
|
for (const font of sel.wrapInTagGen(fakes)) {
|
|
47
|
+
if ((_b = cs.options.exclude) === null || _b === void 0 ? void 0 : _b.length) {
|
|
48
|
+
takeOutOf(jodit, font, cs.options.exclude);
|
|
49
|
+
}
|
|
21
50
|
let state = {
|
|
22
51
|
collapsed,
|
|
23
52
|
mode,
|
package/esm/jodit.js
CHANGED
|
@@ -15,7 +15,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
15
15
|
};
|
|
16
16
|
var Jodit_1;
|
|
17
17
|
import * as constants from "./core/constants.js";
|
|
18
|
-
import { FAT_MODE, IS_PROD, lang } from "./core/constants.js";
|
|
18
|
+
import { FAT_MODE, IS_PROD, KEY_BACKSPACE, KEY_DELETE, KEY_ENTER, lang } from "./core/constants.js";
|
|
19
19
|
import { autobind, cache, cached, derive, throttle, watch } from "./core/decorators/index.js";
|
|
20
20
|
import { eventEmitter, instances, modules, pluginSystem } from "./core/global.js";
|
|
21
21
|
import { asArray, attr, callPromise, ConfigMerge, ConfigProto, css, error, isFunction, isJoditObject, isNumber, isPromise, isString, isVoid, kebabCase, markAsAtomic, normalizeKeyAliases, resolveElement, toArray, ucfirst } from "./core/helpers/index.js";
|
|
@@ -25,6 +25,18 @@ import { Dlgs } from "./core/traits/dlgs.js";
|
|
|
25
25
|
import { Config } from "./config.js";
|
|
26
26
|
import { Create, Dom, History, Plugin, Selection, StatusBar, STATUSES, ViewWithToolbar } from "./modules/index.js";
|
|
27
27
|
const FOCUS_EVENTS = new Set(['focus', 'blur', 'focusin', 'focusout']);
|
|
28
|
+
const EDITING_KEYS = new Set([KEY_ENTER, KEY_BACKSPACE, KEY_DELETE]);
|
|
29
|
+
/**
|
|
30
|
+
* Whether the input method (IME) is using the key. Safari fires the keydown
|
|
31
|
+
* that ends a composition, as the Enter that confirms Japanese text, after
|
|
32
|
+
* `compositionend`, and types Korean without one, so `isComposing` is false and
|
|
33
|
+
* only keyCode 229 tells. Only the keys the editor turns into edits are held
|
|
34
|
+
* back: the handlers that follow typing still see the rest.
|
|
35
|
+
*/
|
|
36
|
+
function isInputMethodKey(event) {
|
|
37
|
+
return (event.isComposing ||
|
|
38
|
+
(event.keyCode === 229 && EDITING_KEYS.has(event.key)));
|
|
39
|
+
}
|
|
28
40
|
const __defaultStyleDisplayKey = 'data-jodit-default-style-display';
|
|
29
41
|
const __defaultClassesKey = 'data-jodit-default-classes';
|
|
30
42
|
const NOEDIT = {
|
|
@@ -1264,7 +1276,7 @@ let Jodit = Jodit_1 = class Jodit extends ViewWithToolbar {
|
|
|
1264
1276
|
}
|
|
1265
1277
|
const w = this.ew;
|
|
1266
1278
|
if (event instanceof w.KeyboardEvent &&
|
|
1267
|
-
event
|
|
1279
|
+
isInputMethodKey(event)) {
|
|
1268
1280
|
return;
|
|
1269
1281
|
}
|
|
1270
1282
|
if (this.e && this.e.fire) {
|
|
@@ -20,7 +20,7 @@ import { isFunction } from "../../core/helpers/checker/is-function.js";
|
|
|
20
20
|
import { isPlainObject } from "../../core/helpers/checker/is-plain-object.js";
|
|
21
21
|
import { normalizeRelativePath } from "../../core/helpers/normalize/normalize-relative-path.js";
|
|
22
22
|
import { ConfigProto } from "../../core/helpers/utils/config-proto.js";
|
|
23
|
-
import { abort, error } from "../../core/helpers/utils/error/index.js";
|
|
23
|
+
import { abort, answer, error } from "../../core/helpers/utils/error/index.js";
|
|
24
24
|
import { set } from "../../core/helpers/utils/set.js";
|
|
25
25
|
import { Ajax } from "../../core/request/ajax.js";
|
|
26
26
|
import { FileBrowserItem } from "./builders/item.js";
|
|
@@ -140,8 +140,9 @@ export default class DataProvider {
|
|
|
140
140
|
return promise
|
|
141
141
|
.then(resp => resp.json())
|
|
142
142
|
.then(resp => {
|
|
143
|
+
var _a;
|
|
143
144
|
if (resp && !this.isSuccess(resp)) {
|
|
144
|
-
throw
|
|
145
|
+
throw answer(this.getMessage(resp), resp, (_a = resp.data) === null || _a === void 0 ? void 0 : _a.code);
|
|
145
146
|
}
|
|
146
147
|
return resp;
|
|
147
148
|
});
|
|
@@ -288,10 +289,11 @@ export default class DataProvider {
|
|
|
288
289
|
getPathByUrl(url) {
|
|
289
290
|
set('options.getLocalFileByUrl.data.url', url, this);
|
|
290
291
|
return this.get('getLocalFileByUrl').then(resp => {
|
|
292
|
+
var _a;
|
|
291
293
|
if (this.isSuccess(resp)) {
|
|
292
294
|
return resp.data;
|
|
293
295
|
}
|
|
294
|
-
throw
|
|
296
|
+
throw answer(this.getMessage(resp), resp, (_a = resp.data) === null || _a === void 0 ? void 0 : _a.code);
|
|
295
297
|
});
|
|
296
298
|
}
|
|
297
299
|
/**
|
|
@@ -89,6 +89,10 @@ Config.prototype.uploader = {
|
|
|
89
89
|
defaultHandlerError(e) {
|
|
90
90
|
this.j.message.error(e.message);
|
|
91
91
|
},
|
|
92
|
+
promptOnExists: true,
|
|
93
|
+
promptOnExistsSuggestName(name) {
|
|
94
|
+
return name;
|
|
95
|
+
},
|
|
92
96
|
contentType(requestData) {
|
|
93
97
|
return this.ow.FormData !== undefined &&
|
|
94
98
|
typeof requestData !== '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>;
|
|
@@ -3,27 +3,52 @@
|
|
|
3
3
|
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
4
|
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { ERROR_CODE_CONFLICT } from "../../../core/constants.js";
|
|
7
|
+
import { error, isArray, isFunction, isPlainObject, toArray } from "../../../core/helpers/index.js";
|
|
8
|
+
import { Dlgs } from "../../../core/traits/dlgs.js";
|
|
9
|
+
import { Prompt } from "../../dialog/prompt.js";
|
|
7
10
|
import { send } from "./send.js";
|
|
11
|
+
import { UploadError } from "./upload-error.js";
|
|
8
12
|
/**
|
|
9
13
|
* Send files to server
|
|
10
14
|
*/
|
|
11
|
-
export function sendFiles(uploader, files, handlerSuccess, handlerError, process
|
|
15
|
+
export async function sendFiles(uploader, files, handlerSuccess, handlerError, process,
|
|
16
|
+
// Set when a refused upload is sent again: `beforeUpload` already had its say
|
|
17
|
+
retryOf) {
|
|
12
18
|
if (!files) {
|
|
13
|
-
|
|
19
|
+
throw error('Need files');
|
|
14
20
|
}
|
|
15
21
|
const { o } = uploader;
|
|
16
22
|
let fileList = toArray(files);
|
|
17
23
|
if (!fileList.length) {
|
|
18
|
-
|
|
24
|
+
throw error('Need files');
|
|
19
25
|
}
|
|
20
|
-
|
|
26
|
+
let extraData = retryOf === null || retryOf === void 0 ? void 0 : retryOf.data;
|
|
27
|
+
// Client-side validation hook — returning `false` aborts the upload, and it may hand back the files to send instead
|
|
21
28
|
// See https://github.com/xdan/jodit/issues/1329
|
|
22
|
-
if (isFunction(o.beforeUpload)) {
|
|
23
|
-
|
|
29
|
+
if (!retryOf && isFunction(o.beforeUpload)) {
|
|
30
|
+
let plan;
|
|
31
|
+
try {
|
|
32
|
+
plan = await o.beforeUpload.call(uploader, fileList);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
(handlerError || o.defaultHandlerError).call(uploader, e);
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
if (plan === false) {
|
|
24
39
|
const err = error('Upload canceled');
|
|
25
40
|
(handlerError || o.defaultHandlerError).call(uploader, err);
|
|
26
|
-
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
if (isArray(plan)) {
|
|
44
|
+
fileList = plan;
|
|
45
|
+
}
|
|
46
|
+
else if (isPlainObject(plan) && isArray(plan.files)) {
|
|
47
|
+
fileList = plan.files;
|
|
48
|
+
extraData = plan.data;
|
|
49
|
+
}
|
|
50
|
+
if (!fileList.length) {
|
|
51
|
+
return [];
|
|
27
52
|
}
|
|
28
53
|
}
|
|
29
54
|
const promises = [];
|
|
@@ -66,6 +91,11 @@ export function sendFiles(uploader, files, handlerSuccess, handlerError, process
|
|
|
66
91
|
form.append(key, o.data[key]);
|
|
67
92
|
});
|
|
68
93
|
}
|
|
94
|
+
if (extraData) {
|
|
95
|
+
Object.keys(extraData).forEach((key) => {
|
|
96
|
+
form.append(key, extraData[key]);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
69
99
|
o.prepareData.call(uploader, form);
|
|
70
100
|
promises.push(send(uploader, form)
|
|
71
101
|
.then(resp => {
|
|
@@ -76,10 +106,18 @@ export function sendFiles(uploader, files, handlerSuccess, handlerError, process
|
|
|
76
106
|
handler.call(uploader, o.process.call(uploader, resp));
|
|
77
107
|
return resp;
|
|
78
108
|
}
|
|
109
|
+
const err = new UploadError(o.getMessage.call(uploader, resp), resp, fileList, plan => {
|
|
110
|
+
var _a;
|
|
111
|
+
return sendFiles(uploader, (_a = plan === null || plan === void 0 ? void 0 : plan.files) !== null && _a !== void 0 ? _a : fileList, handlerSuccess, handlerError, process, { data: { ...extraData, ...plan === null || plan === void 0 ? void 0 : plan.data } });
|
|
112
|
+
});
|
|
113
|
+
// A taken name is part of the upload, not a failure: ask for another one first
|
|
114
|
+
if (err.code === ERROR_CODE_CONFLICT && o.promptOnExists) {
|
|
115
|
+
return askAnotherName(uploader, err);
|
|
116
|
+
}
|
|
79
117
|
const handler = isFunction(handlerError)
|
|
80
118
|
? handlerError
|
|
81
119
|
: o.defaultHandlerError;
|
|
82
|
-
handler.call(uploader,
|
|
120
|
+
handler.call(uploader, err);
|
|
83
121
|
return resp;
|
|
84
122
|
})
|
|
85
123
|
.then(() => {
|
|
@@ -88,6 +126,35 @@ export function sendFiles(uploader, files, handlerSuccess, handlerError, process
|
|
|
88
126
|
}
|
|
89
127
|
return Promise.all(promises);
|
|
90
128
|
}
|
|
129
|
+
function askAnotherName(uploader, err) {
|
|
130
|
+
const { files } = err;
|
|
131
|
+
// A batch is refused as a whole (the connector saved nothing) and the answer does not say which name is taken,
|
|
132
|
+
// so the files go again one by one: the free ones are simply stored, the taken one answers 409 alone and gets its prompt
|
|
133
|
+
if (files.length > 1) {
|
|
134
|
+
return files.reduce((chain, file) => chain.then(() => err.retry({ files: [file] })), Promise.resolve());
|
|
135
|
+
}
|
|
136
|
+
const [file] = files;
|
|
137
|
+
const { j, o } = uploader;
|
|
138
|
+
return new Promise(resolve => {
|
|
139
|
+
let answered = false;
|
|
140
|
+
// `Dlgs.prototype.dlg`: the uploader's view does not always carry the Dlgs trait
|
|
141
|
+
const dialog = Prompt.call(Dlgs.prototype.dlg.call(j, {
|
|
142
|
+
closeOnClickOverlay: true
|
|
143
|
+
}), j.i18n(err.message), j.i18n('Rename'), (newName) => {
|
|
144
|
+
newName = newName.trim();
|
|
145
|
+
if (!newName) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
answered = true;
|
|
149
|
+
resolve(err.retry({
|
|
150
|
+
files: [new File([file], newName, { type: file.type })]
|
|
151
|
+
}));
|
|
152
|
+
}, j.i18n('Enter new name'), o.promptOnExistsSuggestName.call(uploader, file.name));
|
|
153
|
+
dialog.e.on(dialog, 'afterClose', () => {
|
|
154
|
+
!answered && resolve(undefined);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
91
158
|
function readImagesWithReader(fileList, imagesExtensions, promises, uploader, handlerSuccess, defaultHandlerSuccess) {
|
|
92
159
|
const readerPromises = [];
|
|
93
160
|
let file, i;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import { AnswerError } from "../../../core/helpers/utils/error/index.js";
|
|
7
|
+
// The connector refused these files: the handler can change the request and send it again
|
|
8
|
+
export class UploadError extends AnswerError {
|
|
9
|
+
constructor(message, answer, files, retry) {
|
|
10
|
+
var _a;
|
|
11
|
+
super(message, answer, (_a = answer.data) === null || _a === void 0 ? void 0 : _a.code);
|
|
12
|
+
this.files = files;
|
|
13
|
+
this.retry = retry;
|
|
14
|
+
Object.setPrototypeOf(this, UploadError.prototype);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
import { STATUSES, ViewComponent } from "../../core/component/index.js";
|
|
7
7
|
import { IS_ES_NEXT, IS_IE } from "../../core/constants.js";
|
|
8
8
|
import { Dom } from "../../core/dom/dom.js";
|
|
9
|
-
import { attr, ConfigProto,
|
|
9
|
+
import { attr, ConfigProto, isFunction, isJoditObject } from "../../core/helpers/index.js";
|
|
10
|
+
import { answer } from "../../core/helpers/utils/error/index.js";
|
|
10
11
|
import { Config } from "../../config.js";
|
|
11
12
|
import { ajaxInstances, hasFiles, hasItems, processOldBrowserDrag, send, sendFiles } from "./helpers/index.js";
|
|
12
13
|
import "./config.js";
|
|
@@ -162,6 +163,7 @@ export class Uploader extends ViewComponent {
|
|
|
162
163
|
url
|
|
163
164
|
})
|
|
164
165
|
.then(resp => {
|
|
166
|
+
var _a;
|
|
165
167
|
if (o.isSuccess.call(uploader, resp)) {
|
|
166
168
|
const handler = isFunction(handlerSuccess)
|
|
167
169
|
? handlerSuccess
|
|
@@ -169,13 +171,23 @@ export class Uploader extends ViewComponent {
|
|
|
169
171
|
handler.call(uploader, o.process.call(uploader, resp));
|
|
170
172
|
return;
|
|
171
173
|
}
|
|
172
|
-
handlerE.call(uploader,
|
|
174
|
+
handlerE.call(uploader, answer(o.getMessage.call(uploader, resp), resp, (_a = resp.data) === null || _a === void 0 ? void 0 : _a.code));
|
|
173
175
|
})
|
|
174
176
|
.catch(e => handlerE.call(uploader, e));
|
|
175
177
|
}
|
|
176
178
|
upload(files) {
|
|
177
179
|
return this.async.promise((resolve, reject) => {
|
|
178
|
-
|
|
180
|
+
let settled = false;
|
|
181
|
+
const settle = (end) => (value) => {
|
|
182
|
+
settled = true;
|
|
183
|
+
end(value);
|
|
184
|
+
};
|
|
185
|
+
sendFiles(this, files, settle(resolve), settle(reject)).then(() => {
|
|
186
|
+
// `beforeUpload` kept no file, so no handler ran
|
|
187
|
+
if (!settled) {
|
|
188
|
+
resolve({ baseurl: '', files: [], isImages: [] });
|
|
189
|
+
}
|
|
190
|
+
}, settle(reject));
|
|
179
191
|
});
|
|
180
192
|
}
|
|
181
193
|
constructor(editor, options) {
|
|
@@ -20,6 +20,14 @@ function joinNeighbors(jodit, fakeNode, backspace, moved) {
|
|
|
20
20
|
if (checkJoinBareText(jodit, fakeNode, backspace)) {
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
|
+
// Old content can have an inline element round blocks beside the text:
|
|
24
|
+
// moved inside them, the line joins the block as it would bare text
|
|
25
|
+
// (#1781)
|
|
26
|
+
const inline = Dom.findNotEmptySibling(fakeNode, backspace);
|
|
27
|
+
if (joinsBareText(jodit, edgeBlock(inline, backspace)) &&
|
|
28
|
+
moveInlineInside(inline, jodit.editor)) {
|
|
29
|
+
return joinNeighbors(jodit, fakeNode, backspace, moved);
|
|
30
|
+
}
|
|
23
31
|
let nextBox = fakeNode, mainClosestBox = nextBox;
|
|
24
32
|
// Find the main big closest element
|
|
25
33
|
while (nextBox &&
|
|
@@ -350,13 +358,7 @@ function checkJoinInlineSibling(jodit, box, sibling, backspace) {
|
|
|
350
358
|
*/
|
|
351
359
|
function checkJoinBareText(jodit, fakeNode, backspace) {
|
|
352
360
|
const block = Dom.findNotEmptySibling(fakeNode, backspace);
|
|
353
|
-
if (!
|
|
354
|
-
!Dom.isBlock(block) ||
|
|
355
|
-
Dom.isList(block) ||
|
|
356
|
-
Dom.isTag(block, 'table') ||
|
|
357
|
-
Dom.isCell(block) ||
|
|
358
|
-
!Dom.isContentEditable(block, jodit.editor) ||
|
|
359
|
-
Array.from(block.childNodes).some(node => Dom.isBlock(node))) {
|
|
361
|
+
if (!joinsBareText(jodit, block)) {
|
|
360
362
|
return false;
|
|
361
363
|
}
|
|
362
364
|
const filter = getMoveFilter(jodit);
|
|
@@ -384,6 +386,33 @@ function checkJoinBareText(jodit, fakeNode, backspace) {
|
|
|
384
386
|
jodit.s.setCursorBefore(fakeNode);
|
|
385
387
|
return true;
|
|
386
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Whether a block joins the bare text beside it: not a list, a table or a
|
|
391
|
+
* cell, and holding no block of its own
|
|
392
|
+
*/
|
|
393
|
+
function joinsBareText(jodit, block) {
|
|
394
|
+
return (Dom.isElement(block) &&
|
|
395
|
+
Dom.isBlock(block) &&
|
|
396
|
+
!Dom.isList(block) &&
|
|
397
|
+
!Dom.isTag(block, 'table') &&
|
|
398
|
+
!Dom.isCell(block) &&
|
|
399
|
+
Dom.isContentEditable(block, jodit.editor) &&
|
|
400
|
+
!Array.from(block.childNodes).some(node => Dom.isBlock(node)));
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* The block an inline element holds on its side facing the caret, through
|
|
404
|
+
* the inline elements in it: the `<p>` of `<span><strong><p>…</p></strong></span>`
|
|
405
|
+
*/
|
|
406
|
+
function edgeBlock(node, backspace) {
|
|
407
|
+
var _a;
|
|
408
|
+
let edge = node;
|
|
409
|
+
while (Dom.isElement(edge) && !Dom.isBlock(edge)) {
|
|
410
|
+
const children = Array.from(edge.childNodes).filter(child => !Dom.isEmptyTextNode(child));
|
|
411
|
+
edge =
|
|
412
|
+
(_a = (backspace ? children[children.length - 1] : children[0])) !== null && _a !== void 0 ? _a : null;
|
|
413
|
+
}
|
|
414
|
+
return edge === node ? null : edge;
|
|
415
|
+
}
|
|
387
416
|
function checkMoveListContent(jodit, mainClosestBox, sibling, backspace) {
|
|
388
417
|
// Process UL/LI/OL cases
|
|
389
418
|
const siblingIsList = Dom.isTag(sibling, LIST_TAGS);
|