@ekz/react-utils 1.0.1 → 1.0.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.
Files changed (181) hide show
  1. package/lib/cjs/browser/index.d.ts +1 -0
  2. package/lib/cjs/browser/index.js +6 -0
  3. package/lib/cjs/browser/index.js.map +1 -0
  4. package/lib/cjs/browser/useWindowFocusDetection.d.ts +1 -0
  5. package/lib/cjs/browser/useWindowFocusDetection.js +17 -0
  6. package/lib/cjs/browser/useWindowFocusDetection.js.map +1 -0
  7. package/lib/cjs/effects/index.d.ts +3 -0
  8. package/lib/cjs/effects/index.js +10 -0
  9. package/lib/cjs/effects/index.js.map +1 -0
  10. package/lib/cjs/effects/useDebouncedEffect.d.ts +2 -0
  11. package/lib/cjs/effects/useDebouncedEffect.js +13 -0
  12. package/lib/cjs/effects/useDebouncedEffect.js.map +1 -0
  13. package/lib/cjs/effects/useEffectOnUpdate.d.ts +2 -0
  14. package/lib/cjs/effects/useEffectOnUpdate.js +16 -0
  15. package/lib/cjs/effects/useEffectOnUpdate.js.map +1 -0
  16. package/lib/cjs/effects/useRefresh.d.ts +3 -0
  17. package/lib/cjs/effects/useRefresh.js +11 -0
  18. package/lib/cjs/effects/useRefresh.js.map +1 -0
  19. package/lib/cjs/hooks/index.d.ts +1 -0
  20. package/lib/cjs/hooks/index.js +6 -0
  21. package/lib/cjs/hooks/index.js.map +1 -0
  22. package/lib/cjs/hooks/useToggle.d.ts +9 -0
  23. package/lib/cjs/hooks/useToggle.js +13 -0
  24. package/lib/cjs/hooks/useToggle.js.map +1 -0
  25. package/lib/cjs/index.d.ts +7 -0
  26. package/lib/cjs/index.js +11 -0
  27. package/lib/cjs/index.js.map +1 -0
  28. package/lib/cjs/storage/backends.d.ts +20 -0
  29. package/lib/cjs/storage/backends.js +32 -0
  30. package/lib/cjs/storage/backends.js.map +1 -0
  31. package/lib/cjs/storage/index.d.ts +18 -0
  32. package/lib/cjs/storage/index.js +37 -0
  33. package/lib/cjs/storage/index.js.map +1 -0
  34. package/lib/cjs/storage/services.d.ts +20 -0
  35. package/lib/cjs/storage/services.js +70 -0
  36. package/lib/cjs/storage/services.js.map +1 -0
  37. package/lib/cjs/time/datetime.d.ts +9 -0
  38. package/lib/cjs/time/datetime.js +19 -0
  39. package/lib/cjs/time/datetime.js.map +1 -0
  40. package/lib/cjs/time/index.d.ts +2 -0
  41. package/lib/cjs/time/index.js +8 -0
  42. package/lib/cjs/time/index.js.map +1 -0
  43. package/lib/cjs/time/useClock.d.ts +11 -0
  44. package/lib/cjs/time/useClock.js +23 -0
  45. package/lib/cjs/time/useClock.js.map +1 -0
  46. package/lib/cjs/timers/index.d.ts +2 -0
  47. package/lib/cjs/timers/index.js +9 -0
  48. package/lib/cjs/timers/index.js.map +1 -0
  49. package/lib/cjs/timers/useDebounce.d.ts +1 -0
  50. package/lib/cjs/timers/useDebounce.js +16 -0
  51. package/lib/cjs/timers/useDebounce.js.map +1 -0
  52. package/lib/cjs/timers/useTimer.d.ts +13 -0
  53. package/lib/cjs/timers/useTimer.js +44 -0
  54. package/lib/cjs/timers/useTimer.js.map +1 -0
  55. package/lib/cjs/ts/index.d.ts +1 -0
  56. package/lib/cjs/ts/index.js +6 -0
  57. package/lib/cjs/ts/index.js.map +1 -0
  58. package/lib/cjs/ts/unreachable.d.ts +1 -0
  59. package/lib/cjs/ts/unreachable.js +7 -0
  60. package/lib/cjs/ts/unreachable.js.map +1 -0
  61. package/lib/esm/browser/index.d.ts +1 -0
  62. package/lib/esm/browser/index.js +2 -0
  63. package/lib/esm/browser/index.js.map +1 -0
  64. package/lib/esm/browser/useWindowFocusDetection.d.ts +1 -0
  65. package/lib/esm/browser/useWindowFocusDetection.js +13 -0
  66. package/lib/esm/browser/useWindowFocusDetection.js.map +1 -0
  67. package/lib/esm/effects/index.d.ts +3 -0
  68. package/lib/esm/effects/index.js +4 -0
  69. package/lib/esm/effects/index.js.map +1 -0
  70. package/lib/esm/effects/useDebouncedEffect.d.ts +2 -0
  71. package/lib/esm/effects/useDebouncedEffect.js +9 -0
  72. package/lib/esm/effects/useDebouncedEffect.js.map +1 -0
  73. package/lib/esm/effects/useEffectOnUpdate.d.ts +2 -0
  74. package/lib/esm/effects/useEffectOnUpdate.js +12 -0
  75. package/lib/esm/effects/useEffectOnUpdate.js.map +1 -0
  76. package/lib/esm/effects/useRefresh.d.ts +3 -0
  77. package/lib/esm/effects/useRefresh.js +7 -0
  78. package/lib/esm/effects/useRefresh.js.map +1 -0
  79. package/lib/esm/hooks/index.d.ts +1 -0
  80. package/lib/esm/hooks/index.js +2 -0
  81. package/lib/esm/hooks/index.js.map +1 -0
  82. package/lib/esm/hooks/useToggle.d.ts +9 -0
  83. package/lib/esm/hooks/useToggle.js +9 -0
  84. package/lib/esm/hooks/useToggle.js.map +1 -0
  85. package/lib/esm/index.d.ts +7 -0
  86. package/lib/esm/index.js +8 -0
  87. package/lib/esm/index.js.map +1 -0
  88. package/lib/esm/storage/backends.d.ts +20 -0
  89. package/lib/esm/storage/backends.js +27 -0
  90. package/lib/esm/storage/backends.js.map +1 -0
  91. package/lib/esm/storage/index.d.ts +18 -0
  92. package/lib/esm/storage/index.js +30 -0
  93. package/lib/esm/storage/index.js.map +1 -0
  94. package/lib/esm/storage/services.d.ts +20 -0
  95. package/lib/esm/storage/services.js +64 -0
  96. package/lib/esm/storage/services.js.map +1 -0
  97. package/lib/esm/time/datetime.d.ts +9 -0
  98. package/lib/esm/time/datetime.js +16 -0
  99. package/lib/esm/time/datetime.js.map +1 -0
  100. package/lib/esm/time/index.d.ts +2 -0
  101. package/lib/esm/time/index.js +3 -0
  102. package/lib/esm/time/index.js.map +1 -0
  103. package/lib/esm/time/useClock.d.ts +11 -0
  104. package/lib/esm/time/useClock.js +18 -0
  105. package/lib/esm/time/useClock.js.map +1 -0
  106. package/lib/esm/timers/index.d.ts +2 -0
  107. package/lib/esm/timers/index.js +3 -0
  108. package/lib/esm/timers/index.js.map +1 -0
  109. package/lib/esm/timers/useDebounce.d.ts +1 -0
  110. package/lib/esm/timers/useDebounce.js +12 -0
  111. package/lib/esm/timers/useDebounce.js.map +1 -0
  112. package/lib/esm/timers/useTimer.d.ts +13 -0
  113. package/lib/esm/timers/useTimer.js +38 -0
  114. package/lib/esm/timers/useTimer.js.map +1 -0
  115. package/lib/esm/ts/index.d.ts +1 -0
  116. package/lib/esm/ts/index.js +2 -0
  117. package/lib/esm/ts/index.js.map +1 -0
  118. package/lib/esm/ts/unreachable.d.ts +1 -0
  119. package/lib/esm/ts/unreachable.js +4 -0
  120. package/lib/esm/ts/unreachable.js.map +1 -0
  121. package/lib/esnext/browser/index.d.ts +1 -0
  122. package/lib/esnext/browser/index.js +2 -0
  123. package/lib/esnext/browser/index.js.map +1 -0
  124. package/lib/esnext/browser/useWindowFocusDetection.d.ts +1 -0
  125. package/lib/esnext/browser/useWindowFocusDetection.js +13 -0
  126. package/lib/esnext/browser/useWindowFocusDetection.js.map +1 -0
  127. package/lib/esnext/effects/index.d.ts +3 -0
  128. package/lib/esnext/effects/index.js +4 -0
  129. package/lib/esnext/effects/index.js.map +1 -0
  130. package/lib/esnext/effects/useDebouncedEffect.d.ts +2 -0
  131. package/lib/esnext/effects/useDebouncedEffect.js +9 -0
  132. package/lib/esnext/effects/useDebouncedEffect.js.map +1 -0
  133. package/lib/esnext/effects/useEffectOnUpdate.d.ts +2 -0
  134. package/lib/esnext/effects/useEffectOnUpdate.js +12 -0
  135. package/lib/esnext/effects/useEffectOnUpdate.js.map +1 -0
  136. package/lib/esnext/effects/useRefresh.d.ts +3 -0
  137. package/lib/esnext/effects/useRefresh.js +7 -0
  138. package/lib/esnext/effects/useRefresh.js.map +1 -0
  139. package/lib/esnext/hooks/index.d.ts +1 -0
  140. package/lib/esnext/hooks/index.js +2 -0
  141. package/lib/esnext/hooks/index.js.map +1 -0
  142. package/lib/esnext/hooks/useToggle.d.ts +9 -0
  143. package/lib/esnext/hooks/useToggle.js +9 -0
  144. package/lib/esnext/hooks/useToggle.js.map +1 -0
  145. package/lib/esnext/index.d.ts +7 -0
  146. package/lib/esnext/index.js +8 -0
  147. package/lib/esnext/index.js.map +1 -0
  148. package/lib/esnext/storage/backends.d.ts +20 -0
  149. package/lib/esnext/storage/backends.js +22 -0
  150. package/lib/esnext/storage/backends.js.map +1 -0
  151. package/lib/esnext/storage/index.d.ts +18 -0
  152. package/lib/esnext/storage/index.js +30 -0
  153. package/lib/esnext/storage/index.js.map +1 -0
  154. package/lib/esnext/storage/services.d.ts +20 -0
  155. package/lib/esnext/storage/services.js +68 -0
  156. package/lib/esnext/storage/services.js.map +1 -0
  157. package/lib/esnext/time/datetime.d.ts +9 -0
  158. package/lib/esnext/time/datetime.js +16 -0
  159. package/lib/esnext/time/datetime.js.map +1 -0
  160. package/lib/esnext/time/index.d.ts +2 -0
  161. package/lib/esnext/time/index.js +3 -0
  162. package/lib/esnext/time/index.js.map +1 -0
  163. package/lib/esnext/time/useClock.d.ts +11 -0
  164. package/lib/esnext/time/useClock.js +18 -0
  165. package/lib/esnext/time/useClock.js.map +1 -0
  166. package/lib/esnext/timers/index.d.ts +2 -0
  167. package/lib/esnext/timers/index.js +3 -0
  168. package/lib/esnext/timers/index.js.map +1 -0
  169. package/lib/esnext/timers/useDebounce.d.ts +1 -0
  170. package/lib/esnext/timers/useDebounce.js +12 -0
  171. package/lib/esnext/timers/useDebounce.js.map +1 -0
  172. package/lib/esnext/timers/useTimer.d.ts +13 -0
  173. package/lib/esnext/timers/useTimer.js +38 -0
  174. package/lib/esnext/timers/useTimer.js.map +1 -0
  175. package/lib/esnext/ts/index.d.ts +1 -0
  176. package/lib/esnext/ts/index.js +2 -0
  177. package/lib/esnext/ts/index.js.map +1 -0
  178. package/lib/esnext/ts/unreachable.d.ts +1 -0
  179. package/lib/esnext/ts/unreachable.js +4 -0
  180. package/lib/esnext/ts/unreachable.js.map +1 -0
  181. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ export { useWindowFocusDetection } from './useWindowFocusDetection';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useWindowFocusDetection = void 0;
