@varlet/ui 3.15.1 → 3.16.0-alpha.1778310023051
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/README.md +0 -1
- package/README.zh-CN.md +0 -1
- package/es/date-picker/DatePicker.mjs +41 -10
- package/es/date-picker/props.mjs +1 -0
- package/es/index.bundle.mjs +7 -1
- package/es/index.mjs +6 -1
- package/es/otp-input/OtpInput.mjs +424 -0
- package/es/otp-input/OtpInputSfc.css +0 -0
- package/es/otp-input/index.mjs +12 -0
- package/es/otp-input/otpInput.css +1 -0
- package/es/otp-input/props.mjs +78 -0
- package/es/otp-input/style/index.mjs +7 -0
- package/es/style.mjs +1 -0
- package/es/themes/dark/index.mjs +3 -2
- package/es/themes/dark/otpInput.mjs +10 -0
- package/es/themes/md3-dark/index.mjs +3 -2
- package/es/themes/md3-dark/otpInput.mjs +10 -0
- package/es/themes/md3-light/index.mjs +3 -2
- package/es/themes/md3-light/otpInput.mjs +10 -0
- package/es/varlet.css +1 -1
- package/es/varlet.esm.js +8100 -7696
- package/highlight/web-types.en-US.json +210 -1
- package/highlight/web-types.zh-CN.json +210 -1
- package/lib/varlet.cjs.js +2274 -1780
- package/lib/varlet.css +1 -1
- package/package.json +7 -7
- package/types/datePicker.d.ts +1 -0
- package/types/index.d.ts +2 -0
- package/types/otpInput.d.ts +68 -0
- package/types/styleVars.d.ts +5 -0
- package/umd/varlet.js +7 -7
package/README.md
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
<img src="https://img.shields.io/badge/vue-v3.2.0%2B-%23407fbc" alt="vue">
|
|
15
15
|
<img src="https://img.shields.io/npm/l/@varlet/ui.svg" alt="licence">
|
|
16
16
|
<img src="https://img.shields.io/codecov/c/github/varletjs/varlet" alt="coverage">
|
|
17
|
-
<img src="https://github.com/varletjs/varlet/workflows/CI/badge.svg" alt="ci">
|
|
18
17
|
</p>
|
|
19
18
|
</div>
|
|
20
19
|
|
package/README.zh-CN.md
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
<img src="https://img.shields.io/badge/vue-v3.2.0%2B-%23407fbc" alt="vue">
|
|
16
16
|
<img src="https://img.shields.io/npm/l/@varlet/ui.svg" alt="licence">
|
|
17
17
|
<img src="https://img.shields.io/codecov/c/github/varletjs/varlet" alt="coverage">
|
|
18
|
-
<img src="https://github.com/varletjs/varlet/workflows/CI/badge.svg" alt="ci">
|
|
19
18
|
</p>
|
|
20
19
|
</div>
|
|
21
20
|
|
|
@@ -76,9 +76,9 @@ function __render__(_ctx, _cache) {
|
|
|
76
76
|
onClick: _cache[0] || (_cache[0] = ($event) => _ctx.clickEl("year"))
|
|
77
77
|
},
|
|
78
78
|
[
|
|
79
|
-
_renderSlot(_ctx.$slots, "year", { year: _ctx.
|
|
79
|
+
_renderSlot(_ctx.$slots, "year", { year: _ctx.displayYear }, () => [
|
|
80
80
|
_createTextVNode(
|
|
81
|
-
_toDisplayString(_ctx.
|
|
81
|
+
_toDisplayString(_ctx.displayYear),
|
|
82
82
|
1
|
|
83
83
|
/* TEXT */
|
|
84
84
|
)
|
|
@@ -337,6 +337,7 @@ const __sfc__ = defineComponent({
|
|
|
337
337
|
previewMonth: previewMonth.value,
|
|
338
338
|
previewYear: previewYear.value
|
|
339
339
|
}));
|
|
340
|
+
const displayYear = computed(() => previewYear.value || chooseYear.value || "");
|
|
340
341
|
const getYearTitle = computed(() => {
|
|
341
342
|
var _a;
|
|
342
343
|
const { multiple, range } = props2;
|
|
@@ -416,7 +417,7 @@ const __sfc__ = defineComponent({
|
|
|
416
417
|
watch(
|
|
417
418
|
() => props2.modelValue,
|
|
418
419
|
(value) => {
|
|
419
|
-
if (!checkValue()
|
|
420
|
+
if (!checkValue()) {
|
|
420
421
|
return;
|
|
421
422
|
}
|
|
422
423
|
if (props2.range) {
|
|
@@ -431,7 +432,7 @@ const __sfc__ = defineComponent({
|
|
|
431
432
|
}
|
|
432
433
|
multipleInit(value, props2.type);
|
|
433
434
|
} else {
|
|
434
|
-
dateInit(value);
|
|
435
|
+
dateInit(getSingleDate(value));
|
|
435
436
|
}
|
|
436
437
|
},
|
|
437
438
|
{ immediate: true }
|
|
@@ -626,28 +627,47 @@ const __sfc__ = defineComponent({
|
|
|
626
627
|
}
|
|
627
628
|
return false;
|
|
628
629
|
}
|
|
630
|
+
function getFallbackDate() {
|
|
631
|
+
if (props2.fallbackViewDate) {
|
|
632
|
+
const formatDate = dayjs(props2.fallbackViewDate).format("YYYY-MM-D");
|
|
633
|
+
if (formatDate !== "Invalid Date") {
|
|
634
|
+
return props2.fallbackViewDate;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
return dayjs().format("YYYY-MM-D");
|
|
638
|
+
}
|
|
639
|
+
function getSingleDate(value) {
|
|
640
|
+
if (value && !invalidFormatDate(dayjs(value).format("YYYY-MM-D"))) {
|
|
641
|
+
return value;
|
|
642
|
+
}
|
|
643
|
+
return getFallbackDate();
|
|
644
|
+
}
|
|
645
|
+
function getFirstValidDate(value, type) {
|
|
646
|
+
const formatType = type === "year" ? "YYYY" : type === "month" ? "YYYY-MM" : "YYYY-MM-D";
|
|
647
|
+
return value.find((choose) => !invalidFormatDate(dayjs(choose).format(formatType)));
|
|
648
|
+
}
|
|
629
649
|
function rangeInit(value, type) {
|
|
650
|
+
var _a;
|
|
630
651
|
const rangeDate = type === "year" ? chooseRangeYear : type === "month" ? chooseRangeMonth : chooseRangeDay;
|
|
631
652
|
const formatType = type === "year" ? "YYYY" : type === "month" ? "YYYY-MM" : "YYYY-MM-D";
|
|
632
|
-
const formatDateList = value.map((choose) => dayjs(choose).format(formatType)).slice(0, 2);
|
|
633
|
-
const isValid = rangeDate.value.some((date) => invalidFormatDate(date));
|
|
634
|
-
if (isValid) {
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
653
|
+
const formatDateList = value.map((choose) => dayjs(choose).format(formatType)).filter((date) => !invalidFormatDate(date)).slice(0, 2);
|
|
637
654
|
rangeDate.value = formatDateList;
|
|
638
655
|
const isChangeOrder = dayjs(rangeDate.value[0]).isAfter(rangeDate.value[1]);
|
|
639
656
|
if (rangeDate.value.length === 2 && isChangeOrder) {
|
|
640
657
|
rangeDate.value = [rangeDate.value[1], rangeDate.value[0]];
|
|
641
658
|
}
|
|
659
|
+
previewInit((_a = getFirstValidDate(value, type)) != null ? _a : getFallbackDate());
|
|
642
660
|
}
|
|
643
661
|
function multipleInit(value, type) {
|
|
662
|
+
var _a;
|
|
644
663
|
const rangeDate = type === "year" ? chooseYears : type === "month" ? chooseMonths : chooseDays;
|
|
645
664
|
const formatType = type === "year" ? "YYYY" : type === "month" ? "YYYY-MM" : "YYYY-MM-D";
|
|
646
665
|
const formatDateList = Array.from(new Set(value.map((choose) => dayjs(choose).format(formatType))));
|
|
647
666
|
rangeDate.value = formatDateList.filter((date) => date !== "Invalid Date");
|
|
667
|
+
previewInit((_a = getFirstValidDate(value, type)) != null ? _a : getFallbackDate());
|
|
648
668
|
}
|
|
649
669
|
function dateInit(value) {
|
|
650
|
-
const handleValue = value ? dayjs(value) : dayjs();
|
|
670
|
+
const handleValue = value ? dayjs(value) : dayjs(getFallbackDate());
|
|
651
671
|
const formatDate = handleValue.format("YYYY-MM-D");
|
|
652
672
|
if (invalidFormatDate(formatDate)) {
|
|
653
673
|
return;
|
|
@@ -657,6 +677,16 @@ const __sfc__ = defineComponent({
|
|
|
657
677
|
chooseMonth.value = monthDes2;
|
|
658
678
|
chooseYear.value = yearValue;
|
|
659
679
|
chooseDay.value = dayValue;
|
|
680
|
+
previewInit(formatDate);
|
|
681
|
+
}
|
|
682
|
+
function previewInit(value) {
|
|
683
|
+
const handleValue = value ? dayjs(value) : dayjs(getFallbackDate());
|
|
684
|
+
const formatDate = handleValue.format("YYYY-MM-D");
|
|
685
|
+
if (invalidFormatDate(formatDate)) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
const [yearValue, monthValue] = formatDate.split("-");
|
|
689
|
+
const monthDes2 = MONTH_LIST.find((month) => month === monthValue);
|
|
660
690
|
previewMonth.value = monthDes2;
|
|
661
691
|
previewYear.value = yearValue;
|
|
662
692
|
}
|
|
@@ -676,6 +706,7 @@ const __sfc__ = defineComponent({
|
|
|
676
706
|
chooseYear,
|
|
677
707
|
chooseDay,
|
|
678
708
|
previewYear,
|
|
709
|
+
displayYear,
|
|
679
710
|
isYearPanel,
|
|
680
711
|
isMonthPanel,
|
|
681
712
|
getMonthTitle,
|
package/es/date-picker/props.mjs
CHANGED
package/es/index.bundle.mjs
CHANGED
|
@@ -56,6 +56,7 @@ import Menu from './menu/index.mjs'
|
|
|
56
56
|
import MenuOption from './menu-option/index.mjs'
|
|
57
57
|
import MenuSelect from './menu-select/index.mjs'
|
|
58
58
|
import Option from './option/index.mjs'
|
|
59
|
+
import OtpInput from './otp-input/index.mjs'
|
|
59
60
|
import Overlay from './overlay/index.mjs'
|
|
60
61
|
import Pagination from './pagination/index.mjs'
|
|
61
62
|
import Paper from './paper/index.mjs'
|
|
@@ -151,6 +152,7 @@ export * from './menu/index.mjs'
|
|
|
151
152
|
export * from './menu-option/index.mjs'
|
|
152
153
|
export * from './menu-select/index.mjs'
|
|
153
154
|
export * from './option/index.mjs'
|
|
155
|
+
export * from './otp-input/index.mjs'
|
|
154
156
|
export * from './overlay/index.mjs'
|
|
155
157
|
export * from './pagination/index.mjs'
|
|
156
158
|
export * from './paper/index.mjs'
|
|
@@ -246,6 +248,7 @@ import './menu/style/index.mjs'
|
|
|
246
248
|
import './menu-option/style/index.mjs'
|
|
247
249
|
import './menu-select/style/index.mjs'
|
|
248
250
|
import './option/style/index.mjs'
|
|
251
|
+
import './otp-input/style/index.mjs'
|
|
249
252
|
import './overlay/style/index.mjs'
|
|
250
253
|
import './pagination/style/index.mjs'
|
|
251
254
|
import './paper/style/index.mjs'
|
|
@@ -283,7 +286,7 @@ import './tooltip/style/index.mjs'
|
|
|
283
286
|
import './uploader/style/index.mjs'
|
|
284
287
|
import './watermark/style/index.mjs'
|
|
285
288
|
|
|
286
|
-
const version = '3.
|
|
289
|
+
const version = '3.16.0-alpha.1778310023051'
|
|
287
290
|
|
|
288
291
|
function install(app) {
|
|
289
292
|
ActionSheet.install && app.use(ActionSheet)
|
|
@@ -344,6 +347,7 @@ function install(app) {
|
|
|
344
347
|
MenuOption.install && app.use(MenuOption)
|
|
345
348
|
MenuSelect.install && app.use(MenuSelect)
|
|
346
349
|
Option.install && app.use(Option)
|
|
350
|
+
OtpInput.install && app.use(OtpInput)
|
|
347
351
|
Overlay.install && app.use(Overlay)
|
|
348
352
|
Pagination.install && app.use(Pagination)
|
|
349
353
|
Paper.install && app.use(Paper)
|
|
@@ -443,6 +447,7 @@ export {
|
|
|
443
447
|
MenuOption,
|
|
444
448
|
MenuSelect,
|
|
445
449
|
Option,
|
|
450
|
+
OtpInput,
|
|
446
451
|
Overlay,
|
|
447
452
|
Pagination,
|
|
448
453
|
Paper,
|
|
@@ -542,6 +547,7 @@ export default {
|
|
|
542
547
|
MenuOption,
|
|
543
548
|
MenuSelect,
|
|
544
549
|
Option,
|
|
550
|
+
OtpInput,
|
|
545
551
|
Overlay,
|
|
546
552
|
Pagination,
|
|
547
553
|
Paper,
|
package/es/index.mjs
CHANGED
|
@@ -56,6 +56,7 @@ import Menu from './menu/index.mjs'
|
|
|
56
56
|
import MenuOption from './menu-option/index.mjs'
|
|
57
57
|
import MenuSelect from './menu-select/index.mjs'
|
|
58
58
|
import Option from './option/index.mjs'
|
|
59
|
+
import OtpInput from './otp-input/index.mjs'
|
|
59
60
|
import Overlay from './overlay/index.mjs'
|
|
60
61
|
import Pagination from './pagination/index.mjs'
|
|
61
62
|
import Paper from './paper/index.mjs'
|
|
@@ -151,6 +152,7 @@ export * from './menu/index.mjs'
|
|
|
151
152
|
export * from './menu-option/index.mjs'
|
|
152
153
|
export * from './menu-select/index.mjs'
|
|
153
154
|
export * from './option/index.mjs'
|
|
155
|
+
export * from './otp-input/index.mjs'
|
|
154
156
|
export * from './overlay/index.mjs'
|
|
155
157
|
export * from './pagination/index.mjs'
|
|
156
158
|
export * from './paper/index.mjs'
|
|
@@ -188,7 +190,7 @@ export * from './tooltip/index.mjs'
|
|
|
188
190
|
export * from './uploader/index.mjs'
|
|
189
191
|
export * from './watermark/index.mjs'
|
|
190
192
|
|
|
191
|
-
const version = '3.
|
|
193
|
+
const version = '3.16.0-alpha.1778310023051'
|
|
192
194
|
|
|
193
195
|
function install(app) {
|
|
194
196
|
ActionSheet.install && app.use(ActionSheet)
|
|
@@ -249,6 +251,7 @@ function install(app) {
|
|
|
249
251
|
MenuOption.install && app.use(MenuOption)
|
|
250
252
|
MenuSelect.install && app.use(MenuSelect)
|
|
251
253
|
Option.install && app.use(Option)
|
|
254
|
+
OtpInput.install && app.use(OtpInput)
|
|
252
255
|
Overlay.install && app.use(Overlay)
|
|
253
256
|
Pagination.install && app.use(Pagination)
|
|
254
257
|
Paper.install && app.use(Paper)
|
|
@@ -348,6 +351,7 @@ export {
|
|
|
348
351
|
MenuOption,
|
|
349
352
|
MenuSelect,
|
|
350
353
|
Option,
|
|
354
|
+
OtpInput,
|
|
351
355
|
Overlay,
|
|
352
356
|
Pagination,
|
|
353
357
|
Paper,
|
|
@@ -447,6 +451,7 @@ export default {
|
|
|
447
451
|
MenuOption,
|
|
448
452
|
MenuSelect,
|
|
449
453
|
Option,
|
|
454
|
+
OtpInput,
|
|
450
455
|
Overlay,
|
|
451
456
|
Pagination,
|
|
452
457
|
Paper,
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { call, clamp, toNumber } from "@varlet/shared";
|
|
2
|
+
import { onSmartMounted } from "@varlet/use";
|
|
3
|
+
import { computed, defineComponent, nextTick, ref, useSlots } from "vue";
|
|
4
|
+
import VarFormDetails from "../form-details/index.mjs";
|
|
5
|
+
import { useForm } from "../form/provide.mjs";
|
|
6
|
+
import VarInput from "../input/Input.mjs";
|
|
7
|
+
import { createNamespace, flatFragment, useValidation } from "../utils/components.mjs";
|
|
8
|
+
import { toSizeUnit } from "../utils/elements.mjs";
|
|
9
|
+
import { props } from "./props.mjs";
|
|
10
|
+
const { name, n, classes } = createNamespace("otp-input");
|
|
11
|
+
import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, resolveComponent as _resolveComponent, createVNode as _createVNode, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, renderSlot as _renderSlot, createCommentVNode as _createCommentVNode, normalizeStyle as _normalizeStyle } from "vue";
|
|
12
|
+
const _hoisted_1 = ["data-index"];
|
|
13
|
+
function __render__(_ctx, _cache) {
|
|
14
|
+
const _component_var_input = _resolveComponent("var-input");
|
|
15
|
+
const _component_var_form_details = _resolveComponent("var-form-details");
|
|
16
|
+
return _openBlock(), _createElementBlock(
|
|
17
|
+
"div",
|
|
18
|
+
{
|
|
19
|
+
ref: "rootEl",
|
|
20
|
+
class: _normalizeClass(_ctx.classes(_ctx.n(), _ctx.n("$--box"))),
|
|
21
|
+
style: _normalizeStyle({
|
|
22
|
+
"--otp-input-gutter": _ctx.gutterStyle,
|
|
23
|
+
"--otp-input-cell-height": _ctx.cellHeightStyle,
|
|
24
|
+
"--otp-input-cell-max-width": _ctx.cellMaxWidthStyle
|
|
25
|
+
}),
|
|
26
|
+
onClick: _cache[1] || (_cache[1] = (...args) => _ctx.handleClick && _ctx.handleClick(...args)),
|
|
27
|
+
onKeydown: _cache[2] || (_cache[2] = (...args) => _ctx.handleKeydown && _ctx.handleKeydown(...args)),
|
|
28
|
+
onPaste: _cache[3] || (_cache[3] = (...args) => _ctx.handlePaste && _ctx.handlePaste(...args))
|
|
29
|
+
},
|
|
30
|
+
[
|
|
31
|
+
_createElementVNode(
|
|
32
|
+
"div",
|
|
33
|
+
{
|
|
34
|
+
class: _normalizeClass(_ctx.n("cells"))
|
|
35
|
+
},
|
|
36
|
+
[
|
|
37
|
+
(_openBlock(true), _createElementBlock(
|
|
38
|
+
_Fragment,
|
|
39
|
+
null,
|
|
40
|
+
_renderList(_ctx.cellIndexes, (_, index) => {
|
|
41
|
+
return _openBlock(), _createElementBlock(
|
|
42
|
+
_Fragment,
|
|
43
|
+
{ key: index },
|
|
44
|
+
[
|
|
45
|
+
_createElementVNode("div", {
|
|
46
|
+
class: _normalizeClass(_ctx.n("cell")),
|
|
47
|
+
"data-index": index
|
|
48
|
+
}, [
|
|
49
|
+
_createVNode(_component_var_input, {
|
|
50
|
+
ref_for: true,
|
|
51
|
+
ref: (el) => _ctx.setInputRef(el, index),
|
|
52
|
+
"model-value": _ctx.getDisplayChar(index),
|
|
53
|
+
type: _ctx.nativeInputType,
|
|
54
|
+
maxlength: 1,
|
|
55
|
+
autocomplete: "one-time-code",
|
|
56
|
+
placeholder: "",
|
|
57
|
+
hint: false,
|
|
58
|
+
variant: _ctx.variant,
|
|
59
|
+
"text-color": _ctx.textColor,
|
|
60
|
+
"focus-color": _ctx.focusColor,
|
|
61
|
+
"blur-color": _ctx.blurColor,
|
|
62
|
+
disabled: _ctx.formDisabled || _ctx.disabled,
|
|
63
|
+
readonly: _ctx.formReadonly || _ctx.readonly,
|
|
64
|
+
inputmode: _ctx.resolvedInputmode,
|
|
65
|
+
"is-force-focusing-effect": _ctx.activeIndex === index,
|
|
66
|
+
"is-force-error-effect": !!_ctx.errorMessage,
|
|
67
|
+
"is-show-form-details": false,
|
|
68
|
+
onFocus: () => _ctx.handleFocus(index),
|
|
69
|
+
onBlur: _cache[0] || (_cache[0] = (event) => _ctx.handleBlur(event)),
|
|
70
|
+
onInput: (value) => _ctx.handleCellInput(index, value)
|
|
71
|
+
}, null, 8, ["model-value", "type", "variant", "text-color", "focus-color", "blur-color", "disabled", "readonly", "inputmode", "is-force-focusing-effect", "is-force-error-effect", "onFocus", "onInput"])
|
|
72
|
+
], 10, _hoisted_1),
|
|
73
|
+
_ctx.shouldRenderSeparator(index) ? (_openBlock(), _createElementBlock(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
key: 0,
|
|
77
|
+
class: _normalizeClass(_ctx.n("separator"))
|
|
78
|
+
},
|
|
79
|
+
[
|
|
80
|
+
_renderSlot(_ctx.$slots, "separator", { index })
|
|
81
|
+
],
|
|
82
|
+
2
|
|
83
|
+
/* CLASS */
|
|
84
|
+
)) : _createCommentVNode("v-if", true)
|
|
85
|
+
],
|
|
86
|
+
64
|
|
87
|
+
/* STABLE_FRAGMENT */
|
|
88
|
+
);
|
|
89
|
+
}),
|
|
90
|
+
128
|
|
91
|
+
/* KEYED_FRAGMENT */
|
|
92
|
+
))
|
|
93
|
+
],
|
|
94
|
+
2
|
|
95
|
+
/* CLASS */
|
|
96
|
+
),
|
|
97
|
+
_createVNode(_component_var_form_details, {
|
|
98
|
+
class: _normalizeClass(_ctx.n("details")),
|
|
99
|
+
"var-otp-input-cover": "",
|
|
100
|
+
"error-message": _ctx.errorMessage
|
|
101
|
+
}, null, 8, ["class", "error-message"])
|
|
102
|
+
],
|
|
103
|
+
38
|
|
104
|
+
/* CLASS, STYLE, NEED_HYDRATION */
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
const __sfc__ = defineComponent({
|
|
108
|
+
name,
|
|
109
|
+
components: {
|
|
110
|
+
VarFormDetails,
|
|
111
|
+
VarInput
|
|
112
|
+
},
|
|
113
|
+
props,
|
|
114
|
+
setup(props2) {
|
|
115
|
+
const slots = useSlots();
|
|
116
|
+
const rootEl = ref(null);
|
|
117
|
+
const inputRefs = ref([]);
|
|
118
|
+
const activeIndex = ref(-1);
|
|
119
|
+
const { errorMessage, validateWithTrigger: vt, validate: v, resetValidation } = useValidation();
|
|
120
|
+
const { bindForm, form } = useForm();
|
|
121
|
+
const normalizedLength = computed(() => toNumber(props2.length));
|
|
122
|
+
const normalizedMaskSymbol = computed(() => {
|
|
123
|
+
var _a;
|
|
124
|
+
return (_a = splitChars(props2.maskSymbol)[0]) != null ? _a : "\u2022";
|
|
125
|
+
});
|
|
126
|
+
const normalizedValue = computed(() => normalizeValue(props2.modelValue));
|
|
127
|
+
const cellIndexes = computed(() => Array.from({ length: normalizedLength.value }));
|
|
128
|
+
const gutterStyle = computed(() => toSizeUnit(props2.gutter));
|
|
129
|
+
const cellHeightStyle = computed(() => toSizeUnit(props2.cellHeight));
|
|
130
|
+
const cellMaxWidthStyle = computed(() => toSizeUnit(props2.cellMaxWidth));
|
|
131
|
+
const resolvedInputmode = computed(() => props2.type === "digit" ? "numeric" : void 0);
|
|
132
|
+
const nativeInputType = computed(() => props2.type === "digit" ? "tel" : "text");
|
|
133
|
+
const formDisabled = computed(() => {
|
|
134
|
+
var _a;
|
|
135
|
+
return (_a = form == null ? void 0 : form.disabled.value) != null ? _a : false;
|
|
136
|
+
});
|
|
137
|
+
const formReadonly = computed(() => {
|
|
138
|
+
var _a;
|
|
139
|
+
return (_a = form == null ? void 0 : form.readonly.value) != null ? _a : false;
|
|
140
|
+
});
|
|
141
|
+
let pendingFocusIndex = null;
|
|
142
|
+
let focusEffectQueued = false;
|
|
143
|
+
bindForm == null ? void 0 : bindForm({ validate, resetValidation, reset });
|
|
144
|
+
onSmartMounted(() => {
|
|
145
|
+
if (props2.autofocus) {
|
|
146
|
+
focus();
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
function splitChars(value) {
|
|
150
|
+
return Array.from(value);
|
|
151
|
+
}
|
|
152
|
+
function normalizeValue(value) {
|
|
153
|
+
return transformByType(value).slice(0, normalizedLength.value);
|
|
154
|
+
}
|
|
155
|
+
function transformByType(value) {
|
|
156
|
+
switch (props2.type) {
|
|
157
|
+
case "digit":
|
|
158
|
+
return value.replace(/\D+/g, "");
|
|
159
|
+
case "alphanumeric":
|
|
160
|
+
return splitChars(value).filter((char) => /[A-Za-z0-9]/.test(char)).join("");
|
|
161
|
+
default:
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function getValueChars() {
|
|
166
|
+
return splitChars(normalizedValue.value);
|
|
167
|
+
}
|
|
168
|
+
function getDisplayChar(index) {
|
|
169
|
+
var _a;
|
|
170
|
+
const char = (_a = getValueChars()[index]) != null ? _a : "";
|
|
171
|
+
if (!char) {
|
|
172
|
+
return "";
|
|
173
|
+
}
|
|
174
|
+
return props2.mask ? normalizedMaskSymbol.value : char;
|
|
175
|
+
}
|
|
176
|
+
function setInputRef(el, index) {
|
|
177
|
+
inputRefs.value[index] = el && "$" in el ? el : null;
|
|
178
|
+
}
|
|
179
|
+
function shouldRenderSeparator(index) {
|
|
180
|
+
if (index >= normalizedLength.value - 1 || !slots.separator) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const vNodes = slots.separator({ index });
|
|
184
|
+
return flatFragment(vNodes).length > 0;
|
|
185
|
+
}
|
|
186
|
+
function validateWithTrigger(trigger, value = normalizedValue.value) {
|
|
187
|
+
nextTick(() => {
|
|
188
|
+
vt(props2.validateTrigger, trigger, props2.rules, value);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function maybeEmitComplete(value) {
|
|
192
|
+
if (splitChars(value).length !== normalizedLength.value) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
call(props2.onComplete, value);
|
|
196
|
+
validateWithTrigger("onComplete", value);
|
|
197
|
+
}
|
|
198
|
+
function updateValue(value, index) {
|
|
199
|
+
if (value === normalizedValue.value) {
|
|
200
|
+
syncCellDisplayValue(index);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
call(props2["onUpdate:modelValue"], value);
|
|
204
|
+
call(props2.onInput, value);
|
|
205
|
+
validateWithTrigger("onInput", value);
|
|
206
|
+
maybeEmitComplete(value);
|
|
207
|
+
}
|
|
208
|
+
function focusCell(index) {
|
|
209
|
+
var _a, _b;
|
|
210
|
+
const targetIndex = clamp(index, 0, normalizedLength.value - 1);
|
|
211
|
+
(_b = (_a = inputRefs.value[targetIndex]) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a);
|
|
212
|
+
}
|
|
213
|
+
function focus(index) {
|
|
214
|
+
const targetIndex = index == null ? Math.min(getValueChars().length, normalizedLength.value - 1) : index;
|
|
215
|
+
focusCell(targetIndex);
|
|
216
|
+
}
|
|
217
|
+
function blur() {
|
|
218
|
+
inputRefs.value.forEach((inputRef) => {
|
|
219
|
+
var _a;
|
|
220
|
+
(_a = inputRef == null ? void 0 : inputRef.blur) == null ? void 0 : _a.call(inputRef);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function validate() {
|
|
224
|
+
return v(props2.rules, normalizedValue.value);
|
|
225
|
+
}
|
|
226
|
+
function reset() {
|
|
227
|
+
if (normalizedValue.value !== "") {
|
|
228
|
+
call(props2["onUpdate:modelValue"], "");
|
|
229
|
+
}
|
|
230
|
+
resetValidation();
|
|
231
|
+
}
|
|
232
|
+
function syncCellDisplayValue(index) {
|
|
233
|
+
var _a;
|
|
234
|
+
const inputEl = (_a = inputRefs.value[index]) == null ? void 0 : _a.el;
|
|
235
|
+
if (inputEl) {
|
|
236
|
+
inputEl.value = getDisplayChar(index);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function syncAllCellDisplayValues() {
|
|
240
|
+
cellIndexes.value.forEach((_, index) => {
|
|
241
|
+
syncCellDisplayValue(index);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function scheduleFocusEffect(index) {
|
|
245
|
+
pendingFocusIndex = index;
|
|
246
|
+
if (focusEffectQueued) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
focusEffectQueued = true;
|
|
250
|
+
nextTick(() => {
|
|
251
|
+
focusEffectQueued = false;
|
|
252
|
+
if (pendingFocusIndex == null) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
activeIndex.value = pendingFocusIndex;
|
|
256
|
+
focusCell(pendingFocusIndex);
|
|
257
|
+
pendingFocusIndex = null;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function replaceChars(index, chars) {
|
|
261
|
+
const valueChars = getValueChars();
|
|
262
|
+
const targetIndex = clamp(index, 0, valueChars.length);
|
|
263
|
+
const nextChars = [...valueChars];
|
|
264
|
+
const processedChars = chars.slice(0, normalizedLength.value - targetIndex);
|
|
265
|
+
processedChars.forEach((char, offset) => {
|
|
266
|
+
nextChars[targetIndex + offset] = char;
|
|
267
|
+
});
|
|
268
|
+
const nextValue = nextChars.join("").slice(0, normalizedLength.value);
|
|
269
|
+
updateValue(nextValue, targetIndex);
|
|
270
|
+
const nextFocusIndex = clamp(targetIndex + processedChars.length, 0, normalizedLength.value - 1);
|
|
271
|
+
scheduleFocusEffect(nextFocusIndex);
|
|
272
|
+
}
|
|
273
|
+
function removeAt(index, focusIndex = clamp(index, 0, normalizedLength.value - 1)) {
|
|
274
|
+
const valueChars = getValueChars();
|
|
275
|
+
valueChars.splice(index, 1);
|
|
276
|
+
const nextValue = valueChars.join("");
|
|
277
|
+
updateValue(nextValue, index);
|
|
278
|
+
scheduleFocusEffect(focusIndex);
|
|
279
|
+
}
|
|
280
|
+
function removeWithBackspace(index) {
|
|
281
|
+
const valueChars = getValueChars();
|
|
282
|
+
if (!valueChars[index]) {
|
|
283
|
+
if (index <= 0) {
|
|
284
|
+
syncAllCellDisplayValues();
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
removeAt(index - 1, index - 1);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const isLastCell = index === valueChars.length - 1;
|
|
291
|
+
const nextFocusIndex = !isLastCell && index > 0 ? index - 1 : clamp(index, 0, normalizedLength.value - 1);
|
|
292
|
+
removeAt(index, nextFocusIndex);
|
|
293
|
+
}
|
|
294
|
+
function handleClick(event) {
|
|
295
|
+
if (props2.disabled || formDisabled.value) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
call(props2.onClick, event);
|
|
299
|
+
validateWithTrigger("onClick");
|
|
300
|
+
}
|
|
301
|
+
function handleFocus(index) {
|
|
302
|
+
const valueChars = getValueChars();
|
|
303
|
+
activeIndex.value = index;
|
|
304
|
+
if (valueChars[index]) {
|
|
305
|
+
nextTick(() => {
|
|
306
|
+
var _a, _b;
|
|
307
|
+
(_b = (_a = inputRefs.value[index]) == null ? void 0 : _a.select) == null ? void 0 : _b.call(_a);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function handleBlur(event) {
|
|
312
|
+
var _a;
|
|
313
|
+
const relatedTarget = event.relatedTarget;
|
|
314
|
+
const isLeavingComponent = !relatedTarget || !((_a = rootEl.value) == null ? void 0 : _a.contains(relatedTarget));
|
|
315
|
+
if (isLeavingComponent) {
|
|
316
|
+
activeIndex.value = -1;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function handleCellInput(index, value) {
|
|
320
|
+
const inputChars = splitChars(transformByType(value));
|
|
321
|
+
const valueChars = getValueChars();
|
|
322
|
+
const crossTargetIndex = index > valueChars.length;
|
|
323
|
+
if (inputChars.length === 0) {
|
|
324
|
+
if (crossTargetIndex) {
|
|
325
|
+
scheduleFocusEffect(valueChars.length);
|
|
326
|
+
syncCellDisplayValue(index);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (value === "") {
|
|
330
|
+
removeAt(index);
|
|
331
|
+
} else {
|
|
332
|
+
syncCellDisplayValue(index);
|
|
333
|
+
}
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (crossTargetIndex) {
|
|
337
|
+
replaceChars(valueChars.length, inputChars);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
replaceChars(index, inputChars);
|
|
341
|
+
}
|
|
342
|
+
function handlePaste(event) {
|
|
343
|
+
var _a, _b;
|
|
344
|
+
if (!props2.allowPaste || formDisabled.value || formReadonly.value || props2.disabled || props2.readonly) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const text = (_b = (_a = event.clipboardData) == null ? void 0 : _a.getData("text")) != null ? _b : "";
|
|
348
|
+
if (!text) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
event.preventDefault();
|
|
352
|
+
const transformedValue = props2.pasteTransform ? props2.pasteTransform(text) : text;
|
|
353
|
+
const result = transformByType(transformedValue);
|
|
354
|
+
call(props2.onPaste, result, event);
|
|
355
|
+
validateWithTrigger("onPaste", result);
|
|
356
|
+
if (!result) {
|
|
357
|
+
syncAllCellDisplayValues();
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
replaceChars(0, splitChars(result));
|
|
361
|
+
}
|
|
362
|
+
function handleKeydown(event) {
|
|
363
|
+
if (formDisabled.value || formReadonly.value || props2.disabled || props2.readonly) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const target = event.target;
|
|
367
|
+
const cell = target == null ? void 0 : target.closest(`.${n("cell")}`);
|
|
368
|
+
const indexAttr = cell == null ? void 0 : cell.dataset.index;
|
|
369
|
+
if (indexAttr == null) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const index = Number(indexAttr);
|
|
373
|
+
if (event.key === "Backspace" && getValueChars().length > 0) {
|
|
374
|
+
event.preventDefault();
|
|
375
|
+
removeWithBackspace(index);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (event.key === "ArrowLeft" && index > 0) {
|
|
379
|
+
event.preventDefault();
|
|
380
|
+
focusCell(index - 1);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (event.key === "ArrowRight" && index < normalizedLength.value - 1) {
|
|
384
|
+
event.preventDefault();
|
|
385
|
+
focusCell(index + 1);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
rootEl,
|
|
391
|
+
activeIndex,
|
|
392
|
+
errorMessage,
|
|
393
|
+
formDisabled,
|
|
394
|
+
formReadonly,
|
|
395
|
+
cellIndexes,
|
|
396
|
+
gutterStyle,
|
|
397
|
+
cellHeightStyle,
|
|
398
|
+
cellMaxWidthStyle,
|
|
399
|
+
resolvedInputmode,
|
|
400
|
+
nativeInputType,
|
|
401
|
+
n,
|
|
402
|
+
classes,
|
|
403
|
+
setInputRef,
|
|
404
|
+
getDisplayChar,
|
|
405
|
+
shouldRenderSeparator,
|
|
406
|
+
handleClick,
|
|
407
|
+
handleFocus,
|
|
408
|
+
handleBlur,
|
|
409
|
+
handleCellInput,
|
|
410
|
+
handleKeydown,
|
|
411
|
+
handlePaste,
|
|
412
|
+
focus,
|
|
413
|
+
blur,
|
|
414
|
+
reset,
|
|
415
|
+
validate,
|
|
416
|
+
resetValidation
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
__sfc__.render = __render__;
|
|
421
|
+
var stdin_default = __sfc__;
|
|
422
|
+
export {
|
|
423
|
+
stdin_default as default
|
|
424
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { withInstall, withPropsDefaultsSetter } from "../utils/components.mjs";
|
|
2
|
+
import OtpInput from "./OtpInput.mjs";
|
|
3
|
+
import { props as otpInputProps } from "./props.mjs";
|
|
4
|
+
withInstall(OtpInput);
|
|
5
|
+
withPropsDefaultsSetter(OtpInput, otpInputProps);
|
|
6
|
+
const _OtpInputComponent = OtpInput;
|
|
7
|
+
var stdin_default = OtpInput;
|
|
8
|
+
export {
|
|
9
|
+
_OtpInputComponent,
|
|
10
|
+
stdin_default as default,
|
|
11
|
+
otpInputProps
|
|
12
|
+
};
|