intelliwaketssveltekitv25 0.1.119 → 0.1.121

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;
@@ -201,18 +202,11 @@ export declare function IsMobileOrTablet(): boolean;
201
202
  */
202
203
  export declare function DownloadString(filename: string, text: string): void;
203
204
  export declare function HandleKeyDownNumerics(event: KeyboardEvent, allowDecimals?: boolean, allowNegative?: boolean): void;
204
- export type TInputNumberAttributes = Omit<HTMLInputAttributes, 'value' | 'this' | 'onchange' | 'min' | 'max' | 'use'> & {
205
+ export type TInputNumberAttributes = Omit<HTMLInputAttributes, 'value' | 'this' | 'onchange' | 'use'> & {
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,20 @@
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,
28
+ min,
29
+ max,
24
30
  allowNegative,
25
- shiftDigits = 0,
26
31
  use = [],
27
32
  thisRef = $bindable<HTMLInputElement>(),
28
33
  ...otherProps
@@ -30,10 +35,13 @@
30
35
 
31
36
  let displayValue = $state('')
32
37
  let isFocused = $state(false)
38
+ let shiftDigits = $derived(!!percent ? 2 : 0)
33
39
  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)
40
+ let constrainDecimals = $derived(fixedDecimals ?? maxDecimals ?? minDecimals ?? (currency ? 2 : 0))
35
41
  let useDecimals = $derived(!shiftDigits ? constrainDecimals : CleanNumbers(0, constrainDecimals, shiftDigits))
36
42
  let plainTextMode = $derived(!!otherProps.readonly || !!otherProps.disabled)
43
+ let usePrefix = $derived(prefix ?? (currency ? '$' : ''))
44
+ let useSuffix = $derived(suffix ?? (percent ? '%' : ''))
37
45
 
38
46
  function refreshDisplayValue(useValue: number | null) {
39
47
  if (!isFocused) {
@@ -44,18 +52,17 @@
44
52
  newDisplayValue = !!otherProps.required ? '0' : ''
45
53
  } else {
46
54
  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}`
55
+ newDisplayValue = ToNumberString(workingValue, {
56
+ currency: !!plainTextMode && currency,
57
+ percent: !!plainTextMode && percent,
58
+ fixedDecimals,
59
+ minDecimals,
60
+ maxDecimals,
61
+ zeroBlank,
62
+ zeroDash,
63
+ nullBlank,
64
+ nullDash
65
+ })
59
66
  }
60
67
 
61
68
  if (displayValue !== newDisplayValue) {
@@ -79,16 +86,19 @@
79
86
  if (onchange) onchange(numericValue)
80
87
  } else if (!isNaN(numericValue)) {
81
88
  numericValue /= displayMultiplier
82
- if (min !== null) numericValue = Math.max(numericValue, min)
83
- if (max !== null) numericValue = Math.min(numericValue, max)
89
+ const useMin = CleanNumberNull(min)
90
+ if (useMin !== null) numericValue = Math.max(numericValue, useMin)
91
+ const useMax = CleanNumberNull(max)
92
+ if (useMax !== null) numericValue = Math.min(numericValue, useMax)
84
93
  value = CleanNumber(numericValue, useDecimals)
94
+
85
95
  if (onchange) onchange(numericValue)
86
96
  }
87
97
  }
88
98
 
89
99
  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;` : ''
100
+ !!usePrefix ? `padding-left: ${0.75 + (usePrefix.length * 0.5)}em;` : '',
101
+ !!useSuffix ? `padding-right: ${0.75 + (useSuffix.length * 0.5)}em;` : ''
92
102
  ].join(' ').trim())
93
103
 
94
104
  // pattern={!!constrainDecimals ? "[0-9,]*[.,]?[0-9]+" : "[0-9,]*"}
@@ -119,11 +129,11 @@
119
129
  bind:this={thisRef}
120
130
  />
121
131
  {#if !plainTextMode}
122
- {#if prefix}
123
- <div class="absolute pointer-events-none left-1 top-1/2 -translate-y-1/2">{prefix}</div>
132
+ {#if usePrefix}
133
+ <div class="absolute pointer-events-none left-1 top-1/2 -translate-y-1/2">{usePrefix}</div>
124
134
  {/if}
125
- {#if suffix}
126
- <div class="absolute pointer-events-none right-1 top-1/2 -translate-y-1/2">{suffix}</div>
135
+ {#if useSuffix}
136
+ <div class="absolute pointer-events-none right-1 top-1/2 -translate-y-1/2">{useSuffix}</div>
127
137
  {/if}
128
138
  {/if}
129
139
  </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.121",
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;