4
+ var useWindowFocusDetection_1 = require("./useWindowFocusDetection");
5
+ Object.defineProperty(exports, "useWindowFocusDetection", { enumerable: true, get: function () { return useWindowFocusDetection_1.useWindowFocusDetection; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/web/browser/index.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA"}
@@ -0,0 +1 @@
1
+ export declare function useWindowFocusDetection(): boolean;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useWindowFocusDetection = useWindowFocusDetection;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ function useWindowFocusDetection() {
7
+ const [isVisible, setVisible] = React.useState(!document.hidden);
8
+ const visibilityChangeHandler = React.useCallback(() => {
9
+ setVisible(!document.hidden);
10
+ }, []);
11
+ React.useEffect(() => {
12
+ document.addEventListener('visibilitychange', visibilityChangeHandler);
13
+ return () => document.removeEventListener('visibilitychange', visibilityChangeHandler);
14
+ }, [visibilityChangeHandler]);
15
+ return isVisible;
16
+ }
17
+ //# sourceMappingURL=useWindowFocusDetection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindowFocusDetection.js","sourceRoot":"","sources":["../../../src/main/web/browser/useWindowFocusDetection.ts"],"names":[],"mappings":";;AAEA,0DAaC;;AAfD,qDAA+B;AAE/B,SAAgB,uBAAuB;IACnC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEjE,MAAM,uBAAuB,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACnD,UAAU,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,uBAAuB,CAAC,CAAC;QACvE,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,uBAAuB,CAAC,CAAC;IAC3F,CAAC,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC;IAE9B,OAAO,SAAS,CAAC;AACrB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { useDebouncedEffect } from './useDebouncedEffect';
2
+ export { useEffectOnUpdate } from './useEffectOnUpdate';
3
+ export { useRefresh } from './useRefresh';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRefresh = exports.useEffectOnUpdate = exports.useDebouncedEffect = void 0;
4
+ var useDebouncedEffect_1 = require("./useDebouncedEffect");
5
+ Object.defineProperty(exports, "useDebouncedEffect", { enumerable: true, get: function () { return useDebouncedEffect_1.useDebouncedEffect; } });
6
+ var useEffectOnUpdate_1 = require("./useEffectOnUpdate");
7
+ Object.defineProperty(exports, "useEffectOnUpdate", { enumerable: true, get: function () { return useEffectOnUpdate_1.useEffectOnUpdate; } });
8
+ var useRefresh_1 = require("./useRefresh");
9
+ Object.defineProperty(exports, "useRefresh", { enumerable: true, get: function () { return useRefresh_1.useRefresh; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/web/effects/index.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAC1B,2CAA0C;AAAjC,wGAAA,UAAU,OAAA"}
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare function useDebouncedEffect(timeoutMs: number, effect: React.EffectCallback, dependencyList?: React.DependencyList): void;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDebouncedEffect = useDebouncedEffect;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ const timers_1 = require("../timers");
7
+ function useDebouncedEffect(timeoutMs, effect, dependencyList) {
8
+ const deps = dependencyList || [];
9
+ const timeout = (0, timers_1.useTimeout)(timeoutMs);
10
+ // eslint-disable-next-line react-hooks/exhaustive-deps
11
+ React.useEffect(() => timeout(effect), deps);
12
+ }
13
+ //# sourceMappingURL=useDebouncedEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebouncedEffect.js","sourceRoot":"","sources":["../../../src/main/web/effects/useDebouncedEffect.ts"],"names":[],"mappings":";;AAIA,gDASC;;AAbD,qDAA+B;AAE/B,sCAAuC;AAEvC,SAAgB,kBAAkB,CAC9B,SAAiB,EACjB,MAA4B,EAC5B,cAAqC;IAErC,MAAM,IAAI,GAAG,cAAc,IAAI,EAAE,CAAC;IAClC,MAAM,OAAO,GAAG,IAAA,mBAAU,EAAC,SAAS,CAAC,CAAC;IACtC,uDAAuD;IACvD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare function useEffectOnUpdate(effect: React.EffectCallback, deps?: React.DependencyList): void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useEffectOnUpdate = useEffectOnUpdate;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ function useEffectOnUpdate(effect, deps) {
7
+ const hasMounted = React.useRef(false);
8
+ React.useEffect(() => {
9
+ if (hasMounted.current) {
10
+ return effect();
11
+ }
12
+ hasMounted.current = true;
13
+ // eslint-disable-next-line react-hooks/exhaustive-deps
14
+ }, deps);
15
+ }
16
+ //# sourceMappingURL=useEffectOnUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEffectOnUpdate.js","sourceRoot":"","sources":["../../../src/main/web/effects/useEffectOnUpdate.ts"],"names":[],"mappings":";;AAEA,8CAYC;;AAdD,qDAA+B;AAE/B,SAAgB,iBAAiB,CAAC,MAA4B,EAAE,IAA2B;IACvF,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEvC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACrB,OAAO,MAAM,EAAE,CAAC;QACpB,CAAC;QAED,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAE1B,uDAAuD;IAC3D,CAAC,EAAE,IAAI,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,3 @@
1
+ type RefreshToken = number;
2
+ export declare function useRefresh(): [RefreshToken, () => void];
3
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRefresh = useRefresh;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ function useRefresh() {
7
+ const [token, setToken] = React.useState(0);
8
+ const refresh = React.useCallback(() => setToken((x) => x + 1), []);
9
+ return React.useMemo(() => [token, refresh], [token, refresh]);
10
+ }
11
+ //# sourceMappingURL=useRefresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRefresh.js","sourceRoot":"","sources":["../../../src/main/web/effects/useRefresh.ts"],"names":[],"mappings":";;AAIA,gCAMC;;AAVD,qDAA+B;AAI/B,SAAgB,UAAU;IACtB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE5C,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEpE,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1 @@
1
+ export { useToggle, type ToggleApi } from './useToggle';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useToggle = void 0;
4
+ var useToggle_1 = require("./useToggle");
5
+ Object.defineProperty(exports, "useToggle", { enumerable: true, get: function () { return useToggle_1.useToggle; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/web/hooks/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwD;AAA/C,sGAAA,SAAS,OAAA"}
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ export interface ToggleApi {
3
+ isEnabled: boolean;
4
+ onEnable(): void;
5
+ onDisable(): void;
6
+ onToggle(): void;
7
+ setEnabled: React.Dispatch<React.SetStateAction<boolean>>;
8
+ }
9
+ export declare function useToggle(initialOpen?: boolean): ToggleApi;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useToggle = useToggle;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ function useToggle(initialOpen = false) {
7
+ const [isEnabled, setEnabled] = React.useState(initialOpen);
8
+ const onEnable = React.useCallback(() => setEnabled(true), []);
9
+ const onDisable = React.useCallback(() => setEnabled(false), []);
10
+ const onToggle = React.useCallback(() => setEnabled((isEnabled) => !isEnabled), []);
11
+ return React.useMemo(() => ({ isEnabled, onEnable, onDisable, onToggle, setEnabled }), [isEnabled, onEnable, onDisable, onToggle]);
12
+ }
13
+ //# sourceMappingURL=useToggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToggle.js","sourceRoot":"","sources":["../../../src/main/web/hooks/useToggle.ts"],"names":[],"mappings":";;AAUA,8BAWC;;AArBD,qDAA+B;AAU/B,SAAgB,SAAS,CAAC,WAAW,GAAG,KAAK;IACzC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAE5D,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;IAEpF,OAAO,KAAK,CAAC,OAAO,CAChB,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,EAChE,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAC7C,CAAC;AACN,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from './browser';
2
+ export * from './effects';
3
+ export * from './hooks';
4
+ export * from './storage';
5
+ export * from './time';
6
+ export * from './timers';
7
+ export * from './ts';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./browser"), exports);
5
+ tslib_1.__exportStar(require("./effects"), exports);
6
+ tslib_1.__exportStar(require("./hooks"), exports);
7
+ tslib_1.__exportStar(require("./storage"), exports);
8
+ tslib_1.__exportStar(require("./time"), exports);
9
+ tslib_1.__exportStar(require("./timers"), exports);
10
+ tslib_1.__exportStar(require("./ts"), exports);
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/web/index.ts"],"names":[],"mappings":";;;AAAA,oDAA0B;AAC1B,oDAA0B;AAC1B,kDAAwB;AACxB,oDAA0B;AAC1B,iDAAuB;AACvB,mDAAyB;AACzB,+CAAqB"}
@@ -0,0 +1,20 @@
1
+ export interface StorageBackend {
2
+ get(): string | null;
3
+ set(value: string): void;
4
+ delete(): void;
5
+ }
6
+ declare abstract class GenericStorageBackend implements StorageBackend {
7
+ private key;
8
+ protected abstract storage: Storage;
9
+ constructor(key: string);
10
+ get(): string | null;
11
+ set(value: string): void;
12
+ delete(): void;
13
+ }
14
+ export declare class LocalStorageBackend extends GenericStorageBackend {
15
+ protected storage: Storage;
16
+ }
17
+ export declare class SessionStorageBackend extends GenericStorageBackend {
18
+ protected storage: Storage;
19
+ }
20
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionStorageBackend = exports.LocalStorageBackend = void 0;
4
+ class GenericStorageBackend {
5
+ constructor(key) {
6
+ this.key = key;
7
+ }
8
+ get() {
9
+ return this.storage.getItem(this.key);
10
+ }
11
+ set(value) {
12
+ this.storage.setItem(this.key, value);
13
+ }
14
+ delete() {
15
+ this.storage.removeItem(this.key);
16
+ }
17
+ }
18
+ class LocalStorageBackend extends GenericStorageBackend {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.storage = localStorage;
22
+ }
23
+ }
24
+ exports.LocalStorageBackend = LocalStorageBackend;
25
+ class SessionStorageBackend extends GenericStorageBackend {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.storage = sessionStorage;
29
+ }
30
+ }
31
+ exports.SessionStorageBackend = SessionStorageBackend;
32
+ //# sourceMappingURL=backends.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backends.js","sourceRoot":"","sources":["../../../src/main/web/storage/backends.ts"],"names":[],"mappings":";;;AAMA,MAAe,qBAAqB;IAGhC,YAAoB,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;IAEnC,GAAG;QACC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IAED,GAAG,CAAC,KAAa;QACb,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM;QACF,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;CACJ;AAED,MAAa,mBAAoB,SAAQ,qBAAqB;IAA9D;;QACc,YAAO,GAAG,YAAY,CAAC;IACrC,CAAC;CAAA;AAFD,kDAEC;AAED,MAAa,qBAAsB,SAAQ,qBAAqB;IAAhE;;QACc,YAAO,GAAG,cAAc,CAAC;IACvC,CAAC;CAAA;AAFD,sDAEC"}
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ import { StorageService } from './services';
3
+ export { StorageService };
4
+ export type { StorageBackend } from './backends';
5
+ export interface StoredValue<T> {
6
+ value: T;
7
+ set(value: T): void;
8
+ update: React.Dispatch<React.SetStateAction<T>>;
9
+ delete(): void;
10
+ }
11
+ export interface StoredValueConfig<T> {
12
+ defaultValue: T;
13
+ serialize: (value: T) => string | null;
14
+ deserialize: (value: string) => T;
15
+ }
16
+ export declare function useLocalStorage<T>(name: string, config: StoredValueConfig<T>): StoredValue<T>;
17
+ export declare function useSessionStorage<T>(name: string, config: StoredValueConfig<T>): StoredValue<T>;
18
+ export declare function useStoredValue<T>(service: StorageService<T>): StoredValue<T>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageService = void 0;
4
+ exports.useLocalStorage = useLocalStorage;
5
+ exports.useSessionStorage = useSessionStorage;
6
+ exports.useStoredValue = useStoredValue;
7
+ const tslib_1 = require("tslib");
8
+ const React = tslib_1.__importStar(require("react"));
9
+ const services_1 = require("./services");
10
+ Object.defineProperty(exports, "StorageService", { enumerable: true, get: function () { return services_1.StorageService; } });
11
+ function useLocalStorage(name, config) {
12
+ const service = React.useMemo(() => (0, services_1.fromLocalStorage)(name, config.defaultValue, config.serialize, config.deserialize), [name, config.defaultValue, config.serialize, config.deserialize]);
13
+ return useStoredValue(service);
14
+ }
15
+ function useSessionStorage(name, config) {
16
+ const service = React.useMemo(() => (0, services_1.fromSessionStorage)(name, config.defaultValue, config.serialize, config.deserialize), [name, config.defaultValue, config.serialize, config.deserialize]);
17
+ return useStoredValue(service);
18
+ }
19
+ function useStoredValue(service) {
20
+ const [value, setValue] = React.useState(service.get());
21
+ React.useEffect(() => service.addChangeListener(setValue), [service]);
22
+ const set = React.useCallback((value) => {
23
+ service.set(value);
24
+ }, [service]);
25
+ const updateValue = React.useCallback((updater) => {
26
+ return typeof updater === 'function'
27
+ ? service.update(updater)
28
+ : service.set(updater);
29
+ }, [service]);
30
+ const deleteValue = React.useCallback(() => {
31
+ service.delete();
32
+ }, [service]);
33
+ return React.useMemo(() => {
34
+ return { value, set, update: updateValue, delete: deleteValue };
35
+ }, [value, set, deleteValue, updateValue]);
36
+ }
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/web/storage/index.ts"],"names":[],"mappings":";;;AAoBA,0CAOC;AAED,8CAOC;AAED,wCA4BC;;AAlED,qDAA+B;AAE/B,yCAAkF;AAEzE,+FAFA,yBAAc,OAEA;AAgBvB,SAAgB,eAAe,CAAI,IAAY,EAAE,MAA4B;I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,OAAO,OAAO,KAAK,UAAU;YAChC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAA0B,CAAC;YAC5C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC,EACD,CAAC,OAAO,CAAC,CACZ,CAAC;IAEF,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACvC,OAAO,CAAC,MAAM,EAAE,CAAC;IACrB,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACtB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IACpE,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type StorageBackend } from './backends';
2
+ type ChangeListener<T> = (value: T) => unknown;
3
+ type Unsubscribe = () => void;
4
+ export declare class StorageService<T> {
5
+ private storage;
6
+ private defaultValue;
7
+ private serialize;
8
+ private deserialize;
9
+ private changeListeners;
10
+ constructor(storage: StorageBackend, defaultValue: T, serialize: (value: T) => string | null, deserialize: (value: string) => T);
11
+ get(): T;
12
+ set(value: T): void;
13
+ update(updater: (value: T) => T): void;
14
+ delete(): void;
15
+ addChangeListener(listener: ChangeListener<T>): Unsubscribe;
16
+ private emitChange;
17
+ }
18
+ export declare function fromLocalStorage<T>(key: string, defaultValue: T, serialize: (value: T) => string | null, deserialize: (value: string) => T): StorageService<T>;
19
+ export declare function fromSessionStorage<T>(key: string, defaultValue: T, serialize: (value: T) => string | null, deserialize: (value: string) => T): StorageService<T>;
20
+ export {};
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageService = void 0;
4
+ exports.fromLocalStorage = fromLocalStorage;
5
+ exports.fromSessionStorage = fromSessionStorage;
6
+ const backends_1 = require("./backends");
7
+ class StorageService {
8
+ constructor(storage, defaultValue, serialize, deserialize) {
9
+ this.storage = storage;
10
+ this.defaultValue = defaultValue;
11
+ this.serialize = serialize;
12
+ this.deserialize = deserialize;
13
+ this.changeListeners = [];
14
+ }
15
+ get() {
16
+ const value = this.storage.get();
17
+ if (value == null) {
18
+ return this.defaultValue;
19
+ }
20
+ return this.deserialize(value);
21
+ }
22
+ set(value) {
23
+ const serialized = this.serialize(value);
24
+ if (serialized != null) {
25
+ this.storage.set(serialized);
26
+ }
27
+ else {
28
+ this.delete();
29
+ }
30
+ this.emitChange();
31
+ }
32
+ update(updater) {
33
+ const value = updater(this.get());
34
+ this.set(value);
35
+ this.emitChange();
36
+ }
37
+ delete() {
38
+ this.storage.delete();
39
+ this.emitChange();
40
+ }
41
+ addChangeListener(listener) {
42
+ const unsubscribe = () => {
43
+ const index = this.changeListeners.indexOf(listener);
44
+ if (index !== -1) {
45
+ this.changeListeners.splice(index, 1);
46
+ }
47
+ };
48
+ if (this.changeListeners.indexOf(listener) === -1) {
49
+ this.changeListeners.push(listener);
50
+ listener(this.get());
51
+ }
52
+ return unsubscribe;
53
+ }
54
+ emitChange() {
55
+ const value = this.get();
56
+ this.changeListeners.forEach((listener) => {
57
+ listener(value);
58
+ });
59
+ }
60
+ }
61
+ exports.StorageService = StorageService;
62
+ function fromLocalStorage(key, defaultValue, serialize, deserialize) {
63
+ const storageBackend = new backends_1.LocalStorageBackend(key);
64
+ return new StorageService(storageBackend, defaultValue, serialize, deserialize);
65
+ }
66
+ function fromSessionStorage(key, defaultValue, serialize, deserialize) {
67
+ const storageBackend = new backends_1.SessionStorageBackend(key);
68
+ return new StorageService(storageBackend, defaultValue, serialize, deserialize);
69
+ }
70
+ //# sourceMappingURL=services.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.js","sourceRoot":"","sources":["../../../src/main/web/storage/services.ts"],"names":[],"mapp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+ };
5
+ export type ISODate = Opaque<'ISODate', string>;
6
+ export type DateFormat = 'DATETIME_FULL' | 'DATETIME_FULL_WITH_SECONDS' | 'DATETIME_HUGE' | 'DATETIME_HUGE_WITH_SECONDS' | 'DATETIME_MED' | 'DATETIME_MED_WITH_SECONDS' | 'DATETIME_SHORT' | 'DATETIME_SHORT_WITH_SECONDS' | 'DATE_FULL' | 'DATE_HUGE' | 'DATE_MED' | 'DATE_SHORT' | 'TIME_24_SIMPLE' | 'TIME_24_WITH_LONG_OFFSET' | 'TIME_24_WITH_SECONDS' | 'TIME_24_WITH_SHORT_OFFSET' | 'TIME_SIMPLE' | 'TIME_WITH_LONG_OFFSET' | 'TIME_WITH_SECONDS' | 'TIME_WITH_SHORT_OFFSET';
7
+ export type GenericDateTime = string | Date | DateTime | ISODate;
8
+ export declare function toDateTime(value: GenericDateTime): DateTime;
9
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDateTime = toDateTime;
4
+ const luxon_1 = require("luxon");
5
+ function toDateTime(value) {
6
+ if (value instanceof luxon_1.DateTime) {
7
+ return value.toUTC();
8
+ }
9
+ if (value instanceof Date) {
10
+ return luxon_1.DateTime.fromISO(value.toISOString());
11
+ }
12
+ try {
13
+ return luxon_1.DateTime.fromISO(new Date(value).toISOString());
14
+ }
15
+ catch (e) {
16
+ return luxon_1.DateTime.invalid(e instanceof Error ? e.message : '');
17
+ }
18
+ }
19
+ //# sourceMappingURL=datetime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datetime.js","sourceRoot":"","sources":["../../../src/main/web/time/datetime.ts"],"names":[],"mappings":";;AA8BA,gCAcC;AA5CD,iCAAiC;AA8BjC,SAAgB,UAAU,CAAC,KAAsB;IAC7C,IAAI,KAAK,YAAY,gBAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QACxB,OAAO,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,CAAC;QACD,OAAO,gBAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,gBAAQ,CAAC,OAAO,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACjE,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { useClock, type Clock } from './useClock';
2
+ export { type ISODate, type GenericDateTime, type DateFormat, toDateTime } from './datetime';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDateTime = exports.useClock = void 0;
4
+ var useClock_1 = require("./useClock");
5
+ Object.defineProperty(exports, "useClock", { enumerable: true, get: function () { return useClock_1.useClock; } });
6
+ var datetime_1 = require("./datetime");
7
+ Object.defineProperty(exports, "toDateTime", { enumerable: true, get: function () { return datetime_1.toDateTime; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/web/time/index.ts"],"names":[],"mappings":";;;AAAA,uCAAkD;AAAzC,oGAAA,QAAQ,OAAA;AACjB,uCAA6F;AAA/B,sGAAA,UAAU,OAAA"}
@@ -0,0 +1,11 @@
1
+ import { DateTime } from 'luxon';
2
+ export interface Clock {
3
+ readonly now: DateTime<true>;
4
+ /**
5
+ * Updates the current time in the given interval.
6
+ * @param intervalMs Interval for clock update in milliseconds. Defaults to 1000ms.
7
+ */
8
+ tick(intervalMs?: number): () => void;
9
+ update(): void;
10
+ }
11
+ export declare const useClock: (tickIntervalMs?: number, locale?: string) => Clock;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useClock = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const luxon_1 = require("luxon");
6
+ const React = tslib_1.__importStar(require("react"));
7
+ const useClock = function useClock(tickIntervalMs, locale) {
8
+ const getCurrentTime = React.useCallback(() => (locale != null ? luxon_1.DateTime.utc().setLocale(locale) : luxon_1.DateTime.utc()), [locale]);
9
+ const [now, setNow] = React.useState(getCurrentTime);
10
+ const update = React.useCallback(() => setNow(getCurrentTime()), [getCurrentTime]);
11
+ const tick = React.useCallback((intervalMs = 1000) => {
12
+ const interval = setInterval(update, intervalMs);
13
+ return () => clearInterval(interval);
14
+ }, [update]);
15
+ React.useEffect(() => {
16
+ if (tickIntervalMs != null && tickIntervalMs > 0) {
17
+ return tick(tickIntervalMs);
18
+ }
19
+ }, [tick, tickIntervalMs]);
20
+ return React.useMemo(() => ({ now, tick, update }), [now, tick, update]);
21
+ };
22
+ exports.useClock = useClock;
23
+ //# sourceMappingURL=useClock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClock.js","sourceRoot":"","sources":["../../../src/main/web/time/useClock.ts"],"names":[],"mappings":";;;;AAAA,iCAAiC;AACjC,qDAA+B;AAYxB,MAAM,QAAQ,GAAG,SAAS,QAAQ,CAAC,cAAuB,EAAE,MAAe;IAC9E,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CACpC,GAAG,EAAE,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,gBAAQ,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,gBAAQ,CAAC,GAAG,EAAE,CAAC,EAC1E,CAAC,MAAM,CAAC,CACX,CAAC;IAEF,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAErD,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;IAEnF,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAC1B,CAAC,UAAU,GAAG,IAAI,EAAE,EAAE;QAClB,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACjD,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC,EACD,CAAC,MAAM,CAAC,CACX,CAAC;IAEF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IAAI,cAAc,IAAI,IAAI,IAAI,cAAc,GAAG,CAAC,EAAE,CAAC;YAC/C,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC;QAChC,CAAC;IACL,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;IAE3B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAC7E,CAAC,CAAC;AAzBW,QAAA,QAAQ,YAyBnB"}
@@ -0,0 +1,2 @@
1
+ export { useDebounce } from './useDebounce';
2
+ export { useTimeout, useInterval } from './useTimer';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useInterval = exports.useTimeout = exports.useDebounce = void 0;
4
+ var useDebounce_1 = require("./useDebounce");
5
+ Object.defineProperty(exports, "useDebounce", { enumerable: true, get: function () { return useDebounce_1.useDebounce; } });
6
+ var useTimer_1 = require("./useTimer");
7
+ Object.defineProperty(exports, "useTimeout", { enumerable: true, get: function () { return useTimer_1.useTimeout; } });
8
+ Object.defineProperty(exports, "useInterval", { enumerable: true, get: function () { return useTimer_1.useInterval; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/web/timers/index.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,uCAAqD;AAA5C,sGAAA,UAAU,OAAA;AAAE,uGAAA,WAAW,OAAA"}
@@ -0,0 +1 @@
1
+ export declare function useDebounce<T>(value: T, delay: number): T;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDebounce = useDebounce;
4
+ const tslib_1 = require("tslib");
5
+ const react = tslib_1.__importStar(require("react"));
6
+ function useDebounce(value, delay) {
7
+ const [debouncedValue, setDebouncedValue] = react.useState(value);
8
+ react.useEffect(() => {
9
+ const handler = setTimeout(() => {
10
+ setDebouncedValue(value);
11
+ }, delay);
12
+ return () => clearTimeout(handler);
13
+ }, [value, delay]);
14
+ return debouncedValue;
15
+ }
16
+ //# sourceMappingURL=useDebounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.js","sourceRoot":"","sources":["../../../src/main/web/timers/useDebounce.ts"],"names":[],"mappings":";;AAEA,kCAYC;;AAdD,qDAA+B;AAE/B,SAAgB,WAAW,CAAI,KAAQ,EAAE,KAAa;IAClD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAElE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC,EAAE,KAAK,CAAC,CAAC;QAEV,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEnB,OAAO,cAAc,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,13 @@
1
+ type MaybeCleanup = (() => void) | void;
2
+ interface CallbackWithCleanup {
3
+ (): MaybeCleanup;
4
+ }
5
+ interface TimeoutCallback {
6
+ (timeoutHandler: CallbackWithCleanup, timeoutDurationMs?: number): () => void;
7
+ cancel(): void;
8
+ }
9
+ export declare function useTimer(defaultTimeoutDurationMs?: number, timerFunction?: TimerFunction): TimeoutCallback;
10
+ type TimerFunction = typeof setTimeout | typeof setInterval;
11
+ export declare function useTimeout(defaultTimeoutDurationMs?: number): TimeoutCallback;
12
+ export declare function useInterval(defaultTimeoutDurationMs?: number): TimeoutCallback;
13
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useTimer = useTimer;
4
+ exports.useTimeout = useTimeout;
5
+ exports.useInterval = useInterval;
6
+ const tslib_1 = require("tslib");
7
+ const React = tslib_1.__importStar(require("react"));
8
+ function useTimer(defaultTimeoutDurationMs = 0, timerFunction = setTimeout) {
9
+ const timeoutId = React.useRef(undefined);
10
+ const callbackCleanup = React.useRef(undefined);
11
+ const clear = React.useCallback(() => {
12
+ if (timeoutId.current != null) {
13
+ if (timerFunction === setTimeout) {
14
+ clearTimeout(timeoutId.current);
15
+ }
16
+ else {
17
+ clearInterval(timeoutId.current);
18
+ }
19
+ }
20
+ if (typeof callbackCleanup.current === 'function') {
21
+ callbackCleanup.current();
22
+ callbackCleanup.current = undefined;
23
+ }
24
+ }, [timerFunction]);
25
+ React.useEffect(() => clear, [clear]);
26
+ return React.useMemo(() => {
27
+ const runTimeout = (timeoutHandler, timeoutDurationMs = defaultTimeoutDurationMs) => {
28
+ clear();
29
+ timeoutId.current = timerFunction(() => {
30
+ callbackCleanup.current = timeoutHandler();
31
+ }, timeoutDurationMs);
32
+ return clear;
33
+ };
34
+ runTimeout.cancel = clear;
35
+ return runTimeout;
36
+ }, [clear, timerFunction, defaultTimeoutDurationMs]);
37
+ }
38
+ function useTimeout(defaultTimeoutDurationMs = 0) {
39
+ return useTimer(defaultTimeoutDurationMs, setTimeout);
40
+ }
41
+ function useInterval(defaultTimeoutDurationMs = 0) {
42
+ return useTimer(defaultTimeoutDurationMs, setInterval);
43
+ }
44
+ //# sourceMappingURL=useTimer.js.map