intelliwaketssveltekitv25 0.1.119 → 0.1.120

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.
@@ -1,3 +1,4 @@
1
+ import { type TNumberStringOptions } from '@solidbasisventures/intelliwaketsfoundation';
1
2
  import type { HTMLInputAttributes } from 'svelte/elements';
2
3
  import type { ActionArray } from './useActions';
3
4
  export declare const KEY_UP_ARROW = 38;
@@ -205,14 +206,7 @@ export type TInputNumberAttributes = Omit<HTMLInputAttributes, 'value' | 'this'
205
206
  value: number | null;
206
207
  onchange?: (value: number | null) => void;
207
208
  inputClass?: string;
208
- decimals?: number;
209
- decimalsMax?: number;
210
- min?: number | null;
211
- max?: number | null;
212
- prefix?: string;
213
- suffix?: string;
214
- shiftDigits?: number;
215
209
  allowNegative?: boolean;
216
210
  use?: ActionArray;
217
211
  thisRef?: HTMLInputElement;
218
- };
212
+ } & TNumberStringOptions;
@@ -3,8 +3,7 @@
3
3
  CleanNumber,
4
4
  CleanNumberNull,
5
5
  CleanNumbers,
6
- ToDigits,
7
- ToDigitsMax
6
+ ToNumberString
8
7
  } from '@solidbasisventures/intelliwaketsfoundation'
9
8
  import { tick } from 'svelte'
10
9
  import { HandleKeyDownNumerics, type TInputNumberAttributes } from './Functions'
@@ -15,14 +14,18 @@
15
14
  class: clazz = '',
16
15
  inputClass = '',
17
16
  onchange,
18
- decimals,
19
- decimalsMax,
20
- min = null,
21
- max = null,
17
+ currency,
18
+ percent,
19
+ fixedDecimals,
20
+ minDecimals,
21
+ maxDecimals,
22
+ zeroBlank,
23
+ zeroDash,
24
+ nullBlank,
25
+ nullDash,
22
26
  prefix,
23
27
  suffix,
24
28
  allowNegative,
25
- shiftDigits = 0,
26
29
  use = [],
27
30
  thisRef = $bindable<HTMLInputElement>(),
28
31
  ...otherProps
@@ -30,10 +33,13 @@
30
33
 
31
34
  let displayValue = $state('')
32
35
  let isFocused = $state(false)
36
+ let shiftDigits = $derived(!!percent ? 2 : 0)
33
37
  let displayMultiplier = $derived(shiftDigits === 0 ? 1 : shiftDigits > 0 ? CleanNumber(`1${'0'.repeat(shiftDigits)}`) : CleanNumber(`.${'0'.repeat(Math.abs(shiftDigits) + 1)}1`))
34
- let constrainDecimals = $derived(decimalsMax ?? decimals ?? 0)
38
+ let constrainDecimals = $derived(fixedDecimals ?? maxDecimals ?? minDecimals ?? (currency ? 2 : 0))
35
39
  let useDecimals = $derived(!shiftDigits ? constrainDecimals : CleanNumbers(0, constrainDecimals, shiftDigits))
36
40
  let plainTextMode = $derived(!!otherProps.readonly || !!otherProps.disabled)
41
+ let usePrefix = $derived(prefix ?? (currency ? '$' : ''))
42
+ let useSuffix = $derived(suffix ?? (percent ? '%' : ''))
37
43
 
38
44
  function refreshDisplayValue(useValue: number | null) {
39
45
  if (!isFocused) {
@@ -44,18 +50,17 @@
44
50
  newDisplayValue = !!otherProps.required ? '0' : ''
45
51
  } else {
46
52
  const workingValue = useValue * displayMultiplier
47
- if (decimalsMax) {
48
- newDisplayValue = ToDigitsMax(workingValue, decimalsMax, decimals)
49
- } else if (decimals) {
50
- newDisplayValue = ToDigits(workingValue, decimals)
51
- } else {
52
- newDisplayValue = ToDigits(workingValue)
53
- }
54
- }
55
-
56
- if (plainTextMode) {
57
- if (prefix) newDisplayValue = `${prefix} ${newDisplayValue}`
58
- if (suffix) newDisplayValue = `${newDisplayValue} ${suffix}`
53
+ newDisplayValue = ToNumberString(workingValue, {
54
+ currency: !!plainTextMode && currency,
55
+ percent: !!plainTextMode && percent,
56
+ fixedDecimals,
57
+ minDecimals,
58
+ maxDecimals,
59
+ zeroBlank,
60
+ zeroDash,
61
+ nullBlank,
62
+ nullDash
63
+ })
59
64
  }
60
65
 
61
66
  if (displayValue !== newDisplayValue) {
@@ -79,16 +84,22 @@
79
84
  if (onchange) onchange(numericValue)
80
85
  } else if (!isNaN(numericValue)) {
81
86
  numericValue /= displayMultiplier
82
- if (min !== null) numericValue = Math.max(numericValue, min)
83
- if (max !== null) numericValue = Math.min(numericValue, max)
87
+
88
+ let maxAt = CleanNumberNull(fixedDecimals ?? minDecimals)
89
+ if (maxAt !== null) numericValue = Math.max(numericValue, maxAt)
90
+
91
+ let minAt = CleanNumberNull(fixedDecimals ?? maxAt)
92
+ if (minAt !== null) numericValue = Math.min(numericValue, minAt)
93
+
84
94
  value = CleanNumber(numericValue, useDecimals)
95
+
85
96
  if (onchange) onchange(numericValue)
86
97
  }
87
98
  }
88
99
 
