@juspay/svelte-ui-components 2.100.1 → 2.100.2
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.
|
@@ -15,11 +15,22 @@
|
|
|
15
15
|
|
|
16
16
|
let dragOver = $state(false);
|
|
17
17
|
let inputEl: HTMLInputElement | null = $state(null);
|
|
18
|
+
let pickerBusy = false;
|
|
18
19
|
|
|
19
20
|
export const openFilePicker = (): void => {
|
|
20
|
-
if (
|
|
21
|
-
|
|
21
|
+
if (disabled || pickerBusy) {
|
|
22
|
+
return;
|
|
22
23
|
}
|
|
24
|
+
// Idempotent within one click dispatch: if an inner trigger control wires
|
|
25
|
+
// openFilePicker AND the wrapper's own onclick fires for the same user click,
|
|
26
|
+
// the second call is a no-op (guarding against a double-open). Released on the
|
|
27
|
+
// next microtask — after the whole click has finished bubbling — so a genuinely
|
|
28
|
+
// separate later click still opens the picker.
|
|
29
|
+
pickerBusy = true;
|
|
30
|
+
inputEl?.click();
|
|
31
|
+
queueMicrotask(() => {
|
|
32
|
+
pickerBusy = false;
|
|
33
|
+
});
|
|
23
34
|
};
|
|
24
35
|
|
|
25
36
|
function isAccepted(file: File): boolean {
|
|
@@ -107,6 +118,20 @@
|
|
|
107
118
|
openFilePicker();
|
|
108
119
|
}
|
|
109
120
|
}
|
|
121
|
+
|
|
122
|
+
function handleClick(event: MouseEvent): void {
|
|
123
|
+
if (disabled) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
// openFilePicker() calls inputEl.click(), whose click bubbles back up to this
|
|
127
|
+
// wrapper — ignore it so we don't re-enter openFilePicker in a loop. Consumers
|
|
128
|
+
// whose trigger already wires openFilePicker on an inner control should NOT also
|
|
129
|
+
// rely on this handler (it would double-open); clicking the trigger is enough.
|
|
130
|
+
if (event.target === inputEl) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
openFilePicker();
|
|
134
|
+
}
|
|
110
135
|
</script>
|
|
111
136
|
|
|
112
137
|
<div
|
|
@@ -121,6 +146,7 @@
|
|
|
121
146
|
ondragleave={handleDragLeave}
|
|
122
147
|
ondrop={handleDrop}
|
|
123
148
|
onkeydown={handleKeyDown}
|
|
149
|
+
onclick={handleClick}
|
|
124
150
|
>
|
|
125
151
|
<input
|
|
126
152
|
bind:this={inputEl}
|