@varlet/ui 3.15.2 → 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/action-sheet/style/index.mjs +1 -1
- 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 +7926 -7548
- package/highlight/web-types.en-US.json +201 -1
- package/highlight/web-types.zh-CN.json +201 -1
- package/lib/varlet.cjs.js +2229 -1767
- package/lib/varlet.css +1 -1
- package/package.json +7 -7
- 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
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root { --otp-input-gutter: 8px; --otp-input-cell-height: 48px; --otp-input-cell-max-width: 48px; --otp-input-input-font-size: 20px; --otp-input-separator-color: var(--color-text-disabled);}.var-otp-input { display: inline-flex; flex-direction: column; align-items: stretch; width: 100%; max-width: 100%;}.var-otp-input__cells { display: flex; align-items: center; justify-content: center; gap: var(--otp-input-gutter); width: 100%; max-width: 100%;}.var-otp-input__cell { flex: 1 1 0; min-width: 0; height: var(--otp-input-cell-height); max-width: var(--otp-input-cell-max-width);}.var-otp-input__separator { flex: none; display: inline-flex; align-items: center; justify-content: center; color: var(--otp-input-separator-color); white-space: nowrap;}.var-otp-input__details { width: 100%;}.var-otp-input .var-input__input { text-align: center; font-size: var(--otp-input-input-font-size); text-transform: none; height: 100%;}.var-otp-input .var-field-decorator__middle { justify-content: center;}.var-otp-input .var-field-decorator--standard .var-field-decorator__controller,.var-otp-input .var-field-decorator--standard .var-field-decorator__middle { height: 100%;}.var-otp-input .var-field-decorator--standard .var-field-decorator__middle,.var-otp-input .var-field-decorator--standard .var-field-decorator__icon,.var-otp-input .var-field-decorator--standard .var-field-decorator--middle-non-hint,.var-otp-input .var-field-decorator--standard .var-field-decorator--icon-non-hint { margin-top: 0; margin-bottom: 0;}.var-otp-input .var-field-decorator--outlined .var-field-decorator__controller,.var-otp-input .var-field-decorator--outlined .var-field-decorator__middle { height: 100%;}.var-otp-input .var-field-decorator--outlined .var-field-decorator__middle,.var-otp-input .var-field-decorator--outlined .var-field-decorator__icon { margin-top: 0; margin-bottom: 0;}.var-otp-input .var-field-decorator--filled .var-field-decorator__controller,.var-otp-input .var-field-decorator--filled .var-field-decorator__middle { height: 100%;}.var-otp-input .var-field-decorator--filled .var-field-decorator__middle,.var-otp-input .var-field-decorator--filled .var-field-decorator__icon,.var-otp-input .var-field-decorator--filled .var-field-decorator--middle-non-hint,.var-otp-input .var-field-decorator--filled .var-field-decorator--icon-non-hint { margin-top: 0; margin-bottom: 0;}.var-otp-input .var-input,.var-otp-input .var-field-decorator,.var-otp-input .var-field-decorator__container,.var-otp-input .var-field-decorator__main,.var-otp-input .var-field-decorator__body { height: 100%;}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { fieldDecoratorProps } from "../field-decorator/index.mjs";
|
|
21
|
+
import { defineListenerProp, pickProps } from "../utils/components.mjs";
|
|
22
|
+
const props = __spreadProps(__spreadValues({
|
|
23
|
+
modelValue: {
|
|
24
|
+
type: String,
|
|
25
|
+
default: ""
|
|
26
|
+
},
|
|
27
|
+
length: {
|
|
28
|
+
type: [String, Number],
|
|
29
|
+
default: 6
|
|
30
|
+
},
|
|
31
|
+
type: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: "digit"
|
|
34
|
+
},
|
|
35
|
+
mask: Boolean,
|
|
36
|
+
maskSymbol: {
|
|
37
|
+
type: String,
|
|
38
|
+
default: "\u2022"
|
|
39
|
+
},
|
|
40
|
+
cellHeight: {
|
|
41
|
+
type: [String, Number],
|
|
42
|
+
default: 48
|
|
43
|
+
},
|
|
44
|
+
cellMaxWidth: {
|
|
45
|
+
type: [String, Number],
|
|
46
|
+
default: 48
|
|
47
|
+
},
|
|
48
|
+
disabled: Boolean,
|
|
49
|
+
readonly: Boolean,
|
|
50
|
+
autofocus: Boolean,
|
|
51
|
+
gutter: {
|
|
52
|
+
type: [String, Number],
|
|
53
|
+
default: 8
|
|
54
|
+
},
|
|
55
|
+
validateTrigger: {
|
|
56
|
+
type: Array,
|
|
57
|
+
default: () => ["onInput", "onComplete"]
|
|
58
|
+
},
|
|
59
|
+
rules: [Array, Function, Object],
|
|
60
|
+
allowPaste: {
|
|
61
|
+
type: Boolean,
|
|
62
|
+
default: true
|
|
63
|
+
},
|
|
64
|
+
pasteTransform: Function,
|
|
65
|
+
onInput: defineListenerProp(),
|
|
66
|
+
onClick: defineListenerProp(),
|
|
67
|
+
onPaste: defineListenerProp(),
|
|
68
|
+
onComplete: defineListenerProp(),
|
|
69
|
+
"onUpdate:modelValue": defineListenerProp()
|
|
70
|
+
}, pickProps(fieldDecoratorProps, ["textColor", "focusColor", "blurColor"])), {
|
|
71
|
+
variant: {
|
|
72
|
+
type: String,
|
|
73
|
+
default: "outlined"
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
export {
|
|
77
|
+
props
|
|
78
|
+
};
|
package/es/style.mjs
CHANGED
|
@@ -56,6 +56,7 @@ import './menu/style/index.mjs'
|
|
|
56
56
|
import './menu-option/style/index.mjs'
|
|
57
57
|
import './menu-select/style/index.mjs'
|
|
58
58
|
import './option/style/index.mjs'
|
|
59
|
+
import './otp-input/style/index.mjs'
|
|
59
60
|
import './overlay/style/index.mjs'
|
|
60
61
|
import './pagination/style/index.mjs'
|
|
61
62
|
import './paper/style/index.mjs'
|