inertia-bootstrap-forms 4.0.3 → 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 +1298 -1139
- package/dist/style.css +1 -1
- package/index.d.ts +5 -1
- package/package.json +1 -1
- package/src/CheckboxToggle.vue +5 -0
- package/src/CreditCardInput.vue +106 -0
- package/src/ShebaInput.vue +125 -0
- package/src/index.js +7 -1
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.voice-recorder-box audio,.voice-recorder-results audio{vertical-align:middle}.voice-recorder-box{display:block;background-color:var(--bg-1);border-radius:var(--border-radius);border:2px dashed var(--border-color)}
|
|
1
|
+
.form-field.is-invalid{border-color:var(--danger-border)}.voice-recorder-box audio,.voice-recorder-results audio{vertical-align:middle}.voice-recorder-box{display:block;background-color:var(--bg-1);border-radius:var(--border-radius);border:2px dashed var(--border-color)}
|
package/index.d.ts
CHANGED
|
@@ -68,6 +68,10 @@ export declare const CheckboxInput: FieldComponent<{ type?: 'checkbox' | 'radio'
|
|
|
68
68
|
export declare const SwitchInput: FieldComponent<{ value?: any; trueValue?: any; falseValue?: any; checked?: boolean; label?: string | null }>;
|
|
69
69
|
export declare const CheckboxButtonInput: FieldComponent<{ type?: 'checkbox' | 'radio'; value?: any; trueValue?: any; falseValue?: any; checked?: boolean; variant?: string; theme?: string }>;
|
|
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
|
+
export declare const ShebaInput: FieldComponent<{ placeholder?: string | null; prefix?: boolean; size?: 'sm' | 'lg' | null; inputClass?: string | string[] | Record<string, boolean> | null }>;
|
|
72
|
+
|
|
73
|
+
export declare const CreditCardInput: FieldComponent<{ placeholder?: string | null; size?: 'sm' | 'lg' | null; inputClass?: string | string[] | Record<string, boolean> | null }>;
|
|
74
|
+
|
|
71
75
|
export declare const VoiceRecorderInput: FieldComponent<{
|
|
72
76
|
variant?: 'box' | 'button';
|
|
73
77
|
url?: string;
|
|
@@ -160,4 +164,4 @@ export declare function useBsInstance(name: 'Combobox' | 'Chips' | 'OtpInput' |
|
|
|
160
164
|
export declare function toEnglishDigits(input: unknown): string;
|
|
161
165
|
|
|
162
166
|
declare const plugin: Plugin;
|
|
163
|
-
export default plugin;
|
|
167
|
+
export default plugin;
|
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",
|
package/src/CheckboxToggle.vue
CHANGED
|
@@ -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>
|
|
@@ -0,0 +1,125 @@
|
|
|
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 = 24;
|
|
7
|
+
|
|
8
|
+
/** Removes a leading "IR", spaces, dashes and any non-digit; Persian/Arabic digits are converted. */
|
|
9
|
+
export function cleanSheba(input) {
|
|
10
|
+
return toEnglishDigits(input)
|
|
11
|
+
.replace(/^\s*ir/i, '')
|
|
12
|
+
.replace(/\D/g, '')
|
|
13
|
+
.slice(0, MAX_DIGITS);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** 062960000000100324200001 -> "IR06 2960 0000 0010 0324 2000 01" */
|
|
17
|
+
export function formatSheba(digits, prefix = true) {
|
|
18
|
+
if (!digits) return '';
|
|
19
|
+
const groups = [digits.slice(0, 2), ...(digits.slice(2).match(/.{1,4}/g) ?? [])];
|
|
20
|
+
if (prefix) groups[0] = `${groups[0]}`;
|
|
21
|
+
return groups.join(' ');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* IBAN (Sheba) input. The user sees "IR06 2960 0000 …", the form value is the digits only
|
|
26
|
+
* (without "IR", spaces or dashes). The value is a string: 24 digits do not fit into a JS number
|
|
27
|
+
* without losing precision, and a leading zero must be kept.
|
|
28
|
+
*/
|
|
29
|
+
export default defineComponent({
|
|
30
|
+
name: 'ShebaInput',
|
|
31
|
+
emits: ['update:modelValue', 'change', 'input', 'focus', 'blur'],
|
|
32
|
+
props: {
|
|
33
|
+
...fieldProps,
|
|
34
|
+
placeholder: {type: String, default: null},
|
|
35
|
+
/** Show "IR" at the start of the formatted value. */
|
|
36
|
+
prefix: {type: Boolean, default: true},
|
|
37
|
+
inputClass: {type: [String, Array, Object], default: null},
|
|
38
|
+
size: {type: String, default: null},
|
|
39
|
+
},
|
|
40
|
+
setup(props, {emit}) {
|
|
41
|
+
const field = useField(props, emit);
|
|
42
|
+
|
|
43
|
+
const digits = computed(() => cleanSheba(field.model.value ?? ''));
|
|
44
|
+
const displayValue = computed(() => formatSheba(digits.value, props.prefix));
|
|
45
|
+
const sizeClass = computed(() => (props.size ? `form-control-${props.size}` : null));
|
|
46
|
+
const placeholderText = computed(
|
|
47
|
+
() => props.placeholder ?? formatSheba('000000000000000000000000', props.prefix)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
function caretFor(formatted, count) {
|
|
51
|
+
if (count === 0) return props.prefix && formatted ? 2 : 0;
|
|
52
|
+
let seen = 0;
|
|
53
|
+
for (let i = 0; i < formatted.length; i++) {
|
|
54
|
+
if (/\d/.test(formatted[i]) && ++seen === count) return i + 1;
|
|
55
|
+
}
|
|
56
|
+
return formatted.length;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function onInput(event) {
|
|
60
|
+
const el = event.target;
|
|
61
|
+
const caret = el.selectionStart ?? el.value.length;
|
|
62
|
+
const before = cleanSheba(el.value.slice(0, caret)).length;
|
|
63
|
+
|
|
64
|
+
const next = cleanSheba(el.value);
|
|
65
|
+
const formatted = formatSheba(next, props.prefix);
|
|
66
|
+
|
|
67
|
+
field.model.value = next;
|
|
68
|
+
el.value = formatted; // drop characters that were rejected
|
|
69
|
+
|
|
70
|
+
if (document.activeElement === el) {
|
|
71
|
+
const pos = caretFor(formatted, before);
|
|
72
|
+
nextTick(() => el.setSelectionRange(pos, pos));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
emit('input', next, event);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Backspace right after a space / dash would otherwise be swallowed by re-formatting
|
|
79
|
+
function onKeydown(event) {
|
|
80
|
+
if (event.key !== 'Backspace') return;
|
|
81
|
+
const el = event.target;
|
|
82
|
+
if (el.selectionStart !== el.selectionEnd) return;
|
|
83
|
+
const pos = el.selectionStart ?? 0;
|
|
84
|
+
if (pos > 0 && el.value[pos - 1] === ' ') el.setSelectionRange(pos - 1, pos - 1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onChange(event) {
|
|
88
|
+
field.emitChange(digits.value, event);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {...field, displayValue, sizeClass, placeholderText, onInput, onKeydown, onChange};
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<template>
|
|
97
|
+
<div class="input-group" dir="ltr">
|
|
98
|
+
<span class="input-group-text" :id="inputId + 'prefix'">
|
|
99
|
+
<slot>
|
|
100
|
+
IR
|
|
101
|
+
</slot>
|
|
102
|
+
</span>
|
|
103
|
+
<input
|
|
104
|
+
:name="name"
|
|
105
|
+
:id="inputId"
|
|
106
|
+
:value="displayValue"
|
|
107
|
+
:placeholder="placeholderText"
|
|
108
|
+
:required="required"
|
|
109
|
+
:readonly="readonly"
|
|
110
|
+
:disabled="isDisabled"
|
|
111
|
+
:aria-invalid="isInvalid || undefined"
|
|
112
|
+
type="text"
|
|
113
|
+
inputmode="numeric"
|
|
114
|
+
autocomplete="off"
|
|
115
|
+
dir="ltr"
|
|
116
|
+
class="form-control text-start"
|
|
117
|
+
:class="[sizeClass, inputClass, { 'is-invalid': isInvalid }]"
|
|
118
|
+
@input="onInput"
|
|
119
|
+
@keydown="onKeydown"
|
|
120
|
+
@change="onChange"
|
|
121
|
+
@focus="$emit('focus', $event)"
|
|
122
|
+
@blur="$emit('blur', $event)"
|
|
123
|
+
/>
|
|
124
|
+
</div>
|
|
125
|
+
</template>
|
package/src/index.js
CHANGED
|
@@ -2,6 +2,8 @@ import AmountInput from './AmountInput.vue';
|
|
|
2
2
|
import CaptchaInput from './CaptchaInput.vue';
|
|
3
3
|
import CheckboxButtonInput from './CheckboxButtonInput.vue';
|
|
4
4
|
import CheckboxInput from './CheckboxInput.vue';
|
|
5
|
+
import ShebaInput from './ShebaInput.vue';
|
|
6
|
+
import CreditCardInput from './CreditCardInput.vue';
|
|
5
7
|
import CheckboxToggle from './CheckboxToggle.vue';
|
|
6
8
|
import ChipsInput from './ChipsInput.vue';
|
|
7
9
|
import ComboboxInput from './ComboboxInput.vue';
|
|
@@ -37,6 +39,8 @@ const FormAdorn = FormAdornInput;
|
|
|
37
39
|
|
|
38
40
|
const components = {
|
|
39
41
|
AmountInput,
|
|
42
|
+
ShebaInput,
|
|
43
|
+
CreditCardInput,
|
|
40
44
|
CaptchaInput,
|
|
41
45
|
VoiceRecorderInput,
|
|
42
46
|
VoiceRecorderResultArea,
|
|
@@ -92,6 +96,8 @@ export {
|
|
|
92
96
|
VoiceRecorderResultArea,
|
|
93
97
|
CheckboxButtonInput,
|
|
94
98
|
CheckboxInput,
|
|
99
|
+
ShebaInput,
|
|
100
|
+
CreditCardInput,
|
|
95
101
|
CheckboxToggle,
|
|
96
102
|
ChipsInput,
|
|
97
103
|
ComboboxInput,
|
|
@@ -126,4 +132,4 @@ export { fieldProps, useField } from './composables/useField.js';
|
|
|
126
132
|
export { useFormApi } from './composables/useFormApi.js';
|
|
127
133
|
export { useDisposables } from './composables/useDisposables.js';
|
|
128
134
|
export { useBsInstance } from './composables/useBsInstance.js';
|
|
129
|
-
export { toEnglishDigits } from './utils/digits.js';
|
|
135
|
+
export { toEnglishDigits } from './utils/digits.js';
|