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