@targoninc/jess-components 0.0.30 → 0.0.31
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/dist/index.js +16 -10
- package/dist/src/Debounce.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -746,6 +746,18 @@ var InputType;
|
|
|
746
746
|
InputType2["week"] = "week";
|
|
747
747
|
})(InputType ||= {});
|
|
748
748
|
|
|
749
|
+
// src/src/Debounce.ts
|
|
750
|
+
var debounceMap = {};
|
|
751
|
+
function debounce(identifier, func, delay = 500) {
|
|
752
|
+
if (debounceMap[identifier]) {
|
|
753
|
+
clearTimeout(debounceMap[identifier]);
|
|
754
|
+
}
|
|
755
|
+
debounceMap[identifier] = setTimeout(() => {
|
|
756
|
+
func();
|
|
757
|
+
delete debounceMap[identifier];
|
|
758
|
+
}, delay);
|
|
759
|
+
}
|
|
760
|
+
|
|
749
761
|
// src/src/Components.ts
|
|
750
762
|
function getDisabledClass(config) {
|
|
751
763
|
let disabledClass;
|
|
@@ -772,19 +784,13 @@ function input(config) {
|
|
|
772
784
|
const toggleState = signal(false);
|
|
773
785
|
const configTypeSignal = config.type.constructor === Signal ? config.type : signal(config.type);
|
|
774
786
|
const actualType = compute((t) => t ? InputType.text : configTypeSignal.value, toggleState);
|
|
787
|
+
const inputId = v4_default();
|
|
775
788
|
let lastChange = 0;
|
|
776
|
-
let debounceTimeout;
|
|
777
789
|
function validate(newValue) {
|
|
778
790
|
errors.value = [];
|
|
779
791
|
if (config.debounce) {
|
|
780
792
|
if (Date.now() - lastChange < config.debounce) {
|
|
781
|
-
|
|
782
|
-
clearTimeout(debounceTimeout);
|
|
783
|
-
}
|
|
784
|
-
debounceTimeout = setTimeout(() => {
|
|
785
|
-
debounceTimeout = undefined;
|
|
786
|
-
validate(newValue);
|
|
787
|
-
}, config.debounce);
|
|
793
|
+
debounce(inputId, () => validate(newValue), config.debounce);
|
|
788
794
|
return;
|
|
789
795
|
}
|
|
790
796
|
}
|
|
@@ -813,7 +819,7 @@ function input(config) {
|
|
|
813
819
|
validate(e.target.value);
|
|
814
820
|
}
|
|
815
821
|
if (config.onchange) {
|
|
816
|
-
config.onchange(e.target.value);
|
|
822
|
+
debounce(inputId, () => config.onchange(e.target.value), config.debounce);
|
|
817
823
|
}
|
|
818
824
|
value.value = e.target.value;
|
|
819
825
|
}).onchange((e) => {
|
|
@@ -823,7 +829,7 @@ function input(config) {
|
|
|
823
829
|
validate(e.target.value);
|
|
824
830
|
}
|
|
825
831
|
if (config.onchange) {
|
|
826
|
-
config.onchange(e.target.value);
|
|
832
|
+
debounce(inputId, () => config.onchange(e.target.value), config.debounce);
|
|
827
833
|
}
|
|
828
834
|
value.value = e.target.value;
|
|
829
835
|
}).onkeydown(config.onkeydown ?? (() => {})).name(config.name).build(), when(isPassword, eyeButton(toggleState, () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debounce(identifier: any, func: () => void, delay?: number): void;
|