@mbs-dev/react-editor 1.13.2 → 1.13.4

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
@@ -88,9 +88,11 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
88
88
  prepareData: function (formdata) {
89
89
  return formdata;
90
90
  },
91
+ defaultHandlerSuccess: function () {
92
+ return;
93
+ },
91
94
  isSuccess: function (e) {
92
95
  var _this = this;
93
- var _a;
94
96
  var fn = this.jodit;
95
97
  var restoreToLastCaret = function () {
96
98
  var _a, _b;
@@ -124,8 +126,10 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
124
126
  selectionRef.current = null;
125
127
  }
126
128
  };
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) {
129
+ var files = Array.isArray(e === null || e === void 0 ? void 0 : e.files) ? e.files : [];
130
+ var origineFileName = Array.isArray(e === null || e === void 0 ? void 0 : e.origineFileName) ? e.origineFileName : [];
131
+ if (files.length) {
132
+ files.forEach(function (filename, idx) {
129
133
  var _a;
130
134
  var src = imageUrl ? "".concat(imageUrl, "/").concat(filename) : filename;
131
135
  restoreToLastCaret();
@@ -142,7 +146,8 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
142
146
  elm.setAttribute('href', src);
143
147
  elm.setAttribute('target', '_blank');
144
148
  elm.setAttribute('rel', 'noopener noreferrer');
145
- elm.textContent = getDisplayNameFromPath(filename);
149
+ var label = typeof origineFileName[idx] === 'string' ? origineFileName[idx].trim() : '';
150
+ elm.textContent = label ? label : getDisplayNameFromPath(filename);
146
151
  fn.s.insertNode(elm);
147
152
  if ((_a = fn === null || fn === void 0 ? void 0 : fn.s) === null || _a === void 0 ? void 0 : _a.setCursorAfter) {
148
153
  try {
@@ -155,19 +160,32 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
155
160
  }
156
161
  });
157
162
  }
158
- return !!(e === null || e === void 0 ? void 0 : e.success);
163
+ var ok = typeof (e === null || e === void 0 ? void 0 : e.success) !== 'undefined'
164
+ ? !!e.success
165
+ : (e === null || e === void 0 ? void 0 : e.error) === 0 || (e === null || e === void 0 ? void 0 : e.error) === '0';
166
+ return ok;
159
167
  },
160
168
  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('') : '';
169
+ if (typeof (e === null || e === void 0 ? void 0 : e.msg) === 'string' && e.msg.trim()) {
170
+ return e.msg;
171
+ }
172
+ return (e === null || e === void 0 ? void 0 : e.messages) && Array.isArray(e.messages)
173
+ ? e.messages.join('')
174
+ : '';
163
175
  },
164
176
  process: function (resp) {
165
- var files = [];
166
- files.unshift(resp === null || resp === void 0 ? void 0 : resp.data);
177
+ var _a, _b, _c, _d;
178
+ 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 : [];
179
+ 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 : [];
180
+ var errorCode = (_c = resp === null || resp === void 0 ? void 0 : resp.data) === null || _c === void 0 ? void 0 : _c.error;
181
+ 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) || '');
182
+ var success = errorCode === 0 || errorCode === '0';
167
183
  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,
184
+ files: files,
185
+ origineFileName: origineFileName,
186
+ error: errorCode,
187
+ msg: msg,
188
+ success: success,
171
189
  };
172
190
  },
173
191
  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.4",
4
4
  "description": "react editor",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/src/Editor.tsx CHANGED
@@ -55,6 +55,12 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
55
55
  prepareData(formdata: FormData): FormData {
56
56
  return formdata;
57
57
  },
58
+
59
+ // ✅ prevent Jodit default insertion (it was adding "undefined + filename")
60
+ defaultHandlerSuccess(this: any): void {
61
+ return;
62
+ },
63
+
58
64
  isSuccess(this: any, e: any): boolean {
59
65
  const fn = this.jodit;
60
66
 
@@ -92,8 +98,11 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
92
98
  }
93
99
  };
94
100
 
