@v-c/input 1.0.2 → 1.1.0-rc.1

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/BaseInput.js CHANGED
@@ -2,10 +2,11 @@ import { hasAddon, hasPrefixSuffix } from "./utils/commonUtils.js";
2
2
  import { Fragment, computed, createVNode, defineComponent, isVNode, mergeProps, shallowRef } from "vue";
3
3
  import { clsx } from "@v-c/util";
4
4
  import { filterEmpty } from "@v-c/util/dist/props-util";
5
+ //#region src/BaseInput.tsx
5
6
  function _isSlot(s) {
6
7
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
7
8
  }
8
- var BaseInput_default = /* @__PURE__ */ defineComponent((props, { slots, expose, attrs }) => {
9
+ var BaseInput = /* @__PURE__ */ defineComponent((props, { slots, expose, attrs }) => {
9
10
  const containerRef = shallowRef();
10
11
  const onInputClick = (e) => {
11
12
  if (containerRef.value?.contains(e.target)) props?.triggerFocus?.();
@@ -30,21 +31,25 @@ var BaseInput_default = /* @__PURE__ */ defineComponent((props, { slots, expose,
30
31
  if (hasAffix.value) {
31
32
  let clearIcon = null;
32
33
  if (allowClear) {
33
- const needClear = !disabled && !readOnly && value;
34
+ const clearDisabled = typeof allowClear === "object" && allowClear?.disabled;
35
+ const needClear = !disabled && !readOnly && value && !clearDisabled;
34
36
  const clearIconCls = `${prefixCls}-clear-icon`;
35
37
  const iconNode = typeof allowClear === "object" && allowClear?.clearIcon ? allowClear.clearIcon : "✖";
36
38
  clearIcon = createVNode("button", {
37
39
  "type": "button",
38
40
  "tabindex": -1,
41
+ "disabled": clearDisabled || void 0,
39
42
  "onClick": (event) => {
43
+ if (clearDisabled) return;
40
44
  handleReset?.(event);
41
45
  onClear?.();
42
46
  },
43
47
  "onMousedown": (e) => e.preventDefault(),
44
- "class": clsx(clearIconCls, {
48
+ "class": clsx(clearIconCls, classNames?.clear, {
45
49
  [`${clearIconCls}-hidden`]: !needClear,
46
50
  [`${clearIconCls}-has-suffix`]: !!suffix
47
- })
51
+ }),
52
+ "style": styles?.clear
48
53
  }, [iconNode]);
49
54
  }
50
55
  const affixWrapperPrefixCls = `${prefixCls}-affix-wrapper`;
@@ -227,4 +232,5 @@ var BaseInput_default = /* @__PURE__ */ defineComponent((props, { slots, expose,
227
232
  name: "BaseInput",
228
233
  inheritAttrs: false
229
234
  });
230
- export { BaseInput_default as default };
235
+ //#endregion
236
+ export { BaseInput as default };
@@ -1,4 +1,8 @@
1
1
  import { computed } from "vue";
2
+ //#region src/hooks/useCount.ts
3
+ /**
4
+ * Cut `value` by the `count.max` prop.
5
+ */
2
6
  function inCountRange(value, countConfig) {
3
7
  if (!countConfig.max) return true;
4
8
  return countConfig.strategy(value) <= countConfig.max;
@@ -20,4 +24,5 @@ function useCount(count, showCount) {
20
24
  };
21
25
  });
22
26
  }
27
+ //#endregion
23
28
  export { useCount as default, inCountRange };
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { resolveOnChange } from "./utils/commonUtils.js";
2
- import BaseInput_default from "./BaseInput.js";
2
+ import BaseInput from "./BaseInput.js";
3
3
  import useCount from "./hooks/useCount.js";
4
- import input_default from "./input.js";
5
- var src_default = input_default;
6
- export { BaseInput_default as BaseInput, src_default as default, resolveOnChange, useCount };
4
+ import Input from "./input.js";
5
+ //#region src/index.ts
6
+ var src_default = Input;
7
+ //#endregion
8
+ export { BaseInput, src_default as default, resolveOnChange, useCount };
package/dist/input.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resolveOnChange } from "./utils/commonUtils.js";
2
- import BaseInput_default from "./BaseInput.js";
2
+ import BaseInput from "./BaseInput.js";
3
3
  import useCount from "./hooks/useCount.js";
4
4
  import { Fragment, computed, createVNode, defineComponent, isVNode, mergeDefaults, mergeProps, shallowRef, watch } from "vue";
5
5
  import { clsx } from "@v-c/util";
@@ -7,6 +7,7 @@ import { toPropsRefs } from "@v-c/util/dist/props-util";
7
7
  import { triggerFocus } from "@v-c/util/dist/Dom/focus";
8
8
  import { KeyCodeStr } from "@v-c/util/dist/KeyCode";
9
9
  import omit from "@v-c/util/dist/omit";
10
+ //#region src/input.tsx
10
11
  function _isSlot(s) {
11
12
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
12
13
  }
@@ -14,10 +15,11 @@ var defaults = {
14
15
  prefixCls: "vc-input",
15
16
  type: "text"
16
17
  };
17
- var input_default = /* @__PURE__ */ defineComponent((props, { slots, expose, attrs }) => {
18
+ var Input = /* @__PURE__ */ defineComponent((props, { slots, expose, attrs }) => {
18
19
  const focused = shallowRef(false);
19
20
  const compositionRef = shallowRef(false);
20
21
  const keyLockRef = shallowRef(false);
22
+ const compositionEndValueRef = shallowRef(null);
21
23
  const { count, showCount } = toPropsRefs(props, "count", "showCount");
22
24
  const onChange = (e) => {
23
25
  props?.onChange?.(e);
@@ -58,26 +60,34 @@ var input_default = /* @__PURE__ */ defineComponent((props, { slots, expose, att
58
60
  if (keyLockRef.value) keyLockRef.value = false;
59
61
  focused.value = focused.value && props.disabled ? false : focused.value;
60
62
  }, { immediate: true });
61
- const triggerChange = (e, currentValue, info) => {
63
+ const triggerChange = (e, currentValue) => {
64
+ if (compositionRef.value && !props.changeOnComposing) return;
65
+ if (compositionEndValueRef.value !== null) {
66
+ if (currentValue === compositionEndValueRef.value) return;
67
+ compositionEndValueRef.value = null;
68
+ }
62
69
  let cutValue = currentValue;
63
70
  const config = countConfig.value;
64
71
  if (!compositionRef.value && config?.exceedFormatter && config.max && config.strategy(currentValue) > config.max) {
65
72
  cutValue = config.exceedFormatter(currentValue, { max: config.max });
66
73
  if (currentValue !== cutValue) selection.value = [inputRef.value?.selectionStart || 0, inputRef.value?.selectionEnd || 0];
67
- } else if (info.source === "compositionEnd") return;
74
+ }
68
75
  if (props.value === void 0) value.value = cutValue;
69
76
  if (inputRef.value) resolveOnChange(inputRef.value, e, onChange, cutValue);
70
77
  };
71
78
  const onInternalChange = (e) => {
72
- triggerChange(e, e.target.value, { source: "change" });
79
+ triggerChange(e, e.target.value);
73
80
  };
74
81
  const onInternalCompositionStart = (e) => {
75
82
  compositionRef.value = true;
83
+ compositionEndValueRef.value = null;
76
84
  props?.onCompositionStart?.(e);
77
85
  };
78
86
  const onInternalCompositionEnd = (e) => {
79
87
  compositionRef.value = false;
80
- triggerChange(e, e.target.value, { source: "compositionEnd" });
88
+ const currentValue = e.target.value;
89
+ if (!props.changeOnComposing && currentValue !== formatValue.value) triggerChange(e, currentValue);
90
+ if (!props.changeOnComposing) compositionEndValueRef.value = currentValue;
81
91
  props?.onCompositionEnd?.(e);
82
92
  };
83
93
  const handleKeyDown = (e) => {
@@ -101,6 +111,7 @@ var input_default = /* @__PURE__ */ defineComponent((props, { slots, expose, att
101
111
  props?.onBlur?.(e);
102
112
  };
103
113
  const handleReset = (e) => {
114
+ compositionEndValueRef.value = null;
104
115
  if (props.value === void 0) value.value = "";
105
116
  focus();
106
117
  if (inputRef.value) resolveOnChange(inputRef.value, e, onChange);
@@ -168,7 +179,8 @@ var input_default = /* @__PURE__ */ defineComponent((props, { slots, expose, att
168
179
  "onKeyUp",
169
180
  "onCompositionStart",
170
181
  "onCompositionEnd",
171
- "onInput"
182
+ "onInput",
183
+ "changeOnComposing"
172
184
  ]), {
173
185
  "autocomplete": autoComplete,
174
186
  "ref": inputRef,
@@ -188,7 +200,7 @@ var input_default = /* @__PURE__ */ defineComponent((props, { slots, expose, att
188
200
  "disabled": disabled,
189
201
  "readonly": readOnly
190
202
  }), null);
191
- return createVNode(BaseInput_default, {
203
+ return createVNode(BaseInput, {
192
204
  "ref": holderRef,
193
205
  "value": formatValue.value,
194
206
  "prefixCls": prefixCls,
@@ -333,6 +345,11 @@ var input_default = /* @__PURE__ */ defineComponent((props, { slots, expose, att
333
345
  required: false,
334
346
  default: void 0
335
347
  },
348
+ changeOnComposing: {
349
+ type: Boolean,
350
+ required: false,
351
+ default: void 0
352
+ },
336
353
  components: {
337
354
  type: Object,
338
355
  required: false,
@@ -409,4 +426,5 @@ var input_default = /* @__PURE__ */ defineComponent((props, { slots, expose, att
409
426
  name: "Input",
410
427
  inheritAttrs: false
411
428
  });
412
- export { input_default as default };
429
+ //#endregion
430
+ export { Input as default };
@@ -21,14 +21,17 @@ export interface CommonInputProps {
21
21
  groupWrapper?: string;
22
22
  wrapper?: string;
23
23
  variant?: string;
24
+ clear?: string;
24
25
  };
25
26
  styles?: {
26
27
  affixWrapper?: CSSProperties;
27
28
  prefix?: CSSProperties;
28
29
  suffix?: CSSProperties;
30
+ clear?: CSSProperties;
29
31
  };
30
32
  allowClear?: boolean | {
31
33
  clearIcon?: VueNode;
34
+ disabled?: boolean;
32
35
  };
33
36
  }
34
37
  type DataAttr = Record<`data-${string}`, string>;
@@ -102,6 +105,12 @@ export interface InputProps extends Omit<CommonInputProps, 'classNames' | 'style
102
105
  onKeyUp?: KeyboardEventHandler;
103
106
  onCompositionStart?: CompositionEventHandler;
104
107
  onCompositionEnd?: CompositionEventHandler;
108
+ /**
109
+ * Whether to trigger onChange during IME composition.
110
+ * When false (default), onChange only fires after compositionEnd with the final value.
111
+ * When true, onChange fires on every keystroke including intermediate IME values.
112
+ */
113
+ changeOnComposing?: boolean;
105
114
  components?: BaseInputProps['components'];
106
115
  dataAttrs?: BaseInputProps['dataAttrs'];
107
116
  }
@@ -113,7 +122,4 @@ export interface InputRef {
113
122
  input: HTMLInputElement | null;
114
123
  nativeElement: HTMLElement | null;
115
124
  }
116
- export interface ChangeEventInfo {
117
- source: 'compositionEnd' | 'change';
118
- }
119
125
  export {};
@@ -1,4 +1,5 @@
1
1
  import { triggerFocus as triggerFocus$1 } from "@v-c/util/dist/Dom/focus";
2
+ //#region src/utils/commonUtils.ts
2
3
  function createPatchedTarget(target, value) {
3
4
  const patched = target.cloneNode(true);
4
5
  patched.value = value;
@@ -45,5 +46,6 @@ function resolveOnChange(target, e, onChange, targetValue) {
45
46
  }
46
47
  onChange(e);
47
48
  }
48
- const triggerFocus = triggerFocus$1;
49
+ var triggerFocus = triggerFocus$1;
50
+ //#endregion
49
51
  export { hasAddon, hasPrefixSuffix, resolveOnChange, triggerFocus };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/input",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "1.1.0-rc.1",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,7 +10,7 @@
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
13
+ "default": "./dist/index.js"
14
14
  },
15
15
  "./dist/*": "./dist/*",
16
16
  "./package.json": "./package.json"
@@ -24,7 +24,7 @@
24
24
  "vue": "^3.0.0"
25
25
  },
26
26
  "dependencies": {
27
- "@v-c/util": "^1.0.9"
27
+ "@v-c/util": "^1.0.19"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "vite build",
@@ -1,236 +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_commonUtils = require("./utils/commonUtils.cjs");
7
- let vue = require("vue");
8
- let _v_c_util = require("@v-c/util");
9
- let _v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
10
- function _isSlot(s) {
11
- return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
12
- }
13
- var BaseInput = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots, expose, attrs }) => {
14
- const containerRef = (0, vue.shallowRef)();
15
- const onInputClick = (e) => {
16
- if (containerRef.value?.contains(e.target)) props?.triggerFocus?.();
17
- };
18
- const hasAffix = (0, vue.computed)(() => require_commonUtils.hasPrefixSuffix(props));
19
- const groupRef = (0, vue.shallowRef)();
20
- expose({ nativeElement: (0, vue.computed)(() => groupRef.value || containerRef.value) });
21
- return () => {
22
- const { components, allowClear, readOnly, disabled, value, prefixCls, handleReset, onClear, suffix, focused, classNames, styles, dataAttrs, prefix, addonAfter, addonBefore, hidden } = props;
23
- let children = (0, _v_c_util_dist_props_util.filterEmpty)(slots?.default?.() ?? []);
24
- if (children.length === 1) children = children[0];
25
- else children = (0, vue.createVNode)(vue.Fragment, null, children);
26
- const inputElement = children;
27
- const AffixWrapperComponent = components?.affixWrapper || "span";
28
- const GroupWrapperComponent = components?.groupWrapper || "span";
29
- const WrapperComponent = components?.wrapper || "span";
30
- const GroupAddonComponent = components?.groupAddon || "span";
31
- let element = (0, vue.createVNode)(inputElement, {
32
- value,
33
- class: !hasAffix.value && classNames?.variant
34
- });
35
- if (hasAffix.value) {
36
- let clearIcon = null;
37
- if (allowClear) {
38
- const needClear = !disabled && !readOnly && value;
39
- const clearIconCls = `${prefixCls}-clear-icon`;
40
- const iconNode = typeof allowClear === "object" && allowClear?.clearIcon ? allowClear.clearIcon : "✖";
41
- clearIcon = (0, vue.createVNode)("button", {
42
- "type": "button",
43
- "tabindex": -1,
44
- "onClick": (event) => {
45
- handleReset?.(event);
46
- onClear?.();
47
- },
48
- "onMousedown": (e) => e.preventDefault(),
49
- "class": (0, _v_c_util.clsx)(clearIconCls, {
50
- [`${clearIconCls}-hidden`]: !needClear,
51
- [`${clearIconCls}-has-suffix`]: !!suffix
52
- })
53
- }, [iconNode]);
54
- }
55
- const affixWrapperPrefixCls = `${prefixCls}-affix-wrapper`;
56
- const affixWrapperCls = (0, _v_c_util.clsx)(affixWrapperPrefixCls, {
57
- [`${prefixCls}-disabled`]: disabled,
58
- [`${affixWrapperPrefixCls}-disabled`]: disabled,
59
- [`${affixWrapperPrefixCls}-focused`]: focused,
60
- [`${affixWrapperPrefixCls}-readonly`]: readOnly,
61
- [`${affixWrapperPrefixCls}-input-with-clear-btn`]: suffix && allowClear && value
62
- }, classNames?.affixWrapper, classNames?.variant);
63
- const suffixNode = (suffix || allowClear) && (0, vue.createVNode)("span", {
64
- "class": (0, _v_c_util.clsx)(`${prefixCls}-suffix`, classNames?.suffix),
65
- "style": styles?.suffix
66
- }, [clearIcon, suffix]);
67
- const _element = function() {
68
- return element;
69
- }();
70
- element = (0, vue.createVNode)(AffixWrapperComponent, (0, vue.mergeProps)({
71
- "class": affixWrapperCls,
72
- "style": styles?.affixWrapper,
73
- "onClick": onInputClick
74
- }, dataAttrs?.affixWrapper, { "ref": containerRef }), { default: () => [
75
- prefix && (0, vue.createVNode)("span", {
76
- "class": (0, _v_c_util.clsx)(`${prefixCls}-prefix`, classNames?.prefix),
77
- "style": styles?.prefix
78
- }, [prefix]),
79
- _element,
80
- suffixNode
81
- ] });
82
- }
83
- if (require_commonUtils.hasAddon(props)) {
84
- const wrapperCls = `${prefixCls}-group`;
85
- const addonCls = `${wrapperCls}-addon`;
86
- const groupWrapperCls = `${wrapperCls}-wrapper`;
87
- const mergedWrapperClassName = (0, _v_c_util.clsx)(`${prefixCls}-wrapper`, wrapperCls, classNames?.wrapper);
88
- const mergedGroupClassName = (0, _v_c_util.clsx)(groupWrapperCls, { [`${groupWrapperCls}-disabled`]: disabled }, classNames?.groupWrapper);
89
- element = (0, vue.createVNode)(GroupWrapperComponent, {
90
- "class": mergedGroupClassName,
91
- "ref": groupRef
92
- }, { default: () => [(0, vue.createVNode)(WrapperComponent, { "class": mergedWrapperClassName }, { default: () => [
93
- addonBefore && (0, vue.createVNode)(GroupAddonComponent, { "class": addonCls }, _isSlot(addonBefore) ? addonBefore : { default: () => [addonBefore] }),
94
- element,
95
- addonAfter && (0, vue.createVNode)(GroupAddonComponent, { "class": addonCls }, _isSlot(addonAfter) ? addonAfter : { default: () => [addonAfter] })
96
- ] })] });
97
- }
98
- return (0, vue.createVNode)(element, {
99
- ...attrs,
100
- hidden
101
- });
102
- };
103
- }, {
104
- props: {
105
- value: {
106
- required: false,
107
- default: void 0
108
- },
109
- prefixCls: {
110
- type: String,
111
- required: false,
112
- default: void 0
113
- },
114
- disabled: {
115
- type: Boolean,
116
- required: false,
117
- default: void 0
118
- },
119
- focused: {
120
- type: Boolean,
121
- required: false,
122
- default: void 0
123
- },
124
- triggerFocus: {
125
- type: Function,
126
- required: false,
127
- default: void 0
128
- },
129
- readOnly: {
130
- type: Boolean,
131
- required: false,
132
- default: void 0
133
- },
134
- handleReset: {
135
- type: Function,
136
- required: false,
137
- default: void 0
138
- },
139
- onClear: {
140
- type: Function,
141
- required: false,
142
- default: void 0
143
- },
144
- hidden: {
145
- type: Boolean,
146
- required: false,
147
- default: void 0
148
- },
149
- dataAttrs: {
150
- type: Object,
151
- required: false,
152
- default: void 0
153
- },
154
- components: {
155
- type: Object,
156
- required: false,
157
- default: void 0
158
- },
159
- prefix: {
160
- type: [
161
- Object,
162
- Function,
163
- String,
164
- Number,
165
- null,
166
- Boolean,
167
- Array
168
- ],
169
- required: false,
170
- default: void 0
171
- },
172
- suffix: {
173
- type: [
174
- Object,
175
- Function,
176
- String,
177
- Number,
178
- null,
179
- Boolean,
180
- Array
181
- ],
182
- required: false,
183
- default: void 0
184
- },
185
- addonBefore: {
186
- type: [
187
- Object,
188
- Function,
189
- String,
190
- Number,
191
- null,
192
- Boolean,
193
- Array
194
- ],
195
- required: false,
196
- default: void 0
197
- },
198
- addonAfter: {
199
- type: [
200
- Object,
201
- Function,
202
- String,
203
- Number,
204
- null,
205
- Boolean,
206
- Array
207
- ],
208
- required: false,
209
- default: void 0
210
- },
211
- classes: {
212
- type: Object,
213
- required: false,
214
- default: void 0
215
- },
216
- classNames: {
217
- type: Object,
218
- required: false,
219
- default: void 0
220
- },
221
- styles: {
222
- type: Object,
223
- required: false,
224
- default: void 0
225
- },
226
- allowClear: {
227
- type: [Boolean, Object],
228
- required: false,
229
- default: void 0
230
- }
231
- },
232
- name: "BaseInput",
233
- inheritAttrs: false
234
- });
235
- var BaseInput_default = BaseInput;
236
- exports.default = BaseInput_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,29 +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
- let vue = require("vue");
7
- function inCountRange(value, countConfig) {
8
- if (!countConfig.max) return true;
9
- return countConfig.strategy(value) <= countConfig.max;
10
- }
11
- function useCount(count, showCount) {
12
- return (0, vue.computed)(() => {
13
- let mergedConfig = {};
14
- if (showCount?.value) mergedConfig.show = typeof showCount.value === "object" && showCount.value?.formatter ? showCount.value?.formatter : !!showCount.value;
15
- mergedConfig = {
16
- ...mergedConfig,
17
- ...count?.value
18
- };
19
- const { show, ...rest } = mergedConfig;
20
- return {
21
- ...rest,
22
- show: !!show,
23
- showFormatter: typeof show === "function" ? show : void 0,
24
- strategy: rest.strategy || ((value) => value.length)
25
- };
26
- });
27
- }
28
- exports.default = useCount;
29
- exports.inCountRange = inCountRange;
package/dist/index.cjs DELETED
@@ -1,13 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_commonUtils = require("./utils/commonUtils.cjs");
6
- const require_BaseInput = require("./BaseInput.cjs");
7
- const require_useCount = require("./hooks/useCount.cjs");
8
- const require_input = require("./input.cjs");
9
- var src_default = require_input.default;
10
- exports.BaseInput = require_BaseInput.default;
11
- exports.default = src_default;
12
- exports.resolveOnChange = require_commonUtils.resolveOnChange;
13
- exports.useCount = require_useCount.default;
package/dist/input.cjs DELETED
@@ -1,419 +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_commonUtils = require("./utils/commonUtils.cjs");
7
- const require_BaseInput = require("./BaseInput.cjs");
8
- const require_useCount = require("./hooks/useCount.cjs");
9
- let vue = require("vue");
10
- let _v_c_util = require("@v-c/util");
11
- let _v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
12
- let _v_c_util_dist_Dom_focus = require("@v-c/util/dist/Dom/focus");
13
- let _v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
14
- let _v_c_util_dist_omit = require("@v-c/util/dist/omit");
15
- _v_c_util_dist_omit = require_rolldown_runtime.__toESM(_v_c_util_dist_omit);
16
- function _isSlot(s) {
17
- return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
18
- }
19
- var defaults = {
20
- prefixCls: "vc-input",
21
- type: "text"
22
- };
23
- var Input = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots, expose, attrs }) => {
24
- const focused = (0, vue.shallowRef)(false);
25
- const compositionRef = (0, vue.shallowRef)(false);
26
- const keyLockRef = (0, vue.shallowRef)(false);
27
- const { count, showCount } = (0, _v_c_util_dist_props_util.toPropsRefs)(props, "count", "showCount");
28
- const onChange = (e) => {
29
- props?.onChange?.(e);
30
- };
31
- const inputRef = (0, vue.shallowRef)();
32
- const holderRef = (0, vue.shallowRef)();
33
- const focus = (option) => {
34
- if (inputRef.value) (0, _v_c_util_dist_Dom_focus.triggerFocus)(inputRef.value, option);
35
- };
36
- const value = (0, vue.shallowRef)(props?.value ?? props?.defaultValue);
37
- (0, vue.watch)(() => props.value, (newValue) => {
38
- value.value = newValue;
39
- });
40
- const formatValue = (0, vue.computed)(() => value.value === void 0 || value.value === null ? "" : String(value.value));
41
- const selection = (0, vue.shallowRef)(null);
42
- (0, vue.watch)(selection, (newSelection) => {
43
- if (newSelection && inputRef.value) inputRef.value.setSelectionRange(...newSelection);
44
- });
45
- const countConfig = require_useCount.default(count, showCount);
46
- const mergedMax = (0, vue.computed)(() => countConfig?.value?.max || props?.maxLength);
47
- const valueLength = (0, vue.computed)(() => countConfig.value?.strategy?.(formatValue.value) ?? 0);
48
- const isOutOfRange = (0, vue.computed)(() => !!mergedMax.value && valueLength.value > mergedMax.value);
49
- expose({
50
- focus,
51
- blur: () => {
52
- inputRef.value?.blur?.();
53
- },
54
- setSelectionRange: (start, end, direction) => {
55
- inputRef.value?.setSelectionRange(start, end, direction);
56
- },
57
- select: () => {
58
- inputRef.value?.select();
59
- },
60
- input: inputRef,
61
- nativeElement: (0, vue.computed)(() => holderRef.value?.nativeElement || inputRef.value)
62
- });
63
- (0, vue.watch)(() => props.disabled, () => {
64
- if (keyLockRef.value) keyLockRef.value = false;
65
- focused.value = focused.value && props.disabled ? false : focused.value;
66
- }, { immediate: true });
67
- const triggerChange = (e, currentValue, info) => {
68
- let cutValue = currentValue;
69
- const config = countConfig.value;
70
- if (!compositionRef.value && config?.exceedFormatter && config.max && config.strategy(currentValue) > config.max) {
71
- cutValue = config.exceedFormatter(currentValue, { max: config.max });
72
- if (currentValue !== cutValue) selection.value = [inputRef.value?.selectionStart || 0, inputRef.value?.selectionEnd || 0];
73
- } else if (info.source === "compositionEnd") return;
74
- if (props.value === void 0) value.value = cutValue;
75
- if (inputRef.value) require_commonUtils.resolveOnChange(inputRef.value, e, onChange, cutValue);
76
- };
77
- const onInternalChange = (e) => {
78
- triggerChange(e, e.target.value, { source: "change" });
79
- };
80
- const onInternalCompositionStart = (e) => {
81
- compositionRef.value = true;
82
- props?.onCompositionStart?.(e);
83
- };
84
- const onInternalCompositionEnd = (e) => {
85
- compositionRef.value = false;
86
- triggerChange(e, e.target.value, { source: "compositionEnd" });
87
- props?.onCompositionEnd?.(e);
88
- };
89
- const handleKeyDown = (e) => {
90
- if (e.key === _v_c_util_dist_KeyCode.KeyCodeStr.Enter && !keyLockRef.value && !e.isComposing) {
91
- keyLockRef.value = true;
92
- props.onPressEnter?.(e);
93
- }
94
- props?.onKeyDown?.(e);
95
- };
96
- const handleKeyUp = (e) => {
97
- if (e.key === "Enter") keyLockRef.value = false;
98
- props?.onKeyUp?.(e);
99
- };
100
- const handleFocus = (e) => {
101
- focused.value = true;
102
- props?.onFocus?.(e);
103
- };
104
- const handleBlur = (e) => {
105
- if (keyLockRef.value) keyLockRef.value = false;
106
- focused.value = false;
107
- props?.onBlur?.(e);
108
- };
109
- const handleReset = (e) => {
110
- if (props.value === void 0) value.value = "";
111
- focus();
112
- if (inputRef.value) require_commonUtils.resolveOnChange(inputRef.value, e, onChange);
113
- };
114
- const mergedAllowClear = (0, vue.computed)(() => {
115
- if (!props.allowClear) return props.allowClear;
116
- const clearIcon = slots.clearIcon?.();
117
- if (clearIcon) return {
118
- ...typeof props.allowClear === "object" ? props.allowClear : {},
119
- clearIcon
120
- };
121
- return props.allowClear;
122
- });
123
- return () => {
124
- const { autoComplete, prefixCls = defaults.prefixCls, disabled, htmlSize, classNames, styles, suffix, type = defaults.type, classes, readOnly, hidden, dataAttrs, components } = props;
125
- const { class: className, style, ...restAttrs } = attrs;
126
- const mergedClassName = className ?? props.class;
127
- const mergedStyle = style ?? props.style;
128
- const prefixNode = slots.prefix?.() ?? props.prefix;
129
- const suffixNode = slots.suffix?.() ?? suffix;
130
- const addonBefore = slots.addonBefore?.() ?? props.addonBefore;
131
- const addonAfter = slots.addonAfter?.() ?? props.addonAfter;
132
- const config = countConfig.value;
133
- const hasMaxLength = Number(mergedMax.value) > 0;
134
- let mergedSuffix = suffixNode;
135
- if (suffixNode || config?.show) {
136
- const dataCount = config?.showFormatter ? config.showFormatter({
137
- value: formatValue.value,
138
- count: valueLength.value,
139
- maxLength: mergedMax.value
140
- }) : `${valueLength.value}${hasMaxLength ? ` / ${mergedMax.value}` : ""}`;
141
- mergedSuffix = (0, vue.createVNode)(vue.Fragment, null, [config?.show && (0, vue.createVNode)("span", {
142
- "class": (0, _v_c_util.clsx)(`${prefixCls}-show-count-suffix`, { [`${prefixCls}-show-count-has-suffix`]: !!suffixNode }, classNames?.count),
143
- "style": styles?.count
144
- }, [dataCount]), suffixNode]);
145
- }
146
- const inputElement = (0, vue.createVNode)("input", (0, vue.mergeProps)(restAttrs, (0, _v_c_util_dist_omit.default)(props, [
147
- "prefixCls",
148
- "onPressEnter",
149
- "addonBefore",
150
- "addonAfter",
151
- "prefix",
152
- "suffix",
153
- "allowClear",
154
- "defaultValue",
155
- "showCount",
156
- "count",
157
- "classes",
158
- "htmlSize",
159
- "styles",
160
- "classNames",
161
- "onClear",
162
- "dataAttrs",
163
- "components",
164
- "hidden",
165
- "readOnly",
166
- "value",
167
- "type",
168
- "class",
169
- "style",
170
- "onFocus",
171
- "onBlur",
172
- "onChange",
173
- "onKeyDown",
174
- "onKeyUp",
175
- "onCompositionStart",
176
- "onCompositionEnd",
177
- "onInput"
178
- ]), {
179
- "autocomplete": autoComplete,
180
- "ref": inputRef,
181
- "value": formatValue.value,
182
- "onInput": onInternalChange,
183
- "onFocus": handleFocus,
184
- "onBlur": handleBlur,
185
- "onKeydown": handleKeyDown,
186
- "onKeyup": handleKeyUp,
187
- "class": (0, _v_c_util.clsx)(prefixCls, { [`${prefixCls}-disabled`]: disabled }, classNames?.input),
188
- "style": styles?.input,
189
- "size": htmlSize,
190
- "type": type,
191
- "maxlength": props.maxLength,
192
- "onCompositionstart": onInternalCompositionStart,
193
- "onCompositionend": onInternalCompositionEnd,
194
- "disabled": disabled,
195
- "readonly": readOnly
196
- }), null);
197
- return (0, vue.createVNode)(require_BaseInput.default, {
198
- "ref": holderRef,
199
- "value": formatValue.value,
200
- "prefixCls": prefixCls,
201
- "class": (0, _v_c_util.clsx)(mergedClassName, isOutOfRange.value && `${prefixCls}-out-of-range`),
202
- "style": mergedStyle,
203
- "allowClear": mergedAllowClear.value,
204
- "handleReset": handleReset,
205
- "suffix": mergedSuffix,
206
- "prefix": prefixNode,
207
- "addonBefore": addonBefore,
208
- "addonAfter": addonAfter,
209
- "focused": focused.value,
210
- "triggerFocus": focus,
211
- "disabled": disabled,
212
- "readOnly": readOnly,
213
- "classNames": classNames,
214
- "styles": styles,
215
- "dataAttrs": dataAttrs,
216
- "components": components,
217
- "hidden": hidden,
218
- "onClear": props.onClear,
219
- "classes": classes
220
- }, _isSlot(inputElement) ? inputElement : { default: () => [inputElement] });
221
- };
222
- }, {
223
- props: /* @__PURE__ */ (0, vue.mergeDefaults)({
224
- value: {
225
- required: false,
226
- default: void 0
227
- },
228
- defaultValue: {
229
- required: false,
230
- default: void 0
231
- },
232
- disabled: {
233
- type: Boolean,
234
- required: false,
235
- default: void 0
236
- },
237
- prefixCls: {
238
- type: String,
239
- required: false,
240
- default: void 0
241
- },
242
- type: {
243
- type: [String, Object],
244
- required: false,
245
- default: void 0
246
- },
247
- showCount: {
248
- type: [Boolean, Object],
249
- required: false,
250
- default: void 0
251
- },
252
- onPressEnter: {
253
- type: Function,
254
- required: false,
255
- default: void 0
256
- },
257
- autoComplete: {
258
- type: String,
259
- required: false,
260
- default: void 0
261
- },
262
- htmlSize: {
263
- type: Number,
264
- required: false,
265
- default: void 0
266
- },
267
- placeholder: {
268
- type: String,
269
- required: false,
270
- default: void 0
271
- },
272
- classNames: {
273
- type: Object,
274
- required: false,
275
- default: void 0
276
- },
277
- styles: {
278
- type: Object,
279
- required: false,
280
- default: void 0
281
- },
282
- count: {
283
- type: Object,
284
- required: false,
285
- default: void 0
286
- },
287
- onClear: {
288
- type: Function,
289
- required: false,
290
- default: void 0
291
- },
292
- maxLength: {
293
- type: Number,
294
- required: false,
295
- default: void 0
296
- },
297
- readOnly: {
298
- type: Boolean,
299
- required: false,
300
- default: void 0
301
- },
302
- hidden: {
303
- type: Boolean,
304
- required: false,
305
- default: void 0
306
- },
307
- onChange: {
308
- type: Function,
309
- required: false,
310
- default: void 0
311
- },
312
- onFocus: {
313
- type: Function,
314
- required: false,
315
- default: void 0
316
- },
317
- onBlur: {
318
- type: Function,
319
- required: false,
320
- default: void 0
321
- },
322
- onKeyDown: {
323
- type: Function,
324
- required: false,
325
- default: void 0
326
- },
327
- onKeyUp: {
328
- type: Function,
329
- required: false,
330
- default: void 0
331
- },
332
- onCompositionStart: {
333
- type: Function,
334
- required: false,
335
- default: void 0
336
- },
337
- onCompositionEnd: {
338
- type: Function,
339
- required: false,
340
- default: void 0
341
- },
342
- components: {
343
- type: Object,
344
- required: false,
345
- default: void 0
346
- },
347
- dataAttrs: {
348
- type: Object,
349
- required: false,
350
- default: void 0
351
- },
352
- prefix: {
353
- type: [
354
- Object,
355
- Function,
356
- String,
357
- Number,
358
- null,
359
- Boolean,
360
- Array
361
- ],
362
- required: false,
363
- default: void 0
364
- },
365
- suffix: {
366
- type: [
367
- Object,
368
- Function,
369
- String,
370
- Number,
371
- null,
372
- Boolean,
373
- Array
374
- ],
375
- required: false,
376
- default: void 0
377
- },
378
- addonBefore: {
379
- type: [
380
- Object,
381
- Function,
382
- String,
383
- Number,
384
- null,
385
- Boolean,
386
- Array
387
- ],
388
- required: false,
389
- default: void 0
390
- },
391
- addonAfter: {
392
- type: [
393
- Object,
394
- Function,
395
- String,
396
- Number,
397
- null,
398
- Boolean,
399
- Array
400
- ],
401
- required: false,
402
- default: void 0
403
- },
404
- classes: {
405
- type: Object,
406
- required: false,
407
- default: void 0
408
- },
409
- allowClear: {
410
- type: [Boolean, Object],
411
- required: false,
412
- default: void 0
413
- }
414
- }, defaults),
415
- name: "Input",
416
- inheritAttrs: false
417
- });
418
- var input_default = Input;
419
- exports.default = input_default;
@@ -1 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -1,54 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
3
- let _v_c_util_dist_Dom_focus = require("@v-c/util/dist/Dom/focus");
4
- function createPatchedTarget(target, value) {
5
- const patched = target.cloneNode(true);
6
- patched.value = value;
7
- if (typeof target.selectionStart === "number" && typeof target.selectionEnd === "number") {
8
- patched.selectionStart = target.selectionStart;
9
- patched.selectionEnd = target.selectionEnd;
10
- }
11
- patched.setSelectionRange = (start, end, direction) => {
12
- target.setSelectionRange(start, end, direction);
13
- };
14
- return patched;
15
- }
16
- function cloneEvent(event, target, value) {
17
- const patchedTarget = createPatchedTarget(target, value);
18
- return {
19
- type: event?.type,
20
- timeStamp: event?.timeStamp,
21
- bubbles: event?.bubbles,
22
- cancelable: event?.cancelable,
23
- composed: event?.composed,
24
- target: patchedTarget,
25
- currentTarget: patchedTarget,
26
- preventDefault: event?.preventDefault ? event.preventDefault.bind(event) : void 0,
27
- stopPropagation: event?.stopPropagation ? event.stopPropagation.bind(event) : void 0,
28
- stopImmediatePropagation: event?.stopImmediatePropagation ? event.stopImmediatePropagation.bind(event) : void 0,
29
- nativeEvent: event
30
- };
31
- }
32
- function hasAddon(props) {
33
- return !!(props.addonBefore || props.addonAfter);
34
- }
35
- function hasPrefixSuffix(props) {
36
- return !!(props.prefix || props.suffix || props.allowClear);
37
- }
38
- function resolveOnChange(target, e, onChange, targetValue) {
39
- if (!onChange) return;
40
- if (e?.type === "click") {
41
- onChange(cloneEvent(e, target, ""));
42
- return;
43
- }
44
- if (target.type !== "file" && targetValue !== void 0) {
45
- onChange(cloneEvent(e, target, targetValue));
46
- return;
47
- }
48
- onChange(e);
49
- }
50
- const triggerFocus = _v_c_util_dist_Dom_focus.triggerFocus;
51
- exports.hasAddon = hasAddon;
52
- exports.hasPrefixSuffix = hasPrefixSuffix;
53
- exports.resolveOnChange = resolveOnChange;
54
- exports.triggerFocus = triggerFocus;
@@ -1 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });