intelliwaketssveltekitv25 0.1.78 → 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.
@@ -12,7 +12,8 @@
12
12
  placeholder,
13
13
  title,
14
14
  onchange,
15
- decimals = 0,
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 useDecimals = $derived(!shiftDigits ? decimals : CleanNumbers(0, decimals, shiftDigits))
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, decimals).toFixed(decimals) : !!required ? '0' : ''
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, decimals)
76
+ let numericValue = CleanNumberNull(cleanValue, constrainDecimals)
73
77
  if (numericValue === null) {
74
78
  value = !!required ? 0 : null
75
79
  if (onchange) onchange(numericValue)
@@ -89,11 +93,11 @@
89
93
 
90
94
  </script>
91
95
 
92
- <div class="inputAddOn relative overflow-hidden {clazz}">
96
+ <div class="inputAddOn relative overflow-hidden h-fit {clazz}">
93
97
  <input
94
98
  type="text"
95
- inputmode={!!decimals ? "decimal" : "numeric"}
96
- pattern={!!decimals ? "[0-9]*[.,]?[0-9]+" : "[0-9]*"}
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, !!decimals)}
112
+ onkeydown={e => HandleKeyDownNumerics(e, !!constrainDecimals)}
109
113
  onblur={() => refreshDisplayValue(value)}
110
114
  bind:focused={isFocused}
111
115
  />
@@ -8,6 +8,7 @@ type $$ComponentProps = {
8
8
  title?: string;
9
9
  onchange?: (value: number | null) => void;
10
10
  decimals?: number;
11
+ decimalsMax?: number;
11
12
  min?: number | null;
12
13
  max?: number | null;
13
14
  readonly?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelliwaketssveltekitv25",
3
- "version": "0.1.78",
3
+ "version": "0.1.80",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./dist/index.d.ts",