inertia-bootstrap-forms 4.0.4 → 4.0.5
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.cjs +1 -1
- package/dist/index.js +1041 -970
- package/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/CreditCardInput.vue +106 -0
- package/src/index.js +5 -1
package/index.d.ts
CHANGED
|
@@ -70,6 +70,8 @@ export declare const CheckboxButtonInput: FieldComponent<{ type?: 'checkbox' | '
|
|
|
70
70
|
export declare const CheckboxToggle: FieldComponent<{ type?: 'checkbox' | 'radio'; value?: any; trueValue?: any; falseValue?: any; checked?: boolean; hideInput?: boolean, formField?: boolean, formFieldCard?: boolean }>;
|
|
71
71
|
export declare const ShebaInput: FieldComponent<{ placeholder?: string | null; prefix?: boolean; size?: 'sm' | 'lg' | null; inputClass?: string | string[] | Record<string, boolean> | null }>;
|
|
72
72
|
|
|
73
|
+
export declare const CreditCardInput: FieldComponent<{ placeholder?: string | null; size?: 'sm' | 'lg' | null; inputClass?: string | string[] | Record<string, boolean> | null }>;
|
|
74
|
+
|
|
73
75
|
export declare const VoiceRecorderInput: FieldComponent<{
|
|
74
76
|
variant?: 'box' | 'button';
|
|
75
77
|
url?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inertia-bootstrap-forms",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "Bootstrap 6 form components for Vue 3 + Inertia.js (Laravel). Every field is bound to a single FormContainer v-model.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { computed, defineComponent, nextTick } from 'vue';
|
|
3
|
+
import { fieldProps, useField } from './composables/useField.js';
|
|
4
|
+
import { toEnglishDigits } from './utils/digits.js';
|
|
5
|
+
|
|
6
|
+
const MAX_DIGITS = 16;
|
|
7
|
+
|
|
8
|
+
/** Keeps digits only (Persian/Arabic digits are converted); spaces and dashes are removed. */
|
|
9
|
+
export function cleanCard(input) {
|
|
10
|
+
return toEnglishDigits(input).replace(/\D/g, '').slice(0, MAX_DIGITS);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** 6037991712345678 -> "6037 9917 1234 5678" */
|
|
14
|
+
export function formatCard(digits) {
|
|
15
|
+
return (digits.match(/.{1,4}/g) ?? []).join(' ');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 16-digit bank card number input. The user sees "6037 9917 1234 5678", the form value is the digits
|
|
20
|
+
* only. The value is a string: 16 digits can exceed Number.MAX_SAFE_INTEGER and a leading zero must be kept.
|
|
21
|
+
*/
|
|
22
|
+
export default defineComponent({
|
|
23
|
+
name: 'CreditCardInput',
|
|
24
|
+
emits: ['update:modelValue', 'change', 'input', 'focus', 'blur'],
|
|
25
|
+
props: {
|
|
26
|
+
...fieldProps,
|
|
27
|
+
placeholder: { type: String, default: null },
|
|
28
|
+
inputClass: { type: [String, Array, Object], default: null },
|
|
29
|
+
size: { type: String, default: null },
|
|
30
|
+
},
|
|
31
|
+
setup(props, { emit }) {
|
|
32
|
+
const field = useField(props, emit);
|
|
33
|
+
|
|
34
|
+
const digits = computed(() => cleanCard(field.model.value ?? ''));
|
|
35
|
+
const displayValue = computed(() => formatCard(digits.value));
|
|
36
|
+
const sizeClass = computed(() => (props.size ? `form-control-${props.size}` : null));
|
|
37
|
+
|
|
38
|
+
function caretFor(formatted, count) {
|
|
39
|
+
if (count === 0) return 0;
|
|
40
|
+
let seen = 0;
|
|
41
|
+
for (let i = 0; i < formatted.length; i++) {
|
|
42
|
+
if (/\d/.test(formatted[i]) && ++seen === count) return i + 1;
|
|
43
|
+
}
|
|
44
|
+
return formatted.length;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function onInput(event) {
|
|
48
|
+
const el = event.target;
|
|
49
|
+
const caret = el.selectionStart ?? el.value.length;
|
|
50
|
+
const before = cleanCard(el.value.slice(0, caret)).length;
|
|
51
|
+
|
|
52
|
+
const next = cleanCard(el.value);
|
|
53
|
+
const formatted = formatCard(next);
|
|
54
|
+
|
|
55
|
+
field.model.value = next;
|
|
56
|
+
el.value = formatted; // drop rejected characters
|
|
57
|
+
|
|
58
|
+
if (document.activeElement === el) {
|
|
59
|
+
const pos = caretFor(formatted, before);
|
|
60
|
+
nextTick(() => el.setSelectionRange(pos, pos));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
emit('input', next, event);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Backspace right after a space would otherwise be swallowed by re-formatting
|
|
67
|
+
function onKeydown(event) {
|
|
68
|
+
if (event.key !== 'Backspace') return;
|
|
69
|
+
const el = event.target;
|
|
70
|
+
if (el.selectionStart !== el.selectionEnd) return;
|
|
71
|
+
const pos = el.selectionStart ?? 0;
|
|
72
|
+
if (pos > 0 && el.value[pos - 1] === ' ') el.setSelectionRange(pos - 1, pos - 1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function onChange(event) {
|
|
76
|
+
field.emitChange(digits.value, event);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return { ...field, displayValue, sizeClass, onInput, onKeydown, onChange };
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
<input
|
|
86
|
+
:name="name"
|
|
87
|
+
:id="inputId"
|
|
88
|
+
:value="displayValue"
|
|
89
|
+
:placeholder="placeholder ?? '0000 0000 0000 0000'"
|
|
90
|
+
:required="required"
|
|
91
|
+
:readonly="readonly"
|
|
92
|
+
:disabled="isDisabled"
|
|
93
|
+
:aria-invalid="isInvalid || undefined"
|
|
94
|
+
type="text"
|
|
95
|
+
inputmode="numeric"
|
|
96
|
+
autocomplete="cc-number"
|
|
97
|
+
dir="ltr"
|
|
98
|
+
class="form-control text-start"
|
|
99
|
+
:class="[sizeClass, inputClass, { 'is-invalid': isInvalid }]"
|
|
100
|
+
@input="onInput"
|
|
101
|
+
@keydown="onKeydown"
|
|
102
|
+
@change="onChange"
|
|
103
|
+
@focus="$emit('focus', $event)"
|
|
104
|
+
@blur="$emit('blur', $event)"
|
|
105
|
+
/>
|
|
106
|
+
</template>
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import CaptchaInput from './CaptchaInput.vue';
|
|
|
3
3
|
import CheckboxButtonInput from './CheckboxButtonInput.vue';
|
|
4
4
|
import CheckboxInput from './CheckboxInput.vue';
|
|
5
5
|
import ShebaInput from './ShebaInput.vue';
|
|
6
|
+
import CreditCardInput from './CreditCardInput.vue';
|
|
6
7
|
import CheckboxToggle from './CheckboxToggle.vue';
|
|
7
8
|
import ChipsInput from './ChipsInput.vue';
|
|
8
9
|
import ComboboxInput from './ComboboxInput.vue';
|
|
@@ -38,6 +39,8 @@ const FormAdorn = FormAdornInput;
|
|
|
38
39
|
|
|
39
40
|
const components = {
|
|
40
41
|
AmountInput,
|
|
42
|
+
ShebaInput,
|
|
43
|
+
CreditCardInput,
|
|
41
44
|
CaptchaInput,
|
|
42
45
|
VoiceRecorderInput,
|
|
43
46
|
VoiceRecorderResultArea,
|
|
@@ -94,6 +97,7 @@ export {
|
|
|
94
97
|
CheckboxButtonInput,
|
|
95
98
|
CheckboxInput,
|
|
96
99
|
ShebaInput,
|
|
100
|
+
CreditCardInput,
|
|
97
101
|
CheckboxToggle,
|
|
98
102
|
ChipsInput,
|
|
99
103
|
ComboboxInput,
|
|
@@ -128,4 +132,4 @@ export { fieldProps, useField } from './composables/useField.js';
|
|
|
128
132
|
export { useFormApi } from './composables/useFormApi.js';
|
|
129
133
|
export { useDisposables } from './composables/useDisposables.js';
|
|
130
134
|
export { useBsInstance } from './composables/useBsInstance.js';
|
|
131
|
-
export { toEnglishDigits } from './utils/digits.js';
|
|
135
|
+
export { toEnglishDigits } from './utils/digits.js';
|