react-input-emoji 5.8.1 → 5.9.0-beta.2
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 +600 -1052
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +600 -1052
- package/dist/index.js.map +1 -1
- package/dist/src/utils/input-event-utils.d.ts +9 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -37,479 +37,10 @@ function styleInject(css, ref) {
|
|
37
37
|
var css_248z = ".react-input-emoji--container {\n color: #4b4b4b;\n text-rendering: optimizeLegibility;\n background-color: #fff;\n border: 1px solid #fff;\n border-radius: 21px;\n margin: 5px 10px;\n box-sizing: border-box;\n flex: 1 1 auto;\n font-size: 15px;\n font-family: sans-serif;\n font-weight: 400;\n line-height: 20px;\n min-height: 20px;\n min-width: 0;\n outline: none;\n width: inherit;\n will-change: width;\n vertical-align: baseline;\n border: 1px solid #eaeaea;\n margin-right: 0;\n}\n\n.react-input-emoji--wrapper {\n display: flex;\n overflow: hidden;\n flex: 1;\n position: relative;\n padding-right: 0;\n vertical-align: baseline;\n outline: none;\n margin: 0;\n padding: 0;\n border: 0;\n}\n\n.react-input-emoji--input {\n font-weight: 400;\n max-height: 100px;\n min-height: 20px;\n outline: none;\n overflow-x: hidden;\n overflow-y: auto;\n position: relative;\n white-space: pre-wrap;\n word-wrap: break-word;\n z-index: 1;\n width: 100%;\n user-select: text;\n padding: 9px 12px 11px;\n text-align: left;\n}\n\n.react-input-emoji--input img {\n vertical-align: middle;\n width: 18px !important;\n height: 18px !important;\n display: inline !important;\n margin-left: 1px;\n margin-right: 1px;\n}\n\n.react-input-emoji--overlay {\n position: fixed;\n width: 100%;\n height: 100%;\n top: 0;\n left: 0;\n z-index: 9;\n}\n\n.react-input-emoji--placeholder {\n color: #a0a0a0;\n pointer-events: none;\n position: absolute;\n user-select: none;\n z-index: 2;\n left: 16px;\n top: 0;\n bottom: 0;\n display: flex;\n align-items: center;\n width: calc(100% - 22px);\n}\n\n.react-input-emoji--button {\n position: relative;\n display: block;\n text-align: center;\n padding: 0 10px;\n overflow: hidden;\n transition: color 0.1s ease-out;\n margin: 0;\n box-shadow: none;\n background: none;\n border: none;\n outline: none;\n cursor: pointer;\n flex-shrink: 0;\n}\n\n.react-input-emoji--button svg {\n fill: #858585;\n}\n\n.react-input-emoji--button__show svg {\n fill: #128b7e;\n}\n\n.react-emoji {\n display: flex;\n align-items: center;\n position: relative;\n width: 100%;\n}\n\n.react-emoji-picker--container {\n position: absolute;\n top: 0;\n width: 100%;\n}\n\n.react-emoji-picker--wrapper {\n position: absolute;\n bottom: 0;\n right: 0;\n height: 435px;\n width: 352px;\n overflow: hidden;\n z-index: 10;\n}\n\n.react-emoji-picker {\n position: absolute;\n top: 0;\n left: 0;\n animation: slidein 0.1s ease-in-out;\n}\n\n.react-emoji-picker__show {\n top: 0;\n}\n\n.react-input-emoji--mention--container {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n z-index: 10;\n}\n\n.react-input-emoji--mention--list {\n background-color: #fafafa;\n border: 1px solid #eaeaea;\n border-radius: 4px;\n margin: 0;\n padding: 0;\n list-style: none;\n display: flex;\n gap: 5px;\n flex-direction: column;\n position: absolute;\n bottom: 0;\n width: 100%;\n left: 0;\n}\n\n.react-input-emoji--mention--item {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 5px 10px;\n background-color: transparent;\n width: 100%;\n margin: 0;\n border: 0;\n}\n\n.react-input-emoji--mention--item__selected {\n background-color: #eeeeee;\n}\n\n.react-input-emoji--mention--item--img {\n width: 34px;\n height: 34px;\n border-radius: 50%;\n}\n\n.react-input-emoji--mention--item--name {\n font-size: 16px;\n color: #333;\n}\n\n.react-input-emoji--mention--item--name__selected {\n color: green;\n}\n\n.react-input-emoji--mention--text {\n color: #039be5;\n}\n\n.react-input-emoji--mention--loading {\n background-color: #fafafa;\n border: 1px solid #eaeaea;\n border-radius: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 10px 0;\n position: absolute;\n bottom: 0;\n left: 0;\n width: 100%;\n}\n\n.react-input-emoji--mention--loading--spinner,\n.react-input-emoji--mention--loading--spinner::after {\n border-radius: 50%;\n width: 10em;\n height: 10em;\n}\n\n.react-input-emoji--mention--loading--spinner {\n margin: 1px auto;\n font-size: 2px;\n position: relative;\n text-indent: -9999em;\n border-top: 1.1em solid rgba(0, 0, 0, 0.1);\n border-right: 1.1em solid rgba(0, 0, 0, 0.1);\n border-bottom: 1.1em solid rgba(0, 0, 0, 0.1);\n border-left: 1.1em solid rgba(0, 0, 0, 0.4);\n transform: translateZ(0);\n animation: load8 1.1s infinite linear;\n}\n\n@keyframes load8 {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n\n@keyframes slidein {\n from {\n opacity: 0;\n }\n\n to {\n opacity: 1;\n }\n}\n";
|
38
38
|
styleInject(css_248z);
|
39
39
|
|
40
|
-
function _iterableToArrayLimit(r, l) {
|
41
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
42
|
-
if (null != t) {
|
43
|
-
var e,
|
44
|
-
n,
|
45
|
-
i,
|
46
|
-
u,
|
47
|
-
a = [],
|
48
|
-
f = !0,
|
49
|
-
o = !1;
|
50
|
-
try {
|
51
|
-
if (i = (t = t.call(r)).next, 0 === l) {
|
52
|
-
if (Object(t) !== t) return;
|
53
|
-
f = !1;
|
54
|
-
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
55
|
-
} catch (r) {
|
56
|
-
o = !0, n = r;
|
57
|
-
} finally {
|
58
|
-
try {
|
59
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
60
|
-
} finally {
|
61
|
-
if (o) throw n;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
return a;
|
65
|
-
}
|
66
|
-
}
|
67
|
-
function ownKeys(e, r) {
|
68
|
-
var t = Object.keys(e);
|
69
|
-
if (Object.getOwnPropertySymbols) {
|
70
|
-
var o = Object.getOwnPropertySymbols(e);
|
71
|
-
r && (o = o.filter(function (r) {
|
72
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
73
|
-
})), t.push.apply(t, o);
|
74
|
-
}
|
75
|
-
return t;
|
76
|
-
}
|
77
|
-
function _objectSpread2(e) {
|
78
|
-
for (var r = 1; r < arguments.length; r++) {
|
79
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
80
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
81
|
-
_defineProperty(e, r, t[r]);
|
82
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
83
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
84
|
-
});
|
85
|
-
}
|
86
|
-
return e;
|
87
|
-
}
|
88
|
-
function _regeneratorRuntime() {
|
89
|
-
_regeneratorRuntime = function () {
|
90
|
-
return e;
|
91
|
-
};
|
92
|
-
var t,
|
93
|
-
e = {},
|
94
|
-
r = Object.prototype,
|
95
|
-
n = r.hasOwnProperty,
|
96
|
-
o = Object.defineProperty || function (t, e, r) {
|
97
|
-
t[e] = r.value;
|
98
|
-
},
|
99
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
100
|
-
a = i.iterator || "@@iterator",
|
101
|
-
c = i.asyncIterator || "@@asyncIterator",
|
102
|
-
u = i.toStringTag || "@@toStringTag";
|
103
|
-
function define(t, e, r) {
|
104
|
-
return Object.defineProperty(t, e, {
|
105
|
-
value: r,
|
106
|
-
enumerable: !0,
|
107
|
-
configurable: !0,
|
108
|
-
writable: !0
|
109
|
-
}), t[e];
|
110
|
-
}
|
111
|
-
try {
|
112
|
-
define({}, "");
|
113
|
-
} catch (t) {
|
114
|
-
define = function (t, e, r) {
|
115
|
-
return t[e] = r;
|
116
|
-
};
|
117
|
-
}
|
118
|
-
function wrap(t, e, r, n) {
|
119
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
120
|
-
a = Object.create(i.prototype),
|
121
|
-
c = new Context(n || []);
|
122
|
-
return o(a, "_invoke", {
|
123
|
-
value: makeInvokeMethod(t, r, c)
|
124
|
-
}), a;
|
125
|
-
}
|
126
|
-
function tryCatch(t, e, r) {
|
127
|
-
try {
|
128
|
-
return {
|
129
|
-
type: "normal",
|
130
|
-
arg: t.call(e, r)
|
131
|
-
};
|
132
|
-
} catch (t) {
|
133
|
-
return {
|
134
|
-
type: "throw",
|
135
|
-
arg: t
|
136
|
-
};
|
137
|
-
}
|
138
|
-
}
|
139
|
-
e.wrap = wrap;
|
140
|
-
var h = "suspendedStart",
|
141
|
-
l = "suspendedYield",
|
142
|
-
f = "executing",
|
143
|
-
s = "completed",
|
144
|
-
y = {};
|
145
|
-
function Generator() {}
|
146
|
-
function GeneratorFunction() {}
|
147
|
-
function GeneratorFunctionPrototype() {}
|
148
|
-
var p = {};
|
149
|
-
define(p, a, function () {
|
150
|
-
return this;
|
151
|
-
});
|
152
|
-
var d = Object.getPrototypeOf,
|
153
|
-
v = d && d(d(values([])));
|
154
|
-
v && v !== r && n.call(v, a) && (p = v);
|
155
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
156
|
-
function defineIteratorMethods(t) {
|
157
|
-
["next", "throw", "return"].forEach(function (e) {
|
158
|
-
define(t, e, function (t) {
|
159
|
-
return this._invoke(e, t);
|
160
|
-
});
|
161
|
-
});
|
162
|
-
}
|
163
|
-
function AsyncIterator(t, e) {
|
164
|
-
function invoke(r, o, i, a) {
|
165
|
-
var c = tryCatch(t[r], t, o);
|
166
|
-
if ("throw" !== c.type) {
|
167
|
-
var u = c.arg,
|
168
|
-
h = u.value;
|
169
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
170
|
-
invoke("next", t, i, a);
|
171
|
-
}, function (t) {
|
172
|
-
invoke("throw", t, i, a);
|
173
|
-
}) : e.resolve(h).then(function (t) {
|
174
|
-
u.value = t, i(u);
|
175
|
-
}, function (t) {
|
176
|
-
return invoke("throw", t, i, a);
|
177
|
-
});
|
178
|
-
}
|
179
|
-
a(c.arg);
|
180
|
-
}
|
181
|
-
var r;
|
182
|
-
o(this, "_invoke", {
|
183
|
-
value: function (t, n) {
|
184
|
-
function callInvokeWithMethodAndArg() {
|
185
|
-
return new e(function (e, r) {
|
186
|
-
invoke(t, n, e, r);
|
187
|
-
});
|
188
|
-
}
|
189
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
190
|
-
}
|
191
|
-
});
|
192
|
-
}
|
193
|
-
function makeInvokeMethod(e, r, n) {
|
194
|
-
var o = h;
|
195
|
-
return function (i, a) {
|
196
|
-
if (o === f) throw new Error("Generator is already running");
|
197
|
-
if (o === s) {
|
198
|
-
if ("throw" === i) throw a;
|
199
|
-
return {
|
200
|
-
value: t,
|
201
|
-
done: !0
|
202
|
-
};
|
203
|
-
}
|
204
|
-
for (n.method = i, n.arg = a;;) {
|
205
|
-
var c = n.delegate;
|
206
|
-
if (c) {
|
207
|
-
var u = maybeInvokeDelegate(c, n);
|
208
|
-
if (u) {
|
209
|
-
if (u === y) continue;
|
210
|
-
return u;
|
211
|
-
}
|
212
|
-
}
|
213
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
214
|
-
if (o === h) throw o = s, n.arg;
|
215
|
-
n.dispatchException(n.arg);
|
216
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
217
|
-
o = f;
|
218
|
-
var p = tryCatch(e, r, n);
|
219
|
-
if ("normal" === p.type) {
|
220
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
221
|
-
return {
|
222
|
-
value: p.arg,
|
223
|
-
done: n.done
|
224
|
-
};
|
225
|
-
}
|
226
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
227
|
-
}
|
228
|
-
};
|
229
|
-
}
|
230
|
-
function maybeInvokeDelegate(e, r) {
|
231
|
-
var n = r.method,
|
232
|
-
o = e.iterator[n];
|
233
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
234
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
235
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
236
|
-
var a = i.arg;
|
237
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
238
|
-
}
|
239
|
-
function pushTryEntry(t) {
|
240
|
-
var e = {
|
241
|
-
tryLoc: t[0]
|
242
|
-
};
|
243
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
244
|
-
}
|
245
|
-
function resetTryEntry(t) {
|
246
|
-
var e = t.completion || {};
|
247
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
248
|
-
}
|
249
|
-
function Context(t) {
|
250
|
-
this.tryEntries = [{
|
251
|
-
tryLoc: "root"
|
252
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
253
|
-
}
|
254
|
-
function values(e) {
|
255
|
-
if (e || "" === e) {
|
256
|
-
var r = e[a];
|
257
|
-
if (r) return r.call(e);
|
258
|
-
if ("function" == typeof e.next) return e;
|
259
|
-
if (!isNaN(e.length)) {
|
260
|
-
var o = -1,
|
261
|
-
i = function next() {
|
262
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
263
|
-
return next.value = t, next.done = !0, next;
|
264
|
-
};
|
265
|
-
return i.next = i;
|
266
|
-
}
|
267
|
-
}
|
268
|
-
throw new TypeError(typeof e + " is not iterable");
|
269
|
-
}
|
270
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
271
|
-
value: GeneratorFunctionPrototype,
|
272
|
-
configurable: !0
|
273
|
-
}), o(GeneratorFunctionPrototype, "constructor", {
|
274
|
-
value: GeneratorFunction,
|
275
|
-
configurable: !0
|
276
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
277
|
-
var e = "function" == typeof t && t.constructor;
|
278
|
-
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
279
|
-
}, e.mark = function (t) {
|
280
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
281
|
-
}, e.awrap = function (t) {
|
282
|
-
return {
|
283
|
-
__await: t
|
284
|
-
};
|
285
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
286
|
-
return this;
|
287
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
288
|
-
void 0 === i && (i = Promise);
|
289
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
290
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
291
|
-
return t.done ? t.value : a.next();
|
292
|
-
});
|
293
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
294
|
-
return this;
|
295
|
-
}), define(g, "toString", function () {
|
296
|
-
return "[object Generator]";
|
297
|
-
}), e.keys = function (t) {
|
298
|
-
var e = Object(t),
|
299
|
-
r = [];
|
300
|
-
for (var n in e) r.push(n);
|
301
|
-
return r.reverse(), function next() {
|
302
|
-
for (; r.length;) {
|
303
|
-
var t = r.pop();
|
304
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
305
|
-
}
|
306
|
-
return next.done = !0, next;
|
307
|
-
};
|
308
|
-
}, e.values = values, Context.prototype = {
|
309
|
-
constructor: Context,
|
310
|
-
reset: function (e) {
|
311
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
312
|
-
},
|
313
|
-
stop: function () {
|
314
|
-
this.done = !0;
|
315
|
-
var t = this.tryEntries[0].completion;
|
316
|
-
if ("throw" === t.type) throw t.arg;
|
317
|
-
return this.rval;
|
318
|
-
},
|
319
|
-
dispatchException: function (e) {
|
320
|
-
if (this.done) throw e;
|
321
|
-
var r = this;
|
322
|
-
function handle(n, o) {
|
323
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
324
|
-
}
|
325
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
326
|
-
var i = this.tryEntries[o],
|
327
|
-
a = i.completion;
|
328
|
-
if ("root" === i.tryLoc) return handle("end");
|
329
|
-
if (i.tryLoc <= this.prev) {
|
330
|
-
var c = n.call(i, "catchLoc"),
|
331
|
-
u = n.call(i, "finallyLoc");
|
332
|
-
if (c && u) {
|
333
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
334
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
335
|
-
} else if (c) {
|
336
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
337
|
-
} else {
|
338
|
-
if (!u) throw new Error("try statement without catch or finally");
|
339
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
340
|
-
}
|
341
|
-
}
|
342
|
-
}
|
343
|
-
},
|
344
|
-
abrupt: function (t, e) {
|
345
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
346
|
-
var o = this.tryEntries[r];
|
347
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
348
|
-
var i = o;
|
349
|
-
break;
|
350
|
-
}
|
351
|
-
}
|
352
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
353
|
-
var a = i ? i.completion : {};
|
354
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
355
|
-
},
|
356
|
-
complete: function (t, e) {
|
357
|
-
if ("throw" === t.type) throw t.arg;
|
358
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
359
|
-
},
|
360
|
-
finish: function (t) {
|
361
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
362
|
-
var r = this.tryEntries[e];
|
363
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
364
|
-
}
|
365
|
-
},
|
366
|
-
catch: function (t) {
|
367
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
368
|
-
var r = this.tryEntries[e];
|
369
|
-
if (r.tryLoc === t) {
|
370
|
-
var n = r.completion;
|
371
|
-
if ("throw" === n.type) {
|
372
|
-
var o = n.arg;
|
373
|
-
resetTryEntry(r);
|
374
|
-
}
|
375
|
-
return o;
|
376
|
-
}
|
377
|
-
}
|
378
|
-
throw new Error("illegal catch attempt");
|
379
|
-
},
|
380
|
-
delegateYield: function (e, r, n) {
|
381
|
-
return this.delegate = {
|
382
|
-
iterator: values(e),
|
383
|
-
resultName: r,
|
384
|
-
nextLoc: n
|
385
|
-
}, "next" === this.method && (this.arg = t), y;
|
386
|
-
}
|
387
|
-
}, e;
|
388
|
-
}
|
389
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
390
|
-
try {
|
391
|
-
var info = gen[key](arg);
|
392
|
-
var value = info.value;
|
393
|
-
} catch (error) {
|
394
|
-
reject(error);
|
395
|
-
return;
|
396
|
-
}
|
397
|
-
if (info.done) {
|
398
|
-
resolve(value);
|
399
|
-
} else {
|
400
|
-
Promise.resolve(value).then(_next, _throw);
|
401
|
-
}
|
402
|
-
}
|
403
|
-
function _asyncToGenerator(fn) {
|
404
|
-
return function () {
|
405
|
-
var self = this,
|
406
|
-
args = arguments;
|
407
|
-
return new Promise(function (resolve, reject) {
|
408
|
-
var gen = fn.apply(self, args);
|
409
|
-
function _next(value) {
|
410
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
411
|
-
}
|
412
|
-
function _throw(err) {
|
413
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
414
|
-
}
|
415
|
-
_next(undefined);
|
416
|
-
});
|
417
|
-
};
|
418
|
-
}
|
419
|
-
function _defineProperty(obj, key, value) {
|
420
|
-
key = _toPropertyKey(key);
|
421
|
-
if (key in obj) {
|
422
|
-
Object.defineProperty(obj, key, {
|
423
|
-
value: value,
|
424
|
-
enumerable: true,
|
425
|
-
configurable: true,
|
426
|
-
writable: true
|
427
|
-
});
|
428
|
-
} else {
|
429
|
-
obj[key] = value;
|
430
|
-
}
|
431
|
-
return obj;
|
432
|
-
}
|
433
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
434
|
-
if (source == null) return {};
|
435
|
-
var target = {};
|
436
|
-
var sourceKeys = Object.keys(source);
|
437
|
-
var key, i;
|
438
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
439
|
-
key = sourceKeys[i];
|
440
|
-
if (excluded.indexOf(key) >= 0) continue;
|
441
|
-
target[key] = source[key];
|
442
|
-
}
|
443
|
-
return target;
|
444
|
-
}
|
445
|
-
function _objectWithoutProperties(source, excluded) {
|
446
|
-
if (source == null) return {};
|
447
|
-
var target = _objectWithoutPropertiesLoose(source, excluded);
|
448
|
-
var key, i;
|
449
|
-
if (Object.getOwnPropertySymbols) {
|
450
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
451
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
452
|
-
key = sourceSymbolKeys[i];
|
453
|
-
if (excluded.indexOf(key) >= 0) continue;
|
454
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
455
|
-
target[key] = source[key];
|
456
|
-
}
|
457
|
-
}
|
458
|
-
return target;
|
459
|
-
}
|
460
|
-
function _slicedToArray(arr, i) {
|
461
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
462
|
-
}
|
463
|
-
function _toConsumableArray(arr) {
|
464
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
465
|
-
}
|
466
|
-
function _arrayWithoutHoles(arr) {
|
467
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
468
|
-
}
|
469
|
-
function _arrayWithHoles(arr) {
|
470
|
-
if (Array.isArray(arr)) return arr;
|
471
|
-
}
|
472
|
-
function _iterableToArray(iter) {
|
473
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
474
|
-
}
|
475
|
-
function _unsupportedIterableToArray(o, minLen) {
|
476
|
-
if (!o) return;
|
477
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
478
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
479
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
480
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
481
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
482
|
-
}
|
483
|
-
function _arrayLikeToArray(arr, len) {
|
484
|
-
if (len == null || len > arr.length) len = arr.length;
|
485
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
486
|
-
return arr2;
|
487
|
-
}
|
488
|
-
function _nonIterableSpread() {
|
489
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
490
|
-
}
|
491
|
-
function _nonIterableRest() {
|
492
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
493
|
-
}
|
494
|
-
function _toPrimitive(input, hint) {
|
495
|
-
if (typeof input !== "object" || input === null) return input;
|
496
|
-
var prim = input[Symbol.toPrimitive];
|
497
|
-
if (prim !== undefined) {
|
498
|
-
var res = prim.call(input, hint || "default");
|
499
|
-
if (typeof res !== "object") return res;
|
500
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
501
|
-
}
|
502
|
-
return (hint === "string" ? String : Number)(input);
|
503
|
-
}
|
504
|
-
function _toPropertyKey(arg) {
|
505
|
-
var key = _toPrimitive(arg, "string");
|
506
|
-
return typeof key === "symbol" ? key : String(key);
|
507
|
-
}
|
508
|
-
|
509
40
|
/* eslint-disable valid-jsdoc */
|
510
41
|
// @ts-check
|
511
42
|
|
512
|
-
|
43
|
+
const TRANSPARENT_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
513
44
|
|
514
45
|
/**
|
515
46
|
* Replace all text with emoji with an image html tag
|
@@ -517,11 +48,11 @@ var TRANSPARENT_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAA
|
|
517
48
|
* @return {string}
|
518
49
|
*/
|
519
50
|
function replaceAllTextEmojis(text) {
|
520
|
-
|
51
|
+
let allEmojis = getAllEmojisFromText(text);
|
521
52
|
if (allEmojis) {
|
522
|
-
allEmojis =
|
53
|
+
allEmojis = [...new Set(allEmojis)]; // remove duplicates
|
523
54
|
|
524
|
-
allEmojis.forEach(
|
55
|
+
allEmojis.forEach(emoji => {
|
525
56
|
text = replaceAll(text, emoji, getInputEmojiHTML('', emoji));
|
526
57
|
});
|
527
58
|
}
|
@@ -557,18 +88,18 @@ function getAllEmojisFromText(text) {
|
|
557
88
|
function getImageEmoji(emoji) {
|
558
89
|
var _emojiPickerEl$shadow;
|
559
90
|
/** @type {HTMLElement | null} */
|
560
|
-
|
91
|
+
const emojiPickerEl = document.querySelector('em-emoji-picker');
|
561
92
|
if (!emojiPickerEl) {
|
562
|
-
return getInputEmojiNativeHTML(emoji
|
93
|
+
return getInputEmojiNativeHTML(emoji.native);
|
563
94
|
}
|
564
95
|
|
565
96
|
/** @type {HTMLSpanElement | null=} */
|
566
|
-
|
97
|
+
const emojiSpanEl = emojiPickerEl === null || emojiPickerEl === void 0 || (_emojiPickerEl$shadow = emojiPickerEl.shadowRoot) === null || _emojiPickerEl$shadow === void 0 ? void 0 : _emojiPickerEl$shadow.querySelector("[title=\"".concat(emoji.name, "\"] > span > span"));
|
567
98
|
if (!emojiSpanEl) {
|
568
|
-
return getInputEmojiNativeHTML(emoji
|
99
|
+
return getInputEmojiNativeHTML(emoji.native);
|
569
100
|
}
|
570
|
-
|
571
|
-
return getInputEmojiHTML(style, emoji
|
101
|
+
const style = replaceAll(emojiSpanEl.style.cssText, '"', "'");
|
102
|
+
return getInputEmojiHTML(style, emoji.native);
|
572
103
|
}
|
573
104
|
|
574
105
|
// eslint-disable-next-line valid-jsdoc
|
@@ -597,10 +128,10 @@ function getInputEmojiNativeHTML(emoji) {
|
|
597
128
|
* @return {string}
|
598
129
|
*/
|
599
130
|
function replaceAllTextEmojiToString(html) {
|
600
|
-
|
131
|
+
const container = document.createElement("div");
|
601
132
|
container.innerHTML = html;
|
602
|
-
|
603
|
-
images.forEach(
|
133
|
+
const images = Array.prototype.slice.call(container.querySelectorAll("img"));
|
134
|
+
images.forEach(image => {
|
604
135
|
container.innerHTML = container.innerHTML.replace(image.outerHTML, image.dataset.emoji);
|
605
136
|
});
|
606
137
|
return container.innerHTML;
|
@@ -613,12 +144,12 @@ function replaceAllTextEmojiToString(html) {
|
|
613
144
|
* @param {React.ClipboardEvent} event
|
614
145
|
*/
|
615
146
|
function handleCopy(event) {
|
616
|
-
|
147
|
+
const selectedText = window.getSelection();
|
617
148
|
if (selectedText === null) {
|
618
149
|
return;
|
619
150
|
}
|
620
|
-
|
621
|
-
for (
|
151
|
+
let container = document.createElement("div");
|
152
|
+
for (let i = 0, len = selectedText.rangeCount; i < len; ++i) {
|
622
153
|
container.appendChild(selectedText.getRangeAt(i).cloneContents());
|
623
154
|
}
|
624
155
|
container = replaceEmojiToString(container);
|
@@ -626,28 +157,42 @@ function handleCopy(event) {
|
|
626
157
|
event.preventDefault();
|
627
158
|
}
|
628
159
|
|
160
|
+
/** @type {Range|undefined} */
|
161
|
+
/** @type {Range|undefined} */
|
162
|
+
let currentRangeCached;
|
163
|
+
|
629
164
|
/**
|
630
|
-
*
|
631
|
-
|
165
|
+
* Caches the current text selection range
|
166
|
+
*/
|
167
|
+
function cacheCurrentRange() {
|
168
|
+
const selection = window.getSelection();
|
169
|
+
if (!selection.rangeCount || (selection === null || selection === void 0 ? void 0 : selection.anchorNode['className']) !== 'react-input-emoji--input' && selection.anchorNode.parentNode['className'] !== 'react-input-emoji--input') return;
|
170
|
+
const range = selection.getRangeAt(0);
|
171
|
+
currentRangeCached = range.cloneRange();
|
172
|
+
}
|
173
|
+
|
174
|
+
/**
|
175
|
+
* @param {string} html - HTML string to be pasted at the caret position
|
632
176
|
*/
|
633
177
|
function handlePasteHtmlAtCaret(html) {
|
634
|
-
|
635
|
-
|
178
|
+
let sel;
|
179
|
+
let range;
|
636
180
|
if (window.getSelection) {
|
637
181
|
// IE9 and non-IE
|
638
182
|
sel = window.getSelection();
|
639
183
|
if (sel === null) return;
|
640
184
|
if (sel.getRangeAt && sel.rangeCount) {
|
641
|
-
|
185
|
+
var _currentRangeCached;
|
186
|
+
range = (_currentRangeCached = currentRangeCached) !== null && _currentRangeCached !== void 0 ? _currentRangeCached : sel.getRangeAt(0);
|
642
187
|
range.deleteContents();
|
643
188
|
|
644
189
|
// Range.createContextualFragment() would be useful here but is
|
645
190
|
// non-standard and not supported in all browsers (IE9, for one)
|
646
|
-
|
191
|
+
const el = document.createElement("div");
|
647
192
|
el.innerHTML = html;
|
648
|
-
|
649
|
-
|
650
|
-
|
193
|
+
const frag = document.createDocumentFragment();
|
194
|
+
let node;
|
195
|
+
let lastNode;
|
651
196
|
while (node = el.firstChild) {
|
652
197
|
lastNode = frag.appendChild(node);
|
653
198
|
}
|
@@ -656,6 +201,7 @@ function handlePasteHtmlAtCaret(html) {
|
|
656
201
|
// Preserve the selection
|
657
202
|
if (lastNode) {
|
658
203
|
range = range.cloneRange();
|
204
|
+
currentRangeCached = range;
|
659
205
|
range.setStartAfter(lastNode);
|
660
206
|
range.collapse(true);
|
661
207
|
sel.removeAllRanges();
|
@@ -671,8 +217,8 @@ function handlePasteHtmlAtCaret(html) {
|
|
671
217
|
* @return {HTMLDivElement}
|
672
218
|
*/
|
673
219
|
function replaceEmojiToString(container) {
|
674
|
-
|
675
|
-
images.forEach(
|
220
|
+
const images = Array.prototype.slice.call(container.querySelectorAll("img"));
|
221
|
+
images.forEach(image => {
|
676
222
|
image.outerHTML = image.dataset.emoji;
|
677
223
|
});
|
678
224
|
return container;
|
@@ -684,10 +230,12 @@ function replaceEmojiToString(container) {
|
|
684
230
|
* @return {number}
|
685
231
|
*/
|
686
232
|
function totalCharacters(_ref2) {
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
233
|
+
let {
|
234
|
+
text,
|
235
|
+
html
|
236
|
+
} = _ref2;
|
237
|
+
const textCount = text.length;
|
238
|
+
const emojisCount = (html.match(/<img/g) || []).length;
|
691
239
|
return textCount + emojisCount;
|
692
240
|
}
|
693
241
|
/**
|
@@ -696,12 +244,12 @@ function totalCharacters(_ref2) {
|
|
696
244
|
* @return {string}
|
697
245
|
*/
|
698
246
|
function removeHtmlExceptBr(inputDiv) {
|
699
|
-
|
700
|
-
|
247
|
+
const temp = inputDiv.innerHTML.replaceAll(/<br\s*\/?>/gi, "[BR]"); // temporarily replace <br> with placeholder
|
248
|
+
const tempContainer = document.createElement("div");
|
701
249
|
tempContainer.innerHTML = temp;
|
702
|
-
|
703
|
-
|
704
|
-
return
|
250
|
+
const stripped = tempContainer.innerText; // strip all html tags
|
251
|
+
const final = stripped.replaceAll(/\[BR\]/gi, "</br>"); // replace placeholders with <br>
|
252
|
+
return final;
|
705
253
|
}
|
706
254
|
|
707
255
|
/**
|
@@ -710,8 +258,8 @@ function removeHtmlExceptBr(inputDiv) {
|
|
710
258
|
* @returns
|
711
259
|
*/
|
712
260
|
function getSelectionStart$1(range) {
|
713
|
-
|
714
|
-
|
261
|
+
let node = range.startContainer;
|
262
|
+
let offset = range.startOffset;
|
715
263
|
|
716
264
|
// Handle cases where the selection start node is not a text node
|
717
265
|
if (node.nodeType !== Node.TEXT_NODE) {
|
@@ -728,8 +276,8 @@ function getSelectionStart$1(range) {
|
|
728
276
|
offset = 0;
|
729
277
|
}
|
730
278
|
return {
|
731
|
-
node
|
732
|
-
offset
|
279
|
+
node,
|
280
|
+
offset
|
733
281
|
};
|
734
282
|
}
|
735
283
|
|
@@ -738,13 +286,13 @@ function getSelectionStart$1(range) {
|
|
738
286
|
* @return {Object} cursor
|
739
287
|
*/
|
740
288
|
function getCursor() {
|
741
|
-
|
742
|
-
|
743
|
-
|
289
|
+
const selection = window.getSelection();
|
290
|
+
const range = selection.getRangeAt(0);
|
291
|
+
const selectionStart = getSelectionStart$1(range);
|
744
292
|
return {
|
745
|
-
selection
|
746
|
-
range
|
747
|
-
selectionStart
|
293
|
+
selection,
|
294
|
+
range,
|
295
|
+
selectionStart
|
748
296
|
};
|
749
297
|
}
|
750
298
|
|
@@ -752,30 +300,31 @@ function getCursor() {
|
|
752
300
|
*
|
753
301
|
*/
|
754
302
|
function addLineBreak() {
|
755
|
-
|
756
|
-
selection
|
757
|
-
range
|
758
|
-
selectionStart
|
303
|
+
const {
|
304
|
+
selection,
|
305
|
+
range,
|
306
|
+
selectionStart
|
307
|
+
} = getCursor();
|
759
308
|
|
760
309
|
// If cursor is at the end of the text content, add one more line break
|
761
310
|
if (selection.isCollapsed && selectionStart.offset === selectionStart.node.textContent.length) {
|
762
|
-
|
311
|
+
const br = document.createElement("br");
|
763
312
|
range.insertNode(br);
|
764
313
|
range.setStartAfter(br);
|
765
314
|
range.setEndAfter(br);
|
766
315
|
selection.removeAllRanges();
|
767
316
|
selection.addRange(range);
|
768
|
-
|
317
|
+
const br2 = document.createElement("br");
|
769
318
|
range.insertNode(br2);
|
770
319
|
range.setStartAfter(br2);
|
771
320
|
range.setEndAfter(br2);
|
772
321
|
selection.removeAllRanges();
|
773
322
|
selection.addRange(range);
|
774
323
|
} else {
|
775
|
-
|
776
|
-
range.insertNode(
|
777
|
-
range.setStartAfter(
|
778
|
-
range.setEndAfter(
|
324
|
+
const br = document.createElement("br");
|
325
|
+
range.insertNode(br);
|
326
|
+
range.setStartAfter(br);
|
327
|
+
range.setEndAfter(br);
|
779
328
|
selection.removeAllRanges();
|
780
329
|
selection.addRange(range);
|
781
330
|
// Set cursor position right before the first letter after the line break
|
@@ -994,7 +543,7 @@ var reactEasyEmoji = function reactEasyEmoji(element, optionsOrFn) {
|
|
994
543
|
var emoji = reactEasyEmoji;
|
995
544
|
|
996
545
|
// @ts-check
|
997
|
-
|
546
|
+
const EMOJI_REGEX = new RegExp(/(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?)*/g);
|
998
547
|
|
999
548
|
/**
|
1000
549
|
* @typedef {import('../types/types').SanitizeFn} SanitizeFn
|
@@ -1007,17 +556,17 @@ var EMOJI_REGEX = new RegExp(/(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\
|
|
1007
556
|
*/
|
1008
557
|
function useSanitize(shouldReturn, shouldConvertEmojiToImage) {
|
1009
558
|
/** @type {React.MutableRefObject<SanitizeFn[]>} */
|
1010
|
-
|
1011
|
-
|
559
|
+
const sanitizeFnsRef = React.useRef([]);
|
560
|
+
const sanitizedTextRef = React.useRef("");
|
1012
561
|
|
1013
562
|
/** @type {(fn: SanitizeFn) => void} */
|
1014
|
-
|
563
|
+
const addSanitizeFn = React.useCallback(fn => {
|
1015
564
|
sanitizeFnsRef.current.push(fn);
|
1016
565
|
}, []);
|
1017
566
|
|
1018
567
|
/** @type {(html: string) => string} */
|
1019
|
-
|
1020
|
-
|
568
|
+
const sanitize = React.useCallback(html => {
|
569
|
+
let result = sanitizeFnsRef.current.reduce((acc, fn) => {
|
1021
570
|
return fn(acc);
|
1022
571
|
}, html);
|
1023
572
|
result = replaceAllHtmlToString(result, shouldReturn);
|
@@ -1028,9 +577,9 @@ function useSanitize(shouldReturn, shouldConvertEmojiToImage) {
|
|
1028
577
|
return result;
|
1029
578
|
}, [shouldReturn, shouldConvertEmojiToImage]);
|
1030
579
|
return {
|
1031
|
-
addSanitizeFn
|
1032
|
-
sanitize
|
1033
|
-
sanitizedTextRef
|
580
|
+
addSanitizeFn,
|
581
|
+
sanitize,
|
582
|
+
sanitizedTextRef
|
1034
583
|
};
|
1035
584
|
}
|
1036
585
|
|
@@ -1041,9 +590,9 @@ function useSanitize(shouldReturn, shouldConvertEmojiToImage) {
|
|
1041
590
|
* @return {string}
|
1042
591
|
*/
|
1043
592
|
function replaceAllHtmlToString(html, shouldReturn) {
|
1044
|
-
|
593
|
+
const container = document.createElement("div");
|
1045
594
|
container.innerHTML = html;
|
1046
|
-
|
595
|
+
let text;
|
1047
596
|
if (shouldReturn) {
|
1048
597
|
text = removeHtmlExceptBr(container);
|
1049
598
|
} else {
|
@@ -1093,34 +642,35 @@ function handleEmoji(text) {
|
|
1093
642
|
* @param {Props} props
|
1094
643
|
*/
|
1095
644
|
function useExpose(_ref) {
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
645
|
+
let {
|
646
|
+
ref,
|
647
|
+
textInputRef,
|
648
|
+
setValue,
|
649
|
+
emitChange,
|
650
|
+
shouldConvertEmojiToImage
|
651
|
+
} = _ref;
|
652
|
+
const {
|
653
|
+
sanitize,
|
654
|
+
sanitizedTextRef
|
655
|
+
} = useSanitize(false, shouldConvertEmojiToImage);
|
656
|
+
React.useImperativeHandle(ref, () => ({
|
657
|
+
get value() {
|
658
|
+
return sanitizedTextRef.current;
|
659
|
+
},
|
660
|
+
set value(value) {
|
661
|
+
setValue(value);
|
662
|
+
},
|
663
|
+
focus: () => {
|
664
|
+
if (textInputRef.current === null) return;
|
665
|
+
textInputRef.current.focus();
|
666
|
+
},
|
667
|
+
blur: () => {
|
668
|
+
if (textInputRef.current !== null) {
|
669
|
+
sanitize(textInputRef.current.html);
|
1121
670
|
}
|
1122
|
-
|
1123
|
-
|
671
|
+
emitChange();
|
672
|
+
}
|
673
|
+
}));
|
1124
674
|
}
|
1125
675
|
|
1126
676
|
// @ts-check
|
@@ -1134,19 +684,19 @@ function useExpose(_ref) {
|
|
1134
684
|
*/
|
1135
685
|
function useEmit(textInputRef, onResize, onChange) {
|
1136
686
|
/** @type {React.MutableRefObject<{width: number; height: number} | null>} */
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
687
|
+
const currentSizeRef = React.useRef(null);
|
688
|
+
const onChangeFn = React.useRef(onChange);
|
689
|
+
const checkAndEmitResize = React.useCallback(() => {
|
1140
690
|
if (textInputRef.current !== null) {
|
1141
|
-
|
1142
|
-
|
691
|
+
const currentSize = currentSizeRef.current;
|
692
|
+
const nextSize = textInputRef.current.size;
|
1143
693
|
if ((!currentSize || currentSize.width !== nextSize.width || currentSize.height !== nextSize.height) && typeof onResize === "function") {
|
1144
694
|
onResize(nextSize);
|
1145
695
|
}
|
1146
696
|
currentSizeRef.current = nextSize;
|
1147
697
|
}
|
1148
698
|
}, [onResize, textInputRef]);
|
1149
|
-
|
699
|
+
const emitChange = React.useCallback(sanitizedText => {
|
1150
700
|
if (typeof onChangeFn.current === "function") {
|
1151
701
|
onChangeFn.current(sanitizedText);
|
1152
702
|
}
|
@@ -1154,7 +704,7 @@ function useEmit(textInputRef, onResize, onChange) {
|
|
1154
704
|
checkAndEmitResize();
|
1155
705
|
}
|
1156
706
|
}, [checkAndEmitResize, onResize]);
|
1157
|
-
React.useEffect(
|
707
|
+
React.useEffect(() => {
|
1158
708
|
if (textInputRef.current) {
|
1159
709
|
checkAndEmitResize();
|
1160
710
|
}
|
@@ -1162,7 +712,84 @@ function useEmit(textInputRef, onResize, onChange) {
|
|
1162
712
|
return emitChange;
|
1163
713
|
}
|
1164
714
|
|
1165
|
-
|
715
|
+
function ownKeys(e, r) {
|
716
|
+
var t = Object.keys(e);
|
717
|
+
if (Object.getOwnPropertySymbols) {
|
718
|
+
var o = Object.getOwnPropertySymbols(e);
|
719
|
+
r && (o = o.filter(function (r) {
|
720
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
721
|
+
})), t.push.apply(t, o);
|
722
|
+
}
|
723
|
+
return t;
|
724
|
+
}
|
725
|
+
function _objectSpread2(e) {
|
726
|
+
for (var r = 1; r < arguments.length; r++) {
|
727
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
728
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
729
|
+
_defineProperty(e, r, t[r]);
|
730
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
731
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
732
|
+
});
|
733
|
+
}
|
734
|
+
return e;
|
735
|
+
}
|
736
|
+
function _defineProperty(obj, key, value) {
|
737
|
+
key = _toPropertyKey(key);
|
738
|
+
if (key in obj) {
|
739
|
+
Object.defineProperty(obj, key, {
|
740
|
+
value: value,
|
741
|
+
enumerable: true,
|
742
|
+
configurable: true,
|
743
|
+
writable: true
|
744
|
+
});
|
745
|
+
} else {
|
746
|
+
obj[key] = value;
|
747
|
+
}
|
748
|
+
return obj;
|
749
|
+
}
|
750
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
751
|
+
if (source == null) return {};
|
752
|
+
var target = {};
|
753
|
+
var sourceKeys = Object.keys(source);
|
754
|
+
var key, i;
|
755
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
756
|
+
key = sourceKeys[i];
|
757
|
+
if (excluded.indexOf(key) >= 0) continue;
|
758
|
+
target[key] = source[key];
|
759
|
+
}
|
760
|
+
return target;
|
761
|
+
}
|
762
|
+
function _objectWithoutProperties(source, excluded) {
|
763
|
+
if (source == null) return {};
|
764
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
765
|
+
var key, i;
|
766
|
+
if (Object.getOwnPropertySymbols) {
|
767
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
768
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
769
|
+
key = sourceSymbolKeys[i];
|
770
|
+
if (excluded.indexOf(key) >= 0) continue;
|
771
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
772
|
+
target[key] = source[key];
|
773
|
+
}
|
774
|
+
}
|
775
|
+
return target;
|
776
|
+
}
|
777
|
+
function _toPrimitive(input, hint) {
|
778
|
+
if (typeof input !== "object" || input === null) return input;
|
779
|
+
var prim = input[Symbol.toPrimitive];
|
780
|
+
if (prim !== undefined) {
|
781
|
+
var res = prim.call(input, hint || "default");
|
782
|
+
if (typeof res !== "object") return res;
|
783
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
784
|
+
}
|
785
|
+
return (hint === "string" ? String : Number)(input);
|
786
|
+
}
|
787
|
+
function _toPropertyKey(arg) {
|
788
|
+
var key = _toPrimitive(arg, "string");
|
789
|
+
return typeof key === "symbol" ? key : String(key);
|
790
|
+
}
|
791
|
+
|
792
|
+
const _excluded = ["placeholder", "style", "tabIndex", "className", "onChange"];
|
1166
793
|
|
1167
794
|
/**
|
1168
795
|
* @typedef {Object} Props
|
@@ -1196,78 +823,78 @@ var _excluded = ["placeholder", "style", "tabIndex", "className", "onChange"];
|
|
1196
823
|
|
1197
824
|
// eslint-disable-next-line valid-jsdoc
|
1198
825
|
/** @type {React.ForwardRefRenderFunction<Ref, Props>} */
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
826
|
+
const TextInput = (_ref, ref) => {
|
827
|
+
let {
|
828
|
+
placeholder,
|
829
|
+
style,
|
830
|
+
tabIndex,
|
831
|
+
className,
|
832
|
+
onChange
|
833
|
+
} = _ref,
|
1205
834
|
props = _objectWithoutProperties(_ref, _excluded);
|
1206
|
-
React.useImperativeHandle(ref,
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
835
|
+
React.useImperativeHandle(ref, () => ({
|
836
|
+
appendContent: html => {
|
837
|
+
if (textInputRef.current) {
|
838
|
+
textInputRef.current.focus();
|
839
|
+
}
|
840
|
+
handlePasteHtmlAtCaret(html);
|
841
|
+
if (textInputRef.current) {
|
842
|
+
textInputRef.current.focus();
|
843
|
+
}
|
844
|
+
if (textInputRef.current && placeholderRef.current && replaceAllTextEmojiToString(textInputRef.current.innerHTML) === "") {
|
845
|
+
placeholderRef.current.style.visibility = "visible";
|
846
|
+
} else if (placeholderRef.current) {
|
847
|
+
placeholderRef.current.style.visibility = "hidden";
|
848
|
+
}
|
849
|
+
if (textInputRef.current && typeof onChange === 'function') {
|
850
|
+
onChange(textInputRef.current.innerHTML);
|
851
|
+
}
|
852
|
+
},
|
853
|
+
set html(value) {
|
854
|
+
if (textInputRef.current) {
|
855
|
+
textInputRef.current.innerHTML = value;
|
856
|
+
}
|
857
|
+
if (placeholderRef.current) {
|
858
|
+
const text = replaceAllTextEmojiToString(value);
|
859
|
+
if (text === "") {
|
1217
860
|
placeholderRef.current.style.visibility = "visible";
|
1218
|
-
} else
|
861
|
+
} else {
|
1219
862
|
placeholderRef.current.style.visibility = "hidden";
|
1220
863
|
}
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
}
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
}
|
1237
|
-
if (typeof onChange === 'function' && textInputRef.current) {
|
1238
|
-
onChange(textInputRef.current.innerHTML);
|
1239
|
-
}
|
1240
|
-
},
|
1241
|
-
get html() {
|
1242
|
-
if (!textInputRef.current) return '';
|
1243
|
-
return textInputRef.current.innerHTML;
|
1244
|
-
},
|
1245
|
-
get text() {
|
1246
|
-
if (!textInputRef.current) return '';
|
1247
|
-
return textInputRef.current.innerText;
|
1248
|
-
},
|
1249
|
-
get size() {
|
1250
|
-
if (!textInputRef.current) {
|
1251
|
-
return {
|
1252
|
-
width: 0,
|
1253
|
-
height: 0
|
1254
|
-
};
|
1255
|
-
}
|
864
|
+
}
|
865
|
+
if (typeof onChange === 'function' && textInputRef.current) {
|
866
|
+
onChange(textInputRef.current.innerHTML);
|
867
|
+
}
|
868
|
+
},
|
869
|
+
get html() {
|
870
|
+
if (!textInputRef.current) return '';
|
871
|
+
return textInputRef.current.innerHTML;
|
872
|
+
},
|
873
|
+
get text() {
|
874
|
+
if (!textInputRef.current) return '';
|
875
|
+
return textInputRef.current.innerText;
|
876
|
+
},
|
877
|
+
get size() {
|
878
|
+
if (!textInputRef.current) {
|
1256
879
|
return {
|
1257
|
-
width:
|
1258
|
-
height:
|
880
|
+
width: 0,
|
881
|
+
height: 0
|
1259
882
|
};
|
1260
|
-
},
|
1261
|
-
focus: function focus() {
|
1262
|
-
if (!textInputRef.current) return;
|
1263
|
-
textInputRef.current.focus();
|
1264
883
|
}
|
1265
|
-
|
1266
|
-
|
884
|
+
return {
|
885
|
+
width: textInputRef.current.offsetWidth,
|
886
|
+
height: textInputRef.current.offsetHeight
|
887
|
+
};
|
888
|
+
},
|
889
|
+
focus() {
|
890
|
+
if (!textInputRef.current) return;
|
891
|
+
textInputRef.current.focus();
|
892
|
+
}
|
893
|
+
}));
|
1267
894
|
|
1268
895
|
/** @type {React.CSSProperties} */
|
1269
|
-
|
1270
|
-
|
896
|
+
const placeholderStyle = React.useMemo(() => {
|
897
|
+
const placeholderStyle = {};
|
1271
898
|
if (style.placeholderColor) {
|
1272
899
|
placeholderStyle.color = style.placeholderColor;
|
1273
900
|
}
|
@@ -1275,8 +902,8 @@ var TextInput = function TextInput(_ref, ref) {
|
|
1275
902
|
}, [style === null || style === void 0 ? void 0 : style.placeholderColor]);
|
1276
903
|
|
1277
904
|
/** @type {React.CSSProperties} */
|
1278
|
-
|
1279
|
-
|
905
|
+
const inputStyle = React.useMemo(() => {
|
906
|
+
const inputStyle = {};
|
1280
907
|
if (style.color) {
|
1281
908
|
inputStyle.color = style.color;
|
1282
909
|
}
|
@@ -1284,9 +911,9 @@ var TextInput = function TextInput(_ref, ref) {
|
|
1284
911
|
}, [style === null || style === void 0 ? void 0 : style.color]);
|
1285
912
|
|
1286
913
|
/** @type {React.MutableRefObject<HTMLDivElement | null>} */
|
1287
|
-
|
914
|
+
const placeholderRef = React.useRef(null);
|
1288
915
|
/** @type {React.MutableRefObject<HTMLDivElement | null>} */
|
1289
|
-
|
916
|
+
const textInputRef = React.useRef(null);
|
1290
917
|
|
1291
918
|
/**
|
1292
919
|
*
|
@@ -1325,9 +952,9 @@ var TextInput = function TextInput(_ref, ref) {
|
|
1325
952
|
*/
|
1326
953
|
function handleKeyUp(event) {
|
1327
954
|
props.onKeyUp(event);
|
1328
|
-
|
955
|
+
const input = textInputRef.current;
|
1329
956
|
if (placeholderRef.current && input) {
|
1330
|
-
|
957
|
+
const text = replaceAllTextEmojiToString(input.innerHTML);
|
1331
958
|
if (text === "") {
|
1332
959
|
placeholderRef.current.style.visibility = "visible";
|
1333
960
|
} else {
|
@@ -1362,7 +989,9 @@ var TextInput = function TextInput(_ref, ref) {
|
|
1362
989
|
style: inputStyle
|
1363
990
|
})));
|
1364
991
|
};
|
1365
|
-
|
992
|
+
const TextInputWithRef = /*#__PURE__*/React.forwardRef(TextInput);
|
993
|
+
|
994
|
+
// vendors
|
1366
995
|
|
1367
996
|
/**
|
1368
997
|
* @typedef {object} Props
|
@@ -1378,16 +1007,15 @@ var TextInputWithRef = /*#__PURE__*/React.forwardRef(TextInput);
|
|
1378
1007
|
* @return {JSX.Element}
|
1379
1008
|
*/
|
1380
1009
|
function EmojiPickerButton(_ref) {
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
React.useEffect(function () {
|
1010
|
+
let {
|
1011
|
+
showPicker,
|
1012
|
+
toggleShowPicker,
|
1013
|
+
buttonElement,
|
1014
|
+
buttonRef
|
1015
|
+
} = _ref;
|
1016
|
+
const localButtonRef = React.useRef(null);
|
1017
|
+
const [showCustomButtonContent, setShowCustomButtonContent] = React.useState(false);
|
1018
|
+
React.useEffect(() => {
|
1391
1019
|
var _buttonRef$current$ch, _buttonRef$current, _buttonElement$childN, _buttonElement$childN2;
|
1392
1020
|
if (((_buttonRef$current$ch = buttonRef === null || buttonRef === void 0 || (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 || (_buttonRef$current = _buttonRef$current.childNodes) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.length) !== null && _buttonRef$current$ch !== void 0 ? _buttonRef$current$ch : 0) > 2) {
|
1393
1021
|
localButtonRef.current.appendChild(buttonRef.current.childNodes[0]);
|
@@ -3852,8 +3480,9 @@ function $e5534fc185f7111e$export$2e2bcd8739ae039(props) {
|
|
3852
3480
|
});
|
3853
3481
|
}
|
3854
3482
|
|
3855
|
-
|
3856
|
-
|
3483
|
+
// vendors
|
3484
|
+
const EMOJI_MART_DATA_URL = "https://cdn.jsdelivr.net/npm/@emoji-mart/data";
|
3485
|
+
const cacheI18n = {};
|
3857
3486
|
|
3858
3487
|
/**
|
3859
3488
|
* @typedef {object} Props
|
@@ -3869,55 +3498,38 @@ var cacheI18n = {};
|
|
3869
3498
|
* @param {Props} props
|
3870
3499
|
*/
|
3871
3500
|
function EmojiPicker(props) {
|
3872
|
-
|
3873
|
-
|
3874
|
-
|
3875
|
-
|
3876
|
-
|
3501
|
+
const {
|
3502
|
+
theme,
|
3503
|
+
onSelectEmoji,
|
3504
|
+
disableRecent,
|
3505
|
+
customEmojis,
|
3506
|
+
language
|
3507
|
+
} = props;
|
3877
3508
|
|
3878
3509
|
/** @type {string[]} */
|
3879
|
-
|
3510
|
+
const categories = React.useMemo(() => {
|
3880
3511
|
/** @type {string[]} */
|
3881
|
-
|
3512
|
+
let categoryies = [];
|
3882
3513
|
if (!disableRecent) {
|
3883
3514
|
categoryies.push("frequent");
|
3884
3515
|
}
|
3885
|
-
categoryies = [
|
3516
|
+
categoryies = [...categoryies, "people", "nature", "foods", "activity", "places", "objects", "symbols", "flags"];
|
3886
3517
|
return categoryies;
|
3887
3518
|
}, [disableRecent]);
|
3888
|
-
|
3889
|
-
|
3890
|
-
i18n = _useState2[0],
|
3891
|
-
setI18n = _useState2[1];
|
3892
|
-
React.useEffect(function () {
|
3893
|
-
var _ref2;
|
3519
|
+
const [i18n, setI18n] = React.useState(undefined);
|
3520
|
+
React.useEffect(() => {
|
3894
3521
|
if (!language) {
|
3895
|
-
var _ref;
|
3896
3522
|
if (cacheI18n.en) {
|
3897
3523
|
setI18n(cacheI18n.en);
|
3898
3524
|
return;
|
3899
3525
|
}
|
3900
3526
|
|
3901
3527
|
// @ts-ignore
|
3902
|
-
fetch("".concat(EMOJI_MART_DATA_URL, "/i18n/en.json")).then(
|
3903
|
-
|
3904
|
-
|
3905
|
-
|
3906
|
-
|
3907
|
-
case 0:
|
3908
|
-
_context.next = 2;
|
3909
|
-
return data.json();
|
3910
|
-
case 2:
|
3911
|
-
translations = _context.sent;
|
3912
|
-
setI18n(translations);
|
3913
|
-
cacheI18n.en = translations;
|
3914
|
-
case 5:
|
3915
|
-
case "end":
|
3916
|
-
return _context.stop();
|
3917
|
-
}
|
3918
|
-
}, _callee);
|
3919
|
-
}))).apply(this, arguments);
|
3920
|
-
})["catch"](function (error) {
|
3528
|
+
fetch("".concat(EMOJI_MART_DATA_URL, "/i18n/en.json")).then(async data => {
|
3529
|
+
const translations = await data.json();
|
3530
|
+
setI18n(translations);
|
3531
|
+
cacheI18n.en = translations;
|
3532
|
+
}).catch(error => {
|
3921
3533
|
console.error("Failed to load translations:", error);
|
3922
3534
|
});
|
3923
3535
|
return;
|
@@ -3928,25 +3540,11 @@ function EmojiPicker(props) {
|
|
3928
3540
|
}
|
3929
3541
|
|
3930
3542
|
// @ts-ignore
|
3931
|
-
fetch("".concat(EMOJI_MART_DATA_URL, "/i18n/").concat(language, ".json")).then(
|
3932
|
-
|
3933
|
-
|
3934
|
-
|
3935
|
-
|
3936
|
-
case 0:
|
3937
|
-
_context2.next = 2;
|
3938
|
-
return data.json();
|
3939
|
-
case 2:
|
3940
|
-
translations = _context2.sent;
|
3941
|
-
setI18n(translations);
|
3942
|
-
cacheI18n[language] = translations;
|
3943
|
-
case 5:
|
3944
|
-
case "end":
|
3945
|
-
return _context2.stop();
|
3946
|
-
}
|
3947
|
-
}, _callee2);
|
3948
|
-
}))).apply(this, arguments);
|
3949
|
-
})["catch"](function (error) {
|
3543
|
+
fetch("".concat(EMOJI_MART_DATA_URL, "/i18n/").concat(language, ".json")).then(async data => {
|
3544
|
+
const translations = await data.json();
|
3545
|
+
setI18n(translations);
|
3546
|
+
cacheI18n[language] = translations;
|
3547
|
+
}).catch(error => {
|
3950
3548
|
console.error("Failed to load translations:", error);
|
3951
3549
|
});
|
3952
3550
|
}, [language]);
|
@@ -3983,20 +3581,20 @@ var EmojiPicker$1 = /*#__PURE__*/React.memo(EmojiPicker);
|
|
3983
3581
|
* @return {JSX.Element}
|
3984
3582
|
*/
|
3985
3583
|
function EmojiPickerContainer(_ref) {
|
3986
|
-
|
3987
|
-
|
3988
|
-
|
3989
|
-
|
3990
|
-
|
3991
|
-
|
3992
|
-
|
3584
|
+
let {
|
3585
|
+
showPicker,
|
3586
|
+
theme,
|
3587
|
+
handleSelectEmoji,
|
3588
|
+
disableRecent,
|
3589
|
+
customEmojis,
|
3590
|
+
position,
|
3591
|
+
language
|
3592
|
+
} = _ref;
|
3993
3593
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
3994
3594
|
className: "react-emoji-picker--container"
|
3995
3595
|
}, showPicker && /*#__PURE__*/React__default["default"].createElement("div", {
|
3996
3596
|
className: "react-emoji-picker--wrapper",
|
3997
|
-
onClick:
|
3998
|
-
return evt.stopPropagation();
|
3999
|
-
},
|
3597
|
+
onClick: evt => evt.stopPropagation(),
|
4000
3598
|
style: position === 'below' ? {
|
4001
3599
|
top: '40px'
|
4002
3600
|
} : {}
|
@@ -4011,7 +3609,8 @@ function EmojiPickerContainer(_ref) {
|
|
4011
3609
|
}))));
|
4012
3610
|
}
|
4013
3611
|
|
4014
|
-
|
3612
|
+
// @ts-check
|
3613
|
+
const EMOJI_PICKER_CONTAINER_HEIGHT = 435;
|
4015
3614
|
|
4016
3615
|
/**
|
4017
3616
|
* @typedef {import('../types/types').SanitizeFn} SanitizeFn
|
@@ -4037,38 +3636,36 @@ var EMOJI_PICKER_CONTAINER_HEIGHT = 435;
|
|
4037
3636
|
|
4038
3637
|
// eslint-disable-next-line valid-jsdoc
|
4039
3638
|
/** @type {React.FC<Props>} */
|
4040
|
-
|
4041
|
-
|
4042
|
-
|
4043
|
-
|
4044
|
-
|
4045
|
-
|
4046
|
-
|
4047
|
-
|
4048
|
-
|
4049
|
-
|
4050
|
-
|
4051
|
-
|
4052
|
-
|
4053
|
-
|
4054
|
-
setShowPicker = _useState2[1];
|
3639
|
+
const EmojiPickerWrapper = props => {
|
3640
|
+
const {
|
3641
|
+
theme,
|
3642
|
+
keepOpened,
|
3643
|
+
disableRecent,
|
3644
|
+
customEmojis,
|
3645
|
+
addSanitizeFn,
|
3646
|
+
addPolluteFn,
|
3647
|
+
appendContent,
|
3648
|
+
buttonElement,
|
3649
|
+
buttonRef,
|
3650
|
+
language
|
3651
|
+
} = props;
|
3652
|
+
const [showPicker, setShowPicker] = React.useState(false);
|
4055
3653
|
/** @type {[HTMLDivElement | undefined, React.Dispatch<React.SetStateAction<HTMLDivElement | undefined>>]} */
|
4056
|
-
|
4057
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
4058
|
-
customButton = _useState4[0],
|
4059
|
-
setCustomButton = _useState4[1];
|
3654
|
+
const [customButton, setCustomButton] = React.useState();
|
4060
3655
|
/** @type {['above' | 'below' | undefined, React.Dispatch<React.SetStateAction<'above' | 'below' | undefined>>]} */
|
4061
|
-
|
4062
|
-
|
4063
|
-
|
4064
|
-
|
4065
|
-
|
3656
|
+
const [emojiPickerPosition, setEmojiPickerPosition] = React.useState();
|
3657
|
+
React.useEffect(() => {
|
3658
|
+
if (showPicker) {
|
3659
|
+
cacheCurrentRange();
|
3660
|
+
}
|
3661
|
+
}, [showPicker]);
|
3662
|
+
React.useEffect(() => {
|
4066
3663
|
addSanitizeFn(replaceAllTextEmojiToString);
|
4067
3664
|
}, [addSanitizeFn]);
|
4068
|
-
React.useEffect(
|
3665
|
+
React.useEffect(() => {
|
4069
3666
|
addPolluteFn(replaceAllTextEmojis);
|
4070
3667
|
}, [addPolluteFn]);
|
4071
|
-
React.useEffect(
|
3668
|
+
React.useEffect(() => {
|
4072
3669
|
/**
|
4073
3670
|
*
|
4074
3671
|
* @param {MouseEvent} event
|
@@ -4076,14 +3673,14 @@ var EmojiPickerWrapper = function EmojiPickerWrapper(props) {
|
|
4076
3673
|
function checkClickOutside(event) {
|
4077
3674
|
/** @type {HTMLElement} */
|
4078
3675
|
// @ts-ignore
|
4079
|
-
|
3676
|
+
const element = event.target;
|
4080
3677
|
if (element.classList.contains("react-input-emoji--button") || element.classList.contains("react-input-emoji--button--icon")) {
|
4081
3678
|
return;
|
4082
3679
|
}
|
4083
3680
|
setShowPicker(false);
|
4084
3681
|
}
|
4085
3682
|
document.addEventListener("click", checkClickOutside);
|
4086
|
-
return
|
3683
|
+
return () => {
|
4087
3684
|
document.removeEventListener("click", checkClickOutside);
|
4088
3685
|
};
|
4089
3686
|
}, []);
|
@@ -4096,9 +3693,7 @@ var EmojiPickerWrapper = function EmojiPickerWrapper(props) {
|
|
4096
3693
|
event.stopPropagation();
|
4097
3694
|
event.preventDefault();
|
4098
3695
|
setEmojiPickerPosition(calcTopPosition(event));
|
4099
|
-
setShowPicker(
|
4100
|
-
return !currentShowPicker;
|
4101
|
-
});
|
3696
|
+
setShowPicker(currentShowPicker => !currentShowPicker);
|
4102
3697
|
}
|
4103
3698
|
|
4104
3699
|
/**
|
@@ -4107,9 +3702,9 @@ var EmojiPickerWrapper = function EmojiPickerWrapper(props) {
|
|
4107
3702
|
* @return {'above' | 'below'}
|
4108
3703
|
*/
|
4109
3704
|
function calcTopPosition(event) {
|
4110
|
-
|
4111
|
-
|
4112
|
-
|
3705
|
+
const btn = event.currentTarget;
|
3706
|
+
const btnRect = btn.getBoundingClientRect();
|
3707
|
+
const popoverHeight = EMOJI_PICKER_CONTAINER_HEIGHT;
|
4113
3708
|
|
4114
3709
|
// Decide to display above or below based on available space
|
4115
3710
|
if (btnRect.top >= popoverHeight) {
|
@@ -4129,12 +3724,10 @@ var EmojiPickerWrapper = function EmojiPickerWrapper(props) {
|
|
4129
3724
|
function handleSelectEmoji(emoji) {
|
4130
3725
|
appendContent(getImageEmoji(emoji));
|
4131
3726
|
if (!keepOpened) {
|
4132
|
-
setShowPicker(
|
4133
|
-
return !currentShowPicker;
|
4134
|
-
});
|
3727
|
+
setShowPicker(currentShowPicker => !currentShowPicker);
|
4135
3728
|
}
|
4136
3729
|
}
|
4137
|
-
React.useEffect(
|
3730
|
+
React.useEffect(() => {
|
4138
3731
|
var _buttonRef$current;
|
4139
3732
|
if (buttonRef !== null && buttonRef !== void 0 && (_buttonRef$current = buttonRef.current) !== null && _buttonRef$current !== void 0 && _buttonRef$current.style) {
|
4140
3733
|
buttonRef.current.style.position = "relative";
|
@@ -4178,16 +3771,16 @@ var EmojiPickerWrapper = function EmojiPickerWrapper(props) {
|
|
4178
3771
|
* @return {string | null}
|
4179
3772
|
*/
|
4180
3773
|
function getTextFromAtToCaret() {
|
4181
|
-
|
3774
|
+
const range = getRangeFromAtToCaret();
|
4182
3775
|
if (!range) return null;
|
4183
|
-
|
3776
|
+
const text = range.text.substring(range.begin, range.end);
|
4184
3777
|
return text || null;
|
4185
3778
|
}
|
4186
3779
|
|
4187
3780
|
// eslint-disable-next-line valid-jsdoc
|
4188
3781
|
/** */
|
4189
3782
|
function deleteTextFromAtToCaret() {
|
4190
|
-
|
3783
|
+
const range = getRangeFromAtToCaret();
|
4191
3784
|
if (!range) return;
|
4192
3785
|
|
4193
3786
|
// @ts-ignore
|
@@ -4199,22 +3792,24 @@ function deleteTextFromAtToCaret() {
|
|
4199
3792
|
* @return {{begin: number, end: number, text: string, element: Node} | null}
|
4200
3793
|
*/
|
4201
3794
|
function getRangeFromAtToCaret() {
|
4202
|
-
|
3795
|
+
const elementWithFocus = getElementWithFocus();
|
4203
3796
|
if (!elementWithFocus) {
|
4204
3797
|
return null;
|
4205
3798
|
}
|
4206
|
-
|
4207
|
-
|
4208
|
-
|
4209
|
-
|
3799
|
+
const {
|
3800
|
+
element,
|
3801
|
+
caretOffset
|
3802
|
+
} = elementWithFocus;
|
3803
|
+
const text = element.textContent;
|
3804
|
+
const lastAt = text.lastIndexOf("@");
|
4210
3805
|
if (lastAt === -1 || lastAt >= caretOffset || lastAt !== 0 && text[lastAt - 1] !== " ") {
|
4211
3806
|
return null;
|
4212
3807
|
}
|
4213
3808
|
return {
|
4214
3809
|
begin: lastAt,
|
4215
3810
|
end: caretOffset,
|
4216
|
-
text
|
4217
|
-
element
|
3811
|
+
text,
|
3812
|
+
element
|
4218
3813
|
};
|
4219
3814
|
}
|
4220
3815
|
|
@@ -4223,14 +3818,14 @@ function getRangeFromAtToCaret() {
|
|
4223
3818
|
* @return {{element: Node, caretOffset: number}}
|
4224
3819
|
*/
|
4225
3820
|
function getElementWithFocus() {
|
4226
|
-
|
3821
|
+
const element = getSelectionStart();
|
4227
3822
|
if (element === null) {
|
4228
3823
|
return null;
|
4229
3824
|
}
|
4230
|
-
|
3825
|
+
let caretOffset = 0;
|
4231
3826
|
if (typeof window.getSelection != "undefined") {
|
4232
|
-
|
4233
|
-
|
3827
|
+
const range = window.getSelection().getRangeAt(0);
|
3828
|
+
const preCaretRange = range.cloneRange();
|
4234
3829
|
preCaretRange.selectNodeContents(element);
|
4235
3830
|
preCaretRange.setEnd(range.endContainer, range.endOffset);
|
4236
3831
|
caretOffset = preCaretRange.toString().length;
|
@@ -4240,16 +3835,16 @@ function getElementWithFocus() {
|
|
4240
3835
|
// @ts-ignore
|
4241
3836
|
document.selection.type != "Control") {
|
4242
3837
|
// @ts-ignore
|
4243
|
-
|
3838
|
+
const textRange = document.selection.createRange();
|
4244
3839
|
// @ts-ignore
|
4245
|
-
|
3840
|
+
const preCaretTextRange = document.body.createTextRange();
|
4246
3841
|
preCaretTextRange.moveToElementText(element);
|
4247
3842
|
preCaretTextRange.setEndPoint("EndToEnd", textRange);
|
4248
3843
|
caretOffset = preCaretTextRange.text.length;
|
4249
3844
|
}
|
4250
3845
|
return {
|
4251
|
-
element
|
4252
|
-
caretOffset
|
3846
|
+
element,
|
3847
|
+
caretOffset
|
4253
3848
|
};
|
4254
3849
|
}
|
4255
3850
|
|
@@ -4258,10 +3853,12 @@ function getElementWithFocus() {
|
|
4258
3853
|
* @return {Node | null}
|
4259
3854
|
*/
|
4260
3855
|
function getSelectionStart() {
|
4261
|
-
|
3856
|
+
const node = document.getSelection().anchorNode;
|
4262
3857
|
return (node === null || node === void 0 ? void 0 : node.nodeType) == 3 ? node : null;
|
4263
3858
|
}
|
4264
3859
|
|
3860
|
+
// @ts-check
|
3861
|
+
|
4265
3862
|
/**
|
4266
3863
|
* @typedef {import('../types/types').MentionUser} MentionUser
|
4267
3864
|
*/
|
@@ -4273,95 +3870,53 @@ function getSelectionStart() {
|
|
4273
3870
|
* @returns {{mentionSearchText: string | null, mentionUsers: MentionUser[], onKeyUp: (event: React.KeyboardEvent) => void, onFocus: () => void, onSelectUser: () => void, loading: boolean}}
|
4274
3871
|
*/
|
4275
3872
|
function useMention(searchMention) {
|
4276
|
-
|
4277
|
-
var _useState = React.useState(false),
|
4278
|
-
_useState2 = _slicedToArray(_useState, 2),
|
4279
|
-
loading = _useState2[0],
|
4280
|
-
setLoading = _useState2[1];
|
3873
|
+
const [loading, setLoading] = React.useState(false);
|
4281
3874
|
|
4282
3875
|
/** @type {[MentionUser[], React.Dispatch<React.SetStateAction<MentionUser[]>>]} */
|
4283
|
-
|
4284
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
4285
|
-
mentionUsers = _useState4[0],
|
4286
|
-
setMentionUsers = _useState4[1];
|
3876
|
+
const [mentionUsers, setMentionUsers] = React.useState([]);
|
4287
3877
|
|
4288
3878
|
/** @type {[string | null, React.Dispatch<React.SetStateAction<string | null>>]} */
|
4289
|
-
|
4290
|
-
|
4291
|
-
mentionSearchText = _useState6[0],
|
4292
|
-
setMentionSearchText = _useState6[1];
|
4293
|
-
var onSelectUser = React.useCallback(function () {
|
3879
|
+
const [mentionSearchText, setMentionSearchText] = React.useState(null);
|
3880
|
+
const onSelectUser = React.useCallback(() => {
|
4294
3881
|
deleteTextFromAtToCaret();
|
4295
3882
|
setMentionUsers([]);
|
4296
3883
|
}, []);
|
4297
3884
|
|
4298
3885
|
/** */
|
4299
|
-
|
4300
|
-
|
4301
|
-
|
4302
|
-
|
4303
|
-
|
4304
|
-
|
4305
|
-
|
4306
|
-
|
4307
|
-
|
4308
|
-
|
4309
|
-
|
4310
|
-
|
4311
|
-
_context.next = 12;
|
4312
|
-
break;
|
4313
|
-
case 6:
|
4314
|
-
setLoading(true);
|
4315
|
-
_context.next = 9;
|
4316
|
-
return searchMention(metionText);
|
4317
|
-
case 9:
|
4318
|
-
users = _context.sent;
|
4319
|
-
setLoading(false);
|
4320
|
-
setMentionUsers(users);
|
4321
|
-
case 12:
|
4322
|
-
case "end":
|
4323
|
-
return _context.stop();
|
4324
|
-
}
|
4325
|
-
}, _callee);
|
4326
|
-
})), [searchMention]);
|
3886
|
+
const checkMentionText = React.useCallback(async () => {
|
3887
|
+
const metionText = getTextFromAtToCaret();
|
3888
|
+
setMentionSearchText(metionText);
|
3889
|
+
if (metionText === null) {
|
3890
|
+
setMentionUsers([]);
|
3891
|
+
} else {
|
3892
|
+
setLoading(true);
|
3893
|
+
const users = await searchMention(metionText);
|
3894
|
+
setLoading(false);
|
3895
|
+
setMentionUsers(users);
|
3896
|
+
}
|
3897
|
+
}, [searchMention]);
|
4327
3898
|
|
4328
3899
|
/** @type {(event: React.KeyboardEvent) => void} */
|
4329
|
-
|
4330
|
-
|
4331
|
-
|
4332
|
-
|
4333
|
-
|
4334
|
-
|
4335
|
-
|
4336
|
-
|
4337
|
-
|
4338
|
-
break;
|
4339
|
-
}
|
4340
|
-
return _context2.abrupt("return");
|
4341
|
-
case 2:
|
4342
|
-
if (event.key === "Backspace" && (_getElementWithFocus = getElementWithFocus()) !== null && _getElementWithFocus !== void 0 && _getElementWithFocus.element.parentElement.hasAttribute("data-mention-id")) {
|
4343
|
-
elementWithFocus = getElementWithFocus();
|
4344
|
-
elementWithFocus.element.parentElement.remove();
|
4345
|
-
} else if (!["ArrowUp", "ArrowDown", "Esc", "Escape"].includes(event.key)) {
|
4346
|
-
checkMentionText();
|
4347
|
-
}
|
4348
|
-
case 3:
|
4349
|
-
case "end":
|
4350
|
-
return _context2.stop();
|
4351
|
-
}
|
4352
|
-
}, _callee2);
|
4353
|
-
}))).apply(this, arguments);
|
3900
|
+
const onKeyUp = React.useCallback(async event => {
|
3901
|
+
var _getElementWithFocus;
|
3902
|
+
if (typeof searchMention !== "function") return;
|
3903
|
+
if (event.key === "Backspace" && (_getElementWithFocus = getElementWithFocus()) !== null && _getElementWithFocus !== void 0 && _getElementWithFocus.element.parentElement.hasAttribute("data-mention-id")) {
|
3904
|
+
const elementWithFocus = getElementWithFocus();
|
3905
|
+
elementWithFocus.element.parentElement.remove();
|
3906
|
+
} else if (!["ArrowUp", "ArrowDown", "Esc", "Escape"].includes(event.key)) {
|
3907
|
+
checkMentionText();
|
3908
|
+
}
|
4354
3909
|
}, [checkMentionText, searchMention]);
|
4355
|
-
|
3910
|
+
const onFocus = React.useCallback(() => {
|
4356
3911
|
checkMentionText();
|
4357
3912
|
}, [checkMentionText]);
|
4358
3913
|
return {
|
4359
|
-
mentionSearchText
|
4360
|
-
mentionUsers
|
4361
|
-
onKeyUp
|
4362
|
-
onFocus
|
4363
|
-
onSelectUser
|
4364
|
-
loading
|
3914
|
+
mentionSearchText,
|
3915
|
+
mentionUsers,
|
3916
|
+
onKeyUp,
|
3917
|
+
onFocus,
|
3918
|
+
onSelectUser,
|
3919
|
+
loading
|
4365
3920
|
};
|
4366
3921
|
}
|
4367
3922
|
|
@@ -4387,36 +3942,33 @@ function useMention(searchMention) {
|
|
4387
3942
|
|
4388
3943
|
// eslint-disable-next-line valid-jsdoc
|
4389
3944
|
/** @type {React.ForwardRefRenderFunction<Ref, Props>} */
|
4390
|
-
|
4391
|
-
|
4392
|
-
|
4393
|
-
|
4394
|
-
|
4395
|
-
|
4396
|
-
|
4397
|
-
|
4398
|
-
|
4399
|
-
|
4400
|
-
|
4401
|
-
|
4402
|
-
|
4403
|
-
|
4404
|
-
|
4405
|
-
|
4406
|
-
|
4407
|
-
|
4408
|
-
|
4409
|
-
|
4410
|
-
|
4411
|
-
|
4412
|
-
|
4413
|
-
|
4414
|
-
|
4415
|
-
|
4416
|
-
|
4417
|
-
};
|
4418
|
-
});
|
4419
|
-
React.useEffect(function () {
|
3945
|
+
const MentionUserList = (_ref, ref) => {
|
3946
|
+
let {
|
3947
|
+
users,
|
3948
|
+
mentionSearchText,
|
3949
|
+
onSelect,
|
3950
|
+
addEventListener
|
3951
|
+
} = _ref;
|
3952
|
+
const [selectedUser, setSelectedUser] = React.useState(0);
|
3953
|
+
React.useImperativeHandle(ref, () => ({
|
3954
|
+
prevUser: () => {
|
3955
|
+
setSelectedUser(currentSelectedUser => {
|
3956
|
+
if (currentSelectedUser === 0) {
|
3957
|
+
return 0;
|
3958
|
+
}
|
3959
|
+
return currentSelectedUser - 1;
|
3960
|
+
});
|
3961
|
+
},
|
3962
|
+
nextUser: () => {
|
3963
|
+
setSelectedUser(currentSelectedUser => {
|
3964
|
+
if (currentSelectedUser === users.length - 1) {
|
3965
|
+
return users.length - 1;
|
3966
|
+
}
|
3967
|
+
return currentSelectedUser + 1;
|
3968
|
+
});
|
3969
|
+
}
|
3970
|
+
}));
|
3971
|
+
React.useEffect(() => {
|
4420
3972
|
setSelectedUser(0);
|
4421
3973
|
}, [users]);
|
4422
3974
|
|
@@ -4431,16 +3983,16 @@ var MentionUserList = function MentionUserList(_ref, ref) {
|
|
4431
3983
|
}
|
4432
3984
|
|
4433
3985
|
/** @type {(MentionUser & {nameHtml: string})[]} */
|
4434
|
-
|
4435
|
-
|
4436
|
-
return users.map(
|
4437
|
-
|
3986
|
+
const usersFiltered = React.useMemo(() => {
|
3987
|
+
const searchText = mentionSearchText ? mentionSearchText.substring(1).toLocaleLowerCase() : "";
|
3988
|
+
return users.map(user => {
|
3989
|
+
let nameHtml = user.name;
|
4438
3990
|
if (mentionSearchText && mentionSearchText.length > 1) {
|
4439
3991
|
if (user.name.toLowerCase().startsWith(searchText)) {
|
4440
3992
|
nameHtml = getMentionSelectedNameEl(user.name.substring(0, searchText.length), user.name.substring(searchText.length));
|
4441
3993
|
} else {
|
4442
|
-
|
4443
|
-
nameHtml = names.map(
|
3994
|
+
const names = user.name.split(" ");
|
3995
|
+
nameHtml = names.map(name => {
|
4444
3996
|
if (name.toLocaleLowerCase().startsWith(searchText)) {
|
4445
3997
|
return getMentionSelectedNameEl(name.substring(0, searchText.length), name.substring(searchText.length));
|
4446
3998
|
}
|
@@ -4449,7 +4001,7 @@ var MentionUserList = function MentionUserList(_ref, ref) {
|
|
4449
4001
|
}
|
4450
4002
|
}
|
4451
4003
|
return _objectSpread2(_objectSpread2({}, user), {}, {
|
4452
|
-
nameHtml
|
4004
|
+
nameHtml
|
4453
4005
|
});
|
4454
4006
|
});
|
4455
4007
|
}, [mentionSearchText, users]);
|
@@ -4461,47 +4013,45 @@ var MentionUserList = function MentionUserList(_ref, ref) {
|
|
4461
4013
|
* @returns {(event: React.MouseEvent) => void} event
|
4462
4014
|
*/
|
4463
4015
|
function handleClick(user) {
|
4464
|
-
return
|
4016
|
+
return event => {
|
4465
4017
|
event.stopPropagation();
|
4466
4018
|
event.preventDefault();
|
4467
4019
|
onSelect(user);
|
4468
4020
|
};
|
4469
4021
|
}
|
4470
|
-
React.useEffect(
|
4471
|
-
|
4022
|
+
React.useEffect(() => {
|
4023
|
+
const unsubscribe = addEventListener("enter", event => {
|
4472
4024
|
event.stopPropagation();
|
4473
4025
|
event.preventDefault();
|
4474
4026
|
onSelect(usersFiltered[selectedUser]);
|
4475
4027
|
});
|
4476
|
-
return
|
4028
|
+
return () => {
|
4477
4029
|
unsubscribe();
|
4478
4030
|
};
|
4479
4031
|
}, [addEventListener, onSelect, selectedUser, usersFiltered]);
|
4480
4032
|
return /*#__PURE__*/React__default["default"].createElement("ul", {
|
4481
4033
|
className: "react-input-emoji--mention--list",
|
4482
4034
|
"data-testid": "mention-user-list"
|
4483
|
-
}, usersFiltered.map(
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
|
4488
|
-
|
4489
|
-
|
4490
|
-
|
4491
|
-
|
4492
|
-
|
4493
|
-
|
4494
|
-
|
4495
|
-
|
4496
|
-
|
4497
|
-
|
4498
|
-
|
4499
|
-
__html: user.nameHtml
|
4500
|
-
}
|
4501
|
-
})));
|
4502
|
-
}));
|
4035
|
+
}, usersFiltered.map((user, index) => /*#__PURE__*/React__default["default"].createElement("li", {
|
4036
|
+
key: user.id
|
4037
|
+
}, /*#__PURE__*/React__default["default"].createElement("button", {
|
4038
|
+
type: "button",
|
4039
|
+
onClick: handleClick(user),
|
4040
|
+
className: "react-input-emoji--mention--item".concat(selectedUser === index ? " react-input-emoji--mention--item__selected" : ""),
|
4041
|
+
onMouseOver: () => setSelectedUser(index)
|
4042
|
+
}, /*#__PURE__*/React__default["default"].createElement("img", {
|
4043
|
+
className: "react-input-emoji--mention--item--img",
|
4044
|
+
src: user.image
|
4045
|
+
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
4046
|
+
className: "react-input-emoji--mention--item--name",
|
4047
|
+
dangerouslySetInnerHTML: {
|
4048
|
+
__html: user.nameHtml
|
4049
|
+
}
|
4050
|
+
})))));
|
4503
4051
|
};
|
4504
|
-
|
4052
|
+
const MentionUserListWithRef = /*#__PURE__*/React.forwardRef(MentionUserList);
|
4053
|
+
|
4054
|
+
// @ts-check
|
4505
4055
|
|
4506
4056
|
/**
|
4507
4057
|
* @typedef {import('../types/types').MentionUser} MetionUser
|
@@ -4525,55 +4075,55 @@ var MentionUserListWithRef = /*#__PURE__*/React.forwardRef(MentionUserList);
|
|
4525
4075
|
|
4526
4076
|
// eslint-disable-next-line valid-jsdoc
|
4527
4077
|
/** @type {React.FC<Props>} */
|
4528
|
-
|
4529
|
-
|
4530
|
-
|
4531
|
-
|
4532
|
-
|
4078
|
+
const MentionWrapper = _ref => {
|
4079
|
+
let {
|
4080
|
+
searchMention,
|
4081
|
+
addEventListener,
|
4082
|
+
appendContent,
|
4083
|
+
addSanitizeFn
|
4084
|
+
} = _ref;
|
4533
4085
|
/** @type {React.MutableRefObject<import('./mention-user-list').Ref | null>} */
|
4534
|
-
|
4535
|
-
|
4536
|
-
|
4537
|
-
|
4538
|
-
|
4539
|
-
|
4540
|
-
|
4541
|
-
|
4542
|
-
|
4543
|
-
|
4544
|
-
|
4545
|
-
|
4546
|
-
|
4547
|
-
addSanitizeFn(function (html) {
|
4548
|
-
var container = document.createElement("div");
|
4086
|
+
const metionUserListRef = React.useRef(null);
|
4087
|
+
const [showUserList, setShowUserList] = React.useState(false);
|
4088
|
+
const {
|
4089
|
+
mentionSearchText,
|
4090
|
+
mentionUsers,
|
4091
|
+
loading,
|
4092
|
+
onKeyUp,
|
4093
|
+
onFocus,
|
4094
|
+
onSelectUser
|
4095
|
+
} = useMention(searchMention);
|
4096
|
+
React.useEffect(() => {
|
4097
|
+
addSanitizeFn(html => {
|
4098
|
+
const container = document.createElement("div");
|
4549
4099
|
container.innerHTML = html;
|
4550
|
-
|
4551
|
-
mentionsEl.forEach(
|
4100
|
+
const mentionsEl = Array.prototype.slice.call(container.querySelectorAll(".react-input-emoji--mention--text"));
|
4101
|
+
mentionsEl.forEach(mentionEl => {
|
4552
4102
|
container.innerHTML = container.innerHTML.replace(mentionEl.outerHTML, "@[".concat(mentionEl.dataset.mentionName, "](userId:").concat(mentionEl.dataset.mentionId, ")"));
|
4553
4103
|
});
|
4554
4104
|
return container.innerHTML;
|
4555
4105
|
});
|
4556
4106
|
}, [addSanitizeFn]);
|
4557
|
-
React.useEffect(
|
4107
|
+
React.useEffect(() => {
|
4558
4108
|
setShowUserList(mentionUsers.length > 0);
|
4559
4109
|
}, [mentionUsers]);
|
4560
|
-
React.useEffect(
|
4110
|
+
React.useEffect(() => {
|
4561
4111
|
/** */
|
4562
4112
|
function checkClickOutside() {
|
4563
4113
|
setShowUserList(false);
|
4564
4114
|
}
|
4565
4115
|
document.addEventListener("click", checkClickOutside);
|
4566
|
-
return
|
4116
|
+
return () => {
|
4567
4117
|
document.removeEventListener("click", checkClickOutside);
|
4568
4118
|
};
|
4569
4119
|
}, []);
|
4570
|
-
React.useEffect(
|
4571
|
-
|
4572
|
-
return
|
4120
|
+
React.useEffect(() => {
|
4121
|
+
const unsubscribe = addEventListener("keyUp", onKeyUp);
|
4122
|
+
return () => {
|
4573
4123
|
unsubscribe();
|
4574
4124
|
};
|
4575
4125
|
}, [addEventListener, onKeyUp]);
|
4576
|
-
React.useEffect(
|
4126
|
+
React.useEffect(() => {
|
4577
4127
|
/**
|
4578
4128
|
*
|
4579
4129
|
* @param {React.KeyboardEvent} event
|
@@ -4586,30 +4136,30 @@ var MentionWrapper = function MentionWrapper(_ref) {
|
|
4586
4136
|
break;
|
4587
4137
|
}
|
4588
4138
|
}
|
4589
|
-
|
4590
|
-
return
|
4139
|
+
const unsubscribe = addEventListener("keyDown", handleKeyDown);
|
4140
|
+
return () => {
|
4591
4141
|
unsubscribe();
|
4592
4142
|
};
|
4593
4143
|
}, [addEventListener]);
|
4594
|
-
React.useEffect(
|
4595
|
-
|
4596
|
-
return
|
4144
|
+
React.useEffect(() => {
|
4145
|
+
const unsubscribe = addEventListener("focus", onFocus);
|
4146
|
+
return () => {
|
4597
4147
|
unsubscribe();
|
4598
4148
|
};
|
4599
4149
|
}, [addEventListener, onFocus]);
|
4600
|
-
React.useEffect(
|
4150
|
+
React.useEffect(() => {
|
4601
4151
|
if (showUserList) {
|
4602
|
-
|
4152
|
+
const unsubscribeArrowUp = addEventListener("arrowUp", event => {
|
4603
4153
|
event.stopPropagation();
|
4604
4154
|
event.preventDefault();
|
4605
4155
|
metionUserListRef.current.prevUser();
|
4606
4156
|
});
|
4607
|
-
|
4157
|
+
const unsubscribeArrowDown = addEventListener("arrowDown", event => {
|
4608
4158
|
event.stopPropagation();
|
4609
4159
|
event.preventDefault();
|
4610
4160
|
metionUserListRef.current.nextUser();
|
4611
4161
|
});
|
4612
|
-
return
|
4162
|
+
return () => {
|
4613
4163
|
unsubscribeArrowUp();
|
4614
4164
|
unsubscribeArrowDown();
|
4615
4165
|
};
|
@@ -4632,9 +4182,7 @@ var MentionWrapper = function MentionWrapper(_ref) {
|
|
4632
4182
|
className: "react-input-emoji--mention--loading--spinner"
|
4633
4183
|
}, "Loading..."))) : showUserList && /*#__PURE__*/React__default["default"].createElement("div", {
|
4634
4184
|
className: "react-input-emoji--mention--container",
|
4635
|
-
onClick:
|
4636
|
-
return evt.stopPropagation();
|
4637
|
-
}
|
4185
|
+
onClick: evt => evt.stopPropagation()
|
4638
4186
|
}, /*#__PURE__*/React__default["default"].createElement(MentionUserListWithRef, {
|
4639
4187
|
ref: metionUserListRef,
|
4640
4188
|
mentionSearchText: mentionSearchText,
|
@@ -4653,20 +4201,16 @@ var MentionWrapper = function MentionWrapper(_ref) {
|
|
4653
4201
|
*/
|
4654
4202
|
function createObserver() {
|
4655
4203
|
/** @type {import('../types/types').Listerner<T>[]} */
|
4656
|
-
|
4204
|
+
let listeners = [];
|
4657
4205
|
return {
|
4658
|
-
subscribe:
|
4206
|
+
subscribe: listener => {
|
4659
4207
|
listeners.push(listener);
|
4660
|
-
return
|
4661
|
-
listeners = listeners.filter(
|
4662
|
-
return l !== listener;
|
4663
|
-
});
|
4208
|
+
return () => {
|
4209
|
+
listeners = listeners.filter(l => l !== listener);
|
4664
4210
|
};
|
4665
4211
|
},
|
4666
|
-
publish:
|
4667
|
-
listeners.forEach(
|
4668
|
-
return listener(event);
|
4669
|
-
});
|
4212
|
+
publish: event => {
|
4213
|
+
listeners.forEach(listener => listener(event));
|
4670
4214
|
},
|
4671
4215
|
get currentListerners() {
|
4672
4216
|
return listeners;
|
@@ -4684,28 +4228,26 @@ function createObserver() {
|
|
4684
4228
|
/** */
|
4685
4229
|
function useEventListeners() {
|
4686
4230
|
/** @type {TextInputListeners} */
|
4687
|
-
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
|
4693
|
-
|
4694
|
-
|
4695
|
-
|
4696
|
-
};
|
4697
|
-
}, []);
|
4231
|
+
const listeners = React.useMemo(() => ({
|
4232
|
+
keyDown: createObserver(),
|
4233
|
+
keyUp: createObserver(),
|
4234
|
+
arrowUp: createObserver(),
|
4235
|
+
arrowDown: createObserver(),
|
4236
|
+
enter: createObserver(),
|
4237
|
+
focus: createObserver(),
|
4238
|
+
blur: createObserver()
|
4239
|
+
}), []);
|
4698
4240
|
|
4699
4241
|
/**
|
4700
4242
|
* @template {keyof TextInputListeners} T, K
|
4701
4243
|
* @type {(event: keyof TextInputListeners, fn: import('../types/types').Listerner<any>) => () => void}
|
4702
4244
|
*/
|
4703
|
-
|
4245
|
+
const addEventListener = React.useCallback((event, fn) => {
|
4704
4246
|
return listeners[event].subscribe(fn);
|
4705
4247
|
}, [listeners]);
|
4706
4248
|
return {
|
4707
|
-
addEventListener
|
4708
|
-
listeners
|
4249
|
+
addEventListener,
|
4250
|
+
listeners
|
4709
4251
|
};
|
4710
4252
|
}
|
4711
4253
|
|
@@ -4719,23 +4261,23 @@ function useEventListeners() {
|
|
4719
4261
|
/** */
|
4720
4262
|
function usePollute() {
|
4721
4263
|
/** @type {React.MutableRefObject<PolluteFn[]>} */
|
4722
|
-
|
4264
|
+
const polluteFnsRef = React.useRef([]);
|
4723
4265
|
|
4724
4266
|
/** @type {(fn: PolluteFn) => void} */
|
4725
|
-
|
4267
|
+
const addPolluteFn = React.useCallback(fn => {
|
4726
4268
|
polluteFnsRef.current.push(fn);
|
4727
4269
|
}, []);
|
4728
4270
|
|
4729
4271
|
/** @type {(html: string) => string} */
|
4730
|
-
|
4731
|
-
|
4272
|
+
const pollute = React.useCallback(text => {
|
4273
|
+
const result = polluteFnsRef.current.reduce((acc, fn) => {
|
4732
4274
|
return fn(acc);
|
4733
4275
|
}, text);
|
4734
4276
|
return result;
|
4735
4277
|
}, []);
|
4736
4278
|
return {
|
4737
|
-
addPolluteFn
|
4738
|
-
pollute
|
4279
|
+
addPolluteFn,
|
4280
|
+
pollute
|
4739
4281
|
};
|
4740
4282
|
}
|
4741
4283
|
|
@@ -4791,72 +4333,78 @@ function usePollute() {
|
|
4791
4333
|
* @return {JSX.Element}
|
4792
4334
|
*/
|
4793
4335
|
function InputEmoji(props, ref) {
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4797
|
-
|
4798
|
-
|
4799
|
-
|
4800
|
-
|
4801
|
-
|
4802
|
-
|
4803
|
-
|
4804
|
-
|
4805
|
-
|
4806
|
-
|
4807
|
-
|
4808
|
-
|
4809
|
-
|
4810
|
-
|
4811
|
-
|
4812
|
-
|
4813
|
-
|
4814
|
-
|
4815
|
-
|
4816
|
-
|
4817
|
-
|
4818
|
-
|
4819
|
-
|
4820
|
-
|
4821
|
-
|
4822
|
-
|
4823
|
-
|
4336
|
+
const {
|
4337
|
+
onChange,
|
4338
|
+
onEnter,
|
4339
|
+
onResize,
|
4340
|
+
onClick,
|
4341
|
+
onFocus,
|
4342
|
+
onBlur,
|
4343
|
+
onKeyDown,
|
4344
|
+
theme,
|
4345
|
+
cleanOnEnter,
|
4346
|
+
placeholder,
|
4347
|
+
maxLength,
|
4348
|
+
keepOpened,
|
4349
|
+
inputClass,
|
4350
|
+
disableRecent,
|
4351
|
+
tabIndex,
|
4352
|
+
value,
|
4353
|
+
customEmojis,
|
4354
|
+
language,
|
4355
|
+
searchMention,
|
4356
|
+
buttonElement,
|
4357
|
+
buttonRef,
|
4358
|
+
shouldReturn,
|
4359
|
+
shouldConvertEmojiToImage,
|
4360
|
+
// style
|
4361
|
+
borderRadius,
|
4362
|
+
borderColor,
|
4363
|
+
fontSize,
|
4364
|
+
fontFamily,
|
4365
|
+
background,
|
4366
|
+
placeholderColor,
|
4367
|
+
color
|
4368
|
+
} = props;
|
4824
4369
|
|
4825
4370
|
/** @type {React.MutableRefObject<import('./text-input').Ref | null>} */
|
4826
|
-
|
4827
|
-
|
4828
|
-
addEventListener
|
4829
|
-
listeners
|
4830
|
-
|
4831
|
-
|
4832
|
-
|
4833
|
-
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4838
|
-
|
4371
|
+
const textInputRef = React.useRef(null);
|
4372
|
+
const {
|
4373
|
+
addEventListener,
|
4374
|
+
listeners
|
4375
|
+
} = useEventListeners();
|
4376
|
+
const {
|
4377
|
+
addSanitizeFn,
|
4378
|
+
sanitize,
|
4379
|
+
sanitizedTextRef
|
4380
|
+
} = useSanitize(shouldReturn, shouldConvertEmojiToImage);
|
4381
|
+
const {
|
4382
|
+
addPolluteFn,
|
4383
|
+
pollute
|
4384
|
+
} = usePollute();
|
4385
|
+
const updateHTML = React.useCallback(function () {
|
4386
|
+
let nextValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
4839
4387
|
if (textInputRef.current === null) return;
|
4840
4388
|
textInputRef.current.html = replaceAllTextEmojis(nextValue);
|
4841
4389
|
sanitizedTextRef.current = nextValue;
|
4842
4390
|
}, [sanitizedTextRef]);
|
4843
|
-
|
4391
|
+
const setValue = React.useCallback(
|
4844
4392
|
/**
|
4845
4393
|
*
|
4846
4394
|
* @param {string} value
|
4847
4395
|
*/
|
4848
|
-
|
4396
|
+
value => {
|
4849
4397
|
updateHTML(value);
|
4850
4398
|
}, [updateHTML]);
|
4851
|
-
|
4399
|
+
const emitChange = useEmit(textInputRef, onResize, onChange);
|
4852
4400
|
useExpose({
|
4853
|
-
ref
|
4854
|
-
setValue
|
4855
|
-
textInputRef
|
4856
|
-
emitChange
|
4857
|
-
shouldConvertEmojiToImage
|
4401
|
+
ref,
|
4402
|
+
setValue,
|
4403
|
+
textInputRef,
|
4404
|
+
emitChange,
|
4405
|
+
shouldConvertEmojiToImage
|
4858
4406
|
});
|
4859
|
-
React.useEffect(
|
4407
|
+
React.useEffect(() => {
|
4860
4408
|
if (sanitizedTextRef.current !== value) {
|
4861
4409
|
setValue(value);
|
4862
4410
|
}
|
@@ -4866,7 +4414,7 @@ function InputEmoji(props, ref) {
|
|
4866
4414
|
// updateHTML();
|
4867
4415
|
// }, [updateHTML]);
|
4868
4416
|
|
4869
|
-
React.useEffect(
|
4417
|
+
React.useEffect(() => {
|
4870
4418
|
/**
|
4871
4419
|
* Handle keydown event
|
4872
4420
|
* @param {React.KeyboardEvent} event
|
@@ -4878,7 +4426,7 @@ function InputEmoji(props, ref) {
|
|
4878
4426
|
}
|
4879
4427
|
if (event.key === "Enter" && textInputRef.current) {
|
4880
4428
|
event.preventDefault();
|
4881
|
-
|
4429
|
+
const text = sanitize(textInputRef.current.html);
|
4882
4430
|
emitChange(sanitizedTextRef.current);
|
4883
4431
|
if (typeof onEnter === "function" && listeners.enter.currentListerners.length === 0) {
|
4884
4432
|
onEnter(text);
|
@@ -4896,12 +4444,12 @@ function InputEmoji(props, ref) {
|
|
4896
4444
|
}
|
4897
4445
|
return true;
|
4898
4446
|
}
|
4899
|
-
|
4900
|
-
return
|
4447
|
+
const unsubscribe = addEventListener("keyDown", handleKeydown);
|
4448
|
+
return () => {
|
4901
4449
|
unsubscribe();
|
4902
4450
|
};
|
4903
4451
|
}, [addEventListener, cleanOnEnter, emitChange, listeners.enter.currentListerners.length, maxLength, onEnter, onKeyDown, sanitize, sanitizedTextRef, updateHTML]);
|
4904
|
-
React.useEffect(
|
4452
|
+
React.useEffect(() => {
|
4905
4453
|
/** */
|
4906
4454
|
function handleFocus() {
|
4907
4455
|
if (typeof onClick === "function") {
|
@@ -4911,20 +4459,20 @@ function InputEmoji(props, ref) {
|
|
4911
4459
|
onFocus();
|
4912
4460
|
}
|
4913
4461
|
}
|
4914
|
-
|
4915
|
-
return
|
4462
|
+
const unsubscribe = addEventListener("focus", handleFocus);
|
4463
|
+
return () => {
|
4916
4464
|
unsubscribe();
|
4917
4465
|
};
|
4918
4466
|
}, [addEventListener, onClick, onFocus]);
|
4919
|
-
React.useEffect(
|
4467
|
+
React.useEffect(() => {
|
4920
4468
|
/** */
|
4921
4469
|
function handleBlur() {
|
4922
4470
|
if (typeof onBlur === "function") {
|
4923
4471
|
onBlur();
|
4924
4472
|
}
|
4925
4473
|
}
|
4926
|
-
|
4927
|
-
return
|
4474
|
+
const unsubscribe = addEventListener("blur", handleBlur);
|
4475
|
+
return () => {
|
4928
4476
|
unsubscribe();
|
4929
4477
|
};
|
4930
4478
|
}, [addEventListener, onBlur]);
|
@@ -4959,7 +4507,7 @@ function InputEmoji(props, ref) {
|
|
4959
4507
|
*/
|
4960
4508
|
function handlePaste(event) {
|
4961
4509
|
event.preventDefault();
|
4962
|
-
|
4510
|
+
let content;
|
4963
4511
|
if (event.clipboardData) {
|
4964
4512
|
content = event.clipboardData.getData("text/plain");
|
4965
4513
|
content = pollute(content);
|
@@ -4987,13 +4535,13 @@ function InputEmoji(props, ref) {
|
|
4987
4535
|
onEnter: listeners.enter.publish,
|
4988
4536
|
placeholder: placeholder,
|
4989
4537
|
style: {
|
4990
|
-
borderRadius
|
4991
|
-
borderColor
|
4992
|
-
fontSize
|
4993
|
-
fontFamily
|
4994
|
-
background
|
4995
|
-
placeholderColor
|
4996
|
-
color
|
4538
|
+
borderRadius,
|
4539
|
+
borderColor,
|
4540
|
+
fontSize,
|
4541
|
+
fontFamily,
|
4542
|
+
background,
|
4543
|
+
placeholderColor,
|
4544
|
+
color
|
4997
4545
|
},
|
4998
4546
|
tabIndex: tabIndex,
|
4999
4547
|
className: inputClass,
|
@@ -5011,7 +4559,7 @@ function InputEmoji(props, ref) {
|
|
5011
4559
|
language: language
|
5012
4560
|
}));
|
5013
4561
|
}
|
5014
|
-
|
4562
|
+
const InputEmojiWithRef = /*#__PURE__*/React.forwardRef(InputEmoji);
|
5015
4563
|
InputEmojiWithRef.defaultProps = {
|
5016
4564
|
theme: /** @type {const} */"auto",
|
5017
4565
|
height: 30,
|