89
100
  let inputStyle = $derived([
90
- !!prefix ? `padding-left: ${0.75 + (prefix.length * 0.5)}em;` : '',
91
- !!suffix ? `padding-right: ${0.75 + (suffix.length * 0.5)}em;` : ''
101
+ !!usePrefix ? `padding-left: ${0.75 + (usePrefix.length * 0.5)}em;` : '',
102
+ !!useSuffix ? `padding-right: ${0.75 + (useSuffix.length * 0.5)}em;` : ''
92
103
  ].join(' ').trim())
93
104
 
94
105
  // pattern={!!constrainDecimals ? "[0-9,]*[.,]?[0-9]+" : "[0-9,]*"}
@@ -119,11 +130,11 @@
119
130
  bind:this={thisRef}
120
131
  />
121
132
  {#if !plainTextMode}
122
- {#if prefix}
123
- <div class="absolute pointer-events-none left-1 top-1/2 -translate-y-1/2">{prefix}</div>
133
+ {#if usePrefix}
134
+ <div class="absolute pointer-events-none left-1 top-1/2 -translate-y-1/2">{usePrefix}</div>
124
135
  {/if}
125
- {#if suffix}
126
- <div class="absolute pointer-events-none right-1 top-1/2 -translate-y-1/2">{suffix}</div>
136
+ {#if useSuffix}
137
+ <div class="absolute pointer-events-none right-1 top-1/2 -translate-y-1/2">{useSuffix}</div>
127
138
  {/if}
128
139
  {/if}
129
140
  </div>
package/dist/index.d.ts CHANGED
@@ -11,8 +11,6 @@ import DropDownControl from './DropDownControl.svelte';
11
11
  import EllipsesTruncate from './EllipsesTruncate.svelte';
12
12
  import Icon from './Icon.svelte';
13
13
  import InputNumberScroll from './InputNumberScroll.svelte';
14
- import InputPercent from './InputPercent.svelte';
15
- import InputCurrency from './InputCurrency.svelte';
16
14
  import InputNumber from './InputNumber.svelte';
17
15
  import ListGroupItems from './ListGroupItems.svelte';
18
16
  import DisplayHTML from './DisplayHTML.svelte';
@@ -60,8 +58,6 @@ export { DropDownControl };
60
58
  export { EllipsesTruncate };
61
59
  export { Icon };
62
60
  export { InputNumberScroll };
63
- export { InputPercent };
64
- export { InputCurrency };
65
61
  export { InputNumber };
66
62
  export { ListGroupItems };
67
63
  export { MasterDetailLayout };
package/dist/index.js CHANGED
@@ -12,8 +12,6 @@ import DropDownControl from './DropDownControl.svelte';
12
12
  import EllipsesTruncate from './EllipsesTruncate.svelte';
13
13
  import Icon from './Icon.svelte';
14
14
  import InputNumberScroll from './InputNumberScroll.svelte';
15
- import InputPercent from './InputPercent.svelte';
16
- import InputCurrency from './InputCurrency.svelte';
17
15
  import InputNumber from './InputNumber.svelte';
18
16
  import ListGroupItems from './ListGroupItems.svelte';
19
17
  import DisplayHTML from './DisplayHTML.svelte';
@@ -61,8 +59,6 @@ export { DropDownControl };
61
59
  export { EllipsesTruncate };
62
60
  export { Icon };
63
61
  export { InputNumberScroll };
64
- export { InputPercent };
65
- export { InputCurrency };
66
62
  export { InputNumber };
67
63
  export { ListGroupItems };
68
64
  export { MasterDetailLayout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelliwaketssveltekitv25",
3
- "version": "0.1.119",
3
+ "version": "0.1.120",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "!dist/**/*.spec.*"
15
15
  ],
16
16
  "peerDependencies": {
17
- "@solidbasisventures/intelliwaketsfoundation": "^5.12.63",
17
+ "@solidbasisventures/intelliwaketsfoundation": "^5.12.64",
18
18
  "@sveltejs/kit": "^2.21.4",
19
19
  "svelte": "^5.33.19"
20
20
  },
@@ -1,19 +0,0 @@
1
- <script lang="ts">
2
- import InputNumber from './InputNumber.svelte'
3
- import type { TInputNumberAttributes } from './Functions'
4
-
5
- let {
6
- value = $bindable(),
7
- decimals = 2,
8
- thisRef = $bindable<HTMLInputElement>(),
9
- ...otherProps
10
- }: TInputNumberAttributes = $props()
11
-
12
- </script>
13
-
14
- <InputNumber bind:value
15
- bind:thisRef
16
- {decimals}
17
- {...otherProps}
18
- prefix="$"
19
- />
@@ -1,4 +0,0 @@
1
- import type { TInputNumberAttributes } from './Functions';
2
- declare const InputCurrency: import("svelte").Component<TInputNumberAttributes, {}, "value" | "thisRef">;
3
- type InputCurrency = ReturnType<typeof InputCurrency>;
4
- export default InputCurrency;
@@ -1,20 +0,0 @@
1
- <script lang="ts">
2
- import InputNumber from './InputNumber.svelte'
3
- import type { TInputNumberAttributes } from './Functions'
4
-
5
- let {
6
- value = $bindable(),
7
- decimals = 0,
8
- thisRef = $bindable<HTMLInputElement>(),
9
- ...otherProps
10
- }: TInputNumberAttributes = $props()
11
-
12
- </script>
13
-
14
- <InputNumber bind:value
15
- {decimals}
16
- bind:thisRef
17
- {...otherProps}
18
- shiftDigits={2}
19
- suffix="%"
20
- />
@@ -1,4 +0,0 @@
1
- import type { TInputNumberAttributes } from './Functions';
2
- declare const InputPercent: import("svelte").Component<TInputNumberAttributes, {}, "value" | "thisRef">;
3
- type InputPercent = ReturnType<typeof InputPercent>;
4
- export default InputPercent;