@semcore/bulk-textarea 17.2.1 → 17.2.2-prerelease.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/cjs/BulkTextarea.js +18 -12
- package/lib/cjs/BulkTextarea.js.map +1 -1
- package/lib/cjs/BulkTextarea.types.js.map +1 -1
- package/lib/cjs/components/ClearAll.js.map +1 -1
- package/lib/cjs/components/Counter.js.map +1 -1
- package/lib/cjs/components/ErrorsNavigation.js +5 -2
- package/lib/cjs/components/ErrorsNavigation.js.map +1 -1
- package/lib/cjs/components/InputField/History.js +46 -0
- package/lib/cjs/components/InputField/History.js.map +1 -0
- package/lib/cjs/components/InputField/InputField.js +494 -361
- package/lib/cjs/components/InputField/InputField.js.map +1 -1
- package/lib/cjs/components/InputField/inputField.shadow.css +42 -51
- package/lib/cjs/index.js.map +1 -1
- package/lib/es6/BulkTextarea.js +18 -12
- package/lib/es6/BulkTextarea.js.map +1 -1
- package/lib/es6/BulkTextarea.types.js.map +1 -1
- package/lib/es6/components/ClearAll.js.map +1 -1
- package/lib/es6/components/Counter.js.map +1 -1
- package/lib/es6/components/ErrorsNavigation.js +5 -2
- package/lib/es6/components/ErrorsNavigation.js.map +1 -1
- package/lib/es6/components/InputField/History.js +38 -0
- package/lib/es6/components/InputField/History.js.map +1 -0
- package/lib/es6/components/InputField/InputField.js +494 -361
- package/lib/es6/components/InputField/InputField.js.map +1 -1
- package/lib/es6/components/InputField/inputField.shadow.css +42 -51
- package/lib/es6/index.js.map +1 -1
- package/lib/esm/BulkTextarea.mjs +12 -5
- package/lib/esm/components/ErrorsNavigation.mjs +5 -2
- package/lib/esm/components/InputField/History.mjs +40 -0
- package/lib/esm/components/InputField/InputField.mjs +481 -358
- package/lib/esm/components/InputField/inputField.shadow.css +42 -51
- package/lib/types/BulkTextarea.d.ts +108 -2
- package/lib/types/BulkTextarea.types.d.ts +245 -147
- package/lib/types/components/ClearAll.d.ts +4 -6
- package/lib/types/components/Counter.d.ts +4 -9
- package/lib/types/components/ErrorsNavigation.d.ts +4 -14
- package/lib/types/components/InputField/History.d.ts +20 -0
- package/lib/types/components/InputField/InputField.d.ts +30 -24
- package/lib/types/index.d.ts +1 -2
- package/package.json +3 -3
- package/lib/cjs/components/InputField/InputField.types.js +0 -2
- package/lib/cjs/components/InputField/InputField.types.js.map +0 -1
- package/lib/es6/components/InputField/InputField.types.js +0 -2
- package/lib/es6/components/InputField/InputField.types.js.map +0 -1
- package/lib/types/components/InputField/InputField.types.d.ts +0 -44
|
@@ -9,25 +9,27 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _core = require("@semcore/core");
|
|
10
10
|
var _baseComponents = require("@semcore/base-components");
|
|
11
11
|
var _ariaProps = require("@semcore/core/lib/utils/ariaProps");
|
|
12
|
+
var _logger = _interopRequireDefault(require("@semcore/core/lib/utils/logger"));
|
|
12
13
|
var _uniqueID = _interopRequireDefault(require("@semcore/core/lib/utils/uniqueID"));
|
|
13
14
|
var _tooltip = _interopRequireDefault(require("@semcore/tooltip"));
|
|
14
15
|
var _dompurify = _interopRequireDefault(require("dompurify"));
|
|
15
16
|
var _react = _interopRequireDefault(require("react"));
|
|
17
|
+
var _History = require("./History");
|
|
16
18
|
/*!__reshadow-styles__:"./inputField.shadow.css"*/
|
|
17
|
-
const style = (/*__reshadow_css_start__*/_core.sstyled.insert(/*__inner_css_start__*/".
|
|
19
|
+
const style = (/*__reshadow_css_start__*/_core.sstyled.insert(/*__inner_css_start__*/".___SInputField_q6qxb_gg_>ol{box-sizing:initial;outline-color:#0000;border-radius:var(--intergalactic-control-rounded,6px);border-color:var(--intergalactic-border-primary,#000c0829);border-style:solid;border-width:1px;overflow:auto;position:relative;background-color:var(--intergalactic-bg-primary-neutral,oklch(1 0 0));color:var(--intergalactic-text-primary,oklch(.1 .03 137/.899));word-wrap:break-word;word-break:break-word;font-family:inherit;margin:0;list-style-type:none;counter-reset:list-counter}@media (color-gamut:p3){.___SInputField_q6qxb_gg_>ol{border-color:var(--intergalactic-border-primary,oklch(.137 .026 175.7/.161))}}.___SInputField_q6qxb_gg_>ol:empty:before{content:\"1. \" attr(data-placeholder);color:var(--intergalactic-text-placeholder,oklch(.098 .023 157.4/.457));position:absolute;white-space:pre-wrap;padding-left:var(--intergalactic-spacing-4x,16px);text-indent:calc(var(--intergalactic-spacing-4x, 16px)*-1)}.___SInputField_q6qxb_gg_>ol>li{counter-increment:list-counter;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_q6qxb_gg_>ol>li:last-of-type{margin-bottom:0}.___SInputField_q6qxb_gg_>ol>li:before{content:counter(list-counter) \".\";position:absolute;left:0;white-space:nowrap;display:inline-block;text-align:right;color:var(--intergalactic-text-secondary,#00030095);margin-right:var(--intergalactic-spacing-1x,4px);font-feature-settings:normal;font-variant-numeric:normal;font-weight:300}@media (color-gamut:p3){.___SInputField_q6qxb_gg_>ol>li:before{color:var(--intergalactic-text-secondary,oklch(.088 .026 147.7/.583))}}.___SInputField_q6qxb_gg_>ol>li[data-over-max-rows=true]{background-color:var(--intergalactic-bg-secondary-critical,#ffebef)}@media (color-gamut:rec2020){.___SInputField_q6qxb_gg_>ol>li[data-over-max-rows=true]{background-color:var(--intergalactic-bg-secondary-critical,oklch(.958 .029 5.7))}}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+10))>li{padding-left:var(--intergalactic-spacing-6x,24px)}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+10))>li:nth-child(-n+9):before{padding-left:var(--intergalactic-spacing-2x,8px)}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+100))>li{padding-left:var(--intergalactic-spacing-8x,32px)}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+100))>li:nth-child(-n+9):before{padding-left:var(--intergalactic-spacing-4x,16px)}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+100))>li:nth-child(n+10):before{padding-left:var(--intergalactic-spacing-2x,8px)}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+100))>li:nth-child(n+100):before{padding-left:0}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+1000))>li{padding-left:calc(var(--intergalactic-spacing-10x, 40px) + var(--intergalactic-spacing-1x, 4px))}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+1000))>li:nth-child(-n+9):before{padding-left:var(--intergalactic-spacing-6x,24px)}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+1000))>li:nth-child(n+10):before{padding-left:var(--intergalactic-spacing-4x,16px)}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+1000))>li:nth-child(n+100):before{padding-left:var(--intergalactic-spacing-2x,8px)}.___SInputField_q6qxb_gg_>ol:has(li:nth-child(n+1000))>li:nth-child(n+1000):before{padding-left:0}.___SInputField_q6qxb_gg_.__showErrors_q6qxb_gg_>ol[aria-invalid]>li[aria-invalid]:after{content:url(\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgZmlsbD0iI2QxMDAyZiIgdmlld0JveD0iMCAwIDE2IDE2Ij48cGF0aCBkPSJNNyA2aDJ2NEg3em0yIDd2LTJIN3YyeiIvPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgZD0iTTYuMTUyIDEuMTcyYy43MTktMS41NjMgMi45NzctMS41NjMgMy42OTYgMGw2LjA0MyAxMy4xNDFjLjM2My43OTEtLjIyNSAxLjY4Ny0xLjEwOSAxLjY4N0gxLjIxOGMtLjg4NCAwLTEuNDcyLS44OTYtMS4xMDktMS42ODd6bTcuMzc0IDEyLjgzN0w4IDEuOTkgMi40NzQgMTQuMDF6IiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz48L3N2Zz4=\");position:absolute;right:0;top:var(--intergalactic-spacing-05x,2px)}.___SInputField_q6qxb_gg_._size_m_q6qxb_gg_>ol{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_q6qxb)*20px);max-height:calc((var(--maxRows_q6qxb) - 1)*(20px + var(--intergalactic-spacing-1x, 4px)) + 18px)}.___SInputField_q6qxb_gg_._size_m_q6qxb_gg_>ol:empty{padding-left:var(--intergalactic-spacing-8x,32px)}.___SInputField_q6qxb_gg_._size_m_q6qxb_gg_>ol:empty:before{left:calc(var(--intergalactic-spacing-4x, 16px) + 1px)}.___SInputField_q6qxb_gg_._size_l_q6qxb_gg_>ol{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_q6qxb)*24px);max-height:calc((var(--maxRows_q6qxb) - 1)*(24px + var(--intergalactic-spacing-1x, 4px)) + 20px)}.___SInputField_q6qxb_gg_._size_l_q6qxb_gg_>ol:empty{padding-left:calc(var(--intergalactic-spacing-8x, 32px) + var(--intergalactic-spacing-05x, 2px))}.___SInputField_q6qxb_gg_._size_l_q6qxb_gg_>ol:empty:before{left:var(--intergalactic-spacing-4x,16px)}.___SInputField_q6qxb_gg_._state_normal_q6qxb_gg_:not(.__disabled_q6qxb_gg_)>ol:focus{border-color:var(--intergalactic-border-info-active,oklch(.7 .131 275.2));outline-color:var(--intergalactic-keyboard-focus-outline,#0020dd78);outline-style:solid;outline-width:2px;outline-offset:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;transition-property:outline-color,outline-width,outline-offset;outline-offset:0;transition-property:outline-color,outline-width}@media (color-gamut:p3){.___SInputField_q6qxb_gg_._state_normal_q6qxb_gg_:not(.__disabled_q6qxb_gg_)>ol:focus{outline-color:var(--intergalactic-keyboard-focus-outline,oklch(.424 .269 264.2/.469))}}.___SInputField_q6qxb_gg_._state_valid_q6qxb_gg_>ol{border-color:var(--intergalactic-border-success-active,#00b991)}@media (color-gamut:p3){.___SInputField_q6qxb_gg_._state_valid_q6qxb_gg_>ol{border-color:var(--intergalactic-border-success-active,oklch(.7 .166 170))}}.___SInputField_q6qxb_gg_._state_valid_q6qxb_gg_>ol:focus{border-color:var(--intergalactic-border-success-active,#00b991);outline-color:var(--intergalactic-keyboard-focus-outline,#0020dd78);outline-style:solid;outline-width:2px;outline-offset:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;transition-property:outline-color,outline-width,outline-offset;outline-offset:0;transition-property:outline-color,outline-width}@media (color-gamut:p3){.___SInputField_q6qxb_gg_._state_valid_q6qxb_gg_>ol:focus{border-color:var(--intergalactic-border-success-active,oklch(.7 .166 170));outline-color:var(--intergalactic-keyboard-focus-outline,oklch(.424 .269 264.2/.469))}}@supports (color:oklab(0% 0 0%)){.___SInputField_q6qxb_gg_._state_valid_q6qxb_gg_>ol:focus{outline-color:var(--intergalactic-keyboard-focus-valid-outline,#00be8e)}@media (color-gamut:p3){.___SInputField_q6qxb_gg_._state_valid_q6qxb_gg_>ol:focus{outline-color:var(--intergalactic-keyboard-focus-valid-outline,oklch(.711 .146 166.9))}}}.___SInputField_q6qxb_gg_._state_invalid_q6qxb_gg_>ol{border-color:var(--intergalactic-border-critical-active,#ff6364);background-image:var(--intergalactic-border-critical-pattern,repeating-linear-gradient(315deg,#ff6364 0,#ff6364 1px,#0000 0,#0000 50%));background-size:6px 6px;background-color:var(--intergalactic-bg-primary-neutral,oklch(1 0 0));border-bottom-left-radius:var(--intergalactic-control-rounded,6px);border-top-left-radius:var(--intergalactic-control-rounded,6px);background-repeat:repeat-y}@media (color-gamut:p3){.___SInputField_q6qxb_gg_._state_invalid_q6qxb_gg_>ol{border-color:var(--intergalactic-border-critical-active,oklch(.7 .21 23));background-image:var(--intergalactic-border-critical-pattern,repeating-linear-gradient(315deg,oklch(.7 .21 23) 0,oklch(.7 .21 23) 1px,#0000 0,#0000 50%))}}.___SInputField_q6qxb_gg_._state_invalid_q6qxb_gg_>ol:focus{border-color:var(--intergalactic-border-critical-active,#ff6364);outline-color:var(--intergalactic-keyboard-focus-outline,#0020dd78);outline-style:solid;outline-width:2px;outline-offset:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;transition-property:outline-color,outline-width,outline-offset;outline-offset:0;transition-property:outline-color,outline-width}@media (color-gamut:p3){.___SInputField_q6qxb_gg_._state_invalid_q6qxb_gg_>ol:focus{border-color:var(--intergalactic-border-critical-active,oklch(.7 .21 23));outline-color:var(--intergalactic-keyboard-focus-outline,oklch(.424 .269 264.2/.469))}}@supports (color:oklab(0% 0 0%)){.___SInputField_q6qxb_gg_._state_invalid_q6qxb_gg_>ol:focus{outline-color:var(--intergalactic-keyboard-focus-invalid-outline,oklch(.628 .257 28.9/.652))}}.___SInputField_q6qxb_gg_.__readonly_q6qxb_gg_>ol{background-color:var(--intergalactic-bg-secondary-neutral,oklch(.98 .001 180))}.___SInputField_q6qxb_gg_.__disabled_q6qxb_gg_>ol{opacity:var(--intergalactic-disabled-opacity,.4)}", /*__inner_css_end__*/"q6qxb_gg_"),
|
|
18
20
|
/*__reshadow_css_end__*/
|
|
19
21
|
{
|
|
20
|
-
"__SInputField": "
|
|
21
|
-
"_showErrors": "
|
|
22
|
-
"_readonly": "
|
|
23
|
-
"_disabled": "
|
|
24
|
-
"_size_m": "
|
|
25
|
-
"--minRows": "--
|
|
26
|
-
"--maxRows": "--
|
|
27
|
-
"_size_l": "
|
|
28
|
-
"_state_normal": "
|
|
29
|
-
"_state_valid": "
|
|
30
|
-
"_state_invalid": "
|
|
22
|
+
"__SInputField": "___SInputField_q6qxb_gg_",
|
|
23
|
+
"_showErrors": "__showErrors_q6qxb_gg_",
|
|
24
|
+
"_readonly": "__readonly_q6qxb_gg_",
|
|
25
|
+
"_disabled": "__disabled_q6qxb_gg_",
|
|
26
|
+
"_size_m": "_size_m_q6qxb_gg_",
|
|
27
|
+
"--minRows": "--minRows_q6qxb",
|
|
28
|
+
"--maxRows": "--maxRows_q6qxb",
|
|
29
|
+
"_size_l": "_size_l_q6qxb_gg_",
|
|
30
|
+
"_state_normal": "_state_normal_q6qxb_gg_",
|
|
31
|
+
"_state_valid": "_state_valid_q6qxb_gg_",
|
|
32
|
+
"_state_invalid": "_state_invalid_q6qxb_gg_"
|
|
31
33
|
});
|
|
32
34
|
class InputField extends _core.Component {
|
|
33
35
|
constructor(props) {
|
|
@@ -35,6 +37,7 @@ class InputField extends _core.Component {
|
|
|
35
37
|
(0, _defineProperty2.default)(this, "delimiter", '\n');
|
|
36
38
|
(0, _defineProperty2.default)(this, "skipEmptyLines", true);
|
|
37
39
|
(0, _defineProperty2.default)(this, "emptyLineValue", '');
|
|
40
|
+
(0, _defineProperty2.default)(this, "emptyLineValueJs", '\uFEFF');
|
|
38
41
|
(0, _defineProperty2.default)(this, "spaceLineValue", ' ');
|
|
39
42
|
(0, _defineProperty2.default)(this, "containerRef", /*#__PURE__*/_react.default.createRef());
|
|
40
43
|
(0, _defineProperty2.default)(this, "textarea", void 0);
|
|
@@ -48,6 +51,7 @@ class InputField extends _core.Component {
|
|
|
48
51
|
(0, _defineProperty2.default)(this, "isFocusing", false);
|
|
49
52
|
(0, _defineProperty2.default)(this, "linesCountTimeout", 0);
|
|
50
53
|
(0, _defineProperty2.default)(this, "observer", void 0);
|
|
54
|
+
(0, _defineProperty2.default)(this, "history", new _History.History());
|
|
51
55
|
(0, _defineProperty2.default)(this, "state", {
|
|
52
56
|
visibleErrorPopper: false,
|
|
53
57
|
keyboardLineIndex: -1,
|
|
@@ -55,6 +59,8 @@ class InputField extends _core.Component {
|
|
|
55
59
|
});
|
|
56
60
|
this.handlePaste = this.handlePaste.bind(this);
|
|
57
61
|
this.handleChange = this.handleChange.bind(this);
|
|
62
|
+
this.handleCompositionTextStart = this.handleCompositionTextStart.bind(this);
|
|
63
|
+
this.handleCompositionTextEnd = this.handleCompositionTextEnd.bind(this);
|
|
58
64
|
this.handleFocus = this.handleFocus.bind(this);
|
|
59
65
|
this.handleBlur = this.handleBlur.bind(this);
|
|
60
66
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
@@ -64,7 +70,7 @@ class InputField extends _core.Component {
|
|
|
64
70
|
this.handleScroll = this.handleScroll.bind(this);
|
|
65
71
|
this.handleSelectAll = this.handleSelectAll.bind(this);
|
|
66
72
|
this.textarea = this.createContentEditableElement(props);
|
|
67
|
-
this.observer = new MutationObserver(
|
|
73
|
+
this.observer = new MutationObserver(mutationsList => {
|
|
68
74
|
for (const mutation of mutationsList) {
|
|
69
75
|
if (mutation.type === 'characterData' || mutation.type === 'childList') {
|
|
70
76
|
this.props.onImmediatelyChange?.(this.getValues(), this.textarea.textContent ?? '');
|
|
@@ -81,12 +87,13 @@ class InputField extends _core.Component {
|
|
|
81
87
|
}
|
|
82
88
|
componentDidMount() {
|
|
83
89
|
const {
|
|
90
|
+
value,
|
|
84
91
|
autoFocus,
|
|
85
92
|
disabled
|
|
86
93
|
} = this.asProps;
|
|
87
94
|
this.textarea = this.createContentEditableElement(this.asProps);
|
|
88
95
|
this.containerRef.current?.append(this.textarea);
|
|
89
|
-
this.handleValueOutChange();
|
|
96
|
+
this.handleValueOutChange(value);
|
|
90
97
|
const config = {
|
|
91
98
|
childList: true,
|
|
92
99
|
characterData: true,
|
|
@@ -116,8 +123,8 @@ class InputField extends _core.Component {
|
|
|
116
123
|
} = this.props;
|
|
117
124
|
if (prevProps.value !== value) {
|
|
118
125
|
const currentValue = this.getValues().join(this.delimiter);
|
|
119
|
-
if (typeof value === 'string' ? value !== currentValue : value
|
|
120
|
-
this.handleValueOutChange();
|
|
126
|
+
if (typeof value === 'string' ? value !== currentValue : value?.join(this.delimiter) !== currentValue) {
|
|
127
|
+
this.handleValueOutChange(value);
|
|
121
128
|
}
|
|
122
129
|
}
|
|
123
130
|
if (prevProps.showErrors !== showErrors || prevProps.errors !== errors) {
|
|
@@ -127,14 +134,14 @@ class InputField extends _core.Component {
|
|
|
127
134
|
errorsMap.set(error.lineIndex, error);
|
|
128
135
|
});
|
|
129
136
|
this.textarea.childNodes.forEach((node, index) => {
|
|
130
|
-
if (node instanceof
|
|
137
|
+
if (node instanceof HTMLLIElement) {
|
|
131
138
|
const errorItem = errorsMap.get(index);
|
|
132
139
|
if (errorItem) {
|
|
133
140
|
node.setAttribute('aria-invalid', 'true');
|
|
134
141
|
node.dataset.errormessage = errorItem.errorMessage;
|
|
135
142
|
} else {
|
|
136
143
|
node.removeAttribute('aria-invalid');
|
|
137
|
-
node.dataset.errormessage
|
|
144
|
+
delete node.dataset.errormessage;
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
147
|
});
|
|
@@ -170,26 +177,29 @@ class InputField extends _core.Component {
|
|
|
170
177
|
const newValue = lineProcessing(lines[prevState.keyboardLineIndex] ?? '', lines);
|
|
171
178
|
const newValueTextNode = document.createTextNode(newValue);
|
|
172
179
|
const paragraph = this.textarea.childNodes.item(prevState.keyboardLineIndex);
|
|
173
|
-
if (paragraph instanceof
|
|
180
|
+
if (paragraph instanceof HTMLLIElement) {
|
|
174
181
|
if (newValue === '') {
|
|
175
|
-
|
|
182
|
+
if (lines.length === 1) {
|
|
183
|
+
this.textarea.textContent = '';
|
|
184
|
+
} else {
|
|
185
|
+
paragraph.innerHTML = this.emptyLineValue;
|
|
186
|
+
}
|
|
176
187
|
} else {
|
|
177
188
|
paragraph.replaceChild(newValueTextNode, paragraph.childNodes.item(0));
|
|
178
189
|
}
|
|
190
|
+
this.validateLine(paragraph);
|
|
179
191
|
}
|
|
180
|
-
this.validateLine(paragraph);
|
|
181
|
-
setTimeout(() => {
|
|
182
|
-
const newNode = this.textarea.childNodes.item(keyboardLineIndex);
|
|
183
|
-
if (newNode) {
|
|
184
|
-
this.setErrorIndex(newNode);
|
|
185
|
-
}
|
|
186
|
-
}, 0); // need this timeout to update errorIndex to the new (usually empty) line
|
|
187
|
-
}
|
|
188
|
-
if (!showErrors) {
|
|
189
|
-
this.recalculateErrors();
|
|
190
192
|
}
|
|
193
|
+
setTimeout(() => {
|
|
194
|
+
const newNode = this.textarea.childNodes.item(keyboardLineIndex);
|
|
195
|
+
if (newNode) {
|
|
196
|
+
this.setErrorIndex(newNode);
|
|
197
|
+
}
|
|
198
|
+
}, 0); // need this timeout to update errorIndex to the new (usually empty) line
|
|
199
|
+
|
|
200
|
+
this.recalculateErrors();
|
|
191
201
|
this.recalculateLinesCount();
|
|
192
|
-
this.asProps.onChangeLineIndex(
|
|
202
|
+
this.asProps.onChangeLineIndex();
|
|
193
203
|
}
|
|
194
204
|
}
|
|
195
205
|
componentWillUnmount() {
|
|
@@ -235,15 +245,14 @@ class InputField extends _core.Component {
|
|
|
235
245
|
};
|
|
236
246
|
}
|
|
237
247
|
createContentEditableElement(props) {
|
|
238
|
-
const textarea = document.createElement('
|
|
248
|
+
const textarea = document.createElement('ol');
|
|
239
249
|
textarea.setAttribute('contentEditable', props.disabled || props.readonly ? 'false' : 'true');
|
|
240
|
-
textarea.setAttribute('role', 'textbox');
|
|
241
250
|
textarea.setAttribute('classname', 'editable');
|
|
242
251
|
if (props.id) {
|
|
243
252
|
textarea.setAttribute('id', props.id);
|
|
244
253
|
}
|
|
245
254
|
if (props.placeholder) {
|
|
246
|
-
textarea.
|
|
255
|
+
textarea.dataset.placeholder = Array.isArray(props.placeholder) ? props.placeholder.join('\n') : props.placeholder;
|
|
247
256
|
}
|
|
248
257
|
const {
|
|
249
258
|
extractedAriaProps
|
|
@@ -266,12 +275,36 @@ class InputField extends _core.Component {
|
|
|
266
275
|
}
|
|
267
276
|
return textarea;
|
|
268
277
|
}
|
|
269
|
-
|
|
278
|
+
focus(node, offset) {
|
|
279
|
+
this.textarea.focus();
|
|
280
|
+
if (node && offset !== undefined) {
|
|
281
|
+
const startOffset = Array.isArray(offset) ? offset[0] : offset;
|
|
282
|
+
const endOffset = Array.isArray(offset) ? offset[1] : offset;
|
|
283
|
+
this.setSelection(node, startOffset, endOffset);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async addLine(value) {
|
|
287
|
+
return new Promise(resolve => {
|
|
288
|
+
const row = document.createElement('li');
|
|
289
|
+
if (value === '') {
|
|
290
|
+
row.innerHTML = this.emptyLineValue;
|
|
291
|
+
} else {
|
|
292
|
+
row.textContent = value;
|
|
293
|
+
}
|
|
294
|
+
const lastRow = this.textarea.lastChild;
|
|
295
|
+
if (lastRow instanceof HTMLLIElement) {
|
|
296
|
+
lastRow.after(row);
|
|
297
|
+
} else {
|
|
298
|
+
this.textarea.append(row);
|
|
299
|
+
}
|
|
300
|
+
resolve(row);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
handleValueOutChange(value) {
|
|
270
304
|
const {
|
|
271
|
-
value,
|
|
272
305
|
onChangeLinesCount
|
|
273
306
|
} = this.props;
|
|
274
|
-
if (value === '') {
|
|
307
|
+
if (value === '' || value === undefined) {
|
|
275
308
|
this.textarea.textContent = '';
|
|
276
309
|
onChangeLinesCount(0);
|
|
277
310
|
} else {
|
|
@@ -329,173 +362,104 @@ class InputField extends _core.Component {
|
|
|
329
362
|
}
|
|
330
363
|
}
|
|
331
364
|
handlePaste(event) {
|
|
365
|
+
this.history.push(this.createHistoryState());
|
|
366
|
+
this.insertFromPaste(event);
|
|
367
|
+
this.asProps.onPaste();
|
|
368
|
+
}
|
|
369
|
+
handleCompositionTextStart() {
|
|
370
|
+
this.history.push(this.createHistoryState());
|
|
371
|
+
}
|
|
372
|
+
handleCompositionTextEnd(event) {
|
|
332
373
|
event.preventDefault();
|
|
333
|
-
const {
|
|
334
|
-
validateOn
|
|
335
|
-
} = this.asProps;
|
|
336
|
-
const value = event.clipboardData?.getData('text/plain');
|
|
337
|
-
const listOfNodes = value ? this.prepareNodesForPaste(value) : [];
|
|
338
|
-
if (listOfNodes.length === 0) return;
|
|
339
374
|
const selection = document.getSelection();
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
let textNode = null;
|
|
352
|
-
let position = null;
|
|
353
|
-
if (focusElement === this.textarea) {
|
|
354
|
-
this.textarea.replaceChildren(...listOfNodes);
|
|
355
|
-
const lastNodeToInsert = listOfNodes[listOfNodes.length - 1];
|
|
356
|
-
textNode = lastNodeToInsert.childNodes.item(0);
|
|
357
|
-
position = (lastNodeToInsert.textContent ?? '').length;
|
|
358
|
-
} else if (focusNode instanceof HTMLParagraphElement && anchorNode instanceof HTMLParagraphElement) {
|
|
359
|
-
const before = anchorNode?.textContent?.substring(0, fromOffset) ?? '';
|
|
360
|
-
const after = focusNode?.textContent?.substring(toOffset) ?? '';
|
|
361
|
-
const noEmptyLineBefore = before.trim() === '' ? '' : before;
|
|
362
|
-
const noEmptyLineAfter = after.trim() === '' ? '' : after;
|
|
363
|
-
selection.deleteFromDocument();
|
|
364
|
-
if (documentPosition !== 0) {
|
|
365
|
-
this.textarea.removeChild(focusNode);
|
|
366
|
-
}
|
|
367
|
-
const firstNodeToInsert = listOfNodes.splice(0, 1)[0];
|
|
368
|
-
const lastNodeToInsert = listOfNodes[listOfNodes.length - 1];
|
|
369
|
-
anchorNode.textContent = noEmptyLineBefore + (firstNodeToInsert?.textContent ?? '');
|
|
370
|
-
anchorNode.after(...listOfNodes);
|
|
371
|
-
if (lastNodeToInsert) {
|
|
372
|
-
lastNodeToInsert.textContent = (lastNodeToInsert.textContent ?? '') + noEmptyLineAfter;
|
|
373
|
-
textNode = lastNodeToInsert.childNodes.item(0);
|
|
374
|
-
position = (lastNodeToInsert.textContent ?? '').length;
|
|
375
|
-
this.validateLine(lastNodeToInsert);
|
|
376
|
-
this.setErrorIndex(lastNodeToInsert);
|
|
377
|
-
} else {
|
|
378
|
-
position = (anchorNode.textContent ?? '').length;
|
|
379
|
-
anchorNode.textContent = (anchorNode.textContent ?? '') + noEmptyLineAfter;
|
|
380
|
-
textNode = anchorNode.childNodes.item(0);
|
|
381
|
-
this.validateLine(anchorNode);
|
|
382
|
-
this.setErrorIndex(anchorNode);
|
|
375
|
+
|
|
376
|
+
// FF and Safari
|
|
377
|
+
if (selection?.focusNode === this.textarea) {
|
|
378
|
+
const nodes = this.textarea.childNodes;
|
|
379
|
+
const liElement = nodes.length === 1 ? nodes.item(0) : nodes.length === 2 ? nodes.item(1) : null;
|
|
380
|
+
if (selection && liElement instanceof HTMLLIElement) {
|
|
381
|
+
const offset = selection.focusOffset;
|
|
382
|
+
liElement.textContent = (liElement.textContent ?? '').split('').filter(s => s !== this.emptyLineValueJs).join('') + event.data;
|
|
383
|
+
selection.setPosition(liElement.firstChild, offset + event.data.length);
|
|
384
|
+
if (nodes.item(0) instanceof HTMLBRElement) {
|
|
385
|
+
this.textarea.removeChild(nodes.item(0));
|
|
383
386
|
}
|
|
384
387
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
388
|
+
} else {
|
|
389
|
+
const liElement = selection?.focusNode?.parentElement;
|
|
390
|
+
if (selection && liElement instanceof HTMLLIElement) {
|
|
391
|
+
const offset = selection.focusOffset;
|
|
392
|
+
liElement.textContent = (liElement.textContent ?? '').split('').filter(s => s !== this.emptyLineValueJs).join('');
|
|
393
|
+
selection.setPosition(liElement.firstChild, offset);
|
|
391
394
|
}
|
|
392
395
|
}
|
|
393
|
-
|
|
394
|
-
if (validateOn.includes('paste') || this.asProps.showErrors) {
|
|
396
|
+
setTimeout(() => {
|
|
395
397
|
this.recalculateErrors();
|
|
396
|
-
}
|
|
398
|
+
}, 0);
|
|
399
|
+
this.toggleErrorsPopperByKeyboard(0);
|
|
400
|
+
this.recalculateLinesCount();
|
|
397
401
|
}
|
|
398
402
|
handleChange(event) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
keyboardLineIndex: 0
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
let maxDeep = 10;
|
|
426
|
-
let rowNode = selection?.focusNode;
|
|
427
|
-
while (rowNode?.parentNode !== this.textarea && maxDeep > 0) {
|
|
428
|
-
rowNode = rowNode?.parentNode;
|
|
429
|
-
maxDeep--;
|
|
430
|
-
}
|
|
431
|
-
if (rowNode instanceof HTMLParagraphElement) {
|
|
432
|
-
const childNodes = rowNode.childNodes;
|
|
433
|
-
const textContent = rowNode.textContent ?? '';
|
|
434
|
-
if (childNodes.length > 1) {
|
|
435
|
-
const offset = childNodes.item(0).textContent?.length;
|
|
436
|
-
rowNode.textContent = textContent;
|
|
437
|
-
if (offset) {
|
|
438
|
-
this.setSelection(rowNode.childNodes.item(0), offset, offset);
|
|
403
|
+
event.preventDefault();
|
|
404
|
+
const data = event.data ?? '';
|
|
405
|
+
const staticRange = event.getTargetRanges()?.[0];
|
|
406
|
+
if (!staticRange) {
|
|
407
|
+
_logger.default.warn(true, `No staticRange in event: `, event);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const [start, end] = this.getRangeTextNodes(staticRange);
|
|
411
|
+
const range = {
|
|
412
|
+
startElement: start[0],
|
|
413
|
+
endElement: end[0],
|
|
414
|
+
startOffset: start[1],
|
|
415
|
+
endOffset: end[1]
|
|
416
|
+
};
|
|
417
|
+
switch (event.inputType) {
|
|
418
|
+
case 'insertFromComposition':
|
|
419
|
+
case 'insertText':
|
|
420
|
+
{
|
|
421
|
+
this.history.push(this.createHistoryState());
|
|
422
|
+
if (this.asProps.linesDelimiters?.includes(data)) {
|
|
423
|
+
this.insertParagraph(range);
|
|
424
|
+
return;
|
|
439
425
|
}
|
|
426
|
+
this.insertText(data, range);
|
|
427
|
+
break;
|
|
440
428
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
} else if (lastSymbol === this.getEmptyParagraph().textContent) {
|
|
450
|
-
rowNode.textContent = textContent.substring(0, textContent.length - 1);
|
|
451
|
-
offset = rowNode.textContent.length;
|
|
452
|
-
}
|
|
453
|
-
if (offset) {
|
|
454
|
-
this.setSelection(rowNode.childNodes.item(0), offset, offset);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
} else if (childNodes.length === 1 && childNodes[0] instanceof HTMLBRElement) {
|
|
458
|
-
rowNode.innerHTML = this.emptyLineValue;
|
|
429
|
+
case 'insertCompositionText':
|
|
430
|
+
case 'deleteCompositionText':
|
|
431
|
+
case 'historyUndo':
|
|
432
|
+
case 'historyRedo':
|
|
433
|
+
case 'insertFromPaste':
|
|
434
|
+
{
|
|
435
|
+
// handled by native events
|
|
436
|
+
return;
|
|
459
437
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
this.recalculateErrors();
|
|
466
|
-
this.setErrorIndex(rowNode);
|
|
467
|
-
if (!isValid && showErrors) {
|
|
468
|
-
this.toggleErrorsPopper('keyboardLineIndex', rowNode, 0);
|
|
438
|
+
case 'insertParagraph':
|
|
439
|
+
{
|
|
440
|
+
this.history.push(this.createHistoryState());
|
|
441
|
+
this.insertParagraph(range);
|
|
442
|
+
break;
|
|
469
443
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
});
|
|
478
|
-
}
|
|
444
|
+
case 'deleteContentForward':
|
|
445
|
+
case 'deleteContentBackward':
|
|
446
|
+
case 'deleteByCut':
|
|
447
|
+
{
|
|
448
|
+
this.history.push(this.createHistoryState());
|
|
449
|
+
this.deleteText(range, event.inputType);
|
|
450
|
+
break;
|
|
479
451
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
const nodeIndex = selection.focusOffset;
|
|
484
|
-
const emptyParagraph = this.textarea.childNodes.item(nodeIndex - 1);
|
|
485
|
-
const emptyBr = this.textarea.childNodes.item(nodeIndex);
|
|
486
|
-
this.textarea.removeChild(emptyBr);
|
|
487
|
-
if (emptyParagraph instanceof HTMLParagraphElement) {
|
|
488
|
-
emptyParagraph.innerHTML = this.emptyLineValue;
|
|
489
|
-
}
|
|
490
|
-
if (emptyParagraph) {
|
|
491
|
-
this.setSelection(emptyParagraph, 0, 0);
|
|
492
|
-
}
|
|
493
|
-
} else {
|
|
494
|
-
this.setSelection(this.textarea, 0, 0);
|
|
452
|
+
default:
|
|
453
|
+
{
|
|
454
|
+
_logger.default.warn(true, `Unknown input type "${event.inputType}"`, event);
|
|
495
455
|
}
|
|
496
|
-
}
|
|
497
|
-
this.recalculateLinesCount();
|
|
498
456
|
}
|
|
457
|
+
setTimeout(() => {
|
|
458
|
+
this.recalculateErrors();
|
|
459
|
+
}, 0);
|
|
460
|
+
this.toggleErrorsPopperByKeyboard(0);
|
|
461
|
+
this.recalculateLinesCount();
|
|
462
|
+
return;
|
|
499
463
|
}
|
|
500
464
|
handleFocus() {
|
|
501
465
|
this.isFocusing = true;
|
|
@@ -522,157 +486,36 @@ class InputField extends _core.Component {
|
|
|
522
486
|
const valueToChange = typeof value === 'string' ? this.getValues().join(this.delimiter) : this.getValues();
|
|
523
487
|
onBlur(valueToChange, event);
|
|
524
488
|
setTimeout(() => {
|
|
525
|
-
this.
|
|
526
|
-
|
|
527
|
-
|
|
489
|
+
if (document.activeElement !== this.textarea) {
|
|
490
|
+
this.setState({
|
|
491
|
+
keyboardLineIndex: -1
|
|
492
|
+
});
|
|
493
|
+
}
|
|
528
494
|
}, 200);
|
|
529
495
|
}
|
|
530
496
|
handleKeyDown(event) {
|
|
531
497
|
this.errorByInteraction = 'keyboard';
|
|
532
|
-
const {
|
|
533
|
-
linesDelimiters
|
|
534
|
-
} = this.asProps;
|
|
535
498
|
const currentNode = this.getNodeFromSelection();
|
|
536
|
-
if (event.key === '
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
if (currentNode instanceof
|
|
541
|
-
const currentRowValue = currentNode.textContent?.trim();
|
|
542
|
-
if (!currentRowValue) {
|
|
543
|
-
event.preventDefault();
|
|
544
|
-
} else {
|
|
545
|
-
event.preventDefault();
|
|
546
|
-
const selection = document.getSelection();
|
|
547
|
-
const selectionNode = selection?.focusNode instanceof Text ? selection.focusNode : selection?.focusNode?.childNodes.item(0);
|
|
548
|
-
const selectionOffset = selection?.focusOffset;
|
|
549
|
-
let newRowValue = '';
|
|
550
|
-
if (selectionNode instanceof Text && selectionOffset !== undefined && selectionOffset !== selectionNode.textContent?.length) {
|
|
551
|
-
newRowValue = selectionNode.textContent?.substring(selectionOffset) ?? this.emptyLineValue;
|
|
552
|
-
if (selectionNode.textContent) {
|
|
553
|
-
selectionNode.textContent = selectionNode.textContent.substring(0, selectionOffset);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
if (currentNode.textContent?.trim() === '') {
|
|
557
|
-
currentNode.innerHTML = this.emptyLineValue;
|
|
558
|
-
}
|
|
559
|
-
const row = document.createElement('p');
|
|
560
|
-
if (newRowValue) {
|
|
561
|
-
row.textContent = newRowValue;
|
|
562
|
-
} else {
|
|
563
|
-
row.innerHTML = this.emptyLineValue;
|
|
564
|
-
}
|
|
565
|
-
currentNode.after(row);
|
|
566
|
-
this.setSelection(row, 0, 0);
|
|
567
|
-
this.validateLine(currentNode);
|
|
568
|
-
this.validateLine(row);
|
|
569
|
-
if (currentNode.previousSibling) {
|
|
570
|
-
this.validateLine(currentNode.previousSibling);
|
|
571
|
-
}
|
|
572
|
-
this.setErrorIndex(row);
|
|
573
|
-
if (row.textContent?.trim() !== '') {
|
|
574
|
-
this.recalculateLinesCount();
|
|
575
|
-
}
|
|
576
|
-
setTimeout(() => {
|
|
577
|
-
this.recalculateErrors();
|
|
578
|
-
}, 0);
|
|
579
|
-
this.toggleErrorsPopperByKeyboard(0);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
} else if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
|
|
583
|
-
if (currentNode instanceof HTMLParagraphElement) {
|
|
499
|
+
if (event.key === 'Tab' && currentNode instanceof HTMLLIElement) {
|
|
500
|
+
this.validateLine(currentNode);
|
|
501
|
+
}
|
|
502
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
|
|
503
|
+
if (currentNode instanceof HTMLLIElement) {
|
|
584
504
|
this.handleCursorMovement(currentNode, event);
|
|
585
505
|
}
|
|
586
506
|
this.toggleErrorsPopperByKeyboard(200);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
} else {
|
|
599
|
-
if (prevNode instanceof HTMLParagraphElement) {
|
|
600
|
-
const text = prevNode.childNodes.item(0);
|
|
601
|
-
const offset = text.textContent?.length ?? 0;
|
|
602
|
-
this.setSelection(text, offset, offset);
|
|
603
|
-
} else {
|
|
604
|
-
// eslint-disable-next-line no-console
|
|
605
|
-
console.warn('incorrect prevNode type', prevNode);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
setTimeout(() => {
|
|
609
|
-
this.recalculateErrors();
|
|
610
|
-
}, 0);
|
|
611
|
-
this.toggleErrorsPopperByKeyboard(0);
|
|
612
|
-
}
|
|
613
|
-
} else if (this.isRangeSelection()) {
|
|
614
|
-
const selection = document.getSelection();
|
|
615
|
-
const direction = this.getSelectionDirection();
|
|
616
|
-
const anchorElement = direction === 'backward' ? selection?.focusNode : selection?.anchorNode;
|
|
617
|
-
const focusElement = direction === 'backward' ? selection?.anchorNode : selection?.focusNode;
|
|
618
|
-
const anchorOffset = direction === 'backward' ? selection?.focusOffset : selection?.anchorOffset;
|
|
619
|
-
const focusOffset = direction === 'backward' ? selection?.anchorOffset : selection?.focusOffset;
|
|
620
|
-
|
|
621
|
-
// Backspace on selected full row
|
|
622
|
-
if (anchorElement === focusElement && anchorOffset === 0 && (focusElement === currentNode && focusOffset === 1 || focusOffset === currentNode.textContent?.length)) {
|
|
623
|
-
event.preventDefault();
|
|
624
|
-
const anchorParagraph = anchorElement?.parentElement;
|
|
625
|
-
const focusParagraph = focusElement?.parentElement;
|
|
626
|
-
const childNodes = this.textarea.childNodes;
|
|
627
|
-
if (anchorParagraph === childNodes.item(0) && focusParagraph === childNodes.item(childNodes.length - 1)) {
|
|
628
|
-
this.textarea.textContent = '';
|
|
629
|
-
this.setSelection(this.textarea, 0, 0);
|
|
630
|
-
} else {
|
|
631
|
-
currentNode.innerHTML = this.emptyLineValue;
|
|
632
|
-
this.validateLine(currentNode);
|
|
633
|
-
}
|
|
634
|
-
this.setErrorIndex(currentNode);
|
|
635
|
-
this.recalculateLinesCount();
|
|
636
|
-
setTimeout(() => {
|
|
637
|
-
this.recalculateErrors();
|
|
638
|
-
}, 0);
|
|
639
|
-
this.toggleErrorsPopperByKeyboard(0);
|
|
640
|
-
} 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) {
|
|
641
|
-
// Backspace on selected few full rows
|
|
642
|
-
event.preventDefault();
|
|
643
|
-
const paragraphs = Array.from(this.textarea.children);
|
|
644
|
-
const anchorParagraph = anchorElement.parentElement;
|
|
645
|
-
const focusParagraph = focusElement.parentElement;
|
|
646
|
-
const childNodes = this.textarea.childNodes;
|
|
647
|
-
if (anchorParagraph === childNodes.item(0) && focusParagraph === childNodes.item(childNodes.length - 1)) {
|
|
648
|
-
this.textarea.textContent = '';
|
|
649
|
-
this.setSelection(this.textarea, 0, 0);
|
|
650
|
-
} else {
|
|
651
|
-
let isCleaning = false;
|
|
652
|
-
for (const paragraph of paragraphs) {
|
|
653
|
-
if (paragraph === anchorParagraph || isCleaning) {
|
|
654
|
-
isCleaning = true;
|
|
655
|
-
if (paragraph === focusParagraph) {
|
|
656
|
-
focusParagraph.innerHTML = this.emptyLineValue;
|
|
657
|
-
this.setSelection(focusParagraph, 0, 0);
|
|
658
|
-
break;
|
|
659
|
-
} else {
|
|
660
|
-
this.textarea.removeChild(paragraph);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
this.validateLine(currentNode);
|
|
665
|
-
}
|
|
666
|
-
this.setErrorIndex(currentNode);
|
|
667
|
-
this.recalculateLinesCount();
|
|
668
|
-
setTimeout(() => {
|
|
669
|
-
this.recalculateErrors();
|
|
670
|
-
}, 0);
|
|
671
|
-
this.toggleErrorsPopperByKeyboard(0);
|
|
672
|
-
}
|
|
507
|
+
}
|
|
508
|
+
if (event.key === 'z' && !event.shiftKey && (event.ctrlKey || event.metaKey)) {
|
|
509
|
+
const data = this.history.undo(this.createHistoryState());
|
|
510
|
+
if (data) {
|
|
511
|
+
this.restoreHistoryState(data);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if ((event.key === 'z' && event.shiftKey || event.key === 'y') && (event.ctrlKey || event.metaKey)) {
|
|
515
|
+
const data = this.history.redo(this.createHistoryState());
|
|
516
|
+
if (data) {
|
|
517
|
+
this.restoreHistoryState(data);
|
|
673
518
|
}
|
|
674
|
-
} else if (event.key === 'z' && (event.ctrlKey || event.metaKey)) {
|
|
675
|
-
event.preventDefault();
|
|
676
519
|
}
|
|
677
520
|
}
|
|
678
521
|
render() {
|
|
@@ -723,6 +566,303 @@ class InputField extends _core.Component {
|
|
|
723
566
|
}, _ref)
|
|
724
567
|
})));
|
|
725
568
|
}
|
|
569
|
+
insertText(data, range) {
|
|
570
|
+
const {
|
|
571
|
+
startElement,
|
|
572
|
+
endElement,
|
|
573
|
+
startOffset,
|
|
574
|
+
endOffset
|
|
575
|
+
} = range;
|
|
576
|
+
if (startElement === endElement && startOffset === endOffset && startElement.textContent === this.emptyLineValueJs) {
|
|
577
|
+
startElement.textContent = data;
|
|
578
|
+
this.setSelection(startElement, data.length, data.length);
|
|
579
|
+
} else {
|
|
580
|
+
const resultText = `${startElement.textContent.slice(0, range.startOffset)}${data}${endElement.textContent.slice(range.endOffset)}`;
|
|
581
|
+
|
|
582
|
+
// we need to clear empty value in the line node, because this is unnecessary symbol in the next calculations
|
|
583
|
+
startElement.textContent = startElement.textContent === this.emptyLineValueJs ? resultText.slice(0, -1) : resultText;
|
|
584
|
+
this.setSelection(startElement, range.startOffset + 1, range.startOffset + 1);
|
|
585
|
+
}
|
|
586
|
+
if (startElement.parentElement instanceof HTMLLIElement) {
|
|
587
|
+
this.validateLine(startElement.parentElement);
|
|
588
|
+
this.setErrorIndex(startElement.parentElement);
|
|
589
|
+
}
|
|
590
|
+
if (startElement !== endElement) {
|
|
591
|
+
this.clearNodes(startElement, endElement);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
insertParagraph(range) {
|
|
595
|
+
let startElement = range.startElement;
|
|
596
|
+
const endElement = range.endElement;
|
|
597
|
+
const parent = startElement.parentElement;
|
|
598
|
+
if (parent instanceof HTMLLIElement) {
|
|
599
|
+
const currentLineText = startElement.textContent.slice(0, range.startOffset);
|
|
600
|
+
const newLineText = endElement.textContent.slice(range.endOffset);
|
|
601
|
+
startElement.textContent = currentLineText;
|
|
602
|
+
if (startElement.textContent === '') {
|
|
603
|
+
parent.innerHTML = this.emptyLineValue;
|
|
604
|
+
startElement = parent.childNodes.item(0);
|
|
605
|
+
}
|
|
606
|
+
if (startElement !== endElement && endElement.parentElement) {
|
|
607
|
+
this.clearNodes(startElement, endElement);
|
|
608
|
+
}
|
|
609
|
+
const row = document.createElement('li');
|
|
610
|
+
if (newLineText === '') {
|
|
611
|
+
row.innerHTML = this.emptyLineValue;
|
|
612
|
+
} else {
|
|
613
|
+
row.textContent = newLineText;
|
|
614
|
+
}
|
|
615
|
+
parent.after(row);
|
|
616
|
+
this.setSelection(row, 0, 0);
|
|
617
|
+
this.validateLine(parent);
|
|
618
|
+
if (newLineText !== '') {
|
|
619
|
+
this.validateLine(row);
|
|
620
|
+
}
|
|
621
|
+
this.setErrorIndex(parent);
|
|
622
|
+
} else {
|
|
623
|
+
_logger.default.warn(true, `Not texts in start/end`, {
|
|
624
|
+
startElement,
|
|
625
|
+
endElement
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
deleteText(range, inputType) {
|
|
630
|
+
let startElement = range.startElement;
|
|
631
|
+
const endElement = range.endElement;
|
|
632
|
+
const parent = startElement.parentElement;
|
|
633
|
+
if (parent instanceof HTMLLIElement) {
|
|
634
|
+
let resultText = '';
|
|
635
|
+
if (!(range.startElement instanceof HTMLOListElement) && !(range.endElement instanceof HTMLOListElement)) {
|
|
636
|
+
resultText = `${startElement.textContent === this.emptyLineValueJs ? '' : startElement.textContent.slice(0, range.startOffset)}${endElement.textContent === this.emptyLineValueJs ? '' : endElement.textContent.slice(range.endOffset)}`;
|
|
637
|
+
}
|
|
638
|
+
if (resultText === '' && endElement.textContent === this.emptyLineValueJs) {
|
|
639
|
+
const next = parent.nextSibling;
|
|
640
|
+
const prev = parent.previousSibling;
|
|
641
|
+
if (inputType === 'deleteContentForward' && next) {
|
|
642
|
+
this.textarea.removeChild(parent);
|
|
643
|
+
document.getSelection()?.setPosition(next, 0);
|
|
644
|
+
} else if (inputType === 'deleteContentBackward' && prev) {
|
|
645
|
+
if (startElement === endElement) {
|
|
646
|
+
if (prev.textContent === this.emptyLineValueJs) {
|
|
647
|
+
document.getSelection()?.setPosition(prev, 0);
|
|
648
|
+
} else {
|
|
649
|
+
document.getSelection()?.setPosition(prev, 1);
|
|
650
|
+
}
|
|
651
|
+
this.textarea.removeChild(parent);
|
|
652
|
+
} else {
|
|
653
|
+
document.getSelection()?.setPosition(startElement, 0);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
} else {
|
|
657
|
+
if (resultText === '') {
|
|
658
|
+
parent.innerHTML = this.emptyLineValue;
|
|
659
|
+
startElement = parent.childNodes.item(0);
|
|
660
|
+
} else {
|
|
661
|
+
startElement.textContent = resultText;
|
|
662
|
+
}
|
|
663
|
+
document.getSelection()?.setPosition(startElement, range.startElement instanceof HTMLOListElement ? 0 : range.startOffset);
|
|
664
|
+
}
|
|
665
|
+
this.validateLine(parent);
|
|
666
|
+
if (startElement !== endElement && endElement.parentElement) {
|
|
667
|
+
this.clearNodes(startElement, endElement);
|
|
668
|
+
}
|
|
669
|
+
if (resultText === '' && this.textarea.childNodes.length <= 1) {
|
|
670
|
+
this.textarea.innerHTML = '';
|
|
671
|
+
}
|
|
672
|
+
this.setErrorIndex(parent);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
clearNodes(startElement, endElement) {
|
|
676
|
+
const nodes = Array.from(this.textarea.childNodes);
|
|
677
|
+
let forClear = false;
|
|
678
|
+
for (const node of nodes) {
|
|
679
|
+
if (forClear) {
|
|
680
|
+
this.textarea.removeChild(node);
|
|
681
|
+
}
|
|
682
|
+
if (node === (endElement instanceof HTMLLIElement ? endElement : endElement.parentElement)) {
|
|
683
|
+
forClear = false;
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
if (node === startElement.parentElement) {
|
|
687
|
+
forClear = true;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
insertFromPaste(event) {
|
|
692
|
+
event.preventDefault();
|
|
693
|
+
const {
|
|
694
|
+
validateOn
|
|
695
|
+
} = this.asProps;
|
|
696
|
+
const value = event.clipboardData?.getData('text/plain');
|
|
697
|
+
const listOfNodes = value ? this.prepareNodesForPaste(value) : [];
|
|
698
|
+
if (listOfNodes.length === 0) return;
|
|
699
|
+
const selection = document.getSelection();
|
|
700
|
+
if (selection?.anchorNode && selection?.focusNode) {
|
|
701
|
+
const anchorOffset = selection.anchorOffset;
|
|
702
|
+
const focusOffset = selection.focusOffset;
|
|
703
|
+
const documentPosition = selection.anchorNode.compareDocumentPosition(selection.focusNode);
|
|
704
|
+
const direction = this.getSelectionDirection();
|
|
705
|
+
const anchorElement = direction === 'forward' ? selection.anchorNode : selection.focusNode;
|
|
706
|
+
const focusElement = direction === 'forward' ? selection.focusNode : selection.anchorNode;
|
|
707
|
+
const fromOffset = direction === 'forward' ? anchorOffset : focusOffset;
|
|
708
|
+
const toOffset = direction === 'forward' ? focusOffset : anchorOffset;
|
|
709
|
+
const anchorNode = anchorElement instanceof Text ? anchorElement.parentElement : anchorElement;
|
|
710
|
+
const focusNode = focusElement instanceof Text ? focusElement.parentElement : focusElement;
|
|
711
|
+
let textNode = null;
|
|
712
|
+
let position = null;
|
|
713
|
+
if (focusElement === this.textarea) {
|
|
714
|
+
this.textarea.replaceChildren(...listOfNodes);
|
|
715
|
+
const lastNodeToInsert = listOfNodes[listOfNodes.length - 1];
|
|
716
|
+
textNode = lastNodeToInsert.childNodes.item(0);
|
|
717
|
+
position = (lastNodeToInsert.textContent ?? '').length;
|
|
718
|
+
} else if (focusNode instanceof HTMLLIElement && anchorNode instanceof HTMLLIElement) {
|
|
719
|
+
const before = anchorNode?.textContent?.substring(0, fromOffset) ?? '';
|
|
720
|
+
const after = focusNode?.textContent?.substring(toOffset) ?? '';
|
|
721
|
+
const noEmptyLineBefore = before.trim() === '' ? '' : before;
|
|
722
|
+
const noEmptyLineAfter = after.trim() === '' ? '' : after;
|
|
723
|
+
selection.deleteFromDocument();
|
|
724
|
+
if (documentPosition !== 0) {
|
|
725
|
+
this.textarea.removeChild(focusNode);
|
|
726
|
+
}
|
|
727
|
+
const firstNodeToInsert = listOfNodes.splice(0, 1)[0];
|
|
728
|
+
const lastNodeToInsert = listOfNodes[listOfNodes.length - 1];
|
|
729
|
+
anchorNode.textContent = noEmptyLineBefore + (firstNodeToInsert?.textContent ?? '');
|
|
730
|
+
anchorNode.after(...listOfNodes);
|
|
731
|
+
if (lastNodeToInsert) {
|
|
732
|
+
lastNodeToInsert.textContent = (lastNodeToInsert.textContent ?? '') + noEmptyLineAfter;
|
|
733
|
+
textNode = lastNodeToInsert.childNodes.item(0);
|
|
734
|
+
position = (lastNodeToInsert.textContent ?? '').length;
|
|
735
|
+
this.validateLine(lastNodeToInsert);
|
|
736
|
+
this.setErrorIndex(lastNodeToInsert);
|
|
737
|
+
} else {
|
|
738
|
+
position = (anchorNode.textContent ?? '').length;
|
|
739
|
+
anchorNode.textContent = (anchorNode.textContent ?? '') + noEmptyLineAfter;
|
|
740
|
+
textNode = anchorNode.childNodes.item(0);
|
|
741
|
+
this.validateLine(anchorNode);
|
|
742
|
+
this.setErrorIndex(anchorNode);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (textNode instanceof Text) {
|
|
746
|
+
this.setSelection(textNode, position ?? 1, position ?? 1);
|
|
747
|
+
this.toggleErrorsPopper('keyboardLineIndex', textNode.parentNode);
|
|
748
|
+
} else {
|
|
749
|
+
// eslint-disable-next-line no-console
|
|
750
|
+
console.warn('incorrect child type', textNode, textNode?.parentNode);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
this.recalculateLinesCount();
|
|
754
|
+
if (validateOn.includes('paste') || this.asProps.showErrors) {
|
|
755
|
+
this.recalculateErrors();
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
getRangeTextNodes(range) {
|
|
759
|
+
const start = this.getTextNodeAndOffset(range, 'start');
|
|
760
|
+
const end = this.getTextNodeAndOffset(range, 'end');
|
|
761
|
+
return [start, end];
|
|
762
|
+
}
|
|
763
|
+
getTextNodeAndOffset(range, type) {
|
|
764
|
+
const node = this.getNode(range, type);
|
|
765
|
+
if (node instanceof Text) {
|
|
766
|
+
return [node, type === 'start' ? range.startOffset : range.endOffset];
|
|
767
|
+
}
|
|
768
|
+
if (node instanceof HTMLOListElement) {
|
|
769
|
+
const children = this.textarea.childNodes;
|
|
770
|
+
const item = children.item(type === 'start' ? range.startOffset : Math.max(0, range.endOffset - 1));
|
|
771
|
+
if (!item) {
|
|
772
|
+
const node = document.createElement('li');
|
|
773
|
+
const text = document.createTextNode(this.emptyLineValueJs);
|
|
774
|
+
node.append(text);
|
|
775
|
+
this.textarea.append(node);
|
|
776
|
+
return [text, 0];
|
|
777
|
+
}
|
|
778
|
+
const text = item.firstChild;
|
|
779
|
+
if (text instanceof Text) {
|
|
780
|
+
return [text, type === 'start' ? 0 : text.textContent.trim().length];
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if (node instanceof HTMLLIElement) {
|
|
784
|
+
const text = node.firstChild;
|
|
785
|
+
if (text instanceof Text) {
|
|
786
|
+
return [text, type === 'start' ? range.startOffset : range.endOffset];
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
throw new Error(`Unknown node element "${node}"`);
|
|
790
|
+
}
|
|
791
|
+
getNode(range, type) {
|
|
792
|
+
const node = type === 'start' ? range.startContainer : range.endContainer;
|
|
793
|
+
if (node instanceof Text || node instanceof HTMLLIElement || node instanceof HTMLOListElement) {
|
|
794
|
+
return node;
|
|
795
|
+
}
|
|
796
|
+
throw new Error(`Unknown node element "${node}"`);
|
|
797
|
+
}
|
|
798
|
+
createHistoryState() {
|
|
799
|
+
const lines = [];
|
|
800
|
+
const historySelection = {
|
|
801
|
+
startLine: -1,
|
|
802
|
+
startOffset: -1,
|
|
803
|
+
endLine: -1,
|
|
804
|
+
endOffset: -1
|
|
805
|
+
};
|
|
806
|
+
const selection = document.getSelection();
|
|
807
|
+
const direction = this.getSelectionDirection();
|
|
808
|
+
const anchorElement = direction === 'backward' ? selection?.focusNode : selection?.anchorNode;
|
|
809
|
+
const focusElement = direction === 'backward' ? selection?.anchorNode : selection?.focusNode;
|
|
810
|
+
const anchorOffset = direction === 'backward' ? selection?.focusOffset : selection?.anchorOffset;
|
|
811
|
+
const focusOffset = direction === 'backward' ? selection?.anchorOffset : selection?.focusOffset;
|
|
812
|
+
this.textarea.childNodes.forEach((node, index) => {
|
|
813
|
+
if (node.textContent === this.emptyLineValueJs) {
|
|
814
|
+
lines.push('');
|
|
815
|
+
} else {
|
|
816
|
+
lines.push(node.textContent ?? '');
|
|
817
|
+
}
|
|
818
|
+
if ((node === anchorElement || node === anchorElement?.parentElement) && anchorOffset !== undefined) {
|
|
819
|
+
historySelection.startLine = index;
|
|
820
|
+
historySelection.startOffset = anchorOffset;
|
|
821
|
+
}
|
|
822
|
+
// for FF
|
|
823
|
+
if (anchorElement === this.textarea && anchorOffset === index) {
|
|
824
|
+
historySelection.startLine = index;
|
|
825
|
+
historySelection.startOffset = 0;
|
|
826
|
+
}
|
|
827
|
+
if ((node === focusElement || node === focusElement?.parentElement) && focusOffset !== undefined) {
|
|
828
|
+
historySelection.endLine = index;
|
|
829
|
+
historySelection.endOffset = focusOffset;
|
|
830
|
+
}
|
|
831
|
+
// for FF
|
|
832
|
+
if (focusElement === this.textarea && focusOffset === index) {
|
|
833
|
+
historySelection.endLine = index;
|
|
834
|
+
historySelection.endOffset = node.textContent?.length ?? 0;
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
// for FF
|
|
839
|
+
if (focusElement === this.textarea && focusOffset !== undefined && focusOffset === this.textarea.childNodes.length) {
|
|
840
|
+
historySelection.endLine = this.textarea.childNodes.length - 1;
|
|
841
|
+
historySelection.endOffset = this.textarea.lastChild?.textContent?.length ?? 0;
|
|
842
|
+
}
|
|
843
|
+
const historyState = {
|
|
844
|
+
lines,
|
|
845
|
+
selection: historySelection
|
|
846
|
+
};
|
|
847
|
+
return historyState;
|
|
848
|
+
}
|
|
849
|
+
restoreHistoryState(historyState) {
|
|
850
|
+
const isEmptyValue = historyState.lines.length === 1 && historyState.lines[0] === '';
|
|
851
|
+
const newValue = isEmptyValue ? '' : historyState.lines.map(l => l === '' ? this.emptyLineValueJs : l);
|
|
852
|
+
this.handleValueOutChange(newValue);
|
|
853
|
+
const {
|
|
854
|
+
startLine,
|
|
855
|
+
startOffset,
|
|
856
|
+
endLine,
|
|
857
|
+
endOffset
|
|
858
|
+
} = historyState.selection;
|
|
859
|
+
const nodes = this.textarea.childNodes;
|
|
860
|
+
const startNode = nodes.item(startLine)?.firstChild;
|
|
861
|
+
const endNode = nodes.item(endLine)?.firstChild;
|
|
862
|
+
if (startNode && endNode) {
|
|
863
|
+
this.setSelection([startNode, endNode], startOffset, endOffset, 'nearest');
|
|
864
|
+
}
|
|
865
|
+
}
|
|
726
866
|
prepareNodesForPaste(value) {
|
|
727
867
|
const listOfNodes = [];
|
|
728
868
|
const {
|
|
@@ -738,8 +878,8 @@ class InputField extends _core.Component {
|
|
|
738
878
|
lines.forEach((line, index) => {
|
|
739
879
|
const preparedLine = lineProcessing(line, index, lines.length);
|
|
740
880
|
if (preparedLine === '' && skipEmptyLines === false || preparedLine !== '') {
|
|
741
|
-
const node = document.createElement('
|
|
742
|
-
if (preparedLine === '') {
|
|
881
|
+
const node = document.createElement('li');
|
|
882
|
+
if (preparedLine === '' || preparedLine === this.emptyLineValueJs) {
|
|
743
883
|
node.innerHTML = this.emptyLineValue;
|
|
744
884
|
} else if (preparedLine.trim() === '') {
|
|
745
885
|
const allSpacesRegExp = new RegExp('\\s', 'g');
|
|
@@ -756,7 +896,7 @@ class InputField extends _core.Component {
|
|
|
756
896
|
recalculateErrors() {
|
|
757
897
|
const errors = [];
|
|
758
898
|
this.textarea.childNodes.forEach((node, index) => {
|
|
759
|
-
if (node instanceof
|
|
899
|
+
if (node instanceof HTMLLIElement && node.getAttribute('aria-invalid') === 'true') {
|
|
760
900
|
const errorItem = {
|
|
761
901
|
errorMessage: node.dataset.errormessage ?? '',
|
|
762
902
|
lineNode: node,
|
|
@@ -778,9 +918,9 @@ class InputField extends _core.Component {
|
|
|
778
918
|
linesCount
|
|
779
919
|
} = this.asProps;
|
|
780
920
|
this.textarea.childNodes.forEach(node => {
|
|
781
|
-
if (node instanceof
|
|
921
|
+
if (node instanceof HTMLLIElement) {
|
|
782
922
|
node.dataset.overMaxRows = 'false';
|
|
783
|
-
if (node.textContent !== this.
|
|
923
|
+
if (node.textContent !== this.emptyLineValueJs && node.textContent !== '') {
|
|
784
924
|
lines++;
|
|
785
925
|
if (lines > maxLines) {
|
|
786
926
|
node.dataset.overMaxRows = 'true';
|
|
@@ -796,7 +936,7 @@ class InputField extends _core.Component {
|
|
|
796
936
|
getValues() {
|
|
797
937
|
const values = [];
|
|
798
938
|
this.textarea.childNodes.forEach(node => {
|
|
799
|
-
if (node.textContent
|
|
939
|
+
if (node.textContent === this.emptyLineValueJs) {
|
|
800
940
|
values.push('');
|
|
801
941
|
} else {
|
|
802
942
|
values.push(node.textContent ?? '');
|
|
@@ -823,7 +963,7 @@ class InputField extends _core.Component {
|
|
|
823
963
|
}
|
|
824
964
|
}
|
|
825
965
|
toggleErrorsPopper(key, target, timer) {
|
|
826
|
-
if (target instanceof
|
|
966
|
+
if (target instanceof HTMLOListElement || target instanceof HTMLLIElement) {
|
|
827
967
|
if (this.changeTriggerTimeout) {
|
|
828
968
|
clearTimeout(this.changeTriggerTimeout);
|
|
829
969
|
}
|
|
@@ -831,7 +971,7 @@ class InputField extends _core.Component {
|
|
|
831
971
|
const targetElement = target === this.textarea ? this.getNodeFromSelection() : target;
|
|
832
972
|
let lineIndex = -1;
|
|
833
973
|
let isInvalidRow = false;
|
|
834
|
-
if (targetElement instanceof
|
|
974
|
+
if (targetElement instanceof HTMLLIElement) {
|
|
835
975
|
isInvalidRow = targetElement.getAttribute('aria-invalid') === 'true';
|
|
836
976
|
lineIndex = Array.from(this.textarea.childNodes).indexOf(targetElement);
|
|
837
977
|
} else if (targetElement === this.textarea) {
|
|
@@ -878,7 +1018,7 @@ class InputField extends _core.Component {
|
|
|
878
1018
|
const childNodes = this.textarea.childNodes;
|
|
879
1019
|
const node = error ? error.lineNode ?? childNodes.item(error.lineIndex) : null;
|
|
880
1020
|
const selection = document.getSelection();
|
|
881
|
-
if (selection && node instanceof
|
|
1021
|
+
if (selection && node instanceof HTMLLIElement) {
|
|
882
1022
|
this.setState({
|
|
883
1023
|
visibleErrorPopper: false
|
|
884
1024
|
});
|
|
@@ -896,7 +1036,7 @@ class InputField extends _core.Component {
|
|
|
896
1036
|
const {
|
|
897
1037
|
lineValidation
|
|
898
1038
|
} = this.asProps;
|
|
899
|
-
if (lineValidation
|
|
1039
|
+
if (lineValidation) {
|
|
900
1040
|
const {
|
|
901
1041
|
isValid,
|
|
902
1042
|
errorMessage
|
|
@@ -906,7 +1046,7 @@ class InputField extends _core.Component {
|
|
|
906
1046
|
node.dataset.errormessage = errorMessage;
|
|
907
1047
|
} else {
|
|
908
1048
|
node.removeAttribute('aria-invalid');
|
|
909
|
-
node.dataset.errormessage
|
|
1049
|
+
delete node.dataset.errormessage;
|
|
910
1050
|
}
|
|
911
1051
|
return isValid;
|
|
912
1052
|
}
|
|
@@ -915,11 +1055,12 @@ class InputField extends _core.Component {
|
|
|
915
1055
|
setSelection(node, start, end, scrollType = 'center') {
|
|
916
1056
|
const selection = document.getSelection();
|
|
917
1057
|
const range = document.createRange();
|
|
918
|
-
|
|
919
|
-
range.
|
|
1058
|
+
const [startNode, endNode] = Array.isArray(node) ? node : [node, node];
|
|
1059
|
+
range.setStart(startNode, start);
|
|
1060
|
+
range.setEnd(endNode, end);
|
|
920
1061
|
selection?.removeAllRanges();
|
|
921
1062
|
selection?.addRange(range);
|
|
922
|
-
const nodeToScroll =
|
|
1063
|
+
const nodeToScroll = endNode instanceof Text ? endNode.parentNode : endNode;
|
|
923
1064
|
if (nodeToScroll instanceof HTMLElement) {
|
|
924
1065
|
nodeToScroll.scrollIntoView({
|
|
925
1066
|
block: scrollType,
|
|
@@ -946,7 +1087,7 @@ class InputField extends _core.Component {
|
|
|
946
1087
|
break;
|
|
947
1088
|
case 'ArrowLeft':
|
|
948
1089
|
{
|
|
949
|
-
if (currentNode.textContent === this.
|
|
1090
|
+
if (currentNode.textContent === this.emptyLineValueJs) {
|
|
950
1091
|
event.preventDefault();
|
|
951
1092
|
nextNode = currentNode.previousSibling;
|
|
952
1093
|
}
|
|
@@ -954,13 +1095,13 @@ class InputField extends _core.Component {
|
|
|
954
1095
|
}
|
|
955
1096
|
case 'ArrowRight':
|
|
956
1097
|
{
|
|
957
|
-
if (currentNode.textContent === this.
|
|
1098
|
+
if (currentNode.textContent === this.emptyLineValueJs) {
|
|
958
1099
|
event.preventDefault();
|
|
959
1100
|
nextNode = currentNode.nextSibling;
|
|
960
1101
|
}
|
|
961
1102
|
}
|
|
962
1103
|
}
|
|
963
|
-
if (nextNode instanceof
|
|
1104
|
+
if (nextNode instanceof HTMLLIElement) {
|
|
964
1105
|
const selection = document.getSelection();
|
|
965
1106
|
const firstNode = nextNode.childNodes.item(0);
|
|
966
1107
|
const nodeToSetSelection = firstNode instanceof Text ? firstNode : nextNode;
|
|
@@ -985,17 +1126,11 @@ class InputField extends _core.Component {
|
|
|
985
1126
|
});
|
|
986
1127
|
this.handlers.errorIndex(errorIndex);
|
|
987
1128
|
}
|
|
988
|
-
isDeleteKey(event) {
|
|
989
|
-
return event.key === 'Backspace' || event.key === 'x' && (event.ctrlKey || event.metaKey);
|
|
990
|
-
}
|
|
991
|
-
getEmptyParagraph() {
|
|
992
|
-
const element = document.createElement('p');
|
|
993
|
-
element.innerHTML = this.emptyLineValue;
|
|
994
|
-
return element;
|
|
995
|
-
}
|
|
996
1129
|
addEventListeners(textarea) {
|
|
997
1130
|
textarea.addEventListener('paste', this.handlePaste);
|
|
998
|
-
textarea.addEventListener('
|
|
1131
|
+
textarea.addEventListener('beforeinput', this.handleChange);
|
|
1132
|
+
textarea.addEventListener('compositionstart', this.handleCompositionTextStart);
|
|
1133
|
+
textarea.addEventListener('compositionend', this.handleCompositionTextEnd);
|
|
999
1134
|
textarea.addEventListener('focus', this.handleFocus);
|
|
1000
1135
|
textarea.addEventListener('blur', this.handleBlur);
|
|
1001
1136
|
textarea.addEventListener('keydown', this.handleKeyDown);
|
|
@@ -1007,7 +1142,9 @@ class InputField extends _core.Component {
|
|
|
1007
1142
|
}
|
|
1008
1143
|
removeEventListeners(textarea) {
|
|
1009
1144
|
textarea.removeEventListener('paste', this.handlePaste);
|
|
1010
|
-
textarea.removeEventListener('
|
|
1145
|
+
textarea.removeEventListener('beforeinput', this.handleChange);
|
|
1146
|
+
textarea.removeEventListener('compositionstart', this.handleCompositionTextStart);
|
|
1147
|
+
textarea.removeEventListener('compositionend', this.handleCompositionTextEnd);
|
|
1011
1148
|
textarea.removeEventListener('focus', this.handleFocus);
|
|
1012
1149
|
textarea.removeEventListener('blur', this.handleBlur);
|
|
1013
1150
|
textarea.removeEventListener('keydown', this.handleKeyDown);
|
|
@@ -1026,10 +1163,6 @@ class InputField extends _core.Component {
|
|
|
1026
1163
|
}
|
|
1027
1164
|
}
|
|
1028
1165
|
}
|
|
1029
|
-
isRangeSelection() {
|
|
1030
|
-
const selection = document.getSelection();
|
|
1031
|
-
return selection?.focusNode !== selection?.anchorNode || selection?.focusOffset !== selection?.anchorOffset;
|
|
1032
|
-
}
|
|
1033
1166
|
getSelectionDirection() {
|
|
1034
1167
|
const selection = document.getSelection();
|
|
1035
1168
|
if (selection?.anchorNode && selection?.focusNode) {
|