@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 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
- 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 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
- var src = imageUrl ? "".concat(imageUrl, "/").concat(filename) : filename;
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(filename, _this.imagesExtensions || ['jpg', 'png', 'jpeg', 'gif', 'webp'])) {
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(filename);
164
+ elm.textContent = origineFileName || getDisplayNameFromPath(file);
146
165
  fn.s.insertNode(elm);
147
- if ((_a = fn === null || fn === void 0 ? void 0 : fn.s) === null || _a === void 0 ? void 0 : _a.setCursorAfter) {
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 (_b) {
170
+ catch (_c) {
152
171
  }
153
172
  }
154
173
  refreshSavedRange();
155
174
  }
156
175
  });
157
176
  }
158
- return !!(e === null || e === void 0 ? void 0 : e.success);
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
- 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('') : '';
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 files = [];
166
- files.unshift(resp === null || resp === void 0 ? void 0 : resp.data);
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: 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,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbs-dev/react-editor",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "react editor",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/src/Editor.tsx CHANGED
@@ -92,15 +92,35 @@ 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) => {
97
- const src = imageUrl ? `${imageUrl}/${filename}` : filename;
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(filename, this.imagesExtensions || ['jpg', 'png', 'jpeg', 'gif', 'webp'])) {
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
- elm.textContent = getDisplayNameFromPath(filename);
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
- return !!e?.success;
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
- return e?.data?.messages && Array.isArray(e.data.messages) ? e.data.messages.join('') : '';
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 files: any[] = [];
139
- files.unshift(resp?.data);
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: resp?.data,
143
- error: resp?.msg,
144
- msg: resp?.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 {