@editora/react 1.0.1 → 1.0.2
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/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +381 -336
- package/package.json +4 -4
- package/dist/react.css +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { jsx as l, jsxs as
|
|
2
|
-
import ee, { useRef as E, useState as
|
|
3
|
-
import { KeyboardShortcutManager as _, PluginManager as te, Editor as ne } from "@editora/core";
|
|
4
|
-
const
|
|
1
|
+
import { jsx as l, jsxs as R, Fragment as B } from "react/jsx-runtime";
|
|
2
|
+
import ee, { useRef as E, useState as N, useEffect as A, useMemo as j } from "react";
|
|
3
|
+
import { KeyboardShortcutManager as _, PluginManager as te, Editor as ne, StatusBar as oe, calculateTextStats as re, countLines as ae, getCursorPosition as le, getSelectionInfo as ie } from "@editora/core";
|
|
4
|
+
const ce = ({
|
|
5
5
|
isOpen: e,
|
|
6
6
|
options: t,
|
|
7
|
-
onSelect:
|
|
8
|
-
onClose:
|
|
7
|
+
onSelect: m,
|
|
8
|
+
onClose: s,
|
|
9
9
|
anchorRef: i,
|
|
10
10
|
className: r = ""
|
|
11
11
|
}) => {
|
|
12
|
-
const
|
|
13
|
-
return
|
|
12
|
+
const g = E(null), [d, h] = N({ top: 0, left: 0 });
|
|
13
|
+
return A(() => {
|
|
14
14
|
if (e && i.current) {
|
|
15
|
-
const o = i.current.getBoundingClientRect(),
|
|
16
|
-
let
|
|
17
|
-
const
|
|
18
|
-
|
|
15
|
+
const o = i.current.getBoundingClientRect(), u = 120, v = t.length * 36;
|
|
16
|
+
let C = o.bottom + 4, c = o.left;
|
|
17
|
+
const f = window.innerWidth, b = window.innerHeight;
|
|
18
|
+
c + u > f && (c = f - u - 8), C + v > b && (C = o.top - v - 4), h({ top: C, left: c });
|
|
19
19
|
}
|
|
20
|
-
}, [e, i, t.length]),
|
|
21
|
-
if (e && i.current &&
|
|
22
|
-
const o = i.current.getBoundingClientRect(),
|
|
23
|
-
let
|
|
24
|
-
const
|
|
25
|
-
|
|
20
|
+
}, [e, i, t.length]), A(() => {
|
|
21
|
+
if (e && i.current && g.current) {
|
|
22
|
+
const o = i.current.getBoundingClientRect(), u = g.current.getBoundingClientRect();
|
|
23
|
+
let v = o.bottom + 4, C = o.left;
|
|
24
|
+
const c = window.innerWidth, f = window.innerHeight;
|
|
25
|
+
C + u.width > c && (C = c - u.width - 8), v + u.height > f && (v = o.top - u.height - 4), h({ top: v, left: C });
|
|
26
26
|
}
|
|
27
|
-
}, [e]),
|
|
28
|
-
const o = (
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
|
|
27
|
+
}, [e]), A(() => {
|
|
28
|
+
const o = (v) => {
|
|
29
|
+
g.current && !g.current.contains(v.target) && i.current && !i.current.contains(v.target) && s();
|
|
30
|
+
}, u = (v) => {
|
|
31
|
+
v.key === "Escape" && s();
|
|
32
32
|
};
|
|
33
|
-
return e && (document.addEventListener("mousedown", o), document.addEventListener("keydown",
|
|
34
|
-
document.removeEventListener("mousedown", o), document.removeEventListener("keydown",
|
|
33
|
+
return e && (document.addEventListener("mousedown", o), document.addEventListener("keydown", u)), () => {
|
|
34
|
+
document.removeEventListener("mousedown", o), document.removeEventListener("keydown", u);
|
|
35
35
|
};
|
|
36
|
-
}, [e,
|
|
36
|
+
}, [e, s, i]), e ? /* @__PURE__ */ l(
|
|
37
37
|
"div",
|
|
38
38
|
{
|
|
39
|
-
ref:
|
|
39
|
+
ref: g,
|
|
40
40
|
className: `rte-inline-menu ${r}`,
|
|
41
41
|
style: {
|
|
42
42
|
position: "fixed",
|
|
43
|
-
top:
|
|
44
|
-
left:
|
|
43
|
+
top: d.top,
|
|
44
|
+
left: d.left,
|
|
45
45
|
zIndex: 1e3,
|
|
46
46
|
background: "white",
|
|
47
47
|
border: "1px solid #ccc",
|
|
@@ -56,7 +56,7 @@ const oe = ({
|
|
|
56
56
|
{
|
|
57
57
|
className: "rte-inline-menu-item",
|
|
58
58
|
onClick: () => {
|
|
59
|
-
|
|
59
|
+
m(o.value), s();
|
|
60
60
|
},
|
|
61
61
|
style: {
|
|
62
62
|
padding: "8px 12px",
|
|
@@ -67,11 +67,11 @@ const oe = ({
|
|
|
67
67
|
overflow: "hidden",
|
|
68
68
|
textOverflow: "ellipsis"
|
|
69
69
|
},
|
|
70
|
-
onMouseEnter: (
|
|
71
|
-
|
|
70
|
+
onMouseEnter: (u) => {
|
|
71
|
+
u.currentTarget.style.backgroundColor = "#f5f5f5";
|
|
72
72
|
},
|
|
73
|
-
onMouseLeave: (
|
|
74
|
-
|
|
73
|
+
onMouseLeave: (u) => {
|
|
74
|
+
u.currentTarget.style.backgroundColor = "transparent";
|
|
75
75
|
},
|
|
76
76
|
children: o.label
|
|
77
77
|
},
|
|
@@ -82,16 +82,16 @@ const oe = ({
|
|
|
82
82
|
}, V = ({
|
|
83
83
|
editor: e,
|
|
84
84
|
position: t = "top",
|
|
85
|
-
sticky:
|
|
86
|
-
floating:
|
|
85
|
+
sticky: m = !1,
|
|
86
|
+
floating: s = !1
|
|
87
87
|
}) => {
|
|
88
|
-
const [i, r] =
|
|
89
|
-
|
|
88
|
+
const [i, r] = N(null), [g, d] = N(null), [h, o] = N(null), [u, v] = N(null), [C, c] = N(!1), f = E({}), b = E(null), p = E(null), y = E(null), w = e.pluginManager.getToolbarItems();
|
|
89
|
+
A(() => {
|
|
90
90
|
const n = () => {
|
|
91
|
-
if (!
|
|
92
|
-
const W =
|
|
91
|
+
if (!b.current || !p.current) return;
|
|
92
|
+
const W = b.current.clientWidth, H = 16, Y = 40, U = 4, Z = W - H - Y - U;
|
|
93
93
|
let q = 0, P = 0;
|
|
94
|
-
const $ =
|
|
94
|
+
const $ = p.current.children;
|
|
95
95
|
for (let z = 0; z < $.length; z++) {
|
|
96
96
|
const K = $[z].offsetWidth + U;
|
|
97
97
|
if (q + K <= Z)
|
|
@@ -99,49 +99,49 @@ const oe = ({
|
|
|
99
99
|
else
|
|
100
100
|
break;
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
v(Math.max(1, P));
|
|
103
103
|
}, a = requestAnimationFrame(() => {
|
|
104
104
|
n();
|
|
105
|
-
}),
|
|
105
|
+
}), k = new ResizeObserver(() => {
|
|
106
106
|
n();
|
|
107
107
|
});
|
|
108
|
-
|
|
109
|
-
const
|
|
108
|
+
b.current && k.observe(b.current);
|
|
109
|
+
const M = new MutationObserver(() => {
|
|
110
110
|
n();
|
|
111
111
|
});
|
|
112
|
-
return
|
|
112
|
+
return p.current && M.observe(p.current, {
|
|
113
113
|
childList: !0,
|
|
114
114
|
subtree: !0
|
|
115
115
|
}), () => {
|
|
116
|
-
cancelAnimationFrame(a),
|
|
116
|
+
cancelAnimationFrame(a), k.disconnect(), M.disconnect();
|
|
117
117
|
};
|
|
118
118
|
}, [w.length]);
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
119
|
+
const S = (n) => (f.current[n] || (f.current[n] = ee.createRef()), f.current[n]), x = (n, a) => {
|
|
120
|
+
const k = b.current?.closest("[data-editora-editor]"), M = k?.querySelector(".rte-content");
|
|
121
|
+
if (M && M.focus(), h && (n === "setTextAlignment" || n === "setFontFamily" || n === "setBlockType")) {
|
|
122
122
|
const H = window.getSelection();
|
|
123
|
-
H && (H.removeAllRanges(), H.addRange(
|
|
123
|
+
H && (H.removeAllRanges(), H.addRange(h)), o(null);
|
|
124
124
|
}
|
|
125
125
|
typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(n, a), r(null);
|
|
126
|
-
const W =
|
|
126
|
+
const W = k?.querySelector(".rte-content");
|
|
127
127
|
W && W.focus();
|
|
128
|
-
},
|
|
128
|
+
}, T = (n) => {
|
|
129
129
|
const a = window.getSelection();
|
|
130
130
|
a && a.rangeCount > 0 && o(a.getRangeAt(0).cloneRange()), r(i === n ? null : n);
|
|
131
|
-
},
|
|
131
|
+
}, L = (n) => {
|
|
132
132
|
const a = window.getSelection();
|
|
133
|
-
a && a.rangeCount > 0 && o(a.getRangeAt(0).cloneRange()),
|
|
133
|
+
a && a.rangeCount > 0 && o(a.getRangeAt(0).cloneRange()), d(g === n ? null : n), r(null);
|
|
134
134
|
}, I = (n, a) => {
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
137
|
-
|
|
135
|
+
if (h) {
|
|
136
|
+
const k = window.getSelection();
|
|
137
|
+
k && (k.removeAllRanges(), k.addRange(h)), o(null);
|
|
138
138
|
}
|
|
139
|
-
|
|
139
|
+
x(n, a), d(null);
|
|
140
140
|
}, D = (n, a) => n && n.startsWith("<svg") && n.endsWith("</svg>") ? /* @__PURE__ */ l("span", { dangerouslySetInnerHTML: { __html: n } }) : n && n.length === 1 && /^[BIUSH]$/.test(n) ? /* @__PURE__ */ l("span", { style: { fontWeight: "bold", fontSize: "14px", lineHeight: "1" }, children: n }) : n || "⚪";
|
|
141
|
-
if (
|
|
141
|
+
if (s)
|
|
142
142
|
return null;
|
|
143
143
|
const Q = {
|
|
144
|
-
...
|
|
144
|
+
...m && {
|
|
145
145
|
position: "sticky",
|
|
146
146
|
top: 0,
|
|
147
147
|
zIndex: 100,
|
|
@@ -152,44 +152,44 @@ const oe = ({
|
|
|
152
152
|
order: 2
|
|
153
153
|
// Move to bottom in flex container
|
|
154
154
|
}
|
|
155
|
-
}, O = (n) => n.map((a,
|
|
155
|
+
}, O = (n) => n.map((a, k) => /* @__PURE__ */ l(
|
|
156
156
|
"div",
|
|
157
157
|
{
|
|
158
158
|
className: "rte-toolbar-item",
|
|
159
159
|
style: {
|
|
160
|
-
display:
|
|
160
|
+
display: u !== null && k >= u ? "none" : "flex"
|
|
161
161
|
},
|
|
162
|
-
children: a.type === "dropdown" ? /* @__PURE__ */
|
|
163
|
-
/* @__PURE__ */
|
|
162
|
+
children: a.type === "dropdown" ? /* @__PURE__ */ R("div", { className: "rte-toolbar-dropdown", children: [
|
|
163
|
+
/* @__PURE__ */ R(
|
|
164
164
|
"button",
|
|
165
165
|
{
|
|
166
166
|
className: "rte-toolbar-button",
|
|
167
167
|
"data-command": a.command,
|
|
168
168
|
"data-active": "false",
|
|
169
|
-
onClick: () =>
|
|
169
|
+
onClick: () => T(a.command),
|
|
170
170
|
children: [
|
|
171
171
|
a.label,
|
|
172
172
|
" ▼"
|
|
173
173
|
]
|
|
174
174
|
}
|
|
175
175
|
),
|
|
176
|
-
i === a.command && /* @__PURE__ */ l("div", { className: "rte-toolbar-dropdown-menu", children: a.options?.map((
|
|
176
|
+
i === a.command && /* @__PURE__ */ l("div", { className: "rte-toolbar-dropdown-menu", children: a.options?.map((M) => /* @__PURE__ */ l(
|
|
177
177
|
"div",
|
|
178
178
|
{
|
|
179
179
|
className: "rte-toolbar-dropdown-item",
|
|
180
|
-
onClick: () =>
|
|
181
|
-
children:
|
|
180
|
+
onClick: () => x(a.command, M.value),
|
|
181
|
+
children: M.label
|
|
182
182
|
},
|
|
183
|
-
|
|
183
|
+
M.value
|
|
184
184
|
)) })
|
|
185
185
|
] }) : a.type === "inline-menu" ? /* @__PURE__ */ l(
|
|
186
186
|
"button",
|
|
187
187
|
{
|
|
188
|
-
ref:
|
|
188
|
+
ref: S(a.command),
|
|
189
189
|
className: "rte-toolbar-button",
|
|
190
190
|
"data-command": a.command,
|
|
191
191
|
"data-active": "false",
|
|
192
|
-
onClick: () =>
|
|
192
|
+
onClick: () => L(a.command),
|
|
193
193
|
title: a.label,
|
|
194
194
|
children: D(a.icon, a.command)
|
|
195
195
|
}
|
|
@@ -199,11 +199,11 @@ const oe = ({
|
|
|
199
199
|
type: "text",
|
|
200
200
|
className: `rte-toolbar-input ${a.label.toLowerCase().replace(/\s+/g, "-")}`,
|
|
201
201
|
placeholder: a.placeholder,
|
|
202
|
-
onChange: (
|
|
203
|
-
onKeyDown: (
|
|
204
|
-
|
|
202
|
+
onChange: (M) => x(a.command, M.target.value),
|
|
203
|
+
onKeyDown: (M) => {
|
|
204
|
+
M.key === "Enter" && x(
|
|
205
205
|
a.command,
|
|
206
|
-
|
|
206
|
+
M.target.value
|
|
207
207
|
);
|
|
208
208
|
},
|
|
209
209
|
title: a.label
|
|
@@ -227,66 +227,66 @@ const oe = ({
|
|
|
227
227
|
className: "rte-toolbar-button",
|
|
228
228
|
"data-command": a.command,
|
|
229
229
|
"data-active": "false",
|
|
230
|
-
onClick: () =>
|
|
230
|
+
onClick: () => x(a.command),
|
|
231
231
|
title: a.label,
|
|
232
232
|
children: D(a.icon, a.command)
|
|
233
233
|
}
|
|
234
234
|
)
|
|
235
235
|
},
|
|
236
|
-
|
|
236
|
+
k
|
|
237
237
|
));
|
|
238
|
-
return /* @__PURE__ */
|
|
239
|
-
/* @__PURE__ */
|
|
240
|
-
/* @__PURE__ */
|
|
241
|
-
/* @__PURE__ */ l("div", { className: "rte-toolbar-items-container", ref:
|
|
242
|
-
|
|
238
|
+
return /* @__PURE__ */ R(B, { children: [
|
|
239
|
+
/* @__PURE__ */ R("div", { className: "rte-toolbar-wrapper", style: Q, children: [
|
|
240
|
+
/* @__PURE__ */ R("div", { className: "rte-toolbar", ref: b, children: [
|
|
241
|
+
/* @__PURE__ */ l("div", { className: "rte-toolbar-items-container", ref: p, children: O(w) }),
|
|
242
|
+
u !== null && u < w.length && /* @__PURE__ */ l(
|
|
243
243
|
"button",
|
|
244
244
|
{
|
|
245
|
-
ref:
|
|
246
|
-
className: `rte-toolbar-more-button ${
|
|
247
|
-
onClick: () =>
|
|
245
|
+
ref: y,
|
|
246
|
+
className: `rte-toolbar-more-button ${C ? "active" : ""}`,
|
|
247
|
+
onClick: () => c(!C),
|
|
248
248
|
title: "Show more options",
|
|
249
249
|
"aria-label": "More toolbar options",
|
|
250
250
|
children: "☰"
|
|
251
251
|
}
|
|
252
252
|
)
|
|
253
253
|
] }),
|
|
254
|
-
|
|
254
|
+
u !== null && u < w.length && /* @__PURE__ */ l(
|
|
255
255
|
"div",
|
|
256
256
|
{
|
|
257
|
-
className: `rte-toolbar-expanded-row ${
|
|
257
|
+
className: `rte-toolbar-expanded-row ${C ? "show" : ""}`,
|
|
258
258
|
children: w.map(
|
|
259
|
-
(n, a) => a >= (
|
|
260
|
-
/* @__PURE__ */
|
|
259
|
+
(n, a) => a >= (u || 0) && /* @__PURE__ */ l("div", { className: "rte-toolbar-item", children: n.type === "dropdown" ? /* @__PURE__ */ R("div", { className: "rte-toolbar-dropdown", children: [
|
|
260
|
+
/* @__PURE__ */ R(
|
|
261
261
|
"button",
|
|
262
262
|
{
|
|
263
263
|
className: "rte-toolbar-button",
|
|
264
264
|
"data-command": n.command,
|
|
265
265
|
"data-active": "false",
|
|
266
|
-
onClick: () =>
|
|
266
|
+
onClick: () => T(n.command),
|
|
267
267
|
children: [
|
|
268
268
|
n.label,
|
|
269
269
|
" ▼"
|
|
270
270
|
]
|
|
271
271
|
}
|
|
272
272
|
),
|
|
273
|
-
i === n.command && /* @__PURE__ */ l("div", { className: "rte-toolbar-dropdown-menu", children: n.options?.map((
|
|
273
|
+
i === n.command && /* @__PURE__ */ l("div", { className: "rte-toolbar-dropdown-menu", children: n.options?.map((k) => /* @__PURE__ */ l(
|
|
274
274
|
"div",
|
|
275
275
|
{
|
|
276
276
|
className: "rte-toolbar-dropdown-item",
|
|
277
|
-
onClick: () =>
|
|
278
|
-
children:
|
|
277
|
+
onClick: () => x(n.command, k.value),
|
|
278
|
+
children: k.label
|
|
279
279
|
},
|
|
280
|
-
|
|
280
|
+
k.value
|
|
281
281
|
)) })
|
|
282
282
|
] }) : n.type === "inline-menu" ? /* @__PURE__ */ l(
|
|
283
283
|
"button",
|
|
284
284
|
{
|
|
285
|
-
ref:
|
|
285
|
+
ref: S(n.command),
|
|
286
286
|
className: "rte-toolbar-button",
|
|
287
287
|
"data-command": n.command,
|
|
288
288
|
"data-active": "false",
|
|
289
|
-
onClick: () =>
|
|
289
|
+
onClick: () => L(n.command),
|
|
290
290
|
title: n.label,
|
|
291
291
|
children: D(n.icon, n.command)
|
|
292
292
|
}
|
|
@@ -296,11 +296,11 @@ const oe = ({
|
|
|
296
296
|
type: "text",
|
|
297
297
|
className: "rte-toolbar-input",
|
|
298
298
|
placeholder: n.placeholder,
|
|
299
|
-
onChange: (
|
|
300
|
-
onKeyDown: (
|
|
301
|
-
|
|
299
|
+
onChange: (k) => x(n.command, k.target.value),
|
|
300
|
+
onKeyDown: (k) => {
|
|
301
|
+
k.key === "Enter" && x(
|
|
302
302
|
n.command,
|
|
303
|
-
|
|
303
|
+
k.target.value
|
|
304
304
|
);
|
|
305
305
|
},
|
|
306
306
|
title: n.label
|
|
@@ -311,7 +311,7 @@ const oe = ({
|
|
|
311
311
|
className: "rte-toolbar-button",
|
|
312
312
|
"data-command": n.command,
|
|
313
313
|
"data-active": "false",
|
|
314
|
-
onClick: () =>
|
|
314
|
+
onClick: () => x(n.command),
|
|
315
315
|
title: n.label,
|
|
316
316
|
children: D(n.icon, n.command)
|
|
317
317
|
}
|
|
@@ -321,32 +321,32 @@ const oe = ({
|
|
|
321
321
|
)
|
|
322
322
|
] }),
|
|
323
323
|
w.map((n) => n.type === "inline-menu" ? /* @__PURE__ */ l(
|
|
324
|
-
|
|
324
|
+
ce,
|
|
325
325
|
{
|
|
326
|
-
isOpen:
|
|
326
|
+
isOpen: g === n.command,
|
|
327
327
|
options: n.options || [],
|
|
328
328
|
onSelect: (a) => I(n.command, a),
|
|
329
|
-
onClose: () =>
|
|
330
|
-
anchorRef:
|
|
329
|
+
onClose: () => d(null),
|
|
330
|
+
anchorRef: S(n.command)
|
|
331
331
|
},
|
|
332
332
|
`menu-${n.command}`
|
|
333
333
|
) : null)
|
|
334
334
|
] });
|
|
335
335
|
};
|
|
336
|
-
function
|
|
337
|
-
const
|
|
338
|
-
return
|
|
336
|
+
function se(e, t) {
|
|
337
|
+
const m = E(), s = E("");
|
|
338
|
+
return A(() => {
|
|
339
339
|
if (!t?.enabled) return;
|
|
340
|
-
const r = t.intervalMs || 3e4,
|
|
340
|
+
const r = t.intervalMs || 3e4, g = t.storageKey || "rte-autosave", d = t.provider || "localStorage", h = async () => {
|
|
341
341
|
const o = e();
|
|
342
|
-
if (o !==
|
|
343
|
-
if (
|
|
342
|
+
if (o !== s.current) {
|
|
343
|
+
if (s.current = o, d === "localStorage")
|
|
344
344
|
try {
|
|
345
|
-
localStorage.setItem(
|
|
346
|
-
} catch (
|
|
347
|
-
console.error("[Autosave] Failed to save to localStorage:",
|
|
345
|
+
localStorage.setItem(g, o), localStorage.setItem(`${g}-timestamp`, Date.now().toString()), console.log("[Autosave] Content saved to localStorage");
|
|
346
|
+
} catch (u) {
|
|
347
|
+
console.error("[Autosave] Failed to save to localStorage:", u);
|
|
348
348
|
}
|
|
349
|
-
else if (
|
|
349
|
+
else if (d === "api" && t.apiUrl)
|
|
350
350
|
try {
|
|
351
351
|
await fetch(t.apiUrl, {
|
|
352
352
|
method: "POST",
|
|
@@ -355,29 +355,29 @@ function re(e, t) {
|
|
|
355
355
|
},
|
|
356
356
|
body: JSON.stringify({ content: o, timestamp: Date.now() })
|
|
357
357
|
}), console.log("[Autosave] Content saved to API");
|
|
358
|
-
} catch (
|
|
359
|
-
console.error("[Autosave] Failed to save to API:",
|
|
358
|
+
} catch (u) {
|
|
359
|
+
console.error("[Autosave] Failed to save to API:", u);
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
};
|
|
363
|
-
return
|
|
364
|
-
|
|
363
|
+
return m.current = setInterval(h, r), () => {
|
|
364
|
+
m.current && clearInterval(m.current);
|
|
365
365
|
};
|
|
366
366
|
}, [t?.enabled, t?.intervalMs, t?.storageKey, t?.provider, t?.apiUrl, e]), { restore: () => {
|
|
367
367
|
if (!t?.enabled) return null;
|
|
368
368
|
const r = t.storageKey || "rte-autosave";
|
|
369
369
|
if ((t.provider || "localStorage") === "localStorage")
|
|
370
370
|
try {
|
|
371
|
-
const
|
|
372
|
-
if (
|
|
373
|
-
return console.log("[Autosave] Restored from localStorage, saved at:", new Date(parseInt(
|
|
374
|
-
} catch (
|
|
375
|
-
console.error("[Autosave] Failed to restore from localStorage:",
|
|
371
|
+
const d = localStorage.getItem(r), h = localStorage.getItem(`${r}-timestamp`);
|
|
372
|
+
if (d && h)
|
|
373
|
+
return console.log("[Autosave] Restored from localStorage, saved at:", new Date(parseInt(h))), d;
|
|
374
|
+
} catch (d) {
|
|
375
|
+
console.error("[Autosave] Failed to restore from localStorage:", d);
|
|
376
376
|
}
|
|
377
377
|
return null;
|
|
378
378
|
} };
|
|
379
379
|
}
|
|
380
|
-
const
|
|
380
|
+
const de = [
|
|
381
381
|
"p",
|
|
382
382
|
"br",
|
|
383
383
|
"strong",
|
|
@@ -413,7 +413,7 @@ const ae = [
|
|
|
413
413
|
"sup",
|
|
414
414
|
"sub",
|
|
415
415
|
"hr"
|
|
416
|
-
],
|
|
416
|
+
], ue = {
|
|
417
417
|
"*": ["class", "style", "id", "data-*"],
|
|
418
418
|
a: ["href", "target", "rel", "title"],
|
|
419
419
|
img: ["src", "alt", "width", "height", "loading"],
|
|
@@ -423,130 +423,130 @@ const ae = [
|
|
|
423
423
|
td: ["colspan", "rowspan", "align", "valign"],
|
|
424
424
|
th: ["colspan", "rowspan", "align", "valign"]
|
|
425
425
|
};
|
|
426
|
-
function G(e, t,
|
|
426
|
+
function G(e, t, m) {
|
|
427
427
|
if (t?.sanitize === !1)
|
|
428
428
|
return e;
|
|
429
|
-
const
|
|
430
|
-
return r.innerHTML = e, X(r,
|
|
429
|
+
const s = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : de, i = t?.allowedAttributes || ue, r = document.createElement("div");
|
|
430
|
+
return r.innerHTML = e, X(r, s, i), r.innerHTML;
|
|
431
431
|
}
|
|
432
|
-
function X(e, t,
|
|
433
|
-
const
|
|
434
|
-
for (const i of
|
|
432
|
+
function X(e, t, m) {
|
|
433
|
+
const s = Array.from(e.childNodes);
|
|
434
|
+
for (const i of s)
|
|
435
435
|
if (i.nodeType === Node.ELEMENT_NODE) {
|
|
436
|
-
const r = i,
|
|
437
|
-
if (!t.includes(
|
|
436
|
+
const r = i, g = r.tagName.toLowerCase();
|
|
437
|
+
if (!t.includes(g)) {
|
|
438
438
|
for (; r.firstChild; )
|
|
439
439
|
e.insertBefore(r.firstChild, r);
|
|
440
440
|
e.removeChild(r);
|
|
441
441
|
continue;
|
|
442
442
|
}
|
|
443
|
-
|
|
443
|
+
fe(r, m), X(r, t, m);
|
|
444
444
|
} else {
|
|
445
445
|
if (i.nodeType === Node.TEXT_NODE)
|
|
446
446
|
continue;
|
|
447
447
|
e.removeChild(i);
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
|
-
function
|
|
451
|
-
const
|
|
452
|
-
for (const
|
|
453
|
-
const
|
|
450
|
+
function fe(e, t) {
|
|
451
|
+
const m = e.tagName.toLowerCase(), s = Array.from(e.attributes), i = t[m] || [], r = t["*"] || [], g = [...i, ...r];
|
|
452
|
+
for (const d of s) {
|
|
453
|
+
const h = d.name.toLowerCase();
|
|
454
454
|
let o = !1;
|
|
455
|
-
|
|
456
|
-
for (const
|
|
457
|
-
if (
|
|
458
|
-
const
|
|
459
|
-
if (
|
|
455
|
+
g.includes(h) && (o = !0);
|
|
456
|
+
for (const u of g)
|
|
457
|
+
if (u.endsWith("*")) {
|
|
458
|
+
const v = u.slice(0, -1);
|
|
459
|
+
if (h.startsWith(v)) {
|
|
460
460
|
o = !0;
|
|
461
461
|
break;
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
|
-
(
|
|
465
|
-
|
|
464
|
+
(h.startsWith("on") || // Event handlers
|
|
465
|
+
h === "javascript:" || h === "href" && d.value.trim().toLowerCase().startsWith("javascript:") || h === "src" && d.value.trim().toLowerCase().startsWith("javascript:")) && (o = !1), o || e.removeAttribute(d.name);
|
|
466
466
|
}
|
|
467
467
|
e.hasAttribute("href") && (e.getAttribute("href") || "").trim().toLowerCase().startsWith("javascript:") && e.removeAttribute("href"), e.hasAttribute("src") && (e.getAttribute("src") || "").trim().toLowerCase().startsWith("javascript:") && e.removeAttribute("src");
|
|
468
468
|
}
|
|
469
|
-
function
|
|
470
|
-
return
|
|
469
|
+
function me(e, t, m) {
|
|
470
|
+
return m?.sanitizeOnPaste === !1 ? e : G(e, t);
|
|
471
471
|
}
|
|
472
|
-
function
|
|
473
|
-
return
|
|
472
|
+
function ge(e, t, m) {
|
|
473
|
+
return m?.sanitizeOnInput === !1 ? e : G(e, t);
|
|
474
474
|
}
|
|
475
|
-
const
|
|
475
|
+
const be = ({
|
|
476
476
|
editor: e,
|
|
477
477
|
defaultValue: t,
|
|
478
|
-
value:
|
|
479
|
-
onChange:
|
|
478
|
+
value: m,
|
|
479
|
+
onChange: s,
|
|
480
480
|
pasteConfig: i,
|
|
481
481
|
contentConfig: r,
|
|
482
|
-
securityConfig:
|
|
483
|
-
performanceConfig:
|
|
484
|
-
autosaveConfig:
|
|
482
|
+
securityConfig: g,
|
|
483
|
+
performanceConfig: d,
|
|
484
|
+
autosaveConfig: h
|
|
485
485
|
}) => {
|
|
486
|
-
const o = E(null),
|
|
486
|
+
const o = E(null), u = m !== void 0, v = E(), { restore: C } = se(
|
|
487
487
|
() => o.current?.innerHTML || "",
|
|
488
|
-
|
|
488
|
+
h
|
|
489
489
|
);
|
|
490
|
-
return
|
|
490
|
+
return A(() => {
|
|
491
491
|
if (!o.current) return;
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
}, []),
|
|
495
|
-
!o.current || !
|
|
496
|
-
}, [
|
|
492
|
+
const c = C(), f = c || m || t;
|
|
493
|
+
f && o.current.innerHTML !== f && (o.current.innerHTML = f, c && s && s(c));
|
|
494
|
+
}, []), A(() => {
|
|
495
|
+
!o.current || !u || m !== o.current.innerHTML && (o.current.innerHTML = m);
|
|
496
|
+
}, [m, u]), A(() => {
|
|
497
497
|
if (!o.current) return;
|
|
498
|
-
const
|
|
499
|
-
if (!o.current || !
|
|
500
|
-
let
|
|
501
|
-
if (
|
|
502
|
-
const w = window.getSelection(),
|
|
503
|
-
if (o.current.innerHTML =
|
|
498
|
+
const c = () => {
|
|
499
|
+
if (!o.current || !s) return;
|
|
500
|
+
let y = o.current.innerHTML;
|
|
501
|
+
if (g?.sanitizeOnInput !== !1 && r?.sanitize !== !1 && (y = ge(y, r, g), y !== o.current.innerHTML)) {
|
|
502
|
+
const w = window.getSelection(), S = w && w.rangeCount > 0 ? w.getRangeAt(0) : null;
|
|
503
|
+
if (o.current.innerHTML = y, S && w)
|
|
504
504
|
try {
|
|
505
|
-
w.removeAllRanges(), w.addRange(
|
|
505
|
+
w.removeAllRanges(), w.addRange(S);
|
|
506
506
|
} catch {
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
},
|
|
512
|
-
},
|
|
513
|
-
|
|
514
|
-
let w =
|
|
515
|
-
const
|
|
509
|
+
d?.debounceInputMs ? (v.current && clearTimeout(v.current), v.current = setTimeout(() => {
|
|
510
|
+
s(y);
|
|
511
|
+
}, d.debounceInputMs)) : s(y);
|
|
512
|
+
}, f = (y) => {
|
|
513
|
+
y.preventDefault();
|
|
514
|
+
let w = y.clipboardData?.getData("text/html");
|
|
515
|
+
const S = y.clipboardData?.getData("text/plain");
|
|
516
516
|
if (i?.clean || !i?.keepFormatting) {
|
|
517
|
-
|
|
517
|
+
S && document.execCommand("insertText", !1, S);
|
|
518
518
|
return;
|
|
519
519
|
}
|
|
520
520
|
if (w) {
|
|
521
|
-
|
|
522
|
-
const
|
|
523
|
-
if (
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
const
|
|
527
|
-
|
|
521
|
+
g?.sanitizeOnPaste !== !1 && r?.sanitize !== !1 && (w = me(w, r, g));
|
|
522
|
+
const x = window.getSelection();
|
|
523
|
+
if (x && x.rangeCount > 0) {
|
|
524
|
+
const T = x.getRangeAt(0);
|
|
525
|
+
T.deleteContents();
|
|
526
|
+
const L = document.createElement("div");
|
|
527
|
+
L.innerHTML = w;
|
|
528
528
|
const I = document.createDocumentFragment();
|
|
529
|
-
for (;
|
|
530
|
-
I.appendChild(
|
|
531
|
-
|
|
529
|
+
for (; L.firstChild; )
|
|
530
|
+
I.appendChild(L.firstChild);
|
|
531
|
+
T.insertNode(I), T.collapse(!1), x.removeAllRanges(), x.addRange(T);
|
|
532
532
|
}
|
|
533
|
-
} else
|
|
534
|
-
},
|
|
535
|
-
const w =
|
|
533
|
+
} else S && document.execCommand("insertText", !1, S);
|
|
534
|
+
}, b = (y) => {
|
|
535
|
+
const w = y.target;
|
|
536
536
|
(w.tagName === "IMG" || w.tagName === "VIDEO") && (w.style.resize = "both", w.style.overflow = "auto", w.style.display = "inline-block");
|
|
537
|
-
},
|
|
538
|
-
return
|
|
539
|
-
|
|
537
|
+
}, p = o.current;
|
|
538
|
+
return p.addEventListener("input", c), p.addEventListener("paste", f), p.addEventListener("click", b), p.focus(), () => {
|
|
539
|
+
v.current && clearTimeout(v.current), p.removeEventListener("input", c), p.removeEventListener("paste", f), p.removeEventListener("click", b);
|
|
540
540
|
};
|
|
541
|
-
}, [e,
|
|
541
|
+
}, [e, s, i, r, g, d]), A(() => {
|
|
542
542
|
if (!o.current || typeof window > "u") return;
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(
|
|
543
|
+
const c = new _(), f = o.current, b = (p) => {
|
|
544
|
+
c.handleKeyDown(p, (y, w) => {
|
|
545
|
+
typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(y, w);
|
|
546
546
|
});
|
|
547
547
|
};
|
|
548
|
-
return
|
|
549
|
-
|
|
548
|
+
return f.addEventListener("keydown", b), () => {
|
|
549
|
+
f.removeEventListener("keydown", b);
|
|
550
550
|
};
|
|
551
551
|
}, []), /* @__PURE__ */ l(
|
|
552
552
|
"div",
|
|
@@ -561,7 +561,7 @@ const de = ({
|
|
|
561
561
|
padding: "16px",
|
|
562
562
|
outline: "none",
|
|
563
563
|
border: "1px solid #ddd",
|
|
564
|
-
borderRadius: "4px",
|
|
564
|
+
borderRadius: "0px 0px 4px 4px",
|
|
565
565
|
fontSize: "14px",
|
|
566
566
|
lineHeight: "1.5",
|
|
567
567
|
overflow: "auto",
|
|
@@ -573,54 +573,54 @@ const de = ({
|
|
|
573
573
|
children: /* @__PURE__ */ l("p", { children: /* @__PURE__ */ l("br", {}) })
|
|
574
574
|
}
|
|
575
575
|
);
|
|
576
|
-
},
|
|
576
|
+
}, he = ({
|
|
577
577
|
editor: e,
|
|
578
578
|
isEnabled: t
|
|
579
579
|
}) => {
|
|
580
|
-
const [
|
|
581
|
-
|
|
580
|
+
const [m, s] = N(!1), [i, r] = N({ top: 0, left: 0 }), g = E(null), d = E(null), h = E(null), o = E(null);
|
|
581
|
+
A(() => {
|
|
582
582
|
if (!t) {
|
|
583
|
-
|
|
583
|
+
s(!1);
|
|
584
584
|
return;
|
|
585
585
|
}
|
|
586
|
-
o.current =
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
const
|
|
590
|
-
if (!
|
|
591
|
-
|
|
586
|
+
o.current = g.current?.closest("[data-editora-editor]");
|
|
587
|
+
const v = () => {
|
|
588
|
+
h.current && clearTimeout(h.current);
|
|
589
|
+
const c = window.getSelection();
|
|
590
|
+
if (!c || c.rangeCount === 0) {
|
|
591
|
+
s(!1), d.current = null;
|
|
592
592
|
return;
|
|
593
593
|
}
|
|
594
|
-
const
|
|
595
|
-
if (!
|
|
596
|
-
|
|
594
|
+
const f = c.getRangeAt(0), b = c.toString().trim(), p = o.current?.querySelector(".rte-content");
|
|
595
|
+
if (!p || !p.contains(f.commonAncestorContainer)) {
|
|
596
|
+
s(!1), d.current = null;
|
|
597
597
|
return;
|
|
598
598
|
}
|
|
599
|
-
if (
|
|
600
|
-
const
|
|
601
|
-
if (
|
|
602
|
-
const
|
|
603
|
-
let
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
599
|
+
if (b.length > 0) {
|
|
600
|
+
const y = f.getBoundingClientRect(), w = p.getBoundingClientRect(), S = 300;
|
|
601
|
+
if (y && w) {
|
|
602
|
+
const x = y.top - 50;
|
|
603
|
+
let T = y.left + y.width / 2;
|
|
604
|
+
const L = S / 2, I = w.left, D = w.right;
|
|
605
|
+
T - L < I && (T = I + L + 10), T + L > D && (T = D - L - 10), r({ top: x, left: T }), h.current = setTimeout(() => {
|
|
606
|
+
s(!0), d.current = f.cloneRange();
|
|
607
607
|
}, 300);
|
|
608
608
|
}
|
|
609
609
|
} else
|
|
610
|
-
|
|
611
|
-
},
|
|
612
|
-
|
|
610
|
+
s(!1), d.current = null;
|
|
611
|
+
}, C = (c) => {
|
|
612
|
+
g.current && !g.current.contains(c.target) && (window.getSelection(), o.current?.querySelector(".rte-content")?.contains(c.target) || (s(!1), d.current = null));
|
|
613
613
|
};
|
|
614
|
-
return document.addEventListener("selectionchange",
|
|
615
|
-
|
|
614
|
+
return document.addEventListener("selectionchange", v), document.addEventListener("mousedown", C), document.addEventListener("keydown", (c) => {
|
|
615
|
+
c.key === "Escape" && (s(!1), d.current = null);
|
|
616
616
|
}), () => {
|
|
617
|
-
document.removeEventListener("selectionchange",
|
|
617
|
+
document.removeEventListener("selectionchange", v), document.removeEventListener("mousedown", C), h.current && clearTimeout(h.current);
|
|
618
618
|
};
|
|
619
619
|
}, [t]);
|
|
620
|
-
const
|
|
621
|
-
if (!
|
|
622
|
-
const
|
|
623
|
-
|
|
620
|
+
const u = (v, C) => {
|
|
621
|
+
if (!d.current) return;
|
|
622
|
+
const c = o.current?.querySelector(".rte-content");
|
|
623
|
+
c && c.focus(), {
|
|
624
624
|
toggleBold: () => document.execCommand("bold", !1),
|
|
625
625
|
toggleItalic: () => document.execCommand("italic", !1),
|
|
626
626
|
toggleUnderline: () => document.execCommand("underline", !1),
|
|
@@ -632,27 +632,27 @@ const de = ({
|
|
|
632
632
|
document.execCommand("removeFormat", !1), document.execCommand("unlink", !1);
|
|
633
633
|
},
|
|
634
634
|
toggleCode: () => {
|
|
635
|
-
const
|
|
636
|
-
if (
|
|
637
|
-
const
|
|
638
|
-
|
|
635
|
+
const b = window.getSelection();
|
|
636
|
+
if (b && b.rangeCount > 0) {
|
|
637
|
+
const p = b.getRangeAt(0), y = document.createElement("code");
|
|
638
|
+
p.surroundContents(y);
|
|
639
639
|
}
|
|
640
640
|
},
|
|
641
641
|
setBlockType: () => {
|
|
642
|
-
if (
|
|
643
|
-
const
|
|
644
|
-
if (
|
|
645
|
-
const
|
|
646
|
-
(
|
|
642
|
+
if (C === "blockquote") {
|
|
643
|
+
const b = window.getSelection();
|
|
644
|
+
if (b && b.rangeCount > 0) {
|
|
645
|
+
const p = b.getRangeAt(0);
|
|
646
|
+
(p.commonAncestorContainer.nodeType === Node.TEXT_NODE ? p.commonAncestorContainer.parentElement : p.commonAncestorContainer)?.closest?.("blockquote") ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote");
|
|
647
647
|
}
|
|
648
|
-
} else
|
|
648
|
+
} else C && document.execCommand("formatBlock", !1, C);
|
|
649
649
|
}
|
|
650
|
-
}[
|
|
650
|
+
}[v]?.(), s(!1), d.current = null, c && c.focus();
|
|
651
651
|
};
|
|
652
|
-
return !t || !
|
|
652
|
+
return !t || !m ? null : /* @__PURE__ */ R(
|
|
653
653
|
"div",
|
|
654
654
|
{
|
|
655
|
-
ref:
|
|
655
|
+
ref: g,
|
|
656
656
|
className: "floating-toolbar",
|
|
657
657
|
style: {
|
|
658
658
|
position: "fixed",
|
|
@@ -674,7 +674,7 @@ const de = ({
|
|
|
674
674
|
"button",
|
|
675
675
|
{
|
|
676
676
|
className: "floating-toolbar-btn",
|
|
677
|
-
onClick: () =>
|
|
677
|
+
onClick: () => u("toggleBold"),
|
|
678
678
|
title: "Bold (Ctrl+B)",
|
|
679
679
|
children: /* @__PURE__ */ l("strong", { children: "B" })
|
|
680
680
|
}
|
|
@@ -683,7 +683,7 @@ const de = ({
|
|
|
683
683
|
"button",
|
|
684
684
|
{
|
|
685
685
|
className: "floating-toolbar-btn",
|
|
686
|
-
onClick: () =>
|
|
686
|
+
onClick: () => u("toggleItalic"),
|
|
687
687
|
title: "Italic (Ctrl+I)",
|
|
688
688
|
children: /* @__PURE__ */ l("em", { children: "I" })
|
|
689
689
|
}
|
|
@@ -692,7 +692,7 @@ const de = ({
|
|
|
692
692
|
"button",
|
|
693
693
|
{
|
|
694
694
|
className: "floating-toolbar-btn",
|
|
695
|
-
onClick: () =>
|
|
695
|
+
onClick: () => u("toggleUnderline"),
|
|
696
696
|
title: "Underline (Ctrl+U)",
|
|
697
697
|
children: /* @__PURE__ */ l("u", { children: "U" })
|
|
698
698
|
}
|
|
@@ -701,7 +701,7 @@ const de = ({
|
|
|
701
701
|
"button",
|
|
702
702
|
{
|
|
703
703
|
className: "floating-toolbar-btn",
|
|
704
|
-
onClick: () =>
|
|
704
|
+
onClick: () => u("toggleStrikethrough"),
|
|
705
705
|
title: "Strikethrough",
|
|
706
706
|
children: /* @__PURE__ */ l("s", { children: "S" })
|
|
707
707
|
}
|
|
@@ -711,7 +711,7 @@ const de = ({
|
|
|
711
711
|
"button",
|
|
712
712
|
{
|
|
713
713
|
className: "floating-toolbar-btn",
|
|
714
|
-
onClick: () =>
|
|
714
|
+
onClick: () => u("clearFormatting"),
|
|
715
715
|
title: "Clear Formatting",
|
|
716
716
|
children: "⌫"
|
|
717
717
|
}
|
|
@@ -720,7 +720,7 @@ const de = ({
|
|
|
720
720
|
"button",
|
|
721
721
|
{
|
|
722
722
|
className: "floating-toolbar-btn",
|
|
723
|
-
onClick: () =>
|
|
723
|
+
onClick: () => u("createLink"),
|
|
724
724
|
title: "Insert Link",
|
|
725
725
|
children: "🔗"
|
|
726
726
|
}
|
|
@@ -729,7 +729,7 @@ const de = ({
|
|
|
729
729
|
"button",
|
|
730
730
|
{
|
|
731
731
|
className: "floating-toolbar-btn",
|
|
732
|
-
onClick: () =>
|
|
732
|
+
onClick: () => u("toggleCode"),
|
|
733
733
|
title: "Code",
|
|
734
734
|
children: "Code"
|
|
735
735
|
}
|
|
@@ -739,7 +739,7 @@ const de = ({
|
|
|
739
739
|
"button",
|
|
740
740
|
{
|
|
741
741
|
className: "floating-toolbar-btn",
|
|
742
|
-
onClick: () =>
|
|
742
|
+
onClick: () => u("setBlockType", "blockquote"),
|
|
743
743
|
title: "Quote",
|
|
744
744
|
children: "❝"
|
|
745
745
|
}
|
|
@@ -747,24 +747,28 @@ const de = ({
|
|
|
747
747
|
]
|
|
748
748
|
}
|
|
749
749
|
);
|
|
750
|
-
},
|
|
750
|
+
}, we = ({
|
|
751
751
|
plugins: e,
|
|
752
752
|
children: t
|
|
753
753
|
}) => {
|
|
754
|
-
const
|
|
755
|
-
return
|
|
754
|
+
const m = e.filter((i) => i.context?.provider);
|
|
755
|
+
return m.length === 0 ? /* @__PURE__ */ l(B, { children: t }) : m.reduce(
|
|
756
756
|
(i, r) => {
|
|
757
|
-
const
|
|
758
|
-
return /* @__PURE__ */ l(
|
|
757
|
+
const g = r.context.provider;
|
|
758
|
+
return /* @__PURE__ */ l(g, { children: i }, r.name);
|
|
759
759
|
},
|
|
760
|
-
/* @__PURE__ */ l(
|
|
760
|
+
/* @__PURE__ */ l(B, { children: t })
|
|
761
761
|
);
|
|
762
|
-
},
|
|
762
|
+
}, ve = {
|
|
763
763
|
toolbar: {
|
|
764
764
|
items: [],
|
|
765
765
|
floating: !1,
|
|
766
766
|
sticky: !1
|
|
767
767
|
},
|
|
768
|
+
statusbar: {
|
|
769
|
+
enabled: !1,
|
|
770
|
+
position: "bottom"
|
|
771
|
+
},
|
|
768
772
|
menubar: {
|
|
769
773
|
enabled: !1,
|
|
770
774
|
items: []
|
|
@@ -828,16 +832,17 @@ const de = ({
|
|
|
828
832
|
}
|
|
829
833
|
};
|
|
830
834
|
function J(e, t) {
|
|
831
|
-
const
|
|
832
|
-
for (const
|
|
833
|
-
const i = t[
|
|
834
|
-
i !== void 0 && (typeof i == "object" && i !== null && !Array.isArray(i) && typeof r == "object" && r !== null && !Array.isArray(r) ?
|
|
835
|
+
const m = { ...e };
|
|
836
|
+
for (const s in t) {
|
|
837
|
+
const i = t[s], r = m[s];
|
|
838
|
+
i !== void 0 && (typeof i == "object" && i !== null && !Array.isArray(i) && typeof r == "object" && r !== null && !Array.isArray(r) ? m[s] = J(r, i) : m[s] = i);
|
|
835
839
|
}
|
|
836
|
-
return
|
|
840
|
+
return m;
|
|
837
841
|
}
|
|
838
|
-
function
|
|
839
|
-
const t = J(
|
|
842
|
+
function pe(e) {
|
|
843
|
+
const t = J(ve, {
|
|
840
844
|
toolbar: e.toolbar,
|
|
845
|
+
statusbar: e.statusbar,
|
|
841
846
|
menubar: e.menubar,
|
|
842
847
|
contextMenu: e.contextMenu,
|
|
843
848
|
media: e.media,
|
|
@@ -869,19 +874,19 @@ function ge(e) {
|
|
|
869
874
|
onChange: e.onChange,
|
|
870
875
|
onInit: e.onInit,
|
|
871
876
|
onDestroy: e.onDestroy,
|
|
872
|
-
plugins: Array.isArray(e.plugins) ? e.plugins.filter((
|
|
877
|
+
plugins: Array.isArray(e.plugins) ? e.plugins.filter((s) => typeof s != "string") : [],
|
|
873
878
|
pluginConfig: e.pluginConfig || {}
|
|
874
879
|
};
|
|
875
880
|
}
|
|
876
|
-
const
|
|
881
|
+
const F = /* @__PURE__ */ new Map();
|
|
877
882
|
typeof window < "u" && (window.registerEditorCommand = (e, t) => {
|
|
878
|
-
|
|
883
|
+
F.set(e, t);
|
|
879
884
|
}, window.executeEditorCommand = (e, t) => {
|
|
880
|
-
const
|
|
881
|
-
return
|
|
885
|
+
const m = F.get(e);
|
|
886
|
+
return m ? m(t) : (console.warn(`No handler registered for command: ${e}`), !1);
|
|
882
887
|
});
|
|
883
|
-
const
|
|
884
|
-
const t = j(() =>
|
|
888
|
+
const ye = (e) => {
|
|
889
|
+
const t = j(() => pe(e), [
|
|
885
890
|
e.id,
|
|
886
891
|
e.className,
|
|
887
892
|
e.value,
|
|
@@ -902,61 +907,93 @@ const be = (e) => {
|
|
|
902
907
|
e.security,
|
|
903
908
|
e.floatingToolbar,
|
|
904
909
|
e.mediaConfig
|
|
905
|
-
]),
|
|
906
|
-
|
|
910
|
+
]), m = E(null), s = E(null), i = E(e.onInit), r = E(e.onDestroy), g = E(null), d = E(null), h = E(null);
|
|
911
|
+
A(() => {
|
|
907
912
|
i.current = e.onInit, r.current = e.onDestroy;
|
|
908
913
|
});
|
|
909
|
-
const
|
|
910
|
-
const
|
|
911
|
-
t.plugins.forEach((
|
|
912
|
-
|
|
913
|
-
|
|
914
|
+
const o = j(() => {
|
|
915
|
+
const c = new te();
|
|
916
|
+
t.plugins.forEach((b) => {
|
|
917
|
+
c.register(b), b.commands && typeof window < "u" && Object.entries(b.commands).forEach(([p, y]) => {
|
|
918
|
+
F.set(p, y);
|
|
914
919
|
});
|
|
915
920
|
});
|
|
916
|
-
const
|
|
917
|
-
return
|
|
921
|
+
const f = new ne(c);
|
|
922
|
+
return m.current = f, f;
|
|
918
923
|
}, [t.plugins]);
|
|
919
|
-
|
|
920
|
-
const
|
|
921
|
-
getHTML: () =>
|
|
922
|
-
setHTML: (
|
|
923
|
-
const
|
|
924
|
-
|
|
924
|
+
A(() => {
|
|
925
|
+
const c = {
|
|
926
|
+
getHTML: () => g.current?.querySelector(".rte-content")?.innerHTML || "",
|
|
927
|
+
setHTML: (f) => {
|
|
928
|
+
const b = g.current?.querySelector(".rte-content");
|
|
929
|
+
b && (b.innerHTML = f);
|
|
925
930
|
},
|
|
926
|
-
execCommand: (
|
|
927
|
-
typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(
|
|
931
|
+
execCommand: (f, b) => {
|
|
932
|
+
typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(f, b);
|
|
928
933
|
},
|
|
929
|
-
registerCommand: (
|
|
930
|
-
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(
|
|
934
|
+
registerCommand: (f, b) => {
|
|
935
|
+
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(f, b);
|
|
931
936
|
},
|
|
932
937
|
focus: () => {
|
|
933
|
-
|
|
938
|
+
g.current?.querySelector(".rte-content")?.focus();
|
|
934
939
|
},
|
|
935
940
|
blur: () => {
|
|
936
|
-
|
|
941
|
+
g.current?.querySelector(".rte-content")?.blur();
|
|
937
942
|
},
|
|
938
943
|
destroy: () => {
|
|
939
944
|
r.current && r.current();
|
|
940
945
|
},
|
|
941
|
-
onChange: (
|
|
946
|
+
onChange: (f) => () => {
|
|
942
947
|
},
|
|
943
948
|
getState: () => ({
|
|
944
949
|
plugins: t.plugins,
|
|
945
950
|
config: t
|
|
946
951
|
}),
|
|
947
952
|
toolbar: {
|
|
948
|
-
items:
|
|
953
|
+
items: o.toolbar?.items || []
|
|
949
954
|
}
|
|
950
955
|
};
|
|
951
|
-
return
|
|
956
|
+
return s.current = c, i.current && i.current(c), () => {
|
|
952
957
|
r.current && r.current();
|
|
953
958
|
};
|
|
954
|
-
}, [])
|
|
955
|
-
|
|
956
|
-
|
|
959
|
+
}, []), A(() => {
|
|
960
|
+
if (t.statusbar.enabled && h.current && g.current) {
|
|
961
|
+
d.current || (d.current = new oe({
|
|
962
|
+
enabled: !0,
|
|
963
|
+
position: t.statusbar.position
|
|
964
|
+
}), d.current.create(h.current));
|
|
965
|
+
const c = g.current.querySelector(".rte-content");
|
|
966
|
+
if (c) {
|
|
967
|
+
const f = () => {
|
|
968
|
+
const b = c.textContent || "", { words: p, chars: y } = re(b), w = ae(c), S = window.getSelection();
|
|
969
|
+
let x, T;
|
|
970
|
+
if (S && S.rangeCount > 0) {
|
|
971
|
+
const L = S.getRangeAt(0);
|
|
972
|
+
x = le(c, L), L.collapsed || (T = ie(L, x), x = void 0);
|
|
973
|
+
}
|
|
974
|
+
d.current?.update({
|
|
975
|
+
wordCount: p,
|
|
976
|
+
charCount: y,
|
|
977
|
+
lineCount: w,
|
|
978
|
+
cursorPosition: x,
|
|
979
|
+
selectionInfo: T
|
|
980
|
+
});
|
|
981
|
+
};
|
|
982
|
+
return c.addEventListener("input", f), c.addEventListener("selectionchange", f), document.addEventListener("selectionchange", f), f(), () => {
|
|
983
|
+
c.removeEventListener("input", f), c.removeEventListener("selectionchange", f), document.removeEventListener("selectionchange", f);
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
} else
|
|
987
|
+
d.current && (d.current.destroy(), d.current = null);
|
|
988
|
+
return () => {
|
|
989
|
+
d.current && (d.current.destroy(), d.current = null);
|
|
990
|
+
};
|
|
991
|
+
}, [t.statusbar.enabled, t.statusbar.position]);
|
|
992
|
+
const u = t.toolbar.floating ?? !1, v = t.toolbar.position || "top", C = t.toolbar.sticky ?? !1;
|
|
993
|
+
return /* @__PURE__ */ l(we, { plugins: t.plugins, children: /* @__PURE__ */ R(
|
|
957
994
|
"div",
|
|
958
995
|
{
|
|
959
|
-
ref:
|
|
996
|
+
ref: g,
|
|
960
997
|
id: t.id,
|
|
961
998
|
"data-editora-editor": !0,
|
|
962
999
|
className: `rte-editor ${t.className || ""}`,
|
|
@@ -967,19 +1004,19 @@ const be = (e) => {
|
|
|
967
1004
|
height: "100%"
|
|
968
1005
|
},
|
|
969
1006
|
children: [
|
|
970
|
-
|
|
1007
|
+
v !== "bottom" && /* @__PURE__ */ l(
|
|
971
1008
|
V,
|
|
972
1009
|
{
|
|
973
|
-
editor:
|
|
974
|
-
position:
|
|
975
|
-
sticky:
|
|
976
|
-
floating:
|
|
1010
|
+
editor: o,
|
|
1011
|
+
position: v,
|
|
1012
|
+
sticky: C,
|
|
1013
|
+
floating: u
|
|
977
1014
|
}
|
|
978
1015
|
),
|
|
979
1016
|
/* @__PURE__ */ l(
|
|
980
|
-
|
|
1017
|
+
be,
|
|
981
1018
|
{
|
|
982
|
-
editor:
|
|
1019
|
+
editor: o,
|
|
983
1020
|
defaultValue: t.defaultValue,
|
|
984
1021
|
value: t.value,
|
|
985
1022
|
onChange: t.onChange,
|
|
@@ -990,43 +1027,51 @@ const be = (e) => {
|
|
|
990
1027
|
autosaveConfig: t.autosave
|
|
991
1028
|
}
|
|
992
1029
|
),
|
|
993
|
-
|
|
1030
|
+
v === "bottom" && /* @__PURE__ */ l(
|
|
994
1031
|
V,
|
|
995
1032
|
{
|
|
996
|
-
editor:
|
|
997
|
-
position:
|
|
998
|
-
sticky:
|
|
999
|
-
floating:
|
|
1033
|
+
editor: o,
|
|
1034
|
+
position: v,
|
|
1035
|
+
sticky: C,
|
|
1036
|
+
floating: u
|
|
1000
1037
|
}
|
|
1001
1038
|
),
|
|
1002
1039
|
/* @__PURE__ */ l(
|
|
1003
|
-
|
|
1040
|
+
he,
|
|
1041
|
+
{
|
|
1042
|
+
editor: o,
|
|
1043
|
+
isEnabled: u
|
|
1044
|
+
}
|
|
1045
|
+
),
|
|
1046
|
+
t.statusbar.enabled && /* @__PURE__ */ l(
|
|
1047
|
+
"div",
|
|
1004
1048
|
{
|
|
1005
|
-
|
|
1006
|
-
|
|
1049
|
+
ref: h,
|
|
1050
|
+
className: "editora-statusbar-container",
|
|
1051
|
+
style: { order: t.statusbar.position === "top" ? -1 : 1 }
|
|
1007
1052
|
}
|
|
1008
1053
|
)
|
|
1009
1054
|
]
|
|
1010
1055
|
}
|
|
1011
1056
|
) });
|
|
1012
|
-
},
|
|
1013
|
-
function
|
|
1014
|
-
const t = E(null),
|
|
1015
|
-
return
|
|
1016
|
-
|
|
1017
|
-
}),
|
|
1057
|
+
}, Se = (e) => /* @__PURE__ */ l(ye, { ...e });
|
|
1058
|
+
function Te(e = {}) {
|
|
1059
|
+
const t = E(null), m = E(e.onCommand);
|
|
1060
|
+
return A(() => {
|
|
1061
|
+
m.current = e.onCommand;
|
|
1062
|
+
}), A(() => {
|
|
1018
1063
|
if (typeof window > "u" || e.enabled === !1) return;
|
|
1019
|
-
const
|
|
1020
|
-
t.current =
|
|
1021
|
-
const i = (
|
|
1022
|
-
|
|
1064
|
+
const s = new _(e);
|
|
1065
|
+
t.current = s;
|
|
1066
|
+
const i = (g) => s.handleKeyDown(g, (h, o) => {
|
|
1067
|
+
m.current && m.current(h, o), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(h, o);
|
|
1023
1068
|
}), r = e.editorElement || document;
|
|
1024
1069
|
return r && r.addEventListener("keydown", i), () => {
|
|
1025
1070
|
r && r.removeEventListener("keydown", i);
|
|
1026
1071
|
};
|
|
1027
1072
|
}, [e.editorElement, e.enabled, e.shortcuts, e.customShortcuts]), {
|
|
1028
1073
|
getShortcuts: () => t.current?.getAllShortcuts() || [],
|
|
1029
|
-
getShortcutForCommand: (
|
|
1074
|
+
getShortcutForCommand: (s) => t.current?.getShortcutForCommand(s),
|
|
1030
1075
|
getShortcutsHelp: () => t.current?.getShortcutsHelp() || "",
|
|
1031
1076
|
enable: () => t.current?.enable(),
|
|
1032
1077
|
disable: () => t.current?.disable(),
|
|
@@ -1034,11 +1079,11 @@ function Ce(e = {}) {
|
|
|
1034
1079
|
};
|
|
1035
1080
|
}
|
|
1036
1081
|
export {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1082
|
+
be as EditorContent,
|
|
1083
|
+
Se as EditoraEditor,
|
|
1084
|
+
ce as InlineMenu,
|
|
1085
|
+
Se as RichTextEditor,
|
|
1041
1086
|
V as Toolbar,
|
|
1042
|
-
|
|
1043
|
-
|
|
1087
|
+
pe as mergeConfig,
|
|
1088
|
+
Te as useKeyboardShortcuts
|
|
1044
1089
|
};
|