@mbs-dev/react-editor 1.13.0 → 1.13.1

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
@@ -92,6 +92,7 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
92
92
  var _this = this;
93
93
  var _a;
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);
95
96
  var restoreToLastCaret = function () {
96
97
  var _a, _b;
97
98
  var saved = selectionRef === null || selectionRef === void 0 ? void 0 : selectionRef.current;
@@ -124,8 +125,8 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
124
125
  selectionRef.current = null;
125
126
  }
126
127
  };
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) {
128
+ if ((data === null || data === void 0 ? void 0 : data.files) && data.files.length) {
129
+ data.files.forEach(function (filename, idx) {
129
130
  var _a;
130
131
  var src = imageUrl ? "".concat(imageUrl, "/").concat(filename) : filename;
131
132
  restoreToLastCaret();
@@ -142,7 +143,9 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
142
143
  elm.setAttribute('href', src);
143
144
  elm.setAttribute('target', '_blank');
144
145
  elm.setAttribute('rel', 'noopener noreferrer');
145
- elm.textContent = getDisplayNameFromPath(filename);
146
+ elm.textContent =
147
+ ((data === null || data === void 0 ? void 0 : data.origineFileName) && data.origineFileName[idx]) ||
148
+ 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,27 @@ var uploaderConfig = function (apiUrl, imageUrl, selectionRef) { return ({
155
158
  }
156
159
  });
157
160
  }
161
+ if (typeof (data === null || data === void 0 ? void 0 : data.error) !== 'undefined') {
162
+ return Number(data.error) === 0;
163
+ }
158
164
  return !!(e === null || e === void 0 ? void 0 : e.success);
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
+ var data = ((_a = e === null || e === void 0 ? void 0 : e.data) !== null && _a !== void 0 ? _a : e);
169
+ if (typeof (data === null || data === void 0 ? void 0 : data.msg) === 'string')
170
+ return data.msg;
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;
167
177
  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,
178
+ files: (_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.files,
179
+ origineFileName: (_b = resp === null || resp === void 0 ? void 0 : resp.data) === null || _b === void 0 ? void 0 : _b.origineFileName,
180
+ error: (_c = resp === null || resp === void 0 ? void 0 : resp.data) === null || _c === void 0 ? void 0 : _c.error,
181
+ msg: (_d = resp === null || resp === void 0 ? void 0 : resp.data) === null || _d === void 0 ? void 0 : _d.msg,
171
182
  };
172
183
  },
173
184
  error: function (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbs-dev/react-editor",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "description": "react editor",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/src/Editor.tsx CHANGED
@@ -58,6 +58,13 @@ 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
+
61
68
  const restoreToLastCaret = () => {
62
69
  const saved = selectionRef?.current;
63
70
 
@@ -92,8 +99,8 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
92
99
  }
93
100
  };
94
101
 
95
- if (e?.data?.files && e.data.files.length) {
96
- e.data.files.forEach((filename: string) => {
102
+ if (data?.files && data.files.length) {
103
+ data.files.forEach((filename: string, idx: number) => {
97
104
  const src = imageUrl ? `${imageUrl}/${filename}` : filename;
98
105
 
99
106
  // ✅ Restore caret BEFORE inserting anything (image or file)
@@ -112,7 +119,11 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
112
119
  elm.setAttribute('href', src);
113
120
  elm.setAttribute('target', '_blank');
114
121
  elm.setAttribute('rel', 'noopener noreferrer');
115
- elm.textContent = getDisplayNameFromPath(filename);
122
+
123
+ // ✅ Display origineFileName for files (not images)
124
+ elm.textContent =
125
+ (data?.origineFileName && data.origineFileName[idx]) ||
126
+ getDisplayNameFromPath(filename);
116
127
 
117
128
  fn.s.insertNode(elm);
118
129
 
@@ -129,19 +140,26 @@ export const uploaderConfig = (apiUrl?: string, imageUrl?: string, selectionRef?
129
140
  });
130
141
  }
131
142
 
143
+ if (typeof data?.error !== 'undefined') {
144
+ return Number(data.error) === 0;
145
+ }
146
+
132
147
  return !!e?.success;
133
148
  },
134
149
  getMessage(e: any): string {
135
- return e?.data?.messages && Array.isArray(e.data.messages) ? e.data.messages.join('') : '';
136
- },
137
- process(resp: any): { files: any[]; error: string; msg: string } {
138
- const files: any[] = [];
139
- files.unshift(resp?.data);
150
+ const data = (e?.data ?? e) as { msg?: string; messages?: unknown };
151
+ if (typeof data?.msg === 'string') return data.msg;
140
152
 
153
+ return e?.data?.messages && Array.isArray(e.data.messages)
154
+ ? e.data.messages.join('')
155
+ : '';
156
+ },
157
+ process(resp: any): any {
141
158
  return {
142
- files: resp?.data,
143
- error: resp?.msg,
144
- msg: resp?.msg,
159
+ files: resp?.data?.files,
160
+ origineFileName: resp?.data?.origineFileName,
161
+ error: resp?.data?.error,
162
+ msg: resp?.data?.msg,
145
163
  };
146
164
  },
147
165
  error(this: any, e: Error): void {
package/types/Editor.d.ts CHANGED
@@ -14,11 +14,7 @@ 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): {
18
- files: any[];
19
- error: string;
20
- msg: string;
21
- };
17
+ process(resp: any): any;
22
18
  error(this: any, e: Error): void;
23
19
  defaultHandlerError(this: any, e: any): void;
24
20
  };