@mbs-dev/react-editor 1.13.1 → 1.13.3
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/dist/Editor.js +29 -18
- package/package.json +1 -1
- package/src/Editor.tsx +39 -26
- package/types/Editor.d.ts +5 -1
package/dist/Editor.js
CHANGED
|
@@ -90,9 +90,8 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
|
|
|
90
90
|
},
|
|
91
91
|
isSuccess: function (e) {
|
|
92
92
|
var _this = this;
|
|
93
|
-
var _a;
|
|
93
|
+
var _a, _b, _c, _d;
|
|
94
94
|
var fn = this.jodit;
|
|
95
|
-
var data = ((_a = e === null || e === void 0 ? void 0 : e.data) !== null && _a !== void 0 ? _a : e);
|
|
96
95
|
var restoreToLastCaret = function () {
|
|
97
96
|
var _a, _b;
|
|
98
97
|
var saved = selectionRef === null || selectionRef === void 0 ? void 0 : selectionRef.current;
|
|
@@ -125,8 +124,10 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
|
|
|
125
124
|
selectionRef.current = null;
|
|
126
125
|
}
|
|
127
126
|
};
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
var files = Array.isArray((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.files) ? e.data.files : [];
|
|
128
|
+
var origineFileName = Array.isArray((_b = e === null || e === void 0 ? void 0 : e.data) === null || _b === void 0 ? void 0 : _b.origineFileName) ? e.data.origineFileName : [];
|
|
129
|
+
if (files.length) {
|
|
130
|
+
files.forEach(function (filename, idx) {
|
|
130
131
|
var _a;
|
|
131
132
|
var src = imageUrl ? "".concat(imageUrl, "/").concat(filename) : filename;
|
|
132
133
|
restoreToLastCaret();
|
|
@@ -143,9 +144,8 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
|
|
|
143
144
|
elm.setAttribute('href', src);
|
|
144
145
|
elm.setAttribute('target', '_blank');
|
|
145
146
|
elm.setAttribute('rel', 'noopener noreferrer');
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
getDisplayNameFromPath(filename);
|
|
147
|
+
var label = (origineFileName[idx] || '').trim();
|
|
148
|
+
elm.textContent = label ? label : getDisplayNameFromPath(filename);
|
|
149
149
|
fn.s.insertNode(elm);
|
|
150
150
|
if ((_a = fn === null || fn === void 0 ? void 0 : fn.s) === null || _a === void 0 ? void 0 : _a.setCursorAfter) {
|
|
151
151
|
try {
|
|
@@ -158,27 +158,38 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
|
|
|
158
158
|
}
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return
|
|
161
|
+
var ok = typeof (e === null || e === void 0 ? void 0 : e.success) !== 'undefined'
|
|
162
|
+
? !!e.success
|
|
163
|
+
: ((_c = e === null || e === void 0 ? void 0 : e.data) === null || _c === void 0 ? void 0 : _c.error) === 0 || ((_d = e === null || e === void 0 ? void 0 : e.data) === null || _d === void 0 ? void 0 : _d.error) === '0';
|
|
164
|
+
return ok;
|
|
165
165
|
},
|
|
166
166
|
getMessage: function (e) {
|
|
167
167
|
var _a, _b;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
if (typeof ((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.msg) === 'string' && e.data.msg.trim()) {
|
|
169
|
+
return e.data.msg;
|
|
170
|
+
}
|
|
171
171
|
return ((_b = e === null || e === void 0 ? void 0 : e.data) === null || _b === void 0 ? void 0 : _b.messages) && Array.isArray(e.data.messages)
|
|
172
172
|
? e.data.messages.join('')
|
|
173
173
|
: '';
|
|
174
174
|
},
|
|
175
175
|
process: function (resp) {
|
|
176
176
|
var _a, _b, _c, _d;
|
|
177
|
+
var files = Array.isArray((_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.files) ? resp.data.files : [];
|
|
178
|
+
var origineFileName = Array.isArray((_b = resp === null || resp === void 0 ? void 0 : resp.data) === null || _b === void 0 ? void 0 : _b.origineFileName) ? resp.data.origineFileName : [];
|
|
179
|
+
var errorCode = (_c = resp === null || resp === void 0 ? void 0 : resp.data) === null || _c === void 0 ? void 0 : _c.error;
|
|
180
|
+
var msg = typeof ((_d = resp === null || resp === void 0 ? void 0 : resp.data) === null || _d === void 0 ? void 0 : _d.msg) === 'string' ? resp.data.msg : ((resp === null || resp === void 0 ? void 0 : resp.msg) || '');
|
|
181
|
+
var success = errorCode === 0 || errorCode === '0';
|
|
177
182
|
return {
|
|
178
|
-
files:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
183
|
+
files: files,
|
|
184
|
+
error: typeof errorCode !== 'undefined' ? String(errorCode) : '',
|
|
185
|
+
msg: msg,
|
|
186
|
+
success: success,
|
|
187
|
+
data: {
|
|
188
|
+
files: files,
|
|
189
|
+
origineFileName: origineFileName,
|
|
190
|
+
error: errorCode,
|
|
191
|
+
msg: msg,
|
|
192
|
+
},
|
|
182
193
|
};
|
|
183
194
|
},
|
|
184
195
|
error: function (e) {
|
package/package.json
CHANGED
package/src/Editor.tsx
CHANGED
|
@@ -58,13 +58,6 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
|
|
|
58
58
|
isSuccess(this: any, e: any): boolean {
|
|
59
59
|
const fn = this.jodit;
|
|
60
60
|
|
|
61
|
-
const data = (e?.data ?? e) as {
|
|
62
|
-
files?: string[];
|
|
63
|
-
origineFileName?: string[];
|
|
64
|
-
error?: number;
|
|
65
|
-
msg?: string;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
61
|
const restoreToLastCaret = () => {
|
|
69
62
|
const saved = selectionRef?.current;
|
|
70
63
|
|
|
@@ -99,8 +92,11 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
|
|
|
99
92
|
}
|
|
100
93
|
};
|
|
101
94
|
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
const files: string[] = Array.isArray(e?.data?.files) ? e.data.files : [];
|
|
96
|
+
const origineFileName: string[] = Array.isArray(e?.data?.origineFileName) ? e.data.origineFileName : [];
|
|
97
|
+
|
|
98
|
+
if (files.length) {
|
|
99
|
+
files.forEach((filename: string, idx: number) => {
|
|
104
100
|
const src = imageUrl ? `${imageUrl}/${filename}` : filename;
|
|
105
101
|
|
|
106
102
|
// ✅ Restore caret BEFORE inserting anything (image or file)
|
|
@@ -120,10 +116,9 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
|
|
|
120
116
|
elm.setAttribute('target', '_blank');
|
|
121
117
|
elm.setAttribute('rel', 'noopener noreferrer');
|
|
122
118
|
|
|
123
|
-
// ✅
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
getDisplayNameFromPath(filename);
|
|
119
|
+
// ✅ For files: display origineFileName (no filename display for images)
|
|
120
|
+
const label = (origineFileName[idx] || '').trim();
|
|
121
|
+
elm.textContent = label ? label : getDisplayNameFromPath(filename);
|
|
127
122
|
|
|
128
123
|
fn.s.insertNode(elm);
|
|
129
124
|
|
|
@@ -140,27 +135,45 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
|
|
|
140
135
|
});
|
|
141
136
|
}
|
|
142
137
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
138
|
+
const ok =
|
|
139
|
+
typeof e?.success !== 'undefined'
|
|
140
|
+
? !!e.success
|
|
141
|
+
: e?.data?.error === 0 || e?.data?.error === '0';
|
|
146
142
|
|
|
147
|
-
return
|
|
143
|
+
return ok;
|
|
148
144
|
},
|
|
149
145
|
getMessage(e: any): string {
|
|
150
|
-
|
|
151
|
-
|
|
146
|
+
if (typeof e?.data?.msg === 'string' && e.data.msg.trim()) {
|
|
147
|
+
return e.data.msg;
|
|
148
|
+
}
|
|
152
149
|
|
|
153
150
|
return e?.data?.messages && Array.isArray(e.data.messages)
|
|
154
151
|
? e.data.messages.join('')
|
|
155
152
|
: '';
|
|
156
153
|
},
|
|
157
|
-
process(resp: any): any {
|
|
154
|
+
process(resp: any): { files: any[]; error: string; msg: string } {
|
|
155
|
+
const files: any[] = Array.isArray(resp?.data?.files) ? resp.data.files : [];
|
|
156
|
+
const origineFileName: any[] = Array.isArray(resp?.data?.origineFileName) ? resp.data.origineFileName : [];
|
|
157
|
+
|
|
158
|
+
const errorCode = resp?.data?.error;
|
|
159
|
+
const msg = typeof resp?.data?.msg === 'string' ? resp.data.msg : (resp?.msg || '');
|
|
160
|
+
|
|
161
|
+
const success = errorCode === 0 || errorCode === '0';
|
|
162
|
+
|
|
158
163
|
return {
|
|
159
|
-
files
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
+
files,
|
|
165
|
+
error: typeof errorCode !== 'undefined' ? String(errorCode) : '',
|
|
166
|
+
msg,
|
|
167
|
+
|
|
168
|
+
// Extra fields used by isSuccess/getMessage (kept compatible)
|
|
169
|
+
success,
|
|
170
|
+
data: {
|
|
171
|
+
files,
|
|
172
|
+
origineFileName,
|
|
173
|
+
error: errorCode,
|
|
174
|
+
msg,
|
|
175
|
+
},
|
|
176
|
+
} as any;
|
|
164
177
|
},
|
|
165
178
|
error(this: any, e: Error): void {
|
|
166
179
|
this.j.e.fire('errorMessage', e.message, 'error', 4000);
|
|
@@ -352,4 +365,4 @@ export const config = ({ includeUploader, apiUrl, imageUrl, onDeleteImage }: Con
|
|
|
352
365
|
return base;
|
|
353
366
|
};
|
|
354
367
|
|
|
355
|
-
export default ReactEditor;
|
|
368
|
+
export default ReactEditor;
|
package/types/Editor.d.ts
CHANGED
|
@@ -14,7 +14,11 @@ export declare const uploaderConfig: (apiUrl?: string, imageUrl?: string, select
|
|
|
14
14
|
prepareData(formdata: FormData): FormData;
|
|
15
15
|
isSuccess(this: any, e: any): boolean;
|
|
16
16
|
getMessage(e: any): string;
|
|
17
|
-
process(resp: any):
|
|
17
|
+
process(resp: any): {
|
|
18
|
+
files: any[];
|
|
19
|
+
error: string;
|
|
20
|
+
msg: string;
|
|
21
|
+
};
|
|
18
22
|
error(this: any, e: Error): void;
|
|
19
23
|
defaultHandlerError(this: any, e: any): void;
|
|
20
24
|
};
|