@hina-ui/vue 1.7.11 → 1.7.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +815 -761
- package/dist/index.js.map +1 -1
- package/dist/shared/lib/css-time.ts +6 -0
- package/dist/shared/lib/line-clamp.ts +8 -8
- package/dist/shared/primitives/pin-input/index.ts +394 -97
- package/dist/shared/styles/interaction.css +6 -2
- package/dist/shared/styles/line-clamp.css +6 -2
- package/dist/shared/styles/pin-input.css +84 -0
- package/dist/shared/styles/tokens.css +1 -0
- package/dist/shared/variants/pin-input.ts +26 -7
- package/dist/types/shared/src/lib/css-time.d.ts +2 -0
- package/dist/types/shared/src/lib/css-time.d.ts.map +1 -0
- package/dist/types/shared/src/lib/line-clamp.d.ts.map +1 -1
- package/dist/types/shared/src/primitives/pin-input/index.d.ts +35 -27
- package/dist/types/shared/src/primitives/pin-input/index.d.ts.map +1 -1
- package/dist/types/shared/src/variants/pin-input.d.ts +30 -10
- package/dist/types/shared/src/variants/pin-input.d.ts.map +1 -1
- package/dist/types/vue/src/components/image/composables/useImage.d.ts.map +1 -1
- package/dist/types/vue/src/components/pin-input/PinInput.vue.d.ts +2 -0
- package/dist/types/vue/src/components/pin-input/PinInput.vue.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/image/composables/useImage.ts +2 -1
- package/src/components/pin-input/PinInput.vue +103 -33
- package/dist/shared/primitives/pin-input/LICENSE +0 -21
- package/dist/types/vue/src/primitives/pin-input/PinInputInput.d.ts +0 -52
- package/dist/types/vue/src/primitives/pin-input/PinInputInput.d.ts.map +0 -1
- package/dist/types/vue/src/primitives/pin-input/PinInputRoot.d.ts +0 -149
- package/dist/types/vue/src/primitives/pin-input/PinInputRoot.d.ts.map +0 -1
- package/dist/types/vue/src/primitives/pin-input/context.d.ts +0 -20
- package/dist/types/vue/src/primitives/pin-input/context.d.ts.map +0 -1
- package/dist/types/vue/src/primitives/pin-input/index.d.ts +0 -4
- package/dist/types/vue/src/primitives/pin-input/index.d.ts.map +0 -1
- package/src/primitives/pin-input/LICENSE +0 -44
- package/src/primitives/pin-input/PinInputInput.ts +0 -218
- package/src/primitives/pin-input/PinInputRoot.ts +0 -136
- package/src/primitives/pin-input/context.ts +0 -24
- package/src/primitives/pin-input/index.ts +0 -3
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { type PropType } from 'vue';
|
|
2
|
-
import { type PinInputValue } from '../../../../shared/src/primitives/pin-input';
|
|
3
|
-
import { type PrimitiveProps } from '../primitive';
|
|
4
|
-
import { type Direction } from '../utils/useDirection';
|
|
5
|
-
import { type PinInputType } from './context';
|
|
6
|
-
export interface PinInputRootProps {
|
|
7
|
-
modelValue?: PinInputValue | null;
|
|
8
|
-
defaultValue?: PinInputValue;
|
|
9
|
-
placeholder?: string;
|
|
10
|
-
mask?: boolean;
|
|
11
|
-
otp?: boolean;
|
|
12
|
-
type?: PinInputType;
|
|
13
|
-
dir?: Direction;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
id?: string;
|
|
16
|
-
asChild?: boolean;
|
|
17
|
-
as?: PrimitiveProps['as'];
|
|
18
|
-
name?: string;
|
|
19
|
-
required?: boolean;
|
|
20
|
-
}
|
|
21
|
-
export type PinInputRootEmits = {
|
|
22
|
-
'update:modelValue': [value: PinInputValue];
|
|
23
|
-
complete: [value: PinInputValue];
|
|
24
|
-
};
|
|
25
|
-
export declare const PinInputRoot: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
26
|
-
modelValue: {
|
|
27
|
-
type: PropType<PinInputValue | null>;
|
|
28
|
-
required: false;
|
|
29
|
-
};
|
|
30
|
-
defaultValue: {
|
|
31
|
-
type: PropType<PinInputValue>;
|
|
32
|
-
required: false;
|
|
33
|
-
};
|
|
34
|
-
placeholder: {
|
|
35
|
-
type: StringConstructor;
|
|
36
|
-
required: false;
|
|
37
|
-
default: string;
|
|
38
|
-
};
|
|
39
|
-
mask: {
|
|
40
|
-
type: BooleanConstructor;
|
|
41
|
-
required: false;
|
|
42
|
-
};
|
|
43
|
-
otp: {
|
|
44
|
-
type: BooleanConstructor;
|
|
45
|
-
required: false;
|
|
46
|
-
};
|
|
47
|
-
type: {
|
|
48
|
-
type: PropType<PinInputType>;
|
|
49
|
-
required: false;
|
|
50
|
-
default: string;
|
|
51
|
-
};
|
|
52
|
-
dir: {
|
|
53
|
-
type: PropType<Direction>;
|
|
54
|
-
required: false;
|
|
55
|
-
};
|
|
56
|
-
disabled: {
|
|
57
|
-
type: BooleanConstructor;
|
|
58
|
-
required: false;
|
|
59
|
-
};
|
|
60
|
-
id: {
|
|
61
|
-
type: StringConstructor;
|
|
62
|
-
required: false;
|
|
63
|
-
};
|
|
64
|
-
asChild: {
|
|
65
|
-
type: BooleanConstructor;
|
|
66
|
-
required: false;
|
|
67
|
-
};
|
|
68
|
-
as: {
|
|
69
|
-
type: PropType<PrimitiveProps["as"]>;
|
|
70
|
-
required: false;
|
|
71
|
-
};
|
|
72
|
-
name: {
|
|
73
|
-
type: StringConstructor;
|
|
74
|
-
required: false;
|
|
75
|
-
};
|
|
76
|
-
required: {
|
|
77
|
-
type: BooleanConstructor;
|
|
78
|
-
required: false;
|
|
79
|
-
};
|
|
80
|
-
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
81
|
-
[key: string]: any;
|
|
82
|
-
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("update:modelValue" | "complete")[], "update:modelValue" | "complete", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
83
|
-
modelValue: {
|
|
84
|
-
type: PropType<PinInputValue | null>;
|
|
85
|
-
required: false;
|
|
86
|
-
};
|
|
87
|
-
defaultValue: {
|
|
88
|
-
type: PropType<PinInputValue>;
|
|
89
|
-
required: false;
|
|
90
|
-
};
|
|
91
|
-
placeholder: {
|
|
92
|
-
type: StringConstructor;
|
|
93
|
-
required: false;
|
|
94
|
-
default: string;
|
|
95
|
-
};
|
|
96
|
-
mask: {
|
|
97
|
-
type: BooleanConstructor;
|
|
98
|
-
required: false;
|
|
99
|
-
};
|
|
100
|
-
otp: {
|
|
101
|
-
type: BooleanConstructor;
|
|
102
|
-
required: false;
|
|
103
|
-
};
|
|
104
|
-
type: {
|
|
105
|
-
type: PropType<PinInputType>;
|
|
106
|
-
required: false;
|
|
107
|
-
default: string;
|
|
108
|
-
};
|
|
109
|
-
dir: {
|
|
110
|
-
type: PropType<Direction>;
|
|
111
|
-
required: false;
|
|
112
|
-
};
|
|
113
|
-
disabled: {
|
|
114
|
-
type: BooleanConstructor;
|
|
115
|
-
required: false;
|
|
116
|
-
};
|
|
117
|
-
id: {
|
|
118
|
-
type: StringConstructor;
|
|
119
|
-
required: false;
|
|
120
|
-
};
|
|
121
|
-
asChild: {
|
|
122
|
-
type: BooleanConstructor;
|
|
123
|
-
required: false;
|
|
124
|
-
};
|
|
125
|
-
as: {
|
|
126
|
-
type: PropType<PrimitiveProps["as"]>;
|
|
127
|
-
required: false;
|
|
128
|
-
};
|
|
129
|
-
name: {
|
|
130
|
-
type: StringConstructor;
|
|
131
|
-
required: false;
|
|
132
|
-
};
|
|
133
|
-
required: {
|
|
134
|
-
type: BooleanConstructor;
|
|
135
|
-
required: false;
|
|
136
|
-
};
|
|
137
|
-
}>> & Readonly<{
|
|
138
|
-
onComplete?: ((...args: any[]) => any) | undefined;
|
|
139
|
-
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
140
|
-
}>, {
|
|
141
|
-
placeholder: string;
|
|
142
|
-
required: boolean;
|
|
143
|
-
mask: boolean;
|
|
144
|
-
type: PinInputType;
|
|
145
|
-
disabled: boolean;
|
|
146
|
-
asChild: boolean;
|
|
147
|
-
otp: boolean;
|
|
148
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
149
|
-
//# sourceMappingURL=PinInputRoot.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PinInputRoot.d.ts","sourceRoot":"","sources":["../../../../../../src/primitives/pin-input/PinInputRoot.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,QAAQ,EACd,MAAM,KAAK,CAAA;AACZ,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,6CAA6C,CAAA;AACpD,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7D,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAIpE,OAAO,EAA8B,KAAK,YAAY,EAAE,MAAM,WAAW,CAAA;AAEzE,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;IACjC,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB,GAAG,CAAC,EAAE,SAAS,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,EAAE,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAA;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mBAAmB,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;IAC3C,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,YAAY;;cAIkB,QAAQ,CAAC,aAAa,GAAG,IAAI,CAAC;;;;cAC5B,QAAQ,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;cAI/B,QAAQ,CAAC,YAAY,CAAC;;;;;cAChC,QAAQ,CAAC,SAAS,CAAC;;;;;;;;;;;;;;;;cAIX,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;;;;;;;;;;;;;;;cAVtB,QAAQ,CAAC,aAAa,GAAG,IAAI,CAAC;;;;cAC5B,QAAQ,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;cAI/B,QAAQ,CAAC,YAAY,CAAC;;;;;cAChC,QAAQ,CAAC,SAAS,CAAC;;;;;;;;;;;;;;;;cAIX,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;4EA4E/D,CAAA"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ComputedRef, Ref } from 'vue';
|
|
2
|
-
import type { PinInputValue } from '../../../../shared/src/primitives/pin-input';
|
|
3
|
-
import type { Direction } from '../utils/useDirection';
|
|
4
|
-
export type PinInputType = 'text' | 'number';
|
|
5
|
-
export interface PinInputRootContext {
|
|
6
|
-
modelValue: Ref<PinInputValue>;
|
|
7
|
-
currentModelValue: ComputedRef<PinInputValue>;
|
|
8
|
-
mask: Ref<boolean>;
|
|
9
|
-
otp: Ref<boolean>;
|
|
10
|
-
placeholder: Ref<string>;
|
|
11
|
-
type: Ref<PinInputType>;
|
|
12
|
-
dir: Ref<Direction>;
|
|
13
|
-
disabled: Ref<boolean>;
|
|
14
|
-
isCompleted: ComputedRef<boolean>;
|
|
15
|
-
inputElements?: Ref<Set<HTMLInputElement>>;
|
|
16
|
-
onInputElementChange: (element: HTMLInputElement) => void;
|
|
17
|
-
isNumericMode: ComputedRef<boolean>;
|
|
18
|
-
}
|
|
19
|
-
export declare const injectPinInputRootContext: <T extends PinInputRootContext | null | undefined = PinInputRootContext>(fallback?: T | undefined) => T extends null ? PinInputRootContext | null : PinInputRootContext, providePinInputRootContext: (value: PinInputRootContext) => PinInputRootContext;
|
|
20
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../../../src/primitives/pin-input/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAA;AAEhF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE5C,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,GAAG,CAAC,aAAa,CAAC,CAAA;IAC9B,iBAAiB,EAAE,WAAW,CAAC,aAAa,CAAC,CAAA;IAC7C,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAClB,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IACjB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACxB,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,CAAA;IACvB,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;IACnB,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IACtB,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IACjC,aAAa,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAC1C,oBAAoB,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAA;IACzD,aAAa,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CACpC;AAED,eAAO,MAAO,yBAAyB,2KAAE,0BAA0B,qDACf,CAAA"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { injectPinInputRootContext, type PinInputRootContext, type PinInputType } from './context';
|
|
2
|
-
export { PinInputInput, type PinInputInputProps } from './PinInputInput';
|
|
3
|
-
export { PinInputRoot, type PinInputRootEmits, type PinInputRootProps } from './PinInputRoot';
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/primitives/pin-input/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,KAAK,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAA;AAClG,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 UnoVue <https://github.com/unovue>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
Portions adapted from VueUse:
|
|
24
|
-
MIT License
|
|
25
|
-
|
|
26
|
-
Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/antfu>
|
|
27
|
-
|
|
28
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
29
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
30
|
-
in the Software without restriction, including without limitation the rights
|
|
31
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
32
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
33
|
-
furnished to do so, subject to the following conditions:
|
|
34
|
-
|
|
35
|
-
The above copyright notice and this permission notice shall be included in all
|
|
36
|
-
copies or substantial portions of the Software.
|
|
37
|
-
|
|
38
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
39
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
40
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
41
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
42
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
43
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
44
|
-
SOFTWARE.
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
computed,
|
|
3
|
-
defineComponent,
|
|
4
|
-
h,
|
|
5
|
-
nextTick,
|
|
6
|
-
onMounted,
|
|
7
|
-
onUnmounted,
|
|
8
|
-
renderSlot,
|
|
9
|
-
watch,
|
|
10
|
-
withCtx,
|
|
11
|
-
withKeys,
|
|
12
|
-
type PropType,
|
|
13
|
-
} from 'vue'
|
|
14
|
-
import { getActiveElement } from '../../../../shared/src/primitives/focus-scope'
|
|
15
|
-
import {
|
|
16
|
-
navigatePin,
|
|
17
|
-
pinFocusRedirect,
|
|
18
|
-
pinInputLabel,
|
|
19
|
-
pinPlaceholder,
|
|
20
|
-
resolvePinComposition,
|
|
21
|
-
resolvePinInput,
|
|
22
|
-
resolvePinPaste,
|
|
23
|
-
setPinValueAt,
|
|
24
|
-
spreadPinValue,
|
|
25
|
-
type PinTextAction,
|
|
26
|
-
} from '../../../../shared/src/primitives/pin-input'
|
|
27
|
-
import { Primitive, type PrimitiveProps } from '../primitive'
|
|
28
|
-
import { useComposing } from '../utils/useComposing'
|
|
29
|
-
import { usePrimitiveElement } from '../utils/usePrimitiveElement'
|
|
30
|
-
import { injectPinInputRootContext } from './context'
|
|
31
|
-
|
|
32
|
-
export interface PinInputInputProps {
|
|
33
|
-
index: number
|
|
34
|
-
disabled?: boolean
|
|
35
|
-
asChild?: boolean
|
|
36
|
-
as?: PrimitiveProps['as']
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const PinInputInput = defineComponent({
|
|
40
|
-
name: 'PinInputInput',
|
|
41
|
-
props: {
|
|
42
|
-
index: { type: Number, required: true },
|
|
43
|
-
disabled: { type: Boolean, required: false },
|
|
44
|
-
asChild: { type: Boolean, required: false },
|
|
45
|
-
as: {
|
|
46
|
-
type: null as unknown as PropType<PrimitiveProps['as']>,
|
|
47
|
-
required: false,
|
|
48
|
-
default: 'input',
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
setup(props, { slots }) {
|
|
52
|
-
const context = injectPinInputRootContext()
|
|
53
|
-
const inputElements = computed(() => [...context.inputElements!.value])
|
|
54
|
-
const currentValue = computed(() => context.currentModelValue.value[props.index])
|
|
55
|
-
const disabled = computed(() => props.disabled || context.disabled.value)
|
|
56
|
-
const isOtpMode = computed(() => context.otp.value)
|
|
57
|
-
const isPasswordMode = computed(() => context.mask.value)
|
|
58
|
-
const { primitiveElement, currentElement } = usePrimitiveElement()
|
|
59
|
-
|
|
60
|
-
function updateModelValueAt(index: number, value: string) {
|
|
61
|
-
context.modelValue.value = setPinValueAt(
|
|
62
|
-
context.currentModelValue.value,
|
|
63
|
-
index,
|
|
64
|
-
value,
|
|
65
|
-
context.isNumericMode.value,
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function handleMultipleCharacter(characters: string) {
|
|
70
|
-
const { values, filled, end } = spreadPinValue(
|
|
71
|
-
context.currentModelValue.value,
|
|
72
|
-
characters,
|
|
73
|
-
props.index,
|
|
74
|
-
inputElements.value.length,
|
|
75
|
-
context.isNumericMode.value,
|
|
76
|
-
)
|
|
77
|
-
for (const at of filled) inputElements.value[at]!.focus()
|
|
78
|
-
context.modelValue.value = values
|
|
79
|
-
inputElements.value[end]?.focus()
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function apply(target: HTMLInputElement, action: PinTextAction) {
|
|
83
|
-
if (action.kind === 'clear') target.value = ''
|
|
84
|
-
else if (action.kind === 'filter') target.value = action.value
|
|
85
|
-
else if (action.kind === 'spread') handleMultipleCharacter(action.characters)
|
|
86
|
-
else {
|
|
87
|
-
target.value = action.character
|
|
88
|
-
updateModelValueAt(props.index, target.value)
|
|
89
|
-
inputElements.value[props.index + 1]?.focus()
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const { isComposing, handleCompositionStart, handleCompositionEnd } = useComposing(event => {
|
|
94
|
-
const target = event.target as HTMLInputElement
|
|
95
|
-
apply(target, resolvePinComposition(event.data || target.value, context.isNumericMode.value))
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
function handleInput(event: InputEvent) {
|
|
99
|
-
if (isComposing.value || event.isComposing) return
|
|
100
|
-
const target = event.target as HTMLInputElement
|
|
101
|
-
apply(target, resolvePinInput(event.data, target.value, context.isNumericMode.value))
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function updatePlaceholder() {
|
|
105
|
-
void nextTick(() => {
|
|
106
|
-
const target = currentElement.value as HTMLInputElement | undefined
|
|
107
|
-
if (!target) return
|
|
108
|
-
pinPlaceholder(target, getActiveElement(), context.placeholder.value)
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function handleKeydown(event: KeyboardEvent) {
|
|
113
|
-
if (isComposing.value || event.isComposing) return
|
|
114
|
-
navigatePin(
|
|
115
|
-
event,
|
|
116
|
-
getActiveElement() as HTMLElement | null,
|
|
117
|
-
inputElements.value,
|
|
118
|
-
context.dir.value,
|
|
119
|
-
)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function handleBackspace(event: KeyboardEvent) {
|
|
123
|
-
event.preventDefault()
|
|
124
|
-
const target = event.target as HTMLInputElement
|
|
125
|
-
if (target.value) updateModelValueAt(props.index, '')
|
|
126
|
-
else {
|
|
127
|
-
const previous = inputElements.value[props.index - 1]
|
|
128
|
-
if (previous) {
|
|
129
|
-
previous.focus()
|
|
130
|
-
updateModelValueAt(props.index - 1, '')
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function handleDelete(event: KeyboardEvent) {
|
|
136
|
-
if (event.key === 'Delete') {
|
|
137
|
-
event.preventDefault()
|
|
138
|
-
updateModelValueAt(props.index, '')
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function handleFocus(event: FocusEvent) {
|
|
143
|
-
if (context.otp.value) {
|
|
144
|
-
const redirect = pinFocusRedirect(
|
|
145
|
-
context.currentModelValue.value,
|
|
146
|
-
inputElements.value.length,
|
|
147
|
-
props.index,
|
|
148
|
-
)
|
|
149
|
-
if (redirect !== -1) {
|
|
150
|
-
inputElements.value[redirect]!.focus()
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
;(event.target as HTMLInputElement).setSelectionRange(1, 1)
|
|
155
|
-
updatePlaceholder()
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function handlePaste(event: ClipboardEvent) {
|
|
159
|
-
event.preventDefault()
|
|
160
|
-
const clipboardData = event.clipboardData
|
|
161
|
-
if (!clipboardData) return
|
|
162
|
-
handleMultipleCharacter(
|
|
163
|
-
resolvePinPaste(clipboardData.getData('text'), context.isNumericMode.value),
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
watch(currentValue, updatePlaceholder)
|
|
168
|
-
onMounted(() => {
|
|
169
|
-
context.onInputElementChange(currentElement.value as HTMLInputElement)
|
|
170
|
-
})
|
|
171
|
-
onUnmounted(() => {
|
|
172
|
-
context.inputElements?.value.delete(currentElement.value as HTMLInputElement)
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
const onInput = (event: Event) => handleInput(event as InputEvent)
|
|
176
|
-
const onKeydown = [
|
|
177
|
-
withKeys(handleKeydown as (event: Event) => void, [
|
|
178
|
-
'left',
|
|
179
|
-
'right',
|
|
180
|
-
'up',
|
|
181
|
-
'down',
|
|
182
|
-
'home',
|
|
183
|
-
'end',
|
|
184
|
-
]),
|
|
185
|
-
withKeys(handleBackspace as (event: Event) => void, ['backspace']),
|
|
186
|
-
withKeys(handleDelete as (event: Event) => void, ['delete']),
|
|
187
|
-
]
|
|
188
|
-
|
|
189
|
-
return () =>
|
|
190
|
-
h(
|
|
191
|
-
Primitive,
|
|
192
|
-
{
|
|
193
|
-
ref: primitiveElement,
|
|
194
|
-
autocapitalize: 'none',
|
|
195
|
-
as: props.as,
|
|
196
|
-
'as-child': props.asChild,
|
|
197
|
-
autocomplete: isOtpMode.value ? 'one-time-code' : 'false',
|
|
198
|
-
type: isPasswordMode.value ? 'password' : 'text',
|
|
199
|
-
inputmode: context.isNumericMode.value ? 'numeric' : 'text',
|
|
200
|
-
pattern: context.isNumericMode.value ? '[0-9]*' : undefined,
|
|
201
|
-
placeholder: context.placeholder.value,
|
|
202
|
-
value: currentValue.value,
|
|
203
|
-
disabled: disabled.value,
|
|
204
|
-
'data-disabled': disabled.value ? '' : undefined,
|
|
205
|
-
'data-complete': context.isCompleted.value ? '' : undefined,
|
|
206
|
-
'aria-label': pinInputLabel(props.index, inputElements.value.length),
|
|
207
|
-
onInput,
|
|
208
|
-
onKeydown,
|
|
209
|
-
onFocus: handleFocus,
|
|
210
|
-
onBlur: updatePlaceholder,
|
|
211
|
-
onPaste: handlePaste,
|
|
212
|
-
onCompositionstart: handleCompositionStart,
|
|
213
|
-
onCompositionend: handleCompositionEnd,
|
|
214
|
-
},
|
|
215
|
-
{ default: withCtx(() => [renderSlot(slots, 'default')]) },
|
|
216
|
-
)
|
|
217
|
-
},
|
|
218
|
-
})
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
computed,
|
|
3
|
-
defineComponent,
|
|
4
|
-
h,
|
|
5
|
-
mergeProps,
|
|
6
|
-
ref,
|
|
7
|
-
renderSlot,
|
|
8
|
-
toRefs,
|
|
9
|
-
watch,
|
|
10
|
-
withCtx,
|
|
11
|
-
type PropType,
|
|
12
|
-
} from 'vue'
|
|
13
|
-
import {
|
|
14
|
-
isPinInputComplete,
|
|
15
|
-
pinInputValues,
|
|
16
|
-
type PinInputValue,
|
|
17
|
-
} from '../../../../shared/src/primitives/pin-input'
|
|
18
|
-
import { Primitive, type PrimitiveProps } from '../primitive'
|
|
19
|
-
import { useDirection, type Direction } from '../utils/useDirection'
|
|
20
|
-
import { useForwardExpose } from '../utils/useForwardExpose'
|
|
21
|
-
import { useVModel } from '../utils/useVModel'
|
|
22
|
-
import { VisuallyHiddenInput } from '../visually-hidden'
|
|
23
|
-
import { providePinInputRootContext, type PinInputType } from './context'
|
|
24
|
-
|
|
25
|
-
export interface PinInputRootProps {
|
|
26
|
-
modelValue?: PinInputValue | null
|
|
27
|
-
defaultValue?: PinInputValue
|
|
28
|
-
placeholder?: string
|
|
29
|
-
mask?: boolean
|
|
30
|
-
otp?: boolean
|
|
31
|
-
type?: PinInputType
|
|
32
|
-
dir?: Direction
|
|
33
|
-
disabled?: boolean
|
|
34
|
-
id?: string
|
|
35
|
-
asChild?: boolean
|
|
36
|
-
as?: PrimitiveProps['as']
|
|
37
|
-
name?: string
|
|
38
|
-
required?: boolean
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type PinInputRootEmits = {
|
|
42
|
-
'update:modelValue': [value: PinInputValue]
|
|
43
|
-
complete: [value: PinInputValue]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const PinInputRoot = defineComponent({
|
|
47
|
-
name: 'PinInputRoot',
|
|
48
|
-
inheritAttrs: false,
|
|
49
|
-
props: {
|
|
50
|
-
modelValue: { type: null as unknown as PropType<PinInputValue | null>, required: false },
|
|
51
|
-
defaultValue: { type: null as unknown as PropType<PinInputValue>, required: false },
|
|
52
|
-
placeholder: { type: String, required: false, default: '' },
|
|
53
|
-
mask: { type: Boolean, required: false },
|
|
54
|
-
otp: { type: Boolean, required: false },
|
|
55
|
-
type: { type: null as unknown as PropType<PinInputType>, required: false, default: 'text' },
|
|
56
|
-
dir: { type: String as PropType<Direction>, required: false },
|
|
57
|
-
disabled: { type: Boolean, required: false },
|
|
58
|
-
id: { type: String, required: false },
|
|
59
|
-
asChild: { type: Boolean, required: false },
|
|
60
|
-
as: { type: null as unknown as PropType<PrimitiveProps['as']>, required: false },
|
|
61
|
-
name: { type: String, required: false },
|
|
62
|
-
required: { type: Boolean, required: false },
|
|
63
|
-
},
|
|
64
|
-
emits: ['update:modelValue', 'complete'],
|
|
65
|
-
setup(props, { emit, attrs, slots }) {
|
|
66
|
-
const { mask, otp, placeholder, type, disabled, dir: propDir } = toRefs(props)
|
|
67
|
-
const { forwardRef } = useForwardExpose()
|
|
68
|
-
const dir = useDirection(propDir)
|
|
69
|
-
const modelValue = useVModel(
|
|
70
|
-
props,
|
|
71
|
-
'modelValue',
|
|
72
|
-
(_, value) => emit('update:modelValue', value as PinInputValue),
|
|
73
|
-
{ defaultValue: props.defaultValue ?? [], passive: true },
|
|
74
|
-
)
|
|
75
|
-
const currentModelValue = computed(() => pinInputValues(modelValue.value))
|
|
76
|
-
const inputElements = ref(new Set<HTMLInputElement>())
|
|
77
|
-
function onInputElementChange(element: HTMLInputElement) {
|
|
78
|
-
inputElements.value.add(element)
|
|
79
|
-
}
|
|
80
|
-
const isNumericMode = computed(() => props.type === 'number')
|
|
81
|
-
const isCompleted = computed(() =>
|
|
82
|
-
isPinInputComplete(currentModelValue.value, inputElements.value.size, isNumericMode.value),
|
|
83
|
-
)
|
|
84
|
-
watch(
|
|
85
|
-
modelValue,
|
|
86
|
-
() => {
|
|
87
|
-
if (isCompleted.value) emit('complete', modelValue.value as PinInputValue)
|
|
88
|
-
},
|
|
89
|
-
{ deep: true },
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
providePinInputRootContext({
|
|
93
|
-
modelValue: modelValue as never,
|
|
94
|
-
currentModelValue,
|
|
95
|
-
mask,
|
|
96
|
-
otp,
|
|
97
|
-
placeholder,
|
|
98
|
-
type,
|
|
99
|
-
dir,
|
|
100
|
-
disabled,
|
|
101
|
-
isCompleted,
|
|
102
|
-
inputElements: inputElements as never,
|
|
103
|
-
onInputElementChange,
|
|
104
|
-
isNumericMode,
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
const onFocus = () => Array.from(inputElements.value)?.[0]?.focus()
|
|
108
|
-
|
|
109
|
-
return () =>
|
|
110
|
-
h(
|
|
111
|
-
Primitive,
|
|
112
|
-
mergeProps(attrs, {
|
|
113
|
-
ref: forwardRef,
|
|
114
|
-
dir: dir.value,
|
|
115
|
-
'data-complete': isCompleted.value ? '' : undefined,
|
|
116
|
-
'data-disabled': disabled.value ? '' : undefined,
|
|
117
|
-
}),
|
|
118
|
-
{
|
|
119
|
-
default: withCtx(() => [
|
|
120
|
-
renderSlot(slots, 'default', { modelValue: modelValue.value }),
|
|
121
|
-
h(VisuallyHiddenInput, {
|
|
122
|
-
id: props.id,
|
|
123
|
-
as: 'input',
|
|
124
|
-
feature: 'focusable',
|
|
125
|
-
tabindex: '-1',
|
|
126
|
-
value: currentModelValue.value.join(''),
|
|
127
|
-
name: props.name ?? '',
|
|
128
|
-
disabled: disabled.value,
|
|
129
|
-
required: props.required,
|
|
130
|
-
onFocus,
|
|
131
|
-
}),
|
|
132
|
-
]),
|
|
133
|
-
},
|
|
134
|
-
)
|
|
135
|
-
},
|
|
136
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ComputedRef, Ref } from 'vue'
|
|
2
|
-
import type { PinInputValue } from '../../../../shared/src/primitives/pin-input'
|
|
3
|
-
import { createContext } from '../utils/createContext'
|
|
4
|
-
import type { Direction } from '../utils/useDirection'
|
|
5
|
-
|
|
6
|
-
export type PinInputType = 'text' | 'number'
|
|
7
|
-
|
|
8
|
-
export interface PinInputRootContext {
|
|
9
|
-
modelValue: Ref<PinInputValue>
|
|
10
|
-
currentModelValue: ComputedRef<PinInputValue>
|
|
11
|
-
mask: Ref<boolean>
|
|
12
|
-
otp: Ref<boolean>
|
|
13
|
-
placeholder: Ref<string>
|
|
14
|
-
type: Ref<PinInputType>
|
|
15
|
-
dir: Ref<Direction>
|
|
16
|
-
disabled: Ref<boolean>
|
|
17
|
-
isCompleted: ComputedRef<boolean>
|
|
18
|
-
inputElements?: Ref<Set<HTMLInputElement>>
|
|
19
|
-
onInputElementChange: (element: HTMLInputElement) => void
|
|
20
|
-
isNumericMode: ComputedRef<boolean>
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const [injectPinInputRootContext, providePinInputRootContext] =
|
|
24
|
-
createContext<PinInputRootContext>('PinInputRoot')
|