react-input-emoji 4.1.0 → 4.3.0

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 CHANGED
@@ -1,4 +1,5 @@
1
- import React, { useRef, useCallback, useImperativeHandle, useEffect, forwardRef, memo, useMemo, useState } from 'react';
1
+ import React, { useRef, useCallback, useImperativeHandle, useEffect, forwardRef, useState, useMemo, memo } from 'react';
2
+ import ReactDOM from 'react-dom';
2
3
  import PropTypes from 'prop-types';
3
4
 
4
5
  function styleInject(css, ref) {
@@ -156,6 +157,7 @@ function handlePasteHtmlAtCaret(html) {
156
157
  if (window.getSelection) {
157
158
  // IE9 and non-IE
158
159
  sel = window.getSelection();
160
+ if (sel === null) return;
159
161
 
160
162
  if (sel.getRangeAt && sel.rangeCount) {
161
163
  range = sel.getRangeAt(0);
@@ -251,7 +253,7 @@ function replaceAllHtmlToString(html) {
251
253
  /**
252
254
  * @typedef {Object} Props
253
255
  * @property {React.Ref<any>} ref
254
- * @property {React.MutableRefObject<import('../text-input').Ref>} textInputRef
256
+ * @property {React.MutableRefObject<import('../text-input').Ref | null>} textInputRef
255
257
  * @property {(value: string) => void} setValue
256
258
  * @property {() => void} emitChange
257
259
  */
@@ -281,10 +283,14 @@ function useExpose({
281
283
  },
282
284
 
283
285
  focus: () => {
286
+ if (textInputRef.current === null) return;
284
287
  textInputRef.current.focus();
285
288
  },
286
289
  blur: () => {
287
- sanitize(textInputRef.current.html);
290
+ if (textInputRef.current !== null) {
291
+ sanitize(textInputRef.current.html);
292
+ }
293
+
288
294
  emitChange();
289
295
  }
290
296
  }));
@@ -294,16 +300,17 @@ function useExpose({
294
300
 
295
301
  /**
296
302
  * useEmit
297
- * @param {React.MutableRefObject<import('../text-input').Ref>} textInputRef
303
+ * @param {React.MutableRefObject<import('../text-input').Ref | null>} textInputRef
298
304
  * @param {(size: {width: number, height: number}) => void} onResize
299
305
  * @param {(text: string) => void} onChange
300
306
  */
301
307
 
302
308
  function useEmit(textInputRef, onResize, onChange) {
309
+ /** @type {React.MutableRefObject<{width: number; height: number} | null>} */
303
310
  const currentSizeRef = useRef(null);
304
311
  const onChangeFn = useRef(onChange);
305
312
  const checkAndEmitResize = useCallback(() => {
306
- if (textInputRef.current) {
313
+ if (textInputRef.current !== null) {
307
314
  const currentSize = currentSizeRef.current;
308
315
  const nextSize = textInputRef.current.size;
309
316
 
@@ -337,7 +344,7 @@ function useEmit(textInputRef, onResize, onChange) {
337
344
  * @property {(event: React.KeyboardEvent) => void} onKeyDown
338
345
  * @property {(event: React.KeyboardEvent) => void} onKeyUp
339
346
  * @property {() => void} onFocus
340
- * @property {() => void=} onBlur
347
+ * @property {() => void} onBlur
341
348
  * @property {(sanitizedText: string) => void=} onChange
342
349
  * @property {(event: React.KeyboardEvent) => void} onArrowUp
343
350
  * @property {(event: React.KeyboardEvent) => void} onArrowDown
@@ -374,40 +381,63 @@ const TextInput = ({
374
381
  }, ref) => {
375
382
  useImperativeHandle(ref, () => ({
376
383
  appendContent: html => {
377
- textInputRef.current.focus();
384
+ if (textInputRef.current) {
385
+ textInputRef.current.focus();
386
+ }
387
+
378
388
  handlePasteHtmlAtCaret(html);
379
- textInputRef.current.focus();
380
389
 
381
- if (textInputRef.current.innerHTML.trim() === "") {
390
+ if (textInputRef.current) {
391
+ textInputRef.current.focus();
392
+ }
393
+
394
+ if (textInputRef.current && placeholderRef.current && textInputRef.current.innerHTML.trim() === "") {
382
395
  placeholderRef.current.style.visibility = "visible";
383
- } else {
396
+ } else if (placeholderRef.current) {
384
397
  placeholderRef.current.style.visibility = "hidden";
385
398
  }
386
399
 
387
- onChange(textInputRef.current.innerHTML);
400
+ if (textInputRef.current && typeof onChange === 'function') {
401
+ onChange(textInputRef.current.innerHTML);
402
+ }
388
403
  },
389
404
 
390
405
  set html(value) {
391
- textInputRef.current.innerHTML = value;
406
+ if (textInputRef.current) {
407
+ textInputRef.current.innerHTML = value;
408
+ }
392
409
 
393
- if (value.trim() === "") {
394
- placeholderRef.current.style.visibility = "visible";
395
- } else {
396
- placeholderRef.current.style.visibility = "hidden";
410
+ if (placeholderRef.current) {
411
+ if (value.trim() === "") {
412
+ placeholderRef.current.style.visibility = "visible";
413
+ } else {
414
+ placeholderRef.current.style.visibility = "hidden";
415
+ }
397
416
  }
398
417
 
399
- onChange(textInputRef.current.innerHTML);
418
+ if (typeof onChange === 'function' && textInputRef.current) {
419
+ onChange(textInputRef.current.innerHTML);
420
+ }
400
421
  },
401
422
 
402
423
  get html() {
424
+ if (!textInputRef.current) return '';
403
425
  return textInputRef.current.innerHTML;
404
426
  },
405
427
 
406
428
  get text() {
429
+ if (!textInputRef.current) return '';
407
430
  return textInputRef.current.innerText;
408
431
  },
409
432
 
410
433
  get size() {
434
+ if (!textInputRef.current) {
435
+ return {
436
+ width: 0,
437
+ height: 0
438
+ };
439
+ }
440
+
411
441
  return {
412
442
  width: textInputRef.current.offsetWidth,
413
443
  height: textInputRef.current.offsetHeight
@@ -415,14 +445,15 @@ const TextInput = ({
415
445
  },
416
446
 
417
447
  focus() {
448
+ if (!textInputRef.current) return;
418
449
  textInputRef.current.focus();
419
450
  }
420
451
 
421
452
  }));
422
- /** @type {React.MutableRefObject<HTMLDivElement>} */
453
+ /** @type {React.MutableRefObject<HTMLDivElement | null>} */
423
454
 
424
455
  const placeholderRef = useRef(null);
425
- /** @type {React.MutableRefObject<HTMLDivElement>} */
456
+ /** @type {React.MutableRefObject<HTMLDivElement | null>} */
426
457
 
427
458
  const textInputRef = useRef(null);
428
459
  /**
@@ -438,7 +469,7 @@ const TextInput = ({
438
469
  } else if (event.key === "ArrowDown") {
439
470
  props.onArrowDown(event);
440
471
  } else {
441
- if (event.key.length === 1) {
472
+ if (event.key.length === 1 && placeholderRef.current) {
442
473
  placeholderRef.current.style.visibility = "hidden";
443
474
  }
444
475
  }
@@ -458,18 +489,20 @@ const TextInput = ({
458
489
 
459
490
 
460
491
  function handleKeyUp(event) {
461
- var _input$innerText;
462
-
463
492
  props.onKeyUp(event);
464
493
  const input = textInputRef.current;
465
494
 
466
- if (((_input$innerText = input.innerText) === null || _input$innerText === void 0 ? void 0 : _input$innerText.trim()) === "") {
467
- placeholderRef.current.style.visibility = "visible";
468
- } else {
469
- placeholderRef.current.style.visibility = "hidden";
495
+ if (placeholderRef.current) {
496
+ if (input?.innerText?.trim() === "") {
497
+ placeholderRef.current.style.visibility = "visible";
498
+ } else {
499
+ placeholderRef.current.style.visibility = "hidden";
500
+ }
470
501
  }
471
502
 
472
- onChange(textInputRef.current.innerHTML);
503
+ if (typeof onChange === 'function' && textInputRef.current) {
504
+ onChange(textInputRef.current.innerHTML);
505
+ }
473
506
  }
474
507
 
475
508
  return /*#__PURE__*/React.createElement("div", {
@@ -497,6 +530,51 @@ const TextInput = ({
497
530
 
498
531
  const TextInputWithRef = /*#__PURE__*/forwardRef(TextInput);
499
532
 
533
+ /* eslint-disable react/prop-types */
534
+ /**
535
+ * @typedef {object} Props
536
+ * @property {boolean} showPicker
537
+ * @property {(event: React.MouseEvent) => void} toggleShowPicker
538
+ * @property {HTMLDivElement=} buttonElement
539
+ */
540
+
541
+ /**
542
+ * Emoji Picker Button Component
543
+ * @param {Props} props
544
+ * @return {JSX.Element}
545
+ */
546
+
547
+ function EmojiPickerButton({
548
+ showPicker,
549
+ toggleShowPicker,
550
+ buttonElement
551
+ }) {
552
+ const buttonRef = useRef(null);
553
+ const [showCustomButtonContent, setShowCustomButtonContent] = useState(false);
554
+ useEffect(() => {
555
+ if ((buttonElement?.childNodes?.length ?? 0) > 2) {
556
+ buttonRef.current.appendChild(buttonElement?.childNodes[0]);
557
+ setShowCustomButtonContent(true);
558
+ }
559
+ }, [buttonElement?.childNodes]);
560
+ return /*#__PURE__*/React.createElement("button", {
561
+ ref: buttonRef,
562
+ type: "button",
563
+ className: `react-input-emoji--button${showPicker ? " react-input-emoji--button__show" : ""}`,
564
+ onClick: toggleShowPicker
565
+ }, !showCustomButtonContent && /*#__PURE__*/React.createElement("svg", {
566
+ xmlns: "http://www.w3.org/2000/svg",
567
+ viewBox: "0 0 24 24",
568
+ width: "24",
569
+ height: "24",
570
+ className: "react-input-emoji--button--icon"
571
+ }, /*#__PURE__*/React.createElement("path", {
572
+ d: "M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0m0 22C6.486 22 2 17.514 2 12S6.486 2 12 2s10 4.486 10 10-4.486 10-10 10"
573
+ }), /*#__PURE__*/React.createElement("path", {
574
+ d: "M8 7a2 2 0 1 0-.001 3.999A2 2 0 0 0 8 7M16 7a2 2 0 1 0-.001 3.999A2 2 0 0 0 16 7M15.232 15c-.693 1.195-1.87 2-3.349 2-1.477 0-2.655-.805-3.347-2H15m3-2H6a6 6 0 1 0 12 0"
575
+ })));
576
+ }
577
+
500
578
  var compressed = true;
501
579
  var categories$1 = [
502
580
  {
@@ -49301,23 +49379,20 @@ function _defineProperties(target, props) {
49301
49379
  function _createClass(Constructor, protoProps, staticProps) {
49302
49380
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
49303
49381
  if (staticProps) _defineProperties(Constructor, staticProps);
49382
+ Object.defineProperty(Constructor, "prototype", {
49383
+ writable: false
49384
+ });
49304
49385
  return Constructor;
49305
49386
  }
49306
49387
 
49307
49388
  function _typeof(obj) {
49308
49389
  "@babel/helpers - typeof";
49309
49390
 
49310
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
49311
- _typeof = function _typeof(obj) {
49312
- return typeof obj;
49313
- };
49314
- } else {
49315
- _typeof = function _typeof(obj) {
49316
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
49317
- };
49318
- }
49319
-
49320
- return _typeof(obj);
49391
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
49392
+ return typeof obj;
49393
+ } : function (obj) {
49394
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
49395
+ }, _typeof(obj);
49321
49396
  }
49322
49397
 
49323
49398
  var mapping = {
@@ -49407,8 +49482,8 @@ var stringFromCodePoint = _String.fromCodePoint || function stringFromCodePoint(
49407
49482
  codePoint > 0x10ffff || // not a valid Unicode code point
49408
49483
  Math.floor(codePoint) != codePoint // not an integer
49409
49484
  ) {
49410
- throw RangeError('Invalid code point: ' + codePoint);
49411
- }
49485
+ throw RangeError('Invalid code point: ' + codePoint);
49486
+ }
49412
49487
 
49413
49488
  if (codePoint <= 0xffff) {
49414
49489
  // BMP code point
@@ -50011,7 +50086,7 @@ function _defineProperty(obj, key, value) {
50011
50086
  }
50012
50087
 
50013
50088
  function _extends() {
50014
- _extends = Object.assign || function (target) {
50089
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
50015
50090
  for (var i = 1; i < arguments.length; i++) {
50016
50091
  var source = arguments[i];
50017
50092
 
@@ -50024,7 +50099,6 @@ function _extends() {
50024
50099
 
50025
50100
  return target;
50026
50101
  };
50027
-
50028
50102
  return _extends.apply(this, arguments);
50029
50103
  }
50030
50104
 
@@ -50039,24 +50113,25 @@ function _assertThisInitialized(self) {
50039
50113
  function _possibleConstructorReturn(self, call) {
50040
50114
  if (call && (_typeof(call) === "object" || typeof call === "function")) {
50041
50115
  return call;
50116
+ } else if (call !== void 0) {
50117
+ throw new TypeError("Derived constructors may only return object or undefined");
50042
50118
  }
50043
50119
 
50044
50120
  return _assertThisInitialized(self);
50045
50121
  }
50046
50122
 
50047
50123
  function _getPrototypeOf(o) {
50048
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
50124
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
50049
50125
  return o.__proto__ || Object.getPrototypeOf(o);
50050
50126
  };
50051
50127
  return _getPrototypeOf(o);
50052
50128
  }
50053
50129
 
50054
50130
  function _setPrototypeOf(o, p) {
50055
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
50131
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
50056
50132
  o.__proto__ = p;
50057
50133
  return o;
50058
50134
  };
50059
-
50060
50135
  return _setPrototypeOf(o, p);
50061
50136
  }
50062
50137
 
@@ -50072,6 +50147,9 @@ function _inherits(subClass, superClass) {
50072
50147
  configurable: true
50073
50148
  }
50074
50149
  });
50150
+ Object.defineProperty(subClass, "prototype", {
50151
+ writable: false
50152
+ });
50075
50153
  if (superClass) _setPrototypeOf(subClass, superClass);
50076
50154
  }
50077
50155
 
@@ -52349,7 +52427,7 @@ styleInject(css_248z);
52349
52427
  * @property {'light' | 'dark' | 'auto'} theme
52350
52428
  * @property {function(import("../types/types").EmojiMartItem): void} onSelectEmoji
52351
52429
  * @property {boolean} disableRecent
52352
- * @property {object[]} customEmojis
52430
+ * @property {import("emoji-mart").CustomEmoji[]=} customEmojis
52353
52431
  */
52354
52432
 
52355
52433
  /**
@@ -52394,6 +52472,43 @@ EmojiPicker.propTypes = {
52394
52472
  };
52395
52473
  var EmojiPicker$1 = /*#__PURE__*/memo(EmojiPicker);
52396
52474
 
52475
+ /**
52476
+ * @typedef {object} Props
52477
+ * @property {boolean} showPicker
52478
+ * @property {'light' | 'dark' | 'auto'} theme
52479
+ * @property {(emoji: import("../types/types").EmojiMartItem) => void} handleSelectEmoji
52480
+ * @property {boolean} disableRecent
52481
+ * @property {import("emoji-mart").CustomEmoji[]=} customEmojis
52482
+ */
52483
+
52484
+ /**
52485
+ * Emoji Picker Button Component
52486
+ * @param {Props} props
52487
+ * @return {JSX.Element}
52488
+ */
52489
+
52490
+ function EmojiPickerContainer({
52491
+ showPicker,
52492
+ theme,
52493
+ handleSelectEmoji,
52494
+ disableRecent,
52495
+ customEmojis
52496
+ }) {
52497
+ return /*#__PURE__*/React.createElement("div", {
52498
+ className: "react-emoji-picker--container"
52499
+ }, showPicker && /*#__PURE__*/React.createElement("div", {
52500
+ className: "react-emoji-picker--wrapper",
52501
+ onClick: evt => evt.stopPropagation()
52502
+ }, /*#__PURE__*/React.createElement("div", {
52503
+ className: "react-emoji-picker"
52504
+ }, /*#__PURE__*/React.createElement(EmojiPicker$1, {
52505
+ theme: theme,
52506
+ onSelectEmoji: handleSelectEmoji,
52507
+ disableRecent: disableRecent,
52508
+ customEmojis: customEmojis
52509
+ }))));
52510
+ }
52511
+
52397
52512
  // @ts-check
52398
52513
  /**
52399
52514
  * @typedef {import('../types/types').SanitizeFn} SanitizeFn
@@ -52408,10 +52523,11 @@ var EmojiPicker$1 = /*#__PURE__*/memo(EmojiPicker);
52408
52523
  * @property {'light' | 'dark' | 'auto'} theme
52409
52524
  * @property {boolean} keepOpened
52410
52525
  * @property {boolean} disableRecent
52411
- * @property {object[]=} customEmojis
52526
+ * @property {import("emoji-mart").CustomEmoji[]=} customEmojis
52412
52527
  * @property {(fn: SanitizeFn) => void} addSanitizeFn
52413
52528
  * @property {(fn: PolluteFn) => void} addPolluteFn
52414
52529
  * @property {(html: string) => void} appendContent
52530
+ * @property {HTMLDivElement=} buttonElement
52415
52531
  */
52416
52532
  // eslint-disable-next-line valid-jsdoc
52417
52533
 
@@ -52425,9 +52541,13 @@ const EmojiPickerWrapper = props => {
52425
52541
  customEmojis,
52426
52542
  addSanitizeFn,
52427
52543
  addPolluteFn,
52428
- appendContent
52544
+ appendContent,
52545
+ buttonElement
52429
52546
  } = props;
52430
52547
  const [showPicker, setShowPicker] = useState(false);
52548
+ /** @type {[HTMLDivElement | undefined, React.Dispatch<React.SetStateAction<HTMLDivElement | undefined>>]} */
52549
+
52550
+ const [customButton, setCustomButton] = useState();
52431
52551
  useEffect(() => {
52432
52552
  addSanitizeFn(replaceAllTextEmojiToString);
52433
52553
  }, [addSanitizeFn]);
@@ -52481,33 +52601,32 @@ const EmojiPickerWrapper = props => {
52481
52601
  }
52482
52602
  }
52483
52603
 
52484
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
52485
- className: "react-emoji-picker--container"
52486
- }, showPicker && /*#__PURE__*/React.createElement("div", {
52487
- className: "react-emoji-picker--wrapper",
52488
- onClick: evt => evt.stopPropagation()
52489
- }, /*#__PURE__*/React.createElement("div", {
52490
- className: "react-emoji-picker"
52491
- }, /*#__PURE__*/React.createElement(EmojiPicker$1, {
52604
+ useEffect(() => {
52605
+ if (buttonElement?.style) {
52606
+ buttonElement.style.position = "relative";
52607
+ setCustomButton(buttonElement);
52608
+ }
52609
+ }, [buttonElement]);
52610
+ return customButton ? /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EmojiPickerContainer, {
52611
+ showPicker: showPicker,
52492
52612
  theme: theme,
52493
- onSelectEmoji: handleSelectEmoji,
52613
+ handleSelectEmoji: handleSelectEmoji,
52494
52614
  disableRecent: disableRecent,
52495
52615
  customEmojis: customEmojis
52496
- })))), /*#__PURE__*/React.createElement("button", {
52497
- type: "button",
52498
- className: `react-input-emoji--button${showPicker ? " react-input-emoji--button__show" : ""}`,
52499
- onClick: toggleShowPicker
52500
- }, /*#__PURE__*/React.createElement("svg", {
52501
- xmlns: "http://www.w3.org/2000/svg",
52502
- viewBox: "0 0 24 24",
52503
- width: "24",
52504
- height: "24",
52505
- className: "react-input-emoji--button--icon"
52506
- }, /*#__PURE__*/React.createElement("path", {
52507
- d: "M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0m0 22C6.486 22 2 17.514 2 12S6.486 2 12 2s10 4.486 10 10-4.486 10-10 10"
52508
- }), /*#__PURE__*/React.createElement("path", {
52509
- d: "M8 7a2 2 0 1 0-.001 3.999A2 2 0 0 0 8 7M16 7a2 2 0 1 0-.001 3.999A2 2 0 0 0 16 7M15.232 15c-.693 1.195-1.87 2-3.349 2-1.477 0-2.655-.805-3.347-2H15m3-2H6a6 6 0 1 0 12 0"
52510
- }))));
52616
+ }), /*#__PURE__*/React.createElement(EmojiPickerButton, {
52617
+ showPicker: showPicker,
52618
+ toggleShowPicker: toggleShowPicker,
52619
+ buttonElement: customButton
52620
+ })), customButton) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EmojiPickerContainer, {
52621
+ showPicker: showPicker,
52622
+ theme: theme,
52623
+ handleSelectEmoji: handleSelectEmoji,
52624
+ disableRecent: disableRecent,
52625
+ customEmojis: customEmojis
52626
+ }), /*#__PURE__*/React.createElement(EmojiPickerButton, {
52627
+ showPicker: showPicker,
52628
+ toggleShowPicker: toggleShowPicker
52629
+ }));
52511
52630
  };
52512
52631
 
52513
52632
  // @ts-check
@@ -52606,7 +52725,7 @@ function getElementWithFocus() {
52606
52725
 
52607
52726
  function getSelectionStart() {
52608
52727
  const node = document.getSelection().anchorNode;
52609
- return (node === null || node === void 0 ? void 0 : node.nodeType) == 3 ? node : null;
52728
+ return node?.nodeType == 3 ? node : null;
52610
52729
  }
52611
52730
 
52612
52731
  // @ts-check
@@ -52651,11 +52770,9 @@ function useMention(searchMention) {
52651
52770
  /** @type {(event: React.KeyboardEvent) => void} */
52652
52771
 
52653
52772
  const onKeyUp = useCallback(async event => {
52654
- var _getElementWithFocus;
52655
-
52656
52773
  if (typeof searchMention !== "function") return;
52657
52774
 
52658
- if (event.key === "Backspace" && (_getElementWithFocus = getElementWithFocus()) !== null && _getElementWithFocus !== void 0 && _getElementWithFocus.element.parentElement.hasAttribute("data-mention-id")) {
52775
+ if (event.key === "Backspace" && getElementWithFocus()?.element.parentElement.hasAttribute("data-mention-id")) {
52659
52776
  const elementWithFocus = getElementWithFocus();
52660
52777
  elementWithFocus.element.parentElement.remove();
52661
52778
  } else if (!["ArrowUp", "ArrowDown", "Esc", "Escape"].includes(event.key)) {
@@ -53006,7 +53123,8 @@ function useEventListeners() {
53006
53123
  arrowUp: createObserver(),
53007
53124
  arrowDown: createObserver(),
53008
53125
  enter: createObserver(),
53009
- focus: createObserver()
53126
+ focus: createObserver(),
53127
+ blur: createObserver()
53010
53128
  }), []);
53011
53129
  /**
53012
53130
  * @template {keyof TextInputListeners} T, K
@@ -53072,6 +53190,7 @@ function usePollute() {
53072
53190
  * @property {(size: {width: number, height: number}) => void} onResize
53073
53191
  * @property {() => void} onClick
53074
53192
  * @property {() => void} onFocus
53193
+ * @property {() => void=} onBlur
53075
53194
  * @property {number} maxLength
53076
53195
  * @property {boolean} keepOpened
53077
53196
  * @property {(event: KeyboardEvent) => void} onKeyDown
@@ -53085,6 +53204,7 @@ function usePollute() {
53085
53204
  * @property {string} fontFamily
53086
53205
  * @property {object[]=} customEmojis
53087
53206
  * @property {(text: string) => Promise<MetionUser[]>=} searchMention
53207
+ * @property {HTMLDivElement=} buttonElement
53088
53208
  */
53089
53209
 
53090
53210
  /**
@@ -53101,6 +53221,7 @@ function InputEmoji(props, ref) {
53101
53221
  onResize,
53102
53222
  onClick,
53103
53223
  onFocus,
53224
+ onBlur,
53104
53225
  onKeyDown,
53105
53226
  theme,
53106
53227
  cleanOnEnter,
@@ -53113,13 +53234,14 @@ function InputEmoji(props, ref) {
53113
53234
  value,
53114
53235
  customEmojis,
53115
53236
  searchMention,
53237
+ buttonElement,
53116
53238
  // style
53117
53239
  borderRadius,
53118
53240
  borderColor,
53119
53241
  fontSize,
53120
53242
  fontFamily
53121
53243
  } = props;
53122
- /** @type {React.MutableRefObject<import('./text-input').Ref>} */
53244
+ /** @type {React.MutableRefObject<import('./text-input').Ref | null>} */
53123
53245
 
53124
53246
  const textInputRef = useRef(null);
53125
53247
  const {
@@ -53136,6 +53258,7 @@ function InputEmoji(props, ref) {
53136
53258
  pollute
53137
53259
  } = usePollute();
53138
53260
  const updateHTML = useCallback((nextValue = "") => {
53261
+ if (textInputRef.current === null) return;
53139
53262
  textInputRef.current.html = replaceAllTextEmojis(nextValue);
53140
53263
  sanitizedTextRef.current = nextValue;
53141
53264
  }, [sanitizedTextRef]);
@@ -53164,11 +53287,11 @@ function InputEmoji(props, ref) {
53164
53287
  * @return {boolean}
53165
53288
  */
53166
53289
  function handleKeydown(event) {
53167
- if (typeof maxLength !== "undefined" && event.key !== "Backspace" && totalCharacters(textInputRef.current) >= maxLength) {
53290
+ if (typeof maxLength !== "undefined" && event.key !== "Backspace" && textInputRef.current !== null && totalCharacters(textInputRef.current) >= maxLength) {
53168
53291
  event.preventDefault();
53169
53292
  }
53170
53293
 
53171
- if (event.key === "Enter") {
53294
+ if (event.key === "Enter" && textInputRef.current) {
53172
53295
  event.preventDefault();
53173
53296
  const text = sanitize(textInputRef.current.html);
53174
53297
  emitChange(sanitizedTextRef.current);
@@ -53217,6 +53340,19 @@ function InputEmoji(props, ref) {
53217
53340
  unsubscribe();
53218
53341
  };
53219
53342
  }, [addEventListener, onClick, onFocus]);
53343
+ useEffect(() => {
53344
+ /** */
53345
+ function handleBlur() {
53346
+ if (typeof onBlur === "function") {
53347
+ onBlur();
53348
+ }
53349
+ }
53350
+
53351
+ const unsubscribe = addEventListener("blur", handleBlur);
53352
+ return () => {
53353
+ unsubscribe();
53354
+ };
53355
+ }, [addEventListener, onBlur]);
53220
53356
  /**
53221
53357
  *
53222
53358
  * @param {string} html
@@ -53233,11 +53369,13 @@ function InputEmoji(props, ref) {
53233
53369
 
53234
53370
 
53235
53371
  function appendContent(html) {
53236
- if (typeof maxLength !== "undefined" && totalCharacters(textInputRef.current) >= maxLength) {
53372
+ if (typeof maxLength !== "undefined" && textInputRef.current !== null && totalCharacters(textInputRef.current) >= maxLength) {
53237
53373
  return;
53238
53374
  }
53239
53375
 
53240
- textInputRef.current.appendContent(html);
53376
+ if (textInputRef.current !== null) {
53377
+ textInputRef.current.appendContent(html);
53378
+ }
53241
53379
  }
53242
53380
  /**
53243
53381
  * Handle copy of current selected text
@@ -53277,6 +53415,7 @@ function InputEmoji(props, ref) {
53277
53415
  ref: textInputRef,
53278
53416
  onCopy: handleCopy,
53279
53417
  onPaste: handlePaste,
53418
+ onBlur: listeners.blur.publish,
53280
53419
  onFocus: listeners.focus.publish,
53281
53420
  onArrowUp: listeners.arrowUp.publish,
53282
53421
  onArrowDown: listeners.arrowDown.publish,
@@ -53300,7 +53439,8 @@ function InputEmoji(props, ref) {
53300
53439
  customEmojis: customEmojis,
53301
53440
  addSanitizeFn: addSanitizeFn,
53302
53441
  addPolluteFn: addPolluteFn,
53303
- appendContent: appendContent
53442
+ appendContent: appendContent,
53443
+ buttonElement: buttonElement
53304
53444
  }));
53305
53445
  }
53306
53446
 
@@ -53319,5 +53459,5 @@ InputEmojiWithRef.defaultProps = {
53319
53459
  customEmojis: []
53320
53460
  };
53321
53461
 
53322
- export default InputEmojiWithRef;
53462
+ export { InputEmojiWithRef as default };
53323
53463
  //# sourceMappingURL=index.es.js.map