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