95
- if (e?.data?.files && e.data.files.length) {
96
- e.data.files.forEach((filename: string) => {
101
+ const files: string[] = Array.isArray(e?.files) ? e.files : [];
102
+ const origineFileName: string[] = Array.isArray(e?.origineFileName) ? e.origineFileName : [];
103
+
104
+ if (files.length) {
105
+ files.forEach((filename: string, idx: number) => {
97
106
  const src = imageUrl ? `${imageUrl}/${filename}` : filename;
98
107
 
99
108
  // ✅ Restore caret BEFORE inserting anything (image or file)
@@ -112,7 +121,10 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
112
121
  elm.setAttribute('href', src);
113
122
  elm.setAttribute('target', '_blank');
114
123
  elm.setAttribute('rel', 'noopener noreferrer');
115
- elm.textContent = getDisplayNameFromPath(filename);
124
+
125
+ // ✅ For files: display origineFileName ONLY (fallback if missing)
126
+ const label = typeof origineFileName[idx] === 'string' ? origineFileName[idx].trim() : '';
127
+ elm.textContent = label ? label : getDisplayNameFromPath(filename);
116
128
 
117
129
  fn.s.insertNode(elm);
118
130
 
@@ -129,20 +141,38 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
129
141
  });
130
142
  }
131
143
 
132
- return !!e?.success;
144
+ const ok =
145
+ typeof e?.success !== 'undefined'
146
+ ? !!e.success
147
+ : e?.error === 0 || e?.error === '0';
148
+
149
+ return ok;
133
150
  },
134
151
  getMessage(e: any): string {
135
- return e?.data?.messages && Array.isArray(e.data.messages) ? e.data.messages.join('') : '';
152
+ if (typeof e?.msg === 'string' && e.msg.trim()) {
153
+ return e.msg;
154
+ }
155
+
156
+ return e?.messages && Array.isArray(e.messages)
157
+ ? e.messages.join('')
158
+ : '';
136
159
  },
137
- process(resp: any): { files: any[]; error: string; msg: string } {
138
- const files: any[] = [];
139
- files.unshift(resp?.data);
160
+ process(resp: any): { files: any[]; error: any; msg: string; origineFileName?: any[]; success?: boolean } {
161
+ const files: any[] = Array.isArray(resp?.data?.files) ? resp.data.files : [];
162
+ const origineFileName: any[] = Array.isArray(resp?.data?.origineFileName) ? resp.data.origineFileName : [];
163
+
164
+ const errorCode = resp?.data?.error;
165
+ const msg = typeof resp?.data?.msg === 'string' ? resp.data.msg : (resp?.msg || '');
166
+
167
+ const success = errorCode === 0 || errorCode === '0';
140
168
 
141
169
  return {
142
- files: resp?.data,
143
- error: resp?.msg,
144
- msg: resp?.msg,
145
- };
170
+ files,
171
+ origineFileName,
172
+ error: errorCode,
173
+ msg,
174
+ success,
175
+ } as any;
146
176
  },
147
177
  error(this: any, e: Error): void {
148
178
  this.j.e.fire('errorMessage', e.message, 'error', 4000);
@@ -334,4 +364,4 @@ export const config = ({ includeUploader, apiUrl, imageUrl, onDeleteImage }: Con
334
364
  return base;
335
365
  };
336
366
 
337
- export default ReactEditor;
367
+ export default ReactEditor;
package/types/Editor.d.ts CHANGED
@@ -12,12 +12,15 @@ export declare const uploaderConfig: (apiUrl?: string, imageUrl?: string, select
12
12
  format: string;
13
13
  method: string;
14
14
  prepareData(formdata: FormData): FormData;
15
+ defaultHandlerSuccess(this: any): void;
15
16
  isSuccess(this: any, e: any): boolean;
16
17
  getMessage(e: any): string;
17
18
  process(resp: any): {
18
19
  files: any[];
19
- error: string;
20
+ error: any;
20
21
  msg: string;
22
+ origineFileName?: any[] | undefined;
23
+ success?: boolean | undefined;
21
24
  };
22
25
  error(this: any, e: Error): void;
23
26
  defaultHandlerError(this: any, e: any): void;