@connectedxm/entity-editor 0.0.8 → 0.0.10
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 +413 -403
- package/dist/src/Editor.d.ts +9 -6
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
1
1
|
import a from "react";
|
|
2
|
-
var ue = { exports: {} },
|
|
3
|
-
var
|
|
4
|
-
function
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
var e = /* @__PURE__ */ Symbol.for("react.transitional.element"),
|
|
8
|
-
function s(o, r,
|
|
9
|
-
var
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
for (var
|
|
13
|
-
|
|
14
|
-
} else
|
|
15
|
-
return r =
|
|
2
|
+
var ue = { exports: {} }, Z = {};
|
|
3
|
+
var Le;
|
|
4
|
+
function Ze() {
|
|
5
|
+
if (Le) return Z;
|
|
6
|
+
Le = 1;
|
|
7
|
+
var e = /* @__PURE__ */ Symbol.for("react.transitional.element"), t = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
8
|
+
function s(o, r, c) {
|
|
9
|
+
var i = null;
|
|
10
|
+
if (c !== void 0 && (i = "" + c), r.key !== void 0 && (i = "" + r.key), "key" in r) {
|
|
11
|
+
c = {};
|
|
12
|
+
for (var u in r)
|
|
13
|
+
u !== "key" && (c[u] = r[u]);
|
|
14
|
+
} else c = r;
|
|
15
|
+
return r = c.ref, {
|
|
16
16
|
$$typeof: e,
|
|
17
17
|
type: o,
|
|
18
|
-
key:
|
|
18
|
+
key: i,
|
|
19
19
|
ref: r !== void 0 ? r : null,
|
|
20
|
-
props:
|
|
20
|
+
props: c
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return Z.Fragment = t, Z.jsx = s, Z.jsxs = s, Z;
|
|
24
24
|
}
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
function
|
|
28
|
-
return
|
|
29
|
-
function e(
|
|
30
|
-
if (
|
|
31
|
-
if (typeof
|
|
32
|
-
return
|
|
33
|
-
if (typeof
|
|
34
|
-
switch (
|
|
35
|
-
case
|
|
25
|
+
var Q = {};
|
|
26
|
+
var $e;
|
|
27
|
+
function Qe() {
|
|
28
|
+
return $e || ($e = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
29
|
+
function e(n) {
|
|
30
|
+
if (n == null) return null;
|
|
31
|
+
if (typeof n == "function")
|
|
32
|
+
return n.$$typeof === ie ? null : n.displayName || n.name || null;
|
|
33
|
+
if (typeof n == "string") return n;
|
|
34
|
+
switch (n) {
|
|
35
|
+
case O:
|
|
36
36
|
return "Fragment";
|
|
37
|
-
case
|
|
37
|
+
case T:
|
|
38
38
|
return "Profiler";
|
|
39
|
-
case
|
|
39
|
+
case oe:
|
|
40
40
|
return "StrictMode";
|
|
41
|
-
case
|
|
41
|
+
case P:
|
|
42
42
|
return "Suspense";
|
|
43
|
-
case
|
|
43
|
+
case V:
|
|
44
44
|
return "SuspenseList";
|
|
45
|
-
case
|
|
45
|
+
case we:
|
|
46
46
|
return "Activity";
|
|
47
47
|
}
|
|
48
|
-
if (typeof
|
|
49
|
-
switch (typeof
|
|
48
|
+
if (typeof n == "object")
|
|
49
|
+
switch (typeof n.tag == "number" && console.error(
|
|
50
50
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
51
|
-
),
|
|
52
|
-
case
|
|
51
|
+
), n.$$typeof) {
|
|
52
|
+
case D:
|
|
53
53
|
return "Portal";
|
|
54
|
+
case ce:
|
|
55
|
+
return n.displayName || "Context";
|
|
56
|
+
case z:
|
|
57
|
+
return (n._context.displayName || "Context") + ".Consumer";
|
|
54
58
|
case be:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var u = t.render;
|
|
60
|
-
return t = t.displayName, t || (t = u.displayName || u.name || "", t = t !== "" ? "ForwardRef(" + t + ")" : "ForwardRef"), t;
|
|
61
|
-
case we:
|
|
62
|
-
return u = t.displayName || null, u !== null ? u : e(t.type) || "Memo";
|
|
59
|
+
var l = n.render;
|
|
60
|
+
return n = n.displayName, n || (n = l.displayName || l.name || "", n = n !== "" ? "ForwardRef(" + n + ")" : "ForwardRef"), n;
|
|
61
|
+
case X:
|
|
62
|
+
return l = n.displayName || null, l !== null ? l : e(n.type) || "Memo";
|
|
63
63
|
case q:
|
|
64
|
-
|
|
64
|
+
l = n._payload, n = n._init;
|
|
65
65
|
try {
|
|
66
|
-
return e(
|
|
66
|
+
return e(n(l));
|
|
67
67
|
} catch {
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
return null;
|
|
71
71
|
}
|
|
72
|
-
function n
|
|
73
|
-
return "" +
|
|
72
|
+
function t(n) {
|
|
73
|
+
return "" + n;
|
|
74
74
|
}
|
|
75
|
-
function s(
|
|
75
|
+
function s(n) {
|
|
76
76
|
try {
|
|
77
|
-
n
|
|
78
|
-
var
|
|
77
|
+
t(n);
|
|
78
|
+
var l = !1;
|
|
79
79
|
} catch {
|
|
80
|
-
|
|
80
|
+
l = !0;
|
|
81
81
|
}
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
var m =
|
|
82
|
+
if (l) {
|
|
83
|
+
l = console;
|
|
84
|
+
var m = l.error, S = typeof Symbol == "function" && Symbol.toStringTag && n[Symbol.toStringTag] || n.constructor.name || "Object";
|
|
85
85
|
return m.call(
|
|
86
|
-
|
|
86
|
+
l,
|
|
87
87
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
88
|
S
|
|
89
|
-
), n
|
|
89
|
+
), t(n);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
function o(
|
|
93
|
-
if (
|
|
94
|
-
if (typeof
|
|
92
|
+
function o(n) {
|
|
93
|
+
if (n === O) return "<>";
|
|
94
|
+
if (typeof n == "object" && n !== null && n.$$typeof === q)
|
|
95
95
|
return "<...>";
|
|
96
96
|
try {
|
|
97
|
-
var
|
|
98
|
-
return
|
|
97
|
+
var l = e(n);
|
|
98
|
+
return l ? "<" + l + ">" : "<...>";
|
|
99
99
|
} catch {
|
|
100
100
|
return "<...>";
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
function r() {
|
|
104
|
-
var
|
|
105
|
-
return
|
|
104
|
+
var n = x.A;
|
|
105
|
+
return n === null ? null : n.getOwner();
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function c() {
|
|
108
108
|
return Error("react-stack-top-frame");
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
if (
|
|
112
|
-
var
|
|
113
|
-
if (
|
|
110
|
+
function i(n) {
|
|
111
|
+
if (j.call(n, "key")) {
|
|
112
|
+
var l = Object.getOwnPropertyDescriptor(n, "key").get;
|
|
113
|
+
if (l && l.isReactWarning) return !1;
|
|
114
114
|
}
|
|
115
|
-
return
|
|
115
|
+
return n.key !== void 0;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function u(n, l) {
|
|
118
118
|
function m() {
|
|
119
|
-
|
|
119
|
+
G || (G = !0, console.error(
|
|
120
120
|
"%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)",
|
|
121
|
-
|
|
121
|
+
l
|
|
122
122
|
));
|
|
123
123
|
}
|
|
124
|
-
m.isReactWarning = !0, Object.defineProperty(
|
|
124
|
+
m.isReactWarning = !0, Object.defineProperty(n, "key", {
|
|
125
125
|
get: m,
|
|
126
126
|
configurable: !0
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
function f() {
|
|
130
|
-
var
|
|
131
|
-
return
|
|
130
|
+
var n = e(this.type);
|
|
131
|
+
return H[n] || (H[n] = !0, console.error(
|
|
132
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."
|
|
133
|
-
)),
|
|
133
|
+
)), n = this.props.ref, n !== void 0 ? n : null;
|
|
134
134
|
}
|
|
135
|
-
function R(
|
|
135
|
+
function R(n, l, m, S, F, K) {
|
|
136
136
|
var k = m.ref;
|
|
137
|
-
return
|
|
138
|
-
$$typeof:
|
|
139
|
-
type:
|
|
140
|
-
key:
|
|
137
|
+
return n = {
|
|
138
|
+
$$typeof: v,
|
|
139
|
+
type: n,
|
|
140
|
+
key: l,
|
|
141
141
|
props: m,
|
|
142
142
|
_owner: S
|
|
143
|
-
}, (k !== void 0 ? k : null) !== null ? Object.defineProperty(
|
|
143
|
+
}, (k !== void 0 ? k : null) !== null ? Object.defineProperty(n, "ref", {
|
|
144
144
|
enumerable: !1,
|
|
145
145
|
get: f
|
|
146
|
-
}) : Object.defineProperty(
|
|
146
|
+
}) : Object.defineProperty(n, "ref", { enumerable: !1, value: null }), n._store = {}, Object.defineProperty(n._store, "validated", {
|
|
147
147
|
configurable: !1,
|
|
148
148
|
enumerable: !1,
|
|
149
149
|
writable: !0,
|
|
150
150
|
value: 0
|
|
151
|
-
}), Object.defineProperty(
|
|
151
|
+
}), Object.defineProperty(n, "_debugInfo", {
|
|
152
152
|
configurable: !1,
|
|
153
153
|
enumerable: !1,
|
|
154
154
|
writable: !0,
|
|
155
155
|
value: null
|
|
156
|
-
}), Object.defineProperty(
|
|
156
|
+
}), Object.defineProperty(n, "_debugStack", {
|
|
157
157
|
configurable: !1,
|
|
158
158
|
enumerable: !1,
|
|
159
159
|
writable: !0,
|
|
160
|
-
value:
|
|
161
|
-
}), Object.defineProperty(
|
|
160
|
+
value: F
|
|
161
|
+
}), Object.defineProperty(n, "_debugTask", {
|
|
162
162
|
configurable: !1,
|
|
163
163
|
enumerable: !1,
|
|
164
164
|
writable: !0,
|
|
165
|
-
value:
|
|
166
|
-
}), Object.freeze && (Object.freeze(
|
|
165
|
+
value: K
|
|
166
|
+
}), Object.freeze && (Object.freeze(n.props), Object.freeze(n)), n;
|
|
167
167
|
}
|
|
168
|
-
function y(
|
|
169
|
-
var k =
|
|
168
|
+
function y(n, l, m, S, F, K) {
|
|
169
|
+
var k = l.children;
|
|
170
170
|
if (k !== void 0)
|
|
171
171
|
if (S)
|
|
172
|
-
if (
|
|
172
|
+
if (M(k)) {
|
|
173
173
|
for (S = 0; S < k.length; S++)
|
|
174
|
-
|
|
174
|
+
se(k[S]);
|
|
175
175
|
Object.freeze && Object.freeze(k);
|
|
176
176
|
} else
|
|
177
177
|
console.error(
|
|
178
178
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
179
179
|
);
|
|
180
|
-
else
|
|
181
|
-
if (
|
|
182
|
-
k = e(
|
|
183
|
-
var
|
|
184
|
-
return
|
|
180
|
+
else se(k);
|
|
181
|
+
if (j.call(l, "key")) {
|
|
182
|
+
k = e(n);
|
|
183
|
+
var C = Object.keys(l).filter(function(ve) {
|
|
184
|
+
return ve !== "key";
|
|
185
185
|
});
|
|
186
|
-
S = 0 <
|
|
186
|
+
S = 0 < C.length ? "{key: someKey, " + C.join(": ..., ") + ": ...}" : "{key: someKey}", $[k + S] || (C = 0 < C.length ? "{" + C.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
187
187
|
`A props object containing a "key" prop is being spread into JSX:
|
|
188
188
|
let props = %s;
|
|
189
189
|
<%s {...props} />
|
|
@@ -192,296 +192,296 @@ React keys must be passed directly to JSX without using spread:
|
|
|
192
192
|
<%s key={someKey} {...props} />`,
|
|
193
193
|
S,
|
|
194
194
|
k,
|
|
195
|
-
|
|
195
|
+
C,
|
|
196
196
|
k
|
|
197
|
-
),
|
|
197
|
+
), $[k + S] = !0);
|
|
198
198
|
}
|
|
199
|
-
if (k = null, m !== void 0 && (s(m), k = "" + m),
|
|
199
|
+
if (k = null, m !== void 0 && (s(m), k = "" + m), i(l) && (s(l.key), k = "" + l.key), "key" in l) {
|
|
200
200
|
m = {};
|
|
201
|
-
for (var
|
|
202
|
-
|
|
203
|
-
} else m =
|
|
204
|
-
return k &&
|
|
201
|
+
for (var U in l)
|
|
202
|
+
U !== "key" && (m[U] = l[U]);
|
|
203
|
+
} else m = l;
|
|
204
|
+
return k && u(
|
|
205
205
|
m,
|
|
206
|
-
typeof
|
|
206
|
+
typeof n == "function" ? n.displayName || n.name || "Unknown" : n
|
|
207
207
|
), R(
|
|
208
|
-
|
|
208
|
+
n,
|
|
209
209
|
k,
|
|
210
210
|
m,
|
|
211
211
|
r(),
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
F,
|
|
213
|
+
K
|
|
214
214
|
);
|
|
215
215
|
}
|
|
216
|
-
function
|
|
217
|
-
|
|
216
|
+
function se(n) {
|
|
217
|
+
W(n) ? n._store && (n._store.validated = 1) : typeof n == "object" && n !== null && n.$$typeof === q && (n._payload.status === "fulfilled" ? W(n._payload.value) && n._payload.value._store && (n._payload.value._store.validated = 1) : n._store && (n._store.validated = 1));
|
|
218
218
|
}
|
|
219
|
-
function
|
|
220
|
-
return typeof
|
|
219
|
+
function W(n) {
|
|
220
|
+
return typeof n == "object" && n !== null && n.$$typeof === v;
|
|
221
221
|
}
|
|
222
|
-
var w = a,
|
|
222
|
+
var w = a, v = /* @__PURE__ */ Symbol.for("react.transitional.element"), D = /* @__PURE__ */ Symbol.for("react.portal"), O = /* @__PURE__ */ Symbol.for("react.fragment"), oe = /* @__PURE__ */ Symbol.for("react.strict_mode"), T = /* @__PURE__ */ Symbol.for("react.profiler"), z = /* @__PURE__ */ Symbol.for("react.consumer"), ce = /* @__PURE__ */ Symbol.for("react.context"), be = /* @__PURE__ */ Symbol.for("react.forward_ref"), P = /* @__PURE__ */ Symbol.for("react.suspense"), V = /* @__PURE__ */ Symbol.for("react.suspense_list"), X = /* @__PURE__ */ Symbol.for("react.memo"), q = /* @__PURE__ */ Symbol.for("react.lazy"), we = /* @__PURE__ */ Symbol.for("react.activity"), ie = /* @__PURE__ */ Symbol.for("react.client.reference"), x = w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, Y = console.createTask ? console.createTask : function() {
|
|
223
223
|
return null;
|
|
224
224
|
};
|
|
225
225
|
w = {
|
|
226
|
-
react_stack_bottom_frame: function(
|
|
227
|
-
return
|
|
226
|
+
react_stack_bottom_frame: function(n) {
|
|
227
|
+
return n();
|
|
228
228
|
}
|
|
229
229
|
};
|
|
230
|
-
var
|
|
230
|
+
var G, H = {}, J = w.react_stack_bottom_frame.bind(
|
|
231
231
|
w,
|
|
232
|
-
|
|
233
|
-
)(), L =
|
|
234
|
-
|
|
235
|
-
var S = 1e4 >
|
|
232
|
+
c
|
|
233
|
+
)(), L = Y(o(c)), $ = {};
|
|
234
|
+
Q.Fragment = O, Q.jsx = function(n, l, m) {
|
|
235
|
+
var S = 1e4 > x.recentlyCreatedOwnerStacks++;
|
|
236
236
|
return y(
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
n,
|
|
238
|
+
l,
|
|
239
239
|
m,
|
|
240
240
|
!1,
|
|
241
|
-
S ? Error("react-stack-top-frame") :
|
|
242
|
-
S ?
|
|
241
|
+
S ? Error("react-stack-top-frame") : J,
|
|
242
|
+
S ? Y(o(n)) : L
|
|
243
243
|
);
|
|
244
|
-
},
|
|
245
|
-
var S = 1e4 >
|
|
244
|
+
}, Q.jsxs = function(n, l, m) {
|
|
245
|
+
var S = 1e4 > x.recentlyCreatedOwnerStacks++;
|
|
246
246
|
return y(
|
|
247
|
-
|
|
248
|
-
|
|
247
|
+
n,
|
|
248
|
+
l,
|
|
249
249
|
m,
|
|
250
250
|
!0,
|
|
251
|
-
S ? Error("react-stack-top-frame") :
|
|
252
|
-
S ?
|
|
251
|
+
S ? Error("react-stack-top-frame") : J,
|
|
252
|
+
S ? Y(o(n)) : L
|
|
253
253
|
);
|
|
254
254
|
};
|
|
255
|
-
})()),
|
|
255
|
+
})()), Q;
|
|
256
256
|
}
|
|
257
|
-
var
|
|
258
|
-
function
|
|
259
|
-
return
|
|
257
|
+
var Be;
|
|
258
|
+
function et() {
|
|
259
|
+
return Be || (Be = 1, process.env.NODE_ENV === "production" ? ue.exports = Ze() : ue.exports = Qe()), ue.exports;
|
|
260
260
|
}
|
|
261
|
-
var
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
if (!
|
|
265
|
-
if (
|
|
266
|
-
const s =
|
|
261
|
+
var B = et();
|
|
262
|
+
const De = (e) => {
|
|
263
|
+
const t = window.getSelection();
|
|
264
|
+
if (!t || !e) return { start: 0, end: 0 };
|
|
265
|
+
if (t.anchorNode && e.contains(t.anchorNode)) {
|
|
266
|
+
const s = t.getRangeAt(0), o = s.cloneRange();
|
|
267
267
|
o.selectNodeContents(e), o.setEnd(s.startContainer, s.startOffset);
|
|
268
|
-
const r = o.toString().length,
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
return { start: r, end:
|
|
268
|
+
const r = o.toString().length, c = s.cloneRange();
|
|
269
|
+
c.selectNodeContents(e), c.setEnd(s.endContainer, s.endOffset);
|
|
270
|
+
const i = c.toString().length;
|
|
271
|
+
return { start: r, end: i };
|
|
272
272
|
} else
|
|
273
273
|
return null;
|
|
274
|
-
},
|
|
274
|
+
}, tt = (e, t) => {
|
|
275
275
|
const s = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
|
|
276
|
-
let o = 0, r = s.nextNode(),
|
|
276
|
+
let o = 0, r = s.nextNode(), c = null, i = null, u = 0, f = 0;
|
|
277
277
|
for (; r; ) {
|
|
278
278
|
const R = o + (r.textContent?.length || 0);
|
|
279
|
-
if (!
|
|
280
|
-
|
|
279
|
+
if (!c && R >= t.start && (c = r, u = t.start - o), !i && R >= t.end) {
|
|
280
|
+
i = r, f = t.end - o;
|
|
281
281
|
break;
|
|
282
282
|
}
|
|
283
283
|
o = R, r = s.nextNode();
|
|
284
284
|
}
|
|
285
|
-
if (
|
|
285
|
+
if (c && i) {
|
|
286
286
|
const R = document.createRange();
|
|
287
287
|
R.setStart(
|
|
288
|
-
i,
|
|
289
|
-
Math.min(l, i.textContent?.length || 0)
|
|
290
|
-
), R.setEnd(
|
|
291
288
|
c,
|
|
292
|
-
Math.min(
|
|
289
|
+
Math.min(u, c.textContent?.length || 0)
|
|
290
|
+
), R.setEnd(
|
|
291
|
+
i,
|
|
292
|
+
Math.min(f, i.textContent?.length || 0)
|
|
293
293
|
);
|
|
294
294
|
const y = window.getSelection();
|
|
295
295
|
y?.removeAllRanges(), y?.addRange(R);
|
|
296
296
|
}
|
|
297
|
-
},
|
|
298
|
-
let o = "", r = "",
|
|
299
|
-
|
|
300
|
-
let
|
|
301
|
-
return o && (
|
|
302
|
-
},
|
|
303
|
-
if (
|
|
297
|
+
}, nt = (e, t, s) => {
|
|
298
|
+
let o = "", r = "", c = "", i = "";
|
|
299
|
+
t.includes("bold") && (r = "bold"), t.includes("italic") && (c = "italic"), (t.includes("underline") || e === "link") && (i += "underline"), t.includes("strike") && (i += " line-through"), e !== "segment" && (o = "#1da1f2", e === "mention" && s.mentionColor ? o = s.mentionColor : e === "interest" && s.interestColor ? o = s.interestColor : e === "link" && s.linkColor && (o = s.linkColor));
|
|
300
|
+
let u = "";
|
|
301
|
+
return o && (u += `color: ${o}; `), r && (u += `font-weight: ${r}; `), c && (u += `font-style: ${c}; `), i && (u += `text-decoration: ${i}; `), u;
|
|
302
|
+
}, Ye = (e, t, s) => {
|
|
303
|
+
if (t.length === 0)
|
|
304
304
|
return e;
|
|
305
305
|
let o = "", r = 0;
|
|
306
|
-
return
|
|
307
|
-
r <
|
|
308
|
-
const
|
|
309
|
-
o += `<span style="${
|
|
306
|
+
return t.forEach((c) => {
|
|
307
|
+
r < c.startIndex && (o += e.slice(r, c.startIndex));
|
|
308
|
+
const i = e.slice(c.startIndex, c.endIndex), u = nt(c.type, c.marks, s);
|
|
309
|
+
o += `<span style="${u}">${i}</span>`, r = c.endIndex;
|
|
310
310
|
}), o += e.slice(r), o;
|
|
311
|
-
},
|
|
311
|
+
}, rt = (e, t) => {
|
|
312
312
|
let s = !1;
|
|
313
|
-
e.key === "Enter" && !e.shiftKey ? (e.preventDefault(), document.execCommand("insertLineBreak"), s = !0) : (e.metaKey || e.ctrlKey) && (e.key === "b" ? (
|
|
314
|
-
}, he = 128,
|
|
313
|
+
e.key === "Enter" && !e.shiftKey ? (e.preventDefault(), document.execCommand("insertLineBreak"), s = !0) : (e.metaKey || e.ctrlKey) && (e.key === "b" ? (t("bold"), s = !0) : e.key === "i" ? (t("italic"), s = !0) : e.key === "u" ? (t("underline"), s = !0) : e.key === "s" && (t("strike"), s = !0)), s && e.preventDefault();
|
|
314
|
+
}, he = 128, st = "()[]{}", We = "", ot = new RegExp(
|
|
315
315
|
"^(?:(?:(?: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*)?$",
|
|
316
316
|
"i"
|
|
317
|
-
), ze = (e,
|
|
318
|
-
const s =
|
|
317
|
+
), ze = (e, t) => {
|
|
318
|
+
const s = je(
|
|
319
319
|
e,
|
|
320
|
-
|
|
321
|
-
|
|
320
|
+
t,
|
|
321
|
+
st,
|
|
322
322
|
We
|
|
323
323
|
);
|
|
324
|
-
return s?.search.match(
|
|
325
|
-
}, me = (e) => (e & he) !== 0,
|
|
326
|
-
const s =
|
|
324
|
+
return s?.search.match(ot) ? s : null;
|
|
325
|
+
}, me = (e) => (e & he) !== 0, Ae = (e, t) => t ? e | he : e & ~he, Re = 32, ct = /^@[a-zA-Z0-9_'-]+$/, it = `.,!?;()[]{}"'<>#`, ge = "@", Ve = (e, t) => {
|
|
326
|
+
const s = je(
|
|
327
327
|
e,
|
|
328
|
-
|
|
329
|
-
|
|
328
|
+
t,
|
|
329
|
+
it,
|
|
330
330
|
ge
|
|
331
331
|
);
|
|
332
|
-
return s?.search.match(
|
|
332
|
+
return s?.search.match(ct) ? {
|
|
333
333
|
type: "mention",
|
|
334
334
|
...s
|
|
335
335
|
} : null;
|
|
336
|
-
}, ke = (e) => (e & Re) !== 0,
|
|
337
|
-
if (e ===
|
|
336
|
+
}, ke = (e) => (e & Re) !== 0, ye = (e, t) => t ? e | Re : e & ~Re, ee = 2, ae = (e) => (e & ee) !== 0, Oe = (e, t) => t ? e | ee : e & ~ee, te = 4, fe = (e) => (e & te) !== 0, Te = (e, t) => t ? e | te : e & ~te, ne = 16, de = (e) => (e & ne) !== 0, Ce = (e, t) => t ? e | ne : e & ~ne, re = 8, Ee = (e) => (e & re) !== 0, Pe = (e, t) => t ? e | re : e & ~re, Fe = (e, t) => {
|
|
337
|
+
if (e === t) return null;
|
|
338
338
|
let s = 0;
|
|
339
|
-
for (; s < e.length && s <
|
|
339
|
+
for (; s < e.length && s < t.length && e[s] === t[s]; )
|
|
340
340
|
s++;
|
|
341
|
-
let o = e.length, r =
|
|
342
|
-
for (; o > s && r > s && e[o - 1] ===
|
|
341
|
+
let o = e.length, r = t.length;
|
|
342
|
+
for (; o > s && r > s && e[o - 1] === t[r - 1]; )
|
|
343
343
|
o--, r--;
|
|
344
344
|
return {
|
|
345
345
|
position: s,
|
|
346
346
|
deletedLength: o - s,
|
|
347
|
-
insertedText:
|
|
347
|
+
insertedText: t.slice(s, r)
|
|
348
348
|
};
|
|
349
|
-
},
|
|
350
|
-
let r =
|
|
349
|
+
}, xe = (e, t, s, o) => {
|
|
350
|
+
let r = t;
|
|
351
351
|
for (; r < e.length; ) {
|
|
352
|
-
const
|
|
353
|
-
if (s(
|
|
354
|
-
e[r] = o(
|
|
352
|
+
const i = p(e, r);
|
|
353
|
+
if (s(i))
|
|
354
|
+
e[r] = o(i, !1);
|
|
355
355
|
else
|
|
356
356
|
break;
|
|
357
357
|
r++;
|
|
358
358
|
}
|
|
359
|
-
let
|
|
360
|
-
for (;
|
|
361
|
-
const
|
|
362
|
-
if (s(
|
|
363
|
-
e[
|
|
359
|
+
let c = t - 1;
|
|
360
|
+
for (; c >= 0; ) {
|
|
361
|
+
const i = p(e, c);
|
|
362
|
+
if (s(i))
|
|
363
|
+
e[c] = o(i, !1);
|
|
364
364
|
else
|
|
365
365
|
break;
|
|
366
|
-
|
|
366
|
+
c--;
|
|
367
367
|
}
|
|
368
368
|
return e;
|
|
369
|
-
},
|
|
370
|
-
if (!
|
|
371
|
-
const { position: o, deletedLength: r, insertedText:
|
|
372
|
-
let
|
|
373
|
-
const f = p(
|
|
374
|
-
if (ke(f) ?
|
|
369
|
+
}, Ke = (e, t, s) => {
|
|
370
|
+
if (!t) return e;
|
|
371
|
+
const { position: o, deletedLength: r, insertedText: c } = t, i = c.length;
|
|
372
|
+
let u = [...e];
|
|
373
|
+
const f = p(u, o);
|
|
374
|
+
if (ke(f) ? u = xe(u, o, ke, ye) : Ie(f) ? u = xe(u, o, Ie, Me) : me(f) && (u = xe(u, o, me, Ae)), r > 0 && u.splice(o, r), i > 0) {
|
|
375
375
|
let R = 0;
|
|
376
|
-
s.bold && (R =
|
|
377
|
-
const y = new Array(
|
|
378
|
-
|
|
376
|
+
s.bold && (R = Oe(R, !0)), s.italic && (R = Te(R, !0)), s.underline && (R = Pe(R, !0)), s.strike && (R = Ce(R, !0));
|
|
377
|
+
const y = new Array(i).fill(R);
|
|
378
|
+
u.splice(o, 0, ...y);
|
|
379
379
|
}
|
|
380
|
-
return
|
|
381
|
-
},
|
|
382
|
-
if (
|
|
380
|
+
return u;
|
|
381
|
+
}, lt = (e) => /\s/.test(e) || /[\u2000-\u200B\u2028\u2029\u3000]/.test(e), je = (e, t, s, o) => {
|
|
382
|
+
if (t <= 0 || t > e.length)
|
|
383
383
|
return null;
|
|
384
|
-
let r = "",
|
|
385
|
-
const
|
|
386
|
-
for (let f =
|
|
387
|
-
if (
|
|
388
|
-
|
|
384
|
+
let r = "", c = t - 1, i = t;
|
|
385
|
+
const u = (f) => lt(f) || s.includes(f);
|
|
386
|
+
for (let f = c; f >= 0; f--) {
|
|
387
|
+
if (u(e[f])) {
|
|
388
|
+
c = f + 1;
|
|
389
389
|
break;
|
|
390
390
|
}
|
|
391
|
-
f === 0 && (
|
|
391
|
+
f === 0 && (c = 0), r = e[f] + r;
|
|
392
392
|
}
|
|
393
|
-
for (let f =
|
|
394
|
-
if (
|
|
395
|
-
|
|
393
|
+
for (let f = i; f < e.length; f++) {
|
|
394
|
+
if (u(e[f])) {
|
|
395
|
+
i = f;
|
|
396
396
|
break;
|
|
397
397
|
}
|
|
398
398
|
if (o && e[f] === o) {
|
|
399
|
-
|
|
399
|
+
i = f;
|
|
400
400
|
break;
|
|
401
401
|
}
|
|
402
|
-
f === e.length - 1 && (
|
|
402
|
+
f === e.length - 1 && (i = e.length), r = r + e[f];
|
|
403
403
|
}
|
|
404
404
|
return {
|
|
405
|
-
search: e.slice(
|
|
406
|
-
startIndex:
|
|
407
|
-
endIndex:
|
|
405
|
+
search: e.slice(c, i),
|
|
406
|
+
startIndex: c,
|
|
407
|
+
endIndex: i
|
|
408
408
|
};
|
|
409
|
-
}, _e = 64,
|
|
410
|
-
const s =
|
|
409
|
+
}, _e = 64, ut = `.,!?;()[]{}"'<>@`, at = /^#[\w-]+$/, Se = "#", Je = (e, t) => {
|
|
410
|
+
const s = je(
|
|
411
411
|
e,
|
|
412
|
-
|
|
413
|
-
|
|
412
|
+
t,
|
|
413
|
+
ut,
|
|
414
414
|
Se
|
|
415
415
|
);
|
|
416
|
-
return s?.search.match(
|
|
417
|
-
}, Ie = (e) => (e & _e) !== 0,
|
|
418
|
-
(s) => s.startIndex <=
|
|
419
|
-
),
|
|
416
|
+
return s?.search.match(at) ? s : null;
|
|
417
|
+
}, Ie = (e) => (e & _e) !== 0, Me = (e, t) => t ? e | _e : e & ~_e, ft = (e, t) => e.find(
|
|
418
|
+
(s) => s.startIndex <= t && s.endIndex > t
|
|
419
|
+
), dt = (e, t, s) => {
|
|
420
420
|
const o = [];
|
|
421
421
|
let r = 0;
|
|
422
|
-
for (; r <
|
|
423
|
-
const
|
|
424
|
-
if (
|
|
422
|
+
for (; r < t.length; ) {
|
|
423
|
+
const c = p(t, r);
|
|
424
|
+
if (c === 0 || c === 1) {
|
|
425
425
|
r++;
|
|
426
426
|
continue;
|
|
427
427
|
}
|
|
428
|
-
const
|
|
429
|
-
let
|
|
430
|
-
for (;
|
|
431
|
-
|
|
432
|
-
const f =
|
|
428
|
+
const i = r;
|
|
429
|
+
let u = r;
|
|
430
|
+
for (; u + 1 < t.length && p(t, u + 1) === c; )
|
|
431
|
+
u++;
|
|
432
|
+
const f = Et(c, s), R = ht(c), y = {
|
|
433
433
|
type: f,
|
|
434
|
-
startIndex:
|
|
435
|
-
endIndex:
|
|
434
|
+
startIndex: i,
|
|
435
|
+
endIndex: u + 1,
|
|
436
436
|
marks: R,
|
|
437
|
-
username: f === "mention" ? Ve(e,
|
|
438
|
-
interest: f === "interest" ?
|
|
437
|
+
username: f === "mention" ? Ve(e, u)?.search.replace(ge, "") : void 0,
|
|
438
|
+
interest: f === "interest" ? Je(e, u)?.search.replace(
|
|
439
439
|
Se,
|
|
440
440
|
""
|
|
441
441
|
) : void 0,
|
|
442
|
-
href: f === "link" ? ze(e,
|
|
442
|
+
href: f === "link" ? ze(e, u)?.search : void 0
|
|
443
443
|
};
|
|
444
|
-
o.push(y), r =
|
|
444
|
+
o.push(y), r = u + 1;
|
|
445
445
|
}
|
|
446
446
|
return o;
|
|
447
|
-
},
|
|
448
|
-
const
|
|
449
|
-
return e &
|
|
450
|
-
}, p = (e,
|
|
451
|
-
const s = e[
|
|
447
|
+
}, Et = (e, t) => e & Re && t.mentions ? "mention" : e & _e && t.interests ? "interest" : e & he && t.links ? "link" : (e & (ee | te | re | ne), "segment"), ht = (e) => {
|
|
448
|
+
const t = [];
|
|
449
|
+
return e & ee && t.push("bold"), e & te && t.push("italic"), e & re && t.push("underline"), e & ne && t.push("strike"), t;
|
|
450
|
+
}, p = (e, t) => {
|
|
451
|
+
const s = e[t];
|
|
452
452
|
return typeof s != "number" ? 0 : s;
|
|
453
|
-
}, Ne = (e,
|
|
454
|
-
const o = p(e,
|
|
453
|
+
}, Ne = (e, t, s) => {
|
|
454
|
+
const o = p(e, t);
|
|
455
455
|
switch (s) {
|
|
456
456
|
case "mention":
|
|
457
|
-
return
|
|
457
|
+
return ye(o, !0);
|
|
458
458
|
case "interest":
|
|
459
|
-
return
|
|
459
|
+
return Me(o, !0);
|
|
460
460
|
case "link":
|
|
461
|
-
return
|
|
461
|
+
return Ae(o, !0);
|
|
462
462
|
}
|
|
463
463
|
return o;
|
|
464
|
-
},
|
|
465
|
-
let r = p(e,
|
|
464
|
+
}, mt = (e, t, s, o) => {
|
|
465
|
+
let r = p(e, t);
|
|
466
466
|
switch (s) {
|
|
467
467
|
case "bold":
|
|
468
|
-
r =
|
|
468
|
+
r = Oe(r, o);
|
|
469
469
|
break;
|
|
470
470
|
case "italic":
|
|
471
|
-
r =
|
|
471
|
+
r = Te(r, o);
|
|
472
472
|
break;
|
|
473
473
|
case "underline":
|
|
474
474
|
r = Pe(r, o);
|
|
475
475
|
break;
|
|
476
476
|
case "strike":
|
|
477
|
-
r =
|
|
477
|
+
r = Ce(r, o);
|
|
478
478
|
break;
|
|
479
479
|
default:
|
|
480
480
|
return e;
|
|
481
481
|
}
|
|
482
|
-
return e[
|
|
483
|
-
},
|
|
484
|
-
const o = p(e,
|
|
482
|
+
return e[t] = r, e;
|
|
483
|
+
}, Rt = (e, t, s) => {
|
|
484
|
+
const o = p(e, t);
|
|
485
485
|
switch (s) {
|
|
486
486
|
case "bold":
|
|
487
487
|
return ae(o);
|
|
@@ -494,147 +494,157 @@ const Be = (e) => {
|
|
|
494
494
|
default:
|
|
495
495
|
throw Error(`Invalid mark type: ${s}`);
|
|
496
496
|
}
|
|
497
|
-
},
|
|
498
|
-
for (let r = e; r <
|
|
499
|
-
if (!
|
|
497
|
+
}, gt = (e, t, s, o) => {
|
|
498
|
+
for (let r = e; r < t; r++)
|
|
499
|
+
if (!Rt(o, r, s)) return !1;
|
|
500
500
|
return !0;
|
|
501
|
-
},
|
|
501
|
+
}, Ue = (e) => ke(e) || Ie(e) || me(e), kt = (e, t, s, o) => {
|
|
502
502
|
let r = [...e];
|
|
503
|
-
for (;
|
|
504
|
-
|
|
505
|
-
for (;
|
|
503
|
+
for (; Ue(p(e, t - 1)) && t > 0; )
|
|
504
|
+
t--;
|
|
505
|
+
for (; Ue(p(e, s)) && s < e.length; )
|
|
506
506
|
s++;
|
|
507
|
-
let
|
|
508
|
-
|
|
509
|
-
for (let
|
|
510
|
-
r =
|
|
507
|
+
let c = !0;
|
|
508
|
+
gt(t, s, o, r) && (c = !1);
|
|
509
|
+
for (let i = t; i < s; i++)
|
|
510
|
+
r = mt(r, i, o, c);
|
|
511
511
|
return r;
|
|
512
|
-
},
|
|
512
|
+
}, pe = (e, t) => {
|
|
513
513
|
const s = new Array(e.length).fill(0);
|
|
514
514
|
for (let o = 0; o < e.length; o++) {
|
|
515
515
|
let r = 0;
|
|
516
|
-
const
|
|
517
|
-
if (
|
|
518
|
-
|
|
519
|
-
for (const
|
|
520
|
-
|
|
516
|
+
const c = ft(t, o);
|
|
517
|
+
if (c) {
|
|
518
|
+
c.type === "mention" ? r = ye(r, !0) : c.type === "interest" ? r = Me(r, !0) : c.type === "link" && (r = Ae(r, !0));
|
|
519
|
+
for (const i of c.marks)
|
|
520
|
+
i === "bold" ? r = Oe(r, !0) : i === "italic" ? r = Te(r, !0) : i === "underline" ? r = Pe(r, !0) : i === "strike" && (r = Ce(r, !0));
|
|
521
521
|
}
|
|
522
522
|
s[o] = r;
|
|
523
523
|
}
|
|
524
524
|
return s;
|
|
525
|
-
},
|
|
525
|
+
}, _t = {}, St = {}, bt = ({
|
|
526
526
|
ref: e,
|
|
527
|
-
initialPlainText:
|
|
527
|
+
initialPlainText: t = "",
|
|
528
528
|
initialEntities: s = [],
|
|
529
529
|
onMentionSearch: o,
|
|
530
530
|
onMarkStateChange: r,
|
|
531
|
-
onLinkCreated:
|
|
532
|
-
onInterestCreated:
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
531
|
+
onLinkCreated: c,
|
|
532
|
+
onInterestCreated: i,
|
|
533
|
+
onGetState: u,
|
|
534
|
+
options: f = _t,
|
|
535
|
+
entityStyles: R = St,
|
|
536
|
+
placeholder: y = "",
|
|
537
|
+
debug: se = !1,
|
|
538
|
+
...W
|
|
538
539
|
}) => {
|
|
539
|
-
const
|
|
540
|
+
const w = a.useRef(null), [v, D] = a.useState(t), [O, oe] = a.useState({
|
|
540
541
|
bold: !1,
|
|
541
542
|
italic: !1,
|
|
542
543
|
underline: !1,
|
|
543
544
|
strike: !1
|
|
544
|
-
}), [
|
|
545
|
-
|
|
546
|
-
),
|
|
545
|
+
}), [T, z] = a.useState(null), [ce, be] = a.useState({ start: 0, end: 0 }), [P, V] = a.useState(!1), [X, q] = a.useState(!1), [we, ie] = a.useState(!1), [x, j] = a.useState(
|
|
546
|
+
pe(t, s)
|
|
547
|
+
), M = a.useMemo(() => dt(v, x, f), [v, x, f]), Y = a.useRef(o), G = a.useRef(r), H = a.useRef(P), J = a.useRef(!1), L = a.useRef({
|
|
547
548
|
start: 0,
|
|
548
549
|
end: 0
|
|
549
|
-
}),
|
|
550
|
+
}), $ = a.useRef(null), n = a.useRef(!1), l = a.useRef(null), m = a.useRef(!1), S = a.useRef(null), F = a.useRef(null), K = a.useRef(c), k = a.useRef(i), C = a.useRef(u);
|
|
550
551
|
a.useEffect(() => {
|
|
551
|
-
|
|
552
|
+
Y.current = o;
|
|
552
553
|
}, [o]), a.useEffect(() => {
|
|
553
|
-
|
|
554
|
+
G.current = r;
|
|
554
555
|
}, [r]), a.useEffect(() => {
|
|
555
|
-
|
|
556
|
-
}, [i]), a.useEffect(() => {
|
|
557
|
-
F.current = c;
|
|
556
|
+
K.current = c;
|
|
558
557
|
}, [c]), a.useEffect(() => {
|
|
559
|
-
|
|
560
|
-
}, [
|
|
561
|
-
|
|
562
|
-
|
|
558
|
+
k.current = i;
|
|
559
|
+
}, [i]), a.useEffect(() => {
|
|
560
|
+
C.current = u;
|
|
561
|
+
}, [u]), a.useEffect(() => {
|
|
562
|
+
H.current = P;
|
|
563
|
+
}, [P]), a.useEffect(() => {
|
|
564
|
+
if (l.current && clearTimeout(l.current), T === null) {
|
|
565
|
+
Y.current?.(null);
|
|
563
566
|
return;
|
|
564
567
|
}
|
|
565
|
-
return
|
|
566
|
-
|
|
568
|
+
return l.current = setTimeout(() => {
|
|
569
|
+
Y.current?.(T);
|
|
567
570
|
}, 300), () => {
|
|
568
|
-
|
|
571
|
+
l.current && clearTimeout(l.current);
|
|
569
572
|
};
|
|
570
|
-
}, [
|
|
571
|
-
|
|
572
|
-
}, [
|
|
573
|
-
const
|
|
573
|
+
}, [T]), a.useEffect(() => {
|
|
574
|
+
G.current?.(O);
|
|
575
|
+
}, [O]);
|
|
576
|
+
const U = a.useCallback(
|
|
574
577
|
(h) => {
|
|
575
|
-
if (
|
|
578
|
+
if (V(!0), !w.current)
|
|
576
579
|
return;
|
|
577
|
-
const { start: I, end: b } =
|
|
580
|
+
const { start: I, end: b } = L.current;
|
|
578
581
|
if (I !== b) {
|
|
579
|
-
const d =
|
|
580
|
-
|
|
582
|
+
const d = kt(x, I, b, h);
|
|
583
|
+
j(d);
|
|
581
584
|
}
|
|
582
|
-
|
|
585
|
+
oe((d) => {
|
|
583
586
|
const g = { ...d };
|
|
584
587
|
return h === "bold" ? g.bold = !d.bold : h === "italic" ? g.italic = !d.italic : h === "underline" ? g.underline = !d.underline : h === "strike" && (g.strike = !d.strike), g;
|
|
585
588
|
});
|
|
586
589
|
},
|
|
587
|
-
[
|
|
590
|
+
[x]
|
|
588
591
|
);
|
|
589
592
|
a.useImperativeHandle(
|
|
590
593
|
e,
|
|
591
594
|
() => ({
|
|
592
595
|
selectEntity: (h, I, b, d) => {
|
|
593
|
-
if (!
|
|
594
|
-
let g = [...
|
|
596
|
+
if (!w.current) return;
|
|
597
|
+
let g = [...x];
|
|
595
598
|
h === "mention" ? d = ge + d : h === "interest" ? d = Se + d : h === "link" && (d = We + d);
|
|
596
|
-
const E =
|
|
597
|
-
A ? g =
|
|
599
|
+
const E = v.slice(0, I) + d + v.slice(b), A = Fe(v, E);
|
|
600
|
+
A ? g = Ke(x, A, O) : g = pe(E, M);
|
|
598
601
|
for (let _ = I; _ < I + d.length; _++)
|
|
599
602
|
g[_] = Ne(g, _, h);
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
start:
|
|
603
|
-
end:
|
|
604
|
-
},
|
|
603
|
+
const N = I + d.length;
|
|
604
|
+
L.current = {
|
|
605
|
+
start: N,
|
|
606
|
+
end: N
|
|
607
|
+
}, m.current = !0, D(E), j(g), z(null);
|
|
605
608
|
},
|
|
606
|
-
toggleMark:
|
|
609
|
+
toggleMark: U,
|
|
607
610
|
clear: () => {
|
|
608
|
-
|
|
611
|
+
D(""), j([]);
|
|
612
|
+
},
|
|
613
|
+
reset: () => {
|
|
614
|
+
D(t), j(pe(t, s)), z(null);
|
|
609
615
|
},
|
|
610
616
|
focus: () => {
|
|
611
|
-
|
|
617
|
+
w.current?.focus();
|
|
612
618
|
},
|
|
613
|
-
getState: () => ({
|
|
614
|
-
plainText:
|
|
615
|
-
entities:
|
|
616
|
-
markState:
|
|
619
|
+
getState: () => (C.current && C.current({
|
|
620
|
+
plainText: v,
|
|
621
|
+
entities: M,
|
|
622
|
+
markState: O
|
|
623
|
+
}), {
|
|
624
|
+
plainText: v,
|
|
625
|
+
entities: M,
|
|
626
|
+
markState: O
|
|
617
627
|
})
|
|
618
628
|
}),
|
|
619
|
-
[
|
|
629
|
+
[x, v, M, O, U]
|
|
620
630
|
), a.useEffect(() => {
|
|
621
|
-
if (
|
|
622
|
-
|
|
623
|
-
const h =
|
|
624
|
-
|
|
631
|
+
if (w.current && !X) {
|
|
632
|
+
w.current.textContent = v;
|
|
633
|
+
const h = Ye(v, M, R);
|
|
634
|
+
w.current.innerHTML = h, q(!0);
|
|
625
635
|
}
|
|
626
636
|
}, []), a.useLayoutEffect(() => {
|
|
627
|
-
if (!
|
|
628
|
-
const h =
|
|
629
|
-
|
|
630
|
-
const I =
|
|
631
|
-
|
|
632
|
-
|
|
637
|
+
if (!w.current || !X) return;
|
|
638
|
+
const h = m.current ? L.current : De(w.current) ?? L.current;
|
|
639
|
+
m.current = !1;
|
|
640
|
+
const I = Ye(v, M, R);
|
|
641
|
+
n.current = !0, w.current.innerHTML = I, tt(w.current, h), queueMicrotask(() => {
|
|
642
|
+
n.current = !1;
|
|
633
643
|
});
|
|
634
|
-
}, [
|
|
635
|
-
let { start: h, end: I } =
|
|
636
|
-
if (!ke(p(
|
|
637
|
-
const _ = Ve(
|
|
644
|
+
}, [M, R, X]), a.useEffect(() => {
|
|
645
|
+
let { start: h, end: I } = ce, b = null;
|
|
646
|
+
if (!ke(p(x, h - 1))) {
|
|
647
|
+
const _ = Ve(v, h);
|
|
638
648
|
_ && (b = {
|
|
639
649
|
type: "mention",
|
|
640
650
|
search: _.search.replace(ge, ""),
|
|
@@ -642,132 +652,132 @@ const Be = (e) => {
|
|
|
642
652
|
endIndex: _.endIndex
|
|
643
653
|
});
|
|
644
654
|
}
|
|
645
|
-
if (b ? (!
|
|
655
|
+
if (b ? (!T || b.startIndex !== T.startIndex || b.endIndex !== T.endIndex || b.search !== T.search) && z(b) : T && z(null), P) return;
|
|
646
656
|
let d = !0, g = !0, E = !0, A = !0;
|
|
647
657
|
if (h === I)
|
|
648
658
|
if (h > 0) {
|
|
649
|
-
const _ = p(
|
|
659
|
+
const _ = p(x, h - 1);
|
|
650
660
|
d = ae(_), g = fe(_), E = Ee(_), A = de(_);
|
|
651
661
|
} else {
|
|
652
|
-
const _ = p(
|
|
662
|
+
const _ = p(x, h);
|
|
653
663
|
d = ae(_), g = fe(_), E = Ee(_), A = de(_);
|
|
654
664
|
}
|
|
655
665
|
else
|
|
656
666
|
for (let _ = h; _ < I; _++) {
|
|
657
|
-
const le = p(
|
|
667
|
+
const le = p(x, _);
|
|
658
668
|
d = ae(le) ? d : !1, g = fe(le) ? g : !1, E = Ee(le) ? E : !1, A = de(le) ? A : !1;
|
|
659
669
|
}
|
|
660
|
-
|
|
670
|
+
oe({
|
|
661
671
|
bold: d,
|
|
662
672
|
italic: g,
|
|
663
673
|
underline: E,
|
|
664
674
|
strike: A
|
|
665
675
|
});
|
|
666
|
-
}, [
|
|
667
|
-
const
|
|
668
|
-
if (!
|
|
676
|
+
}, [ce, x, v, P]);
|
|
677
|
+
const ve = (h) => {
|
|
678
|
+
if (!w.current) return;
|
|
669
679
|
if (h.target.textContent.length === 0) {
|
|
670
|
-
|
|
680
|
+
D(""), j([]), P && V(!1);
|
|
671
681
|
return;
|
|
672
682
|
}
|
|
673
|
-
const I = h.target.innerText || "", b =
|
|
683
|
+
const I = h.target.innerText || "", b = Fe(v, I);
|
|
674
684
|
if (b) {
|
|
675
|
-
let d =
|
|
685
|
+
let d = Ke(x, b, O);
|
|
676
686
|
if (b.deletedLength === 0 && b.insertedText === " " && b.position > 0) {
|
|
677
687
|
const g = b.position;
|
|
678
688
|
if (!me(p(d, g - 1))) {
|
|
679
689
|
const E = ze(I, g);
|
|
680
690
|
if (E && E.endIndex === g) {
|
|
681
691
|
const A = `${E.startIndex}:${E.endIndex}:${E.search}`;
|
|
682
|
-
if (
|
|
683
|
-
for (let
|
|
684
|
-
d[
|
|
685
|
-
if (
|
|
686
|
-
const
|
|
692
|
+
if (S.current !== A) {
|
|
693
|
+
for (let N = E.startIndex; N < E.endIndex; N++)
|
|
694
|
+
d[N] = Ne(d, N, "link");
|
|
695
|
+
if (S.current = A, K.current) {
|
|
696
|
+
const N = {
|
|
687
697
|
type: "link",
|
|
688
698
|
startIndex: E.startIndex,
|
|
689
699
|
endIndex: E.endIndex,
|
|
690
700
|
marks: [],
|
|
691
701
|
href: E.search
|
|
692
702
|
};
|
|
693
|
-
|
|
703
|
+
K.current(N);
|
|
694
704
|
}
|
|
695
705
|
}
|
|
696
706
|
}
|
|
697
707
|
}
|
|
698
708
|
if (!Ie(p(d, g - 1))) {
|
|
699
|
-
const E =
|
|
709
|
+
const E = Je(I, g);
|
|
700
710
|
if (E && E.endIndex === g) {
|
|
701
711
|
const A = `${E.startIndex}:${E.endIndex}:${E.search}`;
|
|
702
|
-
if (
|
|
703
|
-
for (let
|
|
704
|
-
d[
|
|
705
|
-
if (
|
|
706
|
-
const
|
|
712
|
+
if (F.current !== A) {
|
|
713
|
+
for (let N = E.startIndex; N < E.endIndex; N++)
|
|
714
|
+
d[N] = Ne(d, N, "interest");
|
|
715
|
+
if (F.current = A, k.current) {
|
|
716
|
+
const N = {
|
|
707
717
|
type: "interest",
|
|
708
718
|
startIndex: E.startIndex,
|
|
709
719
|
endIndex: E.endIndex,
|
|
710
720
|
marks: [],
|
|
711
721
|
interest: E.search.replace(Se, "")
|
|
712
722
|
};
|
|
713
|
-
|
|
723
|
+
k.current(N);
|
|
714
724
|
}
|
|
715
725
|
}
|
|
716
726
|
}
|
|
717
727
|
}
|
|
718
728
|
}
|
|
719
|
-
|
|
720
|
-
|
|
729
|
+
j(d), J.current = !0, setTimeout(() => {
|
|
730
|
+
J.current = !1;
|
|
721
731
|
}, 50);
|
|
722
|
-
} else
|
|
723
|
-
|
|
724
|
-
},
|
|
725
|
-
|
|
726
|
-
},
|
|
727
|
-
|
|
728
|
-
},
|
|
729
|
-
|
|
732
|
+
} else P && V(!1);
|
|
733
|
+
D(I);
|
|
734
|
+
}, Xe = (h) => {
|
|
735
|
+
w.current && rt(h, U);
|
|
736
|
+
}, qe = () => {
|
|
737
|
+
ie(!0);
|
|
738
|
+
}, Ge = () => {
|
|
739
|
+
ie(!1);
|
|
730
740
|
};
|
|
731
741
|
a.useEffect(() => {
|
|
732
742
|
const h = () => {
|
|
733
|
-
if (
|
|
734
|
-
const I =
|
|
743
|
+
if (n.current) return;
|
|
744
|
+
const I = De(w.current) ?? {
|
|
735
745
|
start: 0,
|
|
736
746
|
end: 0
|
|
737
|
-
}, b =
|
|
738
|
-
(I.start !== b.start || I.end !== b.end) && (
|
|
747
|
+
}, b = L.current;
|
|
748
|
+
(I.start !== b.start || I.end !== b.end) && (L.current = I, H.current && !J.current && V(!1), $.current && clearTimeout($.current), $.current = setTimeout(() => {
|
|
739
749
|
be(I);
|
|
740
750
|
}, 500));
|
|
741
751
|
};
|
|
742
752
|
return document.addEventListener("selectionchange", h), () => {
|
|
743
|
-
document.removeEventListener("selectionchange", h),
|
|
753
|
+
document.removeEventListener("selectionchange", h), $.current && clearTimeout($.current);
|
|
744
754
|
};
|
|
745
755
|
}, []);
|
|
746
|
-
const
|
|
747
|
-
return /* @__PURE__ */
|
|
748
|
-
/* @__PURE__ */
|
|
749
|
-
/* @__PURE__ */
|
|
756
|
+
const He = v.length === 0 && y && !we;
|
|
757
|
+
return /* @__PURE__ */ B.jsxs(B.Fragment, { children: [
|
|
758
|
+
/* @__PURE__ */ B.jsxs("div", { style: { position: "relative" }, children: [
|
|
759
|
+
/* @__PURE__ */ B.jsx(
|
|
750
760
|
"div",
|
|
751
761
|
{
|
|
752
|
-
ref:
|
|
753
|
-
style: { ...
|
|
754
|
-
className:
|
|
762
|
+
ref: w,
|
|
763
|
+
style: { ...W.style, position: "relative", zIndex: 2 },
|
|
764
|
+
className: W.className,
|
|
755
765
|
contentEditable: !0,
|
|
756
|
-
onKeyDown:
|
|
757
|
-
onInput:
|
|
758
|
-
onFocus:
|
|
759
|
-
onBlur:
|
|
766
|
+
onKeyDown: Xe,
|
|
767
|
+
onInput: ve,
|
|
768
|
+
onFocus: qe,
|
|
769
|
+
onBlur: Ge,
|
|
760
770
|
role: "textbox",
|
|
761
771
|
"aria-multiline": "true",
|
|
762
772
|
autoCapitalize: "off",
|
|
763
773
|
autoFocus: !1
|
|
764
774
|
}
|
|
765
775
|
),
|
|
766
|
-
|
|
776
|
+
He && /* @__PURE__ */ B.jsx(
|
|
767
777
|
"div",
|
|
768
778
|
{
|
|
769
779
|
style: {
|
|
770
|
-
...
|
|
780
|
+
...W.style,
|
|
771
781
|
position: "absolute",
|
|
772
782
|
top: 0,
|
|
773
783
|
left: 0,
|
|
@@ -777,13 +787,13 @@ const Be = (e) => {
|
|
|
777
787
|
pointerEvents: "none"
|
|
778
788
|
},
|
|
779
789
|
"aria-hidden": "true",
|
|
780
|
-
children: /* @__PURE__ */
|
|
790
|
+
children: /* @__PURE__ */ B.jsx("p", { style: { margin: 0 }, children: y })
|
|
781
791
|
}
|
|
782
792
|
)
|
|
783
793
|
] }),
|
|
784
|
-
|
|
794
|
+
se && /* @__PURE__ */ B.jsx("div", { style: {}, children: /* @__PURE__ */ B.jsx("pre", { children: JSON.stringify(x) }) })
|
|
785
795
|
] });
|
|
786
796
|
};
|
|
787
797
|
export {
|
|
788
|
-
|
|
798
|
+
bt as Editor
|
|
789
799
|
};
|
package/dist/src/Editor.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { Entity, EntityOptions, StyleOptions, EntityType, MarkState, MarkType, MentionSearch } from './interfaces';
|
|
3
|
+
export interface EditorState {
|
|
4
|
+
plainText: string;
|
|
5
|
+
entities: Entity[];
|
|
6
|
+
markState: MarkState;
|
|
7
|
+
}
|
|
3
8
|
export interface EditorRef {
|
|
4
9
|
selectEntity: (entityType: EntityType, startIndex: number, endIndex: number, newText: string) => void;
|
|
5
10
|
toggleMark: (markType: MarkType) => void;
|
|
6
11
|
clear: () => void;
|
|
12
|
+
reset: () => void;
|
|
7
13
|
focus: () => void;
|
|
8
|
-
getState: () =>
|
|
9
|
-
plainText: string;
|
|
10
|
-
entities: Entity[];
|
|
11
|
-
markState: MarkState;
|
|
12
|
-
};
|
|
14
|
+
getState: () => EditorState;
|
|
13
15
|
}
|
|
14
16
|
export interface EditorProps {
|
|
15
17
|
ref: React.RefObject<EditorRef | null>;
|
|
@@ -19,6 +21,7 @@ export interface EditorProps {
|
|
|
19
21
|
onMarkStateChange?: (markState: MarkState) => void;
|
|
20
22
|
onLinkCreated?: (link: Entity) => void;
|
|
21
23
|
onInterestCreated?: (interest: Entity) => void;
|
|
24
|
+
onGetState?: (state: EditorState) => void;
|
|
22
25
|
style?: React.CSSProperties;
|
|
23
26
|
className?: string;
|
|
24
27
|
options?: EntityOptions;
|
|
@@ -26,4 +29,4 @@ export interface EditorProps {
|
|
|
26
29
|
placeholder?: string;
|
|
27
30
|
debug?: boolean;
|
|
28
31
|
}
|
|
29
|
-
export declare const Editor: ({ ref, initialPlainText, initialEntities, onMentionSearch, onMarkStateChange, onLinkCreated, onInterestCreated, options, entityStyles, placeholder, debug, ...props }: EditorProps) => import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
export declare const Editor: ({ ref, initialPlainText, initialEntities, onMentionSearch, onMarkStateChange, onLinkCreated, onInterestCreated, onGetState, options, entityStyles, placeholder, debug, ...props }: EditorProps) => import("react/jsx-runtime").JSX.Element;
|