react-lite-rich-text-editor 1.1.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/README.md +69 -0
- package/dist/index.cjs.js +2016 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.esm.js +2014 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,2016 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function _arrayLikeToArray(r, a) {
|
|
6
|
+
(null == a || a > r.length) && (a = r.length);
|
|
7
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
8
|
+
return n;
|
|
9
|
+
}
|
|
10
|
+
function _arrayWithHoles(r) {
|
|
11
|
+
if (Array.isArray(r)) return r;
|
|
12
|
+
}
|
|
13
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
14
|
+
try {
|
|
15
|
+
var i = n[a](c),
|
|
16
|
+
u = i.value;
|
|
17
|
+
} catch (n) {
|
|
18
|
+
return void e(n);
|
|
19
|
+
}
|
|
20
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
21
|
+
}
|
|
22
|
+
function _asyncToGenerator(n) {
|
|
23
|
+
return function () {
|
|
24
|
+
var t = this,
|
|
25
|
+
e = arguments;
|
|
26
|
+
return new Promise(function (r, o) {
|
|
27
|
+
var a = n.apply(t, e);
|
|
28
|
+
function _next(n) {
|
|
29
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
30
|
+
}
|
|
31
|
+
function _throw(n) {
|
|
32
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
33
|
+
}
|
|
34
|
+
_next(void 0);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _createForOfIteratorHelper(r, e) {
|
|
39
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
40
|
+
if (!t) {
|
|
41
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
42
|
+
t && (r = t);
|
|
43
|
+
var n = 0,
|
|
44
|
+
F = function () {};
|
|
45
|
+
return {
|
|
46
|
+
s: F,
|
|
47
|
+
n: function () {
|
|
48
|
+
return n >= r.length ? {
|
|
49
|
+
done: true
|
|
50
|
+
} : {
|
|
51
|
+
done: false,
|
|
52
|
+
value: r[n++]
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
e: function (r) {
|
|
56
|
+
throw r;
|
|
57
|
+
},
|
|
58
|
+
f: F
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
62
|
+
}
|
|
63
|
+
var o,
|
|
64
|
+
a = true,
|
|
65
|
+
u = false;
|
|
66
|
+
return {
|
|
67
|
+
s: function () {
|
|
68
|
+
t = t.call(r);
|
|
69
|
+
},
|
|
70
|
+
n: function () {
|
|
71
|
+
var r = t.next();
|
|
72
|
+
return a = r.done, r;
|
|
73
|
+
},
|
|
74
|
+
e: function (r) {
|
|
75
|
+
u = true, o = r;
|
|
76
|
+
},
|
|
77
|
+
f: function () {
|
|
78
|
+
try {
|
|
79
|
+
a || null == t.return || t.return();
|
|
80
|
+
} finally {
|
|
81
|
+
if (u) throw o;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function _defineProperty(e, r, t) {
|
|
87
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
88
|
+
value: t,
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true
|
|
92
|
+
}) : e[r] = t, e;
|
|
93
|
+
}
|
|
94
|
+
function _iterableToArrayLimit(r, l) {
|
|
95
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
96
|
+
if (null != t) {
|
|
97
|
+
var e,
|
|
98
|
+
n,
|
|
99
|
+
i,
|
|
100
|
+
u,
|
|
101
|
+
a = [],
|
|
102
|
+
f = true,
|
|
103
|
+
o = false;
|
|
104
|
+
try {
|
|
105
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
106
|
+
} catch (r) {
|
|
107
|
+
o = true, n = r;
|
|
108
|
+
} finally {
|
|
109
|
+
try {
|
|
110
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
111
|
+
} finally {
|
|
112
|
+
if (o) throw n;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return a;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function _nonIterableRest() {
|
|
119
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
120
|
+
}
|
|
121
|
+
function ownKeys(e, r) {
|
|
122
|
+
var t = Object.keys(e);
|
|
123
|
+
if (Object.getOwnPropertySymbols) {
|
|
124
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
125
|
+
r && (o = o.filter(function (r) {
|
|
126
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
127
|
+
})), t.push.apply(t, o);
|
|
128
|
+
}
|
|
129
|
+
return t;
|
|
130
|
+
}
|
|
131
|
+
function _objectSpread2(e) {
|
|
132
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
133
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
134
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
135
|
+
_defineProperty(e, r, t[r]);
|
|
136
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
137
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return e;
|
|
141
|
+
}
|
|
142
|
+
function _regenerator() {
|
|
143
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
144
|
+
var e,
|
|
145
|
+
t,
|
|
146
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
147
|
+
n = r.iterator || "@@iterator",
|
|
148
|
+
o = r.toStringTag || "@@toStringTag";
|
|
149
|
+
function i(r, n, o, i) {
|
|
150
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
151
|
+
u = Object.create(c.prototype);
|
|
152
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
153
|
+
var i,
|
|
154
|
+
c,
|
|
155
|
+
u,
|
|
156
|
+
f = 0,
|
|
157
|
+
p = o || [],
|
|
158
|
+
y = false,
|
|
159
|
+
G = {
|
|
160
|
+
p: 0,
|
|
161
|
+
n: 0,
|
|
162
|
+
v: e,
|
|
163
|
+
a: d,
|
|
164
|
+
f: d.bind(e, 4),
|
|
165
|
+
d: function (t, r) {
|
|
166
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
function d(r, n) {
|
|
170
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
171
|
+
var o,
|
|
172
|
+
i = p[t],
|
|
173
|
+
d = G.p,
|
|
174
|
+
l = i[2];
|
|
175
|
+
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
176
|
+
}
|
|
177
|
+
if (o || r > 1) return a;
|
|
178
|
+
throw y = true, n;
|
|
179
|
+
}
|
|
180
|
+
return function (o, p, l) {
|
|
181
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
182
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
183
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
184
|
+
try {
|
|
185
|
+
if (f = 2, i) {
|
|
186
|
+
if (c || (o = "next"), t = i[o]) {
|
|
187
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
188
|
+
if (!t.done) return t;
|
|
189
|
+
u = t.value, c < 2 && (c = 0);
|
|
190
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
191
|
+
i = e;
|
|
192
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
193
|
+
} catch (t) {
|
|
194
|
+
i = e, c = 1, u = t;
|
|
195
|
+
} finally {
|
|
196
|
+
f = 1;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
value: t,
|
|
201
|
+
done: y
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
}(r, o, i), true), u;
|
|
205
|
+
}
|
|
206
|
+
var a = {};
|
|
207
|
+
function Generator() {}
|
|
208
|
+
function GeneratorFunction() {}
|
|
209
|
+
function GeneratorFunctionPrototype() {}
|
|
210
|
+
t = Object.getPrototypeOf;
|
|
211
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
212
|
+
return this;
|
|
213
|
+
}), t),
|
|
214
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
215
|
+
function f(e) {
|
|
216
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
217
|
+
}
|
|
218
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
219
|
+
return this;
|
|
220
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
221
|
+
return "[object Generator]";
|
|
222
|
+
}), (_regenerator = function () {
|
|
223
|
+
return {
|
|
224
|
+
w: i,
|
|
225
|
+
m: f
|
|
226
|
+
};
|
|
227
|
+
})();
|
|
228
|
+
}
|
|
229
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
230
|
+
var i = Object.defineProperty;
|
|
231
|
+
try {
|
|
232
|
+
i({}, "", {});
|
|
233
|
+
} catch (e) {
|
|
234
|
+
i = 0;
|
|
235
|
+
}
|
|
236
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
237
|
+
function o(r, n) {
|
|
238
|
+
_regeneratorDefine(e, r, function (e) {
|
|
239
|
+
return this._invoke(r, n, e);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
r ? i ? i(e, r, {
|
|
243
|
+
value: n,
|
|
244
|
+
enumerable: !t,
|
|
245
|
+
configurable: !t,
|
|
246
|
+
writable: !t
|
|
247
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
248
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
249
|
+
}
|
|
250
|
+
function _regeneratorValues(e) {
|
|
251
|
+
if (null != e) {
|
|
252
|
+
var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"],
|
|
253
|
+
r = 0;
|
|
254
|
+
if (t) return t.call(e);
|
|
255
|
+
if ("function" == typeof e.next) return e;
|
|
256
|
+
if (!isNaN(e.length)) return {
|
|
257
|
+
next: function () {
|
|
258
|
+
return e && r >= e.length && (e = void 0), {
|
|
259
|
+
value: e && e[r++],
|
|
260
|
+
done: !e
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
266
|
+
}
|
|
267
|
+
function _slicedToArray(r, e) {
|
|
268
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
269
|
+
}
|
|
270
|
+
function _toPrimitive(t, r) {
|
|
271
|
+
if ("object" != typeof t || !t) return t;
|
|
272
|
+
var e = t[Symbol.toPrimitive];
|
|
273
|
+
if (void 0 !== e) {
|
|
274
|
+
var i = e.call(t, r);
|
|
275
|
+
if ("object" != typeof i) return i;
|
|
276
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
277
|
+
}
|
|
278
|
+
return ("string" === r ? String : Number)(t);
|
|
279
|
+
}
|
|
280
|
+
function _toPropertyKey(t) {
|
|
281
|
+
var i = _toPrimitive(t, "string");
|
|
282
|
+
return "symbol" == typeof i ? i : i + "";
|
|
283
|
+
}
|
|
284
|
+
function _typeof(o) {
|
|
285
|
+
"@babel/helpers - typeof";
|
|
286
|
+
|
|
287
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
288
|
+
return typeof o;
|
|
289
|
+
} : function (o) {
|
|
290
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
291
|
+
}, _typeof(o);
|
|
292
|
+
}
|
|
293
|
+
function _unsupportedIterableToArray(r, a) {
|
|
294
|
+
if (r) {
|
|
295
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
296
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
297
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
var FaImage = function FaImage(_ref) {
|
|
302
|
+
var className = _ref.className,
|
|
303
|
+
size = _ref.size,
|
|
304
|
+
color = _ref.color,
|
|
305
|
+
style = _ref.style;
|
|
306
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
307
|
+
className: className,
|
|
308
|
+
style: _objectSpread2({
|
|
309
|
+
display: 'inline-flex',
|
|
310
|
+
alignItems: 'center',
|
|
311
|
+
justifyContent: 'center',
|
|
312
|
+
fontSize: size || '1em',
|
|
313
|
+
color: color || 'inherit'
|
|
314
|
+
}, style),
|
|
315
|
+
dangerouslySetInnerHTML: {
|
|
316
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 512 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z\"></path></svg>"
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
var FaBold = function FaBold(_ref3) {
|
|
321
|
+
var className = _ref3.className,
|
|
322
|
+
size = _ref3.size,
|
|
323
|
+
color = _ref3.color,
|
|
324
|
+
style = _ref3.style;
|
|
325
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
326
|
+
className: className,
|
|
327
|
+
style: _objectSpread2({
|
|
328
|
+
display: 'inline-flex',
|
|
329
|
+
alignItems: 'center',
|
|
330
|
+
justifyContent: 'center',
|
|
331
|
+
fontSize: size || '1em',
|
|
332
|
+
color: color || 'inherit'
|
|
333
|
+
}, style),
|
|
334
|
+
dangerouslySetInnerHTML: {
|
|
335
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 384 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M333.49 238a122 122 0 0 0 27-65.21C367.87 96.49 308 32 233.42 32H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h31.87v288H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h209.32c70.8 0 134.14-51.75 141-122.4 4.74-48.45-16.39-92.06-50.83-119.6zM145.66 112h87.76a48 48 0 0 1 0 96h-87.76zm87.76 288h-87.76V288h87.76a56 56 0 0 1 0 112z\"></path></svg>"
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
var FaItalic = function FaItalic(_ref4) {
|
|
340
|
+
var className = _ref4.className,
|
|
341
|
+
size = _ref4.size,
|
|
342
|
+
color = _ref4.color,
|
|
343
|
+
style = _ref4.style;
|
|
344
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
345
|
+
className: className,
|
|
346
|
+
style: _objectSpread2({
|
|
347
|
+
display: 'inline-flex',
|
|
348
|
+
alignItems: 'center',
|
|
349
|
+
justifyContent: 'center',
|
|
350
|
+
fontSize: size || '1em',
|
|
351
|
+
color: color || 'inherit'
|
|
352
|
+
}, style),
|
|
353
|
+
dangerouslySetInnerHTML: {
|
|
354
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 320 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M320 48v32a16 16 0 0 1-16 16h-62.76l-80 320H208a16 16 0 0 1 16 16v32a16 16 0 0 1-16 16H16a16 16 0 0 1-16-16v-32a16 16 0 0 1 16-16h62.76l80-320H112a16 16 0 0 1-16-16V48a16 16 0 0 1 16-16h192a16 16 0 0 1 16 16z\"></path></svg>"
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
var FaUnderline = function FaUnderline(_ref5) {
|
|
359
|
+
var className = _ref5.className,
|
|
360
|
+
size = _ref5.size,
|
|
361
|
+
color = _ref5.color,
|
|
362
|
+
style = _ref5.style;
|
|
363
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
364
|
+
className: className,
|
|
365
|
+
style: _objectSpread2({
|
|
366
|
+
display: 'inline-flex',
|
|
367
|
+
alignItems: 'center',
|
|
368
|
+
justifyContent: 'center',
|
|
369
|
+
fontSize: size || '1em',
|
|
370
|
+
color: color || 'inherit'
|
|
371
|
+
}, style),
|
|
372
|
+
dangerouslySetInnerHTML: {
|
|
373
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 448 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M32 64h32v160c0 88.22 71.78 160 160 160s160-71.78 160-160V64h32a16 16 0 0 0 16-16V16a16 16 0 0 0-16-16H272a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h32v160a80 80 0 0 1-160 0V64h32a16 16 0 0 0 16-16V16a16 16 0 0 0-16-16H32a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16zm400 384H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16z\"></path></svg>"
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
var FaTextHeight = function FaTextHeight(_ref6) {
|
|
378
|
+
var className = _ref6.className,
|
|
379
|
+
size = _ref6.size,
|
|
380
|
+
color = _ref6.color,
|
|
381
|
+
style = _ref6.style;
|
|
382
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
383
|
+
className: className,
|
|
384
|
+
style: _objectSpread2({
|
|
385
|
+
display: 'inline-flex',
|
|
386
|
+
alignItems: 'center',
|
|
387
|
+
justifyContent: 'center',
|
|
388
|
+
fontSize: size || '1em',
|
|
389
|
+
color: color || 'inherit'
|
|
390
|
+
}, style),
|
|
391
|
+
dangerouslySetInnerHTML: {
|
|
392
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 576 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M304 32H16A16 16 0 0 0 0 48v96a16 16 0 0 0 16 16h32a16 16 0 0 0 16-16v-32h56v304H80a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h160a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16h-40V112h56v32a16 16 0 0 0 16 16h32a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16zm256 336h-48V144h48c14.31 0 21.33-17.31 11.31-27.31l-80-80a16 16 0 0 0-22.62 0l-80 80C379.36 126 384.36 144 400 144h48v224h-48c-14.31 0-21.32 17.31-11.31 27.31l80 80a16 16 0 0 0 22.62 0l80-80C580.64 386 575.64 368 560 368z\"></path></svg>"
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
var FaAlignCenter = function FaAlignCenter(_ref7) {
|
|
397
|
+
var className = _ref7.className,
|
|
398
|
+
size = _ref7.size,
|
|
399
|
+
color = _ref7.color,
|
|
400
|
+
style = _ref7.style;
|
|
401
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
402
|
+
className: className,
|
|
403
|
+
style: _objectSpread2({
|
|
404
|
+
display: 'inline-flex',
|
|
405
|
+
alignItems: 'center',
|
|
406
|
+
justifyContent: 'center',
|
|
407
|
+
fontSize: size || '1em',
|
|
408
|
+
color: color || 'inherit'
|
|
409
|
+
}, style),
|
|
410
|
+
dangerouslySetInnerHTML: {
|
|
411
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 448 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M432 160H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0 256H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zM108.1 96h231.81A12.09 12.09 0 0 0 352 83.9V44.09A12.09 12.09 0 0 0 339.91 32H108.1A12.09 12.09 0 0 0 96 44.09V83.9A12.1 12.1 0 0 0 108.1 96zm231.81 256A12.09 12.09 0 0 0 352 339.9v-39.81A12.09 12.09 0 0 0 339.91 288H108.1A12.09 12.09 0 0 0 96 300.09v39.81a12.1 12.1 0 0 0 12.1 12.1z\"></path></svg>"
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
var FaAlignRight = function FaAlignRight(_ref8) {
|
|
416
|
+
var className = _ref8.className,
|
|
417
|
+
size = _ref8.size,
|
|
418
|
+
color = _ref8.color,
|
|
419
|
+
style = _ref8.style;
|
|
420
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
421
|
+
className: className,
|
|
422
|
+
style: _objectSpread2({
|
|
423
|
+
display: 'inline-flex',
|
|
424
|
+
alignItems: 'center',
|
|
425
|
+
justifyContent: 'center',
|
|
426
|
+
fontSize: size || '1em',
|
|
427
|
+
color: color || 'inherit'
|
|
428
|
+
}, style),
|
|
429
|
+
dangerouslySetInnerHTML: {
|
|
430
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 448 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M16 224h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16zm416 192H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm3.17-384H172.83A12.82 12.82 0 0 0 160 44.83v38.34A12.82 12.82 0 0 0 172.83 96h262.34A12.82 12.82 0 0 0 448 83.17V44.83A12.82 12.82 0 0 0 435.17 32zm0 256H172.83A12.82 12.82 0 0 0 160 300.83v38.34A12.82 12.82 0 0 0 172.83 352h262.34A12.82 12.82 0 0 0 448 339.17v-38.34A12.82 12.82 0 0 0 435.17 288z\"></path></svg>"
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
var FaAlignLeft = function FaAlignLeft(_ref0) {
|
|
435
|
+
var className = _ref0.className,
|
|
436
|
+
size = _ref0.size,
|
|
437
|
+
color = _ref0.color,
|
|
438
|
+
style = _ref0.style;
|
|
439
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
440
|
+
className: className,
|
|
441
|
+
style: _objectSpread2({
|
|
442
|
+
display: 'inline-flex',
|
|
443
|
+
alignItems: 'center',
|
|
444
|
+
justifyContent: 'center',
|
|
445
|
+
fontSize: size || '1em',
|
|
446
|
+
color: color || 'inherit'
|
|
447
|
+
}, style),
|
|
448
|
+
dangerouslySetInnerHTML: {
|
|
449
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 448 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12.83 352h262.34A12.82 12.82 0 0 0 288 339.17v-38.34A12.82 12.82 0 0 0 275.17 288H12.83A12.82 12.82 0 0 0 0 300.83v38.34A12.82 12.82 0 0 0 12.83 352zm0-256h262.34A12.82 12.82 0 0 0 288 83.17V44.83A12.82 12.82 0 0 0 275.17 32H12.83A12.82 12.82 0 0 0 0 44.83v38.34A12.82 12.82 0 0 0 12.83 96zM432 160H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0 256H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16z\"></path></svg>"
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
var FaListOl = function FaListOl(_ref1) {
|
|
454
|
+
var className = _ref1.className,
|
|
455
|
+
size = _ref1.size,
|
|
456
|
+
color = _ref1.color,
|
|
457
|
+
style = _ref1.style;
|
|
458
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
459
|
+
className: className,
|
|
460
|
+
style: _objectSpread2({
|
|
461
|
+
display: 'inline-flex',
|
|
462
|
+
alignItems: 'center',
|
|
463
|
+
justifyContent: 'center',
|
|
464
|
+
fontSize: size || '1em',
|
|
465
|
+
color: color || 'inherit'
|
|
466
|
+
}, style),
|
|
467
|
+
dangerouslySetInnerHTML: {
|
|
468
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 512 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M61.77 401l17.5-20.15a19.92 19.92 0 0 0 5.07-14.19v-3.31C84.34 356 80.5 352 73 352H16a8 8 0 0 0-8 8v16a8 8 0 0 0 8 8h22.83a157.41 157.41 0 0 0-11 12.31l-5.61 7c-4 5.07-5.25 10.13-2.8 14.88l1.05 1.93c3 5.76 6.29 7.88 12.25 7.88h4.73c10.33 0 15.94 2.44 15.94 9.09 0 4.72-4.2 8.22-14.36 8.22a41.54 41.54 0 0 1-15.47-3.12c-6.49-3.88-11.74-3.5-15.6 3.12l-5.59 9.31c-3.72 6.13-3.19 11.72 2.63 15.94 7.71 4.69 20.38 9.44 37 9.44 34.16 0 48.5-22.75 48.5-44.12-.03-14.38-9.12-29.76-28.73-34.88zM496 224H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0-160H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16V80a16 16 0 0 0-16-16zm0 320H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zM16 160h64a8 8 0 0 0 8-8v-16a8 8 0 0 0-8-8H64V40a8 8 0 0 0-8-8H32a8 8 0 0 0-7.14 4.42l-8 16A8 8 0 0 0 24 64h8v64H16a8 8 0 0 0-8 8v16a8 8 0 0 0 8 8zm-3.91 160H80a8 8 0 0 0 8-8v-16a8 8 0 0 0-8-8H41.32c3.29-10.29 48.34-18.68 48.34-56.44 0-29.06-25-39.56-44.47-39.56-21.36 0-33.8 10-40.46 18.75-4.37 5.59-3 10.84 2.8 15.37l8.58 6.88c5.61 4.56 11 2.47 16.12-2.44a13.44 13.44 0 0 1 9.46-3.84c3.33 0 9.28 1.56 9.28 8.75C51 248.19 0 257.31 0 304.59v4C0 316 5.08 320 12.09 320z\"></path></svg>"
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
var FaListUl = function FaListUl(_ref10) {
|
|
473
|
+
var className = _ref10.className,
|
|
474
|
+
size = _ref10.size,
|
|
475
|
+
color = _ref10.color,
|
|
476
|
+
style = _ref10.style;
|
|
477
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
478
|
+
className: className,
|
|
479
|
+
style: _objectSpread2({
|
|
480
|
+
display: 'inline-flex',
|
|
481
|
+
alignItems: 'center',
|
|
482
|
+
justifyContent: 'center',
|
|
483
|
+
fontSize: size || '1em',
|
|
484
|
+
color: color || 'inherit'
|
|
485
|
+
}, style),
|
|
486
|
+
dangerouslySetInnerHTML: {
|
|
487
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 512 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M48 48a48 48 0 1 0 48 48 48 48 0 0 0-48-48zm0 160a48 48 0 1 0 48 48 48 48 0 0 0-48-48zm0 160a48 48 0 1 0 48 48 48 48 0 0 0-48-48zm448 16H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0-320H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16V80a16 16 0 0 0-16-16zm0 160H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16z\"></path></svg>"
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
var FaFont = function FaFont(_ref12) {
|
|
492
|
+
var className = _ref12.className,
|
|
493
|
+
size = _ref12.size,
|
|
494
|
+
color = _ref12.color,
|
|
495
|
+
style = _ref12.style;
|
|
496
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
497
|
+
className: className,
|
|
498
|
+
style: _objectSpread2({
|
|
499
|
+
display: 'inline-flex',
|
|
500
|
+
alignItems: 'center',
|
|
501
|
+
justifyContent: 'center',
|
|
502
|
+
fontSize: size || '1em',
|
|
503
|
+
color: color || 'inherit'
|
|
504
|
+
}, style),
|
|
505
|
+
dangerouslySetInnerHTML: {
|
|
506
|
+
__html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 448 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M432 416h-23.41L277.88 53.69A32 32 0 0 0 247.58 32h-47.16a32 32 0 0 0-30.3 21.69L39.41 416H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h128a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16h-19.58l23.3-64h152.56l23.3 64H304a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h128a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zM176.85 272L224 142.51 271.15 272z\"></path></svg>"
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// DraftJS helper stubs
|
|
512
|
+
// Since we are removing specific DraftJS dependencies for this package,
|
|
513
|
+
// these serve as placeholders or basic HTML verifiers.
|
|
514
|
+
|
|
515
|
+
var isValidDraftFormat = function isValidDraftFormat(content) {
|
|
516
|
+
if (_typeof(content) !== "object" || content === null) return false;
|
|
517
|
+
return !!(content.blocks && content.entityMap);
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// A very basic fallback. Ideally, the user should pass HTML strings.
|
|
521
|
+
// Dealing with full DraftJS->HTML conversion without the library is complex.
|
|
522
|
+
// We assume for this package that if the legacy DraftJS format is passed,
|
|
523
|
+
// the user might need to handle it or we expect HTML primarily.
|
|
524
|
+
var draftBlocksToHTML = function draftBlocksToHTML(content) {
|
|
525
|
+
console.warn("draftBlocksToHTML: DraftJS object detected but full conversion is simplified in this package.");
|
|
526
|
+
// Return empty or try to extract text as a fallback
|
|
527
|
+
if (content && content.blocks) {
|
|
528
|
+
return content.blocks.map(function (b) {
|
|
529
|
+
return "<p>".concat(b.text, "</p>");
|
|
530
|
+
}).join("");
|
|
531
|
+
}
|
|
532
|
+
return "";
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
var Spinner = function Spinner() {
|
|
536
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
537
|
+
className: "rte-spinner-container"
|
|
538
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
539
|
+
className: "rte-spinner"
|
|
540
|
+
}));
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
var LabelComponent = function LabelComponent(_ref) {
|
|
544
|
+
var children = _ref.children;
|
|
545
|
+
if (!children) return null;
|
|
546
|
+
return /*#__PURE__*/React.createElement("label", {
|
|
547
|
+
className: "rte-label",
|
|
548
|
+
style: {
|
|
549
|
+
marginBottom: '4px',
|
|
550
|
+
display: 'block'
|
|
551
|
+
}
|
|
552
|
+
}, children);
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
function styleInject(css, ref) {
|
|
556
|
+
if ( ref === void 0 ) ref = {};
|
|
557
|
+
var insertAt = ref.insertAt;
|
|
558
|
+
|
|
559
|
+
if (typeof document === 'undefined') { return; }
|
|
560
|
+
|
|
561
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
562
|
+
var style = document.createElement('style');
|
|
563
|
+
style.type = 'text/css';
|
|
564
|
+
|
|
565
|
+
if (insertAt === 'top') {
|
|
566
|
+
if (head.firstChild) {
|
|
567
|
+
head.insertBefore(style, head.firstChild);
|
|
568
|
+
} else {
|
|
569
|
+
head.appendChild(style);
|
|
570
|
+
}
|
|
571
|
+
} else {
|
|
572
|
+
head.appendChild(style);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (style.styleSheet) {
|
|
576
|
+
style.styleSheet.cssText = css;
|
|
577
|
+
} else {
|
|
578
|
+
style.appendChild(document.createTextNode(css));
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
var css_248z = ".rte-container{background-color:#fff;border:1px solid #e5e7eb;border-radius:12px;box-shadow:0 1px 3px rgba(0,0,0,.05);overflow:hidden;transition:all .2s cubic-bezier(.4,0,.2,1)}.rte-container:focus-within{border-color:#3b82f6;box-shadow:0 0 0 3px rgba(59,130,246,.1)}.rte-toolbar{align-items:center;background-color:#f9fafb;border-bottom:1px solid #f3f4f6;display:flex;flex-wrap:wrap;gap:4px;padding:8px}.rte-toolbar-button{align-items:center;background:transparent;border:none;border-radius:6px;color:#4b5563;cursor:pointer;display:flex;height:32px;justify-content:center;padding:0;transition:all .15s ease;width:32px}.rte-toolbar-button:hover{background-color:#f3f4f6;color:#111827}.rte-toolbar-button.active{background-color:#eff6ff;color:#2563eb}.rte-toolbar-button:disabled{cursor:not-allowed;opacity:.5}.rte-toolbar-select{background-color:#fff;border:1px solid #e5e7eb;border-radius:6px;color:#374151;cursor:pointer;font-size:14px;height:32px;outline:none;padding:0 8px;transition:border-color .15s ease}.rte-toolbar-select:hover{border-color:#d1d5db}.rte-toolbar-select:focus{border-color:#3b82f6}.rte-color-picker-label{align-items:center;border-radius:6px;cursor:pointer;display:flex;height:32px;justify-content:center;position:relative;transition:background-color .15s ease;width:32px}.rte-color-picker-label:hover{background-color:#f3f4f6}.rte-color-input{cursor:pointer;height:100%;inset:0;opacity:0;position:absolute;width:100%}.rte-content{color:#1f2937;font-family:inherit;font-size:16px;line-height:1.6;min-height:150px;outline:none;overflow-y:auto;padding:12px;word-break:break-word}.rte-content ul{list-style-type:disc;margin-left:1.5rem}.rte-content ol{list-style-type:decimal;margin-left:1.5rem}.rte-content img{border-radius:8px;height:auto;max-width:100%}.rte-modal-overlay{align-items:center;animation:rte-fade-in .2s ease-out;backdrop-filter:blur(4px);background-color:rgba(0,0,0,.5);display:flex;inset:0;justify-content:center;position:fixed;z-index:9999}.rte-modal{animation:rte-zoom-in .2s ease-out;background-color:#fff;border:1px solid #f3f4f6;border-radius:16px;box-shadow:0 20px 25px -5px rgba(0,0,0,.1),0 10px 10px -5px rgba(0,0,0,.04);display:flex;flex-direction:column;gap:16px;max-width:400px;padding:24px;width:100%}.rte-modal-title{color:#111827;font-size:18px;font-weight:600;margin-bottom:4px}.rte-form-group{display:flex;flex-direction:column;gap:6px}.rte-label{color:#4b5563;font-size:14px;font-weight:500}.rte-input{border:1px solid #d1d5db;border-radius:8px;outline:none;padding:8px 12px;transition:all .15s ease;width:100%}.rte-input:focus{border-color:#3b82f6;box-shadow:0 0 0 3px rgba(59,130,246,.1)}.rte-modal-actions{display:flex;gap:8px;justify-content:flex-end;margin-top:8px}.rte-button{border:none;border-radius:8px;cursor:pointer;font-weight:500;padding:8px 16px;transition:all .15s ease}.rte-button-secondary{background-color:#f3f4f6;color:#4b5563}.rte-button-secondary:hover{background-color:#e5e7eb}.rte-button-primary{background-color:#2563eb;box-shadow:0 1px 2px rgba(0,0,0,.05);color:#fff}.rte-button-primary:hover{background-color:#1d4ed8}.rte-button-primary:disabled{cursor:not-allowed;opacity:.5}.rte-spinner-container{align-items:center;display:flex;justify-content:center;padding:16px}.rte-spinner{animation:rte-spin .8s linear infinite;border:3px solid #eff6ff;border-radius:50%;border-top-color:#3b82f6;height:32px;width:32px}@keyframes rte-spin{to{transform:rotate(1turn)}}@keyframes rte-fade-in{0%{opacity:0}to{opacity:1}}@keyframes rte-zoom-in{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}.image-container{background:#f9fafb;border:1px solid #f3f4f6;border-radius:12px;box-sizing:border-box;margin:15px;max-width:100%;position:relative;transition:all .2s ease}.image-container.image-align-center{display:block;height:300px;margin:24px auto;width:100%}.image-container.image-align-left,.image-container.image-align-right{display:inline-block;height:300px;width:350px}.image-container.image-align-left{float:left;margin-right:24px}.image-container.image-align-right{float:right;margin-left:24px}.image-container img{background:#fff;border-radius:12px;display:block;height:100%;margin:0 auto;object-fit:contain;width:100%}.image-delete-button{align-items:center;background:#ef4444;border:3px solid #fff;border-radius:9999px;box-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -1px rgba(0,0,0,.06);color:#fff;cursor:pointer;display:flex;font-size:18px;font-weight:700;height:26px;justify-content:center;line-height:1;padding:0;position:absolute;right:0;top:0;transform:translate(50%,-50%);transition:all .2s cubic-bezier(.4,0,.2,1);width:26px;z-index:50}.image-delete-button:hover{background:#b91c1c;box-shadow:0 10px 15px -3px rgba(0,0,0,.1);transform:translate(50%,-50%) scale(1.1)}.image-container:after{clear:both;content:\"\";display:table}";
|
|
583
|
+
styleInject(css_248z);
|
|
584
|
+
|
|
585
|
+
// Helper functions for HTML escaping
|
|
586
|
+
var escapeHtml = function escapeHtml(str) {
|
|
587
|
+
if (!str) return "";
|
|
588
|
+
return String(str).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\"/g, """).replace(/'/g, "'");
|
|
589
|
+
};
|
|
590
|
+
var escapeAttr = function escapeAttr(str) {
|
|
591
|
+
return escapeHtml(str).replace(/"/g, """);
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// URL detection regex
|
|
595
|
+
var URL_REGEX = /(https?:\/\/[^\s]+)/g;
|
|
596
|
+
function RichTextEditor(_ref) {
|
|
597
|
+
var onChange = _ref.onChange,
|
|
598
|
+
showEditButton = _ref.showEditButton,
|
|
599
|
+
onBlur = _ref.onBlur,
|
|
600
|
+
_ref$disabled = _ref.disabled,
|
|
601
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
602
|
+
_ref$editable = _ref.editable,
|
|
603
|
+
defaultEditable = _ref$editable === void 0 ? false : _ref$editable,
|
|
604
|
+
value = _ref.value,
|
|
605
|
+
isLoading = _ref.isLoading,
|
|
606
|
+
_ref$isList = _ref.isList,
|
|
607
|
+
isList = _ref$isList === void 0 ? false : _ref$isList,
|
|
608
|
+
label = _ref.label,
|
|
609
|
+
_ref$showBorder = _ref.showBorder,
|
|
610
|
+
showBorder = _ref$showBorder === void 0 ? true : _ref$showBorder,
|
|
611
|
+
paddingLeft = _ref.paddingLeft,
|
|
612
|
+
minHeight = _ref.minHeight,
|
|
613
|
+
maxHeight = _ref.maxHeight,
|
|
614
|
+
onImageUpload = _ref.onImageUpload;
|
|
615
|
+
if (isLoading) {
|
|
616
|
+
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
617
|
+
}
|
|
618
|
+
var editorRef = React.useRef(null);
|
|
619
|
+
var fileInputRef = React.useRef(null);
|
|
620
|
+
var scrollTopRef = React.useRef(0);
|
|
621
|
+
var _useState = React.useState(""),
|
|
622
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
623
|
+
html = _useState2[0],
|
|
624
|
+
setHtml = _useState2[1];
|
|
625
|
+
var _useState3 = React.useState(false),
|
|
626
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
627
|
+
linkModalOpen = _useState4[0],
|
|
628
|
+
setLinkModalOpen = _useState4[1];
|
|
629
|
+
var _useState5 = React.useState(""),
|
|
630
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
631
|
+
linkUrl = _useState6[0],
|
|
632
|
+
setLinkUrl = _useState6[1];
|
|
633
|
+
var _useState7 = React.useState(""),
|
|
634
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
635
|
+
linkText = _useState8[0],
|
|
636
|
+
setLinkText = _useState8[1];
|
|
637
|
+
var selectionRangeRef = React.useRef(null);
|
|
638
|
+
var _useState9 = React.useState(defaultEditable),
|
|
639
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
640
|
+
editable = _useState0[0],
|
|
641
|
+
setEditable = _useState0[1];
|
|
642
|
+
|
|
643
|
+
// NEW: Track current list type for dropdown
|
|
644
|
+
var _useState1 = React.useState(null),
|
|
645
|
+
_useState10 = _slicedToArray(_useState1, 2),
|
|
646
|
+
currentListType = _useState10[0],
|
|
647
|
+
setCurrentListType = _useState10[1];
|
|
648
|
+
|
|
649
|
+
// NEW: Track active styles for toolbar buttons
|
|
650
|
+
var _useState11 = React.useState(false),
|
|
651
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
652
|
+
isBold = _useState12[0],
|
|
653
|
+
setIsBold = _useState12[1];
|
|
654
|
+
var _useState13 = React.useState(false),
|
|
655
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
656
|
+
isItalic = _useState14[0],
|
|
657
|
+
setIsItalic = _useState14[1];
|
|
658
|
+
var _useState15 = React.useState(false),
|
|
659
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
660
|
+
isUnderline = _useState16[0],
|
|
661
|
+
setIsUnderline = _useState16[1];
|
|
662
|
+
|
|
663
|
+
// NEW: Track current font size
|
|
664
|
+
var _useState17 = React.useState("16"),
|
|
665
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
666
|
+
currentFontSize = _useState18[0],
|
|
667
|
+
setCurrentFontSize = _useState18[1];
|
|
668
|
+
|
|
669
|
+
// NEW: Track current line height
|
|
670
|
+
var _useState19 = React.useState(""),
|
|
671
|
+
_useState20 = _slicedToArray(_useState19, 2),
|
|
672
|
+
currentLineHeight = _useState20[0],
|
|
673
|
+
setCurrentLineHeight = _useState20[1];
|
|
674
|
+
var _useState21 = React.useState(null),
|
|
675
|
+
_useState22 = _slicedToArray(_useState21, 2),
|
|
676
|
+
activeAlign = _useState22[0],
|
|
677
|
+
setActiveAlign = _useState22[1];
|
|
678
|
+
var _useState23 = React.useState(false),
|
|
679
|
+
_useState24 = _slicedToArray(_useState23, 2),
|
|
680
|
+
imageModalOpen = _useState24[0],
|
|
681
|
+
setImageModalOpen = _useState24[1];
|
|
682
|
+
var _useState25 = React.useState(""),
|
|
683
|
+
_useState26 = _slicedToArray(_useState25, 2),
|
|
684
|
+
selectedImageUrl = _useState26[0],
|
|
685
|
+
setSelectedImageUrl = _useState26[1];
|
|
686
|
+
var _useState27 = React.useState(1),
|
|
687
|
+
_useState28 = _slicedToArray(_useState27, 2),
|
|
688
|
+
zoomLevel = _useState28[0],
|
|
689
|
+
setZoomLevel = _useState28[1];
|
|
690
|
+
var _useState29 = React.useState(false),
|
|
691
|
+
_useState30 = _slicedToArray(_useState29, 2),
|
|
692
|
+
isUploading = _useState30[0],
|
|
693
|
+
setIsUploading = _useState30[1];
|
|
694
|
+
var openImageModal = function openImageModal(url) {
|
|
695
|
+
if (editorRef.current) {
|
|
696
|
+
scrollTopRef.current = editorRef.current.scrollTop;
|
|
697
|
+
}
|
|
698
|
+
setSelectedImageUrl(url);
|
|
699
|
+
setImageModalOpen(true);
|
|
700
|
+
};
|
|
701
|
+
var closeImageModal = function closeImageModal() {
|
|
702
|
+
setImageModalOpen(false);
|
|
703
|
+
setSelectedImageUrl("");
|
|
704
|
+
setZoomLevel(1);
|
|
705
|
+
};
|
|
706
|
+
var handleZoomIn = function handleZoomIn() {
|
|
707
|
+
setZoomLevel(function (prevZoom) {
|
|
708
|
+
return prevZoom + 0.1;
|
|
709
|
+
});
|
|
710
|
+
};
|
|
711
|
+
var handleZoomOut = function handleZoomOut() {
|
|
712
|
+
setZoomLevel(function (prevZoom) {
|
|
713
|
+
return Math.max(0.1, prevZoom - 0.1);
|
|
714
|
+
});
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// Effect to restore scroll position after modal closes
|
|
718
|
+
React.useEffect(function () {
|
|
719
|
+
if (!imageModalOpen && editorRef.current) {
|
|
720
|
+
editorRef.current.scrollTop = scrollTopRef.current;
|
|
721
|
+
}
|
|
722
|
+
}, [imageModalOpen]);
|
|
723
|
+
React.useEffect(function () {
|
|
724
|
+
if (!imageModalOpen) return;
|
|
725
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
726
|
+
if (e.key === 'Escape') {
|
|
727
|
+
closeImageModal();
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
var handleWheel = function handleWheel(e) {
|
|
731
|
+
if (e.ctrlKey) {
|
|
732
|
+
e.preventDefault();
|
|
733
|
+
if (e.deltaY < 0) {
|
|
734
|
+
handleZoomIn();
|
|
735
|
+
} else {
|
|
736
|
+
handleZoomOut();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
741
|
+
window.addEventListener('wheel', handleWheel, {
|
|
742
|
+
passive: false
|
|
743
|
+
});
|
|
744
|
+
return function () {
|
|
745
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
746
|
+
window.removeEventListener('wheel', handleWheel);
|
|
747
|
+
};
|
|
748
|
+
}, [imageModalOpen]);
|
|
749
|
+
React.useEffect(function () {
|
|
750
|
+
var handleClick = function handleClick(e) {
|
|
751
|
+
var deleteBtn = e.target.closest('button[title="Remove image"]');
|
|
752
|
+
if (deleteBtn && editable) {
|
|
753
|
+
e.preventDefault();
|
|
754
|
+
e.stopPropagation();
|
|
755
|
+
var wrapper = deleteBtn.closest('.image-container');
|
|
756
|
+
if (wrapper && wrapper.parentNode) {
|
|
757
|
+
wrapper.parentNode.removeChild(wrapper);
|
|
758
|
+
triggerChange();
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
var editor = editorRef.current;
|
|
763
|
+
if (editor) {
|
|
764
|
+
editor.addEventListener('click', handleClick);
|
|
765
|
+
return function () {
|
|
766
|
+
editor.removeEventListener('click', handleClick);
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
}, [editable]);
|
|
770
|
+
React.useEffect(function () {
|
|
771
|
+
if (editorRef.current && value) {
|
|
772
|
+
requestAnimationFrame(function () {
|
|
773
|
+
return processExistingImages(editorRef.current);
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
}, [value]);
|
|
777
|
+
|
|
778
|
+
// Runs whenever editable changes (toggles delete icon visibility)
|
|
779
|
+
React.useEffect(function () {
|
|
780
|
+
processExistingImages(editorRef.current);
|
|
781
|
+
}, [html, editable]);
|
|
782
|
+
React.useEffect(function () {
|
|
783
|
+
// Only update if value is a string and different from current html
|
|
784
|
+
if (value) {
|
|
785
|
+
try {
|
|
786
|
+
// Check if value is a Draft.js content state (either stringified or object)
|
|
787
|
+
if (value && isValidDraftFormat(value)) {
|
|
788
|
+
var htmlContent = draftBlocksToHTML(value);
|
|
789
|
+
setHtml(htmlContent);
|
|
790
|
+
if (editorRef.current) {
|
|
791
|
+
editorRef.current.innerHTML = htmlContent;
|
|
792
|
+
}
|
|
793
|
+
} else if (typeof value === 'string') {
|
|
794
|
+
// Unescape HTML entities before setting the content
|
|
795
|
+
var unescapedValue = unescapeHtml(value);
|
|
796
|
+
setHtml(unescapedValue);
|
|
797
|
+
if (editorRef.current) {
|
|
798
|
+
editorRef.current.innerHTML = unescapedValue || '';
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
} catch (e) {
|
|
802
|
+
console.error('Error processing editor content:', e);
|
|
803
|
+
// Fallback to raw value if parsing fails
|
|
804
|
+
var _unescapedValue = typeof value === 'string' ? unescapeHtml(value) : value;
|
|
805
|
+
setHtml(_unescapedValue);
|
|
806
|
+
if (editorRef.current) {
|
|
807
|
+
editorRef.current.innerHTML = _unescapedValue || '';
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
} else {
|
|
811
|
+
setHtml('');
|
|
812
|
+
if (editorRef.current) {
|
|
813
|
+
editorRef.current.innerHTML = '';
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}, [!isList]);
|
|
817
|
+
|
|
818
|
+
// Call onChange whenever html state updates
|
|
819
|
+
React.useEffect(function () {
|
|
820
|
+
onChange && onChange(html);
|
|
821
|
+
}, [html, onChange]);
|
|
822
|
+
// Trigger change manually
|
|
823
|
+
var triggerChange = React.useCallback(function () {
|
|
824
|
+
var next = getCleanHtml();
|
|
825
|
+
setHtml(next);
|
|
826
|
+
}, []);
|
|
827
|
+
var handleChange = function handleChange() {
|
|
828
|
+
if (!editorRef.current) return;
|
|
829
|
+
|
|
830
|
+
// Clone editor content
|
|
831
|
+
var tempDiv = document.createElement('div');
|
|
832
|
+
tempDiv.innerHTML = editorRef.current.innerHTML;
|
|
833
|
+
|
|
834
|
+
// Remove delete buttons from the clone
|
|
835
|
+
tempDiv.querySelectorAll('button[title="Remove image"]').forEach(function (btn) {
|
|
836
|
+
return btn.remove();
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
// Send cleaned HTML to onBlur
|
|
840
|
+
onBlur && onBlur(tempDiv.innerHTML);
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
// Detect if selection is inside a list (ol or ul)
|
|
844
|
+
var detectListType = function detectListType() {
|
|
845
|
+
var sel = window.getSelection();
|
|
846
|
+
if (!sel || !sel.rangeCount) {
|
|
847
|
+
setCurrentListType(null);
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
var node = sel.anchorNode;
|
|
851
|
+
while (node && node !== editorRef.current) {
|
|
852
|
+
if (node.nodeName === "OL") {
|
|
853
|
+
setCurrentListType("ordered");
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
if (node.nodeName === "UL") {
|
|
857
|
+
setCurrentListType("unordered");
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
node = node.parentNode;
|
|
861
|
+
}
|
|
862
|
+
setCurrentListType(null);
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
// Helper to walk up DOM to find style tags or CSS style:
|
|
866
|
+
var isParentStyle = function isParentStyle(node) {
|
|
867
|
+
for (var _len = arguments.length, tagNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
868
|
+
tagNames[_key - 1] = arguments[_key];
|
|
869
|
+
}
|
|
870
|
+
while (node && node !== editorRef.current) {
|
|
871
|
+
if (node.nodeType === 1 && tagNames.includes(node.tagName)) return true;
|
|
872
|
+
|
|
873
|
+
// Also check inline style for bold and italic:
|
|
874
|
+
if (node.nodeType === 1 && node.style) {
|
|
875
|
+
var style = node.style;
|
|
876
|
+
if (tagNames.includes("bold") && (style.fontWeight === "bold" || Number(style.fontWeight) >= 600)) return true;
|
|
877
|
+
if (tagNames.includes("italic") && style.fontStyle === "italic") return true;
|
|
878
|
+
if (tagNames.includes("underline") && style.textDecoration.includes("underline")) return true;
|
|
879
|
+
if (node.style && node.style.color) {
|
|
880
|
+
return node.style.color;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// 2️⃣ Check for <font color=""> (older HTML)
|
|
884
|
+
if (node.tagName === "FONT" && node.getAttribute("color")) {
|
|
885
|
+
return node.getAttribute("color");
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
node = node.parentNode;
|
|
889
|
+
}
|
|
890
|
+
return false;
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
// Update style states based on selection or cursor position
|
|
894
|
+
var updateStyleStates = function updateStyleStates() {
|
|
895
|
+
var sel = window.getSelection();
|
|
896
|
+
if (!sel || !sel.rangeCount) {
|
|
897
|
+
setIsBold(false);
|
|
898
|
+
setIsItalic(false);
|
|
899
|
+
setIsUnderline(false);
|
|
900
|
+
setFontColor("#000000"); // default
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
var container = sel.anchorNode.nodeType === 3 ? sel.anchorNode.parentNode : sel.anchorNode;
|
|
904
|
+
var computedAlign = window.getComputedStyle(container).textAlign;
|
|
905
|
+
setActiveAlign(computedAlign);
|
|
906
|
+
var range = sel.getRangeAt(0);
|
|
907
|
+
if (range.collapsed) {
|
|
908
|
+
// Cursor only, check parent nodes
|
|
909
|
+
var _container = sel.anchorNode.nodeType === 3 ? sel.anchorNode.parentNode : sel.anchorNode;
|
|
910
|
+
window.getComputedStyle(_container);
|
|
911
|
+
setIsBold(isParentStyle(_container, "B", "STRONG", "bold"));
|
|
912
|
+
setIsItalic(isParentStyle(_container, "I", "EM", "italic"));
|
|
913
|
+
setIsUnderline(isParentStyle(_container, "U", "underline"));
|
|
914
|
+
|
|
915
|
+
// ✅ Get computed color from container
|
|
916
|
+
var computedColor = window.getComputedStyle(_container).color;
|
|
917
|
+
setFontColor(rgbToHex(computedColor));
|
|
918
|
+
} else {
|
|
919
|
+
// Text selected, use execCommand state
|
|
920
|
+
setIsBold(document.queryCommandState("bold"));
|
|
921
|
+
setIsItalic(document.queryCommandState("italic"));
|
|
922
|
+
setIsUnderline(document.queryCommandState("underline"));
|
|
923
|
+
|
|
924
|
+
// ✅ For selection, get color from selection's start container
|
|
925
|
+
var _container2 = sel.anchorNode.nodeType === 3 ? sel.anchorNode.parentNode : sel.anchorNode;
|
|
926
|
+
var _computedColor = window.getComputedStyle(_container2).color;
|
|
927
|
+
setFontColor(rgbToHex(_computedColor));
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
// Helper to convert rgb() to hex
|
|
932
|
+
function rgbToHex(rgb) {
|
|
933
|
+
var result = rgb.match(/\d+/g);
|
|
934
|
+
if (!result) return "#000000";
|
|
935
|
+
return "#" + result.slice(0, 3).map(function (x) {
|
|
936
|
+
var hex = parseInt(x, 10).toString(16);
|
|
937
|
+
return hex.length === 1 ? "0" + hex : hex;
|
|
938
|
+
}).join("");
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
// Listen for selection changes globally to update styles and list type
|
|
942
|
+
React.useEffect(function () {
|
|
943
|
+
document.addEventListener("selectionchange", detectListType);
|
|
944
|
+
document.addEventListener("selectionchange", updateStyleStates);
|
|
945
|
+
var handleSelectionChange = function handleSelectionChange() {
|
|
946
|
+
var selection = window.getSelection();
|
|
947
|
+
if (!selection.rangeCount) return;
|
|
948
|
+
var range = selection.getRangeAt(0);
|
|
949
|
+
var element = range.startContainer.parentElement.closest('[style*="font-size"]');
|
|
950
|
+
if (element) {
|
|
951
|
+
var fontSize = window.getComputedStyle(element).fontSize;
|
|
952
|
+
var sizeValue = fontSize ? parseInt(fontSize) : 16;
|
|
953
|
+
setCurrentFontSize(sizeValue.toString());
|
|
954
|
+
} else {
|
|
955
|
+
setCurrentFontSize("16"); // Default size
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
document.addEventListener('selectionchange', handleSelectionChange);
|
|
959
|
+
return function () {
|
|
960
|
+
document.removeEventListener("selectionchange", detectListType);
|
|
961
|
+
document.removeEventListener("selectionchange", updateStyleStates);
|
|
962
|
+
document.removeEventListener('selectionchange', handleSelectionChange);
|
|
963
|
+
};
|
|
964
|
+
}, []);
|
|
965
|
+
var focus = function focus() {
|
|
966
|
+
return editorRef.current && editorRef.current.focus();
|
|
967
|
+
};
|
|
968
|
+
var exec = function exec(command) {
|
|
969
|
+
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
970
|
+
document.execCommand(command, false, value);
|
|
971
|
+
triggerChange();
|
|
972
|
+
focus();
|
|
973
|
+
};
|
|
974
|
+
var _useState31 = React.useState("#000000"),
|
|
975
|
+
_useState32 = _slicedToArray(_useState31, 2),
|
|
976
|
+
fontColor = _useState32[0],
|
|
977
|
+
setFontColor = _useState32[1];
|
|
978
|
+
var handleColorChange = function handleColorChange(color) {
|
|
979
|
+
setFontColor(color);
|
|
980
|
+
exec("foreColor", color);
|
|
981
|
+
};
|
|
982
|
+
var addLink = function addLink() {
|
|
983
|
+
var sel = window.getSelection();
|
|
984
|
+
if (!sel || sel.rangeCount === 0) return;
|
|
985
|
+
selectionRangeRef.current = sel.getRangeAt(0).cloneRange();
|
|
986
|
+
var selectedText = sel.toString();
|
|
987
|
+
if (selectedText.length > 0) {
|
|
988
|
+
setLinkText(selectedText);
|
|
989
|
+
setLinkUrl("");
|
|
990
|
+
setLinkModalOpen(true);
|
|
991
|
+
} else {
|
|
992
|
+
setLinkText("");
|
|
993
|
+
setLinkUrl("");
|
|
994
|
+
setLinkModalOpen(true);
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
var processExistingImages = function processExistingImages(container) {
|
|
998
|
+
if (!container) return;
|
|
999
|
+
container.querySelectorAll("img").forEach(function (img) {
|
|
1000
|
+
// REMOVE the old wrapper if it exists so we can re-add
|
|
1001
|
+
var oldWrapper = img.closest(".image-container");
|
|
1002
|
+
if (oldWrapper) {
|
|
1003
|
+
oldWrapper.replaceWith(img); // unwrap
|
|
1004
|
+
}
|
|
1005
|
+
var wrapper = document.createElement("div");
|
|
1006
|
+
var align = img.getAttribute('data-align') || 'center';
|
|
1007
|
+
wrapper.className = "image-container image-align-".concat(align);
|
|
1008
|
+
wrapper.style.cursor = editable ? 'pointer' : 'default';
|
|
1009
|
+
img.className = "rte-image";
|
|
1010
|
+
img.style.cssText = ""; // Reset inline styles
|
|
1011
|
+
img.setAttribute('data-align', align);
|
|
1012
|
+
img.dataset.hasDeleteButton = "true";
|
|
1013
|
+
|
|
1014
|
+
// Add click listener to open modal
|
|
1015
|
+
img.addEventListener("click", function () {
|
|
1016
|
+
return openImageModal(img.src);
|
|
1017
|
+
});
|
|
1018
|
+
var deleteBtn = document.createElement("button");
|
|
1019
|
+
deleteBtn.innerHTML = "×";
|
|
1020
|
+
deleteBtn.className = "image-delete-button";
|
|
1021
|
+
deleteBtn.style.display = editable ? 'flex' : 'none';
|
|
1022
|
+
deleteBtn.style.pointerEvents = editable ? 'auto' : 'none';
|
|
1023
|
+
deleteBtn.title = "Remove image";
|
|
1024
|
+
deleteBtn.onclick = function (e) {
|
|
1025
|
+
e.preventDefault();
|
|
1026
|
+
e.stopPropagation();
|
|
1027
|
+
var wrapper = e.currentTarget.closest(".image-container");
|
|
1028
|
+
if (wrapper && wrapper.parentNode) {
|
|
1029
|
+
wrapper.parentNode.removeChild(wrapper);
|
|
1030
|
+
triggerChange && triggerChange();
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
var parentNode = img.parentNode,
|
|
1034
|
+
nextSibling = img.nextSibling;
|
|
1035
|
+
if (parentNode) {
|
|
1036
|
+
parentNode.removeChild(img);
|
|
1037
|
+
wrapper.appendChild(img);
|
|
1038
|
+
wrapper.appendChild(deleteBtn);
|
|
1039
|
+
if (nextSibling) {
|
|
1040
|
+
parentNode.insertBefore(wrapper, nextSibling);
|
|
1041
|
+
} else {
|
|
1042
|
+
parentNode.appendChild(wrapper);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
};
|
|
1047
|
+
React.useEffect(function () {
|
|
1048
|
+
if (editorRef.current && value) {
|
|
1049
|
+
requestAnimationFrame(function () {
|
|
1050
|
+
return processExistingImages(editorRef.current);
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
}, [value]);
|
|
1054
|
+
var insertImage = /*#__PURE__*/function () {
|
|
1055
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(dataUrl, fileName) {
|
|
1056
|
+
var container, img;
|
|
1057
|
+
return _regenerator().w(function (_context) {
|
|
1058
|
+
while (1) switch (_context.n) {
|
|
1059
|
+
case 0:
|
|
1060
|
+
try {
|
|
1061
|
+
if (editable) {
|
|
1062
|
+
// Create container for the image
|
|
1063
|
+
container = document.createElement('div');
|
|
1064
|
+
container.className = 'image-container';
|
|
1065
|
+
|
|
1066
|
+
// Create image element
|
|
1067
|
+
img = document.createElement('img');
|
|
1068
|
+
img.src = dataUrl;
|
|
1069
|
+
img.alt = fileName || "image";
|
|
1070
|
+
img.addEventListener("click", function () {
|
|
1071
|
+
return openImageModal(dataUrl);
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
// Add elements to container
|
|
1075
|
+
container.appendChild(img);
|
|
1076
|
+
|
|
1077
|
+
// Insert at cursor position
|
|
1078
|
+
insertNodeAtCursor(container);
|
|
1079
|
+
triggerChange();
|
|
1080
|
+
|
|
1081
|
+
// Immediately process newly inserted image so delete button appears
|
|
1082
|
+
requestAnimationFrame(function () {
|
|
1083
|
+
processExistingImages(editorRef.current);
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
} catch (err) {
|
|
1087
|
+
console.error('Error inserting image:', err);
|
|
1088
|
+
}
|
|
1089
|
+
case 1:
|
|
1090
|
+
return _context.a(2);
|
|
1091
|
+
}
|
|
1092
|
+
}, _callee);
|
|
1093
|
+
}));
|
|
1094
|
+
return function insertImage(_x, _x2) {
|
|
1095
|
+
return _ref2.apply(this, arguments);
|
|
1096
|
+
};
|
|
1097
|
+
}();
|
|
1098
|
+
var readFileAsDataURL = function readFileAsDataURL(file) {
|
|
1099
|
+
return new Promise(function (res, rej) {
|
|
1100
|
+
var reader = new FileReader();
|
|
1101
|
+
reader.onload = function (ev) {
|
|
1102
|
+
return res(ev.target.result);
|
|
1103
|
+
};
|
|
1104
|
+
reader.onerror = rej;
|
|
1105
|
+
reader.readAsDataURL(file);
|
|
1106
|
+
});
|
|
1107
|
+
};
|
|
1108
|
+
var handlePaste = React.useCallback(function (e) {
|
|
1109
|
+
var clipboardData = e.clipboardData || window.clipboardData;
|
|
1110
|
+
if (!clipboardData) return;
|
|
1111
|
+
|
|
1112
|
+
// Check for image in clipboard
|
|
1113
|
+
var items = clipboardData.items || [];
|
|
1114
|
+
var _loop = function _loop() {
|
|
1115
|
+
var item = items[i];
|
|
1116
|
+
if (item.kind === 'file' && item.type.indexOf('image/') !== -1) {
|
|
1117
|
+
e.preventDefault();
|
|
1118
|
+
var file = item.getAsFile();
|
|
1119
|
+
if (file) {
|
|
1120
|
+
setIsUploading(true);
|
|
1121
|
+
var uploadPromise = onImageUpload ? onImageUpload(file) : readFileAsDataURL(file);
|
|
1122
|
+
uploadPromise.then(function (url) {
|
|
1123
|
+
if (url) {
|
|
1124
|
+
// if the user's onImageUpload resolves to `{ mediaUrl: '...' }` like the previous MediaUpload, handle it
|
|
1125
|
+
var finalUrl = _typeof(url) === 'object' && url !== null && url.mediaUrl ? url.mediaUrl : url;
|
|
1126
|
+
insertImage(finalUrl, file.name || 'pasted-image');
|
|
1127
|
+
}
|
|
1128
|
+
setIsUploading(false);
|
|
1129
|
+
})["catch"](function (error) {
|
|
1130
|
+
console.error('Error uploading pasted image:', error);
|
|
1131
|
+
setIsUploading(false);
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
return {
|
|
1135
|
+
v: void 0
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
},
|
|
1139
|
+
_ret;
|
|
1140
|
+
for (var i = 0; i < items.length; i++) {
|
|
1141
|
+
_ret = _loop();
|
|
1142
|
+
if (_ret) return _ret.v;
|
|
1143
|
+
}
|
|
1144
|
+
var htmlData = clipboardData.getData('text/html');
|
|
1145
|
+
if (htmlData && htmlData.trim()) {
|
|
1146
|
+
e.preventDefault();
|
|
1147
|
+
var tempDiv = document.createElement('div');
|
|
1148
|
+
tempDiv.innerHTML = htmlData;
|
|
1149
|
+
tempDiv.querySelectorAll('script, meta, link').forEach(function (el) {
|
|
1150
|
+
return el.remove();
|
|
1151
|
+
});
|
|
1152
|
+
document.execCommand('styleWithCSS', false, true);
|
|
1153
|
+
document.execCommand('insertHTML', false, tempDiv.innerHTML);
|
|
1154
|
+
document.execCommand('styleWithCSS', false, false);
|
|
1155
|
+
triggerChange();
|
|
1156
|
+
focus();
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
var plainText = clipboardData.getData('text/plain');
|
|
1160
|
+
if (plainText) {
|
|
1161
|
+
e.preventDefault();
|
|
1162
|
+
var htmlToInsert = escapeHtml(plainText);
|
|
1163
|
+
htmlToInsert = htmlToInsert.replace(URL_REGEX, function (url) {
|
|
1164
|
+
var safeUrl = escapeAttr(url.trim());
|
|
1165
|
+
return "<a href=\"".concat(safeUrl, "\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"color: blue; text-decoration: underline;\">").concat(escapeHtml(url), "</a>");
|
|
1166
|
+
});
|
|
1167
|
+
htmlToInsert = htmlToInsert.replace(/\n/g, '<br>');
|
|
1168
|
+
document.execCommand('insertHTML', false, htmlToInsert);
|
|
1169
|
+
triggerChange();
|
|
1170
|
+
focus();
|
|
1171
|
+
}
|
|
1172
|
+
}, [insertImage, triggerChange]);
|
|
1173
|
+
var handleDrop = /*#__PURE__*/function () {
|
|
1174
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
|
|
1175
|
+
var files, imageFiles, _iterator, _step, _loop2, _t;
|
|
1176
|
+
return _regenerator().w(function (_context3) {
|
|
1177
|
+
while (1) switch (_context3.p = _context3.n) {
|
|
1178
|
+
case 0:
|
|
1179
|
+
if (editable) {
|
|
1180
|
+
_context3.n = 1;
|
|
1181
|
+
break;
|
|
1182
|
+
}
|
|
1183
|
+
return _context3.a(2);
|
|
1184
|
+
case 1:
|
|
1185
|
+
e.preventDefault();
|
|
1186
|
+
e.stopPropagation();
|
|
1187
|
+
files = e.dataTransfer.files;
|
|
1188
|
+
if (!(!files || files.length === 0)) {
|
|
1189
|
+
_context3.n = 2;
|
|
1190
|
+
break;
|
|
1191
|
+
}
|
|
1192
|
+
return _context3.a(2);
|
|
1193
|
+
case 2:
|
|
1194
|
+
imageFiles = Array.from(files).filter(function (file) {
|
|
1195
|
+
return file.type.startsWith("image/");
|
|
1196
|
+
});
|
|
1197
|
+
_iterator = _createForOfIteratorHelper(imageFiles);
|
|
1198
|
+
_context3.p = 3;
|
|
1199
|
+
_loop2 = /*#__PURE__*/_regenerator().m(function _loop2() {
|
|
1200
|
+
var file, uploadPromise;
|
|
1201
|
+
return _regenerator().w(function (_context2) {
|
|
1202
|
+
while (1) switch (_context2.n) {
|
|
1203
|
+
case 0:
|
|
1204
|
+
file = _step.value;
|
|
1205
|
+
try {
|
|
1206
|
+
setIsUploading(true);
|
|
1207
|
+
uploadPromise = onImageUpload ? onImageUpload(file) : readFileAsDataURL(file);
|
|
1208
|
+
uploadPromise.then(function (url) {
|
|
1209
|
+
if (url) {
|
|
1210
|
+
var finalUrl = _typeof(url) === 'object' && url !== null && url.mediaUrl ? url.mediaUrl : url;
|
|
1211
|
+
insertImage(finalUrl, file.name);
|
|
1212
|
+
}
|
|
1213
|
+
setIsUploading(false);
|
|
1214
|
+
})["catch"](function (error) {
|
|
1215
|
+
console.error('Error processing image:', error);
|
|
1216
|
+
setIsUploading(false);
|
|
1217
|
+
});
|
|
1218
|
+
} catch (error) {
|
|
1219
|
+
console.error('Error processing image:', error);
|
|
1220
|
+
setIsUploading(false);
|
|
1221
|
+
}
|
|
1222
|
+
case 1:
|
|
1223
|
+
return _context2.a(2);
|
|
1224
|
+
}
|
|
1225
|
+
}, _loop2);
|
|
1226
|
+
});
|
|
1227
|
+
_iterator.s();
|
|
1228
|
+
case 4:
|
|
1229
|
+
if ((_step = _iterator.n()).done) {
|
|
1230
|
+
_context3.n = 6;
|
|
1231
|
+
break;
|
|
1232
|
+
}
|
|
1233
|
+
return _context3.d(_regeneratorValues(_loop2()), 5);
|
|
1234
|
+
case 5:
|
|
1235
|
+
_context3.n = 4;
|
|
1236
|
+
break;
|
|
1237
|
+
case 6:
|
|
1238
|
+
_context3.n = 8;
|
|
1239
|
+
break;
|
|
1240
|
+
case 7:
|
|
1241
|
+
_context3.p = 7;
|
|
1242
|
+
_t = _context3.v;
|
|
1243
|
+
_iterator.e(_t);
|
|
1244
|
+
case 8:
|
|
1245
|
+
_context3.p = 8;
|
|
1246
|
+
_iterator.f();
|
|
1247
|
+
return _context3.f(8);
|
|
1248
|
+
case 9:
|
|
1249
|
+
return _context3.a(2);
|
|
1250
|
+
}
|
|
1251
|
+
}, _callee2, null, [[3, 7, 8, 9]]);
|
|
1252
|
+
}));
|
|
1253
|
+
return function handleDrop(_x3) {
|
|
1254
|
+
return _ref3.apply(this, arguments);
|
|
1255
|
+
};
|
|
1256
|
+
}();
|
|
1257
|
+
var insertNodeAtCursor = function insertNodeAtCursor(node) {
|
|
1258
|
+
try {
|
|
1259
|
+
var sel = window.getSelection();
|
|
1260
|
+
var range;
|
|
1261
|
+
if (!sel || sel.rangeCount === 0 || !editorRef.current.contains(sel.anchorNode)) {
|
|
1262
|
+
editorRef.current.focus();
|
|
1263
|
+
|
|
1264
|
+
// Move cursor to end if not already in editor
|
|
1265
|
+
range = document.createRange();
|
|
1266
|
+
range.selectNodeContents(editorRef.current);
|
|
1267
|
+
range.collapse(false);
|
|
1268
|
+
sel.removeAllRanges();
|
|
1269
|
+
sel.addRange(range);
|
|
1270
|
+
} else {
|
|
1271
|
+
range = sel.getRangeAt(0);
|
|
1272
|
+
}
|
|
1273
|
+
range.deleteContents();
|
|
1274
|
+
range.insertNode(node);
|
|
1275
|
+
var space = document.createTextNode("\xA0");
|
|
1276
|
+
if (node.parentNode) {
|
|
1277
|
+
node.parentNode.insertBefore(space, node.nextSibling);
|
|
1278
|
+
}
|
|
1279
|
+
range.setStartAfter(space);
|
|
1280
|
+
range.collapse(true);
|
|
1281
|
+
sel.removeAllRanges();
|
|
1282
|
+
sel.addRange(range);
|
|
1283
|
+
} catch (error) {
|
|
1284
|
+
console.error("Insertion error:", error);
|
|
1285
|
+
if (editorRef.current) {
|
|
1286
|
+
editorRef.current.appendChild(node);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
var getCleanHtml = function getCleanHtml() {
|
|
1291
|
+
if (!editorRef.current) return "";
|
|
1292
|
+
return editorRef.current.innerHTML;
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
// Helper function to unescape HTML entities
|
|
1296
|
+
var unescapeHtml = function unescapeHtml(html) {
|
|
1297
|
+
if (!html) return '';
|
|
1298
|
+
var txt = document.createElement("textarea");
|
|
1299
|
+
txt.innerHTML = html;
|
|
1300
|
+
return txt.value;
|
|
1301
|
+
};
|
|
1302
|
+
var handleKeyDown = React.useCallback(function (e) {
|
|
1303
|
+
// Handle Enter key
|
|
1304
|
+
if (e.key === 'Enter') {
|
|
1305
|
+
e.preventDefault();
|
|
1306
|
+
var selection = window.getSelection();
|
|
1307
|
+
if (!selection.rangeCount) return;
|
|
1308
|
+
var range = selection.getRangeAt(0);
|
|
1309
|
+
var node = range.startContainer;
|
|
1310
|
+
var parent = node.nodeType === 3 ? node.parentNode : node;
|
|
1311
|
+
|
|
1312
|
+
// Check if we're in a list item
|
|
1313
|
+
var listItem = parent.closest('li');
|
|
1314
|
+
if (listItem) {
|
|
1315
|
+
var list = listItem.parentNode;
|
|
1316
|
+
list.tagName === 'OL';
|
|
1317
|
+
|
|
1318
|
+
// Create a new list item
|
|
1319
|
+
var newItem = document.createElement('li');
|
|
1320
|
+
|
|
1321
|
+
// If we're at the end of a list item, add a new one
|
|
1322
|
+
if (range.collapsed && range.endOffset === node.length) {
|
|
1323
|
+
// If it's empty, create a regular paragraph instead
|
|
1324
|
+
if (listItem.textContent.trim() === '') {
|
|
1325
|
+
document.execCommand('insertHTML', false, '<div><br></div>');
|
|
1326
|
+
// Move the cursor to the new line
|
|
1327
|
+
var _newRange = document.createRange();
|
|
1328
|
+
var newDiv = editorRef.current.lastElementChild;
|
|
1329
|
+
_newRange.setStart(newDiv, 0);
|
|
1330
|
+
_newRange.collapse(true);
|
|
1331
|
+
selection.removeAllRanges();
|
|
1332
|
+
selection.addRange(_newRange);
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// Insert new list item
|
|
1337
|
+
if (listItem.nextSibling) {
|
|
1338
|
+
list.insertBefore(newItem, listItem.nextSibling);
|
|
1339
|
+
} else {
|
|
1340
|
+
list.appendChild(newItem);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// Move cursor to the new list item
|
|
1344
|
+
var newRange = document.createRange();
|
|
1345
|
+
newRange.setStart(newItem, 0);
|
|
1346
|
+
newRange.collapse(true);
|
|
1347
|
+
selection.removeAllRanges();
|
|
1348
|
+
selection.addRange(newRange);
|
|
1349
|
+
} else {
|
|
1350
|
+
// If we're in the middle of text, split the list item
|
|
1351
|
+
var textBefore = node.textContent.substring(0, range.startOffset);
|
|
1352
|
+
var textAfter = node.textContent.substring(range.startOffset);
|
|
1353
|
+
|
|
1354
|
+
// Update current item
|
|
1355
|
+
node.textContent = textBefore;
|
|
1356
|
+
|
|
1357
|
+
// Insert new item after current one
|
|
1358
|
+
newItem.textContent = textAfter;
|
|
1359
|
+
if (listItem.nextSibling) {
|
|
1360
|
+
list.insertBefore(newItem, listItem.nextSibling);
|
|
1361
|
+
} else {
|
|
1362
|
+
list.appendChild(newItem);
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// Move cursor to the new list item
|
|
1366
|
+
var _newRange2 = document.createRange();
|
|
1367
|
+
_newRange2.setStart(newItem.firstChild || newItem, 0);
|
|
1368
|
+
_newRange2.collapse(true);
|
|
1369
|
+
selection.removeAllRanges();
|
|
1370
|
+
selection.addRange(_newRange2);
|
|
1371
|
+
}
|
|
1372
|
+
} else {
|
|
1373
|
+
// Regular text, insert a new paragraph
|
|
1374
|
+
document.execCommand('insertHTML', false, '<div><br></div>');
|
|
1375
|
+
}
|
|
1376
|
+
triggerChange();
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
// Handle Ctrl/Cmd + B/I/U for bold/italic/underline
|
|
1381
|
+
if ((e.ctrlKey || e.metaKey) && e.key === "b") {
|
|
1382
|
+
e.preventDefault();
|
|
1383
|
+
exec("bold");
|
|
1384
|
+
} else if ((e.ctrlKey || e.metaKey) && e.key === "i") {
|
|
1385
|
+
e.preventDefault();
|
|
1386
|
+
exec("italic");
|
|
1387
|
+
} else if ((e.ctrlKey || e.metaKey) && e.key === "u") {
|
|
1388
|
+
e.preventDefault();
|
|
1389
|
+
exec("underline");
|
|
1390
|
+
}
|
|
1391
|
+
}, [exec, triggerChange]);
|
|
1392
|
+
var confirmLink = function confirmLink() {
|
|
1393
|
+
// Add protocol if missing
|
|
1394
|
+
var url = linkUrl.trim();
|
|
1395
|
+
if (url && !/^(https?:\/\/|mailto:|tel:)/i.test(url)) {
|
|
1396
|
+
url = "https://".concat(url);
|
|
1397
|
+
}
|
|
1398
|
+
var safeUrl = escapeAttr(url);
|
|
1399
|
+
var safeText = escapeHtml(linkText || linkUrl);
|
|
1400
|
+
var sel = window.getSelection();
|
|
1401
|
+
sel.removeAllRanges();
|
|
1402
|
+
if (selectionRangeRef.current) {
|
|
1403
|
+
sel.addRange(selectionRangeRef.current);
|
|
1404
|
+
}
|
|
1405
|
+
var linkHtml = "<a href=\"".concat(safeUrl, "\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"color: blue;\">").concat(safeText, "</a>");
|
|
1406
|
+
document.execCommand("insertHTML", false, linkHtml);
|
|
1407
|
+
setLinkModalOpen(false);
|
|
1408
|
+
triggerChange();
|
|
1409
|
+
focus();
|
|
1410
|
+
selectionRangeRef.current = null;
|
|
1411
|
+
};
|
|
1412
|
+
var cancelLink = function cancelLink() {
|
|
1413
|
+
setLinkModalOpen(false);
|
|
1414
|
+
selectionRangeRef.current = null;
|
|
1415
|
+
};
|
|
1416
|
+
var handleSelect = function handleSelect(type) {
|
|
1417
|
+
exec(type === "unordered" ? "insertUnorderedList" : "insertOrderedList");
|
|
1418
|
+
};
|
|
1419
|
+
var onLineHeightChange = function onLineHeightChange(value) {
|
|
1420
|
+
if (!value) return;
|
|
1421
|
+
var sel = window.getSelection();
|
|
1422
|
+
if (!sel || !sel.rangeCount) return;
|
|
1423
|
+
var range = sel.getRangeAt(0);
|
|
1424
|
+
var editor = editorRef.current;
|
|
1425
|
+
if (!editor) return;
|
|
1426
|
+
var walker = document.createTreeWalker(editor, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, {
|
|
1427
|
+
acceptNode: function acceptNode(node) {
|
|
1428
|
+
return range.intersectsNode(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
|
|
1429
|
+
}
|
|
1430
|
+
}, false);
|
|
1431
|
+
var node;
|
|
1432
|
+
var blocksToStyle = new Set();
|
|
1433
|
+
var blockTags = ['P', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'LI', 'BLOCKQUOTE'];
|
|
1434
|
+
var tempRange = range.cloneRange();
|
|
1435
|
+
while (node = walker.nextNode()) {
|
|
1436
|
+
if (node.nodeType === 1 && blockTags.includes(node.tagName)) {
|
|
1437
|
+
blocksToStyle.add(node);
|
|
1438
|
+
} else if (node.nodeType === 3) {
|
|
1439
|
+
var parent = node.parentNode;
|
|
1440
|
+
while (parent && parent !== editor && !blockTags.includes(parent.tagName)) {
|
|
1441
|
+
parent = parent.parentNode;
|
|
1442
|
+
}
|
|
1443
|
+
if (parent && parent !== editor && blockTags.includes(parent.tagName)) {
|
|
1444
|
+
blocksToStyle.add(parent);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
if (blocksToStyle.size > 0) {
|
|
1449
|
+
blocksToStyle.forEach(function (block) {
|
|
1450
|
+
block.style.lineHeight = value;
|
|
1451
|
+
});
|
|
1452
|
+
} else {
|
|
1453
|
+
var common = range.commonAncestorContainer;
|
|
1454
|
+
if (common.nodeType === 3) common = common.parentNode;
|
|
1455
|
+
while (common && common !== editor && !blockTags.includes(common.tagName)) {
|
|
1456
|
+
common = common.parentNode;
|
|
1457
|
+
}
|
|
1458
|
+
if (common && common !== editor) {
|
|
1459
|
+
common.style.lineHeight = value;
|
|
1460
|
+
} else if (editor) {
|
|
1461
|
+
document.execCommand('formatBlock', false, 'div');
|
|
1462
|
+
var newCommon = window.getSelection().getRangeAt(0).commonAncestorContainer;
|
|
1463
|
+
if (newCommon.nodeType === 3) newCommon = newCommon.parentNode;
|
|
1464
|
+
if (newCommon && newCommon !== editor) {
|
|
1465
|
+
newCommon.style.lineHeight = value;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
try {
|
|
1470
|
+
sel.removeAllRanges();
|
|
1471
|
+
sel.addRange(tempRange);
|
|
1472
|
+
} catch (e) {}
|
|
1473
|
+
setCurrentLineHeight(value);
|
|
1474
|
+
triggerChange();
|
|
1475
|
+
focus();
|
|
1476
|
+
};
|
|
1477
|
+
var applyFontSize = function applyFontSize(size) {
|
|
1478
|
+
var sel = window.getSelection();
|
|
1479
|
+
if (!sel || !sel.rangeCount) return;
|
|
1480
|
+
var range = sel.getRangeAt(0);
|
|
1481
|
+
var sizePx = "".concat(size, "px");
|
|
1482
|
+
|
|
1483
|
+
// Collapsed selection (cursor only): insert a styled zero-width span
|
|
1484
|
+
if (range.collapsed) {
|
|
1485
|
+
var span = document.createElement("span");
|
|
1486
|
+
span.style.fontSize = sizePx;
|
|
1487
|
+
span.appendChild(document.createTextNode("\u200B"));
|
|
1488
|
+
range.insertNode(span);
|
|
1489
|
+
var newRange = document.createRange();
|
|
1490
|
+
newRange.setStart(span.firstChild, 1);
|
|
1491
|
+
newRange.collapse(true);
|
|
1492
|
+
sel.removeAllRanges();
|
|
1493
|
+
sel.addRange(newRange);
|
|
1494
|
+
triggerChange();
|
|
1495
|
+
focus();
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
// Extended selection (highlighted text)
|
|
1500
|
+
try {
|
|
1501
|
+
var editor = editorRef.current;
|
|
1502
|
+
if (!editor) return;
|
|
1503
|
+
|
|
1504
|
+
// We will iterate through all the text nodes in the selection
|
|
1505
|
+
var walker = document.createTreeWalker(editor, NodeFilter.SHOW_TEXT, {
|
|
1506
|
+
acceptNode: function acceptNode(node) {
|
|
1507
|
+
return range.intersectsNode(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
|
|
1508
|
+
}
|
|
1509
|
+
}, false);
|
|
1510
|
+
var node;
|
|
1511
|
+
var nodesToStyle = [];
|
|
1512
|
+
while (node = walker.nextNode()) {
|
|
1513
|
+
nodesToStyle.push(node);
|
|
1514
|
+
}
|
|
1515
|
+
var savedRange = range.cloneRange();
|
|
1516
|
+
var lastInsertedNode = null;
|
|
1517
|
+
|
|
1518
|
+
// Iterate through the selected text nodes and wrap them in spans
|
|
1519
|
+
for (var _i = 0, _nodesToStyle = nodesToStyle; _i < _nodesToStyle.length; _i++) {
|
|
1520
|
+
var textNode = _nodesToStyle[_i];
|
|
1521
|
+
var parent = textNode.parentNode;
|
|
1522
|
+
|
|
1523
|
+
// This is important: check if the parent is a block-level element
|
|
1524
|
+
// like a list item or paragraph. If so, we want to style the block
|
|
1525
|
+
// itself to avoid breaking its structure.
|
|
1526
|
+
var isBlockLevel = ['P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'LI', 'BLOCKQUOTE'].includes(parent.tagName);
|
|
1527
|
+
if (isBlockLevel) {
|
|
1528
|
+
parent.style.fontSize = sizePx;
|
|
1529
|
+
} else {
|
|
1530
|
+
// For inline text, wrap the selected portion in a new span
|
|
1531
|
+
var startOffset = textNode === savedRange.startContainer ? savedRange.startOffset : 0;
|
|
1532
|
+
var endOffset = textNode === savedRange.endContainer ? savedRange.endOffset : textNode.length;
|
|
1533
|
+
var newSpan = document.createElement("span");
|
|
1534
|
+
newSpan.style.fontSize = sizePx;
|
|
1535
|
+
newSpan.textContent = textNode.textContent.substring(startOffset, endOffset);
|
|
1536
|
+
var tempRange = document.createRange();
|
|
1537
|
+
tempRange.setStart(textNode, startOffset);
|
|
1538
|
+
tempRange.setEnd(textNode, endOffset);
|
|
1539
|
+
tempRange.deleteContents();
|
|
1540
|
+
tempRange.insertNode(newSpan);
|
|
1541
|
+
lastInsertedNode = newSpan;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
// After styling, we need to correctly position the cursor
|
|
1546
|
+
if (lastInsertedNode) {
|
|
1547
|
+
var _newRange3 = document.createRange();
|
|
1548
|
+
_newRange3.setStartAfter(lastInsertedNode);
|
|
1549
|
+
_newRange3.collapse(true);
|
|
1550
|
+
sel.removeAllRanges();
|
|
1551
|
+
sel.addRange(_newRange3);
|
|
1552
|
+
} else {
|
|
1553
|
+
// If no nodes were wrapped (e.g., we styled a block), restore the original selection
|
|
1554
|
+
sel.removeAllRanges();
|
|
1555
|
+
sel.addRange(savedRange);
|
|
1556
|
+
}
|
|
1557
|
+
} catch (err) {
|
|
1558
|
+
console.error("Error applying font size:", err);
|
|
1559
|
+
}
|
|
1560
|
+
triggerChange();
|
|
1561
|
+
focus();
|
|
1562
|
+
};
|
|
1563
|
+
var handleInput = React.useCallback(function () {
|
|
1564
|
+
if (onChange && editorRef.current) {
|
|
1565
|
+
var _html = editorRef.current.innerHTML;
|
|
1566
|
+
setHtml(_html);
|
|
1567
|
+
onChange(_html);
|
|
1568
|
+
}
|
|
1569
|
+
}, [onChange]);
|
|
1570
|
+
var handleImageUpload = /*#__PURE__*/function () {
|
|
1571
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e) {
|
|
1572
|
+
var file, uploadPromise;
|
|
1573
|
+
return _regenerator().w(function (_context4) {
|
|
1574
|
+
while (1) switch (_context4.n) {
|
|
1575
|
+
case 0:
|
|
1576
|
+
file = e.target.files[0];
|
|
1577
|
+
if (file) {
|
|
1578
|
+
_context4.n = 1;
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
return _context4.a(2);
|
|
1582
|
+
case 1:
|
|
1583
|
+
try {
|
|
1584
|
+
setIsUploading(true);
|
|
1585
|
+
uploadPromise = onImageUpload ? onImageUpload(file) : readFileAsDataURL(file);
|
|
1586
|
+
uploadPromise.then(function (url) {
|
|
1587
|
+
if (url) {
|
|
1588
|
+
var finalUrl = _typeof(url) === 'object' && url !== null && url.mediaUrl ? url.mediaUrl : url;
|
|
1589
|
+
insertImage(finalUrl, file.name);
|
|
1590
|
+
}
|
|
1591
|
+
setIsUploading(false);
|
|
1592
|
+
e.target.value = null;
|
|
1593
|
+
})["catch"](function (error) {
|
|
1594
|
+
console.error('Error uploading image:', error);
|
|
1595
|
+
setIsUploading(false);
|
|
1596
|
+
});
|
|
1597
|
+
} catch (error) {
|
|
1598
|
+
console.error('Error uploading image:', error);
|
|
1599
|
+
setIsUploading(false);
|
|
1600
|
+
}
|
|
1601
|
+
case 2:
|
|
1602
|
+
return _context4.a(2);
|
|
1603
|
+
}
|
|
1604
|
+
}, _callee3);
|
|
1605
|
+
}));
|
|
1606
|
+
return function handleImageUpload(_x4) {
|
|
1607
|
+
return _ref4.apply(this, arguments);
|
|
1608
|
+
};
|
|
1609
|
+
}();
|
|
1610
|
+
React.useEffect(function () {
|
|
1611
|
+
// If disabled is explicitly false, make sure the editor is not editable
|
|
1612
|
+
if (disabled === true) {
|
|
1613
|
+
setEditable(false);
|
|
1614
|
+
}
|
|
1615
|
+
}, [disabled]);
|
|
1616
|
+
var handleEditorClick = React.useCallback(function (e) {
|
|
1617
|
+
// Check if the click is on a link
|
|
1618
|
+
var clickedLink = e.target.closest('a');
|
|
1619
|
+
if (clickedLink) {
|
|
1620
|
+
e.preventDefault();
|
|
1621
|
+
e.stopPropagation();
|
|
1622
|
+
window.open(clickedLink.href, '_blank');
|
|
1623
|
+
return;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
// If disabled is true, prevent editing
|
|
1627
|
+
if (disabled === true) {
|
|
1628
|
+
e.preventDefault();
|
|
1629
|
+
return;
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
// Only allow setting editable to true if not disabled
|
|
1633
|
+
if (!editable && disabled !== true) {
|
|
1634
|
+
setEditable(true);
|
|
1635
|
+
setTimeout(function () {
|
|
1636
|
+
if (editorRef.current) {
|
|
1637
|
+
editorRef.current.focus();
|
|
1638
|
+
}
|
|
1639
|
+
}, 0);
|
|
1640
|
+
}
|
|
1641
|
+
}, [editable, disabled]);
|
|
1642
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1643
|
+
className: "rte-main-wrapper",
|
|
1644
|
+
style: {
|
|
1645
|
+
width: '100%'
|
|
1646
|
+
}
|
|
1647
|
+
}, label && /*#__PURE__*/React.createElement(LabelComponent, null, label), /*#__PURE__*/React.createElement("div", {
|
|
1648
|
+
className: !showBorder ? "" : "rte-container",
|
|
1649
|
+
onClick: handleEditorClick,
|
|
1650
|
+
onDrop: handleDrop,
|
|
1651
|
+
onDragOver: function onDragOver(e) {
|
|
1652
|
+
e.preventDefault();
|
|
1653
|
+
e.stopPropagation();
|
|
1654
|
+
}
|
|
1655
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1656
|
+
className: "rte-toolbar"
|
|
1657
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
1658
|
+
type: "button",
|
|
1659
|
+
title: "Bold",
|
|
1660
|
+
onClick: function onClick(e) {
|
|
1661
|
+
e.preventDefault();
|
|
1662
|
+
e.stopPropagation();
|
|
1663
|
+
document.execCommand("bold");
|
|
1664
|
+
triggerChange();
|
|
1665
|
+
focus();
|
|
1666
|
+
},
|
|
1667
|
+
className: "rte-toolbar-button ".concat(isBold ? "active" : "")
|
|
1668
|
+
}, /*#__PURE__*/React.createElement(FaBold, {
|
|
1669
|
+
size: 14
|
|
1670
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
1671
|
+
type: "button",
|
|
1672
|
+
title: "Italic",
|
|
1673
|
+
onClick: function onClick(e) {
|
|
1674
|
+
e.preventDefault();
|
|
1675
|
+
e.stopPropagation();
|
|
1676
|
+
document.execCommand("italic");
|
|
1677
|
+
triggerChange();
|
|
1678
|
+
focus();
|
|
1679
|
+
},
|
|
1680
|
+
className: "rte-toolbar-button ".concat(isItalic ? "active" : "")
|
|
1681
|
+
}, /*#__PURE__*/React.createElement(FaItalic, {
|
|
1682
|
+
size: 14
|
|
1683
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
1684
|
+
type: "button",
|
|
1685
|
+
title: "Underline",
|
|
1686
|
+
onClick: function onClick(e) {
|
|
1687
|
+
e.preventDefault();
|
|
1688
|
+
e.stopPropagation();
|
|
1689
|
+
document.execCommand("underline");
|
|
1690
|
+
triggerChange();
|
|
1691
|
+
focus();
|
|
1692
|
+
},
|
|
1693
|
+
className: "rte-toolbar-button ".concat(isUnderline ? "active" : "")
|
|
1694
|
+
}, /*#__PURE__*/React.createElement(FaUnderline, {
|
|
1695
|
+
size: 14
|
|
1696
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1697
|
+
style: {
|
|
1698
|
+
width: '1px',
|
|
1699
|
+
height: '20px',
|
|
1700
|
+
backgroundColor: '#e5e7eb',
|
|
1701
|
+
margin: '0 4px'
|
|
1702
|
+
}
|
|
1703
|
+
}), /*#__PURE__*/React.createElement("select", {
|
|
1704
|
+
value: currentFontSize,
|
|
1705
|
+
onMouseDown: function onMouseDown(e) {
|
|
1706
|
+
return e.stopPropagation();
|
|
1707
|
+
},
|
|
1708
|
+
onChange: function onChange(e) {
|
|
1709
|
+
e.preventDefault();
|
|
1710
|
+
e.stopPropagation();
|
|
1711
|
+
var size = e.target.value;
|
|
1712
|
+
if (!size) return;
|
|
1713
|
+
applyFontSize(size);
|
|
1714
|
+
setCurrentFontSize(size);
|
|
1715
|
+
focus();
|
|
1716
|
+
},
|
|
1717
|
+
className: "rte-toolbar-select",
|
|
1718
|
+
style: {
|
|
1719
|
+
width: '70px'
|
|
1720
|
+
}
|
|
1721
|
+
}, [8, 10, 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 48].map(function (s) {
|
|
1722
|
+
return /*#__PURE__*/React.createElement("option", {
|
|
1723
|
+
key: s,
|
|
1724
|
+
value: s
|
|
1725
|
+
}, s, "px");
|
|
1726
|
+
})), /*#__PURE__*/React.createElement("label", {
|
|
1727
|
+
title: "Font Color",
|
|
1728
|
+
className: "rte-color-picker-label"
|
|
1729
|
+
}, /*#__PURE__*/React.createElement(FaFont, {
|
|
1730
|
+
size: 14,
|
|
1731
|
+
style: {
|
|
1732
|
+
color: fontColor
|
|
1733
|
+
}
|
|
1734
|
+
}), /*#__PURE__*/React.createElement("input", {
|
|
1735
|
+
type: "color",
|
|
1736
|
+
value: fontColor,
|
|
1737
|
+
onMouseDown: function onMouseDown(e) {
|
|
1738
|
+
e.preventDefault();
|
|
1739
|
+
e.stopPropagation();
|
|
1740
|
+
},
|
|
1741
|
+
onChange: function onChange(e) {
|
|
1742
|
+
e.stopPropagation();
|
|
1743
|
+
handleColorChange(e.target.value);
|
|
1744
|
+
},
|
|
1745
|
+
className: "rte-color-input"
|
|
1746
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1747
|
+
style: {
|
|
1748
|
+
width: '1px',
|
|
1749
|
+
height: '20px',
|
|
1750
|
+
backgroundColor: '#e5e7eb',
|
|
1751
|
+
margin: '0 4px'
|
|
1752
|
+
}
|
|
1753
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
1754
|
+
type: "button",
|
|
1755
|
+
title: "Align Left",
|
|
1756
|
+
className: "rte-toolbar-button ".concat(activeAlign === "left" ? "active" : ""),
|
|
1757
|
+
onMouseDown: function onMouseDown(e) {
|
|
1758
|
+
e.preventDefault();
|
|
1759
|
+
exec("justifyLeft");
|
|
1760
|
+
setActiveAlign("left");
|
|
1761
|
+
}
|
|
1762
|
+
}, /*#__PURE__*/React.createElement(FaAlignLeft, {
|
|
1763
|
+
size: 14
|
|
1764
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
1765
|
+
type: "button",
|
|
1766
|
+
title: "Align Center",
|
|
1767
|
+
className: "rte-toolbar-button ".concat(activeAlign === "center" ? "active" : ""),
|
|
1768
|
+
onMouseDown: function onMouseDown(e) {
|
|
1769
|
+
e.preventDefault();
|
|
1770
|
+
exec("justifyCenter");
|
|
1771
|
+
setActiveAlign("center");
|
|
1772
|
+
}
|
|
1773
|
+
}, /*#__PURE__*/React.createElement(FaAlignCenter, {
|
|
1774
|
+
size: 14
|
|
1775
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
1776
|
+
type: "button",
|
|
1777
|
+
title: "Align Right",
|
|
1778
|
+
className: "rte-toolbar-button ".concat(activeAlign === "right" ? "active" : ""),
|
|
1779
|
+
onMouseDown: function onMouseDown(e) {
|
|
1780
|
+
e.preventDefault();
|
|
1781
|
+
exec("justifyRight");
|
|
1782
|
+
setActiveAlign("right");
|
|
1783
|
+
}
|
|
1784
|
+
}, /*#__PURE__*/React.createElement(FaAlignRight, {
|
|
1785
|
+
size: 14
|
|
1786
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1787
|
+
style: {
|
|
1788
|
+
width: '1px',
|
|
1789
|
+
height: '20px',
|
|
1790
|
+
backgroundColor: '#e5e7eb',
|
|
1791
|
+
margin: '0 4px'
|
|
1792
|
+
}
|
|
1793
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
1794
|
+
type: "button",
|
|
1795
|
+
title: "Unordered List",
|
|
1796
|
+
onMouseDown: function onMouseDown(e) {
|
|
1797
|
+
e.preventDefault();
|
|
1798
|
+
handleSelect("unordered");
|
|
1799
|
+
},
|
|
1800
|
+
className: "rte-toolbar-button ".concat(currentListType === "unordered" ? "active" : "")
|
|
1801
|
+
}, /*#__PURE__*/React.createElement(FaListUl, {
|
|
1802
|
+
size: 14
|
|
1803
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
1804
|
+
type: "button",
|
|
1805
|
+
title: "Ordered List",
|
|
1806
|
+
onMouseDown: function onMouseDown(e) {
|
|
1807
|
+
e.preventDefault();
|
|
1808
|
+
handleSelect("ordered");
|
|
1809
|
+
},
|
|
1810
|
+
className: "rte-toolbar-button ".concat(currentListType === "ordered" ? "active" : "")
|
|
1811
|
+
}, /*#__PURE__*/React.createElement(FaListOl, {
|
|
1812
|
+
size: 14
|
|
1813
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1814
|
+
style: {
|
|
1815
|
+
position: 'relative',
|
|
1816
|
+
display: 'flex',
|
|
1817
|
+
alignItems: 'center'
|
|
1818
|
+
}
|
|
1819
|
+
}, /*#__PURE__*/React.createElement("select", {
|
|
1820
|
+
value: currentLineHeight,
|
|
1821
|
+
onMouseDown: function onMouseDown(e) {
|
|
1822
|
+
return e.stopPropagation();
|
|
1823
|
+
},
|
|
1824
|
+
onChange: function onChange(e) {
|
|
1825
|
+
e.preventDefault();
|
|
1826
|
+
var height = e.target.value;
|
|
1827
|
+
if (height) {
|
|
1828
|
+
onLineHeightChange(height);
|
|
1829
|
+
setCurrentLineHeight(height);
|
|
1830
|
+
}
|
|
1831
|
+
focus();
|
|
1832
|
+
},
|
|
1833
|
+
className: "rte-toolbar-select",
|
|
1834
|
+
style: {
|
|
1835
|
+
width: '64px',
|
|
1836
|
+
paddingLeft: '24px'
|
|
1837
|
+
}
|
|
1838
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
1839
|
+
value: "",
|
|
1840
|
+
disabled: true
|
|
1841
|
+
}, "\u2195"), ['1', '1.15', '1.5', '2'].map(function (h) {
|
|
1842
|
+
return /*#__PURE__*/React.createElement("option", {
|
|
1843
|
+
key: h,
|
|
1844
|
+
value: h
|
|
1845
|
+
}, h);
|
|
1846
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1847
|
+
style: {
|
|
1848
|
+
position: 'absolute',
|
|
1849
|
+
left: '6px',
|
|
1850
|
+
pointerEvents: 'none',
|
|
1851
|
+
color: '#9ca3af'
|
|
1852
|
+
}
|
|
1853
|
+
}, /*#__PURE__*/React.createElement(FaTextHeight, {
|
|
1854
|
+
size: 12
|
|
1855
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
1856
|
+
style: {
|
|
1857
|
+
width: '1px',
|
|
1858
|
+
height: '20px',
|
|
1859
|
+
backgroundColor: '#e5e7eb',
|
|
1860
|
+
margin: '0 4px'
|
|
1861
|
+
}
|
|
1862
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
1863
|
+
type: "button",
|
|
1864
|
+
title: "Add Link",
|
|
1865
|
+
className: "rte-toolbar-button",
|
|
1866
|
+
onMouseDown: function onMouseDown(e) {
|
|
1867
|
+
e.preventDefault();
|
|
1868
|
+
addLink();
|
|
1869
|
+
}
|
|
1870
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
1871
|
+
style: {
|
|
1872
|
+
fontSize: '16px'
|
|
1873
|
+
}
|
|
1874
|
+
}, "\uD83D\uDD17")), /*#__PURE__*/React.createElement("input", {
|
|
1875
|
+
ref: fileInputRef,
|
|
1876
|
+
type: "file",
|
|
1877
|
+
accept: "image/*",
|
|
1878
|
+
style: {
|
|
1879
|
+
display: "none"
|
|
1880
|
+
},
|
|
1881
|
+
onChange: handleImageUpload,
|
|
1882
|
+
disabled: isUploading
|
|
1883
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
1884
|
+
type: "button",
|
|
1885
|
+
className: "rte-toolbar-button",
|
|
1886
|
+
onMouseDown: function onMouseDown(e) {
|
|
1887
|
+
var _fileInputRef$current;
|
|
1888
|
+
e.preventDefault();
|
|
1889
|
+
if (!isUploading) (_fileInputRef$current = fileInputRef.current) === null || _fileInputRef$current === void 0 || _fileInputRef$current.click();
|
|
1890
|
+
},
|
|
1891
|
+
disabled: isUploading,
|
|
1892
|
+
title: "Upload image"
|
|
1893
|
+
}, isUploading ? /*#__PURE__*/React.createElement("div", {
|
|
1894
|
+
className: "rte-spinner",
|
|
1895
|
+
style: {
|
|
1896
|
+
width: '14px',
|
|
1897
|
+
height: '14px',
|
|
1898
|
+
borderWidth: '2px'
|
|
1899
|
+
}
|
|
1900
|
+
}) : /*#__PURE__*/React.createElement(FaImage, {
|
|
1901
|
+
size: 14
|
|
1902
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
1903
|
+
ref: editorRef,
|
|
1904
|
+
contentEditable: editable && disabled !== true,
|
|
1905
|
+
suppressContentEditableWarning: true,
|
|
1906
|
+
onInput: handleInput,
|
|
1907
|
+
onPaste: handlePaste,
|
|
1908
|
+
onDrop: handleDrop,
|
|
1909
|
+
onDragStart: function onDragStart(e) {
|
|
1910
|
+
return e.preventDefault();
|
|
1911
|
+
},
|
|
1912
|
+
onDragOver: function onDragOver(e) {
|
|
1913
|
+
return e.preventDefault();
|
|
1914
|
+
},
|
|
1915
|
+
onKeyDown: handleKeyDown,
|
|
1916
|
+
onClick: handleEditorClick,
|
|
1917
|
+
style: {
|
|
1918
|
+
minHeight: minHeight || '150px',
|
|
1919
|
+
maxHeight: maxHeight || '500px',
|
|
1920
|
+
paddingLeft: paddingLeft || '12px'
|
|
1921
|
+
},
|
|
1922
|
+
className: "rte-content"
|
|
1923
|
+
}), linkModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
1924
|
+
className: "rte-modal-overlay",
|
|
1925
|
+
onClick: cancelLink
|
|
1926
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1927
|
+
className: "rte-modal",
|
|
1928
|
+
onClick: function onClick(e) {
|
|
1929
|
+
return e.stopPropagation();
|
|
1930
|
+
}
|
|
1931
|
+
}, /*#__PURE__*/React.createElement("h3", {
|
|
1932
|
+
className: "rte-modal-title"
|
|
1933
|
+
}, "Insert Link"), /*#__PURE__*/React.createElement("div", {
|
|
1934
|
+
className: "rte-form-group"
|
|
1935
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
1936
|
+
className: "rte-label"
|
|
1937
|
+
}, "URL"), /*#__PURE__*/React.createElement("input", {
|
|
1938
|
+
type: "url",
|
|
1939
|
+
className: "rte-input",
|
|
1940
|
+
value: linkUrl,
|
|
1941
|
+
onChange: function onChange(e) {
|
|
1942
|
+
return setLinkUrl(e.target.value);
|
|
1943
|
+
},
|
|
1944
|
+
autoFocus: true,
|
|
1945
|
+
placeholder: "https://example.com"
|
|
1946
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1947
|
+
className: "rte-form-group"
|
|
1948
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
1949
|
+
className: "rte-label"
|
|
1950
|
+
}, "Display Text"), /*#__PURE__*/React.createElement("input", {
|
|
1951
|
+
type: "text",
|
|
1952
|
+
className: "rte-input",
|
|
1953
|
+
value: linkText,
|
|
1954
|
+
onChange: function onChange(e) {
|
|
1955
|
+
return setLinkText(e.target.value);
|
|
1956
|
+
},
|
|
1957
|
+
placeholder: "Link text"
|
|
1958
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1959
|
+
className: "rte-modal-actions"
|
|
1960
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
1961
|
+
type: "button",
|
|
1962
|
+
className: "rte-button rte-button-secondary",
|
|
1963
|
+
onClick: cancelLink
|
|
1964
|
+
}, "Cancel"), /*#__PURE__*/React.createElement("button", {
|
|
1965
|
+
type: "button",
|
|
1966
|
+
className: "rte-button rte-button-primary",
|
|
1967
|
+
onClick: confirmLink,
|
|
1968
|
+
disabled: !linkUrl
|
|
1969
|
+
}, "Insert")))), imageModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
1970
|
+
className: "rte-modal-overlay",
|
|
1971
|
+
onClick: closeImageModal
|
|
1972
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1973
|
+
style: {
|
|
1974
|
+
position: "relative",
|
|
1975
|
+
maxWidth: "90%",
|
|
1976
|
+
maxHeight: "90%"
|
|
1977
|
+
},
|
|
1978
|
+
onClick: function onClick(e) {
|
|
1979
|
+
return e.stopPropagation();
|
|
1980
|
+
}
|
|
1981
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
1982
|
+
src: selectedImageUrl,
|
|
1983
|
+
style: {
|
|
1984
|
+
width: "100%",
|
|
1985
|
+
maxHeight: "90vh",
|
|
1986
|
+
borderRadius: '12px',
|
|
1987
|
+
transform: "scale(".concat(zoomLevel, ")"),
|
|
1988
|
+
transition: "transform 0.2s ease",
|
|
1989
|
+
boxShadow: '0 25px 50px -12px rgba(0,0,0,0.5)'
|
|
1990
|
+
},
|
|
1991
|
+
alt: "Zoomed"
|
|
1992
|
+
})))), showEditButton && editable && /*#__PURE__*/React.createElement("div", {
|
|
1993
|
+
style: {
|
|
1994
|
+
display: "flex",
|
|
1995
|
+
justifyContent: "flex-end",
|
|
1996
|
+
gap: "12px",
|
|
1997
|
+
marginTop: "12px"
|
|
1998
|
+
}
|
|
1999
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
2000
|
+
type: "button",
|
|
2001
|
+
className: "rte-button rte-button-secondary",
|
|
2002
|
+
onClick: function onClick() {
|
|
2003
|
+
return setEditable(false);
|
|
2004
|
+
}
|
|
2005
|
+
}, "Cancel"), /*#__PURE__*/React.createElement("button", {
|
|
2006
|
+
type: "button",
|
|
2007
|
+
className: "rte-button rte-button-primary",
|
|
2008
|
+
onClick: function onClick() {
|
|
2009
|
+
handleChange && handleChange();
|
|
2010
|
+
setEditable(false);
|
|
2011
|
+
}
|
|
2012
|
+
}, "Save Changes")));
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
exports.RichTextEditor = RichTextEditor;
|
|
2016
|
+
//# sourceMappingURL=index.cjs.js.map
|