@v-c/textarea 0.0.5 → 0.0.7
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/dist/ResizableTextArea.cjs +190 -124
- package/dist/ResizableTextArea.d.ts +3 -41
- package/dist/ResizableTextArea.js +191 -125
- package/dist/TextArea.cjs +95 -210
- package/dist/TextArea.d.ts +2 -2
- package/dist/TextArea.js +96 -211
- package/dist/calculateNodeHeight.cjs +1 -1
- package/dist/calculateNodeHeight.js +1 -1
- package/dist/interface.d.ts +21 -32
- package/package.json +2 -2
package/dist/TextArea.cjs
CHANGED
|
@@ -3,209 +3,146 @@ const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
|
3
3
|
const require_ResizableTextArea = require("./ResizableTextArea.cjs");
|
|
4
4
|
let vue = require("vue");
|
|
5
5
|
let __v_c_util = require("@v-c/util");
|
|
6
|
-
let
|
|
7
|
-
__v_c_util_dist_omit = require_rolldown_runtime.__toESM(__v_c_util_dist_omit);
|
|
6
|
+
let __v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
8
7
|
let __v_c_input = require("@v-c/input");
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
const
|
|
12
|
-
(0, vue.
|
|
13
|
-
|
|
8
|
+
let __v_c_util_dist_KeyCode_ts = require("@v-c/util/dist/KeyCode.ts");
|
|
9
|
+
var TextArea = /* @__PURE__ */ (0, vue.defineComponent)((props, { expose, attrs }) => {
|
|
10
|
+
const { count, showCount } = (0, __v_c_util_dist_props_util.toPropsRefs)(props, "count", "showCount");
|
|
11
|
+
const value = (0, vue.shallowRef)(props?.value ?? props?.defaultValue ?? "");
|
|
12
|
+
(0, vue.watch)(() => props.value, () => {
|
|
13
|
+
value.value = props.value;
|
|
14
14
|
});
|
|
15
|
-
const
|
|
16
|
-
if (stateValue.value === val) return;
|
|
17
|
-
if (props.value === void 0) stateValue.value = val;
|
|
18
|
-
(0, vue.nextTick)(() => {
|
|
19
|
-
callback?.();
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
const formatValue = (0, vue.computed)(() => stateValue.value === void 0 || stateValue.value === null ? "" : String(stateValue.value));
|
|
15
|
+
const formatValue = (0, vue.computed)(() => value.value === void 0 || value.value === null ? "" : String(value.value));
|
|
23
16
|
const focused = (0, vue.shallowRef)(false);
|
|
24
17
|
const compositionRef = (0, vue.shallowRef)(false);
|
|
25
|
-
const textareaResized = (0, vue.shallowRef)(
|
|
18
|
+
const textareaResized = (0, vue.shallowRef)();
|
|
26
19
|
const holderRef = (0, vue.shallowRef)();
|
|
27
20
|
const resizableTextAreaRef = (0, vue.shallowRef)();
|
|
28
|
-
const getTextArea = () => resizableTextAreaRef.value?.textArea
|
|
21
|
+
const getTextArea = () => resizableTextAreaRef.value?.textArea;
|
|
29
22
|
const focus = () => {
|
|
30
|
-
getTextArea()
|
|
23
|
+
getTextArea().focus();
|
|
31
24
|
};
|
|
32
25
|
expose({
|
|
33
|
-
resizableTextArea:
|
|
26
|
+
resizableTextArea: resizableTextAreaRef,
|
|
34
27
|
focus,
|
|
35
28
|
blur: () => {
|
|
36
|
-
getTextArea()
|
|
29
|
+
getTextArea().blur();
|
|
37
30
|
},
|
|
38
|
-
nativeElement: (0, vue.computed)(() => holderRef.value?.nativeElement || getTextArea()
|
|
31
|
+
nativeElement: (0, vue.computed)(() => holderRef.value?.nativeElement || getTextArea())
|
|
39
32
|
});
|
|
40
|
-
(0, vue.watch)(() => props.disabled, (
|
|
41
|
-
|
|
33
|
+
(0, vue.watch)(() => props.disabled, () => {
|
|
34
|
+
const prev = focused.value;
|
|
35
|
+
if (props.disabled && prev) focused.value = !props?.disabled && prev;
|
|
36
|
+
}, {
|
|
37
|
+
immediate: true,
|
|
38
|
+
flush: "post"
|
|
42
39
|
});
|
|
43
40
|
const selection = (0, vue.shallowRef)(null);
|
|
44
|
-
(0, vue.watch)(selection, (
|
|
45
|
-
if (
|
|
41
|
+
(0, vue.watch)(selection, () => {
|
|
42
|
+
if (selection.value) getTextArea().setSelectionRange(...selection.value);
|
|
46
43
|
});
|
|
47
|
-
const countConfig = (0, __v_c_input.useCount)(
|
|
44
|
+
const countConfig = (0, __v_c_input.useCount)(count, showCount);
|
|
48
45
|
const mergedMax = (0, vue.computed)(() => countConfig.value.max ?? props.maxLength);
|
|
49
46
|
const hasMaxLength = (0, vue.computed)(() => Number(mergedMax.value) > 0);
|
|
50
47
|
const valueLength = (0, vue.computed)(() => countConfig.value.strategy(formatValue.value));
|
|
51
48
|
const isOutOfRange = (0, vue.computed)(() => !!mergedMax.value && valueLength.value > mergedMax.value);
|
|
52
|
-
const onChange = (e) => {
|
|
53
|
-
props.onChange?.(e);
|
|
54
|
-
};
|
|
55
49
|
const triggerChange = (e, currentValue) => {
|
|
56
50
|
let cutValue = currentValue;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
cutValue =
|
|
60
|
-
if (currentValue !== cutValue) selection.value = [getTextArea()?.selectionStart || 0, getTextArea()?.selectionEnd || 0];
|
|
51
|
+
if (!compositionRef.value && countConfig.value.exceedFormatter && countConfig.value.max && countConfig.value.strategy(currentValue) > countConfig.value.max) {
|
|
52
|
+
cutValue = countConfig.value.exceedFormatter(currentValue, { max: countConfig.value.max });
|
|
53
|
+
if (currentValue !== cutValue) selection.value = [getTextArea().selectionStart || 0, getTextArea().selectionEnd || 0];
|
|
61
54
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
(0, vue.nextTick)(() => {
|
|
65
|
-
resizableTextAreaRef.value?.setValue?.(cutValue);
|
|
66
|
-
});
|
|
67
|
-
(0, __v_c_input.resolveOnChange)(e.currentTarget, e, onChange, cutValue);
|
|
55
|
+
value.value = cutValue;
|
|
56
|
+
(0, __v_c_input.resolveOnChange)(e.currentTarget, e, props.onChange, cutValue);
|
|
68
57
|
};
|
|
69
|
-
const onInternalCompositionStart = (
|
|
58
|
+
const onInternalCompositionStart = () => {
|
|
70
59
|
compositionRef.value = true;
|
|
71
|
-
props.onCompositionStart?.(e);
|
|
72
60
|
};
|
|
73
61
|
const onInternalCompositionEnd = (e) => {
|
|
74
62
|
compositionRef.value = false;
|
|
75
|
-
triggerChange(e, e.
|
|
76
|
-
props.onCompositionEnd?.(e);
|
|
63
|
+
triggerChange(e, e.currentTarget.value);
|
|
77
64
|
};
|
|
78
65
|
const onInternalChange = (e) => {
|
|
79
66
|
triggerChange(e, e.target.value);
|
|
80
67
|
};
|
|
81
68
|
const handleKeyDown = (e) => {
|
|
82
|
-
|
|
83
|
-
|
|
69
|
+
const { onPressEnter } = props;
|
|
70
|
+
if (e.key === __v_c_util_dist_KeyCode_ts.KeyCodeStr.Enter && onPressEnter && !e.isComposing) onPressEnter(e);
|
|
84
71
|
};
|
|
85
|
-
const handleFocus = (
|
|
72
|
+
const handleFocus = () => {
|
|
86
73
|
focused.value = true;
|
|
87
|
-
props.onFocus?.(e);
|
|
88
74
|
};
|
|
89
|
-
const handleBlur = (
|
|
75
|
+
const handleBlur = () => {
|
|
90
76
|
focused.value = false;
|
|
91
|
-
props.onBlur?.(e);
|
|
92
77
|
};
|
|
93
78
|
const handleReset = (e) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
value.value = "";
|
|
80
|
+
focus();
|
|
81
|
+
(0, __v_c_input.resolveOnChange)(getTextArea(), e, props.onChange);
|
|
97
82
|
};
|
|
98
83
|
const handleResize = (size) => {
|
|
99
|
-
props
|
|
84
|
+
props?.onResize?.(size);
|
|
100
85
|
if (getTextArea()?.style.height) textareaResized.value = true;
|
|
101
86
|
};
|
|
102
|
-
const mergedAllowClear = (0, vue.computed)(() => {
|
|
103
|
-
if (!props.allowClear) return props.allowClear;
|
|
104
|
-
const clearIcon = slots.clearIcon?.();
|
|
105
|
-
if (clearIcon) return {
|
|
106
|
-
...typeof props.allowClear === "object" ? props.allowClear : {},
|
|
107
|
-
clearIcon
|
|
108
|
-
};
|
|
109
|
-
return props.allowClear;
|
|
110
|
-
});
|
|
111
87
|
return () => {
|
|
112
|
-
const {
|
|
113
|
-
const {
|
|
114
|
-
|
|
115
|
-
const mergedStyle = {
|
|
116
|
-
...props.style,
|
|
117
|
-
...attrStyle
|
|
118
|
-
};
|
|
119
|
-
let suffixNode = slots.suffix?.() ?? suffix;
|
|
88
|
+
const { suffix, className, classNames, styles, prefixCls = "vc-textarea", allowClear, autoSize, showCount: showCount$1, disabled, hidden, readOnly, onClear, maxLength } = props;
|
|
89
|
+
const { style, restAttrs } = (0, __v_c_util_dist_props_util.getAttrStyleAndClass)(attrs);
|
|
90
|
+
let suffixNode = suffix;
|
|
120
91
|
let dataCount;
|
|
121
92
|
if (countConfig.value.show) {
|
|
122
|
-
if (countConfig.value.showFormatter) dataCount = countConfig.value.showFormatter({
|
|
93
|
+
if (countConfig.value.showFormatter) dataCount = countConfig.value.showFormatter?.({
|
|
123
94
|
value: formatValue.value,
|
|
124
95
|
count: valueLength.value,
|
|
125
96
|
maxLength: mergedMax.value
|
|
126
97
|
});
|
|
127
98
|
else dataCount = `${valueLength.value}${hasMaxLength.value ? ` / ${mergedMax.value}` : ""}`;
|
|
128
99
|
suffixNode = (0, vue.createVNode)(vue.Fragment, null, [suffixNode, (0, vue.createVNode)("span", {
|
|
129
|
-
"class": (0, __v_c_util.
|
|
100
|
+
"class": (0, __v_c_util.clsx)(`${prefixCls}-data-count`, classNames?.count),
|
|
130
101
|
"style": styles?.count
|
|
131
102
|
}, [dataCount])]);
|
|
132
103
|
}
|
|
133
|
-
const isPureTextArea = !autoSize && !showCount && !allowClear;
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
104
|
+
const isPureTextArea = !autoSize && !showCount$1 && !allowClear;
|
|
105
|
+
const textareaProps = {
|
|
106
|
+
onKeydown: handleKeyDown,
|
|
107
|
+
onFocus: handleFocus,
|
|
108
|
+
onBlur: handleBlur,
|
|
109
|
+
onCompositionstart: onInternalCompositionStart,
|
|
110
|
+
onCompositionend: onInternalCompositionEnd
|
|
140
111
|
};
|
|
141
|
-
const inputAttrs = (0, __v_c_util_dist_omit.default)(restAttrs, [
|
|
142
|
-
"class",
|
|
143
|
-
"style",
|
|
144
|
-
"onFocus",
|
|
145
|
-
"onBlur",
|
|
146
|
-
"onChange",
|
|
147
|
-
"onCompositionstart",
|
|
148
|
-
"onCompositionend",
|
|
149
|
-
"onKeydown",
|
|
150
|
-
"onKeyup",
|
|
151
|
-
"onInput"
|
|
152
|
-
]);
|
|
153
|
-
const restProps = (0, __v_c_util_dist_omit.default)(props, [
|
|
154
|
-
"class",
|
|
155
|
-
"style",
|
|
156
|
-
"onFocus",
|
|
157
|
-
"onBlur",
|
|
158
|
-
"onChange",
|
|
159
|
-
"onCompositionEnd",
|
|
160
|
-
"onCompositionStart",
|
|
161
|
-
"onKeyDown",
|
|
162
|
-
"allowClear",
|
|
163
|
-
"maxLength",
|
|
164
|
-
"prefixCls",
|
|
165
|
-
"showCount",
|
|
166
|
-
"disabled",
|
|
167
|
-
"hidden",
|
|
168
|
-
"classNames",
|
|
169
|
-
"styles",
|
|
170
|
-
"onClear",
|
|
171
|
-
"readOnly",
|
|
172
|
-
"autoSize",
|
|
173
|
-
"suffix",
|
|
174
|
-
"onResize"
|
|
175
|
-
]);
|
|
176
112
|
return (0, vue.createVNode)(__v_c_input.BaseInput, {
|
|
177
113
|
"ref": holderRef,
|
|
178
114
|
"value": formatValue.value,
|
|
179
|
-
"allowClear":
|
|
115
|
+
"allowClear": allowClear,
|
|
180
116
|
"handleReset": handleReset,
|
|
181
117
|
"suffix": suffixNode,
|
|
182
118
|
"prefixCls": prefixCls,
|
|
183
|
-
"classNames":
|
|
119
|
+
"classNames": {
|
|
120
|
+
...classNames,
|
|
121
|
+
affixWrapper: (0, __v_c_util.clsx)(classNames?.affixWrapper, {
|
|
122
|
+
[`${prefixCls}-show-count`]: showCount$1,
|
|
123
|
+
[`${prefixCls}-textarea-allow-clear`]: allowClear
|
|
124
|
+
})
|
|
125
|
+
},
|
|
184
126
|
"disabled": disabled,
|
|
185
127
|
"focused": focused.value,
|
|
186
|
-
"class": (0, __v_c_util.
|
|
128
|
+
"class": (0, __v_c_util.clsx)(className, isOutOfRange.value && `${prefixCls}-out-of-range`),
|
|
187
129
|
"style": {
|
|
188
|
-
...
|
|
130
|
+
...style,
|
|
189
131
|
...textareaResized.value && !isPureTextArea ? { height: "auto" } : {}
|
|
190
132
|
},
|
|
191
133
|
"dataAttrs": { affixWrapper: { "data-count": typeof dataCount === "string" ? dataCount : void 0 } },
|
|
192
134
|
"hidden": hidden,
|
|
193
135
|
"readOnly": readOnly,
|
|
194
136
|
"onClear": onClear
|
|
195
|
-
}, { default: () => [(0, vue.createVNode)(require_ResizableTextArea.default, (0, vue.mergeProps)(
|
|
196
|
-
"value": stateValue.value,
|
|
137
|
+
}, { default: () => [(0, vue.createVNode)(require_ResizableTextArea.default, (0, vue.mergeProps)(restAttrs, {
|
|
197
138
|
"autoSize": autoSize,
|
|
198
139
|
"maxLength": maxLength,
|
|
199
|
-
"
|
|
200
|
-
|
|
201
|
-
"
|
|
202
|
-
"onBlur": handleBlur,
|
|
203
|
-
"onCompositionstart": onInternalCompositionStart,
|
|
204
|
-
"onCompositionend": onInternalCompositionEnd,
|
|
205
|
-
"class": (0, __v_c_util.classNames)(classNames?.textarea),
|
|
140
|
+
"onChange": onInternalChange
|
|
141
|
+
}, textareaProps, {
|
|
142
|
+
"className": (0, __v_c_util.clsx)(classNames?.textarea),
|
|
206
143
|
"style": {
|
|
207
|
-
|
|
208
|
-
|
|
144
|
+
resize: style?.resize,
|
|
145
|
+
...styles?.textarea
|
|
209
146
|
},
|
|
210
147
|
"disabled": disabled,
|
|
211
148
|
"prefixCls": prefixCls,
|
|
@@ -217,12 +154,12 @@ var TextArea_default = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs,
|
|
|
217
154
|
}, {
|
|
218
155
|
props: /* @__PURE__ */ (0, vue.mergeDefaults)({
|
|
219
156
|
value: {
|
|
220
|
-
type:
|
|
157
|
+
type: null,
|
|
221
158
|
required: false,
|
|
222
159
|
default: void 0
|
|
223
160
|
},
|
|
224
161
|
defaultValue: {
|
|
225
|
-
type:
|
|
162
|
+
type: null,
|
|
226
163
|
required: false,
|
|
227
164
|
default: void 0
|
|
228
165
|
},
|
|
@@ -231,28 +168,28 @@ var TextArea_default = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs,
|
|
|
231
168
|
required: false,
|
|
232
169
|
default: void 0
|
|
233
170
|
},
|
|
234
|
-
|
|
235
|
-
type:
|
|
171
|
+
disabled: {
|
|
172
|
+
type: Boolean,
|
|
236
173
|
required: false,
|
|
237
174
|
default: void 0
|
|
238
175
|
},
|
|
239
|
-
|
|
240
|
-
type:
|
|
176
|
+
className: {
|
|
177
|
+
type: String,
|
|
241
178
|
required: false,
|
|
242
179
|
default: void 0
|
|
243
180
|
},
|
|
244
|
-
|
|
245
|
-
type:
|
|
181
|
+
autoSize: {
|
|
182
|
+
type: [Boolean, Object],
|
|
246
183
|
required: false,
|
|
247
184
|
default: void 0
|
|
248
185
|
},
|
|
249
|
-
|
|
186
|
+
onPressEnter: {
|
|
250
187
|
type: Function,
|
|
251
188
|
required: false,
|
|
252
189
|
default: void 0
|
|
253
190
|
},
|
|
254
|
-
|
|
255
|
-
type:
|
|
191
|
+
onResize: {
|
|
192
|
+
type: Function,
|
|
256
193
|
required: false,
|
|
257
194
|
default: void 0
|
|
258
195
|
},
|
|
@@ -271,106 +208,54 @@ var TextArea_default = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs,
|
|
|
271
208
|
required: false,
|
|
272
209
|
default: void 0
|
|
273
210
|
},
|
|
274
|
-
showCount: {
|
|
275
|
-
type: [Boolean, Object],
|
|
276
|
-
required: false,
|
|
277
|
-
default: void 0
|
|
278
|
-
},
|
|
279
|
-
count: {
|
|
280
|
-
type: Object,
|
|
281
|
-
required: false,
|
|
282
|
-
default: void 0
|
|
283
|
-
},
|
|
284
|
-
maxLength: {
|
|
285
|
-
type: Number,
|
|
286
|
-
required: false,
|
|
287
|
-
default: void 0
|
|
288
|
-
},
|
|
289
211
|
suffix: {
|
|
290
|
-
type:
|
|
291
|
-
String,
|
|
292
|
-
Number,
|
|
293
|
-
null,
|
|
294
|
-
Boolean,
|
|
295
|
-
Array
|
|
296
|
-
],
|
|
297
|
-
required: false,
|
|
298
|
-
skipCheck: true,
|
|
299
|
-
default: void 0
|
|
300
|
-
},
|
|
301
|
-
disabled: {
|
|
302
|
-
type: Boolean,
|
|
303
|
-
required: false,
|
|
304
|
-
default: void 0
|
|
305
|
-
},
|
|
306
|
-
hidden: {
|
|
307
|
-
type: Boolean,
|
|
308
|
-
required: false,
|
|
309
|
-
default: void 0
|
|
310
|
-
},
|
|
311
|
-
onChange: {
|
|
312
|
-
type: Function,
|
|
313
|
-
required: false,
|
|
314
|
-
default: void 0
|
|
315
|
-
},
|
|
316
|
-
onFocus: {
|
|
317
|
-
type: Function,
|
|
212
|
+
type: null,
|
|
318
213
|
required: false,
|
|
319
214
|
default: void 0
|
|
320
215
|
},
|
|
321
|
-
|
|
322
|
-
type:
|
|
216
|
+
showCount: {
|
|
217
|
+
type: [Boolean, Object],
|
|
323
218
|
required: false,
|
|
324
219
|
default: void 0
|
|
325
220
|
},
|
|
326
|
-
|
|
327
|
-
type:
|
|
221
|
+
count: {
|
|
222
|
+
type: null,
|
|
328
223
|
required: false,
|
|
329
224
|
default: void 0
|
|
330
225
|
},
|
|
331
|
-
|
|
226
|
+
onClear: {
|
|
332
227
|
type: Function,
|
|
333
228
|
required: false,
|
|
334
229
|
default: void 0
|
|
335
230
|
},
|
|
336
|
-
|
|
231
|
+
onChange: {
|
|
337
232
|
type: Function,
|
|
338
233
|
required: false,
|
|
339
234
|
default: void 0
|
|
340
235
|
},
|
|
341
|
-
|
|
342
|
-
type:
|
|
236
|
+
maxLength: {
|
|
237
|
+
type: Number,
|
|
343
238
|
required: false,
|
|
344
239
|
default: void 0
|
|
345
240
|
},
|
|
346
|
-
|
|
347
|
-
type:
|
|
241
|
+
minLength: {
|
|
242
|
+
type: Number,
|
|
348
243
|
required: false,
|
|
349
244
|
default: void 0
|
|
350
245
|
},
|
|
351
|
-
|
|
352
|
-
type:
|
|
246
|
+
hidden: {
|
|
247
|
+
type: Boolean,
|
|
353
248
|
required: false,
|
|
354
249
|
default: void 0
|
|
355
250
|
},
|
|
356
|
-
|
|
357
|
-
type:
|
|
251
|
+
readOnly: {
|
|
252
|
+
type: Boolean,
|
|
358
253
|
required: false,
|
|
359
254
|
default: void 0
|
|
360
255
|
}
|
|
361
|
-
},
|
|
256
|
+
}, { prefixCls: "vc-textarea" }),
|
|
362
257
|
name: "TextArea",
|
|
363
|
-
inheritAttrs: false
|
|
364
|
-
emits: [
|
|
365
|
-
"update:value",
|
|
366
|
-
"change",
|
|
367
|
-
"compositionStart",
|
|
368
|
-
"compositionEnd",
|
|
369
|
-
"pressEnter",
|
|
370
|
-
"keydown",
|
|
371
|
-
"focus",
|
|
372
|
-
"blur",
|
|
373
|
-
"resize"
|
|
374
|
-
]
|
|
258
|
+
inheritAttrs: false
|
|
375
259
|
});
|
|
260
|
+
var TextArea_default = TextArea;
|
|
376
261
|
exports.default = TextArea_default;
|
package/dist/TextArea.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { TextAreaProps } from './interface';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
2
|
+
declare const TextArea: import('vue').DefineSetupFnComponent<TextAreaProps, {}, {}, TextAreaProps & {}, import('vue').PublicProps>;
|
|
3
|
+
export default TextArea;
|