@connectedxm/entity-editor 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +147 -160
- package/dist/src/Editor.d.ts +1 -0
- package/dist/src/helpers/dom.d.ts +1 -1
- package/dist/src/helpers/entities/Link.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import A, { useState as $e, useRef as me, useEffect as Ye } from "react";
|
|
2
2
|
var X = { exports: {} }, x = {};
|
|
3
|
-
/**
|
|
4
|
-
* @license React
|
|
5
|
-
* react-jsx-runtime.production.js
|
|
6
|
-
*
|
|
7
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the MIT license found in the
|
|
10
|
-
* LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/
|
|
12
3
|
var Ae;
|
|
13
4
|
function Fe() {
|
|
14
5
|
if (Ae) return x;
|
|
@@ -32,22 +23,13 @@ function Fe() {
|
|
|
32
23
|
return x.Fragment = t, x.jsx = n, x.jsxs = n, x;
|
|
33
24
|
}
|
|
34
25
|
var L = {};
|
|
35
|
-
/**
|
|
36
|
-
* @license React
|
|
37
|
-
* react-jsx-runtime.development.js
|
|
38
|
-
*
|
|
39
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
40
|
-
*
|
|
41
|
-
* This source code is licensed under the MIT license found in the
|
|
42
|
-
* LICENSE file in the root directory of this source tree.
|
|
43
|
-
*/
|
|
44
26
|
var Oe;
|
|
45
27
|
function We() {
|
|
46
28
|
return Oe || (Oe = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
47
29
|
function e(r) {
|
|
48
30
|
if (r == null) return null;
|
|
49
31
|
if (typeof r == "function")
|
|
50
|
-
return r.$$typeof ===
|
|
32
|
+
return r.$$typeof === V ? null : r.displayName || r.name || null;
|
|
51
33
|
if (typeof r == "string") return r;
|
|
52
34
|
switch (r) {
|
|
53
35
|
case O:
|
|
@@ -60,14 +42,14 @@ function We() {
|
|
|
60
42
|
return "Suspense";
|
|
61
43
|
case U:
|
|
62
44
|
return "SuspenseList";
|
|
63
|
-
case
|
|
45
|
+
case z:
|
|
64
46
|
return "Activity";
|
|
65
47
|
}
|
|
66
48
|
if (typeof r == "object")
|
|
67
49
|
switch (typeof r.tag == "number" && console.error(
|
|
68
50
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
69
51
|
), r.$$typeof) {
|
|
70
|
-
case
|
|
52
|
+
case b:
|
|
71
53
|
return "Portal";
|
|
72
54
|
case K:
|
|
73
55
|
return (r.displayName || "Context") + ".Provider";
|
|
@@ -76,9 +58,9 @@ function We() {
|
|
|
76
58
|
case ue:
|
|
77
59
|
var l = r.render;
|
|
78
60
|
return r = r.displayName, r || (r = l.displayName || l.name || "", r = r !== "" ? "ForwardRef(" + r + ")" : "ForwardRef"), r;
|
|
79
|
-
case
|
|
61
|
+
case w:
|
|
80
62
|
return l = r.displayName || null, l !== null ? l : e(r.type) || "Memo";
|
|
81
|
-
case
|
|
63
|
+
case I:
|
|
82
64
|
l = r._payload, r = r._init;
|
|
83
65
|
try {
|
|
84
66
|
return e(r(l));
|
|
@@ -99,17 +81,17 @@ function We() {
|
|
|
99
81
|
}
|
|
100
82
|
if (l) {
|
|
101
83
|
l = console;
|
|
102
|
-
var d = l.error,
|
|
84
|
+
var d = l.error, R = typeof Symbol == "function" && Symbol.toStringTag && r[Symbol.toStringTag] || r.constructor.name || "Object";
|
|
103
85
|
return d.call(
|
|
104
86
|
l,
|
|
105
87
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
106
|
-
|
|
88
|
+
R
|
|
107
89
|
), t(r);
|
|
108
90
|
}
|
|
109
91
|
}
|
|
110
92
|
function s(r) {
|
|
111
93
|
if (r === O) return "<>";
|
|
112
|
-
if (typeof r == "object" && r !== null && r.$$typeof ===
|
|
94
|
+
if (typeof r == "object" && r !== null && r.$$typeof === I)
|
|
113
95
|
return "<...>";
|
|
114
96
|
try {
|
|
115
97
|
var l = e(r);
|
|
@@ -119,7 +101,7 @@ function We() {
|
|
|
119
101
|
}
|
|
120
102
|
}
|
|
121
103
|
function o() {
|
|
122
|
-
var r =
|
|
104
|
+
var r = M.A;
|
|
123
105
|
return r === null ? null : r.getOwner();
|
|
124
106
|
}
|
|
125
107
|
function i() {
|
|
@@ -150,13 +132,13 @@ function We() {
|
|
|
150
132
|
"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."
|
|
151
133
|
)), r = this.props.ref, r !== void 0 ? r : null;
|
|
152
134
|
}
|
|
153
|
-
function m(r, l, d,
|
|
154
|
-
return d =
|
|
155
|
-
$$typeof:
|
|
135
|
+
function m(r, l, d, R, _, v, de, Ee) {
|
|
136
|
+
return d = v.ref, r = {
|
|
137
|
+
$$typeof: j,
|
|
156
138
|
type: r,
|
|
157
139
|
key: l,
|
|
158
|
-
props:
|
|
159
|
-
_owner:
|
|
140
|
+
props: v,
|
|
141
|
+
_owner: _
|
|
160
142
|
}, (d !== void 0 ? d : null) !== null ? Object.defineProperty(r, "ref", {
|
|
161
143
|
enumerable: !1,
|
|
162
144
|
get: f
|
|
@@ -182,13 +164,13 @@ function We() {
|
|
|
182
164
|
value: Ee
|
|
183
165
|
}), Object.freeze && (Object.freeze(r.props), Object.freeze(r)), r;
|
|
184
166
|
}
|
|
185
|
-
function N(r, l, d,
|
|
167
|
+
function N(r, l, d, R, _, v, de, Ee) {
|
|
186
168
|
var k = l.children;
|
|
187
169
|
if (k !== void 0)
|
|
188
|
-
if (
|
|
170
|
+
if (R)
|
|
189
171
|
if (fe(k)) {
|
|
190
|
-
for (
|
|
191
|
-
p(k[
|
|
172
|
+
for (R = 0; R < k.length; R++)
|
|
173
|
+
p(k[R]);
|
|
192
174
|
Object.freeze && Object.freeze(k);
|
|
193
175
|
} else
|
|
194
176
|
console.error(
|
|
@@ -197,21 +179,21 @@ function We() {
|
|
|
197
179
|
else p(k);
|
|
198
180
|
if (G.call(l, "key")) {
|
|
199
181
|
k = e(r);
|
|
200
|
-
var
|
|
201
|
-
return
|
|
182
|
+
var P = Object.keys(l).filter(function(De) {
|
|
183
|
+
return De !== "key";
|
|
202
184
|
});
|
|
203
|
-
|
|
185
|
+
R = 0 < P.length ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}", h[k + R] || (P = 0 < P.length ? "{" + P.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
204
186
|
`A props object containing a "key" prop is being spread into JSX:
|
|
205
187
|
let props = %s;
|
|
206
188
|
<%s {...props} />
|
|
207
189
|
React keys must be passed directly to JSX without using spread:
|
|
208
190
|
let props = %s;
|
|
209
191
|
<%s key={someKey} {...props} />`,
|
|
210
|
-
|
|
192
|
+
R,
|
|
211
193
|
k,
|
|
212
|
-
|
|
194
|
+
P,
|
|
213
195
|
k
|
|
214
|
-
), h[k +
|
|
196
|
+
), h[k + R] = !0);
|
|
215
197
|
}
|
|
216
198
|
if (k = null, d !== void 0 && (n(d), k = "" + d), c(l) && (n(l.key), k = "" + l.key), "key" in l) {
|
|
217
199
|
d = {};
|
|
@@ -224,8 +206,8 @@ React keys must be passed directly to JSX without using spread:
|
|
|
224
206
|
), m(
|
|
225
207
|
r,
|
|
226
208
|
k,
|
|
227
|
-
|
|
228
|
-
|
|
209
|
+
v,
|
|
210
|
+
_,
|
|
229
211
|
o(),
|
|
230
212
|
d,
|
|
231
213
|
de,
|
|
@@ -233,43 +215,43 @@ React keys must be passed directly to JSX without using spread:
|
|
|
233
215
|
);
|
|
234
216
|
}
|
|
235
217
|
function p(r) {
|
|
236
|
-
typeof r == "object" && r !== null && r.$$typeof ===
|
|
218
|
+
typeof r == "object" && r !== null && r.$$typeof === j && r._store && (r._store.validated = 1);
|
|
237
219
|
}
|
|
238
|
-
var
|
|
220
|
+
var y = A, j = Symbol.for("react.transitional.element"), b = Symbol.for("react.portal"), O = Symbol.for("react.fragment"), le = Symbol.for("react.strict_mode"), F = Symbol.for("react.profiler"), W = Symbol.for("react.consumer"), K = Symbol.for("react.context"), ue = Symbol.for("react.forward_ref"), ae = Symbol.for("react.suspense"), U = Symbol.for("react.suspense_list"), w = Symbol.for("react.memo"), I = Symbol.for("react.lazy"), z = Symbol.for("react.activity"), V = Symbol.for("react.client.reference"), M = y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, G = Object.prototype.hasOwnProperty, fe = Array.isArray, T = console.createTask ? console.createTask : function() {
|
|
239
221
|
return null;
|
|
240
222
|
};
|
|
241
|
-
|
|
223
|
+
y = {
|
|
242
224
|
react_stack_bottom_frame: function(r) {
|
|
243
225
|
return r();
|
|
244
226
|
}
|
|
245
227
|
};
|
|
246
|
-
var J, a = {},
|
|
247
|
-
|
|
228
|
+
var J, a = {}, g = y.react_stack_bottom_frame.bind(
|
|
229
|
+
y,
|
|
248
230
|
i
|
|
249
|
-
)(), E =
|
|
250
|
-
L.Fragment = O, L.jsx = function(r, l, d,
|
|
251
|
-
var
|
|
231
|
+
)(), E = T(s(i)), h = {};
|
|
232
|
+
L.Fragment = O, L.jsx = function(r, l, d, R, _) {
|
|
233
|
+
var v = 1e4 > M.recentlyCreatedOwnerStacks++;
|
|
252
234
|
return N(
|
|
253
235
|
r,
|
|
254
236
|
l,
|
|
255
237
|
d,
|
|
256
238
|
!1,
|
|
257
|
-
g,
|
|
258
239
|
R,
|
|
259
|
-
|
|
260
|
-
|
|
240
|
+
_,
|
|
241
|
+
v ? Error("react-stack-top-frame") : g,
|
|
242
|
+
v ? T(s(r)) : E
|
|
261
243
|
);
|
|
262
|
-
}, L.jsxs = function(r, l, d,
|
|
263
|
-
var
|
|
244
|
+
}, L.jsxs = function(r, l, d, R, _) {
|
|
245
|
+
var v = 1e4 > M.recentlyCreatedOwnerStacks++;
|
|
264
246
|
return N(
|
|
265
247
|
r,
|
|
266
248
|
l,
|
|
267
249
|
d,
|
|
268
250
|
!0,
|
|
269
|
-
g,
|
|
270
251
|
R,
|
|
271
|
-
|
|
272
|
-
|
|
252
|
+
_,
|
|
253
|
+
v ? Error("react-stack-top-frame") : g,
|
|
254
|
+
v ? T(s(r)) : E
|
|
273
255
|
);
|
|
274
256
|
};
|
|
275
257
|
})()), L;
|
|
@@ -279,14 +261,14 @@ function Ke() {
|
|
|
279
261
|
return Ie || (Ie = 1, process.env.NODE_ENV === "production" ? X.exports = Fe() : X.exports = We()), X.exports;
|
|
280
262
|
}
|
|
281
263
|
var C = Ke();
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
if (!
|
|
285
|
-
if (
|
|
286
|
-
const n =
|
|
287
|
-
s.selectNodeContents(
|
|
264
|
+
const Ce = (e) => {
|
|
265
|
+
const t = window.getSelection();
|
|
266
|
+
if (!t || !e) return { start: 0, end: 0 };
|
|
267
|
+
if (t.anchorNode && e.contains(t.anchorNode)) {
|
|
268
|
+
const n = t.getRangeAt(0), s = n.cloneRange();
|
|
269
|
+
s.selectNodeContents(e), s.setEnd(n.startContainer, n.startOffset);
|
|
288
270
|
const o = s.toString().length, i = n.cloneRange();
|
|
289
|
-
i.selectNodeContents(
|
|
271
|
+
i.selectNodeContents(e), i.setEnd(n.endContainer, n.endOffset);
|
|
290
272
|
const c = i.toString().length;
|
|
291
273
|
return { start: o, end: c };
|
|
292
274
|
} else
|
|
@@ -314,31 +296,34 @@ const ye = () => {
|
|
|
314
296
|
const N = window.getSelection();
|
|
315
297
|
N?.removeAllRanges(), N?.addRange(m);
|
|
316
298
|
}
|
|
317
|
-
},
|
|
299
|
+
}, ze = (e, t, n) => {
|
|
318
300
|
let s = "", o = "", i = "", c = "";
|
|
319
301
|
t.includes("bold") && (o = "bold"), t.includes("italic") && (i = "italic"), (t.includes("underline") || e === "link") && (c += "underline"), t.includes("strike") && (c += " line-through"), e !== "segment" && (s = "#1da1f2", e === "mention" && n.mentionColor ? s = n.mentionColor : e === "interest" && n.interestColor ? s = n.interestColor : e === "link" && n.linkColor && (s = n.linkColor));
|
|
320
302
|
let u = "";
|
|
321
303
|
return s && (u += `color: ${s}; `), o && (u += `font-weight: ${o}; `), i && (u += `font-style: ${i}; `), c && (u += `text-decoration: ${c}; `), u;
|
|
322
|
-
},
|
|
304
|
+
}, ye = (e, t, n) => {
|
|
323
305
|
if (t.length === 0)
|
|
324
306
|
return e;
|
|
325
307
|
let s = "", o = 0;
|
|
326
308
|
return t.forEach((i) => {
|
|
327
309
|
o < i.startIndex && (s += e.slice(o, i.startIndex));
|
|
328
|
-
const c = e.slice(i.startIndex, i.endIndex), u =
|
|
310
|
+
const c = e.slice(i.startIndex, i.endIndex), u = ze(i.type, i.marks, n);
|
|
329
311
|
s += `<span style="${u}">${c}</span>`, o = i.endIndex;
|
|
330
312
|
}), s += e.slice(o), s;
|
|
331
|
-
},
|
|
313
|
+
}, Ve = (e, t) => {
|
|
332
314
|
let n = !1;
|
|
333
315
|
e.key === "Enter" && !e.shiftKey ? (e.preventDefault(), document.execCommand("insertLineBreak"), n = !0) : (e.metaKey || e.ctrlKey) && (e.key === "b" ? (t("bold"), n = !0) : e.key === "i" ? (t("italic"), n = !0) : e.key === "u" ? (t("underline"), n = !0) : e.key === "s" && (t("strike"), n = !0)), n && e.preventDefault();
|
|
334
|
-
}, ee = 128, Ge =
|
|
316
|
+
}, ee = 128, Ge = "()[]{}", Te = "", Je = new RegExp(
|
|
317
|
+
"^(?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u00a1-\\uffff][a-z0-9\\u00a1-\\uffff_-]{0,62})?[a-z0-9\\u00a1-\\uffff]\\.)+(?:[a-z\\u00a1-\\uffff]{2,}\\.?))(?::\\d{2,5})?(?:[/?#]\\S*)?$",
|
|
318
|
+
"i"
|
|
319
|
+
), xe = (e, t) => {
|
|
335
320
|
const n = ve(
|
|
336
321
|
e,
|
|
337
322
|
t,
|
|
338
|
-
|
|
339
|
-
|
|
323
|
+
Ge,
|
|
324
|
+
Te
|
|
340
325
|
);
|
|
341
|
-
return n?.search.match(
|
|
326
|
+
return n?.search.match(Je) ? {
|
|
342
327
|
type: "link",
|
|
343
328
|
...n
|
|
344
329
|
} : null;
|
|
@@ -353,7 +338,7 @@ const ye = () => {
|
|
|
353
338
|
type: "mention",
|
|
354
339
|
...n
|
|
355
340
|
} : null;
|
|
356
|
-
}, oe = (e) => (e & re) !== 0, _e = (e, t) => t ? e | re : e & ~re,
|
|
341
|
+
}, oe = (e) => (e & re) !== 0, _e = (e, t) => t ? e | re : e & ~re, B = 2, q = (e) => (e & B) !== 0, ke = (e, t) => t ? e | B : e & ~B, D = 4, H = (e) => (e & D) !== 0, Se = (e, t) => t ? e | D : e & ~D, $ = 16, Z = (e) => (e & $) !== 0, be = (e, t) => t ? e | $ : e & ~$, Y = 8, Q = (e) => (e & Y) !== 0, we = (e, t) => t ? e | Y : e & ~Y, je = (e, t) => {
|
|
357
342
|
if (e === t) return null;
|
|
358
343
|
let n = 0;
|
|
359
344
|
for (; n < e.length && n < t.length && e[n] === t[n]; )
|
|
@@ -369,7 +354,7 @@ const ye = () => {
|
|
|
369
354
|
}, ge = (e, t, n, s) => {
|
|
370
355
|
let o = t;
|
|
371
356
|
for (; o < e.length; ) {
|
|
372
|
-
const c =
|
|
357
|
+
const c = S(e, o);
|
|
373
358
|
if (n(c))
|
|
374
359
|
e[o] = s(c, !1);
|
|
375
360
|
else
|
|
@@ -378,7 +363,7 @@ const ye = () => {
|
|
|
378
363
|
}
|
|
379
364
|
let i = t - 1;
|
|
380
365
|
for (; i >= 0; ) {
|
|
381
|
-
const c =
|
|
366
|
+
const c = S(e, i);
|
|
382
367
|
if (n(c))
|
|
383
368
|
e[i] = s(c, !1);
|
|
384
369
|
else
|
|
@@ -386,14 +371,14 @@ const ye = () => {
|
|
|
386
371
|
i--;
|
|
387
372
|
}
|
|
388
373
|
return e;
|
|
389
|
-
},
|
|
374
|
+
}, Pe = (e, t, n) => {
|
|
390
375
|
if (!t) return e;
|
|
391
376
|
const { position: s, deletedLength: o, insertedText: i } = t, c = i.length;
|
|
392
377
|
let u = [...e];
|
|
393
|
-
const f =
|
|
378
|
+
const f = S(u, s);
|
|
394
379
|
if (oe(f) ? u = ge(u, s, oe, _e) : ce(f) ? u = ge(u, s, ce, Ne) : te(f) && (u = ge(u, s, te, Re)), o > 0 && u.splice(s, o), c > 0) {
|
|
395
380
|
let m = 0;
|
|
396
|
-
n.bold && (m = ke(m, !0)), n.italic && (m =
|
|
381
|
+
n.bold && (m = ke(m, !0)), n.italic && (m = Se(m, !0)), n.underline && (m = we(m, !0)), n.strike && (m = be(m, !0));
|
|
397
382
|
const N = new Array(c).fill(m);
|
|
398
383
|
u.splice(s, 0, ...N);
|
|
399
384
|
}
|
|
@@ -426,7 +411,7 @@ const ye = () => {
|
|
|
426
411
|
startIndex: i,
|
|
427
412
|
endIndex: c
|
|
428
413
|
};
|
|
429
|
-
}, se = 64, Ze = `.,!?;()[]{}"'<>@`, Qe = /^#[\w-]+$/, ie = "#",
|
|
414
|
+
}, se = 64, Ze = `.,!?;()[]{}"'<>@`, Qe = /^#[\w-]+$/, ie = "#", Be = (e, t) => {
|
|
430
415
|
const n = ve(
|
|
431
416
|
e,
|
|
432
417
|
t,
|
|
@@ -443,14 +428,14 @@ const ye = () => {
|
|
|
443
428
|
const s = [];
|
|
444
429
|
let o = 0;
|
|
445
430
|
for (; o < t.length; ) {
|
|
446
|
-
const i =
|
|
431
|
+
const i = S(t, o);
|
|
447
432
|
if (i === 0 || i === 1) {
|
|
448
433
|
o++;
|
|
449
434
|
continue;
|
|
450
435
|
}
|
|
451
436
|
const c = o;
|
|
452
437
|
let u = o;
|
|
453
|
-
for (; u + 1 < t.length &&
|
|
438
|
+
for (; u + 1 < t.length && S(t, u + 1) === i; )
|
|
454
439
|
u++;
|
|
455
440
|
const f = rt(i, n), m = nt(i), N = {
|
|
456
441
|
type: f,
|
|
@@ -458,7 +443,7 @@ const ye = () => {
|
|
|
458
443
|
endIndex: u + 1,
|
|
459
444
|
marks: m,
|
|
460
445
|
username: f === "mention" ? Le(e, u)?.search.replace(ne, "") : void 0,
|
|
461
|
-
interest: f === "interest" ?
|
|
446
|
+
interest: f === "interest" ? Be(e, u)?.search.replace(
|
|
462
447
|
ie,
|
|
463
448
|
""
|
|
464
449
|
) : void 0,
|
|
@@ -467,14 +452,14 @@ const ye = () => {
|
|
|
467
452
|
s.push(N), o = u + 1;
|
|
468
453
|
}
|
|
469
454
|
return s;
|
|
470
|
-
}, rt = (e, t) => e & re && t.mentions ? "mention" : e & se && t.interests ? "interest" : e & ee && t.links ? "link" : (e & (
|
|
455
|
+
}, rt = (e, t) => e & re && t.mentions ? "mention" : e & se && t.interests ? "interest" : e & ee && t.links ? "link" : (e & (B | D | Y | $), "segment"), nt = (e) => {
|
|
471
456
|
const t = [];
|
|
472
|
-
return e &
|
|
473
|
-
},
|
|
457
|
+
return e & B && t.push("bold"), e & D && t.push("italic"), e & Y && t.push("underline"), e & $ && t.push("strike"), t;
|
|
458
|
+
}, S = (e, t) => {
|
|
474
459
|
const n = e[t];
|
|
475
460
|
return typeof n != "number" ? 0 : n;
|
|
476
461
|
}, ot = (e, t, n) => {
|
|
477
|
-
const s =
|
|
462
|
+
const s = S(e, t);
|
|
478
463
|
switch (n) {
|
|
479
464
|
case "mention":
|
|
480
465
|
return _e(s, !0);
|
|
@@ -485,26 +470,26 @@ const ye = () => {
|
|
|
485
470
|
}
|
|
486
471
|
return s;
|
|
487
472
|
}, st = (e, t, n, s) => {
|
|
488
|
-
let o =
|
|
473
|
+
let o = S(e, t);
|
|
489
474
|
switch (n) {
|
|
490
475
|
case "bold":
|
|
491
476
|
o = ke(o, s);
|
|
492
477
|
break;
|
|
493
478
|
case "italic":
|
|
494
|
-
o =
|
|
479
|
+
o = Se(o, s);
|
|
495
480
|
break;
|
|
496
481
|
case "underline":
|
|
497
482
|
o = we(o, s);
|
|
498
483
|
break;
|
|
499
484
|
case "strike":
|
|
500
|
-
o =
|
|
485
|
+
o = be(o, s);
|
|
501
486
|
break;
|
|
502
487
|
default:
|
|
503
488
|
return e;
|
|
504
489
|
}
|
|
505
490
|
return e[t] = o, e;
|
|
506
491
|
}, it = (e, t, n) => {
|
|
507
|
-
const s =
|
|
492
|
+
const s = S(e, t);
|
|
508
493
|
switch (n) {
|
|
509
494
|
case "bold":
|
|
510
495
|
return q(s);
|
|
@@ -523,16 +508,16 @@ const ye = () => {
|
|
|
523
508
|
return !0;
|
|
524
509
|
}, pe = (e) => oe(e) || ce(e) || te(e), lt = (e, t, n, s) => {
|
|
525
510
|
let o = [...e];
|
|
526
|
-
for (; pe(
|
|
511
|
+
for (; pe(S(e, t - 1)) && t > 0; )
|
|
527
512
|
t--;
|
|
528
|
-
for (; pe(
|
|
513
|
+
for (; pe(S(e, n)) && n < e.length; )
|
|
529
514
|
n++;
|
|
530
515
|
let i = !0;
|
|
531
516
|
ct(t, n, s, o) && (i = !1);
|
|
532
517
|
for (let c = t; c < n; c++)
|
|
533
518
|
o = st(o, c, s, i);
|
|
534
519
|
return o;
|
|
535
|
-
},
|
|
520
|
+
}, Me = (e, t) => {
|
|
536
521
|
const n = new Array(e.length).fill(0);
|
|
537
522
|
for (let s = 0; s < e.length; s++) {
|
|
538
523
|
let o = 0;
|
|
@@ -540,7 +525,7 @@ const ye = () => {
|
|
|
540
525
|
if (i) {
|
|
541
526
|
i.type === "mention" ? o = _e(o, !0) : i.type === "interest" ? o = Ne(o, !0) : i.type === "link" && (o = Re(o, !0));
|
|
542
527
|
for (const c of i.marks)
|
|
543
|
-
c === "bold" ? o = ke(o, !0) : c === "italic" ? o =
|
|
528
|
+
c === "bold" ? o = ke(o, !0) : c === "italic" ? o = Se(o, !0) : c === "underline" ? o = we(o, !0) : c === "strike" && (o = be(o, !0));
|
|
544
529
|
}
|
|
545
530
|
n[s] = o;
|
|
546
531
|
}
|
|
@@ -565,54 +550,57 @@ const ye = () => {
|
|
|
565
550
|
options: m = {},
|
|
566
551
|
entityStyles: N = {},
|
|
567
552
|
placeholder: p = "",
|
|
568
|
-
debug:
|
|
569
|
-
...
|
|
553
|
+
debug: y = !1,
|
|
554
|
+
...j
|
|
570
555
|
}) => {
|
|
571
|
-
const
|
|
572
|
-
|
|
556
|
+
const b = A.useRef(null), [O, le] = A.useState({ start: 0, end: 0 }), [F, W] = A.useState(!1), [K, ue] = A.useState(!1), [ae, U] = A.useState(!1), [w, I] = A.useState(
|
|
557
|
+
Me(t, s)
|
|
573
558
|
);
|
|
574
559
|
e.current = {
|
|
575
|
-
selectEntity: (a,
|
|
576
|
-
if (!
|
|
577
|
-
let r = [...
|
|
578
|
-
a === "mention" ? h = ne + h : a === "interest" ? h = ie + h : a === "link" && (h =
|
|
579
|
-
const l = t.slice(0,
|
|
580
|
-
d ? r =
|
|
581
|
-
for (let
|
|
582
|
-
r[
|
|
583
|
-
n(l),
|
|
560
|
+
selectEntity: (a, g, E, h) => {
|
|
561
|
+
if (!b.current) return;
|
|
562
|
+
let r = [...w];
|
|
563
|
+
a === "mention" ? h = ne + h : a === "interest" ? h = ie + h : a === "link" && (h = Te + h);
|
|
564
|
+
const l = t.slice(0, g) + h + t.slice(E), d = je(t, l);
|
|
565
|
+
d ? r = Pe(w, d, i) : r = Me(l, s);
|
|
566
|
+
for (let R = g; R < g + h.length; R++)
|
|
567
|
+
r[R] = ot(r, R, a);
|
|
568
|
+
n(l), I(r), f(null);
|
|
584
569
|
},
|
|
585
570
|
toggleMark: (a) => {
|
|
586
|
-
|
|
571
|
+
V(a);
|
|
572
|
+
},
|
|
573
|
+
clear: () => {
|
|
574
|
+
n(""), I([]), o([]);
|
|
587
575
|
}
|
|
588
576
|
}, A.useEffect(() => {
|
|
589
|
-
if (
|
|
590
|
-
|
|
591
|
-
const a =
|
|
592
|
-
|
|
577
|
+
if (b.current) {
|
|
578
|
+
b.current.textContent = t;
|
|
579
|
+
const a = ye(t, s, N);
|
|
580
|
+
b.current.innerHTML = a, K || ue(!0);
|
|
593
581
|
}
|
|
594
582
|
}, []), A.useEffect(() => {
|
|
595
|
-
if (!
|
|
596
|
-
const a = tt(t,
|
|
597
|
-
|
|
598
|
-
}, [
|
|
599
|
-
const
|
|
583
|
+
if (!b.current) return;
|
|
584
|
+
const a = tt(t, w, m), g = Ce(b.current) ?? O, E = ye(t, a, N);
|
|
585
|
+
b.current.innerHTML = E, o(a), K && Ue(b.current, g);
|
|
586
|
+
}, [w]);
|
|
587
|
+
const z = ut(O, 500);
|
|
600
588
|
A.useEffect(() => {
|
|
601
|
-
let { start: a, end:
|
|
602
|
-
if (!E && !oe(
|
|
589
|
+
let { start: a, end: g } = z, E = null;
|
|
590
|
+
if (!E && !oe(S(w, a - 1)) && (E = Le(t, a), E && (E.search = E.search.replace(ne, ""))), !E && !ce(S(w, a - 1)) && (E = Be(t, a), E && (E.search = E.search.replace(ie, ""))), !E && !te(S(w, a - 1)) && (E = xe(t, a)), E ? f(E) : u && f(null), F) return;
|
|
603
591
|
let h = !0, r = !0, l = !0, d = !0;
|
|
604
|
-
if (a ===
|
|
592
|
+
if (a === g)
|
|
605
593
|
if (a > 0) {
|
|
606
|
-
const
|
|
607
|
-
h = q(
|
|
594
|
+
const _ = S(w, a - 1);
|
|
595
|
+
h = q(_), r = H(_), l = Q(_), d = Z(_);
|
|
608
596
|
} else {
|
|
609
|
-
const
|
|
610
|
-
h = q(
|
|
597
|
+
const _ = S(w, a);
|
|
598
|
+
h = q(_), r = H(_), l = Q(_), d = Z(_);
|
|
611
599
|
}
|
|
612
600
|
else
|
|
613
|
-
for (let
|
|
614
|
-
const
|
|
615
|
-
h = q(
|
|
601
|
+
for (let _ = a; _ < g; _++) {
|
|
602
|
+
const v = S(w, _);
|
|
603
|
+
h = q(v) ? h : !1, r = H(v) ? r : !1, l = Q(v) ? l : !1, d = Z(v) ? d : !1;
|
|
616
604
|
}
|
|
617
605
|
c({
|
|
618
606
|
bold: h,
|
|
@@ -620,44 +608,44 @@ const ye = () => {
|
|
|
620
608
|
underline: l,
|
|
621
609
|
strike: d
|
|
622
610
|
});
|
|
623
|
-
}, [
|
|
624
|
-
const
|
|
625
|
-
if (W(!0), !
|
|
611
|
+
}, [z]);
|
|
612
|
+
const V = (a) => {
|
|
613
|
+
if (W(!0), !b.current)
|
|
626
614
|
return;
|
|
627
|
-
const { start:
|
|
628
|
-
if (
|
|
629
|
-
const r = lt(
|
|
630
|
-
|
|
615
|
+
const { start: g, end: E } = O;
|
|
616
|
+
if (g !== E) {
|
|
617
|
+
const r = lt(w, g, E, a);
|
|
618
|
+
I(r);
|
|
631
619
|
}
|
|
632
620
|
const h = { ...i };
|
|
633
621
|
a === "bold" ? h.bold = !i.bold : a === "italic" ? h.italic = !i.italic : a === "underline" ? h.underline = !i.underline : a === "strike" && (h.strike = !i.strike), c(h);
|
|
634
|
-
},
|
|
635
|
-
if (!
|
|
622
|
+
}, M = (a) => {
|
|
623
|
+
if (!b.current) return;
|
|
636
624
|
if (F && W(!1), a.target.textContent.length === 0) {
|
|
637
|
-
n(""),
|
|
625
|
+
n(""), I([]), o([]);
|
|
638
626
|
return;
|
|
639
627
|
}
|
|
640
|
-
const
|
|
628
|
+
const g = a.target.innerText || "", E = je(t, g);
|
|
641
629
|
if (E) {
|
|
642
|
-
const h =
|
|
643
|
-
|
|
630
|
+
const h = Pe(
|
|
631
|
+
w,
|
|
644
632
|
E,
|
|
645
633
|
i
|
|
646
634
|
);
|
|
647
|
-
|
|
635
|
+
I(h);
|
|
648
636
|
}
|
|
649
|
-
n(
|
|
637
|
+
n(g);
|
|
650
638
|
}, G = (a) => {
|
|
651
|
-
|
|
639
|
+
b.current && Ve(a, V);
|
|
652
640
|
}, fe = () => {
|
|
653
641
|
U(!0);
|
|
654
|
-
},
|
|
642
|
+
}, T = () => {
|
|
655
643
|
U(!1);
|
|
656
644
|
};
|
|
657
645
|
A.useEffect(() => {
|
|
658
646
|
const a = () => {
|
|
659
|
-
const
|
|
660
|
-
(
|
|
647
|
+
const g = Ce(b.current);
|
|
648
|
+
g && (g.start !== O.start || g.end !== O.end) && le(g);
|
|
661
649
|
};
|
|
662
650
|
return document.addEventListener("selectionchange", a), () => {
|
|
663
651
|
document.removeEventListener("selectionchange", a);
|
|
@@ -669,15 +657,14 @@ const ye = () => {
|
|
|
669
657
|
/* @__PURE__ */ C.jsx(
|
|
670
658
|
"div",
|
|
671
659
|
{
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
className: I.className,
|
|
660
|
+
ref: b,
|
|
661
|
+
style: { ...j.style, position: "relative", zIndex: 2 },
|
|
662
|
+
className: j.className,
|
|
676
663
|
contentEditable: !0,
|
|
677
664
|
onKeyDown: G,
|
|
678
|
-
onInput:
|
|
665
|
+
onInput: M,
|
|
679
666
|
onFocus: fe,
|
|
680
|
-
onBlur:
|
|
667
|
+
onBlur: T,
|
|
681
668
|
role: "textbox",
|
|
682
669
|
"aria-multiline": "true"
|
|
683
670
|
}
|
|
@@ -686,20 +673,20 @@ const ye = () => {
|
|
|
686
673
|
"div",
|
|
687
674
|
{
|
|
688
675
|
style: {
|
|
676
|
+
...j.style,
|
|
689
677
|
position: "absolute",
|
|
690
678
|
top: 0,
|
|
691
679
|
left: 0,
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
padding: I.style?.padding,
|
|
680
|
+
right: 0,
|
|
681
|
+
bottom: 0,
|
|
695
682
|
color: "#9ca3af"
|
|
696
683
|
},
|
|
697
684
|
"aria-hidden": "true",
|
|
698
|
-
children: p
|
|
685
|
+
children: /* @__PURE__ */ C.jsx("p", { children: p })
|
|
699
686
|
}
|
|
700
687
|
)
|
|
701
688
|
] }),
|
|
702
|
-
|
|
689
|
+
y && /* @__PURE__ */ C.jsx("div", { style: {}, children: /* @__PURE__ */ C.jsx("pre", { children: JSON.stringify(w) }) })
|
|
703
690
|
] });
|
|
704
691
|
};
|
|
705
692
|
export {
|
package/dist/src/Editor.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Entity, EntityOptions, StyleOptions, EntityType, MarkState, MarkType, S
|
|
|
3
3
|
export interface EditorRef {
|
|
4
4
|
selectEntity: (entityType: EntityType, startIndex: number, endIndex: number, newText: string) => void;
|
|
5
5
|
toggleMark: (markType: MarkType) => void;
|
|
6
|
+
clear: () => void;
|
|
6
7
|
}
|
|
7
8
|
export interface EditorProps {
|
|
8
9
|
ref: React.RefObject<EditorRef | null>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Entity, SelectionRange, StyleOptions } from '../interfaces';
|
|
2
|
-
export declare const getSelection: () => SelectionRange | null;
|
|
2
|
+
export declare const getSelection: (editableDiv: HTMLElement | null) => SelectionRange | null;
|
|
3
3
|
export declare const setSelection: (div: HTMLDivElement, selectionRange: SelectionRange) => void;
|
|
4
4
|
export declare const buildHtml: (plainText: string, entities: Entity[], styles: StyleOptions) => string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SearchEntity } from '../../interfaces';
|
|
2
2
|
export declare const LINK_MASK = 128;
|
|
3
|
-
export declare const LINK_REGEX: RegExp;
|
|
4
3
|
export declare const LINK_BOUNDARIES = "()[]{}";
|
|
5
4
|
export declare const LINK_KEY = "";
|
|
5
|
+
export declare const LINK_REGEX: RegExp;
|
|
6
6
|
export declare const getLinkWord: (plainText: string, position: number) => SearchEntity | null;
|
|
7
7
|
export declare const isLink: (value: number) => boolean;
|
|
8
8
|
export declare const setLink: (value: number, link: boolean) => number;
|