@connectedxm/entity-editor 0.0.2 → 0.0.3
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 +423 -391
- package/dist/src/Editor.d.ts +3 -3
- 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 L = {};
|
|
35
35
|
/**
|
|
36
36
|
* @license React
|
|
37
37
|
* react-jsx-runtime.development.js
|
|
@@ -41,377 +41,377 @@ 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 === z ? 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 V:
|
|
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 y:
|
|
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 === y)
|
|
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 = T.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: I,
|
|
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
|
|
197
|
+
else p(k);
|
|
198
|
+
if (G.call(l, "key")) {
|
|
199
|
+
k = e(r);
|
|
200
|
+
var j = Object.keys(l).filter(function(Be) {
|
|
201
201
|
return Be !== "key";
|
|
202
202
|
});
|
|
203
|
-
|
|
203
|
+
g = 0 < j.length ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}", h[k + g] || (j = 0 < j.length ? "{" + j.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
|
+
j,
|
|
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 === I && r._store && (r._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var
|
|
238
|
+
var P = A, I = 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"), y = Symbol.for("react.lazy"), V = Symbol.for("react.activity"), z = Symbol.for("react.client.reference"), T = P.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, G = Object.prototype.hasOwnProperty, fe = Array.isArray, M = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
|
-
|
|
242
|
-
react_stack_bottom_frame: function(
|
|
243
|
-
return
|
|
241
|
+
P = {
|
|
242
|
+
react_stack_bottom_frame: function(r) {
|
|
243
|
+
return r();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var
|
|
247
|
-
|
|
246
|
+
var J, a = {}, _ = P.react_stack_bottom_frame.bind(
|
|
247
|
+
P,
|
|
248
248
|
i
|
|
249
|
-
)(),
|
|
250
|
-
|
|
251
|
-
var
|
|
249
|
+
)(), E = M(s(i)), h = {};
|
|
250
|
+
L.Fragment = O, L.jsx = function(r, l, d, g, R) {
|
|
251
|
+
var w = 1e4 > T.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 ? M(s(r)) : E
|
|
261
261
|
);
|
|
262
|
-
},
|
|
263
|
-
var
|
|
262
|
+
}, L.jsxs = function(r, l, d, g, R) {
|
|
263
|
+
var w = 1e4 > T.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 ? M(s(r)) : E
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
|
-
})()),
|
|
275
|
+
})()), L;
|
|
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 C = 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
|
-
}, Ve = (e, t,
|
|
318
|
-
let s = "",
|
|
319
|
-
t.includes("bold") && (
|
|
320
|
-
let
|
|
321
|
-
return s && (
|
|
322
|
-
}, Ce = (e, t,
|
|
317
|
+
}, Ve = (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(
|
|
327
|
+
o < i.startIndex && (s += e.slice(o, i.startIndex));
|
|
328
|
+
const c = e.slice(i.startIndex, i.endIndex), u = Ve(i.type, i.marks, n);
|
|
329
|
+
s += `<span style="${u}">${c}</span>`, o = i.endIndex;
|
|
330
|
+
}), s += e.slice(o), s;
|
|
331
331
|
}, ze = (e, t) => {
|
|
332
|
-
let
|
|
333
|
-
e.key === "Enter" && !e.shiftKey ? (e.preventDefault(), document.execCommand("insertLineBreak"),
|
|
334
|
-
}, ee = 128, Ge = /^(?<protocol>[a-z\-]+)?:?(?<host>\/\/.*\.[^\/]+)$/,
|
|
335
|
-
const
|
|
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 = /^(?<protocol>[a-z\-]+)?:?(?<host>\/\/.*\.[^\/]+)$/, Je = "()[]{}", Me = "", xe = (e, t) => {
|
|
335
|
+
const n = ve(
|
|
336
336
|
e,
|
|
337
337
|
t,
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
Je,
|
|
339
|
+
Me
|
|
340
340
|
);
|
|
341
|
-
return
|
|
341
|
+
return n?.search.match(Ge) ? {
|
|
342
342
|
type: "link",
|
|
343
|
-
...
|
|
343
|
+
...n
|
|
344
344
|
} : null;
|
|
345
|
-
}, te = (e) => (e & ee) !== 0,
|
|
346
|
-
const
|
|
345
|
+
}, te = (e) => (e & ee) !== 0, Re = (e, t) => t ? e | ee : e & ~ee, re = 32, Xe = /^@[a-zA-Z0-9_'-]+$/, qe = `.,!?;()[]{}"'<>#`, ne = "@", Le = (e, t) => {
|
|
346
|
+
const n = ve(
|
|
347
347
|
e,
|
|
348
348
|
t,
|
|
349
349
|
qe,
|
|
350
350
|
ne
|
|
351
351
|
);
|
|
352
|
-
return
|
|
352
|
+
return n?.search.match(Xe) ? {
|
|
353
353
|
type: "mention",
|
|
354
|
-
...
|
|
354
|
+
...n
|
|
355
355
|
} : null;
|
|
356
|
-
}, oe = (e) => (e & re) !== 0,
|
|
356
|
+
}, oe = (e) => (e & re) !== 0, _e = (e, t) => t ? e | re : e & ~re, D = 2, q = (e) => (e & D) !== 0, ke = (e, t) => t ? e | D : e & ~D, B = 4, H = (e) => (e & B) !== 0, be = (e, t) => t ? e | B : e & ~B, $ = 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, Pe = (e, t) => {
|
|
357
357
|
if (e === t) return null;
|
|
358
|
-
let
|
|
359
|
-
for (;
|
|
360
|
-
|
|
361
|
-
let s = e.length,
|
|
362
|
-
for (; s >
|
|
363
|
-
s--,
|
|
358
|
+
let n = 0;
|
|
359
|
+
for (; n < e.length && n < t.length && e[n] === t[n]; )
|
|
360
|
+
n++;
|
|
361
|
+
let s = e.length, o = t.length;
|
|
362
|
+
for (; s > n && o > n && e[s - 1] === t[o - 1]; )
|
|
363
|
+
s--, o--;
|
|
364
364
|
return {
|
|
365
|
-
position:
|
|
366
|
-
deletedLength: s -
|
|
367
|
-
insertedText: t.slice(
|
|
365
|
+
position: n,
|
|
366
|
+
deletedLength: s - n,
|
|
367
|
+
insertedText: t.slice(n, o)
|
|
368
368
|
};
|
|
369
|
-
},
|
|
370
|
-
let
|
|
371
|
-
for (;
|
|
372
|
-
const c =
|
|
373
|
-
if (
|
|
374
|
-
e[
|
|
369
|
+
}, ge = (e, t, n, s) => {
|
|
370
|
+
let o = t;
|
|
371
|
+
for (; o < e.length; ) {
|
|
372
|
+
const c = b(e, o);
|
|
373
|
+
if (n(c))
|
|
374
|
+
e[o] = s(c, !1);
|
|
375
375
|
else
|
|
376
376
|
break;
|
|
377
|
-
|
|
377
|
+
o++;
|
|
378
378
|
}
|
|
379
379
|
let i = t - 1;
|
|
380
380
|
for (; i >= 0; ) {
|
|
381
|
-
const c =
|
|
382
|
-
if (
|
|
381
|
+
const c = b(e, i);
|
|
382
|
+
if (n(c))
|
|
383
383
|
e[i] = s(c, !1);
|
|
384
384
|
else
|
|
385
385
|
break;
|
|
386
386
|
i--;
|
|
387
387
|
}
|
|
388
388
|
return e;
|
|
389
|
-
},
|
|
389
|
+
}, je = (e, t, n) => {
|
|
390
390
|
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
|
-
|
|
391
|
+
const { position: s, deletedLength: o, insertedText: i } = t, c = i.length;
|
|
392
|
+
let u = [...e];
|
|
393
|
+
const f = b(u, s);
|
|
394
|
+
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
|
+
let m = 0;
|
|
396
|
+
n.bold && (m = ke(m, !0)), n.italic && (m = be(m, !0)), n.underline && (m = we(m, !0)), n.strike && (m = Se(m, !0));
|
|
397
|
+
const N = new Array(c).fill(m);
|
|
398
|
+
u.splice(s, 0, ...N);
|
|
399
399
|
}
|
|
400
|
-
return
|
|
401
|
-
}, He = (e) => /\s/.test(e) || /[\u2000-\u200B\u2028\u2029\u3000]/.test(e),
|
|
400
|
+
return u;
|
|
401
|
+
}, He = (e) => /\s/.test(e) || /[\u2000-\u200B\u2028\u2029\u3000]/.test(e), ve = (e, t, n, s) => {
|
|
402
402
|
if (t <= 0 || t > e.length)
|
|
403
403
|
return null;
|
|
404
|
-
let
|
|
405
|
-
const
|
|
404
|
+
let o = "", i = t - 1, c = t;
|
|
405
|
+
const u = (f) => He(f) || n.includes(f);
|
|
406
406
|
for (let f = i; f >= 0; f--) {
|
|
407
|
-
if (
|
|
407
|
+
if (u(e[f])) {
|
|
408
408
|
i = f + 1;
|
|
409
409
|
break;
|
|
410
410
|
}
|
|
411
|
-
f === 0 && (i = 0),
|
|
411
|
+
f === 0 && (i = 0), o = e[f] + o;
|
|
412
412
|
}
|
|
413
413
|
for (let f = c; f < e.length; f++) {
|
|
414
|
-
if (
|
|
414
|
+
if (u(e[f])) {
|
|
415
415
|
c = f;
|
|
416
416
|
break;
|
|
417
417
|
}
|
|
@@ -419,93 +419,93 @@ const Ie = () => {
|
|
|
419
419
|
c = f;
|
|
420
420
|
break;
|
|
421
421
|
}
|
|
422
|
-
f === e.length - 1 && (c = e.length),
|
|
422
|
+
f === e.length - 1 && (c = e.length), o = o + e[f];
|
|
423
423
|
}
|
|
424
424
|
return {
|
|
425
425
|
search: e.slice(i, c),
|
|
426
426
|
startIndex: i,
|
|
427
427
|
endIndex: c
|
|
428
428
|
};
|
|
429
|
-
}, se = 64, Ze = `.,!?;()[]{}"'<>@`, Qe = /^#[\w-]+$/, ie = "#",
|
|
430
|
-
const
|
|
429
|
+
}, se = 64, Ze = `.,!?;()[]{}"'<>@`, Qe = /^#[\w-]+$/, ie = "#", De = (e, t) => {
|
|
430
|
+
const n = ve(
|
|
431
431
|
e,
|
|
432
432
|
t,
|
|
433
433
|
Ze,
|
|
434
434
|
ie
|
|
435
435
|
);
|
|
436
|
-
return
|
|
436
|
+
return n?.search.match(Qe) ? {
|
|
437
437
|
type: "interest",
|
|
438
|
-
...
|
|
438
|
+
...n
|
|
439
439
|
} : null;
|
|
440
|
-
}, ce = (e) => (e & se) !== 0,
|
|
441
|
-
(
|
|
442
|
-
), tt = (e, t,
|
|
440
|
+
}, ce = (e) => (e & se) !== 0, Ne = (e, t) => t ? e | se : e & ~se, et = (e, t) => e.find(
|
|
441
|
+
(n) => n.startIndex <= t && n.endIndex > t
|
|
442
|
+
), tt = (e, t, n) => {
|
|
443
443
|
const s = [];
|
|
444
|
-
let
|
|
445
|
-
for (;
|
|
446
|
-
const i =
|
|
444
|
+
let o = 0;
|
|
445
|
+
for (; o < t.length; ) {
|
|
446
|
+
const i = b(t, o);
|
|
447
447
|
if (i === 0 || i === 1) {
|
|
448
|
-
|
|
448
|
+
o++;
|
|
449
449
|
continue;
|
|
450
450
|
}
|
|
451
|
-
const c =
|
|
452
|
-
let
|
|
453
|
-
for (;
|
|
454
|
-
|
|
455
|
-
const f = rt(i,
|
|
451
|
+
const c = o;
|
|
452
|
+
let u = o;
|
|
453
|
+
for (; u + 1 < t.length && b(t, u + 1) === i; )
|
|
454
|
+
u++;
|
|
455
|
+
const f = rt(i, n), m = nt(i), N = {
|
|
456
456
|
type: f,
|
|
457
457
|
startIndex: c,
|
|
458
|
-
endIndex:
|
|
459
|
-
marks:
|
|
460
|
-
username: f === "mention" ?
|
|
461
|
-
interest: f === "interest" ?
|
|
458
|
+
endIndex: u + 1,
|
|
459
|
+
marks: m,
|
|
460
|
+
username: f === "mention" ? Le(e, u)?.search.replace(ne, "") : void 0,
|
|
461
|
+
interest: f === "interest" ? De(e, u)?.search.replace(
|
|
462
462
|
ie,
|
|
463
463
|
""
|
|
464
464
|
) : void 0,
|
|
465
|
-
href: f === "link" ?
|
|
465
|
+
href: f === "link" ? xe(e, u)?.search : void 0
|
|
466
466
|
};
|
|
467
|
-
s.push(N),
|
|
467
|
+
s.push(N), o = u + 1;
|
|
468
468
|
}
|
|
469
469
|
return s;
|
|
470
|
-
}, rt = (e, t) => e & re && t.mentions ? "mention" : e & se && t.interests ? "interest" : e & ee && t.links ? "link" : (e & (
|
|
470
|
+
}, rt = (e, t) => e & re && t.mentions ? "mention" : e & se && t.interests ? "interest" : e & ee && t.links ? "link" : (e & (D | B | Y | $), "segment"), nt = (e) => {
|
|
471
471
|
const t = [];
|
|
472
|
-
return e &
|
|
473
|
-
},
|
|
474
|
-
const
|
|
475
|
-
return typeof
|
|
476
|
-
}, ot = (e, t,
|
|
477
|
-
const s =
|
|
478
|
-
switch (
|
|
472
|
+
return e & D && t.push("bold"), e & B && t.push("italic"), e & Y && t.push("underline"), e & $ && t.push("strike"), t;
|
|
473
|
+
}, b = (e, t) => {
|
|
474
|
+
const n = e[t];
|
|
475
|
+
return typeof n != "number" ? 0 : n;
|
|
476
|
+
}, ot = (e, t, n) => {
|
|
477
|
+
const s = b(e, t);
|
|
478
|
+
switch (n) {
|
|
479
479
|
case "mention":
|
|
480
|
-
return
|
|
480
|
+
return _e(s, !0);
|
|
481
481
|
case "interest":
|
|
482
|
-
return
|
|
482
|
+
return Ne(s, !0);
|
|
483
483
|
case "link":
|
|
484
|
-
return
|
|
484
|
+
return Re(s, !0);
|
|
485
485
|
}
|
|
486
486
|
return s;
|
|
487
|
-
}, st = (e, t,
|
|
488
|
-
let
|
|
489
|
-
switch (
|
|
487
|
+
}, st = (e, t, n, s) => {
|
|
488
|
+
let o = b(e, t);
|
|
489
|
+
switch (n) {
|
|
490
490
|
case "bold":
|
|
491
|
-
|
|
491
|
+
o = ke(o, s);
|
|
492
492
|
break;
|
|
493
493
|
case "italic":
|
|
494
|
-
|
|
494
|
+
o = be(o, s);
|
|
495
495
|
break;
|
|
496
496
|
case "underline":
|
|
497
|
-
|
|
497
|
+
o = we(o, s);
|
|
498
498
|
break;
|
|
499
499
|
case "strike":
|
|
500
|
-
|
|
500
|
+
o = Se(o, s);
|
|
501
501
|
break;
|
|
502
502
|
default:
|
|
503
503
|
return e;
|
|
504
504
|
}
|
|
505
|
-
return e[t] =
|
|
506
|
-
}, it = (e, t,
|
|
507
|
-
const s =
|
|
508
|
-
switch (
|
|
505
|
+
return e[t] = o, e;
|
|
506
|
+
}, it = (e, t, n) => {
|
|
507
|
+
const s = b(e, t);
|
|
508
|
+
switch (n) {
|
|
509
509
|
case "bold":
|
|
510
510
|
return q(s);
|
|
511
511
|
case "italic":
|
|
@@ -515,160 +515,192 @@ const Ie = () => {
|
|
|
515
515
|
case "strike":
|
|
516
516
|
return Z(s);
|
|
517
517
|
default:
|
|
518
|
-
throw Error(`Invalid mark type: ${
|
|
518
|
+
throw Error(`Invalid mark type: ${n}`);
|
|
519
519
|
}
|
|
520
|
-
}, ct = (e, t,
|
|
521
|
-
for (let
|
|
522
|
-
if (!it(s,
|
|
520
|
+
}, ct = (e, t, n, s) => {
|
|
521
|
+
for (let o = e; o < t; o++)
|
|
522
|
+
if (!it(s, o, n)) return !1;
|
|
523
523
|
return !0;
|
|
524
|
-
},
|
|
525
|
-
let
|
|
526
|
-
for (;
|
|
524
|
+
}, pe = (e) => oe(e) || ce(e) || te(e), lt = (e, t, n, s) => {
|
|
525
|
+
let o = [...e];
|
|
526
|
+
for (; pe(b(e, t - 1)) && t > 0; )
|
|
527
527
|
t--;
|
|
528
|
-
for (;
|
|
529
|
-
|
|
528
|
+
for (; pe(b(e, n)) && n < e.length; )
|
|
529
|
+
n++;
|
|
530
530
|
let i = !0;
|
|
531
|
-
ct(t,
|
|
532
|
-
for (let c = t; c <
|
|
533
|
-
|
|
534
|
-
return
|
|
531
|
+
ct(t, n, s, o) && (i = !1);
|
|
532
|
+
for (let c = t; c < n; c++)
|
|
533
|
+
o = st(o, c, s, i);
|
|
534
|
+
return o;
|
|
535
535
|
}, Te = (e, t) => {
|
|
536
|
-
const
|
|
536
|
+
const n = new Array(e.length).fill(0);
|
|
537
537
|
for (let s = 0; s < e.length; s++) {
|
|
538
|
-
let
|
|
538
|
+
let o = 0;
|
|
539
539
|
const i = et(t, s);
|
|
540
540
|
if (i) {
|
|
541
|
-
i.type === "mention" ?
|
|
541
|
+
i.type === "mention" ? o = _e(o, !0) : i.type === "interest" ? o = Ne(o, !0) : i.type === "link" && (o = Re(o, !0));
|
|
542
542
|
for (const c of i.marks)
|
|
543
|
-
c === "bold" ?
|
|
543
|
+
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
544
|
}
|
|
545
|
-
|
|
545
|
+
n[s] = o;
|
|
546
546
|
}
|
|
547
|
-
return
|
|
548
|
-
}, ut = (e, t,
|
|
549
|
-
const [s,
|
|
550
|
-
return
|
|
551
|
-
|
|
547
|
+
return n;
|
|
548
|
+
}, ut = (e, t, n) => {
|
|
549
|
+
const [s, o] = $e(e), i = me(Date.now()), c = me(null), u = me(null);
|
|
550
|
+
return Ye(() => (c.current && clearTimeout(c.current), u.current && clearTimeout(u.current), Date.now() - i.current, c.current = setTimeout(() => {
|
|
551
|
+
o(e), i.current = Date.now();
|
|
552
552
|
}, t), () => {
|
|
553
|
-
c.current && clearTimeout(c.current),
|
|
554
|
-
}), [e, t,
|
|
553
|
+
c.current && clearTimeout(c.current), u.current && clearTimeout(u.current);
|
|
554
|
+
}), [e, t, n]), s;
|
|
555
555
|
}, ft = ({
|
|
556
556
|
ref: e,
|
|
557
557
|
plainText: t = "",
|
|
558
|
-
setPlainText:
|
|
558
|
+
setPlainText: n,
|
|
559
559
|
entities: s = [],
|
|
560
|
-
setEntities:
|
|
560
|
+
setEntities: o,
|
|
561
561
|
markState: i,
|
|
562
562
|
setMarkState: c,
|
|
563
|
-
search:
|
|
563
|
+
search: u,
|
|
564
564
|
setSearch: f,
|
|
565
|
-
options:
|
|
565
|
+
options: m = {},
|
|
566
566
|
entityStyles: N = {},
|
|
567
|
-
|
|
568
|
-
|
|
567
|
+
placeholder: p = "",
|
|
568
|
+
debug: P = !1,
|
|
569
|
+
...I
|
|
569
570
|
}) => {
|
|
570
|
-
const
|
|
571
|
+
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, y] = A.useState(
|
|
571
572
|
Te(t, s)
|
|
572
573
|
);
|
|
573
574
|
e.current = {
|
|
574
|
-
selectEntity: (
|
|
575
|
-
if (!
|
|
576
|
-
let
|
|
577
|
-
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
for (let
|
|
581
|
-
|
|
582
|
-
|
|
575
|
+
selectEntity: (a, _, E, h) => {
|
|
576
|
+
if (!v.current) return;
|
|
577
|
+
let r = [...S];
|
|
578
|
+
a === "mention" ? h = ne + h : a === "interest" ? h = ie + h : a === "link" && (h = Me + h);
|
|
579
|
+
const l = t.slice(0, _) + h + t.slice(E), d = Pe(t, l);
|
|
580
|
+
d ? r = je(S, d, i) : r = Te(l, s);
|
|
581
|
+
for (let g = _; g < _ + h.length; g++)
|
|
582
|
+
r[g] = ot(r, g, a);
|
|
583
|
+
n(l), y(r), f(null);
|
|
583
584
|
},
|
|
584
|
-
toggleMark: (
|
|
585
|
-
|
|
585
|
+
toggleMark: (a) => {
|
|
586
|
+
z(a);
|
|
586
587
|
}
|
|
587
|
-
},
|
|
588
|
-
if (
|
|
589
|
-
|
|
590
|
-
const
|
|
591
|
-
|
|
588
|
+
}, A.useEffect(() => {
|
|
589
|
+
if (v.current) {
|
|
590
|
+
v.current.textContent = t;
|
|
591
|
+
const a = Ce(t, s, N);
|
|
592
|
+
v.current.innerHTML = a, K || ue(!0);
|
|
592
593
|
}
|
|
593
|
-
}, []),
|
|
594
|
-
if (!
|
|
595
|
-
const
|
|
596
|
-
|
|
597
|
-
}, [
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
let { start:
|
|
601
|
-
if (!
|
|
602
|
-
let
|
|
603
|
-
if (
|
|
604
|
-
if (
|
|
605
|
-
const
|
|
606
|
-
|
|
594
|
+
}, []), A.useEffect(() => {
|
|
595
|
+
if (!v.current) return;
|
|
596
|
+
const a = tt(t, S, m), _ = ye() ?? O, E = Ce(t, a, N);
|
|
597
|
+
v.current.innerHTML = E, o(a), K && Ue(v.current, _);
|
|
598
|
+
}, [S]);
|
|
599
|
+
const V = ut(O, 500);
|
|
600
|
+
A.useEffect(() => {
|
|
601
|
+
let { start: a, end: _ } = V, E = null;
|
|
602
|
+
if (!E && !oe(b(S, a - 1)) && (E = Le(t, a), E && (E.search = E.search.replace(ne, ""))), !E && !ce(b(S, a - 1)) && (E = De(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;
|
|
603
|
+
let h = !0, r = !0, l = !0, d = !0;
|
|
604
|
+
if (a === _)
|
|
605
|
+
if (a > 0) {
|
|
606
|
+
const R = b(S, a - 1);
|
|
607
|
+
h = q(R), r = H(R), l = Q(R), d = Z(R);
|
|
607
608
|
} else {
|
|
608
|
-
const
|
|
609
|
-
|
|
609
|
+
const R = b(S, a);
|
|
610
|
+
h = q(R), r = H(R), l = Q(R), d = Z(R);
|
|
610
611
|
}
|
|
611
612
|
else
|
|
612
|
-
for (let
|
|
613
|
-
const
|
|
614
|
-
|
|
613
|
+
for (let R = a; R < _; R++) {
|
|
614
|
+
const w = b(S, R);
|
|
615
|
+
h = q(w) ? h : !1, r = H(w) ? r : !1, l = Q(w) ? l : !1, d = Z(w) ? d : !1;
|
|
615
616
|
}
|
|
616
617
|
c({
|
|
617
|
-
bold:
|
|
618
|
-
italic:
|
|
619
|
-
underline:
|
|
620
|
-
strike:
|
|
618
|
+
bold: h,
|
|
619
|
+
italic: r,
|
|
620
|
+
underline: l,
|
|
621
|
+
strike: d
|
|
621
622
|
});
|
|
622
|
-
}, [
|
|
623
|
-
const
|
|
624
|
-
if (
|
|
623
|
+
}, [V]);
|
|
624
|
+
const z = (a) => {
|
|
625
|
+
if (W(!0), !v.current)
|
|
625
626
|
return;
|
|
626
|
-
const { start:
|
|
627
|
-
if (
|
|
628
|
-
const
|
|
629
|
-
|
|
627
|
+
const { start: _, end: E } = O;
|
|
628
|
+
if (_ !== E) {
|
|
629
|
+
const r = lt(S, _, E, a);
|
|
630
|
+
y(r);
|
|
630
631
|
}
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
},
|
|
634
|
-
if (!
|
|
635
|
-
if (
|
|
636
|
-
|
|
632
|
+
const h = { ...i };
|
|
633
|
+
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
|
+
}, T = (a) => {
|
|
635
|
+
if (!v.current) return;
|
|
636
|
+
if (F && W(!1), a.target.textContent.length === 0) {
|
|
637
|
+
n(""), y([]), o([]);
|
|
637
638
|
return;
|
|
638
639
|
}
|
|
639
|
-
const
|
|
640
|
-
if (
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
|
|
640
|
+
const _ = a.target.innerText || "", E = Pe(t, _);
|
|
641
|
+
if (E) {
|
|
642
|
+
const h = je(
|
|
643
|
+
S,
|
|
644
|
+
E,
|
|
644
645
|
i
|
|
645
646
|
);
|
|
646
|
-
|
|
647
|
+
y(h);
|
|
647
648
|
}
|
|
648
|
-
|
|
649
|
-
},
|
|
650
|
-
|
|
649
|
+
n(_);
|
|
650
|
+
}, G = (a) => {
|
|
651
|
+
v.current && ze(a, z);
|
|
652
|
+
}, fe = () => {
|
|
653
|
+
U(!0);
|
|
654
|
+
}, M = () => {
|
|
655
|
+
U(!1);
|
|
651
656
|
};
|
|
652
|
-
|
|
653
|
-
const
|
|
654
|
-
const
|
|
655
|
-
(
|
|
657
|
+
A.useEffect(() => {
|
|
658
|
+
const a = () => {
|
|
659
|
+
const _ = ye() ?? { start: 0, end: 0 };
|
|
660
|
+
(_.start !== O.start || _.end !== O.end) && le(_);
|
|
656
661
|
};
|
|
657
|
-
return document.addEventListener("selectionchange",
|
|
658
|
-
document.removeEventListener("selectionchange",
|
|
662
|
+
return document.addEventListener("selectionchange", a), () => {
|
|
663
|
+
document.removeEventListener("selectionchange", a);
|
|
659
664
|
};
|
|
660
|
-
}, [])
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
665
|
+
}, []);
|
|
666
|
+
const J = t.length === 0 && p && !ae;
|
|
667
|
+
return /* @__PURE__ */ C.jsxs(C.Fragment, { children: [
|
|
668
|
+
/* @__PURE__ */ C.jsxs("div", { style: { position: "relative" }, children: [
|
|
669
|
+
/* @__PURE__ */ C.jsx(
|
|
670
|
+
"div",
|
|
671
|
+
{
|
|
672
|
+
id: "entity-editor",
|
|
673
|
+
ref: v,
|
|
674
|
+
style: { ...I.style, position: "relative", zIndex: 2 },
|
|
675
|
+
className: I.className,
|
|
676
|
+
contentEditable: !0,
|
|
677
|
+
onKeyDown: G,
|
|
678
|
+
onInput: T,
|
|
679
|
+
onFocus: fe,
|
|
680
|
+
onBlur: M,
|
|
681
|
+
role: "textbox",
|
|
682
|
+
"aria-multiline": "true"
|
|
683
|
+
}
|
|
684
|
+
),
|
|
685
|
+
J && /* @__PURE__ */ C.jsx(
|
|
686
|
+
"div",
|
|
687
|
+
{
|
|
688
|
+
style: {
|
|
689
|
+
position: "absolute",
|
|
690
|
+
top: 0,
|
|
691
|
+
left: 0,
|
|
692
|
+
paddingTop: I.style?.paddingTop,
|
|
693
|
+
paddingLeft: I.style?.paddingLeft,
|
|
694
|
+
padding: I.style?.padding,
|
|
695
|
+
color: "#9ca3af"
|
|
696
|
+
},
|
|
697
|
+
"aria-hidden": "true",
|
|
698
|
+
children: p
|
|
699
|
+
}
|
|
700
|
+
)
|
|
701
|
+
] }),
|
|
702
|
+
P && /* @__PURE__ */ C.jsx("div", { style: {}, children: /* @__PURE__ */ C.jsx("pre", { children: JSON.stringify(S) }) })
|
|
703
|
+
] });
|
|
672
704
|
};
|
|
673
705
|
export {
|
|
674
706
|
ft as Editor
|
package/dist/src/Editor.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface EditorRef {
|
|
|
4
4
|
selectEntity: (entityType: EntityType, startIndex: number, endIndex: number, newText: string) => void;
|
|
5
5
|
toggleMark: (markType: MarkType) => void;
|
|
6
6
|
}
|
|
7
|
-
interface EditorProps {
|
|
7
|
+
export interface EditorProps {
|
|
8
8
|
ref: React.RefObject<EditorRef | null>;
|
|
9
9
|
plainText: string;
|
|
10
10
|
setPlainText: (plainText: string) => void;
|
|
@@ -18,7 +18,7 @@ interface EditorProps {
|
|
|
18
18
|
className?: string;
|
|
19
19
|
options?: EntityOptions;
|
|
20
20
|
entityStyles?: StyleOptions;
|
|
21
|
+
placeholder?: string;
|
|
21
22
|
debug?: boolean;
|
|
22
23
|
}
|
|
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 {};
|
|
24
|
+
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;
|