@mbs-dev/react-editor 1.5.0 → 1.6.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
@@ -94,6 +94,7 @@ var uploaderConfig = function (apiUrl, imageUrl) { return ({
94
94
  var fn = this.jodit;
95
95
  if (((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.files) && e.data.files.length) {
96
96
  e.data.files.forEach(function (filename) {
97
+ var _a, _b, _c;
97
98
  var src = imageUrl ? "".concat(imageUrl, "/").concat(filename) : filename;
98
99
  if (isImageByExtension(filename, _this.imagesExtensions || ['jpg', 'png', 'jpeg', 'gif', 'webp'])) {
99
100
  var tagName = 'img';
@@ -102,6 +103,15 @@ var uploaderConfig = function (apiUrl, imageUrl) { return ({
102
103
  fn.s.insertImage(elm, null, fn.o.imageDefaultWidth);
103
104
  }
104
105
  else {
106
+ if ((_a = fn === null || fn === void 0 ? void 0 : fn.s) === null || _a === void 0 ? void 0 : _a.focus)
107
+ fn.s.focus();
108
+ if ((_b = fn === null || fn === void 0 ? void 0 : fn.s) === null || _b === void 0 ? void 0 : _b.restore) {
109
+ try {
110
+ fn.s.restore();
111
+ }
112
+ catch (_d) {
113
+ }
114
+ }
105
115
  var tagName = 'a';
106
116
  var elm = fn.createInside.element(tagName);
107
117
  elm.setAttribute('href', src);
@@ -109,6 +119,13 @@ var uploaderConfig = function (apiUrl, imageUrl) { return ({
109
119
  elm.setAttribute('rel', 'noopener noreferrer');
110
120
  elm.textContent = getDisplayNameFromPath(filename);
111
121
  fn.s.insertNode(elm);
122
+ if ((_c = fn === null || fn === void 0 ? void 0 : fn.s) === null || _c === void 0 ? void 0 : _c.setCursorAfter) {
123
+ try {
124
+ fn.s.setCursorAfter(elm);
125
+ }
126
+ catch (_e) {
127
+ }
128
+ }
112
129
  }
113
130
  });
114
131
  }
@@ -116,9 +133,7 @@ var uploaderConfig = function (apiUrl, imageUrl) { return ({
116
133
  },
117
134
  getMessage: function (e) {
118
135
  var _a;
119
- return ((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.messages) && Array.isArray(e.data.messages)
120
- ? e.data.messages.join('')
121
- : '';
136
+ 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('') : '';
122
137
  },
123
138
  process: function (resp) {
124
139
  var files = [];
@@ -195,9 +210,7 @@ var config = function (_a) {
195
210
  var container = document.createElement('div');
196
211
  container.innerHTML = html || '';
197
212
  var imgs = Array.from(container.getElementsByTagName('img'));
198
- return new Set(imgs
199
- .map(function (img) { return img.getAttribute('src') || ''; })
200
- .filter(function (src) { return !!src; }));
213
+ return new Set(imgs.map(function (img) { return img.getAttribute('src') || ''; }).filter(function (src) { return !!src; }));
201
214
  };
202
215
  var prevValue = editor.value || '';
203
216
  var prevSrcs = extractImageSrcs(prevValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbs-dev/react-editor",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "react editor",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/src/Editor.tsx CHANGED
@@ -19,8 +19,6 @@ const isImageByExtension = (filename: string, imageExts: string[]): boolean => {
19
19
  return !!ext && imageExts.includes(ext);
20
20
  };
21
21
 
22
- // ✅ UPDATED: for files, display name without extension and without last "-..."
23
- // Example: recu-202600004-2-69956651a3b98099024323.pdf -> recu-202600004-2
24
22
  const getDisplayNameFromPath = (filename: string): string => {
25
23
  const clean = (filename || '').split('?')[0]?.split('#')[0] ?? '';
26
24
  const last = clean.split('/').pop();
@@ -43,10 +41,7 @@ const getDisplayNameFromPath = (filename: string): string => {
43
41
  * Uploader configuration for Jodit
44
42
  * Handles image upload + insertion in the editor
45
43
  */
46
- export const uploaderConfig = (
47
- apiUrl?: string,
48
- imageUrl?: string
49
- ) => ({
44
+ export const uploaderConfig = (apiUrl?: string, imageUrl?: string) => ({
50
45
  imagesExtensions: ['jpg', 'png', 'jpeg', 'gif', 'webp'],
51
46
  filesVariableName(t: number): string {
52
47
  return 'files[' + t + ']';
@@ -72,13 +67,32 @@ export const uploaderConfig = (
72
67
  elm.setAttribute('src', src);
73
68
  fn.s.insertImage(elm as HTMLImageElement, null, fn.o.imageDefaultWidth);
74
69
  } else {
70
+ // ✅ FIX: restore caret/selection before inserting file link
71
+ if (fn?.s?.focus) fn.s.focus();
72
+ if (fn?.s?.restore) {
73
+ try {
74
+ fn.s.restore();
75
+ } catch {
76
+ // ignore
77
+ }
78
+ }
79
+
75
80
  const tagName = 'a';
76
81
  const elm = fn.createInside.element(tagName);
77
82
  elm.setAttribute('href', src);
78
83
  elm.setAttribute('target', '_blank');
79
84
  elm.setAttribute('rel', 'noopener noreferrer');
80
85
  elm.textContent = getDisplayNameFromPath(filename);
86
+
81
87
  fn.s.insertNode(elm);
88
+
89
+ if (fn?.s?.setCursorAfter) {
90
+ try {
91
+ fn.s.setCursorAfter(elm);
92
+ } catch {
93
+ // ignore
94
+ }
95
+ }
82
96
  }
83
97
  });
84
98
  }
@@ -86,9 +100,7 @@ export const uploaderConfig = (
86
100
  return !!e?.success;
87
101
  },
88
102
  getMessage(e: any): string {
89
- return e?.data?.messages && Array.isArray(e.data.messages)
90
- ? e.data.messages.join('')
91
- : '';
103
+ return e?.data?.messages && Array.isArray(e.data.messages) ? e.data.messages.join('') : '';
92
104
  },
93
105
  process(resp: any): { files: any[]; error: string; msg: string } {
94
106
  const files: any[] = [];
@@ -122,12 +134,7 @@ type ConfigParams = {
122
134
  /**
123
135
  * Build Jodit config for ReactEditor
124
136
  */
125
- export const config = ({
126
- includeUploader,
127
- apiUrl,
128
- imageUrl,
129
- onDeleteImage,
130
- }: ConfigParams = {}) => {
137
+ export const config = ({ includeUploader, apiUrl, imageUrl, onDeleteImage }: ConfigParams = {}) => {
131
138
  const base: any = {
132
139
  readonly: false,
133
140
  placeholder: 'Start typing...',
@@ -193,11 +200,7 @@ export const config = ({
193
200
  container.innerHTML = html || '';
194
201
  const imgs = Array.from(container.getElementsByTagName('img')) as HTMLImageElement[];
195
202
 
196
- return new Set(
197
- imgs
198
- .map((img) => img.getAttribute('src') || '')
199
- .filter((src) => !!src)
200
- );
203
+ return new Set(imgs.map((img) => img.getAttribute('src') || '').filter((src) => !!src));
201
204
  };
202
205
 
203
206
  let prevValue: string = editor.value || '';
package/types/Editor.d.ts CHANGED
@@ -25,5 +25,5 @@ type ConfigParams = {
25
25
  imageUrl?: string;
26
26
  onDeleteImage?: (imageUrl: string) => void | Promise<void>;
27
27
  };
28
- export declare const config: ({ includeUploader, apiUrl, imageUrl, onDeleteImage, }?: ConfigParams) => any;
28
+ export declare const config: ({ includeUploader, apiUrl, imageUrl, onDeleteImage }?: ConfigParams) => any;
29
29
  export default ReactEditor;