@v-c/textarea 1.0.3 → 1.0.4

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.
@@ -5,10 +5,11 @@ import { clsx } from "@v-c/util";
5
5
  import omit from "@v-c/util/dist/omit";
6
6
  import { getAttrStyleAndClass } from "@v-c/util/dist/props-util";
7
7
  import raf from "@v-c/util/dist/raf";
8
+ //#region src/ResizableTextArea.tsx
8
9
  var RESIZE_START = 0;
9
10
  var RESIZE_MEASURING = 1;
10
11
  var RESIZE_STABLE = 2;
11
- var ResizableTextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }) => {
12
+ var ResizableTextArea = /* @__PURE__ */ defineComponent((props, { expose, attrs }) => {
12
13
  const internalValue = ref(props?.value ?? props?.defaultValue ?? "");
13
14
  watch(() => props.value, () => {
14
15
  internalValue.value = props.value;
@@ -229,9 +230,15 @@ var ResizableTextArea_default = /* @__PURE__ */ defineComponent((props, { expose
229
230
  type: Function,
230
231
  required: false,
231
232
  default: void 0
233
+ },
234
+ changeOnComposing: {
235
+ type: Boolean,
236
+ required: false,
237
+ default: void 0
232
238
  }
233
239
  },
234
240
  name: "ResizableTextArea",
235
241
  inheritAttrs: false
236
242
  });
237
- export { ResizableTextArea_default as default };
243
+ //#endregion
244
+ export { ResizableTextArea as default };
package/dist/TextArea.js CHANGED
@@ -1,11 +1,12 @@
1
- import ResizableTextArea_default from "./ResizableTextArea.js";
1
+ import ResizableTextArea from "./ResizableTextArea.js";
2
2
  import { Fragment, computed, createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef, watch } from "vue";
3
3
  import { clsx } from "@v-c/util";
4
4
  import omit from "@v-c/util/dist/omit";
5
5
  import { getAttrStyleAndClass, toPropsRefs } from "@v-c/util/dist/props-util";
6
6
  import { BaseInput, resolveOnChange, useCount } from "@v-c/input";
7
7
  import { KeyCodeStr } from "@v-c/util/dist/KeyCode";
8
- var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }) => {
8
+ //#region src/TextArea.tsx
9
+ var TextArea = /* @__PURE__ */ defineComponent((props, { expose, attrs }) => {
9
10
  const { count, showCount } = toPropsRefs(props, "count", "showCount");
10
11
  const value = shallowRef(props?.value ?? props?.defaultValue ?? "");
11
12
  watch(() => props.value, () => {
@@ -14,6 +15,7 @@ var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
14
15
  const formatValue = computed(() => value.value === void 0 || value.value === null ? "" : String(value.value));
15
16
  const focused = shallowRef(false);
16
17
  const compositionRef = shallowRef(false);
18
+ const compositionEndValueRef = shallowRef(null);
17
19
  const textareaResized = shallowRef();
18
20
  const holderRef = shallowRef();
19
21
  const resizableTextAreaRef = shallowRef();
@@ -46,23 +48,31 @@ var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
46
48
  const valueLength = computed(() => countConfig.value.strategy(formatValue.value));
47
49
  const isOutOfRange = computed(() => !!mergedMax.value && valueLength.value > mergedMax.value);
48
50
  const triggerChange = (e, currentValue) => {
51
+ if (compositionRef.value && !props.changeOnComposing) return;
52
+ if (compositionEndValueRef.value !== null) {
53
+ if (currentValue === compositionEndValueRef.value) return;
54
+ compositionEndValueRef.value = null;
55
+ }
49
56
  let cutValue = currentValue;
50
57
  if (!compositionRef.value && countConfig.value.exceedFormatter && countConfig.value.max && countConfig.value.strategy(currentValue) > countConfig.value.max) {
51
58
  cutValue = countConfig.value.exceedFormatter(currentValue, { max: countConfig.value.max });
52
- const textarea$1 = getTextArea();
53
- if (currentValue !== cutValue) selection.value = [textarea$1.selectionStart || 0, textarea$1.selectionEnd || 0];
59
+ const textarea = getTextArea();
60
+ if (currentValue !== cutValue) selection.value = [textarea.selectionStart || 0, textarea.selectionEnd || 0];
54
61
  }
55
62
  const textarea = getTextArea();
56
- if (!compositionRef.value && textarea && textarea.value !== cutValue) textarea.value = cutValue;
63
+ if (textarea && textarea.value !== cutValue) textarea.value = cutValue;
57
64
  value.value = cutValue;
58
65
  resolveOnChange(e.currentTarget, e, props.onChange, cutValue);
59
66
  };
60
67
  const onInternalCompositionStart = () => {
61
68
  compositionRef.value = true;
69
+ compositionEndValueRef.value = null;
62
70
  };
63
71
  const onInternalCompositionEnd = (e) => {
64
72
  compositionRef.value = false;
65
- triggerChange(e, e.currentTarget.value);
73
+ const currentValue = e.currentTarget.value;
74
+ if (!props.changeOnComposing && currentValue !== formatValue.value) triggerChange(e, currentValue);
75
+ if (!props.changeOnComposing) compositionEndValueRef.value = currentValue;
66
76
  };
67
77
  const onInternalChange = (e) => {
68
78
  triggerChange(e, e.target.value);
@@ -81,6 +91,7 @@ var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
81
91
  props?.onBlur?.(e);
82
92
  };
83
93
  const handleReset = (e) => {
94
+ compositionEndValueRef.value = null;
84
95
  value.value = "";
85
96
  focus();
86
97
  resolveOnChange(getTextArea(), e, props.onChange);
@@ -90,7 +101,7 @@ var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
90
101
  if (getTextArea()?.style.height) textareaResized.value = true;
91
102
  };
92
103
  return () => {
93
- const { suffix, classNames, styles, prefixCls = "vc-textarea", allowClear, autoSize, showCount: showCount$1, disabled, hidden, readOnly, onClear, maxLength } = props;
104
+ const { suffix, classNames, styles, prefixCls = "vc-textarea", allowClear, autoSize, showCount, disabled, hidden, readOnly, onClear, maxLength } = props;
94
105
  const { style, restAttrs, className } = getAttrStyleAndClass(attrs);
95
106
  let suffixNode = suffix;
96
107
  let dataCount;
@@ -106,7 +117,7 @@ var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
106
117
  "style": styles?.count
107
118
  }, [dataCount])]);
108
119
  }
109
- const isPureTextArea = !autoSize && !showCount$1 && !allowClear;
120
+ const isPureTextArea = !autoSize && !showCount && !allowClear;
110
121
  const textareaProps = {
111
122
  onKeydown: handleKeyDown,
112
123
  onFocus: handleFocus,
@@ -124,7 +135,7 @@ var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
124
135
  "classNames": {
125
136
  ...classNames,
126
137
  affixWrapper: clsx(classNames?.affixWrapper, {
127
- [`${prefixCls}-show-count`]: showCount$1,
138
+ [`${prefixCls}-show-count`]: showCount,
128
139
  [`${prefixCls}-textarea-allow-clear`]: allowClear
129
140
  })
130
141
  },
@@ -139,7 +150,7 @@ var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
139
150
  "hidden": hidden,
140
151
  "readOnly": readOnly,
141
152
  "onClear": onClear
142
- }, { default: () => [createVNode(ResizableTextArea_default, mergeProps(restAttrs, omit(props, [
153
+ }, { default: () => [createVNode(ResizableTextArea, mergeProps(restAttrs, omit(props, [
143
154
  "suffix",
144
155
  "classNames",
145
156
  "styles",
@@ -157,7 +168,8 @@ var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
157
168
  "onKeydown",
158
169
  "onPressEnter",
159
170
  "onFocus",
160
- "onBlur"
171
+ "onBlur",
172
+ "changeOnComposing"
161
173
  ]), {
162
174
  "autoSize": autoSize,
163
175
  "maxLength": maxLength,
@@ -293,9 +305,15 @@ var TextArea_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
293
305
  type: Function,
294
306
  required: false,
295
307
  default: void 0
308
+ },
309
+ changeOnComposing: {
310
+ type: Boolean,
311
+ required: false,
312
+ default: void 0
296
313
  }
297
314
  }, { prefixCls: "vc-textarea" }),
298
315
  name: "TextArea",
299
316
  inheritAttrs: false
300
317
  });
301
- export { TextArea_default as default };
318
+ //#endregion
319
+ export { TextArea as default };
@@ -1,3 +1,7 @@
1
+ //#region src/calculateNodeHeight.tsx
2
+ /**
3
+ * calculateNodeHeight(uiTextNode, useCache = false)
4
+ */
1
5
  var HIDDEN_TEXTAREA_STYLE = `
2
6
  min-height:0 !important;
3
7
  max-height:none !important;
@@ -91,4 +95,5 @@ function calculateAutoSizeStyle(uiTextNode, useCache = false, minRows = null, ma
91
95
  if (maxHeight) style.maxHeight = `${maxHeight}px`;
92
96
  return style;
93
97
  }
98
+ //#endregion
94
99
  export { calculateNodeStyling, calculateAutoSizeStyle as default };
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
- import ResizableTextArea_default from "./ResizableTextArea.js";
2
- import TextArea_default from "./TextArea.js";
3
- var src_default = TextArea_default;
4
- export { ResizableTextArea_default as ResizableTextArea, src_default as default };
1
+ import ResizableTextArea from "./ResizableTextArea.js";
2
+ import TextArea from "./TextArea.js";
3
+ //#region src/index.ts
4
+ var src_default = TextArea;
5
+ //#endregion
6
+ export { ResizableTextArea, src_default as default };
@@ -42,6 +42,12 @@ export interface TextAreaProps {
42
42
  onKeyup?: (e: KeyboardEvent) => void;
43
43
  onFocus?: (e: FocusEvent) => void;
44
44
  onBlur?: (e: FocusEvent) => void;
45
+ /**
46
+ * Whether to trigger onChange during IME composition.
47
+ * When false (default), onChange only fires after compositionEnd with the final value.
48
+ * When true, onChange fires on every keystroke including intermediate IME values.
49
+ */
50
+ changeOnComposing?: boolean;
45
51
  }
46
52
  export interface TextAreaRef {
47
53
  resizableTextArea: ResizableTextAreaRef;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/textarea",
3
3
  "type": "module",
4
- "version": "1.0.3",
4
+ "version": "1.0.4",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -9,7 +9,7 @@
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.js",
12
- "require": "./dist/index.cjs"
12
+ "default": "./dist/index.js"
13
13
  },
14
14
  "./dist/*": "./dist/*",
15
15
  "./package.json": "./package.json"
@@ -23,9 +23,9 @@
23
23
  "vue": "^3.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "@v-c/input": "^1.0.2",
26
+ "@v-c/input": "^1.0.3",
27
27
  "@v-c/resize-observer": "^1.0.8",
28
- "@v-c/util": "^1.0.9"
28
+ "@v-c/util": "^1.0.19"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "vite build",
@@ -1,245 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
6
- const require_calculateNodeHeight = require("./calculateNodeHeight.cjs");
7
- let vue = require("vue");
8
- let _v_c_resize_observer = require("@v-c/resize-observer");
9
- let _v_c_util = require("@v-c/util");
10
- let _v_c_util_dist_omit = require("@v-c/util/dist/omit");
11
- _v_c_util_dist_omit = require_rolldown_runtime.__toESM(_v_c_util_dist_omit);
12
- let _v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
13
- let _v_c_util_dist_raf = require("@v-c/util/dist/raf");
14
- _v_c_util_dist_raf = require_rolldown_runtime.__toESM(_v_c_util_dist_raf);
15
- var RESIZE_START = 0;
16
- var RESIZE_MEASURING = 1;
17
- var RESIZE_STABLE = 2;
18
- var ResizableTextArea = /* @__PURE__ */ (0, vue.defineComponent)((props, { expose, attrs }) => {
19
- const internalValue = (0, vue.ref)(props?.value ?? props?.defaultValue ?? "");
20
- (0, vue.watch)(() => props.value, () => {
21
- internalValue.value = props.value;
22
- });
23
- const mergedValue = (0, vue.computed)(() => internalValue.value ?? "");
24
- const onInternalChange = (e) => {
25
- if (props.value === void 0) internalValue.value = e.target.value;
26
- props?.onChange?.(e);
27
- };
28
- const textareaRef = (0, vue.shallowRef)();
29
- expose({ textArea: textareaRef });
30
- const autoSizeData = (0, vue.computed)(() => {
31
- const autoSize = props.autoSize;
32
- if (autoSize && typeof autoSize === "object") return [autoSize.minRows, autoSize.maxRows];
33
- return [];
34
- });
35
- const minRows = (0, vue.computed)(() => autoSizeData?.value?.[0]);
36
- const maxRows = (0, vue.computed)(() => autoSizeData?.value?.[1]);
37
- const resizeState = (0, vue.ref)(RESIZE_STABLE);
38
- const autoSizeStyle = (0, vue.shallowRef)({});
39
- const startResize = () => {
40
- resizeState.value = RESIZE_START;
41
- };
42
- const needAutoSize = (0, vue.computed)(() => !!props.autoSize);
43
- (0, vue.watch)([
44
- () => props.value,
45
- minRows,
46
- maxRows,
47
- needAutoSize
48
- ], async () => {
49
- await (0, vue.nextTick)();
50
- if (needAutoSize.value) startResize();
51
- }, {
52
- immediate: true,
53
- flush: "post"
54
- });
55
- (0, vue.watch)([resizeState, textareaRef], () => {
56
- if (!textareaRef.value) return;
57
- if (resizeState.value === RESIZE_START) resizeState.value = RESIZE_MEASURING;
58
- else if (resizeState.value === RESIZE_MEASURING) {
59
- const textareaStyles = require_calculateNodeHeight.default(textareaRef.value, false, minRows.value, maxRows.value);
60
- resizeState.value = RESIZE_STABLE;
61
- autoSizeStyle.value = textareaStyles;
62
- }
63
- });
64
- const resizeRafRef = (0, vue.shallowRef)();
65
- const cleanRaf = () => {
66
- _v_c_util_dist_raf.default.cancel(resizeRafRef.value);
67
- };
68
- const onInternalResize = (size) => {
69
- if (resizeState.value === RESIZE_STABLE) {
70
- props?.onResize?.(size);
71
- if (props.autoSize) {
72
- cleanRaf();
73
- resizeRafRef.value = (0, _v_c_util_dist_raf.default)(() => {
74
- startResize();
75
- });
76
- }
77
- }
78
- };
79
- (0, vue.onUnmounted)(() => {
80
- cleanRaf();
81
- });
82
- (0, _v_c_resize_observer.useResizeObserver)((0, vue.computed)(() => {
83
- return !!(props.autoSize || props.onResize);
84
- }), textareaRef, onInternalResize);
85
- return () => {
86
- const { prefixCls, disabled, readOnly } = props;
87
- const { style, restAttrs, className } = (0, _v_c_util_dist_props_util.getAttrStyleAndClass)(attrs, { omits: ["onKeydown"] });
88
- const mergedAutoSizeStyle = needAutoSize.value ? autoSizeStyle.value : null;
89
- const mergedStyle = {
90
- ...style,
91
- ...mergedAutoSizeStyle
92
- };
93
- if (resizeState.value === RESIZE_START || resizeState.value === RESIZE_MEASURING) {
94
- mergedStyle.overflowY = "hidden";
95
- mergedStyle.overflowX = "hidden";
96
- }
97
- return (0, vue.createVNode)("textarea", (0, vue.mergeProps)((0, _v_c_util_dist_omit.default)(restAttrs, ["readonly"]), (0, _v_c_util_dist_omit.default)(props, [
98
- "suffix",
99
- "classNames",
100
- "styles",
101
- "prefixCls",
102
- "allowClear",
103
- "autoSize",
104
- "showCount",
105
- "disabled",
106
- "hidden",
107
- "readOnly",
108
- "onClear",
109
- "maxLength",
110
- "onResize",
111
- "onChange"
112
- ]), {
113
- "readonly": restAttrs?.readonly ?? readOnly,
114
- "ref": textareaRef,
115
- "style": mergedStyle,
116
- "class": (0, _v_c_util.clsx)(prefixCls, className, { [`${prefixCls}-disabled`]: disabled }),
117
- "disabled": disabled,
118
- "value": mergedValue.value,
119
- "onInput": onInternalChange
120
- }), null);
121
- };
122
- }, {
123
- props: {
124
- value: {
125
- required: false,
126
- default: void 0
127
- },
128
- defaultValue: {
129
- required: false,
130
- default: void 0
131
- },
132
- prefixCls: {
133
- type: String,
134
- required: false,
135
- default: void 0
136
- },
137
- disabled: {
138
- type: Boolean,
139
- required: false,
140
- default: void 0
141
- },
142
- autoSize: {
143
- type: [Boolean, Object],
144
- required: false,
145
- default: void 0
146
- },
147
- onPressEnter: {
148
- type: Function,
149
- required: false,
150
- default: void 0
151
- },
152
- onResize: {
153
- type: Function,
154
- required: false,
155
- default: void 0
156
- },
157
- classNames: {
158
- type: Object,
159
- required: false,
160
- default: void 0
161
- },
162
- styles: {
163
- type: Object,
164
- required: false,
165
- default: void 0
166
- },
167
- allowClear: {
168
- type: [Boolean, Object],
169
- required: false,
170
- default: void 0
171
- },
172
- suffix: {
173
- required: false,
174
- default: void 0
175
- },
176
- showCount: {
177
- type: [Boolean, Object],
178
- required: false,
179
- default: void 0
180
- },
181
- count: {
182
- required: false,
183
- default: void 0
184
- },
185
- onClear: {
186
- type: Function,
187
- required: false,
188
- default: void 0
189
- },
190
- onChange: {
191
- type: Function,
192
- required: false,
193
- default: void 0
194
- },
195
- maxLength: {
196
- type: Number,
197
- required: false,
198
- default: void 0
199
- },
200
- hidden: {
201
- type: Boolean,
202
- required: false,
203
- default: void 0
204
- },
205
- readOnly: {
206
- type: Boolean,
207
- required: false,
208
- default: void 0
209
- },
210
- placeholder: {
211
- type: String,
212
- required: false,
213
- default: void 0
214
- },
215
- autoFocus: {
216
- type: Boolean,
217
- required: false,
218
- default: void 0
219
- },
220
- onKeydown: {
221
- type: Function,
222
- required: false,
223
- default: void 0
224
- },
225
- onKeyup: {
226
- type: Function,
227
- required: false,
228
- default: void 0
229
- },
230
- onFocus: {
231
- type: Function,
232
- required: false,
233
- default: void 0
234
- },
235
- onBlur: {
236
- type: Function,
237
- required: false,
238
- default: void 0
239
- }
240
- },
241
- name: "ResizableTextArea",
242
- inheritAttrs: false
243
- });
244
- var ResizableTextArea_default = ResizableTextArea;
245
- exports.default = ResizableTextArea_default;
package/dist/TextArea.cjs DELETED
@@ -1,308 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
6
- const require_ResizableTextArea = require("./ResizableTextArea.cjs");
7
- let vue = require("vue");
8
- let _v_c_util = require("@v-c/util");
9
- let _v_c_util_dist_omit = require("@v-c/util/dist/omit");
10
- _v_c_util_dist_omit = require_rolldown_runtime.__toESM(_v_c_util_dist_omit);
11
- let _v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
12
- let _v_c_input = require("@v-c/input");
13
- let _v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
14
- var TextArea = /* @__PURE__ */ (0, vue.defineComponent)((props, { expose, attrs }) => {
15
- const { count, showCount } = (0, _v_c_util_dist_props_util.toPropsRefs)(props, "count", "showCount");
16
- const value = (0, vue.shallowRef)(props?.value ?? props?.defaultValue ?? "");
17
- (0, vue.watch)(() => props.value, () => {
18
- value.value = props.value;
19
- });
20
- const formatValue = (0, vue.computed)(() => value.value === void 0 || value.value === null ? "" : String(value.value));
21
- const focused = (0, vue.shallowRef)(false);
22
- const compositionRef = (0, vue.shallowRef)(false);
23
- const textareaResized = (0, vue.shallowRef)();
24
- const holderRef = (0, vue.shallowRef)();
25
- const resizableTextAreaRef = (0, vue.shallowRef)();
26
- const getTextArea = () => resizableTextAreaRef.value?.textArea;
27
- const focus = () => {
28
- getTextArea().focus();
29
- };
30
- expose({
31
- resizableTextArea: resizableTextAreaRef,
32
- focus,
33
- blur: () => {
34
- getTextArea().blur();
35
- },
36
- nativeElement: (0, vue.computed)(() => holderRef.value?.nativeElement || getTextArea())
37
- });
38
- (0, vue.watch)(() => props.disabled, () => {
39
- const prev = focused.value;
40
- if (props.disabled && prev) focused.value = !props?.disabled && prev;
41
- }, {
42
- immediate: true,
43
- flush: "post"
44
- });
45
- const selection = (0, vue.shallowRef)(null);
46
- (0, vue.watch)(selection, () => {
47
- if (selection.value) getTextArea().setSelectionRange(...selection.value);
48
- });
49
- const countConfig = (0, _v_c_input.useCount)(count, showCount);
50
- const mergedMax = (0, vue.computed)(() => countConfig.value.max ?? props.maxLength);
51
- const hasMaxLength = (0, vue.computed)(() => Number(mergedMax.value) > 0);
52
- const valueLength = (0, vue.computed)(() => countConfig.value.strategy(formatValue.value));
53
- const isOutOfRange = (0, vue.computed)(() => !!mergedMax.value && valueLength.value > mergedMax.value);
54
- const triggerChange = (e, currentValue) => {
55
- let cutValue = currentValue;
56
- if (!compositionRef.value && countConfig.value.exceedFormatter && countConfig.value.max && countConfig.value.strategy(currentValue) > countConfig.value.max) {
57
- cutValue = countConfig.value.exceedFormatter(currentValue, { max: countConfig.value.max });
58
- const textarea$1 = getTextArea();
59
- if (currentValue !== cutValue) selection.value = [textarea$1.selectionStart || 0, textarea$1.selectionEnd || 0];
60
- }
61
- const textarea = getTextArea();
62
- if (!compositionRef.value && textarea && textarea.value !== cutValue) textarea.value = cutValue;
63
- value.value = cutValue;
64
- (0, _v_c_input.resolveOnChange)(e.currentTarget, e, props.onChange, cutValue);
65
- };
66
- const onInternalCompositionStart = () => {
67
- compositionRef.value = true;
68
- };
69
- const onInternalCompositionEnd = (e) => {
70
- compositionRef.value = false;
71
- triggerChange(e, e.currentTarget.value);
72
- };
73
- const onInternalChange = (e) => {
74
- triggerChange(e, e.target.value);
75
- };
76
- const handleKeyDown = (e) => {
77
- const { onPressEnter } = props;
78
- if (e.key === _v_c_util_dist_KeyCode.KeyCodeStr.Enter && onPressEnter && !e.isComposing) onPressEnter(e);
79
- props?.onKeydown?.(e);
80
- };
81
- const handleFocus = (e) => {
82
- focused.value = true;
83
- props?.onFocus?.(e);
84
- };
85
- const handleBlur = (e) => {
86
- focused.value = false;
87
- props?.onBlur?.(e);
88
- };
89
- const handleReset = (e) => {
90
- value.value = "";
91
- focus();
92
- (0, _v_c_input.resolveOnChange)(getTextArea(), e, props.onChange);
93
- };
94
- const handleResize = (size) => {
95
- props?.onResize?.(size);
96
- if (getTextArea()?.style.height) textareaResized.value = true;
97
- };
98
- return () => {
99
- const { suffix, classNames, styles, prefixCls = "vc-textarea", allowClear, autoSize, showCount: showCount$1, disabled, hidden, readOnly, onClear, maxLength } = props;
100
- const { style, restAttrs, className } = (0, _v_c_util_dist_props_util.getAttrStyleAndClass)(attrs);
101
- let suffixNode = suffix;
102
- let dataCount;
103
- if (countConfig.value.show) {
104
- if (countConfig.value.showFormatter) dataCount = countConfig.value.showFormatter?.({
105
- value: formatValue.value,
106
- count: valueLength.value,
107
- maxLength: mergedMax.value
108
- });
109
- else dataCount = `${valueLength.value}${hasMaxLength.value ? ` / ${mergedMax.value}` : ""}`;
110
- suffixNode = (0, vue.createVNode)(vue.Fragment, null, [suffixNode, (0, vue.createVNode)("span", {
111
- "class": (0, _v_c_util.clsx)(`${prefixCls}-data-count`, classNames?.count),
112
- "style": styles?.count
113
- }, [dataCount])]);
114
- }
115
- const isPureTextArea = !autoSize && !showCount$1 && !allowClear;
116
- const textareaProps = {
117
- onKeydown: handleKeyDown,
118
- onFocus: handleFocus,
119
- onBlur: handleBlur,
120
- onCompositionstart: onInternalCompositionStart,
121
- onCompositionend: onInternalCompositionEnd
122
- };
123
- return (0, vue.createVNode)(_v_c_input.BaseInput, {
124
- "ref": holderRef,
125
- "value": formatValue.value,
126
- "allowClear": allowClear,
127
- "handleReset": handleReset,
128
- "suffix": suffixNode,
129
- "prefixCls": prefixCls,
130
- "classNames": {
131
- ...classNames,
132
- affixWrapper: (0, _v_c_util.clsx)(classNames?.affixWrapper, {
133
- [`${prefixCls}-show-count`]: showCount$1,
134
- [`${prefixCls}-textarea-allow-clear`]: allowClear
135
- })
136
- },
137
- "disabled": disabled,
138
- "focused": focused.value,
139
- "class": (0, _v_c_util.clsx)(className, isOutOfRange.value && `${prefixCls}-out-of-range`),
140
- "style": {
141
- ...style,
142
- ...textareaResized.value && !isPureTextArea ? { height: "auto" } : {}
143
- },
144
- "dataAttrs": { affixWrapper: { "data-count": typeof dataCount === "string" ? dataCount : void 0 } },
145
- "hidden": hidden,
146
- "readOnly": readOnly,
147
- "onClear": onClear
148
- }, { default: () => [(0, vue.createVNode)(require_ResizableTextArea.default, (0, vue.mergeProps)(restAttrs, (0, _v_c_util_dist_omit.default)(props, [
149
- "suffix",
150
- "classNames",
151
- "styles",
152
- "prefixCls",
153
- "allowClear",
154
- "autoSize",
155
- "showCount",
156
- "disabled",
157
- "hidden",
158
- "readOnly",
159
- "onClear",
160
- "maxLength",
161
- "onResize",
162
- "onChange",
163
- "onKeydown",
164
- "onPressEnter",
165
- "onFocus",
166
- "onBlur"
167
- ]), {
168
- "autoSize": autoSize,
169
- "maxLength": maxLength,
170
- "onChange": onInternalChange
171
- }, textareaProps, {
172
- "class": (0, _v_c_util.clsx)(classNames?.textarea),
173
- "style": {
174
- resize: style?.resize,
175
- ...styles?.textarea
176
- },
177
- "disabled": disabled,
178
- "value": value.value,
179
- "prefixCls": prefixCls,
180
- "onResize": handleResize,
181
- "ref": resizableTextAreaRef,
182
- "readOnly": readOnly
183
- }), null)] });
184
- };
185
- }, {
186
- props: /* @__PURE__ */ (0, vue.mergeDefaults)({
187
- value: {
188
- required: false,
189
- default: void 0
190
- },
191
- defaultValue: {
192
- required: false,
193
- default: void 0
194
- },
195
- prefixCls: {
196
- type: String,
197
- required: false,
198
- default: void 0
199
- },
200
- disabled: {
201
- type: Boolean,
202
- required: false,
203
- default: void 0
204
- },
205
- autoSize: {
206
- type: [Boolean, Object],
207
- required: false,
208
- default: void 0
209
- },
210
- onPressEnter: {
211
- type: Function,
212
- required: false,
213
- default: void 0
214
- },
215
- onResize: {
216
- type: Function,
217
- required: false,
218
- default: void 0
219
- },
220
- classNames: {
221
- type: Object,
222
- required: false,
223
- default: void 0
224
- },
225
- styles: {
226
- type: Object,
227
- required: false,
228
- default: void 0
229
- },
230
- allowClear: {
231
- type: [Boolean, Object],
232
- required: false,
233
- default: void 0
234
- },
235
- suffix: {
236
- required: false,
237
- default: void 0
238
- },
239
- showCount: {
240
- type: [Boolean, Object],
241
- required: false,
242
- default: void 0
243
- },
244
- count: {
245
- required: false,
246
- default: void 0
247
- },
248
- onClear: {
249
- type: Function,
250
- required: false,
251
- default: void 0
252
- },
253
- onChange: {
254
- type: Function,
255
- required: false,
256
- default: void 0
257
- },
258
- maxLength: {
259
- type: Number,
260
- required: false,
261
- default: void 0
262
- },
263
- hidden: {
264
- type: Boolean,
265
- required: false,
266
- default: void 0
267
- },
268
- readOnly: {
269
- type: Boolean,
270
- required: false,
271
- default: void 0
272
- },
273
- placeholder: {
274
- type: String,
275
- required: false,
276
- default: void 0
277
- },
278
- autoFocus: {
279
- type: Boolean,
280
- required: false,
281
- default: void 0
282
- },
283
- onKeydown: {
284
- type: Function,
285
- required: false,
286
- default: void 0
287
- },
288
- onKeyup: {
289
- type: Function,
290
- required: false,
291
- default: void 0
292
- },
293
- onFocus: {
294
- type: Function,
295
- required: false,
296
- default: void 0
297
- },
298
- onBlur: {
299
- type: Function,
300
- required: false,
301
- default: void 0
302
- }
303
- }, { prefixCls: "vc-textarea" }),
304
- name: "TextArea",
305
- inheritAttrs: false
306
- });
307
- var TextArea_default = TextArea;
308
- exports.default = TextArea_default;
@@ -1,21 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
9
- key = keys[i];
10
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
11
- get: ((k) => from[k]).bind(null, key),
12
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
13
- });
14
- }
15
- return to;
16
- };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
18
- value: mod,
19
- enumerable: true
20
- }) : target, mod));
21
- exports.__toESM = __toESM;
@@ -1,99 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- var HIDDEN_TEXTAREA_STYLE = `
6
- min-height:0 !important;
7
- max-height:none !important;
8
- height:0 !important;
9
- visibility:hidden !important;
10
- overflow:hidden !important;
11
- position:absolute !important;
12
- z-index:-1000 !important;
13
- top:0 !important;
14
- right:0 !important;
15
- pointer-events: none !important;
16
- `;
17
- var SIZING_STYLE = [
18
- "letter-spacing",
19
- "line-height",
20
- "padding-top",
21
- "padding-bottom",
22
- "font-family",
23
- "font-weight",
24
- "font-size",
25
- "font-variant",
26
- "text-rendering",
27
- "text-transform",
28
- "width",
29
- "text-indent",
30
- "padding-left",
31
- "padding-right",
32
- "border-width",
33
- "box-sizing",
34
- "word-break",
35
- "white-space"
36
- ];
37
- var computedStyleCache = {};
38
- var hiddenTextarea;
39
- function calculateNodeStyling(node, useCache = false) {
40
- const nodeRef = node.getAttribute("id") || node.getAttribute("data-reactid") || node.getAttribute("name");
41
- if (useCache && computedStyleCache[nodeRef]) return computedStyleCache[nodeRef];
42
- const style = window.getComputedStyle(node);
43
- const boxSizing = style.getPropertyValue("box-sizing") || style.getPropertyValue("-moz-box-sizing") || style.getPropertyValue("-webkit-box-sizing");
44
- const paddingSize = parseFloat(style.getPropertyValue("padding-bottom")) + parseFloat(style.getPropertyValue("padding-top"));
45
- const borderSize = parseFloat(style.getPropertyValue("border-bottom-width")) + parseFloat(style.getPropertyValue("border-top-width"));
46
- const nodeInfo = {
47
- sizingStyle: SIZING_STYLE.map((name) => `${name}:${style.getPropertyValue(name)}`).join(";"),
48
- paddingSize,
49
- borderSize,
50
- boxSizing
51
- };
52
- if (useCache && nodeRef) computedStyleCache[nodeRef] = nodeInfo;
53
- return nodeInfo;
54
- }
55
- function calculateAutoSizeStyle(uiTextNode, useCache = false, minRows = null, maxRows = null) {
56
- if (!hiddenTextarea) {
57
- hiddenTextarea = document.createElement("textarea");
58
- hiddenTextarea.setAttribute("tab-index", "-1");
59
- hiddenTextarea.setAttribute("aria-hidden", "true");
60
- hiddenTextarea.setAttribute("name", "hiddenTextarea");
61
- document.body.appendChild(hiddenTextarea);
62
- }
63
- if (uiTextNode.getAttribute("wrap")) hiddenTextarea.setAttribute("wrap", uiTextNode.getAttribute("wrap"));
64
- else hiddenTextarea.removeAttribute("wrap");
65
- const { paddingSize, borderSize, boxSizing, sizingStyle } = calculateNodeStyling(uiTextNode, useCache);
66
- hiddenTextarea.setAttribute("style", `${sizingStyle};${HIDDEN_TEXTAREA_STYLE}`);
67
- hiddenTextarea.value = uiTextNode.value || uiTextNode.placeholder || "";
68
- let minHeight;
69
- let maxHeight;
70
- let overflowY;
71
- let height = hiddenTextarea.scrollHeight;
72
- if (boxSizing === "border-box") height += borderSize;
73
- else if (boxSizing === "content-box") height -= paddingSize;
74
- if (minRows !== null || maxRows !== null) {
75
- hiddenTextarea.value = " ";
76
- const singleRowHeight = hiddenTextarea.scrollHeight - paddingSize;
77
- if (minRows !== null) {
78
- minHeight = singleRowHeight * minRows;
79
- if (boxSizing === "border-box") minHeight = minHeight + paddingSize + borderSize;
80
- height = Math.max(minHeight, height);
81
- }
82
- if (maxRows !== null) {
83
- maxHeight = singleRowHeight * maxRows;
84
- if (boxSizing === "border-box") maxHeight = maxHeight + paddingSize + borderSize;
85
- overflowY = height > maxHeight ? "" : "hidden";
86
- height = Math.min(maxHeight, height);
87
- }
88
- }
89
- const style = {
90
- height: `${height}px`,
91
- overflowY,
92
- resize: "none"
93
- };
94
- if (minHeight) style.minHeight = `${minHeight}px`;
95
- if (maxHeight) style.maxHeight = `${maxHeight}px`;
96
- return style;
97
- }
98
- exports.calculateNodeStyling = calculateNodeStyling;
99
- exports.default = calculateAutoSizeStyle;
package/dist/index.cjs DELETED
@@ -1,9 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_ResizableTextArea = require("./ResizableTextArea.cjs");
6
- const require_TextArea = require("./TextArea.cjs");
7
- var src_default = require_TextArea.default;
8
- exports.ResizableTextArea = require_ResizableTextArea.default;
9
- exports.default = src_default;
@@ -1 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });