@ekz/react-utils 1.0.0
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/LICENSE +21 -0
- package/lib/cjs/browser/index.d.ts +1 -0
- package/lib/cjs/browser/index.js +6 -0
- package/lib/cjs/browser/index.js.map +1 -0
- package/lib/cjs/browser/useWindowFocusDetection.d.ts +1 -0
- package/lib/cjs/browser/useWindowFocusDetection.js +17 -0
- package/lib/cjs/browser/useWindowFocusDetection.js.map +1 -0
- package/lib/cjs/effects/index.d.ts +3 -0
- package/lib/cjs/effects/index.js +11 -0
- package/lib/cjs/effects/index.js.map +1 -0
- package/lib/cjs/effects/useDebouncedEffect.d.ts +2 -0
- package/lib/cjs/effects/useDebouncedEffect.js +13 -0
- package/lib/cjs/effects/useDebouncedEffect.js.map +1 -0
- package/lib/cjs/effects/useEffectOnUpdate.d.ts +2 -0
- package/lib/cjs/effects/useEffectOnUpdate.js +16 -0
- package/lib/cjs/effects/useEffectOnUpdate.js.map +1 -0
- package/lib/cjs/effects/useRefresh.d.ts +3 -0
- package/lib/cjs/effects/useRefresh.js +11 -0
- package/lib/cjs/effects/useRefresh.js.map +1 -0
- package/lib/cjs/hooks/index.d.ts +1 -0
- package/lib/cjs/hooks/index.js +6 -0
- package/lib/cjs/hooks/index.js.map +1 -0
- package/lib/cjs/hooks/useToggle.d.ts +9 -0
- package/lib/cjs/hooks/useToggle.js +13 -0
- package/lib/cjs/hooks/useToggle.js.map +1 -0
- package/lib/cjs/index.d.ts +7 -0
- package/lib/cjs/index.js +11 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/storage/backends.d.ts +20 -0
- package/lib/cjs/storage/backends.js +33 -0
- package/lib/cjs/storage/backends.js.map +1 -0
- package/lib/cjs/storage/index.d.ts +18 -0
- package/lib/cjs/storage/index.js +37 -0
- package/lib/cjs/storage/index.js.map +1 -0
- package/lib/cjs/storage/services.d.ts +20 -0
- package/lib/cjs/storage/services.js +71 -0
- package/lib/cjs/storage/services.js.map +1 -0
- package/lib/cjs/time/datetime.d.ts +9 -0
- package/lib/cjs/time/datetime.js +19 -0
- package/lib/cjs/time/datetime.js.map +1 -0
- package/lib/cjs/time/index.d.ts +2 -0
- package/lib/cjs/time/index.js +8 -0
- package/lib/cjs/time/index.js.map +1 -0
- package/lib/cjs/time/useClock.d.ts +11 -0
- package/lib/cjs/time/useClock.js +23 -0
- package/lib/cjs/time/useClock.js.map +1 -0
- package/lib/cjs/timers/index.d.ts +2 -0
- package/lib/cjs/timers/index.js +10 -0
- package/lib/cjs/timers/index.js.map +1 -0
- package/lib/cjs/timers/useDebounce.d.ts +1 -0
- package/lib/cjs/timers/useDebounce.js +16 -0
- package/lib/cjs/timers/useDebounce.js.map +1 -0
- package/lib/cjs/timers/useTimer.d.ts +13 -0
- package/lib/cjs/timers/useTimer.js +44 -0
- package/lib/cjs/timers/useTimer.js.map +1 -0
- package/lib/cjs/ts/index.d.ts +1 -0
- package/lib/cjs/ts/index.js +6 -0
- package/lib/cjs/ts/index.js.map +1 -0
- package/lib/cjs/ts/unreachable.d.ts +1 -0
- package/lib/cjs/ts/unreachable.js +7 -0
- package/lib/cjs/ts/unreachable.js.map +1 -0
- package/lib/esm/browser/index.d.ts +1 -0
- package/lib/esm/browser/index.js +2 -0
- package/lib/esm/browser/index.js.map +1 -0
- package/lib/esm/browser/useWindowFocusDetection.d.ts +1 -0
- package/lib/esm/browser/useWindowFocusDetection.js +13 -0
- package/lib/esm/browser/useWindowFocusDetection.js.map +1 -0
- package/lib/esm/effects/index.d.ts +3 -0
- package/lib/esm/effects/index.js +4 -0
- package/lib/esm/effects/index.js.map +1 -0
- package/lib/esm/effects/useDebouncedEffect.d.ts +2 -0
- package/lib/esm/effects/useDebouncedEffect.js +9 -0
- package/lib/esm/effects/useDebouncedEffect.js.map +1 -0
- package/lib/esm/effects/useEffectOnUpdate.d.ts +2 -0
- package/lib/esm/effects/useEffectOnUpdate.js +12 -0
- package/lib/esm/effects/useEffectOnUpdate.js.map +1 -0
- package/lib/esm/effects/useRefresh.d.ts +3 -0
- package/lib/esm/effects/useRefresh.js +7 -0
- package/lib/esm/effects/useRefresh.js.map +1 -0
- package/lib/esm/hooks/index.d.ts +1 -0
- package/lib/esm/hooks/index.js +2 -0
- package/lib/esm/hooks/index.js.map +1 -0
- package/lib/esm/hooks/useToggle.d.ts +9 -0
- package/lib/esm/hooks/useToggle.js +9 -0
- package/lib/esm/hooks/useToggle.js.map +1 -0
- package/lib/esm/index.d.ts +7 -0
- package/lib/esm/index.js +8 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/storage/backends.d.ts +20 -0
- package/lib/esm/storage/backends.js +28 -0
- package/lib/esm/storage/backends.js.map +1 -0
- package/lib/esm/storage/index.d.ts +18 -0
- package/lib/esm/storage/index.js +30 -0
- package/lib/esm/storage/index.js.map +1 -0
- package/lib/esm/storage/services.d.ts +20 -0
- package/lib/esm/storage/services.js +65 -0
- package/lib/esm/storage/services.js.map +1 -0
- package/lib/esm/time/datetime.d.ts +9 -0
- package/lib/esm/time/datetime.js +16 -0
- package/lib/esm/time/datetime.js.map +1 -0
- package/lib/esm/time/index.d.ts +2 -0
- package/lib/esm/time/index.js +3 -0
- package/lib/esm/time/index.js.map +1 -0
- package/lib/esm/time/useClock.d.ts +11 -0
- package/lib/esm/time/useClock.js +18 -0
- package/lib/esm/time/useClock.js.map +1 -0
- package/lib/esm/timers/index.d.ts +2 -0
- package/lib/esm/timers/index.js +3 -0
- package/lib/esm/timers/index.js.map +1 -0
- package/lib/esm/timers/useDebounce.d.ts +1 -0
- package/lib/esm/timers/useDebounce.js +12 -0
- package/lib/esm/timers/useDebounce.js.map +1 -0
- package/lib/esm/timers/useTimer.d.ts +13 -0
- package/lib/esm/timers/useTimer.js +38 -0
- package/lib/esm/timers/useTimer.js.map +1 -0
- package/lib/esm/ts/index.d.ts +1 -0
- package/lib/esm/ts/index.js +2 -0
- package/lib/esm/ts/index.js.map +1 -0
- package/lib/esm/ts/unreachable.d.ts +1 -0
- package/lib/esm/ts/unreachable.js +4 -0
- package/lib/esm/ts/unreachable.js.map +1 -0
- package/lib/esnext/browser/index.d.ts +1 -0
- package/lib/esnext/browser/index.js +2 -0
- package/lib/esnext/browser/index.js.map +1 -0
- package/lib/esnext/browser/useWindowFocusDetection.d.ts +1 -0
- package/lib/esnext/browser/useWindowFocusDetection.js +13 -0
- package/lib/esnext/browser/useWindowFocusDetection.js.map +1 -0
- package/lib/esnext/effects/index.d.ts +3 -0
- package/lib/esnext/effects/index.js +4 -0
- package/lib/esnext/effects/index.js.map +1 -0
- package/lib/esnext/effects/useDebouncedEffect.d.ts +2 -0
- package/lib/esnext/effects/useDebouncedEffect.js +9 -0
- package/lib/esnext/effects/useDebouncedEffect.js.map +1 -0
- package/lib/esnext/effects/useEffectOnUpdate.d.ts +2 -0
- package/lib/esnext/effects/useEffectOnUpdate.js +12 -0
- package/lib/esnext/effects/useEffectOnUpdate.js.map +1 -0
- package/lib/esnext/effects/useRefresh.d.ts +3 -0
- package/lib/esnext/effects/useRefresh.js +7 -0
- package/lib/esnext/effects/useRefresh.js.map +1 -0
- package/lib/esnext/hooks/index.d.ts +1 -0
- package/lib/esnext/hooks/index.js +2 -0
- package/lib/esnext/hooks/index.js.map +1 -0
- package/lib/esnext/hooks/useToggle.d.ts +9 -0
- package/lib/esnext/hooks/useToggle.js +9 -0
- package/lib/esnext/hooks/useToggle.js.map +1 -0
- package/lib/esnext/index.d.ts +7 -0
- package/lib/esnext/index.js +8 -0
- package/lib/esnext/index.js.map +1 -0
- package/lib/esnext/storage/backends.d.ts +20 -0
- package/lib/esnext/storage/backends.js +23 -0
- package/lib/esnext/storage/backends.js.map +1 -0
- package/lib/esnext/storage/index.d.ts +18 -0
- package/lib/esnext/storage/index.js +30 -0
- package/lib/esnext/storage/index.js.map +1 -0
- package/lib/esnext/storage/services.d.ts +20 -0
- package/lib/esnext/storage/services.js +69 -0
- package/lib/esnext/storage/services.js.map +1 -0
- package/lib/esnext/time/datetime.d.ts +9 -0
- package/lib/esnext/time/datetime.js +16 -0
- package/lib/esnext/time/datetime.js.map +1 -0
- package/lib/esnext/time/index.d.ts +2 -0
- package/lib/esnext/time/index.js +3 -0
- package/lib/esnext/time/index.js.map +1 -0
- package/lib/esnext/time/useClock.d.ts +11 -0
- package/lib/esnext/time/useClock.js +18 -0
- package/lib/esnext/time/useClock.js.map +1 -0
- package/lib/esnext/timers/index.d.ts +2 -0
- package/lib/esnext/timers/index.js +3 -0
- package/lib/esnext/timers/index.js.map +1 -0
- package/lib/esnext/timers/useDebounce.d.ts +1 -0
- package/lib/esnext/timers/useDebounce.js +12 -0
- package/lib/esnext/timers/useDebounce.js.map +1 -0
- package/lib/esnext/timers/useTimer.d.ts +13 -0
- package/lib/esnext/timers/useTimer.js +38 -0
- package/lib/esnext/timers/useTimer.js.map +1 -0
- package/lib/esnext/ts/index.d.ts +1 -0
- package/lib/esnext/ts/index.js +2 -0
- package/lib/esnext/ts/index.js.map +1 -0
- package/lib/esnext/ts/unreachable.d.ts +1 -0
- package/lib/esnext/ts/unreachable.js +4 -0
- package/lib/esnext/ts/unreachable.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 erkez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -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,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRefresh = exports.useEffectOnUpdate = exports.useDebouncedEffect = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var useDebouncedEffect_1 = require("./useDebouncedEffect");
|
|
6
|
+
Object.defineProperty(exports, "useDebouncedEffect", { enumerable: true, get: function () { return tslib_1.__importDefault(useDebouncedEffect_1).default; } });
|
|
7
|
+
var useEffectOnUpdate_1 = require("./useEffectOnUpdate");
|
|
8
|
+
Object.defineProperty(exports, "useEffectOnUpdate", { enumerable: true, get: function () { return tslib_1.__importDefault(useEffectOnUpdate_1).default; } });
|
|
9
|
+
var useRefresh_1 = require("./useRefresh");
|
|
10
|
+
Object.defineProperty(exports, "useRefresh", { enumerable: true, get: function () { return tslib_1.__importDefault(useRefresh_1).default; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/web/effects/index.ts"],"names":[],"mappings":";;;;AAAA,2DAAqE;AAA5D,iJAAA,OAAO,OAAsB;AACtC,yDAAmE;AAA1D,+IAAA,OAAO,OAAqB;AACrC,2CAAqD;AAA5C,iIAAA,OAAO,OAAc"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = 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,qCASC;;AAbD,qDAA+B;AAE/B,sCAAuC;AAEvC,SAAwB,kBAAkB,CACtC,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,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = 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,oCAeC;;AAjBD,qDAA+B;AAE/B,SAAwB,iBAAiB,CACrC,MAA4B,EAC5B,IAA2B;IAE3B,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,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = 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,6BAMC;;AAVD,qDAA+B;AAI/B,SAAwB,UAAU;IAC9B,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"}
|
package/lib/cjs/index.js
ADDED
|
@@ -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,33 @@
|
|
|
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
|
+
// eslint-disable-next-line prettier/prettier
|
|
22
|
+
this.storage = localStorage;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.LocalStorageBackend = LocalStorageBackend;
|
|
26
|
+
class SessionStorageBackend extends GenericStorageBackend {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
this.storage = sessionStorage;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.SessionStorageBackend = SessionStorageBackend;
|
|
33
|
+
//# 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;;QACI,6CAA6C;QACnC,YAAO,GAAG,YAAY,CAAC;IACrC,CAAC;CAAA;AAHD,kDAGC;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 default 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.default = 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,iCA4BC;;AAlED,qDAA+B;AAE/B,yCAAkF;AAEzE,+FAFA,yBAAc,OAEA;AAgBvB,SAAgB,eAAe,CAAI,IAAY,EAAE,MAA4B;IACzE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CACzB,GAAG,EAAE,CAAC,IAAA,2BAAgB,EAAC,IAAI,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,EACvF,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,CACpE,CAAC;IAEF,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAED,SAAgB,iBAAiB,CAAI,IAAY,EAAE,MAA4B;IAC3E,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CACzB,GAAG,EAAE,CAAC,IAAA,6BAAkB,EAAC,IAAI,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,EACzF,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,CACpE,CAAC;IAEF,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAED,SAAwB,cAAc,CAAI,OAA0B;IAChE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAE3D,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEtE,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,CACzB,CAAC,KAAQ,EAAE,EAAE;QACT,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC,EACD,CAAC,OAAO,CAAC,CACZ,CAAC;IAEF,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CACjC,CAAC,OAAgC,EAAE,EAAE;QACjC,OAAO,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,71 @@
|
|
|
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
|
+
// eslint-disable-next-line prettier/prettier
|
|
14
|
+
this.changeListeners = [];
|
|
15
|
+
}
|
|
16
|
+
get() {
|
|
17
|
+
const value = this.storage.get();
|
|
18
|
+
if (value == null) {
|
|
19
|
+
return this.defaultValue;
|
|
20
|
+
}
|
|
21
|
+
return this.deserialize(value);
|
|
22
|
+
}
|
|
23
|
+
set(value) {
|
|
24
|
+
const serialized = this.serialize(value);
|
|
25
|
+
if (serialized != null) {
|
|
26
|
+
this.storage.set(serialized);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.delete();
|
|
30
|
+
}
|
|
31
|
+
this.emitChange();
|
|
32
|
+
}
|
|
33
|
+
update(updater) {
|
|
34
|
+
const value = updater(this.get());
|
|
35
|
+
this.set(value);
|
|
36
|
+
this.emitChange();
|
|
37
|
+
}
|
|
38
|
+
delete() {
|
|
39
|
+
this.storage.delete();
|
|
40
|
+
this.emitChange();
|
|
41
|
+
}
|
|
42
|
+
addChangeListener(listener) {
|
|
43
|
+
const unsubscribe = () => {
|
|
44
|
+
const index = this.changeListeners.indexOf(listener);
|
|
45
|
+
if (index !== -1) {
|
|
46
|
+
this.changeListeners.splice(index, 1);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
if (this.changeListeners.indexOf(listener) === -1) {
|
|
50
|
+
this.changeListeners.push(listener);
|
|
51
|
+
listener(this.get());
|
|
52
|
+
}
|
|
53
|
+
return unsubscribe;
|
|
54
|
+
}
|
|
55
|
+
emitChange() {
|
|
56
|
+
const value = this.get();
|
|
57
|
+
this.changeListeners.forEach((listener) => {
|
|
58
|
+
listener(value);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.StorageService = StorageService;
|
|
63
|
+
function fromLocalStorage(key, defaultValue, serialize, deserialize) {
|
|
64
|
+
const storageBackend = new backends_1.LocalStorageBackend(key);
|
|
65
|
+
return new StorageService(storageBackend, defaultValue, serialize, deserialize);
|
|
66
|
+
}
|
|
67
|
+
function fromSessionStorage(key, defaultValue, serialize, deserialize) {
|
|
68
|
+
const storageBackend = new backends_1.SessionStorageBackend(key);
|
|
69
|
+
return new StorageService(storageBackend, defaultValue, serialize, deserialize);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services.js","sourceRoot":"","sources":["../../../src/main/web/storage/services.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
type Opaque<K, T> = T & {
|
|
3
|
+
__TYPE__: K;
|
|
4
|
+
};
|
|
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,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;
|
|
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,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useInterval = exports.useTimeout = exports.useDebounce = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var useDebounce_1 = require("./useDebounce");
|
|
6
|
+
Object.defineProperty(exports, "useDebounce", { enumerable: true, get: function () { return tslib_1.__importDefault(useDebounce_1).default; } });
|
|
7
|
+
var useTimer_1 = require("./useTimer");
|
|
8
|
+
Object.defineProperty(exports, "useTimeout", { enumerable: true, get: function () { return useTimer_1.useTimeout; } });
|
|
9
|
+
Object.defineProperty(exports, "useInterval", { enumerable: true, get: function () { return useTimer_1.useInterval; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/web/timers/index.ts"],"names":[],"mappings":";;;;AAAA,6CAAuD;AAA9C,mIAAA,OAAO,OAAe;AAC/B,uCAAqD;AAA5C,sGAAA,UAAU,OAAA;AAAE,uGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useDebounce<T>(value: T, delay: number): T;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = 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,8BAYC;;AAdD,qDAA+B;AAE/B,SAAwB,WAAW,CAAI,KAAQ,EAAE,KAAa;IAC1D,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 default 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 {};
|