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