intelliwaketssveltekitv25 0.1.79 → 0.1.80
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/InputNumber.svelte
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
placeholder,
|
|
13
13
|
title,
|
|
14
14
|
onchange,
|
|
15
|
-
decimals
|
|
15
|
+
decimals,
|
|
16
|
+
decimalsMax,
|
|
16
17
|
min = null,
|
|
17
18
|
max = null,
|
|
18
19
|
readonly,
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
title?: string,
|
|
32
33
|
onchange?: (value: number | null) => void
|
|
33
34
|
decimals?: number
|
|
35
|
+
decimalsMax?: number
|
|
34
36
|
min?: number | null
|
|
35
37
|
max?: number | null
|
|
36
38
|
readonly?: boolean
|
|
@@ -44,15 +46,17 @@
|
|
|
44
46
|
let displayValue = $state('')
|
|
45
47
|
let isFocused = $state(false)
|
|
46
48
|
let displayMultiplier = $derived(shiftDigits === 0 ? 1 : shiftDigits > 0 ? CleanNumber(`1${'0'.repeat(shiftDigits)}`) : CleanNumber(`.${'0'.repeat(Math.abs(shiftDigits) + 1)}1`))
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
$inspect('useDecimals', useDecimals)
|
|
49
|
+
let constrainDecimals = $derived(decimalsMax ?? decimals ?? 0)
|
|
50
|
+
let useDecimals = $derived(!shiftDigits ? constrainDecimals : CleanNumbers(0, constrainDecimals, shiftDigits))
|
|
50
51
|
|
|
51
52
|
function refreshDisplayValue(useValue: number | null) {
|
|
52
53
|
if (!isFocused) {
|
|
53
54
|
tick()
|
|
54
55
|
.then(() => {
|
|
55
|
-
let newDisplayValue = useValue != null ? CleanNumber(useValue * displayMultiplier,
|
|
56
|
+
let newDisplayValue = useValue != null ? CleanNumber(useValue * displayMultiplier, constrainDecimals).toFixed(constrainDecimals) : !!required ? '0' : ''
|
|
57
|
+
if (!!decimalsMax && newDisplayValue.includes('.')) {
|
|
58
|
+
newDisplayValue = newDisplayValue.replace(/\.?0+$/, '')
|
|
59
|
+
}
|
|
56
60
|
|
|
57
61
|
if (displayValue !== newDisplayValue) {
|
|
58
62
|
displayValue = newDisplayValue
|
|
@@ -69,7 +73,7 @@
|
|
|
69
73
|
|
|
70
74
|
const cleanValue = newValue.replace(/[^\d.]/g, '')
|
|
71
75
|
|
|
72
|
-
let numericValue = CleanNumberNull(cleanValue,
|
|
76
|
+
let numericValue = CleanNumberNull(cleanValue, constrainDecimals)
|
|
73
77
|
if (numericValue === null) {
|
|
74
78
|
value = !!required ? 0 : null
|
|
75
79
|
if (onchange) onchange(numericValue)
|
|
@@ -92,8 +96,8 @@
|
|
|
92
96
|
<div class="inputAddOn relative overflow-hidden h-fit {clazz}">
|
|
93
97
|
<input
|
|
94
98
|
type="text"
|
|
95
|
-
inputmode={!!
|
|
96
|
-
pattern={!!
|
|
99
|
+
inputmode={!!constrainDecimals ? "decimal" : "numeric"}
|
|
100
|
+
pattern={!!constrainDecimals ? "[0-9]*[.,]?[0-9]+" : "[0-9]*"}
|
|
97
101
|
class="text-right {inputClass}"
|
|
98
102
|
style={inputStyle}
|
|
99
103
|
{id}
|
|
@@ -105,7 +109,7 @@
|
|
|
105
109
|
{required}
|
|
106
110
|
value={displayValue}
|
|
107
111
|
oninput={handleInput}
|
|
108
|
-
onkeydown={e => HandleKeyDownNumerics(e, !!
|
|
112
|
+
onkeydown={e => HandleKeyDownNumerics(e, !!constrainDecimals)}
|
|
109
113
|
onblur={() => refreshDisplayValue(value)}
|
|
110
114
|
bind:focused={isFocused}
|
|
111
115
|
/>
|