@semcore/bulk-textarea 16.6.2 → 17.0.0-prerelease.18

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +4 -4
  3. package/lib/cjs/BulkTextarea.js +248 -269
  4. package/lib/cjs/BulkTextarea.js.map +1 -1
  5. package/lib/cjs/BulkTextarea.types.js.map +1 -1
  6. package/lib/cjs/components/ClearAll.js +9 -8
  7. package/lib/cjs/components/ClearAll.js.map +1 -1
  8. package/lib/cjs/components/Counter.js +12 -10
  9. package/lib/cjs/components/Counter.js.map +1 -1
  10. package/lib/cjs/components/ErrorsNavigation.js +22 -20
  11. package/lib/cjs/components/ErrorsNavigation.js.map +1 -1
  12. package/lib/cjs/components/InputField/InputField.js +916 -1045
  13. package/lib/cjs/components/InputField/InputField.js.map +1 -1
  14. package/lib/cjs/index.js +3 -3
  15. package/lib/cjs/translations/__intergalactic-dynamic-locales.js +16 -16
  16. package/lib/cjs/translations/__intergalactic-dynamic-locales.js.map +1 -1
  17. package/lib/es6/BulkTextarea.js +242 -263
  18. package/lib/es6/BulkTextarea.js.map +1 -1
  19. package/lib/es6/BulkTextarea.types.js.map +1 -1
  20. package/lib/es6/components/ClearAll.js +8 -7
  21. package/lib/es6/components/ClearAll.js.map +1 -1
  22. package/lib/es6/components/Counter.js +7 -5
  23. package/lib/es6/components/Counter.js.map +1 -1
  24. package/lib/es6/components/ErrorsNavigation.js +15 -13
  25. package/lib/es6/components/ErrorsNavigation.js.map +1 -1
  26. package/lib/es6/components/InputField/InputField.js +910 -1040
  27. package/lib/es6/components/InputField/InputField.js.map +1 -1
  28. package/lib/es6/translations/__intergalactic-dynamic-locales.js +15 -15
  29. package/lib/es6/translations/__intergalactic-dynamic-locales.js.map +1 -1
  30. package/lib/esm/BulkTextarea.mjs +244 -223
  31. package/lib/esm/components/ClearAll.mjs +8 -7
  32. package/lib/esm/components/Counter.mjs +7 -2
  33. package/lib/esm/components/ErrorsNavigation.mjs +13 -2
  34. package/lib/esm/components/InputField/InputField.mjs +903 -981
  35. package/lib/esm/translations/__intergalactic-dynamic-locales.mjs +1 -1
  36. package/lib/types/BulkTextarea.types.d.ts +1 -1
  37. package/lib/types/components/InputField/InputField.d.ts +6 -2
  38. package/package.json +11 -11
@@ -1,1162 +1,1032 @@
1
- import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
- import _createForOfIteratorHelper from "@babel/runtime/helpers/createForOfIteratorHelper";
4
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
- import _createClass from "@babel/runtime/helpers/createClass";
6
- import _callSuper from "@babel/runtime/helpers/callSuper";
7
- import _inherits from "@babel/runtime/helpers/inherits";
8
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
2
  import { sstyled as _sstyled } from "@semcore/core";
10
3
  import { assignProps as _assignProps } from "@semcore/core";
4
+ import { Box } from '@semcore/base-components';
11
5
  import { Component, sstyled, Root } from '@semcore/core';
12
6
  import { extractAriaProps } from '@semcore/core/lib/utils/ariaProps';
13
7
  import uniqueIDEnhancement from '@semcore/core/lib/utils/uniqueID';
14
- import { Box } from '@semcore/flex-box';
15
8
  import Tooltip from '@semcore/tooltip';
16
9
  import DOMPurify from 'dompurify';
17
10
  import React from 'react';
18
11
  /*!__reshadow-styles__:"./inputField.shadow.css"*/
