@v-c/input 0.0.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/LICENSE +21 -0
- package/dist/BaseInput.cjs +230 -0
- package/dist/BaseInput.d.ts +7 -0
- package/dist/BaseInput.js +227 -0
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/hooks/useCount.cjs +26 -0
- package/dist/hooks/useCount.d.ts +18 -0
- package/dist/hooks/useCount.js +23 -0
- package/dist/index.cjs +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -0
- package/dist/input.cjs +414 -0
- package/dist/input.d.ts +3 -0
- package/dist/input.js +410 -0
- package/dist/interface.cjs +0 -0
- package/dist/interface.d.ts +119 -0
- package/dist/interface.js +0 -0
- package/dist/utils/commonUtils.cjs +44 -0
- package/dist/utils/commonUtils.d.ts +6 -0
- package/dist/utils/commonUtils.js +40 -0
- package/dist/utils/types.cjs +0 -0
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.js +0 -0
- package/package.json +35 -0
package/dist/input.cjs
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
+
const require_commonUtils = require("./utils/commonUtils.cjs");
|
|
4
|
+
const require_BaseInput = require("./BaseInput.cjs");
|
|
5
|
+
const require_useCount = require("./hooks/useCount.cjs");
|
|
6
|
+
let vue = require("vue");
|
|
7
|
+
let __v_c_util = require("@v-c/util");
|
|
8
|
+
let __v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
9
|
+
let __v_c_util_dist_Dom_focus = require("@v-c/util/dist/Dom/focus");
|
|
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
|
+
function _isSlot(s) {
|
|
13
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
|
|
14
|
+
}
|
|
15
|
+
var defaults = {
|
|
16
|
+
prefixCls: "vc-input",
|
|
17
|
+
type: "text"
|
|
18
|
+
};
|
|
19
|
+
var Input = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots, expose, attrs }) => {
|
|
20
|
+
const focused = (0, vue.shallowRef)(false);
|
|
21
|
+
const compositionRef = (0, vue.shallowRef)(false);
|
|
22
|
+
const keyLockRef = (0, vue.shallowRef)(false);
|
|
23
|
+
const { count, showCount } = (0, __v_c_util_dist_props_util.toPropsRefs)(props, "count", "showCount");
|
|
24
|
+
const onChange = (e) => {
|
|
25
|
+
props?.onChange?.(e);
|
|
26
|
+
};
|
|
27
|
+
const inputRef = (0, vue.shallowRef)();
|
|
28
|
+
const holderRef = (0, vue.shallowRef)();
|
|
29
|
+
const focus = (option) => {
|
|
30
|
+
if (inputRef.value) (0, __v_c_util_dist_Dom_focus.triggerFocus)(inputRef.value, option);
|
|
31
|
+
};
|
|
32
|
+
const value = (0, vue.shallowRef)(props?.value ?? props?.defaultValue);
|
|
33
|
+
(0, vue.watch)(() => props.value, (newValue) => {
|
|
34
|
+
value.value = newValue;
|
|
35
|
+
});
|
|
36
|
+
const formatValue = (0, vue.computed)(() => value.value === void 0 || value.value === null ? "" : String(value.value));
|
|
37
|
+
const selection = (0, vue.shallowRef)(null);
|
|
38
|
+
(0, vue.watch)(selection, (newSelection) => {
|
|
39
|
+
if (newSelection && inputRef.value) inputRef.value.setSelectionRange(...newSelection);
|
|
40
|
+
});
|
|
41
|
+
const countConfig = require_useCount.default(count, showCount);
|
|
42
|
+
const mergedMax = (0, vue.computed)(() => countConfig?.value?.max || props?.maxLength);
|
|
43
|
+
const valueLength = (0, vue.computed)(() => countConfig.value?.strategy?.(formatValue.value) ?? 0);
|
|
44
|
+
const isOutOfRange = (0, vue.computed)(() => !!mergedMax.value && valueLength.value > mergedMax.value);
|
|
45
|
+
expose({
|
|
46
|
+
focus,
|
|
47
|
+
blur: () => {
|
|
48
|
+
inputRef.value?.blur?.();
|
|
49
|
+
},
|
|
50
|
+
setSelectionRange: (start, end, direction) => {
|
|
51
|
+
inputRef.value?.setSelectionRange(start, end, direction);
|
|
52
|
+
},
|
|
53
|
+
select: () => {
|
|
54
|
+
inputRef.value?.select();
|
|
55
|
+
},
|
|
56
|
+
input: inputRef,
|
|
57
|
+
nativeElement: (0, vue.computed)(() => holderRef.value?.nativeElement || inputRef.value)
|
|
58
|
+
});
|
|
59
|
+
(0, vue.watch)(() => props.disabled, () => {
|
|
60
|
+
if (keyLockRef.value) keyLockRef.value = false;
|
|
61
|
+
focused.value = focused.value && props.disabled ? false : focused.value;
|
|
62
|
+
}, { immediate: true });
|
|
63
|
+
const triggerChange = (e, currentValue, info) => {
|
|
64
|
+
let cutValue = currentValue;
|
|
65
|
+
const config = countConfig.value;
|
|
66
|
+
if (!compositionRef.value && config?.exceedFormatter && config.max && config.strategy(currentValue) > config.max) {
|
|
67
|
+
cutValue = config.exceedFormatter(currentValue, { max: config.max });
|
|
68
|
+
if (currentValue !== cutValue) selection.value = [inputRef.value?.selectionStart || 0, inputRef.value?.selectionEnd || 0];
|
|
69
|
+
} else if (info.source === "compositionEnd") return;
|
|
70
|
+
if (props.value === void 0) value.value = cutValue;
|
|
71
|
+
if (inputRef.value) require_commonUtils.resolveOnChange(inputRef.value, e, onChange, cutValue);
|
|
72
|
+
};
|
|
73
|
+
const onInternalChange = (e) => {
|
|
74
|
+
triggerChange(e, e.target.value, { source: "change" });
|
|
75
|
+
};
|
|
76
|
+
const onInternalCompositionStart = (e) => {
|
|
77
|
+
compositionRef.value = true;
|
|
78
|
+
props?.onCompositionStart?.(e);
|
|
79
|
+
};
|
|
80
|
+
const onInternalCompositionEnd = (e) => {
|
|
81
|
+
compositionRef.value = false;
|
|
82
|
+
triggerChange(e, e.target.value, { source: "compositionEnd" });
|
|
83
|
+
props?.onCompositionEnd?.(e);
|
|
84
|
+
};
|
|
85
|
+
const handleKeyDown = (e) => {
|
|
86
|
+
if (e.key === "Enter" && !keyLockRef.value && !e.isComposing) {
|
|
87
|
+
keyLockRef.value = true;
|
|
88
|
+
props.onPressEnter?.(e);
|
|
89
|
+
}
|
|
90
|
+
props?.onKeyDown?.(e);
|
|
91
|
+
};
|
|
92
|
+
const handleKeyUp = (e) => {
|
|
93
|
+
if (e.key === "Enter") keyLockRef.value = false;
|
|
94
|
+
props?.onKeyUp?.(e);
|
|
95
|
+
};
|
|
96
|
+
const handleFocus = (e) => {
|
|
97
|
+
focused.value = true;
|
|
98
|
+
props?.onFocus?.(e);
|
|
99
|
+
};
|
|
100
|
+
const handleBlur = (e) => {
|
|
101
|
+
if (keyLockRef.value) keyLockRef.value = false;
|
|
102
|
+
focused.value = false;
|
|
103
|
+
props?.onBlur?.(e);
|
|
104
|
+
};
|
|
105
|
+
const handleReset = (e) => {
|
|
106
|
+
if (props.value === void 0) value.value = "";
|
|
107
|
+
focus();
|
|
108
|
+
if (inputRef.value) require_commonUtils.resolveOnChange(inputRef.value, e, onChange);
|
|
109
|
+
};
|
|
110
|
+
const mergedAllowClear = (0, vue.computed)(() => {
|
|
111
|
+
if (!props.allowClear) return props.allowClear;
|
|
112
|
+
const clearIcon = slots.clearIcon?.();
|
|
113
|
+
if (clearIcon) return {
|
|
114
|
+
...typeof props.allowClear === "object" ? props.allowClear : {},
|
|
115
|
+
clearIcon
|
|
116
|
+
};
|
|
117
|
+
return props.allowClear;
|
|
118
|
+
});
|
|
119
|
+
return () => {
|
|
120
|
+
const { autoComplete, prefixCls = defaults.prefixCls, disabled, htmlSize, classNames, styles, suffix, type = defaults.type, classes, readOnly, hidden, dataAttrs, components } = props;
|
|
121
|
+
const { class: className, style,...restAttrs } = attrs;
|
|
122
|
+
const mergedClassName = className ?? props.class;
|
|
123
|
+
const mergedStyle = style ?? props.style;
|
|
124
|
+
const prefixNode = slots.prefix?.() ?? props.prefix;
|
|
125
|
+
const suffixNode = slots.suffix?.() ?? suffix;
|
|
126
|
+
const addonBefore = slots.addonBefore?.() ?? props.addonBefore;
|
|
127
|
+
const addonAfter = slots.addonAfter?.() ?? props.addonAfter;
|
|
128
|
+
const config = countConfig.value;
|
|
129
|
+
const hasMaxLength = Number(mergedMax.value) > 0;
|
|
130
|
+
let mergedSuffix = suffixNode;
|
|
131
|
+
if (suffixNode || config?.show) {
|
|
132
|
+
const dataCount = config?.showFormatter ? config.showFormatter({
|
|
133
|
+
value: formatValue.value,
|
|
134
|
+
count: valueLength.value,
|
|
135
|
+
maxLength: mergedMax.value
|
|
136
|
+
}) : `${valueLength.value}${hasMaxLength ? ` / ${mergedMax.value}` : ""}`;
|
|
137
|
+
mergedSuffix = (0, vue.createVNode)(vue.Fragment, null, [config?.show && (0, vue.createVNode)("span", {
|
|
138
|
+
"class": (0, __v_c_util.clsx)(`${prefixCls}-show-count-suffix`, { [`${prefixCls}-show-count-has-suffix`]: !!suffixNode }, classNames?.count),
|
|
139
|
+
"style": styles?.count
|
|
140
|
+
}, [dataCount]), suffixNode]);
|
|
141
|
+
}
|
|
142
|
+
const inputElement = (0, vue.createVNode)("input", (0, vue.mergeProps)(restAttrs, (0, __v_c_util_dist_omit.default)(props, [
|
|
143
|
+
"prefixCls",
|
|
144
|
+
"onPressEnter",
|
|
145
|
+
"addonBefore",
|
|
146
|
+
"addonAfter",
|
|
147
|
+
"prefix",
|
|
148
|
+
"suffix",
|
|
149
|
+
"allowClear",
|
|
150
|
+
"defaultValue",
|
|
151
|
+
"showCount",
|
|
152
|
+
"count",
|
|
153
|
+
"classes",
|
|
154
|
+
"htmlSize",
|
|
155
|
+
"styles",
|
|
156
|
+
"classNames",
|
|
157
|
+
"onClear",
|
|
158
|
+
"dataAttrs",
|
|
159
|
+
"components",
|
|
160
|
+
"hidden",
|
|
161
|
+
"readOnly",
|
|
162
|
+
"value",
|
|
163
|
+
"type",
|
|
164
|
+
"class",
|
|
165
|
+
"style",
|
|
166
|
+
"onFocus",
|
|
167
|
+
"onBlur",
|
|
168
|
+
"onChange",
|
|
169
|
+
"onKeyDown",
|
|
170
|
+
"onKeyUp",
|
|
171
|
+
"onCompositionStart",
|
|
172
|
+
"onCompositionEnd",
|
|
173
|
+
"onInput"
|
|
174
|
+
]), {
|
|
175
|
+
"autocomplete": autoComplete,
|
|
176
|
+
"ref": inputRef,
|
|
177
|
+
"value": formatValue.value,
|
|
178
|
+
"onChange": onInternalChange,
|
|
179
|
+
"onInput": onInternalChange,
|
|
180
|
+
"onFocus": handleFocus,
|
|
181
|
+
"onBlur": handleBlur,
|
|
182
|
+
"onKeydown": handleKeyDown,
|
|
183
|
+
"onKeyup": handleKeyUp,
|
|
184
|
+
"class": (0, __v_c_util.clsx)(prefixCls, { [`${prefixCls}-disabled`]: disabled }, classNames?.input),
|
|
185
|
+
"style": styles?.input,
|
|
186
|
+
"size": htmlSize,
|
|
187
|
+
"type": type,
|
|
188
|
+
"maxlength": props.maxLength,
|
|
189
|
+
"onCompositionstart": onInternalCompositionStart,
|
|
190
|
+
"onCompositionend": onInternalCompositionEnd,
|
|
191
|
+
"disabled": disabled,
|
|
192
|
+
"readonly": readOnly
|
|
193
|
+
}), null);
|
|
194
|
+
return (0, vue.createVNode)(require_BaseInput.default, {
|
|
195
|
+
"ref": holderRef,
|
|
196
|
+
"value": formatValue.value,
|
|
197
|
+
"prefixCls": prefixCls,
|
|
198
|
+
"class": (0, __v_c_util.clsx)(mergedClassName, isOutOfRange.value && `${prefixCls}-out-of-range`),
|
|
199
|
+
"style": mergedStyle,
|
|
200
|
+
"allowClear": mergedAllowClear.value,
|
|
201
|
+
"handleReset": handleReset,
|
|
202
|
+
"suffix": mergedSuffix,
|
|
203
|
+
"prefix": prefixNode,
|
|
204
|
+
"addonBefore": addonBefore,
|
|
205
|
+
"addonAfter": addonAfter,
|
|
206
|
+
"focused": focused.value,
|
|
207
|
+
"triggerFocus": focus,
|
|
208
|
+
"disabled": disabled,
|
|
209
|
+
"readOnly": readOnly,
|
|
210
|
+
"classNames": classNames,
|
|
211
|
+
"styles": styles,
|
|
212
|
+
"dataAttrs": dataAttrs,
|
|
213
|
+
"components": components,
|
|
214
|
+
"hidden": hidden,
|
|
215
|
+
"onClear": props.onClear,
|
|
216
|
+
"classes": classes
|
|
217
|
+
}, _isSlot(inputElement) ? inputElement : { default: () => [inputElement] });
|
|
218
|
+
};
|
|
219
|
+
}, {
|
|
220
|
+
props: /* @__PURE__ */ (0, vue.mergeDefaults)({
|
|
221
|
+
value: {
|
|
222
|
+
type: null,
|
|
223
|
+
required: false,
|
|
224
|
+
default: void 0
|
|
225
|
+
},
|
|
226
|
+
defaultValue: {
|
|
227
|
+
type: null,
|
|
228
|
+
required: false,
|
|
229
|
+
default: void 0
|
|
230
|
+
},
|
|
231
|
+
disabled: {
|
|
232
|
+
type: Boolean,
|
|
233
|
+
required: false,
|
|
234
|
+
default: void 0
|
|
235
|
+
},
|
|
236
|
+
prefixCls: {
|
|
237
|
+
type: String,
|
|
238
|
+
required: false,
|
|
239
|
+
default: void 0
|
|
240
|
+
},
|
|
241
|
+
type: {
|
|
242
|
+
type: [String, Object],
|
|
243
|
+
required: false,
|
|
244
|
+
default: void 0
|
|
245
|
+
},
|
|
246
|
+
showCount: {
|
|
247
|
+
type: [Boolean, Object],
|
|
248
|
+
required: false,
|
|
249
|
+
default: void 0
|
|
250
|
+
},
|
|
251
|
+
onPressEnter: {
|
|
252
|
+
type: Function,
|
|
253
|
+
required: false,
|
|
254
|
+
default: void 0
|
|
255
|
+
},
|
|
256
|
+
autoComplete: {
|
|
257
|
+
type: String,
|
|
258
|
+
required: false,
|
|
259
|
+
default: void 0
|
|
260
|
+
},
|
|
261
|
+
htmlSize: {
|
|
262
|
+
type: Number,
|
|
263
|
+
required: false,
|
|
264
|
+
default: void 0
|
|
265
|
+
},
|
|
266
|
+
placeholder: {
|
|
267
|
+
type: String,
|
|
268
|
+
required: false,
|
|
269
|
+
default: void 0
|
|
270
|
+
},
|
|
271
|
+
classNames: {
|
|
272
|
+
type: Object,
|
|
273
|
+
required: false,
|
|
274
|
+
default: void 0
|
|
275
|
+
},
|
|
276
|
+
styles: {
|
|
277
|
+
type: Object,
|
|
278
|
+
required: false,
|
|
279
|
+
default: void 0
|
|
280
|
+
},
|
|
281
|
+
count: {
|
|
282
|
+
type: Object,
|
|
283
|
+
required: false,
|
|
284
|
+
default: void 0
|
|
285
|
+
},
|
|
286
|
+
onClear: {
|
|
287
|
+
type: Function,
|
|
288
|
+
required: false,
|
|
289
|
+
default: void 0
|
|
290
|
+
},
|
|
291
|
+
maxLength: {
|
|
292
|
+
type: Number,
|
|
293
|
+
required: false,
|
|
294
|
+
default: void 0
|
|
295
|
+
},
|
|
296
|
+
readOnly: {
|
|
297
|
+
type: Boolean,
|
|
298
|
+
required: false,
|
|
299
|
+
default: void 0
|
|
300
|
+
},
|
|
301
|
+
hidden: {
|
|
302
|
+
type: Boolean,
|
|
303
|
+
required: false,
|
|
304
|
+
default: void 0
|
|
305
|
+
},
|
|
306
|
+
onChange: {
|
|
307
|
+
type: Function,
|
|
308
|
+
required: false,
|
|
309
|
+
default: void 0
|
|
310
|
+
},
|
|
311
|
+
onFocus: {
|
|
312
|
+
type: Function,
|
|
313
|
+
required: false,
|
|
314
|
+
default: void 0
|
|
315
|
+
},
|
|
316
|
+
onBlur: {
|
|
317
|
+
type: Function,
|
|
318
|
+
required: false,
|
|
319
|
+
default: void 0
|
|
320
|
+
},
|
|
321
|
+
onKeyDown: {
|
|
322
|
+
type: Function,
|
|
323
|
+
required: false,
|
|
324
|
+
default: void 0
|
|
325
|
+
},
|
|
326
|
+
onKeyUp: {
|
|
327
|
+
type: Function,
|
|
328
|
+
required: false,
|
|
329
|
+
default: void 0
|
|
330
|
+
},
|
|
331
|
+
onCompositionStart: {
|
|
332
|
+
type: Function,
|
|
333
|
+
required: false,
|
|
334
|
+
default: void 0
|
|
335
|
+
},
|
|
336
|
+
onCompositionEnd: {
|
|
337
|
+
type: Function,
|
|
338
|
+
required: false,
|
|
339
|
+
default: void 0
|
|
340
|
+
},
|
|
341
|
+
components: {
|
|
342
|
+
type: Object,
|
|
343
|
+
required: false,
|
|
344
|
+
default: void 0
|
|
345
|
+
},
|
|
346
|
+
dataAttrs: {
|
|
347
|
+
type: Object,
|
|
348
|
+
required: false,
|
|
349
|
+
default: void 0
|
|
350
|
+
},
|
|
351
|
+
prefix: {
|
|
352
|
+
type: [
|
|
353
|
+
String,
|
|
354
|
+
Number,
|
|
355
|
+
null,
|
|
356
|
+
Boolean,
|
|
357
|
+
Array
|
|
358
|
+
],
|
|
359
|
+
required: false,
|
|
360
|
+
skipCheck: true,
|
|
361
|
+
default: void 0
|
|
362
|
+
},
|
|
363
|
+
suffix: {
|
|
364
|
+
type: [
|
|
365
|
+
String,
|
|
366
|
+
Number,
|
|
367
|
+
null,
|
|
368
|
+
Boolean,
|
|
369
|
+
Array
|
|
370
|
+
],
|
|
371
|
+
required: false,
|
|
372
|
+
skipCheck: true,
|
|
373
|
+
default: void 0
|
|
374
|
+
},
|
|
375
|
+
addonBefore: {
|
|
376
|
+
type: [
|
|
377
|
+
String,
|
|
378
|
+
Number,
|
|
379
|
+
null,
|
|
380
|
+
Boolean,
|
|
381
|
+
Array
|
|
382
|
+
],
|
|
383
|
+
required: false,
|
|
384
|
+
skipCheck: true,
|
|
385
|
+
default: void 0
|
|
386
|
+
},
|
|
387
|
+
addonAfter: {
|
|
388
|
+
type: [
|
|
389
|
+
String,
|
|
390
|
+
Number,
|
|
391
|
+
null,
|
|
392
|
+
Boolean,
|
|
393
|
+
Array
|
|
394
|
+
],
|
|
395
|
+
required: false,
|
|
396
|
+
skipCheck: true,
|
|
397
|
+
default: void 0
|
|
398
|
+
},
|
|
399
|
+
classes: {
|
|
400
|
+
type: Object,
|
|
401
|
+
required: false,
|
|
402
|
+
default: void 0
|
|
403
|
+
},
|
|
404
|
+
allowClear: {
|
|
405
|
+
type: [Boolean, Object],
|
|
406
|
+
required: false,
|
|
407
|
+
default: void 0
|
|
408
|
+
}
|
|
409
|
+
}, defaults),
|
|
410
|
+
name: "Input",
|
|
411
|
+
inheritAttrs: false
|
|
412
|
+
});
|
|
413
|
+
var input_default = Input;
|
|
414
|
+
exports.default = input_default;
|
package/dist/input.d.ts
ADDED