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