@mbs-dev/react-editor 1.10.0 → 1.11.0
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 +43 -16
- package/package.json +1 -1
- package/src/Editor.tsx +45 -12
package/dist/Editor.js
CHANGED
|
@@ -90,7 +90,7 @@ 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;
|
|
94
94
|
var fn = this.jodit;
|
|
95
95
|
var restoreToLastCaret = function () {
|
|
96
96
|
var _a, _b;
|
|
@@ -124,12 +124,31 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
|
|
|
124
124
|
selectionRef.current = null;
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
var normalizedFiles = (function () {
|
|
128
|
+
var _a, _b, _c;
|
|
129
|
+
var raw = (_c = (_a = (Array.isArray(e === null || e === void 0 ? void 0 : e.files) ? e.files : null)) !== null && _a !== void 0 ? _a : (Array.isArray((_b = e === null || e === void 0 ? void 0 : e.data) === null || _b === void 0 ? void 0 : _b.files) ? e.data.files : null)) !== null && _c !== void 0 ? _c : [];
|
|
130
|
+
return raw
|
|
131
|
+
.map(function (item) {
|
|
129
132
|
var _a;
|
|
130
|
-
|
|
133
|
+
if (typeof item === 'string')
|
|
134
|
+
return { file: item };
|
|
135
|
+
if (item && typeof item === 'object') {
|
|
136
|
+
return {
|
|
137
|
+
file: String((_a = item.file) !== null && _a !== void 0 ? _a : ''),
|
|
138
|
+
origineFileName: item.origineFileName ? String(item.origineFileName) : undefined,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return { file: '' };
|
|
142
|
+
})
|
|
143
|
+
.filter(function (x) { return !!x.file; });
|
|
144
|
+
})();
|
|
145
|
+
if (normalizedFiles.length) {
|
|
146
|
+
normalizedFiles.forEach(function (_a) {
|
|
147
|
+
var _b;
|
|
148
|
+
var file = _a.file, origineFileName = _a.origineFileName;
|
|
149
|
+
var src = imageUrl ? "".concat(imageUrl, "/").concat(file) : file;
|
|
131
150
|
restoreToLastCaret();
|
|
132
|
-
if (isImageByExtension(
|
|
151
|
+
if (isImageByExtension(file, _this.imagesExtensions || ['jpg', 'png', 'jpeg', 'gif', 'webp'])) {
|
|
133
152
|
var tagName = 'img';
|
|
134
153
|
var elm = fn.createInside.element(tagName);
|
|
135
154
|
elm.setAttribute('src', src);
|
|
@@ -142,32 +161,40 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
|
|
|
142
161
|
elm.setAttribute('href', src);
|
|
143
162
|
elm.setAttribute('target', '_blank');
|
|
144
163
|
elm.setAttribute('rel', 'noopener noreferrer');
|
|
145
|
-
elm.textContent = getDisplayNameFromPath(
|
|
164
|
+
elm.textContent = origineFileName || getDisplayNameFromPath(file);
|
|
146
165
|
fn.s.insertNode(elm);
|
|
147
|
-
if ((
|
|
166
|
+
if ((_b = fn === null || fn === void 0 ? void 0 : fn.s) === null || _b === void 0 ? void 0 : _b.setCursorAfter) {
|
|
148
167
|
try {
|
|
149
168
|
fn.s.setCursorAfter(elm);
|
|
150
169
|
}
|
|
151
|
-
catch (
|
|
170
|
+
catch (_c) {
|
|
152
171
|
}
|
|
153
172
|
}
|
|
154
173
|
refreshSavedRange();
|
|
155
174
|
}
|
|
156
175
|
});
|
|
157
176
|
}
|
|
158
|
-
|
|
177
|
+
var err = (_a = (typeof (e === null || e === void 0 ? void 0 : e.error) === 'number' ? e.error : undefined)) !== null && _a !== void 0 ? _a : (typeof ((_b = e === null || e === void 0 ? void 0 : e.data) === null || _b === void 0 ? void 0 : _b.error) === 'number' ? e.data.error : undefined);
|
|
178
|
+
if ((e === null || e === void 0 ? void 0 : e.success) === true)
|
|
179
|
+
return true;
|
|
180
|
+
if (typeof err === 'number')
|
|
181
|
+
return err === 0;
|
|
182
|
+
return false;
|
|
159
183
|
},
|
|
160
184
|
getMessage: function (e) {
|
|
161
|
-
var _a;
|
|
162
|
-
|
|
185
|
+
var _a, _b;
|
|
186
|
+
var msg = (_a = e === null || e === void 0 ? void 0 : e.msg) !== null && _a !== void 0 ? _a : (_b = e === null || e === void 0 ? void 0 : e.data) === null || _b === void 0 ? void 0 : _b.msg;
|
|
187
|
+
return typeof msg === 'string' ? msg : '';
|
|
163
188
|
},
|
|
164
189
|
process: function (resp) {
|
|
165
|
-
var
|
|
166
|
-
files.
|
|
190
|
+
var payload = (resp === null || resp === void 0 ? void 0 : resp.data) ? resp.data : resp;
|
|
191
|
+
var files = Array.isArray(payload === null || payload === void 0 ? void 0 : payload.files) ? payload.files : [];
|
|
192
|
+
var error = payload === null || payload === void 0 ? void 0 : payload.error;
|
|
193
|
+
var msg = payload === null || payload === void 0 ? void 0 : payload.msg;
|
|
167
194
|
return {
|
|
168
|
-
files:
|
|
169
|
-
error:
|
|
170
|
-
msg:
|
|
195
|
+
files: files,
|
|
196
|
+
error: typeof error === 'number' ? String(error) : (error !== null && error !== void 0 ? error : ''),
|
|
197
|
+
msg: typeof msg === 'string' ? msg : '',
|
|
171
198
|
};
|
|
172
199
|
},
|
|
173
200
|
error: function (e) {
|
package/package.json
CHANGED
package/src/Editor.tsx
CHANGED
|
@@ -92,15 +92,35 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
const normalizedFiles: Array<{ file: string; origineFileName?: string }> = (() => {
|
|
96
|
+
const raw =
|
|
97
|
+
(Array.isArray(e?.files) ? e.files : null) ??
|
|
98
|
+
(Array.isArray(e?.data?.files) ? e.data.files : null) ??
|
|
99
|
+
[];
|
|
100
|
+
|
|
101
|
+
return raw
|
|
102
|
+
.map((item: any) => {
|
|
103
|
+
if (typeof item === 'string') return { file: item };
|
|
104
|
+
if (item && typeof item === 'object') {
|
|
105
|
+
return {
|
|
106
|
+
file: String(item.file ?? ''),
|
|
107
|
+
origineFileName: item.origineFileName ? String(item.origineFileName) : undefined,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return { file: '' };
|
|
111
|
+
})
|
|
112
|
+
.filter((x: { file: any; }) => !!x.file);
|
|
113
|
+
})();
|
|
114
|
+
|
|
115
|
+
if (normalizedFiles.length) {
|
|
116
|
+
normalizedFiles.forEach(({ file, origineFileName }) => {
|
|
117
|
+
const src = imageUrl ? `${imageUrl}/${file}` : file;
|
|
98
118
|
|
|
99
119
|
// ✅ Restore caret BEFORE inserting anything (image or file)
|
|
100
120
|
restoreToLastCaret();
|
|
101
121
|
|
|
102
122
|
// ✅ If it's an image => insert <img>, otherwise insert <a href="...">
|
|
103
|
-
if (isImageByExtension(
|
|
123
|
+
if (isImageByExtension(file, this.imagesExtensions || ['jpg', 'png', 'jpeg', 'gif', 'webp'])) {
|
|
104
124
|
const tagName = 'img';
|
|
105
125
|
const elm = fn.createInside.element(tagName);
|
|
106
126
|
elm.setAttribute('src', src);
|
|
@@ -112,7 +132,9 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
|
|
|
112
132
|
elm.setAttribute('href', src);
|
|
113
133
|
elm.setAttribute('target', '_blank');
|
|
114
134
|
elm.setAttribute('rel', 'noopener noreferrer');
|
|
115
|
-
|
|
135
|
+
|
|
136
|
+
// ✅ Display origineFileName (new response), fallback to previous logic
|
|
137
|
+
elm.textContent = origineFileName || getDisplayNameFromPath(file);
|
|
116
138
|
|
|
117
139
|
fn.s.insertNode(elm);
|
|
118
140
|
|
|
@@ -129,19 +151,30 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
|
|
|
129
151
|
});
|
|
130
152
|
}
|
|
131
153
|
|
|
132
|
-
|
|
154
|
+
const err =
|
|
155
|
+
(typeof e?.error === 'number' ? e.error : undefined) ??
|
|
156
|
+
(typeof e?.data?.error === 'number' ? e.data.error : undefined);
|
|
157
|
+
|
|
158
|
+
if (e?.success === true) return true;
|
|
159
|
+
if (typeof err === 'number') return err === 0;
|
|
160
|
+
|
|
161
|
+
return false;
|
|
133
162
|
},
|
|
134
163
|
getMessage(e: any): string {
|
|
135
|
-
|
|
164
|
+
const msg = e?.msg ?? e?.data?.msg;
|
|
165
|
+
return typeof msg === 'string' ? msg : '';
|
|
136
166
|
},
|
|
137
167
|
process(resp: any): { files: any[]; error: string; msg: string } {
|
|
138
|
-
const
|
|
139
|
-
|
|
168
|
+
const payload = resp?.data ? resp.data : resp;
|
|
169
|
+
|
|
170
|
+
const files = Array.isArray(payload?.files) ? payload.files : [];
|
|
171
|
+
const error = payload?.error;
|
|
172
|
+
const msg = payload?.msg;
|
|
140
173
|
|
|
141
174
|
return {
|
|
142
|
-
files
|
|
143
|
-
error:
|
|
144
|
-
msg:
|
|
175
|
+
files,
|
|
176
|
+
error: typeof error === 'number' ? String(error) : (error ?? ''),
|
|
177
|
+
msg: typeof msg === 'string' ? msg : '',
|
|
145
178
|
};
|
|
146
179
|
},
|
|
147
180
|
error(this: any, e: Error): void {
|