@hashrytech/quick-components-kit 0.19.14 → 0.19.16
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/CHANGELOG.md +12 -0
- package/dist/components/text-input/TextInput.svelte +32 -1
- package/dist/components/text-input/TextInput.svelte.d.ts +3 -1
- package/dist/functions/click-outside.d.ts +22 -0
- package/dist/functions/click-outside.js +38 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -51,8 +51,10 @@
|
|
|
51
51
|
inputmode?: InputMode;
|
|
52
52
|
min?: number;
|
|
53
53
|
max?: number;
|
|
54
|
+
step?: number;
|
|
54
55
|
debounceDelay?: number;
|
|
55
|
-
|
|
56
|
+
forcePositiveNumber?: boolean;
|
|
57
|
+
onInput?: (value: string|number|null) => void;
|
|
56
58
|
onchange?: (event: Event) => void;
|
|
57
59
|
onmouseup?: () => void;
|
|
58
60
|
label?: Snippet;
|
|
@@ -88,7 +90,9 @@
|
|
|
88
90
|
inputmode,
|
|
89
91
|
min,
|
|
90
92
|
max,
|
|
93
|
+
step,
|
|
91
94
|
debounceDelay=300, //ms
|
|
95
|
+
forcePositiveNumber=false,
|
|
92
96
|
onchange,
|
|
93
97
|
onInput,
|
|
94
98
|
onmouseup,
|
|
@@ -128,6 +132,11 @@
|
|
|
128
132
|
|
|
129
133
|
function handleInput(e: Event) {
|
|
130
134
|
localValue = (e.target as HTMLInputElement).value;
|
|
135
|
+
if (forcePositiveNumber) {
|
|
136
|
+
localValue = sanitizePositiveNumber(localValue);
|
|
137
|
+
(e.target as HTMLInputElement).value = localValue; // reflect sanitized value in the UI
|
|
138
|
+
}
|
|
139
|
+
|
|
131
140
|
clearTimeout(debounceTimer);
|
|
132
141
|
debounceTimer = setTimeout(() => {
|
|
133
142
|
value = localValue; // sync to bound value after delay
|
|
@@ -135,6 +144,28 @@
|
|
|
135
144
|
}, debounceDelay);
|
|
136
145
|
}
|
|
137
146
|
|
|
147
|
+
function sanitizePositiveNumber(value: string | number | null): string {
|
|
148
|
+
// Handle null, undefined, or empty string
|
|
149
|
+
if (value === null || value === undefined || value === "") {
|
|
150
|
+
return "1";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Convert to string and strip non-digits
|
|
154
|
+
let v = value.toString().replace(/[^0-9]/g, "") || "1";
|
|
155
|
+
|
|
156
|
+
// Convert to number
|
|
157
|
+
let num = parseInt(v, 10);
|
|
158
|
+
|
|
159
|
+
// If NaN, zero, or negative → force to 1
|
|
160
|
+
if (isNaN(num) || num <= 0) {
|
|
161
|
+
return "1";
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Return normalized positive integer as string
|
|
165
|
+
return String(num);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
138
169
|
</script>
|
|
139
170
|
|
|
140
171
|
<div class={twMerge("", firstDivClass)}>
|
|
@@ -48,8 +48,10 @@ export type TextInputProps = {
|
|
|
48
48
|
inputmode?: InputMode;
|
|
49
49
|
min?: number;
|
|
50
50
|
max?: number;
|
|
51
|
+
step?: number;
|
|
51
52
|
debounceDelay?: number;
|
|
52
|
-
|
|
53
|
+
forcePositiveNumber?: boolean;
|
|
54
|
+
onInput?: (value: string | number | null) => void;
|
|
53
55
|
onchange?: (event: Event) => void;
|
|
54
56
|
onmouseup?: () => void;
|
|
55
57
|
label?: Snippet;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type ClickOutsideEvent = MouseEvent | TouchEvent | PointerEvent;
|
|
2
|
+
export interface ClickOutsideOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Function to call when clicking outside
|
|
5
|
+
*/
|
|
6
|
+
callback: (event: ClickOutsideEvent) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Array of element IDs to ignore
|
|
9
|
+
*/
|
|
10
|
+
ignoreIds?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Whether the action is enabled
|
|
13
|
+
*/
|
|
14
|
+
enabled?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Triggers callback when clicking outside the element.
|
|
18
|
+
*/
|
|
19
|
+
export declare function clickOutside(node: HTMLElement, options: ClickOutsideOptions): {
|
|
20
|
+
update(options: ClickOutsideOptions): void;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Triggers callback when clicking outside the element.
|
|
3
|
+
*/
|
|
4
|
+
export function clickOutside(node, options) {
|
|
5
|
+
let { callback, ignoreIds = [], enabled = true } = options;
|
|
6
|
+
const handleClick = (event) => {
|
|
7
|
+
if (!enabled)
|
|
8
|
+
return;
|
|
9
|
+
const target = event.target;
|
|
10
|
+
if (!target)
|
|
11
|
+
return;
|
|
12
|
+
// Click inside the node → ignore
|
|
13
|
+
if (node.contains(target))
|
|
14
|
+
return;
|
|
15
|
+
// Click is on an ignored element or one of its parents → ignore
|
|
16
|
+
if (ignoreIds.length > 0) {
|
|
17
|
+
let element = target;
|
|
18
|
+
while (element) {
|
|
19
|
+
if (element.id && ignoreIds.includes(element.id)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
element = element.parentElement;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Click is outside and not on ignored element
|
|
26
|
+
callback(event);
|
|
27
|
+
};
|
|
28
|
+
// Attach listener
|
|
29
|
+
document.addEventListener('click', handleClick, true);
|
|
30
|
+
return {
|
|
31
|
+
update(newOptions) {
|
|
32
|
+
({ callback, ignoreIds = [], enabled = true } = newOptions);
|
|
33
|
+
},
|
|
34
|
+
destroy() {
|
|
35
|
+
document.removeEventListener('click', handleClick, true);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export * from './modules/crypto.js';
|
|
|
25
25
|
export * from './modules/problem-details.js';
|
|
26
26
|
export * from './functions/object-to-form-data.js';
|
|
27
27
|
export * from './functions/compare-objects.js';
|
|
28
|
+
export * from './functions/click-outside.js';
|
|
28
29
|
export * from './ui/headers/header-1/index.js';
|
|
29
30
|
export * from './ui/footers/footer-1/index.js';
|
|
30
31
|
export * from './ui/banners/banner-1/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Reexport your entry components here
|
|
2
1
|
// lib/index.js
|
|
3
2
|
export * from './components/icon/index.js';
|
|
4
3
|
export * from './components/text-input/index.js';
|
|
@@ -15,18 +14,23 @@ export * from './components/checkbox/index.js';
|
|
|
15
14
|
export * from './components/tab-navigation/index.js';
|
|
16
15
|
export * from './components/portal/index.js';
|
|
17
16
|
export * from './components/table/index.js';
|
|
17
|
+
// Actions
|
|
18
18
|
export * from './actions/disable-scroll.js';
|
|
19
19
|
export * from './actions/on-keydown.js';
|
|
20
20
|
export * from './actions/lock-scroll.js';
|
|
21
21
|
export * from './actions/scroll-to.js';
|
|
22
22
|
export * from './actions/stop-interaction.js';
|
|
23
23
|
export * from './actions/portal.js';
|
|
24
|
+
// Modules
|
|
24
25
|
export * from './modules/fetch-client.js';
|
|
25
26
|
export * from './modules/api-proxy.js';
|
|
26
27
|
export * from './modules/crypto.js';
|
|
27
28
|
export * from './modules/problem-details.js';
|
|
29
|
+
// Functions
|
|
28
30
|
export * from './functions/object-to-form-data.js';
|
|
29
31
|
export * from './functions/compare-objects.js';
|
|
32
|
+
export * from './functions/click-outside.js';
|
|
33
|
+
// UI Components
|
|
30
34
|
export * from './ui/headers/header-1/index.js';
|
|
31
35
|
export * from './ui/footers/footer-1/index.js';
|
|
32
36
|
export * from './ui/banners/banner-1/index.js';
|