19
- var style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SInputField_dlt8x_gg_>div{box-sizing:content-box;outline:0;border-radius:var(--intergalactic-control-rounded, 6px);border-color:var(--intergalactic-border-primary, #c4c7cf);border-style:solid;border-width:1px;overflow:auto;position:relative;background-color:var(--intergalactic-bg-primary-neutral, #ffffff);color:var(--intergalactic-text-primary, #191b23);word-wrap:break-word;word-break:break-word;font-family:inherit}.___SInputField_dlt8x_gg_>div:empty::before{content:\"1. \"attr(placeholder);color:var(--intergalactic-text-placeholder, #8a8e9b);position:absolute}.___SInputField_dlt8x_gg_>div:nth-child(even){color:red;counter-increment:row;margin-bottom:var(--intergalactic-spacing-1x, 4px);position:relative;word-break:break-all}.___SInputField_dlt8x_gg_>div:nth-child(even)::before{content:counter(row)\".\";display:inline-block;white-space:nowrap;text-align:right;color:var(--intergalactic-text-secondary, #6c6e79);margin-right:var(--intergalactic-spacing-1x, 4px)}.___SInputField_dlt8x_gg_>div>p{counter-increment:row;margin:0 0 var(--intergalactic-spacing-1x, 4px)0;position:relative;word-break:break-all;white-space:pre-wrap;padding:0 var(--intergalactic-spacing-5x, 20px)0 var(--intergalactic-spacing-4x, 16px)}.___SInputField_dlt8x_gg_>div>p:last-of-type{margin-bottom:0}.___SInputField_dlt8x_gg_>div>p:not(:empty)::before{content:counter(row)\".\";display:inline-block;white-space:nowrap;text-align:right;color:var(--intergalactic-text-secondary, #6c6e79);margin-right:var(--intergalactic-spacing-1x, 4px);position:absolute;left:0}.___SInputField_dlt8x_gg_>div>p[data-over-max-rows=true]{background-color:var(--intergalactic-bg-secondary-critical, #fff0f7)}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+10))>p{padding-left:var(--intergalactic-spacing-6x, 24px)}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+10))>p:nth-child(-n+9)::before{padding-left:var(--intergalactic-spacing-2x, 8px)}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+100))>p{padding-left:var(--intergalactic-spacing-8x, 32px)}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+100))>p:nth-child(-n+9)::before{padding-left:var(--intergalactic-spacing-4x, 16px)}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+100))>p:nth-child(n+10)::before{padding-left:var(--intergalactic-spacing-2x, 8px)}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+100))>p:nth-child(n+100)::before{padding-left:0}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+1000))>p{padding-left:calc(var(--intergalactic-spacing-10x, 40px) + var(--intergalactic-spacing-1x, 4px))}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+1000))>p:nth-child(-n+9)::before{padding-left:var(--intergalactic-spacing-6x, 24px)}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+1000))>p:nth-child(n+10)::before{padding-left:var(--intergalactic-spacing-4x, 16px)}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+1000))>p:nth-child(n+100)::before{padding-left:var(--intergalactic-spacing-2x, 8px)}.___SInputField_dlt8x_gg_>div:has(p:nth-child(n+1000))>p:nth-child(n+1000)::before{padding-left:0}.___SInputField_dlt8x_gg_.__showErrors_dlt8x_gg_>div[aria-invalid]>p[aria-invalid]:after{content:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBmaWxsPSIjZDEwMDJmIj48cGF0aCBkPSJNNyA2aDJ2NEg3VjZabTIgN3YtMkg3djJoMloiLz48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTYuMTUyIDEuMTcyYy43MTktMS41NjMgMi45NzctMS41NjMgMy42OTYgMGw2LjA0MyAxMy4xNDFjLjM2My43OTEtLjIyNSAxLjY4Ny0xLjEwOSAxLjY4N0gxLjIxOGMtLjg4NCAwLTEuNDcyLS44OTYtMS4xMDktMS42ODdMNi4xNTIgMS4xNzJabTcuMzc0IDEyLjgzN0w4IDEuOTkgMi40NzQgMTQuMDFoMTEuMDUyWiIvPjwvc3ZnPgo=\\ );position:absolute;right:0;top:var(--intergalactic-spacing-05x, 2px)}.___SInputField_dlt8x_gg_._size_m_dlt8x_gg_>div{padding:var(--intergalactic-spacing-2x, 8px) var(--intergalactic-spacing-4x, 16px);font-size:var(--intergalactic-fs-200, 14px);line-height:var(--intergalactic-lh-200, 142%);min-height:calc(var(--minRows_dlt8x)*20px);max-height:calc((var(--maxRows_dlt8x) - 1)*(20px + var(--intergalactic-spacing-1x, 4px)) + 18px)}.___SInputField_dlt8x_gg_._size_m_dlt8x_gg_>div:empty{padding-left:var(--intergalactic-spacing-8x, 32px)}.___SInputField_dlt8x_gg_._size_l_dlt8x_gg_>div:empty::before,.___SInputField_dlt8x_gg_._size_m_dlt8x_gg_>div:empty::before{left:var(--intergalactic-spacing-4x, 16px)}.___SInputField_dlt8x_gg_._size_l_dlt8x_gg_>div{padding:var(--intergalactic-spacing-3x, 12px) var(--intergalactic-spacing-4x, 16px);font-size:var(--intergalactic-fs-300, 16px);line-height:var(--intergalactic-lh-300, 150%);min-height:calc(var(--minRows_dlt8x)*24px);max-height:calc((var(--maxRows_dlt8x) - 1)*(24px + var(--intergalactic-spacing-1x, 4px)) + 20px)}.___SInputField_dlt8x_gg_._size_l_dlt8x_gg_>div:empty{padding-left:calc(var(--intergalactic-spacing-8x, 32px) + var(--intergalactic-spacing-05x, 2px))}.___SInputField_dlt8x_gg_._state_normal_dlt8x_gg_:not(.__disabled_dlt8x_gg_)>div:focus{border-color:var(--intergalactic-border-info-active, #006dca);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;outline-offset:0;transition-property:outline-color,outline-width}.___SInputField_dlt8x_gg_._state_valid_dlt8x_gg_>div{border-color:var(--intergalactic-border-success-active, #007c65)}.___SInputField_dlt8x_gg_._state_valid_dlt8x_gg_>div:focus{border-color:var(--intergalactic-border-success-active, #007c65);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;outline-offset:0;transition-property:outline-color,outline-width;outline-color:var(--intergalactic-keyboard-focus-valid-outline, #009f81)}.___SInputField_dlt8x_gg_._state_invalid_dlt8x_gg_>div{border-color:var(--intergalactic-border-critical-active, #d1002f);background-image:var(--intergalactic-border-critical-pattern, repeating-linear-gradient(315deg, rgba(209, 0, 47, 1) 0, rgba(209, 0, 47, 1) 2px, transparent 0, transparent 50%));background-size:6px 6px;background-color:var(--intergalactic-bg-primary-neutral, #ffffff);border-bottom-left-radius:var(--intergalactic-control-rounded, 6px);border-top-left-radius:var(--intergalactic-control-rounded, 6px);background-repeat:repeat-y}.___SInputField_dlt8x_gg_._state_invalid_dlt8x_gg_>div:focus{border-color:var(--intergalactic-border-critical-active, #d1002f);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;outline-offset:0;transition-property:outline-color,outline-width;outline-color:var(--intergalactic-keyboard-focus-invalid-outline, #ff4953)}.___SInputField_dlt8x_gg_.__readonly_dlt8x_gg_>div{background-color:var(--intergalactic-bg-secondary-neutral, #f4f5f9)}.___SInputField_dlt8x_gg_.__disabled_dlt8x_gg_>div{opacity:var(--intergalactic-disabled-opacity, 0.3)}", /*__inner_css_end__*/"dlt8x_gg_"),
12
+ const style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SInputField_clk0e_gg_>div{box-sizing:content-box;outline:0;border-radius:var(--intergalactic-control-rounded, 6px);border-color:var(--intergalactic-border-primary, #c4c7cf);border-style:solid;border-width:1px;overflow:auto;position:relative;background-color:var(--intergalactic-bg-primary-neutral, #ffffff);color:var(--intergalactic-text-primary, #191b23);word-wrap:break-word;word-break:break-word;font-family:inherit}.___SInputField_clk0e_gg_>div:empty::before{content:\"1. \"attr(placeholder);color:var(--intergalactic-text-placeholder, #8a8e9b);position:absolute}.___SInputField_clk0e_gg_>div:nth-child(even){color:red;counter-increment:row;margin-bottom:var(--intergalactic-spacing-1x, 4px);position:relative;word-break:break-all}.___SInputField_clk0e_gg_>div:nth-child(even)::before{content:counter(row)\".\";display:inline-block;white-space:nowrap;text-align:right;color:var(--intergalactic-text-secondary, #6c6e79);margin-right:var(--intergalactic-spacing-1x, 4px)}.___SInputField_clk0e_gg_>div>p{counter-increment:row;margin:0 0 var(--intergalactic-spacing-1x, 4px)0;position:relative;word-break:break-all;white-space:pre-wrap;padding:0 var(--intergalactic-spacing-5x, 20px)0 var(--intergalactic-spacing-4x, 16px)}.___SInputField_clk0e_gg_>div>p:last-of-type{margin-bottom:0}.___SInputField_clk0e_gg_>div>p:not(:empty)::before{content:counter(row)\".\";display:inline-block;white-space:nowrap;text-align:right;color:var(--intergalactic-text-secondary, #6c6e79);margin-right:var(--intergalactic-spacing-1x, 4px);position:absolute;left:0}.___SInputField_clk0e_gg_>div>p[data-over-max-rows=true]{background-color:var(--intergalactic-bg-secondary-critical, #fff0f7)}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+10))>p{padding-left:var(--intergalactic-spacing-6x, 24px)}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+10))>p:nth-child(-n+9)::before{padding-left:var(--intergalactic-spacing-2x, 8px)}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+100))>p{padding-left:var(--intergalactic-spacing-8x, 32px)}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+100))>p:nth-child(-n+9)::before{padding-left:var(--intergalactic-spacing-4x, 16px)}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+100))>p:nth-child(n+10)::before{padding-left:var(--intergalactic-spacing-2x, 8px)}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+100))>p:nth-child(n+100)::before{padding-left:0}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+1000))>p{padding-left:calc(var(--intergalactic-spacing-10x, 40px) + var(--intergalactic-spacing-1x, 4px))}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+1000))>p:nth-child(-n+9)::before{padding-left:var(--intergalactic-spacing-6x, 24px)}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+1000))>p:nth-child(n+10)::before{padding-left:var(--intergalactic-spacing-4x, 16px)}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+1000))>p:nth-child(n+100)::before{padding-left:var(--intergalactic-spacing-2x, 8px)}.___SInputField_clk0e_gg_>div:has(p:nth-child(n+1000))>p:nth-child(n+1000)::before{padding-left:0}.___SInputField_clk0e_gg_.__showErrors_clk0e_gg_>div[aria-invalid]>p[aria-invalid]:after{content:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBmaWxsPSIjZDEwMDJmIj48cGF0aCBkPSJNNyA2aDJ2NEg3VjZabTIgN3YtMkg3djJoMloiLz48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTYuMTUyIDEuMTcyYy43MTktMS41NjMgMi45NzctMS41NjMgMy42OTYgMGw2LjA0MyAxMy4xNDFjLjM2My43OTEtLjIyNSAxLjY4Ny0xLjEwOSAxLjY4N0gxLjIxOGMtLjg4NCAwLTEuNDcyLS44OTYtMS4xMDktMS42ODdMNi4xNTIgMS4xNzJabTcuMzc0IDEyLjgzN0w4IDEuOTkgMi40NzQgMTQuMDFoMTEuMDUyWiIvPjwvc3ZnPgo=\\ );position:absolute;right:0;top:var(--intergalactic-spacing-05x, 2px)}.___SInputField_clk0e_gg_._size_m_clk0e_gg_>div{padding:var(--intergalactic-spacing-2x, 8px) var(--intergalactic-spacing-4x, 16px);font-size:var(--intergalactic-fs-200, 14px);line-height:var(--intergalactic-lh-200, 142%);min-height:calc(var(--minRows_clk0e)*20px);max-height:calc((var(--maxRows_clk0e) - 1)*(20px + var(--intergalactic-spacing-1x, 4px)) + 18px)}.___SInputField_clk0e_gg_._size_m_clk0e_gg_>div:empty{padding-left:var(--intergalactic-spacing-8x, 32px)}.___SInputField_clk0e_gg_._size_l_clk0e_gg_>div:empty::before,.___SInputField_clk0e_gg_._size_m_clk0e_gg_>div:empty::before{left:var(--intergalactic-spacing-4x, 16px)}.___SInputField_clk0e_gg_._size_l_clk0e_gg_>div{padding:var(--intergalactic-spacing-3x, 12px) var(--intergalactic-spacing-4x, 16px);font-size:var(--intergalactic-fs-300, 16px);line-height:var(--intergalactic-lh-300, 150%);min-height:calc(var(--minRows_clk0e)*24px);max-height:calc((var(--maxRows_clk0e) - 1)*(24px + var(--intergalactic-spacing-1x, 4px)) + 20px)}.___SInputField_clk0e_gg_._size_l_clk0e_gg_>div:empty{padding-left:calc(var(--intergalactic-spacing-8x, 32px) + var(--intergalactic-spacing-05x, 2px))}.___SInputField_clk0e_gg_._state_normal_clk0e_gg_:not(.__disabled_clk0e_gg_)>div:focus{border-color:var(--intergalactic-border-info-active, #006dca);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;outline-offset:0;transition-property:outline-color,outline-width}.___SInputField_clk0e_gg_._state_valid_clk0e_gg_>div{border-color:var(--intergalactic-border-success-active, #007c65)}.___SInputField_clk0e_gg_._state_valid_clk0e_gg_>div:focus{border-color:var(--intergalactic-border-success-active, #007c65);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;outline-offset:0;transition-property:outline-color,outline-width;outline-color:var(--intergalactic-keyboard-focus-valid-outline, #009f81)}.___SInputField_clk0e_gg_._state_invalid_clk0e_gg_>div{border-color:var(--intergalactic-border-critical-active, #d1002f);background-image:var(--intergalactic-border-critical-pattern, repeating-linear-gradient(315deg, rgba(209, 0, 47, 1) 0, rgba(209, 0, 47, 1) 2px, transparent 0, transparent 50%));background-size:6px 6px;background-color:var(--intergalactic-bg-primary-neutral, #ffffff);border-bottom-left-radius:var(--intergalactic-control-rounded, 6px);border-top-left-radius:var(--intergalactic-control-rounded, 6px);background-repeat:repeat-y}.___SInputField_clk0e_gg_._state_invalid_clk0e_gg_>div:focus{border-color:var(--intergalactic-border-critical-active, #d1002f);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;outline-offset:0;transition-property:outline-color,outline-width;outline-color:var(--intergalactic-keyboard-focus-invalid-outline, #ff4953)}.___SInputField_clk0e_gg_.__readonly_clk0e_gg_>div{background-color:var(--intergalactic-bg-secondary-neutral, #f4f5f9)}.___SInputField_clk0e_gg_.__disabled_clk0e_gg_>div{opacity:var(--intergalactic-disabled-opacity, 0.3)}", /*__inner_css_end__*/"clk0e_gg_"),
20
13
  /*__reshadow_css_end__*/
21
14
  {
22
- "__SInputField": "___SInputField_dlt8x_gg_",
23
- "_showErrors": "__showErrors_dlt8x_gg_",
24
- "_readonly": "__readonly_dlt8x_gg_",
25
- "_disabled": "__disabled_dlt8x_gg_",
26
- "_size_m": "_size_m_dlt8x_gg_",
27
- "--minRows": "--minRows_dlt8x",
28
- "--maxRows": "--maxRows_dlt8x",
29
- "_size_l": "_size_l_dlt8x_gg_",
30
- "_state_normal": "_state_normal_dlt8x_gg_",
31
- "_state_valid": "_state_valid_dlt8x_gg_",
32
- "_state_invalid": "_state_invalid_dlt8x_gg_"
15
+ "__SInputField": "___SInputField_clk0e_gg_",
16
+ "_showErrors": "__showErrors_clk0e_gg_",
17
+ "_readonly": "__readonly_clk0e_gg_",
18
+ "_disabled": "__disabled_clk0e_gg_",
19
+ "_size_m": "_size_m_clk0e_gg_",
20
+ "--minRows": "--minRows_clk0e",
21
+ "--maxRows": "--maxRows_clk0e",
22
+ "_size_l": "_size_l_clk0e_gg_",
23
+ "_state_normal": "_state_normal_clk0e_gg_",
24
+ "_state_valid": "_state_valid_clk0e_gg_",
25
+ "_state_invalid": "_state_invalid_clk0e_gg_"
33
26
  });
34
- var InputField = /*#__PURE__*/function (_Component) {
35
- function InputField(props) {
36
- var _this;
37
- _classCallCheck(this, InputField);
38
- _this = _callSuper(this, InputField, [props]);
39
- _defineProperty(_this, "delimiter", '\n');
40
- _defineProperty(_this, "skipEmptyLines", true);
41
- _defineProperty(_this, "emptyLineValue", '');
42
- _defineProperty(_this, "spaceLineValue", ' ');
43
- _defineProperty(_this, "containerRef", /*#__PURE__*/React.createRef());
44
- _defineProperty(_this, "textarea", void 0);
45
- _defineProperty(_this, "popper", null);
46
- _defineProperty(_this, "setPopperTrigger", null);
47
- _defineProperty(_this, "errorByInteraction", null);
48
- _defineProperty(_this, "changeTriggerTimeout", 0);
49
- _defineProperty(_this, "isScrolling", false);
50
- _defineProperty(_this, "scrollingTimeout", 0);
51
- _defineProperty(_this, "toggleErrorsPopperTimeout", 0);
52
- _defineProperty(_this, "isFocusing", false);
53
- _defineProperty(_this, "linesCountTimeout", 0);
54
- _defineProperty(_this, "observer", void 0);
55
- _defineProperty(_this, "state", {
27
+ class InputField extends Component {
28
+ constructor(props) {
29
+ super(props);
30
+ _defineProperty(this, "delimiter", '\n');
31
+ _defineProperty(this, "skipEmptyLines", true);
32
+ _defineProperty(this, "emptyLineValue", '');
33
+ _defineProperty(this, "spaceLineValue", ' ');
34
+ _defineProperty(this, "containerRef", /*#__PURE__*/React.createRef());
35
+ _defineProperty(this, "textarea", void 0);
36
+ _defineProperty(this, "popper", null);
37
+ _defineProperty(this, "setPopperTrigger", null);
38
+ _defineProperty(this, "errorByInteraction", null);
39
+ _defineProperty(this, "changeTriggerTimeout", 0);
40
+ _defineProperty(this, "isScrolling", false);
41
+ _defineProperty(this, "scrollingTimeout", 0);
42
+ _defineProperty(this, "toggleErrorsPopperTimeout", 0);
43
+ _defineProperty(this, "isFocusing", false);
44
+ _defineProperty(this, "linesCountTimeout", 0);
45
+ _defineProperty(this, "observer", void 0);
46
+ _defineProperty(this, "state", {
56
47
  visibleErrorPopper: false,
57
48
  keyboardLineIndex: -1,
58
49
  mouseLineIndex: -1
59
50
  });
60
- _this.handlePaste = _this.handlePaste.bind(_this);
61
- _this.handleChange = _this.handleChange.bind(_this);
62
- _this.handleFocus = _this.handleFocus.bind(_this);
63
- _this.handleBlur = _this.handleBlur.bind(_this);
64
- _this.handleKeyDown = _this.handleKeyDown.bind(_this);
65
- _this.handleMouseDown = _this.handleMouseDown.bind(_this);
66
- _this.handleMouseMove = _this.handleMouseMove.bind(_this);
67
- _this.handleMouseLeave = _this.handleMouseLeave.bind(_this);
68
- _this.handleScroll = _this.handleScroll.bind(_this);
69
- _this.handleSelectAll = _this.handleSelectAll.bind(_this);
70
- _this.textarea = _this.createContentEditableElement(props);
71
- _this.observer = new MutationObserver(function (mutationsList, observer) {
72
- var _iterator = _createForOfIteratorHelper(mutationsList),
73
- _step;
74
- try {
75
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
76
- var mutation = _step.value;
77
- if (mutation.type === 'characterData' || mutation.type === 'childList') {
78
- var _this$props$onImmedia, _this$props, _this$textarea$textCo;
79
- (_this$props$onImmedia = (_this$props = _this.props).onImmediatelyChange) === null || _this$props$onImmedia === void 0 || _this$props$onImmedia.call(_this$props, _this.getValues(), (_this$textarea$textCo = _this.textarea.textContent) !== null && _this$textarea$textCo !== void 0 ? _this$textarea$textCo : '');
80
- }
51
+ this.handlePaste = this.handlePaste.bind(this);
52
+ this.handleChange = this.handleChange.bind(this);
53
+ this.handleFocus = this.handleFocus.bind(this);
54
+ this.handleBlur = this.handleBlur.bind(this);
55
+ this.handleKeyDown = this.handleKeyDown.bind(this);
56
+ this.handleMouseDown = this.handleMouseDown.bind(this);
57
+ this.handleMouseMove = this.handleMouseMove.bind(this);
58
+ this.handleMouseLeave = this.handleMouseLeave.bind(this);
59
+ this.handleScroll = this.handleScroll.bind(this);
60
+ this.handleSelectAll = this.handleSelectAll.bind(this);
61
+ this.textarea = this.createContentEditableElement(props);
62
+ this.observer = new MutationObserver((mutationsList, observer) => {
63
+ for (const mutation of mutationsList) {
64
+ if (mutation.type === 'characterData' || mutation.type === 'childList') {
65
+ this.props.onImmediatelyChange?.(this.getValues(), this.textarea.textContent ?? '');
81
66
  }
82
- } catch (err) {
83
- _iterator.e(err);
84
- } finally {
85
- _iterator.f();
86
67
  }
87
68
  });
88
- return _this;
89
69
  }
90
- _inherits(InputField, _Component);
91
- return _createClass(InputField, [{
92
- key: "uncontrolledProps",
93
- value: function uncontrolledProps() {
94
- return {
95
- value: null,
96
- linesCount: null,
97
- errorIndex: null
98
- };
70
+ uncontrolledProps() {
71
+ return {
72
+ value: null,
73
+ linesCount: null,
74
+ errorIndex: null
75
+ };
76
+ }
77
+ componentDidMount() {
78
+ this.containerRef.current?.append(this.textarea);
79
+ this.handleValueOutChange();
80
+ const config = {
81
+ childList: true,
82
+ characterData: true,
83
+ subtree: true
84
+ };
85
+ if (this.props.onImmediatelyChange) {
86
+ this.observer.observe(this.textarea, config);
99
87
  }
100
- }, {
101
- key: "componentDidMount",
102
- value: function componentDidMount() {
103
- var _this$containerRef$cu;
104
- (_this$containerRef$cu = this.containerRef.current) === null || _this$containerRef$cu === void 0 || _this$containerRef$cu.append(this.textarea);
105
- this.handleValueOutChange();
106
- var config = {
107
- childList: true,
108
- characterData: true,
109
- subtree: true
110
- };
111
- if (this.props.onImmediatelyChange) {
112
- this.observer.observe(this.textarea, config);
88
+ }
89
+ componentDidUpdate(prevProps, prevState) {
90
+ const {
91
+ value,
92
+ errors,
93
+ errorIndex,
94
+ showErrors,
95
+ disabled,
96
+ readonly,
97
+ highlightErrorIndex,
98
+ lineProcessing,
99
+ ['aria-describedby']: ariaDescribedby = ''
100
+ } = this.props;
101
+ if (prevProps.value !== value) {
102
+ const currentValue = this.getValues().join(this.delimiter);
103
+ if (typeof value === 'string' ? value !== currentValue : value.join(this.delimiter) !== currentValue) {
104
+ this.handleValueOutChange();
113
105
  }
114
106
  }
115
- }, {
116
- key: "componentDidUpdate",
117
- value: function componentDidUpdate(prevProps, prevState) {
118
- var _this2 = this;
119
- var _this$props2 = this.props,
120
- value = _this$props2.value,
121
- errors = _this$props2.errors,
122
- errorIndex = _this$props2.errorIndex,
123
- showErrors = _this$props2.showErrors,
124
- disabled = _this$props2.disabled,
125
- readonly = _this$props2.readonly,
126
- highlightErrorIndex = _this$props2.highlightErrorIndex,
127
- lineProcessing = _this$props2.lineProcessing,
128
- _this$props2$ariaDes = _this$props2['aria-describedby'],
129
- ariaDescribedby = _this$props2$ariaDes === void 0 ? '' : _this$props2$ariaDes;
130
- if (prevProps.value !== value) {
131
- var currentValue = this.getValues().join(this.delimiter);
132
- if (typeof value === 'string' ? value !== currentValue : value.join(this.delimiter) !== currentValue) {
133
- this.handleValueOutChange();
134
- }
135
- }
136
- if (prevProps.showErrors !== showErrors || prevProps.errors !== errors) {
137
- if (showErrors) {
138
- var errorsMap = new Map();
139
- errors.forEach(function (error) {
140
- errorsMap.set(error.lineIndex, error);
141
- });
142
- this.textarea.childNodes.forEach(function (node, index) {
143
- if (node instanceof HTMLParagraphElement) {
144
- var errorItem = errorsMap.get(index);
145
- if (errorItem) {
146
- node.setAttribute('aria-invalid', 'true');
147
- node.dataset.errormessage = errorItem.errorMessage;
148
- } else {
149
- node.removeAttribute('aria-invalid');
150
- node.dataset.errormessage = undefined;
151
- }
152
- }
153
- });
154
- }
155
- this.toggleAriaInvalid(showErrors, errors.length);
156
- if (showErrors === false) {
157
- this.textarea.setAttribute('aria-describedby', ariaDescribedby);
158
- }
159
- }
160
- if (prevProps.errorIndex !== errorIndex && highlightErrorIndex) {
161
- this.handleChangeErrorIndex(errorIndex);
162
- }
163
- if (prevProps.disabled !== disabled || prevProps.readonly !== readonly) {
164
- if (this.isDisabled) {
165
- this.textarea.setAttribute('contenteditable', 'false');
166
- this.removeEventListeners(this.textarea);
167
- } else {
168
- this.textarea.setAttribute('contenteditable', 'true');
169
- this.addEventListeners(this.textarea);
170
- }
171
- if (disabled) {
172
- this.textarea.setAttribute('tabindex', '-1');
173
- } else {
174
- this.textarea.setAttribute('tabindex', '0');
175
- }
176
- }
177
- var keyboardLineIndex = this.state.keyboardLineIndex;
178
- if (prevState.keyboardLineIndex !== -1 && prevState.keyboardLineIndex !== keyboardLineIndex) {
179
- if (lineProcessing) {
180
- var _lines$prevState$keyb;
181
- var lines = this.getValues();
182
- var newValue = lineProcessing((_lines$prevState$keyb = lines[prevState.keyboardLineIndex]) !== null && _lines$prevState$keyb !== void 0 ? _lines$prevState$keyb : '', lines);
183
- var newValueTextNode = document.createTextNode(newValue);
184
- var paragraph = this.textarea.childNodes.item(prevState.keyboardLineIndex);
185
- if (paragraph instanceof HTMLParagraphElement) {
186
- if (newValue === '') {
187
- paragraph.innerHTML = this.emptyLineValue;
107
+ if (prevProps.showErrors !== showErrors || prevProps.errors !== errors) {
108
+ if (showErrors) {
109
+ const errorsMap = new Map();
110
+ errors.forEach(error => {
111
+ errorsMap.set(error.lineIndex, error);
112
+ });
113
+ this.textarea.childNodes.forEach((node, index) => {
114
+ if (node instanceof HTMLParagraphElement) {
115
+ const errorItem = errorsMap.get(index);
116
+ if (errorItem) {
117
+ node.setAttribute('aria-invalid', 'true');
118
+ node.dataset.errormessage = errorItem.errorMessage;
188
119
  } else {
189
- paragraph.replaceChild(newValueTextNode, paragraph.childNodes.item(0));
120
+ node.removeAttribute('aria-invalid');
121
+ node.dataset.errormessage = undefined;
190
122
  }
191
123
  }
192
- this.validateLine(paragraph);
193
- setTimeout(function () {
194
- var newNode = _this2.textarea.childNodes.item(keyboardLineIndex);
195
- if (newNode) {
196
- _this2.setErrorIndex(newNode);
197
- }
198
- }, 0); // need this timeout to update errorIndex to the new (usually empty) line
199
- }
200
- if (!showErrors) {
201
- this.recalculateErrors();
202
- }
203
- this.recalculateLinesCount();
204
- this.asProps.onChangeLineIndex(keyboardLineIndex);
205
- }
206
- }
207
- }, {
208
- key: "componentWillUnmount",
209
- value: function componentWillUnmount() {
210
- this.removeEventListeners(this.textarea);
211
- this.observer.disconnect();
212
- }
213
- }, {
214
- key: "isDisabled",
215
- get: function get() {
216
- var _this$asProps = this.asProps,
217
- disabled = _this$asProps.disabled,
218
- readonly = _this$asProps.readonly;
219
- return Boolean(disabled || readonly);
220
- }
221
- }, {
222
- key: "popperDescribedId",
223
- get: function get() {
224
- var uid = this.asProps.uid;
225
- return "bulk-textarea-".concat(uid, "-popper-describedby");
226
- }
227
- }, {
228
- key: "errorMessage",
229
- get: function get() {
230
- var _errorItem$errorMessa, _errorItem, _errorItem2;
231
- var _this$asProps2 = this.asProps,
232
- errors = _this$asProps2.errors,
233
- errorIndex = _this$asProps2.errorIndex,
234
- commonErrorMessage = _this$asProps2.commonErrorMessage,
235
- prevError = _this$asProps2.prevError;
236
- var _this$state = this.state,
237
- mouseLineIndex = _this$state.mouseLineIndex,
238
- keyboardLineIndex = _this$state.keyboardLineIndex;
239
- var currentLineIndex = this.errorByInteraction === 'keyboard' ? keyboardLineIndex : this.errorByInteraction === 'mouse' ? mouseLineIndex : -1;
240
- var errorItem = errors[errorIndex];
241
- if (currentLineIndex !== -1) {
242
- errorItem = errors.find(function (e) {
243
- return (e === null || e === void 0 ? void 0 : e.lineIndex) === currentLineIndex;
244
124
  });
245
125
  }
246
- var errorMessage = errors.length === 0 && !prevError // show any errors only if there are at least one error
247
- ? null : (_errorItem$errorMessa = (_errorItem = errorItem) === null || _errorItem === void 0 ? void 0 : _errorItem.errorMessage) !== null && _errorItem$errorMessa !== void 0 ? _errorItem$errorMessa : commonErrorMessage === '' || errors.length === 0 ? prevError === null || prevError === void 0 ? void 0 : prevError.errorMessage : commonErrorMessage;
248
- var isCommonError = !((_errorItem2 = errorItem) !== null && _errorItem2 !== void 0 && _errorItem2.errorMessage) && (commonErrorMessage === '' || errors.length === 0 ? !(prevError !== null && prevError !== void 0 && prevError.errorMessage) : true);
249
- return {
250
- errorMessage: errorMessage,
251
- isCommonError: isCommonError
252
- };
253
- }
254
- }, {
255
- key: "createContentEditableElement",
256
- value: function createContentEditableElement(props) {
257
- var textarea = document.createElement('div');
258
- textarea.setAttribute('contentEditable', props.disabled || props.readonly ? 'false' : 'true');
259
- textarea.setAttribute('role', 'textbox');
260
- textarea.setAttribute('classname', 'editable');
261
- if (props.id) {
262
- textarea.setAttribute('id', props.id);
126
+ this.toggleAriaInvalid(showErrors, errors.length);
127
+ if (showErrors === false) {
128
+ this.textarea.setAttribute('aria-describedby', ariaDescribedby);
263
129
  }
264
- if (props.placeholder) {
265
- textarea.setAttribute('placeholder', props.placeholder);
266
- }
267
- var _extractAriaProps = extractAriaProps(props),
268
- extractedAriaProps = _extractAriaProps.extractedAriaProps;
269
- for (var key in extractedAriaProps) {
270
- var ariaProp = props[key];
271
- if (ariaProp) {
272
- textarea.setAttribute(key, ariaProp);
273
- }
274
- }
275
- if (!props.disabled) {
276
- textarea.setAttribute('tabIndex', '0');
130
+ }
131
+ if (prevProps.errorIndex !== errorIndex && highlightErrorIndex) {
132
+ this.handleChangeErrorIndex(errorIndex);
133
+ }
134
+ if (prevProps.disabled !== disabled || prevProps.readonly !== readonly) {
135
+ if (this.isDisabled) {
136
+ this.textarea.setAttribute('contenteditable', 'false');
137
+ this.removeEventListeners(this.textarea);
277
138
  } else {
278
- textarea.setAttribute('tabIndex', '-1');
139
+ this.textarea.setAttribute('contenteditable', 'true');
140
+ this.addEventListeners(this.textarea);
279
141
  }
280
- if (!props.disabled && !props.readonly) {
281
- this.addEventListeners(textarea);
142
+ if (disabled) {
143
+ this.textarea.setAttribute('tabindex', '-1');
282
144
  } else {
283
- textarea.addEventListener('keydown', this.handleSelectAll.bind(this));
145
+ this.textarea.setAttribute('tabindex', '0');
284
146
  }
285
- return textarea;
286
147
  }
287
- }, {
288
- key: "handleValueOutChange",
289
- value: function handleValueOutChange() {
290
- var _this$props3 = this.props,
291
- value = _this$props3.value,
292
- onChangeLinesCount = _this$props3.onChangeLinesCount;
293
- if (value === '') {
294
- this.textarea.textContent = '';
295
- onChangeLinesCount(0);
296
- } else {
297
- var _this$textarea;
298
- var listOfNodes = this.prepareNodesForPaste(value);
299
- (_this$textarea = this.textarea).replaceChildren.apply(_this$textarea, _toConsumableArray(listOfNodes));
300
- this.recalculateLinesCount();
148
+ const {
149
+ keyboardLineIndex
150
+ } = this.state;
151
+ if (prevState.keyboardLineIndex !== -1 && prevState.keyboardLineIndex !== keyboardLineIndex) {
152
+ if (lineProcessing) {
153
+ const lines = this.getValues();
154
+ const newValue = lineProcessing(lines[prevState.keyboardLineIndex] ?? '', lines);
155
+ const newValueTextNode = document.createTextNode(newValue);
156
+ const paragraph = this.textarea.childNodes.item(prevState.keyboardLineIndex);
157
+ if (paragraph instanceof HTMLParagraphElement) {
158
+ if (newValue === '') {
159
+ paragraph.innerHTML = this.emptyLineValue;
160
+ } else {
161
+ paragraph.replaceChild(newValueTextNode, paragraph.childNodes.item(0));
162
+ }
163
+ }
164
+ this.validateLine(paragraph);
165
+ setTimeout(() => {
166
+ const newNode = this.textarea.childNodes.item(keyboardLineIndex);
167
+ if (newNode) {
168
+ this.setErrorIndex(newNode);
169
+ }
170
+ }, 0); // need this timeout to update errorIndex to the new (usually empty) line
171
+ }
172
+ if (!showErrors) {
301
173
  this.recalculateErrors();
302
174
  }
175
+ this.recalculateLinesCount();
176
+ this.asProps.onChangeLineIndex(keyboardLineIndex);
303
177
  }
304
- }, {
305
- key: "handleScroll",
306
- value: function handleScroll() {
307
- var _this3 = this;
308
- if (this.scrollingTimeout) {
309
- clearTimeout(this.scrollingTimeout);
310
- }
311
- this.isScrolling = true;
312
- this.scrollingTimeout = window.setTimeout(function () {
313
- _this3.isScrolling = false;
314
- }, 50);
178
+ }
179
+ componentWillUnmount() {
180
+ this.removeEventListeners(this.textarea);
181
+ this.observer.disconnect();
182
+ }
183
+ get isDisabled() {
184
+ const {
185
+ disabled,
186
+ readonly
187
+ } = this.asProps;
188
+ return Boolean(disabled || readonly);
189
+ }
190
+ get popperDescribedId() {
191
+ const {
192
+ uid
193
+ } = this.asProps;
194
+ return `bulk-textarea-${uid}-popper-describedby`;
195
+ }
196
+ get errorMessage() {
197
+ const {
198
+ errors,
199
+ errorIndex,
200
+ commonErrorMessage,
201
+ prevError
202
+ } = this.asProps;
203
+ const {
204
+ mouseLineIndex,
205
+ keyboardLineIndex
206
+ } = this.state;
207
+ const currentLineIndex = this.errorByInteraction === 'keyboard' ? keyboardLineIndex : this.errorByInteraction === 'mouse' ? mouseLineIndex : -1;
208
+ let errorItem = errors[errorIndex];
209
+ if (currentLineIndex !== -1) {
210
+ errorItem = errors.find(e => e?.lineIndex === currentLineIndex);
315
211
  }
316
- }, {
317
- key: "handleMouseDown",
318
- value: function handleMouseDown(event) {
319
- var element = event.target;
320
- if (element instanceof HTMLElement) {
321
- // we need to change keyboardLineIndex, because the caret in real on that current row
322
- this.toggleErrorsPopper('keyboardLineIndex', element);
323
- this.setErrorIndex(element);
324
- }
212
+ const errorMessage = errors.length === 0 && !prevError // show any errors only if there are at least one error
213
+ ? null : errorItem?.errorMessage ?? (commonErrorMessage === '' || errors.length === 0 ? prevError?.errorMessage : commonErrorMessage);
214
+ const isCommonError = !errorItem?.errorMessage && (commonErrorMessage === '' || errors.length === 0 ? !prevError?.errorMessage : true);
215
+ return {
216
+ errorMessage,
217
+ isCommonError
218
+ };
219
+ }
220
+ createContentEditableElement(props) {
221
+ const textarea = document.createElement('div');
222
+ textarea.setAttribute('contentEditable', props.disabled || props.readonly ? 'false' : 'true');
223
+ textarea.setAttribute('role', 'textbox');
224
+ textarea.setAttribute('classname', 'editable');
225
+ if (props.id) {
226
+ textarea.setAttribute('id', props.id);
325
227
  }
326
- }, {
327
- key: "handleMouseMove",
328
- value: function handleMouseMove(event) {
329
- this.errorByInteraction = 'mouse';
330
- var element = event.target;
331
- if (element !== this.textarea) {
332
- if (this.isFocusing || element instanceof HTMLElement && element.getAttribute('aria-invalid') === 'true') {
333
- this.toggleErrorsPopper('mouseLineIndex', element);
334
- } else {
335
- this.setState({
336
- visibleErrorPopper: false
337
- });
338
- }
339
- }
228
+ if (props.placeholder) {
229
+ textarea.setAttribute('placeholder', props.placeholder);
340
230
  }
341
- }, {
342
- key: "handleMouseLeave",
343
- value: function handleMouseLeave() {
344
- if (this.changeTriggerTimeout) {
345
- clearTimeout(this.changeTriggerTimeout);
231
+ const {
232
+ extractedAriaProps
233
+ } = extractAriaProps(props);
234
+ for (const key in extractedAriaProps) {
235
+ const ariaProp = props[key];
236
+ if (ariaProp) {
237
+ textarea.setAttribute(key, ariaProp);
346
238
  }
347
- if (this.isFocusing) {
348
- this.errorByInteraction = 'keyboard';
349
- var rowNode = this.getNodeFromSelection();
350
- this.toggleErrorsPopper('keyboardLineIndex', rowNode, 0);
351
- this.setState({
352
- mouseLineIndex: -1
353
- });
239
+ }
240
+ if (!props.disabled) {
241
+ textarea.setAttribute('tabIndex', '0');
242
+ } else {
243
+ textarea.setAttribute('tabIndex', '-1');
244
+ }
245
+ if (!props.disabled && !props.readonly) {
246
+ this.addEventListeners(textarea);
247
+ } else {
248
+ textarea.addEventListener('keydown', this.handleSelectAll.bind(this));
249
+ }
250
+ return textarea;
251
+ }
252
+ handleValueOutChange() {
253
+ const {
254
+ value,
255
+ onChangeLinesCount
256
+ } = this.props;
257
+ if (value === '') {
258
+ this.textarea.textContent = '';
259
+ onChangeLinesCount(0);
260
+ } else {
261
+ const listOfNodes = this.prepareNodesForPaste(value);
262
+ this.textarea.replaceChildren(...listOfNodes);
263
+ this.recalculateLinesCount();
264
+ this.recalculateErrors();
265
+ }
266
+ }
267
+ handleScroll() {
268
+ if (this.scrollingTimeout) {
269
+ clearTimeout(this.scrollingTimeout);
270
+ }
271
+ this.isScrolling = true;
272
+ this.scrollingTimeout = window.setTimeout(() => {
273
+ this.isScrolling = false;
274
+ }, 50);
275
+ }
276
+ handleMouseDown(event) {
277
+ const element = event.target;
278
+ if (element instanceof HTMLElement) {
279
+ // we need to change keyboardLineIndex, because the caret in real on that current row
280
+ this.toggleErrorsPopper('keyboardLineIndex', element);
281
+ this.setErrorIndex(element);
282
+ }
283
+ }
284
+ handleMouseMove(event) {
285
+ this.errorByInteraction = 'mouse';
286
+ const element = event.target;
287
+ if (element !== this.textarea) {
288
+ if (this.isFocusing || element instanceof HTMLElement && element.getAttribute('aria-invalid') === 'true') {
289
+ this.toggleErrorsPopper('mouseLineIndex', element);
354
290
  } else {
355
291
  this.setState({
356
292
  visibleErrorPopper: false
357
293
  });
358
294
  }
359
295
  }
360
- }, {
361
- key: "handlePaste",
362
- value: function handlePaste(event) {
363
- var _event$clipboardData;
364
- event.preventDefault();
365
- var validateOn = this.asProps.validateOn;
366
- var value = (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.getData('text/plain');
367
- var listOfNodes = value ? this.prepareNodesForPaste(value) : [];
368
- if (listOfNodes.length === 0) return;
369
- var selection = document.getSelection();
370
- if (selection !== null && selection !== void 0 && selection.anchorNode && selection !== null && selection !== void 0 && selection.focusNode) {
371
- var anchorOffset = selection.anchorOffset;
372
- var focusOffset = selection.focusOffset;
373
- var documentPosition = selection.anchorNode.compareDocumentPosition(selection.focusNode);
374
- var direction = this.getSelectionDirection();
375
- var anchorElement = direction === 'forward' ? selection.anchorNode : selection.focusNode;
376
- var focusElement = direction === 'forward' ? selection.focusNode : selection.anchorNode;
377
- var fromOffset = direction === 'forward' ? anchorOffset : focusOffset;
378
- var toOffset = direction === 'forward' ? focusOffset : anchorOffset;
379
- var anchorNode = anchorElement instanceof Text ? anchorElement.parentElement : anchorElement;
380
- var focusNode = focusElement instanceof Text ? focusElement.parentElement : focusElement;
381
- var textNode = null;
382
- var position = null;
383
- if (focusElement === this.textarea) {
384
- var _this$textarea2, _lastNodeToInsert$tex;
385
- (_this$textarea2 = this.textarea).replaceChildren.apply(_this$textarea2, _toConsumableArray(listOfNodes));
386
- var lastNodeToInsert = listOfNodes[listOfNodes.length - 1];
387
- textNode = lastNodeToInsert.childNodes.item(0);
388
- position = ((_lastNodeToInsert$tex = lastNodeToInsert.textContent) !== null && _lastNodeToInsert$tex !== void 0 ? _lastNodeToInsert$tex : '').length;
389
- } else if (focusNode instanceof HTMLParagraphElement && anchorNode instanceof HTMLParagraphElement) {
390
- var _anchorNode$textConte, _anchorNode$textConte2, _focusNode$textConten, _focusNode$textConten2, _firstNodeToInsert$te;
391
- var before = (_anchorNode$textConte = anchorNode === null || anchorNode === void 0 || (_anchorNode$textConte2 = anchorNode.textContent) === null || _anchorNode$textConte2 === void 0 ? void 0 : _anchorNode$textConte2.substring(0, fromOffset)) !== null && _anchorNode$textConte !== void 0 ? _anchorNode$textConte : '';
392
- var after = (_focusNode$textConten = focusNode === null || focusNode === void 0 || (_focusNode$textConten2 = focusNode.textContent) === null || _focusNode$textConten2 === void 0 ? void 0 : _focusNode$textConten2.substring(toOffset)) !== null && _focusNode$textConten !== void 0 ? _focusNode$textConten : '';
393
- var noEmptyLineBefore = before.trim() === '' ? '' : before;
394
- var noEmptyLineAfter = after.trim() === '' ? '' : after;
395
- selection.deleteFromDocument();
396
- if (documentPosition !== 0) {
397
- this.textarea.removeChild(focusNode);
398
- }
399
- var firstNodeToInsert = listOfNodes.splice(0, 1)[0];
400
- var _lastNodeToInsert = listOfNodes[listOfNodes.length - 1];
401
- anchorNode.textContent = noEmptyLineBefore + ((_firstNodeToInsert$te = firstNodeToInsert === null || firstNodeToInsert === void 0 ? void 0 : firstNodeToInsert.textContent) !== null && _firstNodeToInsert$te !== void 0 ? _firstNodeToInsert$te : '');
402
- anchorNode.after.apply(anchorNode, _toConsumableArray(listOfNodes));
403
- if (_lastNodeToInsert) {
404
- var _lastNodeToInsert$tex2, _lastNodeToInsert$tex3;
405
- _lastNodeToInsert.textContent = ((_lastNodeToInsert$tex2 = _lastNodeToInsert.textContent) !== null && _lastNodeToInsert$tex2 !== void 0 ? _lastNodeToInsert$tex2 : '') + noEmptyLineAfter;
406
- textNode = _lastNodeToInsert.childNodes.item(0);
407
- position = ((_lastNodeToInsert$tex3 = _lastNodeToInsert.textContent) !== null && _lastNodeToInsert$tex3 !== void 0 ? _lastNodeToInsert$tex3 : '').length;
408
- this.validateLine(_lastNodeToInsert);
409
- this.setErrorIndex(_lastNodeToInsert);
410
- } else {
411
- var _anchorNode$textConte3, _anchorNode$textConte4;
412
- position = ((_anchorNode$textConte3 = anchorNode.textContent) !== null && _anchorNode$textConte3 !== void 0 ? _anchorNode$textConte3 : '').length;
413
- anchorNode.textContent = ((_anchorNode$textConte4 = anchorNode.textContent) !== null && _anchorNode$textConte4 !== void 0 ? _anchorNode$textConte4 : '') + noEmptyLineAfter;
414
- textNode = anchorNode.childNodes.item(0);
415
- this.validateLine(anchorNode);
416
- this.setErrorIndex(anchorNode);
417
- }
296
+ }
297
+ handleMouseLeave() {
298
+ if (this.changeTriggerTimeout) {
299
+ clearTimeout(this.changeTriggerTimeout);
300
+ }
301
+ if (this.isFocusing) {
302
+ this.errorByInteraction = 'keyboard';
303
+ const rowNode = this.getNodeFromSelection();
304
+ this.toggleErrorsPopper('keyboardLineIndex', rowNode, 0);
305
+ this.setState({
306
+ mouseLineIndex: -1
307
+ });
308
+ } else {
309
+ this.setState({
310
+ visibleErrorPopper: false
311
+ });
312
+ }
313
+ }
314
+ handlePaste(event) {
315
+ event.preventDefault();
316
+ const {
317
+ validateOn
318
+ } = this.asProps;
319
+ const value = event.clipboardData?.getData('text/plain');
320
+ const listOfNodes = value ? this.prepareNodesForPaste(value) : [];
321
+ if (listOfNodes.length === 0) return;
322
+ const selection = document.getSelection();
323
+ if (selection?.anchorNode && selection?.focusNode) {
324
+ const anchorOffset = selection.anchorOffset;
325
+ const focusOffset = selection.focusOffset;
326
+ const documentPosition = selection.anchorNode.compareDocumentPosition(selection.focusNode);
327
+ const direction = this.getSelectionDirection();
328
+ const anchorElement = direction === 'forward' ? selection.anchorNode : selection.focusNode;
329
+ const focusElement = direction === 'forward' ? selection.focusNode : selection.anchorNode;
330
+ const fromOffset = direction === 'forward' ? anchorOffset : focusOffset;
331
+ const toOffset = direction === 'forward' ? focusOffset : anchorOffset;
332
+ const anchorNode = anchorElement instanceof Text ? anchorElement.parentElement : anchorElement;
333
+ const focusNode = focusElement instanceof Text ? focusElement.parentElement : focusElement;
334
+ let textNode = null;
335
+ let position = null;
336
+ if (focusElement === this.textarea) {
337
+ this.textarea.replaceChildren(...listOfNodes);
338
+ const lastNodeToInsert = listOfNodes[listOfNodes.length - 1];
339
+ textNode = lastNodeToInsert.childNodes.item(0);
340
+ position = (lastNodeToInsert.textContent ?? '').length;
341
+ } else if (focusNode instanceof HTMLParagraphElement && anchorNode instanceof HTMLParagraphElement) {
342
+ const before = anchorNode?.textContent?.substring(0, fromOffset) ?? '';
343
+ const after = focusNode?.textContent?.substring(toOffset) ?? '';
344
+ const noEmptyLineBefore = before.trim() === '' ? '' : before;
345
+ const noEmptyLineAfter = after.trim() === '' ? '' : after;
346
+ selection.deleteFromDocument();
347
+ if (documentPosition !== 0) {
348
+ this.textarea.removeChild(focusNode);
418
349
  }
419
- if (textNode instanceof Text) {
420
- this.setSelection(textNode, position !== null && position !== void 0 ? position : 1, position !== null && position !== void 0 ? position : 1);
421
- this.toggleErrorsPopper('keyboardLineIndex', textNode.parentNode);
350
+ const firstNodeToInsert = listOfNodes.splice(0, 1)[0];
351
+ const lastNodeToInsert = listOfNodes[listOfNodes.length - 1];
352
+ anchorNode.textContent = noEmptyLineBefore + (firstNodeToInsert?.textContent ?? '');
353
+ anchorNode.after(...listOfNodes);
354
+ if (lastNodeToInsert) {
355
+ lastNodeToInsert.textContent = (lastNodeToInsert.textContent ?? '') + noEmptyLineAfter;
356
+ textNode = lastNodeToInsert.childNodes.item(0);
357
+ position = (lastNodeToInsert.textContent ?? '').length;
358
+ this.validateLine(lastNodeToInsert);
359
+ this.setErrorIndex(lastNodeToInsert);
422
360
  } else {
423
- var _textNode;
424
- // eslint-disable-next-line no-console
425
- console.warn('incorrect child type', textNode, (_textNode = textNode) === null || _textNode === void 0 ? void 0 : _textNode.parentNode);
361
+ position = (anchorNode.textContent ?? '').length;
362
+ anchorNode.textContent = (anchorNode.textContent ?? '') + noEmptyLineAfter;
363
+ textNode = anchorNode.childNodes.item(0);
364
+ this.validateLine(anchorNode);
365
+ this.setErrorIndex(anchorNode);
426
366
  }
427
367
  }
428
- this.recalculateLinesCount();
429
- if (validateOn.includes('paste') || this.asProps.showErrors) {
430
- this.recalculateErrors();
368
+ if (textNode instanceof Text) {
369
+ this.setSelection(textNode, position ?? 1, position ?? 1);
370
+ this.toggleErrorsPopper('keyboardLineIndex', textNode.parentNode);
371
+ } else {
372
+ // eslint-disable-next-line no-console
373
+ console.warn('incorrect child type', textNode, textNode?.parentNode);
431
374
  }
432
375
  }
433
- }, {
434
- key: "handleChange",
435
- value: function handleChange(event) {
436
- var target = event.target;
437
- if (target instanceof HTMLDivElement && event instanceof InputEvent) {
438
- var _firstNode$textConten2;
439
- var nodes = this.textarea.childNodes;
440
- var firstNode = nodes.item(0);
441
- var secondNode = nodes.item(1);
442
- var selection = document.getSelection();
443
- if (firstNode instanceof Text) {
444
- var _firstNode$textConten;
445
- var nodeText = (_firstNode$textConten = firstNode.textContent) !== null && _firstNode$textConten !== void 0 ? _firstNode$textConten : '';
446
- var firstRow = document.createElement('p');
447
- var text = document.createTextNode(nodeText);
448
- firstRow.append(text);
449
- firstNode.replaceWith(firstRow);
450
- selection === null || selection === void 0 || selection.setPosition(firstRow, nodeText.length);
451
- } else if (!firstNode || firstNode instanceof HTMLBRElement && nodes.length === 1) {
376
+ this.recalculateLinesCount();
377
+ if (validateOn.includes('paste') || this.asProps.showErrors) {
378
+ this.recalculateErrors();
379
+ }
380
+ }
381
+ handleChange(event) {
382
+ const target = event.target;
383
+ if (target instanceof HTMLDivElement && event instanceof InputEvent) {
384
+ const nodes = this.textarea.childNodes;
385
+ const firstNode = nodes.item(0);
386
+ const secondNode = nodes.item(1);
387
+ const selection = document.getSelection();
388
+ if (firstNode instanceof Text) {
389
+ const nodeText = firstNode.textContent ?? '';
390
+ const firstRow = document.createElement('p');
391
+ const text = document.createTextNode(nodeText);
392
+ firstRow.append(text);
393
+ firstNode.replaceWith(firstRow);
394
+ selection?.setPosition(firstRow, nodeText.length);
395
+ } else if (!firstNode || firstNode instanceof HTMLBRElement && nodes.length === 1) {
396
+ this.textarea.textContent = '';
397
+ this.setState({
398
+ keyboardLineIndex: 0
399
+ });
400
+ } else if (firstNode instanceof HTMLParagraphElement && !firstNode.textContent?.trim()) {
401
+ if (nodes.length <= 1 || secondNode instanceof HTMLBRElement) {
452
402
  this.textarea.textContent = '';
453
403
  this.setState({
454
404
  keyboardLineIndex: 0
455
405
  });
456
- } else if (firstNode instanceof HTMLParagraphElement && !((_firstNode$textConten2 = firstNode.textContent) !== null && _firstNode$textConten2 !== void 0 && _firstNode$textConten2.trim())) {
457
- if (nodes.length <= 1 || secondNode instanceof HTMLBRElement) {
458
- this.textarea.textContent = '';
459
- this.setState({
460
- keyboardLineIndex: 0
461
- });
462
- }
463
406
  }
464
- var maxDeep = 10;
465
- var rowNode = selection === null || selection === void 0 ? void 0 : selection.focusNode;
466
- while (((_rowNode = rowNode) === null || _rowNode === void 0 ? void 0 : _rowNode.parentNode) !== this.textarea && maxDeep > 0) {
467
- var _rowNode, _rowNode2;
468
- rowNode = (_rowNode2 = rowNode) === null || _rowNode2 === void 0 ? void 0 : _rowNode2.parentNode;
469
- maxDeep--;
407
+ }
408
+ let maxDeep = 10;
409
+ let rowNode = selection?.focusNode;
410
+ while (rowNode?.parentNode !== this.textarea && maxDeep > 0) {
411
+ rowNode = rowNode?.parentNode;
412
+ maxDeep--;
413
+ }
414
+ if (rowNode instanceof HTMLParagraphElement) {
415
+ const childNodes = rowNode.childNodes;
416
+ const textContent = rowNode.textContent ?? '';
417
+ if (childNodes.length > 1) {
418
+ const offset = childNodes.item(0).textContent?.length;
419
+ rowNode.textContent = textContent;
420
+ if (offset) {
421
+ this.setSelection(rowNode.childNodes.item(0), offset, offset);
422
+ }
470
423
  }
471
- if (rowNode instanceof HTMLParagraphElement) {
472
- var _rowNode$textContent, _this$popper;
473
- var childNodes = rowNode.childNodes;
474
- var textContent = (_rowNode$textContent = rowNode.textContent) !== null && _rowNode$textContent !== void 0 ? _rowNode$textContent : '';
475
- if (childNodes.length > 1) {
476
- var _childNodes$item$text;
477
- var offset = (_childNodes$item$text = childNodes.item(0).textContent) === null || _childNodes$item$text === void 0 ? void 0 : _childNodes$item$text.length;
478
- rowNode.textContent = textContent;
424
+ if (textContent.length > 0) {
425
+ const firstSymbol = textContent.at(0);
426
+ const lastSymbol = textContent.at(textContent.length - 1);
427
+ if (firstSymbol === this.getEmptyParagraph().textContent || lastSymbol === this.getEmptyParagraph().textContent) {
428
+ let offset = null;
429
+ if (firstSymbol === this.getEmptyParagraph().textContent) {
430
+ rowNode.textContent = textContent.substring(1);
431
+ offset = event.inputType === 'deleteContentBackward' || event.inputType === 'deleteContentForward' ? 0 : rowNode.textContent.length;
432
+ } else if (lastSymbol === this.getEmptyParagraph().textContent) {
433
+ rowNode.textContent = textContent.substring(0, textContent.length - 1);
434
+ offset = rowNode.textContent.length;
435
+ }
479
436
  if (offset) {
480
437
  this.setSelection(rowNode.childNodes.item(0), offset, offset);
481
438
  }
482
439
  }
483
- if (textContent.length > 0) {
484
- var firstSymbol = textContent.at(0);
485
- var lastSymbol = textContent.at(textContent.length - 1);
486
- if (firstSymbol === this.getEmptyParagraph().textContent || lastSymbol === this.getEmptyParagraph().textContent) {
487
- var _offset = null;
488
- if (firstSymbol === this.getEmptyParagraph().textContent) {
489
- rowNode.textContent = textContent.substring(1);
490
- _offset = event.inputType === 'deleteContentBackward' || event.inputType === 'deleteContentForward' ? 0 : rowNode.textContent.length;
491
- } else if (lastSymbol === this.getEmptyParagraph().textContent) {
492
- rowNode.textContent = textContent.substring(0, textContent.length - 1);
493
- _offset = rowNode.textContent.length;
494
- }
495
- if (_offset) {
496
- this.setSelection(rowNode.childNodes.item(0), _offset, _offset);
497
- }
498
- }
499
- } else if (childNodes.length === 1 && childNodes[0] instanceof HTMLBRElement) {
500
- rowNode.innerHTML = this.emptyLineValue;
501
- }
502
- var _this$asProps3 = this.asProps,
503
- errors = _this$asProps3.errors,
504
- showErrors = _this$asProps3.showErrors;
505
- var isValid = this.validateLine(rowNode);
506
- this.recalculateErrors();
507
- this.setErrorIndex(rowNode);
508
- if (!isValid && showErrors) {
509
- this.toggleErrorsPopper('keyboardLineIndex', rowNode, 0);
440
+ } else if (childNodes.length === 1 && childNodes[0] instanceof HTMLBRElement) {
441
+ rowNode.innerHTML = this.emptyLineValue;
442
+ }
443
+ const {
444
+ errors,
445
+ showErrors
446
+ } = this.asProps;
447
+ const isValid = this.validateLine(rowNode);
448
+ this.recalculateErrors();
449
+ this.setErrorIndex(rowNode);
450
+ if (!isValid && showErrors) {
451
+ this.toggleErrorsPopper('keyboardLineIndex', rowNode, 0);
452
+ }
453
+ const trigger = !isValid || isValid && errors.length === 1 && errors[0].lineNode === rowNode ? rowNode : this.textarea;
454
+ if (showErrors && this.popper?.current?.state.elements.reference !== trigger) {
455
+ if (this.shouldChangePopperTrigger(trigger)) {
456
+ this.setPopperTrigger?.(trigger);
457
+ } else {
458
+ this.setState({
459
+ visibleErrorPopper: false
460
+ });
510
461
  }
511
- var trigger = !isValid || isValid && errors.length === 1 && errors[0].lineNode === rowNode ? rowNode : this.textarea;
512
- if (showErrors && ((_this$popper = this.popper) === null || _this$popper === void 0 || (_this$popper = _this$popper.current) === null || _this$popper === void 0 ? void 0 : _this$popper.state.elements.reference) !== trigger) {
513
- if (this.shouldChangePopperTrigger(trigger)) {
514
- var _this$setPopperTrigge;
515
- (_this$setPopperTrigge = this.setPopperTrigger) === null || _this$setPopperTrigge === void 0 || _this$setPopperTrigge.call(this, trigger);
516
- } else {
517
- this.setState({
518
- visibleErrorPopper: false
519
- });
520
- }
462
+ }
463
+ } else if (rowNode === null) {
464
+ this.setPopperTrigger?.(this.textarea);
465
+ if (selection?.focusNode === this.textarea && this.textarea.childNodes.length > 1) {
466
+ const nodeIndex = selection.focusOffset;
467
+ const emptyParagraph = this.textarea.childNodes.item(nodeIndex - 1);
468
+ const emptyBr = this.textarea.childNodes.item(nodeIndex);
469
+ this.textarea.removeChild(emptyBr);
470
+ if (emptyParagraph instanceof HTMLParagraphElement) {
471
+ emptyParagraph.innerHTML = this.emptyLineValue;
521
472
  }
522
- } else if (rowNode === null) {
523
- var _this$setPopperTrigge2;
524
- (_this$setPopperTrigge2 = this.setPopperTrigger) === null || _this$setPopperTrigge2 === void 0 || _this$setPopperTrigge2.call(this, this.textarea);
525
- if ((selection === null || selection === void 0 ? void 0 : selection.focusNode) === this.textarea && this.textarea.childNodes.length > 1) {
526
- var nodeIndex = selection.focusOffset;
527
- var emptyParagraph = this.textarea.childNodes.item(nodeIndex - 1);
528
- var emptyBr = this.textarea.childNodes.item(nodeIndex);
529
- this.textarea.removeChild(emptyBr);
530
- if (emptyParagraph instanceof HTMLParagraphElement) {
531
- emptyParagraph.innerHTML = this.emptyLineValue;
532
- }
533
- if (emptyParagraph) {
534
- this.setSelection(emptyParagraph, 0, 0);
535
- }
536
- } else {
537
- this.setSelection(this.textarea, 0, 0);
473
+ if (emptyParagraph) {
474
+ this.setSelection(emptyParagraph, 0, 0);
538
475
  }
476
+ } else {
477
+ this.setSelection(this.textarea, 0, 0);
539
478
  }
540
- this.recalculateLinesCount();
541
479
  }
480
+ this.recalculateLinesCount();
542
481
  }
543
- }, {
544
- key: "handleFocus",
545
- value: function handleFocus() {
546
- this.isFocusing = true;
547
- this.errorByInteraction = 'keyboard';
548
- if (this.asProps.showErrors) {
549
- this.toggleErrorsPopperByKeyboard(150);
550
- } else {
551
- this.toggleErrorsPopper('keyboardLineIndex', this.textarea);
552
- }
482
+ }
483
+ handleFocus() {
484
+ this.isFocusing = true;
485
+ this.errorByInteraction = 'keyboard';
486
+ if (this.asProps.showErrors) {
487
+ this.toggleErrorsPopperByKeyboard(150);
488
+ } else {
489
+ this.toggleErrorsPopper('keyboardLineIndex', this.textarea);
553
490
  }
554
- }, {
555
- key: "handleBlur",
556
- value: function handleBlur(event) {
557
- var _this4 = this;
558
- this.isFocusing = false;
491
+ }
492
+ handleBlur(event) {
493
+ this.isFocusing = false;
494
+ this.setState({
495
+ visibleErrorPopper: false
496
+ });
497
+ const {
498
+ validateOn,
499
+ onBlur,
500
+ value
501
+ } = this.asProps;
502
+ if (validateOn.includes('blur')) {
503
+ this.recalculateErrors();
504
+ }
505
+ const valueToChange = typeof value === 'string' ? this.getValues().join(this.delimiter) : this.getValues();
506
+ onBlur(valueToChange, event);
507
+ setTimeout(() => {
559
508
  this.setState({
560
- visibleErrorPopper: false
509
+ keyboardLineIndex: -1
561
510
  });
562
- var _this$asProps4 = this.asProps,
563
- validateOn = _this$asProps4.validateOn,
564
- onBlur = _this$asProps4.onBlur,
565
- value = _this$asProps4.value;
566
- if (validateOn.includes('blur')) {
567
- this.recalculateErrors();
511
+ }, 200);
512
+ }
513
+ handleKeyDown(event) {
514
+ this.errorByInteraction = 'keyboard';
515
+ const {
516
+ linesDelimiters
517
+ } = this.asProps;
518
+ const currentNode = this.getNodeFromSelection();
519
+ if (event.key === 'Enter' || linesDelimiters?.includes(event.key)) {
520
+ if (currentNode === this.textarea) {
521
+ event.preventDefault();
568
522
  }
569
- var valueToChange = typeof value === 'string' ? this.getValues().join(this.delimiter) : this.getValues();
570
- onBlur(valueToChange, event);
571
- setTimeout(function () {
572
- _this4.setState({
573
- keyboardLineIndex: -1
574
- });
575
- }, 200);
576
- }
577
- }, {
578
- key: "handleKeyDown",
579
- value: function handleKeyDown(event) {
580
- var _this5 = this;
581
- this.errorByInteraction = 'keyboard';
582
- var linesDelimiters = this.asProps.linesDelimiters;
583
- var currentNode = this.getNodeFromSelection();
584
- if (event.key === 'Enter' || linesDelimiters !== null && linesDelimiters !== void 0 && linesDelimiters.includes(event.key)) {
585
- if (currentNode === this.textarea) {
523
+ if (currentNode instanceof HTMLParagraphElement) {
524
+ const currentRowValue = currentNode.textContent?.trim();
525
+ if (!currentRowValue) {
586
526
  event.preventDefault();
587
- }
588
- if (currentNode instanceof HTMLParagraphElement) {
589
- var _currentNode$textCont;
590
- var currentRowValue = (_currentNode$textCont = currentNode.textContent) === null || _currentNode$textCont === void 0 ? void 0 : _currentNode$textCont.trim();
591
- if (!currentRowValue) {
592
- event.preventDefault();
593
- } else {
594
- var _selection$focusNode, _selectionNode$textCo, _currentNode$textCont2, _row$textContent;
595
- event.preventDefault();
596
- var selection = document.getSelection();
597
- var selectionNode = (selection === null || selection === void 0 ? void 0 : selection.focusNode) instanceof Text ? selection.focusNode : selection === null || selection === void 0 || (_selection$focusNode = selection.focusNode) === null || _selection$focusNode === void 0 ? void 0 : _selection$focusNode.childNodes.item(0);
598
- var selectionOffset = selection === null || selection === void 0 ? void 0 : selection.focusOffset;
599
- var newRowValue = '';
600
- if (selectionNode instanceof Text && selectionOffset !== undefined && selectionOffset !== ((_selectionNode$textCo = selectionNode.textContent) === null || _selectionNode$textCo === void 0 ? void 0 : _selectionNode$textCo.length)) {
601
- var _selectionNode$textCo2, _selectionNode$textCo3;
602
- newRowValue = (_selectionNode$textCo2 = (_selectionNode$textCo3 = selectionNode.textContent) === null || _selectionNode$textCo3 === void 0 ? void 0 : _selectionNode$textCo3.substring(selectionOffset)) !== null && _selectionNode$textCo2 !== void 0 ? _selectionNode$textCo2 : this.emptyLineValue;
603
- if (selectionNode.textContent) {
604
- selectionNode.textContent = selectionNode.textContent.substring(0, selectionOffset);
605
- }
606
- }
607
- if (((_currentNode$textCont2 = currentNode.textContent) === null || _currentNode$textCont2 === void 0 ? void 0 : _currentNode$textCont2.trim()) === '') {
608
- currentNode.innerHTML = this.emptyLineValue;
609
- }
610
- var row = document.createElement('p');
611
- if (newRowValue) {
612
- row.textContent = newRowValue;
613
- } else {
614
- row.innerHTML = this.emptyLineValue;
615
- }
616
- currentNode.after(row);
617
- this.setSelection(row, 0, 0);
618
- this.validateLine(currentNode);
619
- this.validateLine(row);
620
- if (currentNode.previousSibling) {
621
- this.validateLine(currentNode.previousSibling);
622
- }
623
- this.setErrorIndex(row);
624
- if (((_row$textContent = row.textContent) === null || _row$textContent === void 0 ? void 0 : _row$textContent.trim()) !== '') {
625
- this.recalculateLinesCount();
527
+ } else {
528
+ event.preventDefault();
529
+ const selection = document.getSelection();
530
+ const selectionNode = selection?.focusNode instanceof Text ? selection.focusNode : selection?.focusNode?.childNodes.item(0);
531
+ const selectionOffset = selection?.focusOffset;
532
+ let newRowValue = '';
533
+ if (selectionNode instanceof Text && selectionOffset !== undefined && selectionOffset !== selectionNode.textContent?.length) {
534
+ newRowValue = selectionNode.textContent?.substring(selectionOffset) ?? this.emptyLineValue;
535
+ if (selectionNode.textContent) {
536
+ selectionNode.textContent = selectionNode.textContent.substring(0, selectionOffset);
626
537
  }
627
- setTimeout(function () {
628
- _this5.recalculateErrors();
629
- }, 0);
630
- this.toggleErrorsPopperByKeyboard(0);
631
538
  }
539
+ if (currentNode.textContent?.trim() === '') {
540
+ currentNode.innerHTML = this.emptyLineValue;
541
+ }
542
+ const row = document.createElement('p');
543
+ if (newRowValue) {
544
+ row.textContent = newRowValue;
545
+ } else {
546
+ row.innerHTML = this.emptyLineValue;
547
+ }
548
+ currentNode.after(row);
549
+ this.setSelection(row, 0, 0);
550
+ this.validateLine(currentNode);
551
+ this.validateLine(row);
552
+ if (currentNode.previousSibling) {
553
+ this.validateLine(currentNode.previousSibling);
554
+ }
555
+ this.setErrorIndex(row);
556
+ if (row.textContent?.trim() !== '') {
557
+ this.recalculateLinesCount();
558
+ }
559
+ setTimeout(() => {
560
+ this.recalculateErrors();
561
+ }, 0);
562
+ this.toggleErrorsPopperByKeyboard(0);
632
563
  }
633
- } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
634
- if (currentNode instanceof HTMLParagraphElement) {
635
- this.handleCursorMovement(currentNode, event);
636
- }
637
- this.toggleErrorsPopperByKeyboard(200);
638
- } else if (this.isDeleteKey(event) && currentNode instanceof HTMLParagraphElement) {
639
- var _currentNode$textCont3;
640
- if (((_currentNode$textCont3 = currentNode.textContent) === null || _currentNode$textCont3 === void 0 ? void 0 : _currentNode$textCont3.trim()) === '' && !this.isRangeSelection()) {
641
- // Backspace on empty row
642
- var prevNode = currentNode.previousSibling;
643
- if (prevNode instanceof HTMLParagraphElement) {
644
- var _prevNode$textContent;
645
- event.preventDefault();
646
- this.textarea.removeChild(currentNode);
647
- this.toggleErrorsPopperByKeyboard(0);
648
- if (((_prevNode$textContent = prevNode.textContent) === null || _prevNode$textContent === void 0 ? void 0 : _prevNode$textContent.trim()) === '' && prevNode.previousSibling === null && this.textarea.childNodes.length === 1) {
649
- this.textarea.textContent = '';
650
- this.setSelection(this.textarea, 0, 0);
564
+ }
565
+ } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
566
+ if (currentNode instanceof HTMLParagraphElement) {
567
+ this.handleCursorMovement(currentNode, event);
568
+ }
569
+ this.toggleErrorsPopperByKeyboard(200);
570
+ } else if (this.isDeleteKey(event) && currentNode instanceof HTMLParagraphElement) {
571
+ if (currentNode.textContent?.trim() === '' && !this.isRangeSelection()) {
572
+ // Backspace on empty row
573
+ const prevNode = currentNode.previousSibling;
574
+ if (prevNode instanceof HTMLParagraphElement) {
575
+ event.preventDefault();
576
+ this.textarea.removeChild(currentNode);
577
+ this.toggleErrorsPopperByKeyboard(0);
578
+ if (prevNode.textContent?.trim() === '' && prevNode.previousSibling === null && this.textarea.childNodes.length === 1) {
579
+ this.textarea.textContent = '';
580
+ this.setSelection(this.textarea, 0, 0);
581
+ } else {
582
+ if (prevNode instanceof HTMLParagraphElement) {
583
+ const text = prevNode.childNodes.item(0);
584
+ const offset = text.textContent?.length ?? 0;
585
+ this.setSelection(text, offset, offset);
651
586
  } else {
652
- if (prevNode instanceof HTMLParagraphElement) {
653
- var _text$textContent$len, _text$textContent;
654
- var text = prevNode.childNodes.item(0);
655
- var offset = (_text$textContent$len = (_text$textContent = text.textContent) === null || _text$textContent === void 0 ? void 0 : _text$textContent.length) !== null && _text$textContent$len !== void 0 ? _text$textContent$len : 0;
656
- this.setSelection(text, offset, offset);
657
- } else {
658
- // eslint-disable-next-line no-console
659
- console.warn('incorrect prevNode type', prevNode);
660
- }
587
+ // eslint-disable-next-line no-console
588
+ console.warn('incorrect prevNode type', prevNode);
661
589
  }
662
- setTimeout(function () {
663
- _this5.recalculateErrors();
664
- }, 0);
665
- this.toggleErrorsPopperByKeyboard(0);
666
590
  }
667
- } else if (this.isRangeSelection()) {
668
- var _currentNode$textCont4, _focusElement$parentN, _anchorElement$parent, _focusElement$parentN2;
669
- var _selection = document.getSelection();
670
- var direction = this.getSelectionDirection();
671
- var anchorElement = direction === 'backward' ? _selection === null || _selection === void 0 ? void 0 : _selection.focusNode : _selection === null || _selection === void 0 ? void 0 : _selection.anchorNode;
672
- var focusElement = direction === 'backward' ? _selection === null || _selection === void 0 ? void 0 : _selection.anchorNode : _selection === null || _selection === void 0 ? void 0 : _selection.focusNode;
673
- var anchorOffset = direction === 'backward' ? _selection === null || _selection === void 0 ? void 0 : _selection.focusOffset : _selection === null || _selection === void 0 ? void 0 : _selection.anchorOffset;
674
- var focusOffset = direction === 'backward' ? _selection === null || _selection === void 0 ? void 0 : _selection.anchorOffset : _selection === null || _selection === void 0 ? void 0 : _selection.focusOffset;
591
+ setTimeout(() => {
592
+ this.recalculateErrors();
593
+ }, 0);
594
+ this.toggleErrorsPopperByKeyboard(0);
595
+ }
596
+ } else if (this.isRangeSelection()) {
597
+ const selection = document.getSelection();
598
+ const direction = this.getSelectionDirection();
599
+ const anchorElement = direction === 'backward' ? selection?.focusNode : selection?.anchorNode;
600
+ const focusElement = direction === 'backward' ? selection?.anchorNode : selection?.focusNode;
601
+ const anchorOffset = direction === 'backward' ? selection?.focusOffset : selection?.anchorOffset;
602
+ const focusOffset = direction === 'backward' ? selection?.anchorOffset : selection?.focusOffset;
675
603
 
676
- // Backspace on selected full row
677
- if (anchorElement === focusElement && anchorOffset === 0 && (focusElement === currentNode && focusOffset === 1 || focusOffset === ((_currentNode$textCont4 = currentNode.textContent) === null || _currentNode$textCont4 === void 0 ? void 0 : _currentNode$textCont4.length))) {
678
- event.preventDefault();
679
- var anchorParagraph = anchorElement === null || anchorElement === void 0 ? void 0 : anchorElement.parentElement;
680
- var focusParagraph = focusElement === null || focusElement === void 0 ? void 0 : focusElement.parentElement;
681
- var childNodes = this.textarea.childNodes;
682
- if (anchorParagraph === childNodes.item(0) && focusParagraph === childNodes.item(childNodes.length - 1)) {
683
- this.textarea.textContent = '';
684
- this.setSelection(this.textarea, 0, 0);
685
- } else {
686
- currentNode.innerHTML = this.emptyLineValue;
687
- this.validateLine(currentNode);
688
- }
689
- this.setErrorIndex(currentNode);
690
- this.recalculateLinesCount();
691
- setTimeout(function () {
692
- _this5.recalculateErrors();
693
- }, 0);
694
- this.toggleErrorsPopperByKeyboard(0);
695
- } else if (focusElement !== anchorElement && focusElement instanceof Text && anchorElement instanceof Text && (focusElement === null || focusElement === void 0 ? void 0 : focusElement.textContent) === (focusElement === null || focusElement === void 0 || (_focusElement$parentN = focusElement.parentNode) === null || _focusElement$parentN === void 0 ? void 0 : _focusElement$parentN.textContent) && (anchorElement === null || anchorElement === void 0 ? void 0 : anchorElement.textContent) === (anchorElement === null || anchorElement === void 0 || (_anchorElement$parent = anchorElement.parentNode) === null || _anchorElement$parent === void 0 ? void 0 : _anchorElement$parent.textContent) && anchorOffset === 0 && focusOffset === (focusElement === null || focusElement === void 0 || (_focusElement$parentN2 = focusElement.parentNode) === null || _focusElement$parentN2 === void 0 || (_focusElement$parentN2 = _focusElement$parentN2.textContent) === null || _focusElement$parentN2 === void 0 ? void 0 : _focusElement$parentN2.length)) {
696
- // Backspace on selected few full rows
697
- event.preventDefault();
698
- var paragraphs = Array.from(this.textarea.children);
699
- var _anchorParagraph = anchorElement.parentElement;
700
- var _focusParagraph = focusElement.parentElement;
701
- var _childNodes = this.textarea.childNodes;
702
- if (_anchorParagraph === _childNodes.item(0) && _focusParagraph === _childNodes.item(_childNodes.length - 1)) {
703
- this.textarea.textContent = '';
704
- this.setSelection(this.textarea, 0, 0);
705
- } else {
706
- var isCleaning = false;
707
- var _iterator2 = _createForOfIteratorHelper(paragraphs),
708
- _step2;
709
- try {
710
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
711
- var paragraph = _step2.value;
712
- if (paragraph === _anchorParagraph || isCleaning) {
713
- isCleaning = true;
714
- if (paragraph === _focusParagraph) {
715
- _focusParagraph.innerHTML = this.emptyLineValue;
716
- this.setSelection(_focusParagraph, 0, 0);
717
- break;
718
- } else {
719
- this.textarea.removeChild(paragraph);
720
- }
721
- }
604
+ // Backspace on selected full row
605
+ if (anchorElement === focusElement && anchorOffset === 0 && (focusElement === currentNode && focusOffset === 1 || focusOffset === currentNode.textContent?.length)) {
606
+ event.preventDefault();
607
+ const anchorParagraph = anchorElement?.parentElement;
608
+ const focusParagraph = focusElement?.parentElement;
609
+ const childNodes = this.textarea.childNodes;
610
+ if (anchorParagraph === childNodes.item(0) && focusParagraph === childNodes.item(childNodes.length - 1)) {
611
+ this.textarea.textContent = '';
612
+ this.setSelection(this.textarea, 0, 0);
613
+ } else {
614
+ currentNode.innerHTML = this.emptyLineValue;
615
+ this.validateLine(currentNode);
616
+ }
617
+ this.setErrorIndex(currentNode);
618
+ this.recalculateLinesCount();
619
+ setTimeout(() => {
620
+ this.recalculateErrors();
621
+ }, 0);
622
+ this.toggleErrorsPopperByKeyboard(0);
623
+ } else if (focusElement !== anchorElement && focusElement instanceof Text && anchorElement instanceof Text && focusElement?.textContent === focusElement?.parentNode?.textContent && anchorElement?.textContent === anchorElement?.parentNode?.textContent && anchorOffset === 0 && focusOffset === focusElement?.parentNode?.textContent?.length) {
624
+ // Backspace on selected few full rows
625
+ event.preventDefault();
626
+ const paragraphs = Array.from(this.textarea.children);
627
+ const anchorParagraph = anchorElement.parentElement;
628
+ const focusParagraph = focusElement.parentElement;
629
+ const childNodes = this.textarea.childNodes;
630
+ if (anchorParagraph === childNodes.item(0) && focusParagraph === childNodes.item(childNodes.length - 1)) {
631
+ this.textarea.textContent = '';
632
+ this.setSelection(this.textarea, 0, 0);
633
+ } else {
634
+ let isCleaning = false;
635
+ for (const paragraph of paragraphs) {
636
+ if (paragraph === anchorParagraph || isCleaning) {
637
+ isCleaning = true;
638
+ if (paragraph === focusParagraph) {
639
+ focusParagraph.innerHTML = this.emptyLineValue;
640
+ this.setSelection(focusParagraph, 0, 0);
641
+ break;
642
+ } else {
643
+ this.textarea.removeChild(paragraph);
722
644
  }
723
- } catch (err) {
724
- _iterator2.e(err);
725
- } finally {
726
- _iterator2.f();
727
645
  }
728
- this.validateLine(currentNode);
729
646
  }
730
- this.setErrorIndex(currentNode);
731
- this.recalculateLinesCount();
732
- setTimeout(function () {
733
- _this5.recalculateErrors();
734
- }, 0);
735
- this.toggleErrorsPopperByKeyboard(0);
647
+ this.validateLine(currentNode);
736
648
  }
649
+ this.setErrorIndex(currentNode);
650
+ this.recalculateLinesCount();
651
+ setTimeout(() => {
652
+ this.recalculateErrors();
653
+ }, 0);
654
+ this.toggleErrorsPopperByKeyboard(0);
737
655
  }
738
- } else if (event.key === 'z' && (event.ctrlKey || event.metaKey)) {
739
- event.preventDefault();
740
656
  }
657
+ } else if (event.key === 'z' && (event.ctrlKey || event.metaKey)) {
658
+ event.preventDefault();
741
659
  }
742
- }, {
743
- key: "render",
744
- value: function render() {
745
- var _ref = this.asProps,
746
- _ref2,
747
- _this$containerRef$cu2,
748
- _this6 = this;
749
- var SInputField = Box;
750
- var _this$asProps5 = this.asProps,
751
- styles = _this$asProps5.styles,
752
- showErrors = _this$asProps5.showErrors;
753
- var visibleErrorPopper = this.state.visibleErrorPopper;
754
- var _this$errorMessage = this.errorMessage,
755
- errorMessage = _this$errorMessage.errorMessage,
756
- isCommonError = _this$errorMessage.isCommonError;
757
- var visibleErrorTooltip = showErrors && visibleErrorPopper && Boolean(errorMessage) && !this.isDisabled;
758
- var _extractAriaProps2 = extractAriaProps(this.asProps),
759
- __excludeProps = _extractAriaProps2.__excludeProps;
760
- return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip, _ref2.cn("Tooltip", {
761
- "interaction": 'none',
762
- "placement": isCommonError ? 'right-start' : 'right',
763
- "visible": visibleErrorTooltip,
764
- "theme": 'warning',
765
- "offset": isCommonError ? undefined : [0, 26],
766
- "preventOverflow": {
767
- boundary: (_this$containerRef$cu2 = this.containerRef.current) !== null && _this$containerRef$cu2 !== void 0 ? _this$containerRef$cu2 : undefined,
768
- tether: false
769
- }
770
- }), function (_ref3) {
771
- var popper = _ref3.popper,
772
- setTrigger = _ref3.setTrigger;
773
- if (!_this6.popper) {
774
- _this6.setPopperTrigger = setTrigger;
775
- // @ts-ignore
776
- _this6.popper = popper;
777
- }
778
- return /*#__PURE__*/React.createElement(Tooltip.Popper, {
779
- id: _this6.popperDescribedId
780
- }, errorMessage);
781
- }), /*#__PURE__*/React.createElement(SInputField, _ref2.cn("SInputField", _objectSpread({}, _assignProps({
660
+ }
661
+ render() {
662
+ var _ref = this.asProps,
663
+ _ref2;
664
+ const SInputField = Box;
665
+ const {
666
+ styles,
667
+ showErrors
668
+ } = this.asProps;
669
+ const {
670
+ visibleErrorPopper
671
+ } = this.state;
672
+ const {
673
+ errorMessage,
674
+ isCommonError
675
+ } = this.errorMessage;
676
+ const visibleErrorTooltip = showErrors && visibleErrorPopper && Boolean(errorMessage) && !this.isDisabled;
677
+ const {
678
+ __excludeProps
679
+ } = extractAriaProps(this.asProps);
680
+ return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip, _ref2.cn("Tooltip", {
681
+ "interaction": 'none',
682
+ "placement": isCommonError ? 'right-start' : 'right',
683
+ "visible": visibleErrorTooltip,
684
+ "theme": 'warning',
685
+ "offset": isCommonError ? undefined : [0, 26],
686
+ "preventOverflow": {
687
+ boundary: this.containerRef.current ?? undefined,
688
+ tether: false
689
+ }
690
+ }), ({
691
+ popper,
692
+ setTrigger
693
+ }) => {
694
+ if (!this.popper) {
695
+ this.setPopperTrigger = setTrigger;
696
+ // @ts-ignore
697
+ this.popper = popper;
698
+ }
699
+ return /*#__PURE__*/React.createElement(Tooltip.Popper, {
700
+ id: this.popperDescribedId
701
+ }, errorMessage);
702
+ }), /*#__PURE__*/React.createElement(SInputField, _ref2.cn("SInputField", {
703
+ ..._assignProps({
782
704
  "ref": this.containerRef,
783
- "__excludeProps": ['onBlur', 'value'].concat(_toConsumableArray(__excludeProps))
784
- }, _ref)))));
785
- }
786
- }, {
787
- key: "prepareNodesForPaste",
788
- value: function prepareNodesForPaste(value) {
789
- var _pasteProps$lineProce,
790
- _pasteProps$skipEmpty,
791
- _pasteProps$delimiter,
792
- _this7 = this;
793
- var listOfNodes = [];
794
- var pasteProps = this.asProps.pasteProps;
795
- var lineProcessing = (_pasteProps$lineProce = pasteProps === null || pasteProps === void 0 ? void 0 : pasteProps.lineProcessing) !== null && _pasteProps$lineProce !== void 0 ? _pasteProps$lineProce : function (line) {
796
- var trimmedLine = line.trim();
797
- return trimmedLine === '' ? line : trimmedLine;
798
- };
799
- var skipEmptyLines = (_pasteProps$skipEmpty = pasteProps === null || pasteProps === void 0 ? void 0 : pasteProps.skipEmptyLines) !== null && _pasteProps$skipEmpty !== void 0 ? _pasteProps$skipEmpty : this.skipEmptyLines;
800
- var delimiter = (_pasteProps$delimiter = pasteProps === null || pasteProps === void 0 ? void 0 : pasteProps.delimiter) !== null && _pasteProps$delimiter !== void 0 ? _pasteProps$delimiter : this.delimiter;
801
- var lines = Array.isArray(value) ? value : value.split(delimiter);
802
- lines.forEach(function (line, index) {
803
- var preparedLine = lineProcessing(line, index, lines.length);
804
- if (preparedLine === '' && skipEmptyLines === false || preparedLine !== '') {
805
- var node = document.createElement('p');
806
- if (preparedLine === '') {
807
- node.innerHTML = _this7.emptyLineValue;
808
- } else if (preparedLine.trim() === '') {
809
- var allSpacesRegExp = new RegExp('\\s', 'g');
810
- node.innerHTML = DOMPurify.sanitize(preparedLine.replace(allSpacesRegExp, _this7.spaceLineValue));
811
- } else {
812
- node.append(document.createTextNode(preparedLine));
813
- }
814
- listOfNodes.push(node);
815
- _this7.validateLine(node);
816
- }
817
- });
818
- return listOfNodes;
819
- }
820
- }, {
821
- key: "recalculateErrors",
822
- value: function recalculateErrors() {
823
- var errors = [];
824
- this.textarea.childNodes.forEach(function (node, index) {
825
- if (node instanceof HTMLParagraphElement && node.getAttribute('aria-invalid') === 'true') {
826
- var _node$dataset$errorme;
827
- var errorItem = {
828
- errorMessage: (_node$dataset$errorme = node.dataset.errormessage) !== null && _node$dataset$errorme !== void 0 ? _node$dataset$errorme : '',
829
- lineNode: node,
830
- lineIndex: index
831
- };
832
- errors.push(errorItem);
705
+ "__excludeProps": ['onBlur', 'value', ...__excludeProps]
706
+ }, _ref)
707
+ })));
708
+ }
709
+ prepareNodesForPaste(value) {
710
+ const listOfNodes = [];
711
+ const {
712
+ pasteProps
713
+ } = this.asProps;
714
+ const lineProcessing = pasteProps?.lineProcessing ?? (line => {
715
+ const trimmedLine = line.trim();
716
+ return trimmedLine === '' ? line : trimmedLine;
717
+ });
718
+ const skipEmptyLines = pasteProps?.skipEmptyLines ?? this.skipEmptyLines;
719
+ const delimiter = pasteProps?.delimiter ?? this.delimiter;
720
+ const lines = Array.isArray(value) ? value : value.split(delimiter);
721
+ lines.forEach((line, index) => {
722
+ const preparedLine = lineProcessing(line, index, lines.length);
723
+ if (preparedLine === '' && skipEmptyLines === false || preparedLine !== '') {
724
+ const node = document.createElement('p');
725
+ if (preparedLine === '') {
726
+ node.innerHTML = this.emptyLineValue;
727
+ } else if (preparedLine.trim() === '') {
728
+ const allSpacesRegExp = new RegExp('\\s', 'g');
729
+ node.innerHTML = DOMPurify.sanitize(preparedLine.replace(allSpacesRegExp, this.spaceLineValue));
730
+ } else {
731
+ node.append(document.createTextNode(preparedLine));
833
732
  }
834
- });
835
- this.asProps.onErrorsChange(errors);
836
- }
837
- }, {
838
- key: "recalculateLinesCount",
839
- value: function recalculateLinesCount() {
840
- var _this8 = this;
841
- if (this.linesCountTimeout) {
842
- clearTimeout(this.linesCountTimeout);
733
+ listOfNodes.push(node);
734
+ this.validateLine(node);
843
735
  }
844
- this.linesCountTimeout = window.setTimeout(function () {
845
- var lines = 0;
846
- var _this8$asProps = _this8.asProps,
847
- maxLines = _this8$asProps.maxLines,
848
- linesCount = _this8$asProps.linesCount;
849
- _this8.textarea.childNodes.forEach(function (node) {
850
- if (node instanceof HTMLParagraphElement) {
851
- node.dataset.overMaxRows = 'false';
852
- if (node.textContent !== _this8.getEmptyParagraph().textContent && node.textContent !== '') {
853
- lines++;
854
- if (lines > maxLines) {
855
- node.dataset.overMaxRows = 'true';
856
- }
736
+ });
737
+ return listOfNodes;
738
+ }
739
+ recalculateErrors() {
740
+ const errors = [];
741
+ this.textarea.childNodes.forEach((node, index) => {
742
+ if (node instanceof HTMLParagraphElement && node.getAttribute('aria-invalid') === 'true') {
743
+ const errorItem = {
744
+ errorMessage: node.dataset.errormessage ?? '',
745
+ lineNode: node,
746
+ lineIndex: index
747
+ };
748
+ errors.push(errorItem);
749
+ }
750
+ });
751
+ this.asProps.onErrorsChange(errors);
752
+ }
753
+ recalculateLinesCount() {
754
+ if (this.linesCountTimeout) {
755
+ clearTimeout(this.linesCountTimeout);
756
+ }
757
+ this.linesCountTimeout = window.setTimeout(() => {
758
+ let lines = 0;
759
+ const {
760
+ maxLines,
761
+ linesCount
762
+ } = this.asProps;
763
+ this.textarea.childNodes.forEach(node => {
764
+ if (node instanceof HTMLParagraphElement) {
765
+ node.dataset.overMaxRows = 'false';
766
+ if (node.textContent !== this.getEmptyParagraph().textContent && node.textContent !== '') {
767
+ lines++;
768
+ if (lines > maxLines) {
769
+ node.dataset.overMaxRows = 'true';
857
770
  }
858
771
  }
859
- });
860
- if (linesCount !== lines) {
861
- _this8.asProps.onChangeLinesCount(lines);
862
- }
863
- }, 100);
864
- }
865
- }, {
866
- key: "getValues",
867
- value: function getValues() {
868
- var values = [];
869
- this.textarea.childNodes.forEach(function (node) {
870
- var _node$textContent;
871
- if (((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.trim()) === '') {
872
- values.push('');
873
- } else {
874
- var _node$textContent2;
875
- values.push((_node$textContent2 = node.textContent) !== null && _node$textContent2 !== void 0 ? _node$textContent2 : '');
876
772
  }
877
773
  });
878
- return values;
879
- }
880
- }, {
881
- key: "shouldChangePopperTrigger",
882
- value: function shouldChangePopperTrigger(node) {
883
- return this.textarea !== node || this.textarea === node && Boolean(this.asProps.commonErrorMessage);
884
- }
885
- }, {
886
- key: "toggleErrorsPopperByKeyboard",
887
- value: function toggleErrorsPopperByKeyboard(timer) {
888
- var _this9 = this;
889
- if (this.toggleErrorsPopperTimeout) {
890
- clearTimeout(this.toggleErrorsPopperTimeout);
891
- }
892
- if (!this.isScrolling) {
893
- setTimeout(function () {
894
- var rowNode = _this9.getNodeFromSelection();
895
- _this9.toggleErrorsPopper('keyboardLineIndex', rowNode, timer);
896
- }, 0);
897
- } else {
898
- this.toggleErrorsPopperTimeout = window.setTimeout(function () {
899
- _this9.toggleErrorsPopperByKeyboard(timer);
900
- }, 50);
774
+ if (linesCount !== lines) {
775
+ this.asProps.onChangeLinesCount(lines);
901
776
  }
902
- }
903
- }, {
904
- key: "toggleErrorsPopper",
905
- value: function toggleErrorsPopper(key, target, timer) {
906
- var _this0 = this;
907
- if (target instanceof HTMLDivElement || target instanceof HTMLParagraphElement) {
908
- if (this.changeTriggerTimeout) {
909
- clearTimeout(this.changeTriggerTimeout);
910
- }
911
- this.changeTriggerTimeout = window.setTimeout(function () {
912
- var targetElement = target === _this0.textarea ? _this0.getNodeFromSelection() : target;
913
- var lineIndex = -1;
914
- var isInvalidRow = false;
915
- if (targetElement instanceof HTMLParagraphElement) {
916
- isInvalidRow = targetElement.getAttribute('aria-invalid') === 'true';
917
- lineIndex = Array.from(_this0.textarea.childNodes).indexOf(targetElement);
918
- } else if (targetElement === _this0.textarea) {
919
- lineIndex = 0;
920
- }
921
- if (targetElement instanceof HTMLElement) {
922
- _this0.setState(function (prevState) {
923
- var newState = {
924
- visibleErrorPopper: _this0.isFocusing && Boolean(_this0.asProps.commonErrorMessage) ? true : isInvalidRow,
925
- mouseLineIndex: prevState.mouseLineIndex,
926
- keyboardLineIndex: prevState.keyboardLineIndex
927
- };
928
- if (_this0.isFocusing || key === 'mouseLineIndex' && isInvalidRow) {
929
- newState[key] = lineIndex;
930
- }
931
- return newState;
932
- }, function () {
933
- _this0.errorByInteraction = key === 'mouseLineIndex' ? 'mouse' : 'keyboard';
934
- var trigger = isInvalidRow ? targetElement : _this0.textarea;
935
- if (_this0.shouldChangePopperTrigger(trigger)) {
936
- var _this0$setPopperTrigg;
937
- (_this0$setPopperTrigg = _this0.setPopperTrigger) === null || _this0$setPopperTrigg === void 0 || _this0$setPopperTrigg.call(_this0, trigger);
938
- _this0.forceUpdate();
939
- }
940
- });
941
- }
942
- }, timer !== null && timer !== void 0 ? timer : 50);
777
+ }, 100);
778
+ }
779
+ getValues() {
780
+ const values = [];
781
+ this.textarea.childNodes.forEach(node => {
782
+ if (node.textContent?.trim() === '') {
783
+ values.push('');
943
784
  } else {
944
- this.setState({
945
- visibleErrorPopper: false
946
- });
785
+ values.push(node.textContent ?? '');
947
786
  }
787
+ });
788
+ return values;
789
+ }
790
+ shouldChangePopperTrigger(node) {
791
+ return this.textarea !== node || this.textarea === node && Boolean(this.asProps.commonErrorMessage);
792
+ }
793
+ toggleErrorsPopperByKeyboard(timer) {
794
+ if (this.toggleErrorsPopperTimeout) {
795
+ clearTimeout(this.toggleErrorsPopperTimeout);
948
796
  }
949
- }, {
950
- key: "toggleAriaInvalid",
951
- value: function toggleAriaInvalid(showErrors, errorsLength) {
952
- if (showErrors && errorsLength > 0) {
953
- this.textarea.setAttribute('aria-describedby', this.popperDescribedId);
954
- this.textarea.setAttribute('aria-invalid', 'true');
955
- } else {
956
- this.textarea.removeAttribute('aria-invalid');
957
- this.textarea.removeAttribute('aria-describedby');
958
- }
797
+ if (!this.isScrolling) {
798
+ setTimeout(() => {
799
+ const rowNode = this.getNodeFromSelection();
800
+ this.toggleErrorsPopper('keyboardLineIndex', rowNode, timer);
801
+ }, 0);
802
+ } else {
803
+ this.toggleErrorsPopperTimeout = window.setTimeout(() => {
804
+ this.toggleErrorsPopperByKeyboard(timer);
805
+ }, 50);
959
806
  }
960
- }, {
961
- key: "handleChangeErrorIndex",
962
- value: function handleChangeErrorIndex(errorIndex) {
963
- var _error$lineNode,
964
- _this1 = this;
965
- var error = this.asProps.errors[errorIndex];
966
- var childNodes = this.textarea.childNodes;
967
- var node = error ? (_error$lineNode = error.lineNode) !== null && _error$lineNode !== void 0 ? _error$lineNode : childNodes.item(error.lineIndex) : null;
968
- var selection = document.getSelection();
969
- if (selection && node instanceof HTMLParagraphElement) {
970
- this.setState({
971
- visibleErrorPopper: false
972
- });
973
- setTimeout(function () {
974
- var text = node.childNodes.item(0);
975
- if (text instanceof Text) {
976
- _this1.setSelection(text, 0, text.length);
977
- } else {
978
- _this1.setSelection(node, 0, 1);
979
- }
980
- }, 150);
807
+ }
808
+ toggleErrorsPopper(key, target, timer) {
809
+ if (target instanceof HTMLDivElement || target instanceof HTMLParagraphElement) {
810
+ if (this.changeTriggerTimeout) {
811
+ clearTimeout(this.changeTriggerTimeout);
981
812
  }
982
- }
983
- }, {
984
- key: "validateLine",
985
- value: function validateLine(node) {
986
- var lineValidation = this.asProps.lineValidation;
987
- if (lineValidation && node instanceof HTMLElement) {
988
- var _node$textContent3;
989
- var _lineValidation = lineValidation((_node$textContent3 = node.textContent) !== null && _node$textContent3 !== void 0 ? _node$textContent3 : '', this.getValues()),
990
- isValid = _lineValidation.isValid,
991
- errorMessage = _lineValidation.errorMessage;
992
- if (!isValid) {
993
- node.setAttribute('aria-invalid', 'true');
994
- node.dataset.errormessage = errorMessage;
995
- } else {
996
- node.removeAttribute('aria-invalid');
997
- node.dataset.errormessage = undefined;
813
+ this.changeTriggerTimeout = window.setTimeout(() => {
814
+ const targetElement = target === this.textarea ? this.getNodeFromSelection() : target;
815
+ let lineIndex = -1;
816
+ let isInvalidRow = false;
817
+ if (targetElement instanceof HTMLParagraphElement) {
818
+ isInvalidRow = targetElement.getAttribute('aria-invalid') === 'true';
819
+ lineIndex = Array.from(this.textarea.childNodes).indexOf(targetElement);
820
+ } else if (targetElement === this.textarea) {
821
+ lineIndex = 0;
998
822
  }
999
- return isValid;
1000
- }
1001
- return true;
1002
- }
1003
- }, {
1004
- key: "setSelection",
1005
- value: function setSelection(node, start, end) {
1006
- var scrollType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'center';
1007
- var selection = document.getSelection();
1008
- var range = document.createRange();
1009
- range.setStart(node, start);
1010
- range.setEnd(node, end);
1011
- selection === null || selection === void 0 || selection.removeAllRanges();
1012
- selection === null || selection === void 0 || selection.addRange(range);
1013
- var nodeToScroll = node instanceof Text ? node.parentNode : node;
1014
- if (nodeToScroll instanceof HTMLElement) {
1015
- nodeToScroll.scrollIntoView({
1016
- block: scrollType,
1017
- inline: scrollType,
1018
- behavior: 'smooth'
1019
- });
1020
- }
1021
- }
1022
- }, {
1023
- key: "getNodeFromSelection",
1024
- value: function getNodeFromSelection() {
1025
- var selection = document.getSelection();
1026
- var rowNode = (selection === null || selection === void 0 ? void 0 : selection.focusNode) instanceof Text ? selection.focusNode.parentNode : selection === null || selection === void 0 ? void 0 : selection.focusNode;
1027
- return rowNode !== null && rowNode !== void 0 ? rowNode : null;
1028
- }
1029
- }, {
1030
- key: "handleCursorMovement",
1031
- value: function handleCursorMovement(currentNode, event) {
1032
- var nextNode = null;
1033
- switch (event.key) {
1034
- case 'ArrowUp':
1035
- event.preventDefault();
1036
- nextNode = currentNode.previousSibling;
1037
- break;
1038
- case 'ArrowDown':
1039
- event.preventDefault();
1040
- nextNode = currentNode.nextSibling;
1041
- break;
1042
- case 'ArrowLeft':
1043
- {
1044
- if (currentNode.textContent === this.getEmptyParagraph().textContent) {
1045
- event.preventDefault();
1046
- nextNode = currentNode.previousSibling;
823
+ if (targetElement instanceof HTMLElement) {
824
+ this.setState(prevState => {
825
+ const newState = {
826
+ visibleErrorPopper: this.isFocusing && Boolean(this.asProps.commonErrorMessage) ? true : isInvalidRow,
827
+ mouseLineIndex: prevState.mouseLineIndex,
828
+ keyboardLineIndex: prevState.keyboardLineIndex
829
+ };
830
+ if (this.isFocusing || key === 'mouseLineIndex' && isInvalidRow) {
831
+ newState[key] = lineIndex;
1047
832
  }
1048
- break;
1049
- }
1050
- case 'ArrowRight':
1051
- {
1052
- if (currentNode.textContent === this.getEmptyParagraph().textContent) {
1053
- event.preventDefault();
1054
- nextNode = currentNode.nextSibling;
833
+ return newState;
834
+ }, () => {
835
+ this.errorByInteraction = key === 'mouseLineIndex' ? 'mouse' : 'keyboard';
836
+ const trigger = isInvalidRow ? targetElement : this.textarea;
837
+ if (this.shouldChangePopperTrigger(trigger)) {
838
+ this.setPopperTrigger?.(trigger);
839
+ this.forceUpdate();
1055
840
  }
1056
- }
1057
- }
1058
- if (nextNode instanceof HTMLParagraphElement) {
1059
- var _nextNode$textContent, _nextNode$textContent2, _selection$focusOffse;
1060
- var selection = document.getSelection();
1061
- var firstNode = nextNode.childNodes.item(0);
1062
- var nodeToSetSelection = firstNode instanceof Text ? firstNode : nextNode;
1063
- var textNode = (_nextNode$textContent = (_nextNode$textContent2 = nextNode.textContent) === null || _nextNode$textContent2 === void 0 ? void 0 : _nextNode$textContent2.trim()) !== null && _nextNode$textContent !== void 0 ? _nextNode$textContent : '';
1064
- var currentOffset = (_selection$focusOffse = selection === null || selection === void 0 ? void 0 : selection.focusOffset) !== null && _selection$focusOffse !== void 0 ? _selection$focusOffse : 0;
1065
- var offset = currentOffset <= textNode.length ? currentOffset : textNode.length;
1066
-
1067
- // it only works if node is empty, that's why here we could set 0 or node.length
1068
- if (event.key === 'ArrowLeft') {
1069
- offset = textNode.length;
1070
- } else if (event.key === 'ArrowRight') {
1071
- offset = 0;
841
+ });
1072
842
  }
1073
- this.setSelection(nodeToSetSelection, offset, offset, 'nearest');
1074
- }
1075
- }
1076
- }, {
1077
- key: "setErrorIndex",
1078
- value: function setErrorIndex(nodeToCompare) {
1079
- var errorIndex = Array.from(this.textarea.childNodes).filter(function (node) {
1080
- return node instanceof Element && node.getAttribute('aria-invalid') === 'true';
1081
- }).findIndex(function (node) {
1082
- return node === nodeToCompare;
843
+ }, timer ?? 50);
844
+ } else {
845
+ this.setState({
846
+ visibleErrorPopper: false
1083
847
  });
1084
- this.handlers.errorIndex(errorIndex);
1085
848
  }
1086
- }, {
1087
- key: "isDeleteKey",
1088
- value: function isDeleteKey(event) {
1089
- return event.key === 'Backspace' || event.key === 'x' && (event.ctrlKey || event.metaKey);
849
+ }
850
+ toggleAriaInvalid(showErrors, errorsLength) {
851
+ if (showErrors && errorsLength > 0) {
852
+ this.textarea.setAttribute('aria-describedby', this.popperDescribedId);
853
+ this.textarea.setAttribute('aria-invalid', 'true');
854
+ } else {
855
+ this.textarea.removeAttribute('aria-invalid');
856
+ this.textarea.removeAttribute('aria-describedby');
1090
857
  }
1091
- }, {
1092
- key: "getEmptyParagraph",
1093
- value: function getEmptyParagraph() {
1094
- var element = document.createElement('p');
1095
- element.innerHTML = this.emptyLineValue;
1096
- return element;
858
+ }
859
+ handleChangeErrorIndex(errorIndex) {
860
+ const error = this.asProps.errors[errorIndex];
861
+ const childNodes = this.textarea.childNodes;
862
+ const node = error ? error.lineNode ?? childNodes.item(error.lineIndex) : null;
863
+ const selection = document.getSelection();
864
+ if (selection && node instanceof HTMLParagraphElement) {
865
+ this.setState({
866
+ visibleErrorPopper: false
867
+ });
868
+ setTimeout(() => {
869
+ const text = node.childNodes.item(0);
870
+ if (text instanceof Text) {
871
+ this.setSelection(text, 0, text.length);
872
+ } else {
873
+ this.setSelection(node, 0, 1);
874
+ }
875
+ }, 150);
1097
876
  }
1098
- }, {
1099
- key: "addEventListeners",
1100
- value: function addEventListeners(textarea) {
1101
- textarea.addEventListener('paste', this.handlePaste);
1102
- textarea.addEventListener('input', this.handleChange);
1103
- textarea.addEventListener('focus', this.handleFocus);
1104
- textarea.addEventListener('blur', this.handleBlur);
1105
- textarea.addEventListener('keydown', this.handleKeyDown);
1106
- textarea.addEventListener('mousedown', this.handleMouseDown);
1107
- textarea.addEventListener('mousemove', this.handleMouseMove);
1108
- textarea.addEventListener('mouseleave', this.handleMouseLeave);
1109
- textarea.addEventListener('scroll', this.handleScroll);
1110
- textarea.removeEventListener('keydown', this.handleSelectAll);
877
+ }
878
+ validateLine(node) {
879
+ const {
880
+ lineValidation
881
+ } = this.asProps;
882
+ if (lineValidation && node instanceof HTMLElement) {
883
+ const {
884
+ isValid,
885
+ errorMessage
886
+ } = lineValidation(node.textContent ?? '', this.getValues());
887
+ if (!isValid) {
888
+ node.setAttribute('aria-invalid', 'true');
889
+ node.dataset.errormessage = errorMessage;
890
+ } else {
891
+ node.removeAttribute('aria-invalid');
892
+ node.dataset.errormessage = undefined;
893
+ }
894
+ return isValid;
1111
895
  }
1112
- }, {
1113
- key: "removeEventListeners",
1114
- value: function removeEventListeners(textarea) {
1115
- textarea.removeEventListener('paste', this.handlePaste);
1116
- textarea.removeEventListener('input', this.handleChange);
1117
- textarea.removeEventListener('focus', this.handleFocus);
1118
- textarea.removeEventListener('blur', this.handleBlur);
1119
- textarea.removeEventListener('keydown', this.handleKeyDown);
1120
- textarea.removeEventListener('mousedown', this.handleMouseDown);
1121
- textarea.removeEventListener('mousemove', this.handleMouseMove);
1122
- textarea.removeEventListener('mouseleave', this.handleMouseLeave);
1123
- textarea.removeEventListener('scroll', this.handleScroll);
1124
- textarea.addEventListener('keydown', this.handleSelectAll);
896
+ return true;
897
+ }
898
+ setSelection(node, start, end, scrollType = 'center') {
899
+ const selection = document.getSelection();
900
+ const range = document.createRange();
901
+ range.setStart(node, start);
902
+ range.setEnd(node, end);
903
+ selection?.removeAllRanges();
904
+ selection?.addRange(range);
905
+ const nodeToScroll = node instanceof Text ? node.parentNode : node;
906
+ if (nodeToScroll instanceof HTMLElement) {
907
+ nodeToScroll.scrollIntoView({
908
+ block: scrollType,
909
+ inline: scrollType,
910
+ behavior: 'smooth'
911
+ });
1125
912
  }
1126
- }, {
1127
- key: "handleSelectAll",
1128
- value: function handleSelectAll(event) {
1129
- if (event.key === 'a' && (event.metaKey || event.ctrlKey)) {
913
+ }
914
+ getNodeFromSelection() {
915
+ const selection = document.getSelection();
916
+ const rowNode = selection?.focusNode instanceof Text ? selection.focusNode.parentNode : selection?.focusNode;
917
+ return rowNode ?? null;
918
+ }
919
+ handleCursorMovement(currentNode, event) {
920
+ let nextNode = null;
921
+ switch (event.key) {
922
+ case 'ArrowUp':
1130
923
  event.preventDefault();
1131
- var node = event.target;
1132
- if (node instanceof HTMLElement && node === this.textarea) {
1133
- this.setSelection(node, 0, node.childNodes.length);
924
+ nextNode = currentNode.previousSibling;
925
+ break;
926
+ case 'ArrowDown':
927
+ event.preventDefault();
928
+ nextNode = currentNode.nextSibling;
929
+ break;
930
+ case 'ArrowLeft':
931
+ {
932
+ if (currentNode.textContent === this.getEmptyParagraph().textContent) {
933
+ event.preventDefault();
934
+ nextNode = currentNode.previousSibling;
935
+ }
936
+ break;
1134
937
  }
938
+ case 'ArrowRight':
939
+ {
940
+ if (currentNode.textContent === this.getEmptyParagraph().textContent) {
941
+ event.preventDefault();
942
+ nextNode = currentNode.nextSibling;
943
+ }
944
+ }
945
+ }
946
+ if (nextNode instanceof HTMLParagraphElement) {
947
+ const selection = document.getSelection();
948
+ const firstNode = nextNode.childNodes.item(0);
949
+ const nodeToSetSelection = firstNode instanceof Text ? firstNode : nextNode;
950
+ const textNode = nextNode.textContent?.trim() ?? '';
951
+ const currentOffset = selection?.focusOffset ?? 0;
952
+ let offset = currentOffset <= textNode.length ? currentOffset : textNode.length;
953
+
954
+ // it only works if node is empty, that's why here we could set 0 or node.length
955
+ if (event.key === 'ArrowLeft') {
956
+ offset = textNode.length;
957
+ } else if (event.key === 'ArrowRight') {
958
+ offset = 0;
1135
959
  }
960
+ this.setSelection(nodeToSetSelection, offset, offset, 'nearest');
1136
961
  }
1137
- }, {
1138
- key: "isRangeSelection",
1139
- value: function isRangeSelection() {
1140
- var selection = document.getSelection();
1141
- return (selection === null || selection === void 0 ? void 0 : selection.focusNode) !== (selection === null || selection === void 0 ? void 0 : selection.anchorNode) || (selection === null || selection === void 0 ? void 0 : selection.focusOffset) !== (selection === null || selection === void 0 ? void 0 : selection.anchorOffset);
962
+ }
963
+ setErrorIndex(nodeToCompare) {
964
+ const errorIndex = Array.from(this.textarea.childNodes).filter(node => {
965
+ return node instanceof Element && node.getAttribute('aria-invalid') === 'true';
966
+ }).findIndex(node => {
967
+ return node === nodeToCompare;
968
+ });
969
+ this.handlers.errorIndex(errorIndex);
970
+ }
971
+ isDeleteKey(event) {
972
+ return event.key === 'Backspace' || event.key === 'x' && (event.ctrlKey || event.metaKey);
973
+ }
974
+ getEmptyParagraph() {
975
+ const element = document.createElement('p');
976
+ element.innerHTML = this.emptyLineValue;
977
+ return element;
978
+ }
979
+ addEventListeners(textarea) {
980
+ textarea.addEventListener('paste', this.handlePaste);
981
+ textarea.addEventListener('input', this.handleChange);
982
+ textarea.addEventListener('focus', this.handleFocus);
983
+ textarea.addEventListener('blur', this.handleBlur);
984
+ textarea.addEventListener('keydown', this.handleKeyDown);
985
+ textarea.addEventListener('mousedown', this.handleMouseDown);
986
+ textarea.addEventListener('mousemove', this.handleMouseMove);
987
+ textarea.addEventListener('mouseleave', this.handleMouseLeave);
988
+ textarea.addEventListener('scroll', this.handleScroll);
989
+ textarea.removeEventListener('keydown', this.handleSelectAll);
990
+ }
991
+ removeEventListeners(textarea) {
992
+ textarea.removeEventListener('paste', this.handlePaste);
993
+ textarea.removeEventListener('input', this.handleChange);
994
+ textarea.removeEventListener('focus', this.handleFocus);
995
+ textarea.removeEventListener('blur', this.handleBlur);
996
+ textarea.removeEventListener('keydown', this.handleKeyDown);
997
+ textarea.removeEventListener('mousedown', this.handleMouseDown);
998
+ textarea.removeEventListener('mousemove', this.handleMouseMove);
999
+ textarea.removeEventListener('mouseleave', this.handleMouseLeave);
1000
+ textarea.removeEventListener('scroll', this.handleScroll);
1001
+ textarea.addEventListener('keydown', this.handleSelectAll);
1002
+ }
1003
+ handleSelectAll(event) {
1004
+ if (event.key === 'a' && (event.metaKey || event.ctrlKey)) {
1005
+ event.preventDefault();
1006
+ const node = event.target;
1007
+ if (node instanceof HTMLElement && node === this.textarea) {
1008
+ this.setSelection(node, 0, node.childNodes.length);
1009
+ }
1142
1010
  }
1143
- }, {
1144
- key: "getSelectionDirection",
1145
- value: function getSelectionDirection() {
1146
- var selection = document.getSelection();
1147
- if (selection !== null && selection !== void 0 && selection.anchorNode && selection !== null && selection !== void 0 && selection.focusNode) {
1148
- var documentPosition = selection.anchorNode.compareDocumentPosition(selection.focusNode);
1149
- if (documentPosition === 0 && selection.anchorOffset > selection.focusOffset ||
1150
- // if nodes are the same
1151
- documentPosition === Node.DOCUMENT_POSITION_PRECEDING) {
1152
- return 'backward';
1153
- }
1154
- return 'forward';
1011
+ }
1012
+ isRangeSelection() {
1013
+ const selection = document.getSelection();
1014
+ return selection?.focusNode !== selection?.anchorNode || selection?.focusOffset !== selection?.anchorOffset;
1015
+ }
1016
+ getSelectionDirection() {
1017
+ const selection = document.getSelection();
1018
+ if (selection?.anchorNode && selection?.focusNode) {
1019
+ const documentPosition = selection.anchorNode.compareDocumentPosition(selection.focusNode);
1020
+ if (documentPosition === 0 && selection.anchorOffset > selection.focusOffset ||
1021
+ // if nodes are the same
1022
+ documentPosition === Node.DOCUMENT_POSITION_PRECEDING) {
1023
+ return 'backward';
1155
1024
  }
1156
- return null;
1025
+ return 'forward';
1157
1026
  }
1158
- }]);
1159
- }(Component);
1027
+ return null;
1028
+ }
1029
+ }
1160
1030
  _defineProperty(InputField, "displayName", 'Textarea');
1161
1031
  _defineProperty(InputField, "style", style);
1162
1032
  _defineProperty(InputField, "enhance", [uniqueIDEnhancement()]);