@semcore/bulk-textarea 1.0.1

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