fan-standard-comp 3.2.3 → 3.2.5

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.
@@ -29,6 +29,8 @@ interface ButtonGroupProps {
29
29
  dropdownConfig?: Object;
30
30
  moreText?: string;
31
31
  moreIcon?: React.ReactNode | string | number;
32
+ className?: string;
33
+ style?: object;
32
34
  }
33
35
  declare const ButtonGroup: (props: ButtonGroupProps) => React.JSX.Element;
34
36
  export default ButtonGroup;
@@ -41,7 +41,9 @@ var ButtonGroup = function ButtonGroup(props) {
41
41
  dropdownConfig = _props$dropdownConfig === void 0 ? {} : _props$dropdownConfig,
42
42
  _props$moreText = props.moreText,
43
43
  moreText = _props$moreText === void 0 ? '更多' : _props$moreText,
44
- moreIcon = props.moreIcon;
44
+ moreIcon = props.moreIcon,
45
+ className = props.className,
46
+ style = props.style;
45
47
  var _props$options = props.options,
46
48
  options = _props$options === void 0 ? [] : _props$options,
47
49
  _props$min = props.min,
@@ -316,7 +318,8 @@ var ButtonGroup = function ButtonGroup(props) {
316
318
  var forGroup = resetList.slice(0, min - 1);
317
319
  var forDrop = resetList.slice(min - 1);
318
320
  return /*#__PURE__*/React.createElement("span", {
319
- className: "spec-button-group"
321
+ className: "spec-button-group ".concat(className || ''),
322
+ style: style
320
323
  }, forGroup.map(function (item, index) {
321
324
  return index < min - 1 ? renderDisplayButton(item, index) : null;
322
325
  }), type === 'button' ? /*#__PURE__*/React.createElement(_Dropdown, Object.assign({
@@ -365,7 +368,8 @@ var ButtonGroup = function ButtonGroup(props) {
365
368
  }, moreText || '更多', moreIcon || /*#__PURE__*/React.createElement(DownOutlined, null)))));
366
369
  }
367
370
  return /*#__PURE__*/React.createElement("span", {
368
- className: "spec-button-group"
371
+ className: "spec-button-group ".concat(className || ''),
372
+ style: style
369
373
  }, resetList.map(function (item, index) {
370
374
  return renderDisplayButton(item, index);
371
375
  }));
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Created by S.C. on 2024/10/10
3
+ */
4
+ import React from 'react';
5
+ interface VarTemplateProps {
6
+ style?: Object;
7
+ tags: any[];
8
+ showCountTip?: boolean;
9
+ [k: string]: any;
10
+ }
11
+ declare const VarTemplate: (props: VarTemplateProps) => React.JSX.Element;
12
+ export default VarTemplate;
@@ -1,248 +1,267 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
1
  import "antd/es/tag/style";
3
2
  import _Tag from "antd/es/tag";
4
3
  import "antd/es/input/style";
5
4
  import _Input from "antd/es/input";
6
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
9
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
10
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
11
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
12
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
13
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
15
- function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
16
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
17
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
18
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
19
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
20
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
5
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
21
11
  /**
22
- * Created by S.C. on 2019/11/16.
12
+ * Created by S.C. on 2024/10/10
23
13
  */
24
- import React, { Component } from 'react';
14
+ import React, { useRef, useState, useEffect, useCallback } from 'react';
25
15
  var TextArea = _Input.TextArea;
26
16
  var isIE = !!document.all;
27
- var VarTemplate = /*#__PURE__*/function (_Component) {
28
- function VarTemplate(props) {
29
- var _this;
30
- _classCallCheck(this, VarTemplate);
31
- _this = _callSuper(this, VarTemplate, [props]);
32
- _this.handleBlur = function (e) {
33
- _this.getCurrentCursor();
34
- };
35
- _this.handleFocus = function (e) {
36
- // console.log('获取焦点')
37
- // this.$emit('focus', event)
38
- };
39
- _this.handleInputChange = function (e) {
40
- var onChange = _this.props.onChange;
41
- _this.getCurrentCursor();
42
- _this.setState({
43
- currentContent: e.target.value,
44
- startNum: e.target.value.length,
45
- endNum: e.target.value.length,
46
- wordCount: e.target.value.length
47
- });
48
- if (onChange) onChange(e.target.value);
49
- };
50
- _this.setTagWords = function (key) {
51
- var onChange = _this.props.onChange;
52
- var _this$state = _this.state,
53
- currentContent = _this$state.currentContent,
54
- startNum = _this$state.startNum,
55
- endNum = _this$state.endNum;
56
- _this.setState({
57
- currentContent: _this.insertContent(currentContent, key, startNum, endNum),
58
- startNum: startNum + key.length,
59
- // 光标起始位置累加
60
- endNum: endNum + key.length,
61
- // 光标起始位置累加
62
- wordCount: _this.insertContent(currentContent, key, startNum, endNum).length
63
- });
64
- if (onChange) onChange(_this.insertContent(currentContent, key, startNum, endNum));
65
- setTimeout(function () {
66
- _this.moveToCursor(); // 重新定位光标
67
- });
68
- };
69
- /**
70
- * 指定位置插入标签占位符字符串,当光标有选中一段字符时,会将直接将其替换
71
- * @param {str} 需要做插入的字符串
72
- * @param {insertStr} 需要插入的字符串
73
- * @param {start} 指定开始位置
74
- * @param {end} 指定结束位置
75
- * */
76
- _this.insertContent = function (str, insertStr, start, end) {
77
- if (start !== end) {
78
- var _prevStr = str.substring(0, start);
79
- var _nextStr = str.substring(end, str.length);
80
- return _prevStr + insertStr + _nextStr;
81
- }
82
- var prevStr = str.substring(0, start);
83
- var nextStr = str.substring(start, str.length);
84
- return prevStr + insertStr + nextStr;
85
- };
86
- /**
87
- * 获取当前(上一次)光标的位置
88
- * @参考 http://blog.csdn.net/chadcao/article/details/6575927
89
- * @TODO IE、火狐浏览器下未验证
90
- */
91
- _this.getCurrentCursor = function () {
92
- var start = 0;
93
- var end = 0;
94
- var oTextarea = _this.content.querySelector('textarea'); // 获取textarea标签
95
- if (isIE) {
96
- // selection 当前激活选中区,即高亮文本块,和/或文当中用户可执行某些操作的其它元素。
97
- // createRange 从当前文本选中区中创建 TextRange 对象,
98
- // 或从控件选中区中创建 controlRange 集合。
99
- var sTextRange = document.selection.createRange();
100
- // 判断选中的是不是textarea对象
101
- if (sTextRange.parentElement() === oTextarea) {
102
- // 创建一个TextRange对象
103
- var oTextRange = document.body.createTextRange();
104
- // 移动文本范围以便范围的开始和结束位置能够完全包含给定元素的文本。
105
- oTextRange.moveToElementText(oTextarea);
106
- // 这里我们比较oTextRange和sTextRange的开头,的到选中区域的开头位置
107
- for (start = 0; oTextRange.compareEndPoints('StartToStart', sTextRange) < 0; start++) {
108
- oTextRange.moveStart('character', 1);
109
- }
110
- // 需要计算一下\n的数目(按字符移动的方式不计\n,所以这里加上)
111
- for (var i = 0; i <= start; i++) {
112
- if (oTextarea.value.charAt(i) === '\n') {
113
- start++;
114
- }
115
- }
116
- // 再计算一次结束的位置
117
- oTextRange.moveToElementText(oTextarea);
118
- for (end = 0; oTextRange.compareEndPoints('StartToEnd', sTextRange) < 0; end++) {
119
- oTextRange.moveStart('character', 1);
120
- }
121
- for (var j = 0; j <= end; j++) {
122
- if (oTextarea.value.charAt(j) === '\n') {
123
- end++;
124
- }
125
- }
17
+ var VarTemplate = function VarTemplate(props) {
18
+ var value = props.value,
19
+ size = props.size,
20
+ style = props.style,
21
+ tags = props.tags,
22
+ disabled = props.disabled,
23
+ fieldStatus = props.fieldStatus,
24
+ _props$tagsOptionName = props.tagsOptionName,
25
+ tagsOptionName = _props$tagsOptionName === void 0 ? {
26
+ key: 'key',
27
+ label: 'label',
28
+ value: 'value'
29
+ } : _props$tagsOptionName,
30
+ showCountTip = props.showCountTip,
31
+ onChange = props.onChange;
32
+ var contentRef = useRef();
33
+ var _useState = useState({
34
+ currentContent: '',
35
+ startNum: 0,
36
+ endNum: 0,
37
+ wordCount: 0
38
+ }),
39
+ _useState2 = _slicedToArray(_useState, 2),
40
+ vartData = _useState2[0],
41
+ setVartData = _useState2[1];
42
+ var handleBlur = function handleBlur() {
43
+ getCurrentCursor();
44
+ };
45
+ var handleFocus = function handleFocus() {
46
+ // console.log('获取焦点', event)
47
+ };
48
+ var handleInputChange = function handleInputChange(e) {
49
+ var eValue = e === null || e === void 0 ? void 0 : e.target.value;
50
+ getCurrentCursor();
51
+ setVartData({
52
+ currentContent: eValue,
53
+ startNum: eValue.length,
54
+ endNum: eValue.length,
55
+ wordCount: eValue.length
56
+ });
57
+ if (onChange) onChange(eValue);
58
+ };
59
+ var setTagWords = useCallback(function (key) {
60
+ var currentContent = vartData.currentContent,
61
+ startNum = vartData.startNum,
62
+ endNum = vartData.endNum;
63
+ setVartData({
64
+ currentContent: insertContent(currentContent, key, startNum, endNum),
65
+ startNum: startNum + key.length,
66
+ endNum: endNum + key.length,
67
+ wordCount: insertContent(currentContent, key, startNum, endNum).length
68
+ });
69
+ if (onChange) onChange(insertContent(currentContent, key, startNum, endNum));
70
+ setTimeout(function () {
71
+ moveToCursor(key.length); // 重新定位光标
72
+ });
73
+ }, [vartData]);
74
+ /**
75
+ * 指定位置插入标签占位符字符串,当光标有选中一段字符时,会将直接将其替换
76
+ * @param {str} 需要做插入的字符串
77
+ * @param {insertStr} 需要插入的字符串
78
+ * @param {start} 指定开始位置
79
+ * @param {end} 指定结束位置
80
+ * */
81
+ var insertContent = function insertContent(str, insertStr, start, end) {
82
+ if (start !== end) {
83
+ var _prevStr = str.substring(0, start);
84
+ var _nextStr = str.substring(end, str.length);
85
+ return _prevStr + insertStr + _nextStr;
86
+ }
87
+ var prevStr = str.substring(0, start);
88
+ var nextStr = str.substring(start, str.length);
89
+ return prevStr + insertStr + nextStr;
90
+ };
91
+ /**
92
+ * 获取当前(上一次)光标的位置
93
+ * @参考 http://blog.csdn.net/chadcao/article/details/6575927
94
+ * @TODO IE、火狐浏览器下未验证
95
+ */
96
+ var getCurrentCursor = useCallback(function () {
97
+ var _a;
98
+ var start = 0;
99
+ var end = 0;
100
+ var oTextarea = (_a = contentRef === null || contentRef === void 0 ? void 0 : contentRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('textarea'); // 获取textarea标签
101
+ if (isIE) {
102
+ // selection 当前激活选中区,即高亮文本块,和/或文当中用户可执行某些操作的其它元素。
103
+ // createRange 从当前文本选中区中创建 TextRange 对象,
104
+ // 或从控件选中区中创建 controlRange 集合。
105
+ // @ts-ignore
106
+ var sTextRange = document.selection.createRange();
107
+ // 判断选中的是不是textarea对象
108
+ if (sTextRange.parentElement() === oTextarea) {
109
+ // 创建一个TextRange对象
110
+ // @ts-ignore
111
+ var oTextRange = document.body.createTextRange();
112
+ // 移动文本范围以便范围的开始和结束位置能够完全包含给定元素的文本。
113
+ oTextRange.moveToElementText(oTextarea);
114
+ // 这里我们比较oTextRange和sTextRange的开头,的到选中区域的开头位置
115
+ for (start = 0; oTextRange.compareEndPoints('StartToStart', sTextRange) < 0; start++) {
116
+ oTextRange.moveStart('character', 1);
126
117
  }
127
- } else {
128
- start = oTextarea.selectionStart;
129
- end = oTextarea.selectionEnd;
130
- }
131
- _this.setState({
132
- startNum: start,
133
- endNum: end
134
- });
135
- };
136
- /**
137
- * 跳转到上一次光标的位置
138
- * @参考 http://blog.csdn.net/chadcao/article/details/6575927
139
- * @TODO IE、火狐浏览器下未验证
140
- */
141
- _this.moveToCursor = function () {
142
- var _this$state2 = _this.state,
143
- startNum = _this$state2.startNum,
144
- endNum = _this$state2.endNum;
145
- var oTextarea = _this.content.querySelector('textarea');
146
- var start = startNum;
147
- var end = endNum;
148
- if (isNaN(start) || isNaN(end)) {
149
- alert('位置输入错误');
150
- }
151
- if (isIE) {
152
- var oTextRange = oTextarea.createTextRange();
153
- var LStart = startNum;
154
- var LEnd = endNum;
155
- var _start = 0;
156
- var _end = 0;
157
- var value = oTextarea.value;
158
- for (var i = 0; i < value.length && i < LStart; i++) {
159
- var c = value.charAt(i);
160
- if (c !== '\n') {
161
- _start++;
118
+ // 需要计算一下\n的数目(按字符移动的方式不计\n,所以这里加上)
119
+ for (var i = 0; i <= start; i++) {
120
+ if (oTextarea.value.charAt(i) === '\n') {
121
+ start++;
162
122
  }
163
123
  }
164
- for (var j = value.length - 1; j >= LEnd && j >= 0; j--) {
165
- var _c = value.charAt(j);
166
- if (_c !== '\n') {
167
- _end++;
124
+ // 再计算一次结束的位置
125
+ oTextRange.moveToElementText(oTextarea);
126
+ for (end = 0; oTextRange.compareEndPoints('StartToEnd', sTextRange) < 0; end++) {
127
+ oTextRange.moveStart('character', 1);
128
+ }
129
+ for (var j = 0; j <= end; j++) {
130
+ if (oTextarea.value.charAt(j) === '\n') {
131
+ end++;
168
132
  }
169
133
  }
170
- oTextRange.moveStart('character', _start);
171
- oTextRange.moveEnd('character', -_end);
172
- // oTextRange.collapse(true);
173
- oTextRange.select();
174
- oTextarea.focus();
175
- } else {
176
- oTextarea.select();
177
- oTextarea.selectionStart = startNum;
178
- oTextarea.selectionEnd = endNum;
179
134
  }
180
- };
181
- var _value = props.value || '';
182
- _this.state = {
183
- currentContent: _value,
184
- startNum: _value.length,
185
- // 光标开始位置(当选中文本时)
186
- endNum: _value.length,
187
- // 光标结束位置(当选中文本时)
188
- wordCount: _value.length // 输入框内的字符数总和(包含占位符所需要的长度)
189
- };
190
- _this.content = /*#__PURE__*/React.createRef();
191
- return _this;
192
- }
193
- _inherits(VarTemplate, _Component);
194
- return _createClass(VarTemplate, [{
195
- key: "render",
196
- value: function render() {
197
- var _this2 = this;
198
- var _this$props = this.props,
199
- size = _this$props.size,
200
- style = _this$props.style,
201
- tags = _this$props.tags,
202
- disabled = _this$props.disabled;
203
- var _this$state3 = this.state,
204
- currentContent = _this$state3.currentContent,
205
- wordCount = _this$state3.wordCount;
206
- return /*#__PURE__*/React.createElement("div", {
207
- className: "vart-wrap",
208
- style: style,
209
- ref: function ref(cRef) {
210
- _this2.content = cRef;
135
+ } else {
136
+ start = oTextarea.selectionStart;
137
+ end = oTextarea.selectionEnd;
138
+ }
139
+ setVartData(Object.assign(Object.assign({}, vartData), {
140
+ startNum: start,
141
+ endNum: end
142
+ }));
143
+ }, [vartData, value]);
144
+ /**
145
+ * 跳转到上一次光标的位置
146
+ * @参考 http://blog.csdn.net/chadcao/article/details/6575927
147
+ * @TODO IE、火狐浏览器下未验证
148
+ * @{params} {number} appendLength 当前切换的长度
149
+ */
150
+ var moveToCursor = useCallback(function (insertLength) {
151
+ var _a;
152
+ var startNum = vartData.startNum,
153
+ endNum = vartData.endNum;
154
+ var oTextarea = (_a = contentRef === null || contentRef === void 0 ? void 0 : contentRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('textarea');
155
+ var start = startNum;
156
+ var end = endNum;
157
+ if (isNaN(start) || isNaN(end)) {
158
+ console.error('位置输入错误');
159
+ }
160
+ if (isIE) {
161
+ var oTextRange = oTextarea.createTextRange();
162
+ var LStart = startNum;
163
+ var LEnd = endNum;
164
+ var _start = 0;
165
+ var _end = 0;
166
+ var _value = oTextarea.value;
167
+ for (var i = 0; i < _value.length && i < LStart; i++) {
168
+ var c = _value.charAt(i);
169
+ if (c !== '\n') {
170
+ _start++;
211
171
  }
212
- }, tags && Array.isArray(tags) && /*#__PURE__*/React.createElement("div", {
213
- className: "vart-header"
214
- }, tags.map(function (item) {
215
- return /*#__PURE__*/React.createElement(_Tag, {
216
- key: item.id,
217
- onClick: function onClick() {
218
- return !disabled && _this2.setTagWords(item.variableNameFormatted);
219
- }
220
- }, item.variableName);
221
- })), /*#__PURE__*/React.createElement("div", {
222
- className: "vart-input"
223
- }, /*#__PURE__*/React.createElement(TextArea, {
224
- type: "text",
225
- size: size,
226
- value: currentContent,
227
- placeholder: "\u8BF7\u8F93\u5165",
228
- onFocus: this.handleFocus,
229
- onBlur: this.handleBlur,
230
- onChange: function onChange(e) {
231
- return _this2.handleInputChange(e);
232
- },
233
- disabled: disabled
234
- })));
172
+ }
173
+ for (var j = _value.length - 1; j >= LEnd && j >= 0; j--) {
174
+ var _c = _value.charAt(j);
175
+ if (_c !== '\n') {
176
+ _end++;
177
+ }
178
+ }
179
+ oTextRange.moveStart('character', _start);
180
+ oTextRange.moveEnd('character', -_end);
181
+ // oTextRange.collapse(true);
182
+ oTextRange.select();
183
+ oTextarea.focus();
184
+ } else {
185
+ oTextarea.select();
186
+ oTextarea.focus();
187
+ // 判断如果是原来已经有选中(文本高亮),则插入文本后高亮的位置需要变成当前插入的文本
188
+ // startNum === endNum表示未选中过
189
+ // let aStartNum = startNum === endNum ? startNum + insertLength : startNum
190
+ // let aEndNum = startNum === endNum ? endNum + insertLength : startNum + insertLength
191
+ oTextarea.selectionStart = startNum + insertLength; // aStartNum
192
+ oTextarea.selectionEnd = startNum + insertLength; // aEndNum
193
+ // if (oTextarea.setSelectionRange) {
194
+ // setTimeout(() => {
195
+ // oTextarea.focus();
196
+ // oTextarea.setSelectionRange(aStartNum, aEndNum);
197
+ // }, 0);
198
+ // } else {
199
+ // oTextarea.selectionStart = aStartNum
200
+ // oTextarea.selectionEnd = aEndNum
201
+ // }
235
202
  }
236
- }], [{
237
- key: "getDerivedStateFromProps",
238
- value: function getDerivedStateFromProps(nextProps) {
239
- // console.log('执行getDerivedStateFromProps', nextProps)
240
- // Should be a controlled component.
241
- if ('value' in nextProps) {
242
- return _objectSpread({}, nextProps.value || {});
203
+ }, [vartData]);
204
+ useEffect(function () {
205
+ setVartData({
206
+ currentContent: value || '',
207
+ startNum: (value === null || value === void 0 ? void 0 : value.length) || 0,
208
+ endNum: (value === null || value === void 0 ? void 0 : value.length) || 0,
209
+ wordCount: (value === null || value === void 0 ? void 0 : value.length) || 0 // 输入框内的字符数总和(包含占位符所需要的长度)
210
+ });
211
+ }, [value]);
212
+ // const setCursorPosition = (elemId, index) =>{
213
+ // const elem = document.getElementById(elemId);
214
+ // if (elem.setSelectionRange) {
215
+ // setTimeout(function() {
216
+ // elem.focus();
217
+ // elem.setSelectionRange(index, index);
218
+ // }, 0);
219
+ // } else if (elem.createTextRange) {
220
+ // const range = elem.createTextRange();
221
+ // range.collapse(true);
222
+ // range.moveEnd('character', index);
223
+ // range.moveStart('character', index);
224
+ // range.select();
225
+ // }
226
+ // }
227
+ return /*#__PURE__*/React.createElement("div", {
228
+ className: "spec-vart-wrap",
229
+ style: style,
230
+ ref: contentRef
231
+ }, tags && Array.isArray(tags) && (/*#__PURE__*/React.createElement("div", {
232
+ className: "spec-vart-header"
233
+ }, tags.map(function (item) {
234
+ return /*#__PURE__*/React.createElement(_Tag, {
235
+ style: {
236
+ marginBottom: '4px',
237
+ cursor: 'pointer'
238
+ },
239
+ key: item[(tagsOptionName === null || tagsOptionName === void 0 ? void 0 : tagsOptionName.key) || 'key'],
240
+ onClick: function onClick() {
241
+ return !(disabled || fieldStatus === 'disabled') && setTagWords(item[(tagsOptionName === null || tagsOptionName === void 0 ? void 0 : tagsOptionName.value) || 'value']);
243
242
  }
244
- return null;
243
+ }, item[(tagsOptionName === null || tagsOptionName === void 0 ? void 0 : tagsOptionName.label) || 'label']);
244
+ }))), /*#__PURE__*/React.createElement("div", {
245
+ className: "spec-vart-input"
246
+ }, /*#__PURE__*/React.createElement(TextArea
247
+ // type="text"
248
+ , {
249
+ // type="text"
250
+ size: size,
251
+ value: vartData.currentContent,
252
+ placeholder: "\u8BF7\u8F93\u5165",
253
+ onFocus: handleFocus,
254
+ onBlur: handleBlur,
255
+ onChange: function onChange(e) {
256
+ return handleInputChange(e);
257
+ },
258
+ disabled: disabled || fieldStatus === 'disabled'
259
+ })), showCountTip && /*#__PURE__*/React.createElement("div", {
260
+ className: "spec-vart-desc",
261
+ style: {
262
+ marginTop: '4px',
263
+ fontSize: '12px'
245
264
  }
246
- }]);
247
- }(Component);
265
+ }, " \u60A8\u5DF2\u5F55\u5165 ", /*#__PURE__*/React.createElement("b", null, vartData.wordCount), " \u4E2A\u5B57"));
266
+ };
248
267
  export default VarTemplate;