@mbs-dev/react-editor 1.13.2 → 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 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, _c, _d;
94
94
  var fn = this.jodit;
95
95
  var restoreToLastCaret = function () {
96
96
  var _a, _b;
@@ -124,8 +124,10 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
124
124
  selectionRef.current = null;
125
125
  }
126
126
  };
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) {
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) {
129
131
  var _a;
130
132
  var src = imageUrl ? "".concat(imageUrl, "/").concat(filename) : filename;
131
133
  restoreToLastCaret();
@@ -142,7 +144,8 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
142
144
  elm.setAttribute('href', src);
143
145
  elm.setAttribute('target', '_blank');
144
146
  elm.setAttribute('rel', 'noopener noreferrer');
145
- elm.textContent = getDisplayNameFromPath(filename);
147
+ var label = (origineFileName[idx] || '').trim();
148
+ elm.textContent = label ? label : getDisplayNameFromPath(filename);
146
149
  fn.s.insertNode(elm);
147
150
  if ((_a = fn === null || fn === void 0 ? void 0 : fn.s) === null || _a === void 0 ? void 0 : _a.setCursorAfter) {
148
151
  try {
@@ -155,19 +158,38 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
155
158
  }
156
159
  });
157
160
  }
158
- return !!(e === null || e === void 0 ? void 0 : e.success);
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;
159
165
  },
160
166
  getMessage: function (e) {
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('') : '';
167
+ var _a, _b;
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
+ 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
+ ? e.data.messages.join('')
173
+ : '';
163
174
  },
164
175
  process: function (resp) {
165
- var files = [];
166
- files.unshift(resp === null || resp === void 0 ? void 0 : resp.data);
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';
167
182
  return {
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,
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
+ },
171
193
  };
172
194
  },
173
195
  error: function (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbs-dev/react-editor",
3
- "version": "1.13.2",
3
+ "version": "1.13.3",
4
4
  "description": "react editor",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/src/Editor.tsx CHANGED
@@ -92,8 +92,11 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
92
92
  }
93
93
  };
94
94
 
95
- if (e?.data?.files && e.data.files.length) {
96
- e.data.files.forEach((filename: string) => {
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) => {
97
100
  const src = imageUrl ? `${imageUrl}/${filename}` : filename;
98
101
 
99
102
  // ✅ Restore caret BEFORE inserting anything (image or file)
@@ -112,7 +115,10 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
112
115
  elm.setAttribute('href', src);
113
116
  elm.setAttribute('target', '_blank');
114
117
  elm.setAttribute('rel', 'noopener noreferrer');
115
- elm.textContent = getDisplayNameFromPath(filename);
118
+
119
+ // ✅ For files: display origineFileName (no filename display for images)
120
+ const label = (origineFileName[idx] || '').trim();
121
+ elm.textContent = label ? label : getDisplayNameFromPath(filename);
116
122
 
117
123
  fn.s.insertNode(elm);
118
124
 
@@ -129,20 +135,45 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
129
135
  });
130
136
  }
131
137
 
132
- return !!e?.success;
138
+ const ok =
139
+ typeof e?.success !== 'undefined'
140
+ ? !!e.success
141
+ : e?.data?.error === 0 || e?.data?.error === '0';
142
+
143
+ return ok;
133
144
  },
134
145
  getMessage(e: any): string {
135
- return e?.data?.messages && Array.isArray(e.data.messages) ? e.data.messages.join('') : '';
146
+ if (typeof e?.data?.msg === 'string' && e.data.msg.trim()) {
147
+ return e.data.msg;
148
+ }
149
+
150
+ return e?.data?.messages && Array.isArray(e.data.messages)
151
+ ? e.data.messages.join('')
152
+ : '';
136
153
  },
137
154
  process(resp: any): { files: any[]; error: string; msg: string } {
138
- const files: any[] = [];
139
- files.unshift(resp?.data);
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';
140
162
 
141
163
  return {
142
- files: resp?.data,
143
- error: resp?.msg,
144
- msg: resp?.msg,
145
- };
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;
146
177
  },
147
178
  error(this: any, e: Error): void {
148
179
  this.j.e.fire('errorMessage', e.message, 'error', 4000);
@@ -334,4 +365,4 @@ export const config = ({ includeUploader, apiUrl, imageUrl, onDeleteImage }: Con
334
365
  return base;
335
366
  };
336
367
 
337
- export default ReactEditor;
368
+ export default ReactEditor;