scrible 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +304 -0
- package/dist/scrible.cjs.js +7 -0
- package/dist/scrible.css +1 -0
- package/dist/scrible.es.js +1446 -0
- package/dist/scrible.umd.js +7 -0
- package/dist/vite.svg +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,1446 @@
|
|
|
1
|
+
import $e, { useState as M, useCallback as y, useEffect as U, useRef as se, useMemo as Le } from "react";
|
|
2
|
+
import { Editor as u, Transforms as g, Element as T, Range as A, Point as ue, Text as He, createEditor as Ie } from "slate";
|
|
3
|
+
import { useSlate as re, useSelected as Pe, useFocused as De, ReactEditor as he, withReact as Oe, Slate as Be, Editable as Ve } from "slate-react";
|
|
4
|
+
import { withHistory as Fe } from "slate-history";
|
|
5
|
+
import D from "escape-html";
|
|
6
|
+
var O = { exports: {} }, S = {};
|
|
7
|
+
var de;
|
|
8
|
+
function Ue() {
|
|
9
|
+
if (de) return S;
|
|
10
|
+
de = 1;
|
|
11
|
+
var e = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
12
|
+
function s(n, a, c) {
|
|
13
|
+
var o = null;
|
|
14
|
+
if (c !== void 0 && (o = "" + c), a.key !== void 0 && (o = "" + a.key), "key" in a) {
|
|
15
|
+
c = {};
|
|
16
|
+
for (var i in a)
|
|
17
|
+
i !== "key" && (c[i] = a[i]);
|
|
18
|
+
} else c = a;
|
|
19
|
+
return a = c.ref, {
|
|
20
|
+
$$typeof: e,
|
|
21
|
+
type: n,
|
|
22
|
+
key: o,
|
|
23
|
+
ref: a !== void 0 ? a : null,
|
|
24
|
+
props: c
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return S.Fragment = t, S.jsx = s, S.jsxs = s, S;
|
|
28
|
+
}
|
|
29
|
+
var $ = {};
|
|
30
|
+
var me;
|
|
31
|
+
function We() {
|
|
32
|
+
return me || (me = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
33
|
+
function e(l) {
|
|
34
|
+
if (l == null) return null;
|
|
35
|
+
if (typeof l == "function")
|
|
36
|
+
return l.$$typeof === _e ? null : l.displayName || l.name || null;
|
|
37
|
+
if (typeof l == "string") return l;
|
|
38
|
+
switch (l) {
|
|
39
|
+
case E:
|
|
40
|
+
return "Fragment";
|
|
41
|
+
case R:
|
|
42
|
+
return "Profiler";
|
|
43
|
+
case N:
|
|
44
|
+
return "StrictMode";
|
|
45
|
+
case ze:
|
|
46
|
+
return "Suspense";
|
|
47
|
+
case Me:
|
|
48
|
+
return "SuspenseList";
|
|
49
|
+
case Te:
|
|
50
|
+
return "Activity";
|
|
51
|
+
}
|
|
52
|
+
if (typeof l == "object")
|
|
53
|
+
switch (typeof l.tag == "number" && console.error(
|
|
54
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
55
|
+
), l.$$typeof) {
|
|
56
|
+
case z:
|
|
57
|
+
return "Portal";
|
|
58
|
+
case Ne:
|
|
59
|
+
return l.displayName || "Context";
|
|
60
|
+
case W:
|
|
61
|
+
return (l._context.displayName || "Context") + ".Consumer";
|
|
62
|
+
case Ee:
|
|
63
|
+
var m = l.render;
|
|
64
|
+
return l = l.displayName, l || (l = m.displayName || m.name || "", l = l !== "" ? "ForwardRef(" + l + ")" : "ForwardRef"), l;
|
|
65
|
+
case Re:
|
|
66
|
+
return m = l.displayName || null, m !== null ? m : e(l.type) || "Memo";
|
|
67
|
+
case q:
|
|
68
|
+
m = l._payload, l = l._init;
|
|
69
|
+
try {
|
|
70
|
+
return e(l(m));
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
function t(l) {
|
|
77
|
+
return "" + l;
|
|
78
|
+
}
|
|
79
|
+
function s(l) {
|
|
80
|
+
try {
|
|
81
|
+
t(l);
|
|
82
|
+
var m = !1;
|
|
83
|
+
} catch {
|
|
84
|
+
m = !0;
|
|
85
|
+
}
|
|
86
|
+
if (m) {
|
|
87
|
+
m = console;
|
|
88
|
+
var v = m.error, w = typeof Symbol == "function" && Symbol.toStringTag && l[Symbol.toStringTag] || l.constructor.name || "Object";
|
|
89
|
+
return v.call(
|
|
90
|
+
m,
|
|
91
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
92
|
+
w
|
|
93
|
+
), t(l);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function n(l) {
|
|
97
|
+
if (l === E) return "<>";
|
|
98
|
+
if (typeof l == "object" && l !== null && l.$$typeof === q)
|
|
99
|
+
return "<...>";
|
|
100
|
+
try {
|
|
101
|
+
var m = e(l);
|
|
102
|
+
return m ? "<" + m + ">" : "<...>";
|
|
103
|
+
} catch {
|
|
104
|
+
return "<...>";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function a() {
|
|
108
|
+
var l = Y.A;
|
|
109
|
+
return l === null ? null : l.getOwner();
|
|
110
|
+
}
|
|
111
|
+
function c() {
|
|
112
|
+
return Error("react-stack-top-frame");
|
|
113
|
+
}
|
|
114
|
+
function o(l) {
|
|
115
|
+
if (ne.call(l, "key")) {
|
|
116
|
+
var m = Object.getOwnPropertyDescriptor(l, "key").get;
|
|
117
|
+
if (m && m.isReactWarning) return !1;
|
|
118
|
+
}
|
|
119
|
+
return l.key !== void 0;
|
|
120
|
+
}
|
|
121
|
+
function i(l, m) {
|
|
122
|
+
function v() {
|
|
123
|
+
ae || (ae = !0, console.error(
|
|
124
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
125
|
+
m
|
|
126
|
+
));
|
|
127
|
+
}
|
|
128
|
+
v.isReactWarning = !0, Object.defineProperty(l, "key", {
|
|
129
|
+
get: v,
|
|
130
|
+
configurable: !0
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function d() {
|
|
134
|
+
var l = e(this.type);
|
|
135
|
+
return le[l] || (le[l] = !0, console.error(
|
|
136
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
137
|
+
)), l = this.props.ref, l !== void 0 ? l : null;
|
|
138
|
+
}
|
|
139
|
+
function x(l, m, v, w, P, J) {
|
|
140
|
+
var k = v.ref;
|
|
141
|
+
return l = {
|
|
142
|
+
$$typeof: C,
|
|
143
|
+
type: l,
|
|
144
|
+
key: m,
|
|
145
|
+
props: v,
|
|
146
|
+
_owner: w
|
|
147
|
+
}, (k !== void 0 ? k : null) !== null ? Object.defineProperty(l, "ref", {
|
|
148
|
+
enumerable: !1,
|
|
149
|
+
get: d
|
|
150
|
+
}) : Object.defineProperty(l, "ref", { enumerable: !1, value: null }), l._store = {}, Object.defineProperty(l._store, "validated", {
|
|
151
|
+
configurable: !1,
|
|
152
|
+
enumerable: !1,
|
|
153
|
+
writable: !0,
|
|
154
|
+
value: 0
|
|
155
|
+
}), Object.defineProperty(l, "_debugInfo", {
|
|
156
|
+
configurable: !1,
|
|
157
|
+
enumerable: !1,
|
|
158
|
+
writable: !0,
|
|
159
|
+
value: null
|
|
160
|
+
}), Object.defineProperty(l, "_debugStack", {
|
|
161
|
+
configurable: !1,
|
|
162
|
+
enumerable: !1,
|
|
163
|
+
writable: !0,
|
|
164
|
+
value: P
|
|
165
|
+
}), Object.defineProperty(l, "_debugTask", {
|
|
166
|
+
configurable: !1,
|
|
167
|
+
enumerable: !1,
|
|
168
|
+
writable: !0,
|
|
169
|
+
value: J
|
|
170
|
+
}), Object.freeze && (Object.freeze(l.props), Object.freeze(l)), l;
|
|
171
|
+
}
|
|
172
|
+
function b(l, m, v, w, P, J) {
|
|
173
|
+
var k = m.children;
|
|
174
|
+
if (k !== void 0)
|
|
175
|
+
if (w)
|
|
176
|
+
if (Ae(k)) {
|
|
177
|
+
for (w = 0; w < k.length; w++)
|
|
178
|
+
f(k[w]);
|
|
179
|
+
Object.freeze && Object.freeze(k);
|
|
180
|
+
} else
|
|
181
|
+
console.error(
|
|
182
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
183
|
+
);
|
|
184
|
+
else f(k);
|
|
185
|
+
if (ne.call(m, "key")) {
|
|
186
|
+
k = e(l);
|
|
187
|
+
var _ = Object.keys(m).filter(function(Se) {
|
|
188
|
+
return Se !== "key";
|
|
189
|
+
});
|
|
190
|
+
w = 0 < _.length ? "{key: someKey, " + _.join(": ..., ") + ": ...}" : "{key: someKey}", ie[k + w] || (_ = 0 < _.length ? "{" + _.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
191
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
192
|
+
let props = %s;
|
|
193
|
+
<%s {...props} />
|
|
194
|
+
React keys must be passed directly to JSX without using spread:
|
|
195
|
+
let props = %s;
|
|
196
|
+
<%s key={someKey} {...props} />`,
|
|
197
|
+
w,
|
|
198
|
+
k,
|
|
199
|
+
_,
|
|
200
|
+
k
|
|
201
|
+
), ie[k + w] = !0);
|
|
202
|
+
}
|
|
203
|
+
if (k = null, v !== void 0 && (s(v), k = "" + v), o(m) && (s(m.key), k = "" + m.key), "key" in m) {
|
|
204
|
+
v = {};
|
|
205
|
+
for (var G in m)
|
|
206
|
+
G !== "key" && (v[G] = m[G]);
|
|
207
|
+
} else v = m;
|
|
208
|
+
return k && i(
|
|
209
|
+
v,
|
|
210
|
+
typeof l == "function" ? l.displayName || l.name || "Unknown" : l
|
|
211
|
+
), x(
|
|
212
|
+
l,
|
|
213
|
+
k,
|
|
214
|
+
v,
|
|
215
|
+
a(),
|
|
216
|
+
P,
|
|
217
|
+
J
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
function f(l) {
|
|
221
|
+
h(l) ? l._store && (l._store.validated = 1) : typeof l == "object" && l !== null && l.$$typeof === q && (l._payload.status === "fulfilled" ? h(l._payload.value) && l._payload.value._store && (l._payload.value._store.validated = 1) : l._store && (l._store.validated = 1));
|
|
222
|
+
}
|
|
223
|
+
function h(l) {
|
|
224
|
+
return typeof l == "object" && l !== null && l.$$typeof === C;
|
|
225
|
+
}
|
|
226
|
+
var p = $e, C = Symbol.for("react.transitional.element"), z = Symbol.for("react.portal"), E = Symbol.for("react.fragment"), N = Symbol.for("react.strict_mode"), R = Symbol.for("react.profiler"), W = Symbol.for("react.consumer"), Ne = Symbol.for("react.context"), Ee = Symbol.for("react.forward_ref"), ze = Symbol.for("react.suspense"), Me = Symbol.for("react.suspense_list"), Re = Symbol.for("react.memo"), q = Symbol.for("react.lazy"), Te = Symbol.for("react.activity"), _e = Symbol.for("react.client.reference"), Y = p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, ne = Object.prototype.hasOwnProperty, Ae = Array.isArray, X = console.createTask ? console.createTask : function() {
|
|
227
|
+
return null;
|
|
228
|
+
};
|
|
229
|
+
p = {
|
|
230
|
+
react_stack_bottom_frame: function(l) {
|
|
231
|
+
return l();
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var ae, le = {}, oe = p.react_stack_bottom_frame.bind(
|
|
235
|
+
p,
|
|
236
|
+
c
|
|
237
|
+
)(), ce = X(n(c)), ie = {};
|
|
238
|
+
$.Fragment = E, $.jsx = function(l, m, v) {
|
|
239
|
+
var w = 1e4 > Y.recentlyCreatedOwnerStacks++;
|
|
240
|
+
return b(
|
|
241
|
+
l,
|
|
242
|
+
m,
|
|
243
|
+
v,
|
|
244
|
+
!1,
|
|
245
|
+
w ? Error("react-stack-top-frame") : oe,
|
|
246
|
+
w ? X(n(l)) : ce
|
|
247
|
+
);
|
|
248
|
+
}, $.jsxs = function(l, m, v) {
|
|
249
|
+
var w = 1e4 > Y.recentlyCreatedOwnerStacks++;
|
|
250
|
+
return b(
|
|
251
|
+
l,
|
|
252
|
+
m,
|
|
253
|
+
v,
|
|
254
|
+
!0,
|
|
255
|
+
w ? Error("react-stack-top-frame") : oe,
|
|
256
|
+
w ? X(n(l)) : ce
|
|
257
|
+
);
|
|
258
|
+
};
|
|
259
|
+
})()), $;
|
|
260
|
+
}
|
|
261
|
+
var fe;
|
|
262
|
+
function qe() {
|
|
263
|
+
return fe || (fe = 1, process.env.NODE_ENV === "production" ? O.exports = Ue() : O.exports = We()), O.exports;
|
|
264
|
+
}
|
|
265
|
+
var r = qe();
|
|
266
|
+
const L = (e, t) => {
|
|
267
|
+
const s = I(e, t);
|
|
268
|
+
if (t.startsWith("font-size-")) {
|
|
269
|
+
u.removeMark(e, "font-size-small"), u.removeMark(e, "font-size-normal"), u.removeMark(e, "font-size-large"), u.removeMark(e, "font-size-extra-large"), s || u.addMark(e, t, !0);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
s ? u.removeMark(e, t) : u.addMark(e, t, !0);
|
|
273
|
+
}, I = (e, t) => {
|
|
274
|
+
const s = u.marks(e);
|
|
275
|
+
return s ? s[t] === !0 : !1;
|
|
276
|
+
}, K = (e, t) => {
|
|
277
|
+
t ? u.addMark(e, "color", t) : u.removeMark(e, "color");
|
|
278
|
+
}, Ye = (e) => u.marks(e)?.color || null, Q = (e, t) => {
|
|
279
|
+
t ? u.addMark(e, "backgroundColor", t) : u.removeMark(e, "backgroundColor");
|
|
280
|
+
}, Xe = (e) => u.marks(e)?.backgroundColor || null, Z = (e, t) => {
|
|
281
|
+
const s = te(e, t), n = pe.includes(t);
|
|
282
|
+
g.unwrapNodes(e, {
|
|
283
|
+
match: (c) => !u.isEditor(c) && T.isElement(c) && pe.includes(c.type),
|
|
284
|
+
split: !0
|
|
285
|
+
});
|
|
286
|
+
let a;
|
|
287
|
+
if (s ? a = { type: "paragraph" } : n ? a = { type: "list-item" } : a = { type: t }, g.setNodes(e, a), !s && n) {
|
|
288
|
+
const c = { type: t, children: [] };
|
|
289
|
+
g.wrapNodes(e, c);
|
|
290
|
+
}
|
|
291
|
+
}, B = (e, t) => {
|
|
292
|
+
g.setNodes(
|
|
293
|
+
e,
|
|
294
|
+
{ align: t },
|
|
295
|
+
{
|
|
296
|
+
match: (s) => T.isElement(s) && u.isBlock(e, s),
|
|
297
|
+
split: !0
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
}, te = (e, t, s = "type") => {
|
|
301
|
+
const { selection: n } = e;
|
|
302
|
+
if (!n) return !1;
|
|
303
|
+
const [a] = Array.from(
|
|
304
|
+
u.nodes(e, {
|
|
305
|
+
at: u.unhangRange(e, n),
|
|
306
|
+
match: (c) => !u.isEditor(c) && T.isElement(c) && c[s] === t
|
|
307
|
+
})
|
|
308
|
+
);
|
|
309
|
+
return !!a;
|
|
310
|
+
}, pe = ["numbered-list", "bulleted-list"], ke = (e, t, s = "") => {
|
|
311
|
+
const a = {
|
|
312
|
+
type: "image",
|
|
313
|
+
url: t,
|
|
314
|
+
alt: s,
|
|
315
|
+
width: "auto",
|
|
316
|
+
height: "auto",
|
|
317
|
+
children: [{ text: "" }]
|
|
318
|
+
};
|
|
319
|
+
g.insertNodes(e, a), g.insertNodes(e, { type: "paragraph", children: [{ text: "" }] });
|
|
320
|
+
}, Je = (e) => {
|
|
321
|
+
if (!e || !Ge(e)) return !1;
|
|
322
|
+
const t = new URL(e).pathname.split(".").pop();
|
|
323
|
+
return ["jpg", "jpeg", "png", "gif", "webp", "svg"].includes(t.toLowerCase());
|
|
324
|
+
}, Ge = (e) => {
|
|
325
|
+
try {
|
|
326
|
+
return new URL(e), !0;
|
|
327
|
+
} catch {
|
|
328
|
+
return !1;
|
|
329
|
+
}
|
|
330
|
+
}, Ke = (e, t) => {
|
|
331
|
+
e.selection && Qe(e, t);
|
|
332
|
+
}, Qe = (e, t) => {
|
|
333
|
+
et(e) && Ze(e);
|
|
334
|
+
const { selection: s } = e, n = s && A.isCollapsed(s), a = {
|
|
335
|
+
type: "link",
|
|
336
|
+
url: t,
|
|
337
|
+
children: n ? [{ text: t }] : []
|
|
338
|
+
};
|
|
339
|
+
n ? g.insertNodes(e, a) : (g.wrapNodes(e, a, { split: !0 }), g.collapse(e, { edge: "end" }));
|
|
340
|
+
}, Ze = (e) => {
|
|
341
|
+
g.unwrapNodes(e, {
|
|
342
|
+
match: (t) => !u.isEditor(t) && T.isElement(t) && t.type === "link"
|
|
343
|
+
});
|
|
344
|
+
}, et = (e) => {
|
|
345
|
+
const [t] = u.nodes(e, {
|
|
346
|
+
match: (s) => !u.isEditor(s) && T.isElement(s) && s.type === "link"
|
|
347
|
+
});
|
|
348
|
+
return !!t;
|
|
349
|
+
}, je = (e, t = 3, s = 3) => {
|
|
350
|
+
const n = tt(t, s);
|
|
351
|
+
g.insertNodes(e, n);
|
|
352
|
+
const c = [...u.path(e, e.selection.anchor), 0, 0, 0];
|
|
353
|
+
g.select(e, c);
|
|
354
|
+
}, tt = (e, t) => {
|
|
355
|
+
const s = (a = !1) => ({
|
|
356
|
+
type: "table-cell",
|
|
357
|
+
header: a,
|
|
358
|
+
children: [{ type: "paragraph", children: [{ text: "" }] }]
|
|
359
|
+
}), n = (a = !1) => ({
|
|
360
|
+
type: "table-row",
|
|
361
|
+
children: Array.from({ length: t }, () => s(a))
|
|
362
|
+
});
|
|
363
|
+
return {
|
|
364
|
+
type: "table",
|
|
365
|
+
children: [
|
|
366
|
+
n(!0),
|
|
367
|
+
// Header row
|
|
368
|
+
...Array.from({ length: e - 1 }, () => n(!1))
|
|
369
|
+
]
|
|
370
|
+
};
|
|
371
|
+
}, Ut = (e) => {
|
|
372
|
+
const [t] = u.nodes(e, {
|
|
373
|
+
match: (s) => s.type === "table"
|
|
374
|
+
});
|
|
375
|
+
if (t) {
|
|
376
|
+
const [, s] = t, [n] = u.nodes(e, {
|
|
377
|
+
match: (a) => a.type === "table-row"
|
|
378
|
+
});
|
|
379
|
+
if (n) {
|
|
380
|
+
const [a] = n, c = {
|
|
381
|
+
type: "table-row",
|
|
382
|
+
children: a.children.map(() => ({
|
|
383
|
+
type: "table-cell",
|
|
384
|
+
children: [{ type: "paragraph", children: [{ text: "" }] }]
|
|
385
|
+
}))
|
|
386
|
+
}, o = [...s, t[0].children.length];
|
|
387
|
+
g.insertNodes(e, c, { at: o });
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}, Wt = (e) => {
|
|
391
|
+
const [t] = u.nodes(e, {
|
|
392
|
+
match: (s) => s.type === "table"
|
|
393
|
+
});
|
|
394
|
+
if (t) {
|
|
395
|
+
const [s, n] = t;
|
|
396
|
+
s.children.forEach((a, c) => {
|
|
397
|
+
const o = {
|
|
398
|
+
type: "table-cell",
|
|
399
|
+
children: [{ type: "paragraph", children: [{ text: "" }] }]
|
|
400
|
+
}, i = [...n, c, a.children.length];
|
|
401
|
+
g.insertNodes(e, o, { at: i });
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}, qt = (e) => {
|
|
405
|
+
const [t] = u.nodes(e, {
|
|
406
|
+
match: (s) => s.type === "table-row"
|
|
407
|
+
});
|
|
408
|
+
t && g.removeNodes(e, {
|
|
409
|
+
match: (s) => s.type === "table-row"
|
|
410
|
+
});
|
|
411
|
+
}, Yt = (e) => {
|
|
412
|
+
const [t] = u.nodes(e, {
|
|
413
|
+
match: (s) => s.type === "table-cell"
|
|
414
|
+
});
|
|
415
|
+
if (t) {
|
|
416
|
+
const [, s] = t, n = s[s.length - 1], [a] = u.nodes(e, {
|
|
417
|
+
match: (c) => c.type === "table"
|
|
418
|
+
});
|
|
419
|
+
if (a) {
|
|
420
|
+
const [c, o] = a;
|
|
421
|
+
for (let i = c.children.length - 1; i >= 0; i--) {
|
|
422
|
+
const d = [...o, i, n];
|
|
423
|
+
g.removeNodes(e, { at: d });
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}, st = (e) => {
|
|
428
|
+
const [t] = u.nodes(e, {
|
|
429
|
+
match: (s) => T.isElement(s) && u.isBlock(e, s)
|
|
430
|
+
});
|
|
431
|
+
return t ? t[0].type : "paragraph";
|
|
432
|
+
}, rt = (e) => {
|
|
433
|
+
const t = u.marks(e);
|
|
434
|
+
return t?.["font-size-small"] ? "small" : t?.["font-size-large"] ? "large" : t?.["font-size-extra-large"] ? "extra-large" : "normal";
|
|
435
|
+
}, V = (e) => {
|
|
436
|
+
const [t] = u.nodes(e, {
|
|
437
|
+
match: (s) => T.isElement(s) && u.isBlock(e, s)
|
|
438
|
+
});
|
|
439
|
+
return t && t[0].align ? t[0].align : "left";
|
|
440
|
+
}, nt = (e) => {
|
|
441
|
+
g.delete(e, {
|
|
442
|
+
at: {
|
|
443
|
+
anchor: u.start(e, []),
|
|
444
|
+
focus: u.end(e, [])
|
|
445
|
+
}
|
|
446
|
+
}), g.select(e, u.start(e, []));
|
|
447
|
+
}, j = ({ active: e, children: t, onMouseDown: s, title: n, className: a = "", ...c }) => /* @__PURE__ */ r.jsx(
|
|
448
|
+
"button",
|
|
449
|
+
{
|
|
450
|
+
className: `toolbar-button ${e ? "active" : ""} ${a}`,
|
|
451
|
+
onMouseDown: (o) => {
|
|
452
|
+
o.preventDefault(), s && s();
|
|
453
|
+
},
|
|
454
|
+
title: n,
|
|
455
|
+
...c,
|
|
456
|
+
children: t
|
|
457
|
+
}
|
|
458
|
+
), ge = ({ value: e, onChange: t, children: s, title: n, ...a }) => /* @__PURE__ */ r.jsx(
|
|
459
|
+
"select",
|
|
460
|
+
{
|
|
461
|
+
className: "toolbar-select",
|
|
462
|
+
value: e,
|
|
463
|
+
onChange: (c) => t(c.target.value),
|
|
464
|
+
title: n,
|
|
465
|
+
...a,
|
|
466
|
+
children: s
|
|
467
|
+
}
|
|
468
|
+
), at = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z" }) }), lt = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z" }) }), ot = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M12 17c3.31 0 6-2.69 6-6V3h-2.5v8c0 1.93-1.57 3.5-3.5 3.5S8.5 12.93 8.5 11V3H6v8c0 3.31 2.69 6 6 6zm-7 2v2h14v-2H5z" }) }), ct = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z" }) }), it = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z" }) }), ut = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z" }) }), ht = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M15 15H3v2h12v-2zm0-8H3v2h12V7zM3 13h18v-2H3v2zm0 8h18v-2H3v2zM3 3v2h18V3H3z" }) }), dt = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M7 15v2h10v-2H7zm-4 6h18v-2H3v2zm0-8h18v-2H3v2zm4-6v2h10V7H7zM3 3v2h18V3H3z" }) }), mt = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M3 21h18v-2H3v2zm6-4h12v-2H9v2zm-6-4h18v-2H3v2zm6-4h12V7H9v2zM3 3v2h18V3H3z" }) }), ft = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M3 21h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18V7H3v2zm0-6v2h18V3H3z" }) }), pt = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z" }) }), gt = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z" }) }), xt = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M10 10.02h5V21h-5zM17 21h3c1.1 0 2-.9 2-2v-9h-5v11zm3-18H5c-1.1 0-2 .9-2 2v3h19V5c0-1.1-.9-2-2-2zM3 19c0 1.1.9 2 2 2h3V10H3v9z" }) }), vt = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" }) }), bt = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M2.5 4v3h5v12h3V7h5V4h-13zm19 5h-9v3h3v7h3v-7h3V9z" }) }), wt = () => /* @__PURE__ */ r.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ r.jsx("path", { d: "M16.56 8.94L7.62 0 6.21 1.41l2.38 2.38-5.15 5.15c-.59.59-.59 1.54 0 2.12l5.5 5.5c.29.29.68.44 1.06.44s.77-.15 1.06-.44l5.5-5.5c.59-.58.59-1.53 0-2.12zM5.21 10L10 5.21 14.79 10H5.21zM19 11.5s-2 2.17-2 3.5c0 1.1.9 2 2 2s2-.9 2-2c0-1.33-2-3.5-2-3.5z" }) }), xe = ({ editor: e, type: t = "text" }) => {
|
|
469
|
+
const [s, n] = M(!1), [a, c] = M(""), o = t === "text", i = o ? Ye(e) : Xe(e), d = [
|
|
470
|
+
"#000000",
|
|
471
|
+
"#374151",
|
|
472
|
+
"#6b7280",
|
|
473
|
+
"#9ca3af",
|
|
474
|
+
"#d1d5db",
|
|
475
|
+
"#ffffff",
|
|
476
|
+
"#ef4444",
|
|
477
|
+
"#f97316",
|
|
478
|
+
"#f59e0b",
|
|
479
|
+
"#eab308",
|
|
480
|
+
"#84cc16",
|
|
481
|
+
"#22c55e",
|
|
482
|
+
"#10b981",
|
|
483
|
+
"#14b8a6",
|
|
484
|
+
"#06b6d4",
|
|
485
|
+
"#0ea5e9",
|
|
486
|
+
"#3b82f6",
|
|
487
|
+
"#6366f1",
|
|
488
|
+
"#8b5cf6",
|
|
489
|
+
"#a855f7",
|
|
490
|
+
"#d946ef",
|
|
491
|
+
"#ec4899",
|
|
492
|
+
"#f43f5e",
|
|
493
|
+
"#fb7185"
|
|
494
|
+
], x = y((h) => {
|
|
495
|
+
o ? K(e, h) : Q(e, h), n(!1);
|
|
496
|
+
}, [e, o]), b = y((h) => {
|
|
497
|
+
const p = h.target.value;
|
|
498
|
+
c(p), o ? K(e, p) : Q(e, p);
|
|
499
|
+
}, [e, o]), f = y(() => {
|
|
500
|
+
o ? K(e, null) : Q(e, null), n(!1);
|
|
501
|
+
}, [e, o]);
|
|
502
|
+
return U(() => {
|
|
503
|
+
if (!s) return;
|
|
504
|
+
const h = (p) => {
|
|
505
|
+
p.target.closest(".color-picker-dropdown") || n(!1);
|
|
506
|
+
};
|
|
507
|
+
return document.addEventListener("mousedown", h), () => document.removeEventListener("mousedown", h);
|
|
508
|
+
}, [s]), /* @__PURE__ */ r.jsxs("div", { className: "color-picker-dropdown", children: [
|
|
509
|
+
/* @__PURE__ */ r.jsxs(
|
|
510
|
+
"button",
|
|
511
|
+
{
|
|
512
|
+
className: "toolbar-button color-picker-button",
|
|
513
|
+
onMouseDown: (h) => {
|
|
514
|
+
h.preventDefault(), n(!s);
|
|
515
|
+
},
|
|
516
|
+
title: o ? "Text Color" : "Background Color",
|
|
517
|
+
style: { position: "relative" },
|
|
518
|
+
children: [
|
|
519
|
+
o ? /* @__PURE__ */ r.jsx(bt, {}) : /* @__PURE__ */ r.jsx(wt, {}),
|
|
520
|
+
i && /* @__PURE__ */ r.jsx(
|
|
521
|
+
"div",
|
|
522
|
+
{
|
|
523
|
+
className: "color-indicator",
|
|
524
|
+
style: {
|
|
525
|
+
backgroundColor: i,
|
|
526
|
+
position: "absolute",
|
|
527
|
+
bottom: "4px",
|
|
528
|
+
left: "50%",
|
|
529
|
+
transform: "translateX(-50%)",
|
|
530
|
+
width: "20px",
|
|
531
|
+
height: "3px",
|
|
532
|
+
borderRadius: "2px"
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
)
|
|
536
|
+
]
|
|
537
|
+
}
|
|
538
|
+
),
|
|
539
|
+
s && /* @__PURE__ */ r.jsxs("div", { className: "color-picker-panel", children: [
|
|
540
|
+
/* @__PURE__ */ r.jsx("div", { className: "color-picker-presets", children: d.map((h) => /* @__PURE__ */ r.jsx(
|
|
541
|
+
"button",
|
|
542
|
+
{
|
|
543
|
+
className: `color-swatch ${i === h ? "active" : ""}`,
|
|
544
|
+
style: { backgroundColor: h },
|
|
545
|
+
onClick: (p) => {
|
|
546
|
+
p.stopPropagation(), x(h);
|
|
547
|
+
},
|
|
548
|
+
title: h
|
|
549
|
+
},
|
|
550
|
+
h
|
|
551
|
+
)) }),
|
|
552
|
+
/* @__PURE__ */ r.jsx("div", { className: "color-picker-custom", children: /* @__PURE__ */ r.jsxs("label", { className: "color-picker-label", children: [
|
|
553
|
+
"Custom Color:",
|
|
554
|
+
/* @__PURE__ */ r.jsx(
|
|
555
|
+
"input",
|
|
556
|
+
{
|
|
557
|
+
type: "color",
|
|
558
|
+
value: a || i || "#000000",
|
|
559
|
+
onChange: b,
|
|
560
|
+
className: "color-picker-input"
|
|
561
|
+
}
|
|
562
|
+
)
|
|
563
|
+
] }) }),
|
|
564
|
+
i && /* @__PURE__ */ r.jsx(
|
|
565
|
+
"button",
|
|
566
|
+
{
|
|
567
|
+
className: "color-picker-remove",
|
|
568
|
+
onClick: (h) => {
|
|
569
|
+
h.stopPropagation(), f();
|
|
570
|
+
},
|
|
571
|
+
children: "Remove Color"
|
|
572
|
+
}
|
|
573
|
+
)
|
|
574
|
+
] })
|
|
575
|
+
] });
|
|
576
|
+
}, kt = ({ editor: e }) => {
|
|
577
|
+
const [t, s] = M(!1), [n, a] = M({ row: 0, col: 0 }), c = y((o, i) => {
|
|
578
|
+
je(e, o + 1, i + 1), s(!1), a({ row: 0, col: 0 });
|
|
579
|
+
}, [e]);
|
|
580
|
+
return U(() => {
|
|
581
|
+
if (!t) return;
|
|
582
|
+
const o = (i) => {
|
|
583
|
+
i.target.closest(".table-dropdown") || s(!1);
|
|
584
|
+
};
|
|
585
|
+
return document.addEventListener("mousedown", o), () => document.removeEventListener("mousedown", o);
|
|
586
|
+
}, [t]), /* @__PURE__ */ r.jsxs("div", { className: "table-dropdown", children: [
|
|
587
|
+
/* @__PURE__ */ r.jsx(
|
|
588
|
+
"button",
|
|
589
|
+
{
|
|
590
|
+
className: "toolbar-button",
|
|
591
|
+
onMouseDown: (o) => {
|
|
592
|
+
o.preventDefault(), s(!t);
|
|
593
|
+
},
|
|
594
|
+
title: "Insert Table",
|
|
595
|
+
children: /* @__PURE__ */ r.jsx(xt, {})
|
|
596
|
+
}
|
|
597
|
+
),
|
|
598
|
+
t && /* @__PURE__ */ r.jsxs("div", { className: "table-size-selector", children: [
|
|
599
|
+
/* @__PURE__ */ r.jsx("div", { className: "table-grid", children: Array.from(
|
|
600
|
+
{ length: 6 },
|
|
601
|
+
(o, i) => Array.from({ length: 6 }, (d, x) => /* @__PURE__ */ r.jsx(
|
|
602
|
+
"div",
|
|
603
|
+
{
|
|
604
|
+
className: `table-cell-selector ${i <= n.row && x <= n.col ? "active" : ""}`,
|
|
605
|
+
onMouseEnter: () => a({ row: i, col: x }),
|
|
606
|
+
onClick: (b) => {
|
|
607
|
+
b.stopPropagation(), c(i, x);
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
`${i}-${x}`
|
|
611
|
+
))
|
|
612
|
+
) }),
|
|
613
|
+
/* @__PURE__ */ r.jsxs("div", { className: "table-size-label", children: [
|
|
614
|
+
n.row + 1,
|
|
615
|
+
" × ",
|
|
616
|
+
n.col + 1
|
|
617
|
+
] })
|
|
618
|
+
] })
|
|
619
|
+
] });
|
|
620
|
+
}, jt = ({
|
|
621
|
+
features: e = [
|
|
622
|
+
"bold",
|
|
623
|
+
"italic",
|
|
624
|
+
"underline",
|
|
625
|
+
"strikethrough",
|
|
626
|
+
"headings",
|
|
627
|
+
"lists",
|
|
628
|
+
"alignment",
|
|
629
|
+
"fontSize",
|
|
630
|
+
"textColor",
|
|
631
|
+
"backgroundColor",
|
|
632
|
+
"link",
|
|
633
|
+
"image",
|
|
634
|
+
"table",
|
|
635
|
+
"clear"
|
|
636
|
+
]
|
|
637
|
+
}) => {
|
|
638
|
+
const t = re(), s = se(), n = (o) => e.includes(o), a = (o) => {
|
|
639
|
+
const i = o.target.files[0];
|
|
640
|
+
if (i && i.type.startsWith("image/")) {
|
|
641
|
+
const d = new FileReader();
|
|
642
|
+
d.onload = (x) => {
|
|
643
|
+
ke(t, x.target.result);
|
|
644
|
+
}, d.readAsDataURL(i);
|
|
645
|
+
}
|
|
646
|
+
o.target.value = "";
|
|
647
|
+
}, c = () => {
|
|
648
|
+
const o = window.prompt("Enter the URL:");
|
|
649
|
+
o && Ke(t, o);
|
|
650
|
+
};
|
|
651
|
+
return /* @__PURE__ */ r.jsxs("div", { className: "toolbar", children: [
|
|
652
|
+
(n("bold") || n("italic") || n("underline") || n("strikethrough")) && /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
|
|
653
|
+
/* @__PURE__ */ r.jsxs("div", { className: "toolbar-group", children: [
|
|
654
|
+
n("bold") && /* @__PURE__ */ r.jsx(
|
|
655
|
+
j,
|
|
656
|
+
{
|
|
657
|
+
active: I(t, "bold"),
|
|
658
|
+
onMouseDown: () => L(t, "bold"),
|
|
659
|
+
title: "Bold (Ctrl+B)",
|
|
660
|
+
children: /* @__PURE__ */ r.jsx(at, {})
|
|
661
|
+
}
|
|
662
|
+
),
|
|
663
|
+
n("italic") && /* @__PURE__ */ r.jsx(
|
|
664
|
+
j,
|
|
665
|
+
{
|
|
666
|
+
active: I(t, "italic"),
|
|
667
|
+
onMouseDown: () => L(t, "italic"),
|
|
668
|
+
title: "Italic (Ctrl+I)",
|
|
669
|
+
children: /* @__PURE__ */ r.jsx(lt, {})
|
|
670
|
+
}
|
|
671
|
+
),
|
|
672
|
+
n("underline") && /* @__PURE__ */ r.jsx(
|
|
673
|
+
j,
|
|
674
|
+
{
|
|
675
|
+
active: I(t, "underline"),
|
|
676
|
+
onMouseDown: () => L(t, "underline"),
|
|
677
|
+
title: "Underline (Ctrl+U)",
|
|
678
|
+
children: /* @__PURE__ */ r.jsx(ot, {})
|
|
679
|
+
}
|
|
680
|
+
),
|
|
681
|
+
n("strikethrough") && /* @__PURE__ */ r.jsx(
|
|
682
|
+
j,
|
|
683
|
+
{
|
|
684
|
+
active: I(t, "strikethrough"),
|
|
685
|
+
onMouseDown: () => L(t, "strikethrough"),
|
|
686
|
+
title: "Strikethrough",
|
|
687
|
+
children: /* @__PURE__ */ r.jsx(ct, {})
|
|
688
|
+
}
|
|
689
|
+
)
|
|
690
|
+
] }),
|
|
691
|
+
/* @__PURE__ */ r.jsx("div", { className: "toolbar-separator" })
|
|
692
|
+
] }),
|
|
693
|
+
n("headings") && /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
|
|
694
|
+
/* @__PURE__ */ r.jsx("div", { className: "toolbar-group", children: /* @__PURE__ */ r.jsxs(
|
|
695
|
+
ge,
|
|
696
|
+
{
|
|
697
|
+
value: st(t),
|
|
698
|
+
onChange: (o) => Z(t, o),
|
|
699
|
+
children: [
|
|
700
|
+
/* @__PURE__ */ r.jsx("option", { value: "paragraph", children: "Paragraph" }),
|
|
701
|
+
/* @__PURE__ */ r.jsx("option", { value: "heading-one", children: "Heading 1" }),
|
|
702
|
+
/* @__PURE__ */ r.jsx("option", { value: "heading-two", children: "Heading 2" }),
|
|
703
|
+
/* @__PURE__ */ r.jsx("option", { value: "heading-three", children: "Heading 3" }),
|
|
704
|
+
/* @__PURE__ */ r.jsx("option", { value: "blockquote", children: "Quote" })
|
|
705
|
+
]
|
|
706
|
+
}
|
|
707
|
+
) }),
|
|
708
|
+
/* @__PURE__ */ r.jsx("div", { className: "toolbar-separator" })
|
|
709
|
+
] }),
|
|
710
|
+
n("lists") && /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
|
|
711
|
+
/* @__PURE__ */ r.jsxs("div", { className: "toolbar-group", children: [
|
|
712
|
+
/* @__PURE__ */ r.jsx(
|
|
713
|
+
j,
|
|
714
|
+
{
|
|
715
|
+
active: te(t, "bulleted-list"),
|
|
716
|
+
onMouseDown: () => Z(t, "bulleted-list"),
|
|
717
|
+
title: "Bulleted List",
|
|
718
|
+
children: /* @__PURE__ */ r.jsx(it, {})
|
|
719
|
+
}
|
|
720
|
+
),
|
|
721
|
+
/* @__PURE__ */ r.jsx(
|
|
722
|
+
j,
|
|
723
|
+
{
|
|
724
|
+
active: te(t, "numbered-list"),
|
|
725
|
+
onMouseDown: () => Z(t, "numbered-list"),
|
|
726
|
+
title: "Numbered List",
|
|
727
|
+
children: /* @__PURE__ */ r.jsx(ut, {})
|
|
728
|
+
}
|
|
729
|
+
)
|
|
730
|
+
] }),
|
|
731
|
+
/* @__PURE__ */ r.jsx("div", { className: "toolbar-separator" })
|
|
732
|
+
] }),
|
|
733
|
+
n("alignment") && /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
|
|
734
|
+
/* @__PURE__ */ r.jsxs("div", { className: "toolbar-group", children: [
|
|
735
|
+
/* @__PURE__ */ r.jsx(
|
|
736
|
+
j,
|
|
737
|
+
{
|
|
738
|
+
active: V(t) === "left",
|
|
739
|
+
onMouseDown: () => B(t, "left"),
|
|
740
|
+
title: "Align Left",
|
|
741
|
+
children: /* @__PURE__ */ r.jsx(ht, {})
|
|
742
|
+
}
|
|
743
|
+
),
|
|
744
|
+
/* @__PURE__ */ r.jsx(
|
|
745
|
+
j,
|
|
746
|
+
{
|
|
747
|
+
active: V(t) === "center",
|
|
748
|
+
onMouseDown: () => B(t, "center"),
|
|
749
|
+
title: "Align Center",
|
|
750
|
+
children: /* @__PURE__ */ r.jsx(dt, {})
|
|
751
|
+
}
|
|
752
|
+
),
|
|
753
|
+
/* @__PURE__ */ r.jsx(
|
|
754
|
+
j,
|
|
755
|
+
{
|
|
756
|
+
active: V(t) === "right",
|
|
757
|
+
onMouseDown: () => B(t, "right"),
|
|
758
|
+
title: "Align Right",
|
|
759
|
+
children: /* @__PURE__ */ r.jsx(mt, {})
|
|
760
|
+
}
|
|
761
|
+
),
|
|
762
|
+
/* @__PURE__ */ r.jsx(
|
|
763
|
+
j,
|
|
764
|
+
{
|
|
765
|
+
active: V(t) === "justify",
|
|
766
|
+
onMouseDown: () => B(t, "justify"),
|
|
767
|
+
title: "Justify",
|
|
768
|
+
children: /* @__PURE__ */ r.jsx(ft, {})
|
|
769
|
+
}
|
|
770
|
+
)
|
|
771
|
+
] }),
|
|
772
|
+
/* @__PURE__ */ r.jsx("div", { className: "toolbar-separator" })
|
|
773
|
+
] }),
|
|
774
|
+
n("fontSize") && /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
|
|
775
|
+
/* @__PURE__ */ r.jsx("div", { className: "toolbar-group", children: /* @__PURE__ */ r.jsxs(
|
|
776
|
+
ge,
|
|
777
|
+
{
|
|
778
|
+
value: rt(t),
|
|
779
|
+
onChange: (o) => L(t, `font-size-${o}`),
|
|
780
|
+
title: "Font Size",
|
|
781
|
+
children: [
|
|
782
|
+
/* @__PURE__ */ r.jsx("option", { value: "small", children: "Small" }),
|
|
783
|
+
/* @__PURE__ */ r.jsx("option", { value: "normal", children: "Normal" }),
|
|
784
|
+
/* @__PURE__ */ r.jsx("option", { value: "large", children: "Large" }),
|
|
785
|
+
/* @__PURE__ */ r.jsx("option", { value: "extra-large", children: "Extra Large" })
|
|
786
|
+
]
|
|
787
|
+
}
|
|
788
|
+
) }),
|
|
789
|
+
/* @__PURE__ */ r.jsx("div", { className: "toolbar-separator" })
|
|
790
|
+
] }),
|
|
791
|
+
(n("textColor") || n("backgroundColor")) && /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
|
|
792
|
+
/* @__PURE__ */ r.jsxs("div", { className: "toolbar-group", children: [
|
|
793
|
+
n("textColor") && /* @__PURE__ */ r.jsx(xe, { editor: t, type: "text" }),
|
|
794
|
+
n("backgroundColor") && /* @__PURE__ */ r.jsx(xe, { editor: t, type: "background" })
|
|
795
|
+
] }),
|
|
796
|
+
/* @__PURE__ */ r.jsx("div", { className: "toolbar-separator" })
|
|
797
|
+
] }),
|
|
798
|
+
(n("link") || n("image") || n("table")) && /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
|
|
799
|
+
/* @__PURE__ */ r.jsxs("div", { className: "toolbar-group", children: [
|
|
800
|
+
n("link") && /* @__PURE__ */ r.jsx(
|
|
801
|
+
j,
|
|
802
|
+
{
|
|
803
|
+
onMouseDown: c,
|
|
804
|
+
title: "Insert Link",
|
|
805
|
+
children: /* @__PURE__ */ r.jsx(pt, {})
|
|
806
|
+
}
|
|
807
|
+
),
|
|
808
|
+
n("image") && /* @__PURE__ */ r.jsx(
|
|
809
|
+
j,
|
|
810
|
+
{
|
|
811
|
+
onMouseDown: () => s.current?.click(),
|
|
812
|
+
title: "Insert Image",
|
|
813
|
+
children: /* @__PURE__ */ r.jsx(gt, {})
|
|
814
|
+
}
|
|
815
|
+
),
|
|
816
|
+
n("table") && /* @__PURE__ */ r.jsx(kt, { editor: t })
|
|
817
|
+
] }),
|
|
818
|
+
/* @__PURE__ */ r.jsx("div", { className: "toolbar-separator" })
|
|
819
|
+
] }),
|
|
820
|
+
n("clear") && /* @__PURE__ */ r.jsx("div", { className: "toolbar-group", children: /* @__PURE__ */ r.jsx(
|
|
821
|
+
j,
|
|
822
|
+
{
|
|
823
|
+
onMouseDown: () => nt(t),
|
|
824
|
+
title: "Clear All Content",
|
|
825
|
+
className: "clear-button",
|
|
826
|
+
children: /* @__PURE__ */ r.jsx(vt, {})
|
|
827
|
+
}
|
|
828
|
+
) }),
|
|
829
|
+
/* @__PURE__ */ r.jsx(
|
|
830
|
+
"input",
|
|
831
|
+
{
|
|
832
|
+
ref: s,
|
|
833
|
+
type: "file",
|
|
834
|
+
accept: "image/*",
|
|
835
|
+
onChange: a,
|
|
836
|
+
style: { display: "none" }
|
|
837
|
+
}
|
|
838
|
+
)
|
|
839
|
+
] });
|
|
840
|
+
}, yt = ({ attributes: e, children: t, element: s, editor: n }) => {
|
|
841
|
+
const a = Pe(), c = De(), [o, i] = M(!1), d = se(), x = y((h) => {
|
|
842
|
+
h.preventDefault(), h.stopPropagation(), i(!0);
|
|
843
|
+
const p = h.clientX, C = d.current.offsetWidth;
|
|
844
|
+
d.current.naturalHeight / d.current.naturalWidth;
|
|
845
|
+
const z = (N) => {
|
|
846
|
+
const R = N.clientX - p, W = Math.max(100, Math.min(1200, C + R));
|
|
847
|
+
d.current.style.width = `${W}px`, d.current.style.height = "auto";
|
|
848
|
+
}, E = () => {
|
|
849
|
+
i(!1);
|
|
850
|
+
const N = d.current.offsetWidth;
|
|
851
|
+
try {
|
|
852
|
+
const R = he.findPath(n, s);
|
|
853
|
+
g.setNodes(
|
|
854
|
+
n,
|
|
855
|
+
{
|
|
856
|
+
width: N,
|
|
857
|
+
height: "auto"
|
|
858
|
+
},
|
|
859
|
+
{ at: R }
|
|
860
|
+
);
|
|
861
|
+
} catch (R) {
|
|
862
|
+
console.warn("Could not update image dimensions:", R);
|
|
863
|
+
}
|
|
864
|
+
document.removeEventListener("mousemove", z), document.removeEventListener("mouseup", E);
|
|
865
|
+
};
|
|
866
|
+
document.addEventListener("mousemove", z), document.addEventListener("mouseup", E);
|
|
867
|
+
}, [n, s]), b = y((h) => {
|
|
868
|
+
h.preventDefault(), h.stopPropagation();
|
|
869
|
+
try {
|
|
870
|
+
const p = he.findPath(n, s);
|
|
871
|
+
g.removeNodes(n, { at: p });
|
|
872
|
+
} catch (p) {
|
|
873
|
+
console.warn("Could not delete image:", p);
|
|
874
|
+
}
|
|
875
|
+
}, [n, s]), f = s.width || 300;
|
|
876
|
+
return /* @__PURE__ */ r.jsxs("div", { ...e, children: [
|
|
877
|
+
t,
|
|
878
|
+
/* @__PURE__ */ r.jsx(
|
|
879
|
+
"div",
|
|
880
|
+
{
|
|
881
|
+
contentEditable: !1,
|
|
882
|
+
className: `image-container ${a && c ? "selected" : ""}`,
|
|
883
|
+
style: {
|
|
884
|
+
display: "block",
|
|
885
|
+
position: "relative",
|
|
886
|
+
margin: "16px 0",
|
|
887
|
+
textAlign: "center"
|
|
888
|
+
},
|
|
889
|
+
children: /* @__PURE__ */ r.jsxs("div", { style: { display: "inline-block", position: "relative" }, children: [
|
|
890
|
+
/* @__PURE__ */ r.jsx(
|
|
891
|
+
"img",
|
|
892
|
+
{
|
|
893
|
+
ref: d,
|
|
894
|
+
src: s.url,
|
|
895
|
+
alt: s.alt || "",
|
|
896
|
+
className: "resizable-image",
|
|
897
|
+
style: {
|
|
898
|
+
width: `${f}px`,
|
|
899
|
+
height: "auto",
|
|
900
|
+
maxWidth: "100%",
|
|
901
|
+
display: "block",
|
|
902
|
+
borderRadius: "4px",
|
|
903
|
+
boxShadow: a && c ? "0 0 0 3px #3b82f6" : "0 1px 3px rgba(0, 0, 0, 0.1)",
|
|
904
|
+
transition: o ? "none" : "box-shadow 0.15s ease",
|
|
905
|
+
userSelect: "none"
|
|
906
|
+
},
|
|
907
|
+
draggable: !1
|
|
908
|
+
}
|
|
909
|
+
),
|
|
910
|
+
a && c && /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
|
|
911
|
+
/* @__PURE__ */ r.jsx(
|
|
912
|
+
"div",
|
|
913
|
+
{
|
|
914
|
+
className: "resize-handle",
|
|
915
|
+
onMouseDown: x,
|
|
916
|
+
style: {
|
|
917
|
+
position: "absolute",
|
|
918
|
+
bottom: "-6px",
|
|
919
|
+
right: "-6px",
|
|
920
|
+
width: "16px",
|
|
921
|
+
height: "16px",
|
|
922
|
+
background: "#3b82f6",
|
|
923
|
+
border: "2px solid white",
|
|
924
|
+
cursor: "nwse-resize",
|
|
925
|
+
borderRadius: "50%",
|
|
926
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.3)",
|
|
927
|
+
zIndex: 10
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
),
|
|
931
|
+
/* @__PURE__ */ r.jsx(
|
|
932
|
+
"button",
|
|
933
|
+
{
|
|
934
|
+
className: "delete-button",
|
|
935
|
+
onMouseDown: b,
|
|
936
|
+
title: "Delete image",
|
|
937
|
+
type: "button",
|
|
938
|
+
style: {
|
|
939
|
+
position: "absolute",
|
|
940
|
+
top: "-10px",
|
|
941
|
+
right: "-10px",
|
|
942
|
+
width: "24px",
|
|
943
|
+
height: "24px",
|
|
944
|
+
background: "#ef4444",
|
|
945
|
+
color: "white",
|
|
946
|
+
border: "none",
|
|
947
|
+
borderRadius: "50%",
|
|
948
|
+
cursor: "pointer",
|
|
949
|
+
fontSize: "18px",
|
|
950
|
+
fontWeight: "bold",
|
|
951
|
+
lineHeight: "1",
|
|
952
|
+
display: "flex",
|
|
953
|
+
alignItems: "center",
|
|
954
|
+
justifyContent: "center",
|
|
955
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.3)",
|
|
956
|
+
zIndex: 11,
|
|
957
|
+
padding: 0
|
|
958
|
+
},
|
|
959
|
+
children: "×"
|
|
960
|
+
}
|
|
961
|
+
)
|
|
962
|
+
] })
|
|
963
|
+
] })
|
|
964
|
+
}
|
|
965
|
+
)
|
|
966
|
+
] });
|
|
967
|
+
}, Ct = ({ attributes: e, children: t, element: s }) => {
|
|
968
|
+
const n = { textAlign: s.align };
|
|
969
|
+
switch (s.type) {
|
|
970
|
+
case "heading-one":
|
|
971
|
+
return /* @__PURE__ */ r.jsx("h1", { ...e, style: n, className: "heading-one", children: t });
|
|
972
|
+
case "heading-two":
|
|
973
|
+
return /* @__PURE__ */ r.jsx("h2", { ...e, style: n, className: "heading-two", children: t });
|
|
974
|
+
case "heading-three":
|
|
975
|
+
return /* @__PURE__ */ r.jsx("h3", { ...e, style: n, className: "heading-three", children: t });
|
|
976
|
+
case "blockquote":
|
|
977
|
+
return /* @__PURE__ */ r.jsx("blockquote", { ...e, style: n, className: "blockquote", children: t });
|
|
978
|
+
case "bulleted-list":
|
|
979
|
+
return /* @__PURE__ */ r.jsx("ul", { ...e, style: n, className: "bulleted-list", children: t });
|
|
980
|
+
case "numbered-list":
|
|
981
|
+
return /* @__PURE__ */ r.jsx("ol", { ...e, style: n, className: "numbered-list", children: t });
|
|
982
|
+
case "list-item":
|
|
983
|
+
return /* @__PURE__ */ r.jsx("li", { ...e, className: "list-item", children: t });
|
|
984
|
+
case "link":
|
|
985
|
+
return /* @__PURE__ */ r.jsx("a", { ...e, href: s.url, className: "link", children: t });
|
|
986
|
+
case "image":
|
|
987
|
+
return /* @__PURE__ */ r.jsx(yt, { attributes: e, children: t, element: s, editor: re() });
|
|
988
|
+
case "table":
|
|
989
|
+
return /* @__PURE__ */ r.jsx("div", { ...e, className: "table-container", children: /* @__PURE__ */ r.jsx("table", { className: "simple-table", children: /* @__PURE__ */ r.jsx("tbody", { children: t }) }) });
|
|
990
|
+
case "table-row":
|
|
991
|
+
return /* @__PURE__ */ r.jsx("tr", { ...e, className: "table-row", children: t });
|
|
992
|
+
case "table-cell":
|
|
993
|
+
return /* @__PURE__ */ r.jsx("td", { ...e, className: `table-cell ${s.header ? "table-header-cell" : ""}`, children: t });
|
|
994
|
+
default:
|
|
995
|
+
return /* @__PURE__ */ r.jsx("p", { ...e, style: n, className: "paragraph", children: t });
|
|
996
|
+
}
|
|
997
|
+
}, Nt = ({ attributes: e, children: t, leaf: s }) => {
|
|
998
|
+
let n = "", a = {};
|
|
999
|
+
return s.bold && (n += " bold"), s.italic && (n += " italic"), s.underline && (n += " underline"), s.strikethrough && (n += " strikethrough"), s["font-size-small"] && (n += " font-size-small"), s["font-size-large"] && (n += " font-size-large"), s["font-size-extra-large"] && (n += " font-size-extra-large"), s.color && (a.color = s.color), s.backgroundColor && (a.backgroundColor = s.backgroundColor), /* @__PURE__ */ r.jsx("span", { ...e, className: n.trim(), style: a, children: t });
|
|
1000
|
+
}, Et = ({ target: e, search: t, onClose: s }) => {
|
|
1001
|
+
const n = re(), a = se(), [c, o] = M(0), d = [
|
|
1002
|
+
{
|
|
1003
|
+
title: "Heading 1",
|
|
1004
|
+
description: "Big section heading",
|
|
1005
|
+
icon: "H1",
|
|
1006
|
+
command: () => x(n, "heading-one")
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
title: "Heading 2",
|
|
1010
|
+
description: "Medium section heading",
|
|
1011
|
+
icon: "H2",
|
|
1012
|
+
command: () => x(n, "heading-two")
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
title: "Heading 3",
|
|
1016
|
+
description: "Small section heading",
|
|
1017
|
+
icon: "H3",
|
|
1018
|
+
command: () => x(n, "heading-three")
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
title: "Bulleted List",
|
|
1022
|
+
description: "Create a simple bulleted list",
|
|
1023
|
+
icon: "•",
|
|
1024
|
+
command: () => x(n, "bulleted-list")
|
|
1025
|
+
},
|
|
1026
|
+
{
|
|
1027
|
+
title: "Numbered List",
|
|
1028
|
+
description: "Create a list with numbering",
|
|
1029
|
+
icon: "1.",
|
|
1030
|
+
command: () => x(n, "numbered-list")
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
title: "Quote",
|
|
1034
|
+
description: "Capture a quote",
|
|
1035
|
+
icon: '"',
|
|
1036
|
+
command: () => x(n, "blockquote")
|
|
1037
|
+
},
|
|
1038
|
+
{
|
|
1039
|
+
title: "Table",
|
|
1040
|
+
description: "Insert a table",
|
|
1041
|
+
icon: "⊞",
|
|
1042
|
+
command: () => {
|
|
1043
|
+
b(n, e), je(n, 3, 3), s();
|
|
1044
|
+
}
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
title: "Image",
|
|
1048
|
+
description: "Upload or embed an image",
|
|
1049
|
+
icon: "🖼",
|
|
1050
|
+
command: () => {
|
|
1051
|
+
b(n, e);
|
|
1052
|
+
const f = document.createElement("input");
|
|
1053
|
+
f.type = "file", f.accept = "image/*", f.onchange = (h) => {
|
|
1054
|
+
const p = h.target.files[0];
|
|
1055
|
+
if (p) {
|
|
1056
|
+
const C = new FileReader();
|
|
1057
|
+
C.onload = (z) => {
|
|
1058
|
+
ke(n, z.target.result);
|
|
1059
|
+
}, C.readAsDataURL(p);
|
|
1060
|
+
}
|
|
1061
|
+
}, f.click(), s();
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
].filter(
|
|
1065
|
+
(f) => f.title.toLowerCase().includes(t.toLowerCase()) || f.description.toLowerCase().includes(t.toLowerCase())
|
|
1066
|
+
), x = (f, h) => {
|
|
1067
|
+
b(f, e);
|
|
1068
|
+
const p = { type: h };
|
|
1069
|
+
h === "bulleted-list" || h === "numbered-list" ? (g.setNodes(f, { type: "list-item" }), g.wrapNodes(f, { type: h, children: [] })) : g.setNodes(f, p), s();
|
|
1070
|
+
}, b = (f, h) => {
|
|
1071
|
+
g.select(f, h), g.delete(f);
|
|
1072
|
+
};
|
|
1073
|
+
return U(() => {
|
|
1074
|
+
o(0);
|
|
1075
|
+
}, [t]), U(() => {
|
|
1076
|
+
const f = (h) => {
|
|
1077
|
+
h.key === "ArrowDown" ? (h.preventDefault(), o(
|
|
1078
|
+
(p) => p < d.length - 1 ? p + 1 : 0
|
|
1079
|
+
)) : h.key === "ArrowUp" ? (h.preventDefault(), o(
|
|
1080
|
+
(p) => p > 0 ? p - 1 : d.length - 1
|
|
1081
|
+
)) : h.key === "Enter" ? (h.preventDefault(), d[c] && d[c].command()) : h.key === "Escape" && (h.preventDefault(), s());
|
|
1082
|
+
};
|
|
1083
|
+
return document.addEventListener("keydown", f), () => document.removeEventListener("keydown", f);
|
|
1084
|
+
}, [c, d, s]), d.length === 0 ? null : /* @__PURE__ */ r.jsx("div", { ref: a, className: "slash-menu", children: d.map((f, h) => /* @__PURE__ */ r.jsxs(
|
|
1085
|
+
"div",
|
|
1086
|
+
{
|
|
1087
|
+
className: `slash-menu-item ${h === c ? "selected" : ""}`,
|
|
1088
|
+
onClick: f.command,
|
|
1089
|
+
children: [
|
|
1090
|
+
/* @__PURE__ */ r.jsx("div", { className: "slash-menu-icon", children: f.icon }),
|
|
1091
|
+
/* @__PURE__ */ r.jsxs("div", { className: "slash-menu-content", children: [
|
|
1092
|
+
/* @__PURE__ */ r.jsx("div", { className: "slash-menu-title", children: f.title }),
|
|
1093
|
+
/* @__PURE__ */ r.jsx("div", { className: "slash-menu-description", children: f.description })
|
|
1094
|
+
] })
|
|
1095
|
+
]
|
|
1096
|
+
},
|
|
1097
|
+
f.title
|
|
1098
|
+
)) });
|
|
1099
|
+
}, zt = (e) => {
|
|
1100
|
+
const { insertData: t, isVoid: s } = e;
|
|
1101
|
+
return e.isVoid = (n) => n.type === "image" ? !0 : s(n), e.insertData = (n) => {
|
|
1102
|
+
const a = n.getData("text/plain"), { files: c } = n;
|
|
1103
|
+
if (c && c.length > 0)
|
|
1104
|
+
for (const o of c) {
|
|
1105
|
+
const i = new FileReader(), [d] = o.type.split("/");
|
|
1106
|
+
d === "image" && (i.addEventListener("load", () => {
|
|
1107
|
+
const x = i.result;
|
|
1108
|
+
ve(e, x);
|
|
1109
|
+
}), i.readAsDataURL(o));
|
|
1110
|
+
}
|
|
1111
|
+
else Je(a) ? ve(e, a) : t(n);
|
|
1112
|
+
}, e;
|
|
1113
|
+
}, ve = (e, t) => {
|
|
1114
|
+
const n = { type: "image", url: t, children: [{ text: "" }] };
|
|
1115
|
+
g.insertNodes(e, n);
|
|
1116
|
+
}, Mt = (e) => {
|
|
1117
|
+
const { deleteBackward: t, deleteForward: s, insertBreak: n } = e;
|
|
1118
|
+
return e.deleteBackward = (...a) => {
|
|
1119
|
+
const { selection: c } = e;
|
|
1120
|
+
if (c && A.isCollapsed(c)) {
|
|
1121
|
+
const [o] = u.nodes(e, {
|
|
1122
|
+
match: (i) => i.type === "table-cell"
|
|
1123
|
+
});
|
|
1124
|
+
if (o) {
|
|
1125
|
+
const [, i] = o, d = u.start(e, i);
|
|
1126
|
+
if (ue.equals(c.anchor, d))
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
t(...a);
|
|
1131
|
+
}, e.deleteForward = (...a) => {
|
|
1132
|
+
const { selection: c } = e;
|
|
1133
|
+
if (c && A.isCollapsed(c)) {
|
|
1134
|
+
const [o] = u.nodes(e, {
|
|
1135
|
+
match: (i) => i.type === "table-cell"
|
|
1136
|
+
});
|
|
1137
|
+
if (o) {
|
|
1138
|
+
const [, i] = o, d = u.end(e, i);
|
|
1139
|
+
if (ue.equals(c.anchor, d))
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
s(...a);
|
|
1144
|
+
}, e.insertBreak = (...a) => {
|
|
1145
|
+
const { selection: c } = e;
|
|
1146
|
+
if (c) {
|
|
1147
|
+
const [o] = u.nodes(e, {
|
|
1148
|
+
match: (i) => i.type === "table"
|
|
1149
|
+
});
|
|
1150
|
+
if (o)
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
n(...a);
|
|
1154
|
+
}, e;
|
|
1155
|
+
}, Rt = (e) => {
|
|
1156
|
+
const { insertData: t, insertText: s, isInline: n } = e;
|
|
1157
|
+
return e.isInline = (a) => a.type === "link" ? !0 : n(a), e.insertText = (a) => {
|
|
1158
|
+
a && be(a) ? we(e, a) : s(a);
|
|
1159
|
+
}, e.insertData = (a) => {
|
|
1160
|
+
const c = a.getData("text/plain");
|
|
1161
|
+
c && be(c) ? we(e, c) : t(a);
|
|
1162
|
+
}, e;
|
|
1163
|
+
}, be = (e) => {
|
|
1164
|
+
try {
|
|
1165
|
+
return new URL(e), !0;
|
|
1166
|
+
} catch {
|
|
1167
|
+
return !1;
|
|
1168
|
+
}
|
|
1169
|
+
}, we = (e, t) => {
|
|
1170
|
+
_t(e) && Tt(e);
|
|
1171
|
+
const { selection: s } = e, n = s && A.isCollapsed(s), a = {
|
|
1172
|
+
type: "link",
|
|
1173
|
+
url: t,
|
|
1174
|
+
children: n ? [{ text: t }] : []
|
|
1175
|
+
};
|
|
1176
|
+
n ? g.insertNodes(e, a) : (g.wrapNodes(e, a, { split: !0 }), g.collapse(e, { edge: "end" }));
|
|
1177
|
+
}, Tt = (e) => {
|
|
1178
|
+
g.unwrapNodes(e, {
|
|
1179
|
+
match: (t) => t.type === "link"
|
|
1180
|
+
});
|
|
1181
|
+
}, _t = (e) => {
|
|
1182
|
+
const [t] = u.nodes(e, {
|
|
1183
|
+
match: (s) => s.type === "link"
|
|
1184
|
+
});
|
|
1185
|
+
return !!t;
|
|
1186
|
+
}, At = (e) => e.map((t) => ye(t)).join(""), ye = (e) => {
|
|
1187
|
+
if (He.isText(e)) {
|
|
1188
|
+
let s = D(e.text);
|
|
1189
|
+
return e.bold && (s = `<strong>${s}</strong>`), e.italic && (s = `<em>${s}</em>`), e.underline && (s = `<u>${s}</u>`), e.strikethrough && (s = `<s>${s}</s>`), e["font-size-small"] ? s = `<span style="font-size: 12px;">${s}</span>` : e["font-size-large"] ? s = `<span style="font-size: 16px;">${s}</span>` : e["font-size-extra-large"] && (s = `<span style="font-size: 18px;">${s}</span>`), e.color && (s = `<span style="color: ${e.color};">${s}</span>`), e.backgroundColor && (s = `<span style="background-color: ${e.backgroundColor};">${s}</span>`), s;
|
|
1190
|
+
}
|
|
1191
|
+
const t = e.children.map((s) => ye(s)).join("");
|
|
1192
|
+
switch (e.type) {
|
|
1193
|
+
case "paragraph":
|
|
1194
|
+
return `<p${H(e)}>${t}</p>`;
|
|
1195
|
+
case "heading-one":
|
|
1196
|
+
return `<h1${H(e)}>${t}</h1>`;
|
|
1197
|
+
case "heading-two":
|
|
1198
|
+
return `<h2${H(e)}>${t}</h2>`;
|
|
1199
|
+
case "heading-three":
|
|
1200
|
+
return `<h3${H(e)}>${t}</h3>`;
|
|
1201
|
+
case "blockquote":
|
|
1202
|
+
return `<blockquote${H(e)}>${t}</blockquote>`;
|
|
1203
|
+
case "bulleted-list":
|
|
1204
|
+
return `<ul>${t}</ul>`;
|
|
1205
|
+
case "numbered-list":
|
|
1206
|
+
return `<ol>${t}</ol>`;
|
|
1207
|
+
case "list-item":
|
|
1208
|
+
return `<li>${t}</li>`;
|
|
1209
|
+
case "link":
|
|
1210
|
+
return `<a href="${D(e.url)}">${t}</a>`;
|
|
1211
|
+
case "image":
|
|
1212
|
+
const s = e.width ? `width: ${e.width}px; ` : "";
|
|
1213
|
+
return `<img src="${D(e.url)}" alt="${D(e.alt || "")}" style="${s}max-width: 100%; height: auto;" />`;
|
|
1214
|
+
case "table":
|
|
1215
|
+
return `<table border="1" style="border-collapse: collapse; width: 100%;">${t}</table>`;
|
|
1216
|
+
case "table-row":
|
|
1217
|
+
return `<tr>${t}</tr>`;
|
|
1218
|
+
case "table-cell":
|
|
1219
|
+
const n = e.header ? "th" : "td";
|
|
1220
|
+
return `<${n} style="border: 1px solid #ccc; padding: 8px;">${t}</${n}>`;
|
|
1221
|
+
default:
|
|
1222
|
+
return t;
|
|
1223
|
+
}
|
|
1224
|
+
}, H = (e) => e.align ? ` style="text-align: ${e.align};"` : "", St = (e) => {
|
|
1225
|
+
const t = new DOMParser().parseFromString(e, "text/html");
|
|
1226
|
+
return Ce(t.body.childNodes);
|
|
1227
|
+
}, Ce = (e) => {
|
|
1228
|
+
const t = [];
|
|
1229
|
+
for (const s of e) {
|
|
1230
|
+
const n = $t(s);
|
|
1231
|
+
n && (Array.isArray(n) ? t.push(...n) : t.push(n));
|
|
1232
|
+
}
|
|
1233
|
+
return t.length > 0 ? t : [{ type: "paragraph", children: [{ text: "" }] }];
|
|
1234
|
+
}, $t = (e) => {
|
|
1235
|
+
if (e.nodeType === Node.TEXT_NODE)
|
|
1236
|
+
return { text: e.textContent };
|
|
1237
|
+
if (e.nodeType !== Node.ELEMENT_NODE)
|
|
1238
|
+
return null;
|
|
1239
|
+
const t = Ce(e.childNodes), s = { children: t }, n = e.getAttribute("style");
|
|
1240
|
+
if (n && n.includes("text-align:")) {
|
|
1241
|
+
const a = n.match(/text-align:\s*([^;]+)/);
|
|
1242
|
+
a && (s.align = a[1].trim());
|
|
1243
|
+
}
|
|
1244
|
+
switch (e.nodeName.toLowerCase()) {
|
|
1245
|
+
case "p":
|
|
1246
|
+
return { ...s, type: "paragraph" };
|
|
1247
|
+
case "h1":
|
|
1248
|
+
return { ...s, type: "heading-one" };
|
|
1249
|
+
case "h2":
|
|
1250
|
+
return { ...s, type: "heading-two" };
|
|
1251
|
+
case "h3":
|
|
1252
|
+
return { ...s, type: "heading-three" };
|
|
1253
|
+
case "blockquote":
|
|
1254
|
+
return { ...s, type: "blockquote" };
|
|
1255
|
+
case "ul":
|
|
1256
|
+
return { ...s, type: "bulleted-list" };
|
|
1257
|
+
case "ol":
|
|
1258
|
+
return { ...s, type: "numbered-list" };
|
|
1259
|
+
case "li":
|
|
1260
|
+
return { ...s, type: "list-item" };
|
|
1261
|
+
case "a":
|
|
1262
|
+
return { ...s, type: "link", url: e.getAttribute("href") };
|
|
1263
|
+
case "img":
|
|
1264
|
+
const a = e.getAttribute("style");
|
|
1265
|
+
let c = 300;
|
|
1266
|
+
if (a && a.includes("width:")) {
|
|
1267
|
+
const o = a.match(/width:\s*(\d+)px/);
|
|
1268
|
+
o && (c = parseInt(o[1]));
|
|
1269
|
+
}
|
|
1270
|
+
return {
|
|
1271
|
+
type: "image",
|
|
1272
|
+
url: e.getAttribute("src"),
|
|
1273
|
+
alt: e.getAttribute("alt") || "",
|
|
1274
|
+
width: c,
|
|
1275
|
+
children: [{ text: "" }]
|
|
1276
|
+
};
|
|
1277
|
+
case "table":
|
|
1278
|
+
return { ...s, type: "table" };
|
|
1279
|
+
case "tr":
|
|
1280
|
+
return { ...s, type: "table-row" };
|
|
1281
|
+
case "td":
|
|
1282
|
+
return { ...s, type: "table-cell" };
|
|
1283
|
+
case "th":
|
|
1284
|
+
return { ...s, type: "table-cell", header: !0 };
|
|
1285
|
+
case "strong":
|
|
1286
|
+
case "b":
|
|
1287
|
+
return F(t, "bold");
|
|
1288
|
+
case "em":
|
|
1289
|
+
case "i":
|
|
1290
|
+
return F(t, "italic");
|
|
1291
|
+
case "u":
|
|
1292
|
+
return F(t, "underline");
|
|
1293
|
+
case "s":
|
|
1294
|
+
case "strike":
|
|
1295
|
+
return F(t, "strikethrough");
|
|
1296
|
+
case "span":
|
|
1297
|
+
return Lt(e, t);
|
|
1298
|
+
case "br":
|
|
1299
|
+
return { text: `
|
|
1300
|
+
` };
|
|
1301
|
+
case "div":
|
|
1302
|
+
return t.length > 0 ? { ...s, type: "paragraph" } : null;
|
|
1303
|
+
default:
|
|
1304
|
+
return t;
|
|
1305
|
+
}
|
|
1306
|
+
}, F = (e, t) => e.map((s) => s.text !== void 0 ? { ...s, [t]: !0 } : s), Lt = (e, t) => {
|
|
1307
|
+
const s = e.getAttribute("style");
|
|
1308
|
+
let n = {};
|
|
1309
|
+
if (s) {
|
|
1310
|
+
s.includes("font-size: 12px") ? n["font-size-small"] = !0 : s.includes("font-size: 16px") ? n["font-size-large"] = !0 : s.includes("font-size: 18px") && (n["font-size-extra-large"] = !0);
|
|
1311
|
+
const a = s.match(/color:\s*([^;]+)/);
|
|
1312
|
+
a && (n.color = a[1].trim());
|
|
1313
|
+
const c = s.match(/background-color:\s*([^;]+)/);
|
|
1314
|
+
c && (n.backgroundColor = c[1].trim());
|
|
1315
|
+
}
|
|
1316
|
+
return Object.keys(n).length > 0 ? t.map((a) => a.text !== void 0 ? { ...a, ...n } : a) : t;
|
|
1317
|
+
}, Ht = (e, t, s) => {
|
|
1318
|
+
const [n, a] = M(() => t ? typeof t == "string" ? St(t) : t : e || [
|
|
1319
|
+
{
|
|
1320
|
+
type: "paragraph",
|
|
1321
|
+
children: [{ text: "" }]
|
|
1322
|
+
}
|
|
1323
|
+
]);
|
|
1324
|
+
return { editorValue: n, handleChange: (o, i) => {
|
|
1325
|
+
if (a(o), i && i(o), s) {
|
|
1326
|
+
const d = o.length === 1 && o[0].type === "paragraph" && o[0].children.length === 1 && o[0].children[0].text === "", x = d ? "" : At(o);
|
|
1327
|
+
s(x, d ? [] : o);
|
|
1328
|
+
}
|
|
1329
|
+
} };
|
|
1330
|
+
}, It = (e) => {
|
|
1331
|
+
const [t, s] = M(null), n = y((c) => {
|
|
1332
|
+
const { selection: o } = e;
|
|
1333
|
+
if (o && A.isCollapsed(o)) {
|
|
1334
|
+
const [i] = A.edges(o), d = u.before(e, i, { unit: "word" }), x = d && u.before(e, d), b = x && u.range(e, x, i), f = b && u.string(e, b), h = f && f.match(/\/(\w*)$/), p = u.after(e, i), C = u.range(e, i, p), E = u.string(e, C).match(/^(\s|$)/);
|
|
1335
|
+
s(h && E ? {
|
|
1336
|
+
target: b,
|
|
1337
|
+
search: h[1]
|
|
1338
|
+
} : null);
|
|
1339
|
+
} else
|
|
1340
|
+
s(null);
|
|
1341
|
+
}, [e]), a = y(() => {
|
|
1342
|
+
s(null);
|
|
1343
|
+
}, []);
|
|
1344
|
+
return { slashMenu: t, handleSlashMenu: n, closeSlashMenu: a };
|
|
1345
|
+
}, ee = (e, t) => {
|
|
1346
|
+
const s = u.marks(e);
|
|
1347
|
+
(s ? s[t] === !0 : !1) ? u.removeMark(e, t) : u.addMark(e, t, !0);
|
|
1348
|
+
}, Pt = (e) => y((t) => {
|
|
1349
|
+
if (t.ctrlKey)
|
|
1350
|
+
switch (t.key) {
|
|
1351
|
+
case "b": {
|
|
1352
|
+
t.preventDefault(), ee(e, "bold");
|
|
1353
|
+
break;
|
|
1354
|
+
}
|
|
1355
|
+
case "i": {
|
|
1356
|
+
t.preventDefault(), ee(e, "italic");
|
|
1357
|
+
break;
|
|
1358
|
+
}
|
|
1359
|
+
case "u": {
|
|
1360
|
+
t.preventDefault(), ee(e, "underline");
|
|
1361
|
+
break;
|
|
1362
|
+
}
|
|
1363
|
+
case "z": {
|
|
1364
|
+
t.shiftKey ? (t.preventDefault(), e.redo()) : (t.preventDefault(), e.undo());
|
|
1365
|
+
break;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}, [e]), Xt = ({
|
|
1369
|
+
value: e,
|
|
1370
|
+
onChange: t,
|
|
1371
|
+
placeholder: s = "Enter some text...",
|
|
1372
|
+
readOnly: n = !1,
|
|
1373
|
+
className: a = "",
|
|
1374
|
+
initialValue: c = null,
|
|
1375
|
+
features: o = ["bold", "italic", "underline", "fontSize"]
|
|
1376
|
+
// features = [
|
|
1377
|
+
// 'bold', 'italic', 'underline', 'strikethrough',
|
|
1378
|
+
// 'headings', 'lists', 'alignment', 'fontSize',
|
|
1379
|
+
// 'textColor', 'backgroundColor',
|
|
1380
|
+
// 'link', 'image', 'table', 'clear'
|
|
1381
|
+
// ]
|
|
1382
|
+
}) => {
|
|
1383
|
+
const i = Le(
|
|
1384
|
+
() => Rt(Mt(zt(Fe(Oe(Ie()))))),
|
|
1385
|
+
[]
|
|
1386
|
+
), { editorValue: d, handleChange: x } = Ht(
|
|
1387
|
+
e,
|
|
1388
|
+
c,
|
|
1389
|
+
t
|
|
1390
|
+
), { slashMenu: b, handleSlashMenu: f, closeSlashMenu: h } = It(i), p = Pt(i), C = y((N) => /* @__PURE__ */ r.jsx(Ct, { ...N }), []), z = y((N) => /* @__PURE__ */ r.jsx(Nt, { ...N }), []), E = y(
|
|
1391
|
+
(N) => {
|
|
1392
|
+
x(N, f);
|
|
1393
|
+
},
|
|
1394
|
+
[x, f]
|
|
1395
|
+
);
|
|
1396
|
+
return /* @__PURE__ */ r.jsx("div", { className: `scrible-editor ${a}`, children: /* @__PURE__ */ r.jsxs(Be, { editor: i, initialValue: d, onChange: E, children: [
|
|
1397
|
+
!n && /* @__PURE__ */ r.jsx(jt, { features: o }),
|
|
1398
|
+
/* @__PURE__ */ r.jsxs("div", { className: "editor-container", children: [
|
|
1399
|
+
/* @__PURE__ */ r.jsx(
|
|
1400
|
+
Ve,
|
|
1401
|
+
{
|
|
1402
|
+
renderElement: C,
|
|
1403
|
+
renderLeaf: z,
|
|
1404
|
+
placeholder: s,
|
|
1405
|
+
onKeyDown: p,
|
|
1406
|
+
readOnly: n,
|
|
1407
|
+
className: "editor-content"
|
|
1408
|
+
}
|
|
1409
|
+
),
|
|
1410
|
+
b && /* @__PURE__ */ r.jsx(
|
|
1411
|
+
Et,
|
|
1412
|
+
{
|
|
1413
|
+
target: b.target,
|
|
1414
|
+
search: b.search,
|
|
1415
|
+
onClose: h
|
|
1416
|
+
}
|
|
1417
|
+
)
|
|
1418
|
+
] })
|
|
1419
|
+
] }) });
|
|
1420
|
+
};
|
|
1421
|
+
export {
|
|
1422
|
+
Xt as ScribleEditor,
|
|
1423
|
+
Xt as default,
|
|
1424
|
+
Yt as deleteTableColumn,
|
|
1425
|
+
qt as deleteTableRow,
|
|
1426
|
+
St as deserialize,
|
|
1427
|
+
Xe as getBackgroundColor,
|
|
1428
|
+
Ye as getTextColor,
|
|
1429
|
+
ke as insertImage,
|
|
1430
|
+
Ke as insertLink,
|
|
1431
|
+
je as insertTable,
|
|
1432
|
+
Wt as insertTableColumn,
|
|
1433
|
+
Ut as insertTableRow,
|
|
1434
|
+
te as isBlockActive,
|
|
1435
|
+
Je as isImageUrl,
|
|
1436
|
+
et as isLinkActive,
|
|
1437
|
+
I as isMarkActive,
|
|
1438
|
+
At as serialize,
|
|
1439
|
+
Q as setBackgroundColor,
|
|
1440
|
+
K as setTextColor,
|
|
1441
|
+
B as toggleAlignment,
|
|
1442
|
+
Z as toggleBlock,
|
|
1443
|
+
L as toggleMark,
|
|
1444
|
+
Ze as unwrapLink,
|
|
1445
|
+
Qe as wrapLink
|
|
1446
|
+
};
|