@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/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 __v_c_util_dist_omit = require("@v-c/util/dist/omit");
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
- var defaults = { prefixCls: "vc-textarea" };
10
- var TextArea_default = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, expose, slots, emit }) => {
11
- const stateValue = (0, vue.shallowRef)(props.value ?? props.defaultValue);
12
- (0, vue.watch)(() => props.value, (newValue) => {
13
- if ("value" in props || {}) stateValue.value = newValue;
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 setValue = (val, callback) => {
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)(false);
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()?.focus();
23
+ getTextArea().focus();
31
24
  };
32
25
  expose({
33
- resizableTextArea: (0, vue.computed)(() => resizableTextAreaRef.value),
26
+ resizableTextArea: resizableTextAreaRef,
34
27
  focus,
35
28
  blur: () => {
36
- getTextArea()?.blur();
29
+ getTextArea().blur();
37
30
  },
38
- nativeElement: (0, vue.computed)(() => holderRef.value?.nativeElement || getTextArea() || null)
31
+ nativeElement: (0, vue.computed)(() => holderRef.value?.nativeElement || getTextArea())
39
32
  });
40
- (0, vue.watch)(() => props.disabled, (newDisabled) => {
41
- focused.value = !newDisabled && focused.value;
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, (newSelection) => {
45
- if (newSelection) getTextArea()?.setSelectionRange(...newSelection);
41
+ (0, vue.watch)(selection, () => {
42
+ if (selection.value) getTextArea().setSelectionRange(...selection.value);
46
43
  });
47
- const countConfig = (0, __v_c_input.useCount)((0, vue.computed)(() => props.count), (0, vue.computed)(() => props.showCount));
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
- const cfg = countConfig.value;
58
- if (!compositionRef.value && cfg.exceedFormatter && cfg.max && cfg.strategy(currentValue) > cfg.max) {
59
- cutValue = cfg.exceedFormatter(currentValue, { max: cfg.max });
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
- setValue(cutValue);
63
- emit("update:value", cutValue);
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 = (e) => {
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.target.value);
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
- if (e.key === "Enter" && props.onPressEnter && !e.isComposing) props.onPressEnter?.(e);
83
- props.onKeyDown?.(e);
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 = (e) => {
72
+ const handleFocus = () => {
86
73
  focused.value = true;
87
- props.onFocus?.(e);
88
74
  };
89
- const handleBlur = (e) => {
75
+ const handleBlur = () => {
90
76
  focused.value = false;
91
- props.onBlur?.(e);
92
77
  };
93
78
  const handleReset = (e) => {
94
- (0, __v_c_input.resolveOnChange)(getTextArea(), e, onChange);
95
- setValue("", () => focus());
96
- emit("update:value", "");
79
+ value.value = "";
80
+ focus();
81
+ (0, __v_c_input.resolveOnChange)(getTextArea(), e, props.onChange);
97
82
  };
98
83
  const handleResize = (size) => {
99
- props.onResize?.(size);
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 { allowClear, maxLength, prefixCls = defaults.prefixCls, showCount, disabled, hidden, classNames, styles, onClear, readOnly, autoSize, suffix } = props;
113
- const { class: attrClass, style: attrStyle,...restAttrs } = attrs;
114
- const mergedClassName = props.className || attrClass;
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.classNames)(`${prefixCls}-data-count`, classNames?.count),
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 baseInputClassNames = {
135
- ...classNames,
136
- affixWrapper: (0, __v_c_util.classNames)(classNames?.affixWrapper, {
137
- [`${prefixCls}-show-count`]: showCount,
138
- [`${prefixCls}-textarea-allow-clear`]: allowClear
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": mergedAllowClear.value,
115
+ "allowClear": allowClear,
180
116
  "handleReset": handleReset,
181
117
  "suffix": suffixNode,
182
118
  "prefixCls": prefixCls,
183
- "classNames": baseInputClassNames,
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.classNames)([mergedClassName], isOutOfRange.value && `${prefixCls}-out-of-range`),
128
+ "class": (0, __v_c_util.clsx)(className, isOutOfRange.value && `${prefixCls}-out-of-range`),
187
129
  "style": {
188
- ...mergedStyle,
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)(inputAttrs, restProps, {
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
- "onKeydown": handleKeyDown,
200
- "onChange": onInternalChange,
201
- "onFocus": handleFocus,
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
- ...styles?.textarea,
208
- resize: attrStyle?.resize
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: [String, Number],
157
+ type: null,
221
158
  required: false,
222
159
  default: void 0
223
160
  },
224
161
  defaultValue: {
225
- type: [String, Number],
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
- autoSize: {
235
- type: [Boolean, Object],
171
+ disabled: {
172
+ type: Boolean,
236
173
  required: false,
237
174
  default: void 0
238
175
  },
239
- onPressEnter: {
240
- type: Function,
176
+ className: {
177
+ type: String,
241
178
  required: false,
242
179
  default: void 0
243
180
  },
244
- onResize: {
245
- type: Function,
181
+ autoSize: {
182
+ type: [Boolean, Object],
246
183
  required: false,
247
184
  default: void 0
248
185
  },
249
- onClear: {
186
+ onPressEnter: {
250
187
  type: Function,
251
188
  required: false,
252
189
  default: void 0
253
190
  },
254
- readOnly: {
255
- type: Boolean,
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
- onBlur: {
322
- type: Function,
216
+ showCount: {
217
+ type: [Boolean, Object],
323
218
  required: false,
324
219
  default: void 0
325
220
  },
326
- onCompositionStart: {
327
- type: Function,
221
+ count: {
222
+ type: null,
328
223
  required: false,
329
224
  default: void 0
330
225
  },
331
- onCompositionEnd: {
226
+ onClear: {
332
227
  type: Function,
333
228
  required: false,
334
229
  default: void 0
335
230
  },
336
- onKeyDown: {
231
+ onChange: {
337
232
  type: Function,
338
233
  required: false,
339
234
  default: void 0
340
235
  },
341
- className: {
342
- type: String,
236
+ maxLength: {
237
+ type: Number,
343
238
  required: false,
344
239
  default: void 0
345
240
  },
346
- class: {
347
- type: null,
241
+ minLength: {
242
+ type: Number,
348
243
  required: false,
349
244
  default: void 0
350
245
  },
351
- style: {
352
- type: null,
246
+ hidden: {
247
+ type: Boolean,
353
248
  required: false,
354
249
  default: void 0
355
250
  },
356
- placeholder: {
357
- type: String,
251
+ readOnly: {
252
+ type: Boolean,
358
253
  required: false,
359
254
  default: void 0
360
255
  }
361
- }, defaults),
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;
@@ -1,3 +1,3 @@
1
1
  import { TextAreaProps } from './interface';
2
- declare const _default: import('vue').DefineSetupFnComponent<TextAreaProps, {}, {}, TextAreaProps & {}, import('vue').PublicProps>;
3
- export default _default;
2
+ declare const TextArea: import('vue').DefineSetupFnComponent<TextAreaProps, {}, {}, TextAreaProps & {}, import('vue').PublicProps>;
3
+ export default TextArea;