inertia-bootstrap-forms 4.0.2 → 4.0.4
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 +1138 -1049
- package/dist/style.css +1 -1
- package/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/CheckboxToggle.vue +5 -0
- package/src/ShebaInput.vue +125 -0
- package/src/VoiceRecorderInput.vue +0 -4
- package/src/VoiceRecorderResultArea.vue +7 -0
- package/src/index.js +2 -0
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.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,8 @@ 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
|
+
|
|
71
73
|
export declare const VoiceRecorderInput: FieldComponent<{
|
|
72
74
|
variant?: 'box' | 'button';
|
|
73
75
|
url?: string;
|
|
@@ -160,4 +162,4 @@ export declare function useBsInstance(name: 'Combobox' | 'Chips' | 'OtpInput' |
|
|
|
160
162
|
export declare function toEnglishDigits(input: unknown): string;
|
|
161
163
|
|
|
162
164
|
declare const plugin: Plugin;
|
|
163
|
-
export default plugin;
|
|
165
|
+
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.4",
|
|
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,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>
|
|
@@ -57,6 +57,7 @@ export default defineComponent({
|
|
|
57
57
|
ref="root"
|
|
58
58
|
class="voice-recorder-results"
|
|
59
59
|
>
|
|
60
|
+
<slot />
|
|
60
61
|
<div v-if="showProblem && channel.problem" :class="alertClass" role="alert" :data-code="channel.problem.code">
|
|
61
62
|
{{ channel.problem.message }}
|
|
62
63
|
</div>
|
|
@@ -107,3 +108,9 @@ export default defineComponent({
|
|
|
107
108
|
</ul>
|
|
108
109
|
</div>
|
|
109
110
|
</template>
|
|
111
|
+
<style>
|
|
112
|
+
.voice-recorder-box audio,
|
|
113
|
+
.voice-recorder-results audio{
|
|
114
|
+
vertical-align: middle;
|
|
115
|
+
}
|
|
116
|
+
</style>
|
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ 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';
|
|
5
6
|
import CheckboxToggle from './CheckboxToggle.vue';
|
|
6
7
|
import ChipsInput from './ChipsInput.vue';
|
|
7
8
|
import ComboboxInput from './ComboboxInput.vue';
|
|
@@ -92,6 +93,7 @@ export {
|
|
|
92
93
|
VoiceRecorderResultArea,
|
|
93
94
|
CheckboxButtonInput,
|
|
94
95
|
CheckboxInput,
|
|
96
|
+
ShebaInput,
|
|
95
97
|
CheckboxToggle,
|
|
96
98
|
ChipsInput,
|
|
97
99
|
ComboboxInput,
|