index.js
3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "ResizableTextArea", {
enumerable: true,
get: function get() {
return _ResizableTextArea.default;
}
});
exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var React = _interopRequireWildcard(require("react"));
var _ResizableTextArea = _interopRequireDefault(require("./ResizableTextArea"));
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
var TextArea = /*#__PURE__*/function (_React$Component) {
(0, _inherits2.default)(TextArea, _React$Component);
var _super = _createSuper(TextArea);
function TextArea(props) {
var _this;
(0, _classCallCheck2.default)(this, TextArea);
_this = _super.call(this, props);
_this.focus = function () {
_this.resizableTextArea.textArea.focus();
};
_this.saveTextArea = function (resizableTextArea) {
_this.resizableTextArea = resizableTextArea;
};
_this.handleChange = function (e) {
var onChange = _this.props.onChange;
_this.setValue(e.target.value, function () {
_this.resizableTextArea.resizeTextarea();
});
if (onChange) {
onChange(e);
}
};
_this.handleKeyDown = function (e) {
var _this$props = _this.props,
onPressEnter = _this$props.onPressEnter,
onKeyDown = _this$props.onKeyDown;
if (e.keyCode === 13 && onPressEnter) {
onPressEnter(e);
}
if (onKeyDown) {
onKeyDown(e);
}
};
var value = typeof props.value === 'undefined' || props.value === null ? props.defaultValue : props.value;
_this.state = {
value: value
};
return _this;
}
(0, _createClass2.default)(TextArea, [{
key: "setValue",
value: function setValue(value, callback) {
if (!('value' in this.props)) {
this.setState({
value: value
}, callback);
}
}
}, {
key: "blur",
value: function blur() {
this.resizableTextArea.textArea.blur();
}
}, {
key: "render",
value: function render() {
return React.createElement(_ResizableTextArea.default, Object.assign({}, this.props, {
value: this.state.value,
onKeyDown: this.handleKeyDown,
onChange: this.handleChange,
ref: this.saveTextArea
}));
}
}], [{
key: "getDerivedStateFromProps",
value: function getDerivedStateFromProps(nextProps) {
if ('value' in nextProps) {
return {
value: nextProps.value
};
}
return null;
}
}]);
return TextArea;
}(React.Component);
var _default = TextArea;
exports.default = _default;