@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.
- package/CHANGELOG.md +6 -0
- package/README.md +4 -4
- package/lib/cjs/BulkTextarea.js +248 -269
- package/lib/cjs/BulkTextarea.js.map +1 -1
- package/lib/cjs/BulkTextarea.types.js.map +1 -1
- package/lib/cjs/components/ClearAll.js +9 -8
- package/lib/cjs/components/ClearAll.js.map +1 -1
- package/lib/cjs/components/Counter.js +12 -10
- package/lib/cjs/components/Counter.js.map +1 -1
- package/lib/cjs/components/ErrorsNavigation.js +22 -20
- package/lib/cjs/components/ErrorsNavigation.js.map +1 -1
- package/lib/cjs/components/InputField/InputField.js +916 -1045
- package/lib/cjs/components/InputField/InputField.js.map +1 -1
- package/lib/cjs/index.js +3 -3
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js +16 -16
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/es6/BulkTextarea.js +242 -263
- package/lib/es6/BulkTextarea.js.map +1 -1
- package/lib/es6/BulkTextarea.types.js.map +1 -1
- package/lib/es6/components/ClearAll.js +8 -7
- package/lib/es6/components/ClearAll.js.map +1 -1
- package/lib/es6/components/Counter.js +7 -5
- package/lib/es6/components/Counter.js.map +1 -1
- package/lib/es6/components/ErrorsNavigation.js +15 -13
- package/lib/es6/components/ErrorsNavigation.js.map +1 -1
- package/lib/es6/components/InputField/InputField.js +910 -1040
- package/lib/es6/components/InputField/InputField.js.map +1 -1
- package/lib/es6/translations/__intergalactic-dynamic-locales.js +15 -15
- package/lib/es6/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/esm/BulkTextarea.mjs +244 -223
- package/lib/esm/components/ClearAll.mjs +8 -7
- package/lib/esm/components/Counter.mjs +7 -2
- package/lib/esm/components/ErrorsNavigation.mjs +13 -2
- package/lib/esm/components/InputField/InputField.mjs +903 -981
- package/lib/esm/translations/__intergalactic-dynamic-locales.mjs +1 -1
- package/lib/types/BulkTextarea.types.d.ts +1 -1
- package/lib/types/components/InputField/InputField.d.ts +6 -2
- 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
|
-
|
|
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": "
|
|
23
|
-
"_showErrors": "
|
|
24
|
-
"_readonly": "
|
|
25
|
-
"_disabled": "
|
|
26
|
-
"_size_m": "
|
|
27
|
-
"--minRows": "--
|
|
28
|
-
"--maxRows": "--
|
|
29
|
-
"_size_l": "
|
|
30
|
-
"_state_normal": "
|
|
31
|
-
"_state_valid": "
|
|
32
|
-
"_state_invalid": "
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_defineProperty(
|
|
40
|
-
_defineProperty(
|
|
41
|
-
_defineProperty(
|
|
42
|
-
_defineProperty(
|
|
43
|
-
_defineProperty(
|
|
44
|
-
_defineProperty(
|
|
45
|
-
_defineProperty(
|
|
46
|
-
_defineProperty(
|
|
47
|
-
_defineProperty(
|
|
48
|
-
_defineProperty(
|
|
49
|
-
_defineProperty(
|
|
50
|
-
_defineProperty(
|
|
51
|
-
_defineProperty(
|
|
52
|
-
_defineProperty(
|
|
53
|
-
_defineProperty(
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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('
|
|
139
|
+
this.textarea.setAttribute('contenteditable', 'true');
|
|
140
|
+
this.addEventListeners(this.textarea);
|
|
279
141
|
}
|
|
280
|
-
if (
|
|
281
|
-
this.
|
|
142
|
+
if (disabled) {
|
|
143
|
+
this.textarea.setAttribute('tabindex', '-1');
|
|
282
144
|
} else {
|
|
283
|
-
textarea.
|
|
145
|
+
this.textarea.setAttribute('tabindex', '0');
|
|
284
146
|
}
|
|
285
|
-
return textarea;
|
|
286
147
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
|
|
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
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
-
|
|
429
|
-
|
|
430
|
-
this.
|
|
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
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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 (
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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
|
-
|
|
523
|
-
|
|
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
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
-
|
|
509
|
+
keyboardLineIndex: -1
|
|
561
510
|
});
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
-
|
|
570
|
-
|
|
571
|
-
|
|
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
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
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
|
-
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
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
|
-
|
|
653
|
-
|
|
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
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
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
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
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.
|
|
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
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
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']
|
|
784
|
-
}, _ref)
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
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
|
-
|
|
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
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
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
|
-
|
|
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
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
if (
|
|
908
|
-
|
|
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
|
-
|
|
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
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
this.
|
|
957
|
-
|
|
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
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
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
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
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
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
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
|
-
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
if (
|
|
1053
|
-
|
|
1054
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
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
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
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
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
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
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
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
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
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
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
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
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
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
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
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
|
|
1025
|
+
return 'forward';
|
|
1157
1026
|
}
|
|
1158
|
-
|
|
1159
|
-
}
|
|
1027
|
+
return null;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1160
1030
|
_defineProperty(InputField, "displayName", 'Textarea');
|
|
1161
1031
|
_defineProperty(InputField, "style", style);
|
|
1162
1032
|
_defineProperty(InputField, "enhance", [uniqueIDEnhancement()]);
|