@codeleap/hooks 7.0.2 → 7.1.1
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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -57
- package/dist/index.js.map +1 -1
- package/dist/onMount.js +3 -7
- package/dist/onMount.js.map +1 -1
- package/dist/onUpdate.js +3 -7
- package/dist/onUpdate.js.map +1 -1
- package/dist/useBooleanToggle.js +3 -6
- package/dist/useBooleanToggle.js.map +1 -1
- package/dist/useComponentTestId.js +6 -10
- package/dist/useComponentTestId.js.map +1 -1
- package/dist/useConditionalState.js +6 -10
- package/dist/useConditionalState.js.map +1 -1
- package/dist/useDebounce.js +5 -8
- package/dist/useDebounce.js.map +1 -1
- package/dist/useDebounceCallback.js +6 -9
- package/dist/useDebounceCallback.js.map +1 -1
- package/dist/useDerivedRef.js +4 -8
- package/dist/useDerivedRef.js.map +1 -1
- package/dist/useDerivedState.js +6 -10
- package/dist/useDerivedState.js.map +1 -1
- package/dist/useEffectOnce.js +3 -7
- package/dist/useEffectOnce.js.map +1 -1
- package/dist/useFilteredList.js +3 -6
- package/dist/useFilteredList.js.map +1 -1
- package/dist/useForceRender.js +3 -6
- package/dist/useForceRender.js.map +1 -1
- package/dist/useGuardedAsyncCallback.d.ts +31 -0
- package/dist/useGuardedAsyncCallback.d.ts.map +1 -0
- package/dist/useGuardedAsyncCallback.js +38 -0
- package/dist/useGuardedAsyncCallback.js.map +1 -0
- package/dist/useId.js +5 -9
- package/dist/useId.js.map +1 -1
- package/dist/useInterval.js +8 -11
- package/dist/useInterval.js.map +1 -1
- package/dist/useIsMounted.js +5 -9
- package/dist/useIsMounted.js.map +1 -1
- package/dist/useLazyStore.js +5 -8
- package/dist/useLazyStore.js.map +1 -1
- package/dist/useModal.js +5 -8
- package/dist/useModal.js.map +1 -1
- package/dist/useOptions.js +4 -7
- package/dist/useOptions.js.map +1 -1
- package/dist/usePartialState.js +6 -9
- package/dist/usePartialState.js.map +1 -1
- package/dist/usePlaces.js +23 -43
- package/dist/usePlaces.js.map +1 -1
- package/dist/usePlacesAutocompleteUtils.js +12 -19
- package/dist/usePlacesAutocompleteUtils.js.map +1 -1
- package/dist/usePrevious.js +4 -8
- package/dist/usePrevious.js.map +1 -1
- package/dist/usePromise.js +17 -32
- package/dist/usePromise.js.map +1 -1
- package/dist/useRenderCall.js +3 -6
- package/dist/useRenderCall.js.map +1 -1
- package/dist/useSearch/index.js +24 -38
- package/dist/useSearch/index.js.map +1 -1
- package/dist/useSearch/types.js +1 -2
- package/dist/useStableReference.js +5 -8
- package/dist/useStableReference.js.map +1 -1
- package/dist/useToggle.js +3 -6
- package/dist/useToggle.js.map +1 -1
- package/dist/useUncontrolled.js +6 -10
- package/dist/useUncontrolled.js.map +1 -1
- package/dist/useUnmount.js +5 -9
- package/dist/useUnmount.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +1 -0
- package/src/useGuardedAsyncCallback.ts +43 -0
package/dist/useId.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useId = useId;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useRef, useId as _useId } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Hook that returns a stable ID, using provided ID if available or generating one.
|
|
7
4
|
*
|
|
@@ -9,10 +6,9 @@ const react_1 = require("react");
|
|
|
9
6
|
* const id = useId('custom-id') // Returns 'custom-id'
|
|
10
7
|
* const id = useId() // Returns generated ID like ':r1:'
|
|
11
8
|
*/
|
|
12
|
-
function useId(id) {
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
return (_a = idRef.current) !== null && _a !== void 0 ? _a : defaultId;
|
|
9
|
+
export function useId(id) {
|
|
10
|
+
const defaultId = _useId();
|
|
11
|
+
const idRef = useRef(id);
|
|
12
|
+
return idRef.current ?? defaultId;
|
|
17
13
|
}
|
|
18
14
|
//# sourceMappingURL=useId.js.map
|
package/dist/useId.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useId.js","sourceRoot":"","sources":["../src/useId.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useId.js","sourceRoot":"","sources":["../src/useId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,MAAM,EAAE,MAAM,OAAO,CAAA;AAE/C;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAI,EAAM;IAC7B,MAAM,SAAS,GAAG,MAAM,EAAE,CAAA;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAA;IAExB,OAAO,KAAK,CAAC,OAAO,IAAI,SAAS,CAAA;AACnC,CAAC"}
|
package/dist/useInterval.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useInterval = useInterval;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Hook that manages an interval with start and clear controls.
|
|
7
4
|
* The handler receives a clear function to stop the interval from within.
|
|
@@ -15,19 +12,19 @@ const react_1 = require("react");
|
|
|
15
12
|
* start() // Starts the interval
|
|
16
13
|
* clear() // Stops the interval
|
|
17
14
|
*/
|
|
18
|
-
function useInterval(handler, interval) {
|
|
19
|
-
const intervalRef =
|
|
20
|
-
const handlerRef =
|
|
21
|
-
|
|
15
|
+
export function useInterval(handler, interval) {
|
|
16
|
+
const intervalRef = useRef(null);
|
|
17
|
+
const handlerRef = useRef(handler);
|
|
18
|
+
useEffect(() => {
|
|
22
19
|
handlerRef.current = handler;
|
|
23
20
|
}, [handler]);
|
|
24
|
-
const clear =
|
|
21
|
+
const clear = useCallback(() => {
|
|
25
22
|
if (intervalRef.current != null) {
|
|
26
23
|
clearInterval(intervalRef.current);
|
|
27
24
|
intervalRef.current = null;
|
|
28
25
|
}
|
|
29
26
|
}, []);
|
|
30
|
-
const start =
|
|
27
|
+
const start = useCallback(() => {
|
|
31
28
|
clear();
|
|
32
29
|
if (intervalRef.current == null) {
|
|
33
30
|
intervalRef.current = setInterval(() => {
|
|
@@ -35,7 +32,7 @@ function useInterval(handler, interval) {
|
|
|
35
32
|
}, interval);
|
|
36
33
|
}
|
|
37
34
|
}, []);
|
|
38
|
-
|
|
35
|
+
useEffect(() => {
|
|
39
36
|
return () => {
|
|
40
37
|
clear();
|
|
41
38
|
};
|
package/dist/useInterval.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInterval.js","sourceRoot":"","sources":["../src/useInterval.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useInterval.js","sourceRoot":"","sources":["../src/useInterval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,OAA2B,EAAE,QAAgB;IACvE,MAAM,WAAW,GAAG,MAAM,CAAwC,IAAI,CAAC,CAAA;IACvE,MAAM,UAAU,GAAG,MAAM,CAAqB,OAAO,CAAC,CAAA;IAEtD,SAAS,CAAC,GAAG,EAAE;QACb,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA;IAC9B,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,IAAI,WAAW,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YAChC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;YAClC,WAAW,CAAC,OAAO,GAAG,IAAI,CAAA;QAC5B,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,KAAK,EAAE,CAAA;QAEP,IAAI,WAAW,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YAChC,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;gBACrC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAC3B,CAAC,EAAE,QAAQ,CAAC,CAAA;QACd,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,KAAK,EAAE,CAAA;QACT,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO;QACL,KAAK;QACL,KAAK;QACL,QAAQ,EAAE,WAAW,CAAC,OAAO;KAC9B,CAAA;AACH,CAAC"}
|
package/dist/useIsMounted.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useIsMounted = useIsMounted;
|
|
4
|
-
exports.useIsClient = useIsClient;
|
|
5
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect, useLayoutEffect, useState } from 'react';
|
|
6
2
|
const isReactNativeOrServer = typeof navigator !== 'undefined';
|
|
7
|
-
const useIsomorphicLayoutEffect = isReactNativeOrServer ?
|
|
3
|
+
const useIsomorphicLayoutEffect = isReactNativeOrServer ? useLayoutEffect : useEffect;
|
|
8
4
|
/**
|
|
9
5
|
* Hook to check if the component has mounted. SSR safe.
|
|
10
6
|
*
|
|
@@ -14,8 +10,8 @@ const useIsomorphicLayoutEffect = isReactNativeOrServer ? react_1.useLayoutEffec
|
|
|
14
10
|
* // Safe to use browser APIs
|
|
15
11
|
* }
|
|
16
12
|
*/
|
|
17
|
-
function useIsMounted() {
|
|
18
|
-
const [mounted, setMounted] =
|
|
13
|
+
export function useIsMounted() {
|
|
14
|
+
const [mounted, setMounted] = useState(false);
|
|
19
15
|
useIsomorphicLayoutEffect(() => {
|
|
20
16
|
setMounted(true);
|
|
21
17
|
}, []);
|
|
@@ -31,7 +27,7 @@ function useIsMounted() {
|
|
|
31
27
|
* // Safe to use browser APIs
|
|
32
28
|
* }
|
|
33
29
|
*/
|
|
34
|
-
function useIsClient() {
|
|
30
|
+
export function useIsClient() {
|
|
35
31
|
return {
|
|
36
32
|
isClient: useIsMounted(),
|
|
37
33
|
};
|
package/dist/useIsMounted.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsMounted.js","sourceRoot":"","sources":["../src/useIsMounted.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIsMounted.js","sourceRoot":"","sources":["../src/useIsMounted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE5D,MAAM,qBAAqB,GAAG,OAAO,SAAS,KAAK,WAAW,CAAA;AAE9D,MAAM,yBAAyB,GAC7B,qBAAqB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAA;AAErD;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAE7C,yBAAyB,CAAC,GAAG,EAAE;QAC7B,UAAU,CAAC,IAAI,CAAC,CAAA;IAClB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO;QACL,QAAQ,EAAE,YAAY,EAAE;KACzB,CAAA;AACH,CAAC"}
|
package/dist/useLazyStore.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useLazyStore = useLazyStore;
|
|
4
|
-
const store_1 = require("@codeleap/store");
|
|
5
|
-
const react_1 = require("react");
|
|
1
|
+
import { globalState } from '@codeleap/store';
|
|
2
|
+
import { useMemo } from 'react';
|
|
6
3
|
/**
|
|
7
4
|
* Hook that lazily creates a global store with an initial value.
|
|
8
5
|
* The store is created only once and persists across re-renders.
|
|
@@ -11,9 +8,9 @@ const react_1 = require("react");
|
|
|
11
8
|
* const counterStore = useLazyStore(0)
|
|
12
9
|
* // Store is created once and can be used across components
|
|
13
10
|
*/
|
|
14
|
-
function useLazyStore(initialValue) {
|
|
15
|
-
const store =
|
|
16
|
-
return
|
|
11
|
+
export function useLazyStore(initialValue) {
|
|
12
|
+
const store = useMemo(() => {
|
|
13
|
+
return globalState(initialValue);
|
|
17
14
|
}, []);
|
|
18
15
|
return store;
|
|
19
16
|
}
|
package/dist/useLazyStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLazyStore.js","sourceRoot":"","sources":["../src/useLazyStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLazyStore.js","sourceRoot":"","sources":["../src/useLazyStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAI,YAAe;IAC7C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,OAAO,WAAW,CAAC,YAAY,CAAC,CAAA;IAClC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/dist/useModal.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useModal = useModal;
|
|
4
|
-
const types_1 = require("@codeleap/types");
|
|
5
|
-
const react_1 = require("react");
|
|
1
|
+
import { TypeGuards } from '@codeleap/types';
|
|
2
|
+
import { useState } from 'react';
|
|
6
3
|
/**
|
|
7
4
|
* Hook that manages modal visibility state with open, close, and toggle functions.
|
|
8
5
|
*
|
|
@@ -13,8 +10,8 @@ const react_1 = require("react");
|
|
|
13
10
|
* modal.toggle() // Toggles visibility
|
|
14
11
|
* modal.toggle(true) // Forces open
|
|
15
12
|
*/
|
|
16
|
-
function useModal(startsOpen = false) {
|
|
17
|
-
const [visible, setVisible] =
|
|
13
|
+
export function useModal(startsOpen = false) {
|
|
14
|
+
const [visible, setVisible] = useState(startsOpen);
|
|
18
15
|
function open() {
|
|
19
16
|
setVisible(true);
|
|
20
17
|
}
|
|
@@ -22,7 +19,7 @@ function useModal(startsOpen = false) {
|
|
|
22
19
|
setVisible(false);
|
|
23
20
|
}
|
|
24
21
|
function toggle(forceVisible) {
|
|
25
|
-
setVisible(prev =>
|
|
22
|
+
setVisible(prev => TypeGuards.isBoolean(forceVisible) ? forceVisible : !prev);
|
|
26
23
|
}
|
|
27
24
|
return {
|
|
28
25
|
visible,
|
package/dist/useModal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModal.js","sourceRoot":"","sources":["../src/useModal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useModal.js","sourceRoot":"","sources":["../src/useModal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,UAAU,GAAG,KAAK;IACzC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAA;IAElD,SAAS,IAAI;QACX,UAAU,CAAC,IAAI,CAAC,CAAA;IAClB,CAAC;IAED,SAAS,KAAK;QACZ,UAAU,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC;IAED,SAAS,MAAM,CAAC,YAAsB;QACpC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAC/E,CAAC;IAED,OAAO;QACL,OAAO;QACP,MAAM;QACN,IAAI;QACJ,KAAK;KACN,CAAA;AACH,CAAC"}
|
package/dist/useOptions.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useOptions = useOptions;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Hook that manages selected option state with boolean flags for each option.
|
|
7
4
|
*
|
|
@@ -11,9 +8,9 @@ const react_1 = require("react");
|
|
|
11
8
|
* setSelectedOption('dark')
|
|
12
9
|
* // isSelected = { light: false, dark: true }
|
|
13
10
|
*/
|
|
14
|
-
function useOptions(options, initialOptions = options[0]) {
|
|
15
|
-
const [selectedOption, setSelectedOption] =
|
|
16
|
-
const isSelected =
|
|
11
|
+
export function useOptions(options, initialOptions = options[0]) {
|
|
12
|
+
const [selectedOption, setSelectedOption] = useState(initialOptions);
|
|
13
|
+
const isSelected = useMemo(() => {
|
|
17
14
|
return options.reduce((acc, option) => {
|
|
18
15
|
acc[option] = option === selectedOption;
|
|
19
16
|
return acc;
|
package/dist/useOptions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOptions.js","sourceRoot":"","sources":["../src/useOptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useOptions.js","sourceRoot":"","sources":["../src/useOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEzC;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAmB,OAAqB,EAAE,iBAAoB,OAAO,CAAC,CAAC,CAAC;IAChG,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAI,cAAc,CAAC,CAAA;IAEvE,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE;QAC9B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACpC,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,KAAK,cAAc,CAAA;YACvC,OAAO,GAAG,CAAA;QACZ,CAAC,EAAE,EAAwB,CAAC,CAAA;IAC9B,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAA;IAE7B,OAAO;QACL,cAAc;QACd,iBAAiB;QACjB,UAAU;KACX,CAAA;AACH,CAAC"}
|
package/dist/usePartialState.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.usePartialState = usePartialState;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const utils_1 = require("@codeleap/utils");
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { deepMerge } from '@codeleap/utils';
|
|
6
3
|
/**
|
|
7
4
|
* Hook that manages state with partial updates using deep merge.
|
|
8
5
|
*
|
|
@@ -11,14 +8,14 @@ const utils_1 = require("@codeleap/utils");
|
|
|
11
8
|
* setUser({ age: 31 }) // Only updates age, keeps name
|
|
12
9
|
* setUser(prev => ({ age: prev.age + 1 })) // Functional update
|
|
13
10
|
*/
|
|
14
|
-
function usePartialState(initial) {
|
|
15
|
-
const [state, setState] =
|
|
11
|
+
export function usePartialState(initial) {
|
|
12
|
+
const [state, setState] = useState(initial);
|
|
16
13
|
function setPartial(value) {
|
|
17
14
|
if (typeof value === 'function') {
|
|
18
|
-
setState((v) =>
|
|
15
|
+
setState((v) => deepMerge(v, value(v)));
|
|
19
16
|
}
|
|
20
17
|
else {
|
|
21
|
-
setState(
|
|
18
|
+
setState(deepMerge(state, value));
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
return [state, setPartial];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePartialState.js","sourceRoot":"","sources":["../src/usePartialState.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePartialState.js","sourceRoot":"","sources":["../src/usePartialState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAI3C;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAyB,OAAsB;IAC5E,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAE3C,SAAS,UAAU,CACjB,KAAkD;QAElD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YAChC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAM,CAAC,CAAC,CAAC,CAAA;QAC9C,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IAED,OAAO,CAAC,KAAU,EAAE,UAAU,CAAU,CAAA;AAC1C,CAAC"}
|
package/dist/usePlaces.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.usePlaces = exports.retrievePlaces = exports.retrievePlaceDetails = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
18
3
|
const BASE_URL = 'https://maps.googleapis.com/maps/api/place/autocomplete/json';
|
|
19
4
|
const BASE_URL_DETAILS = 'https://maps.googleapis.com/maps/api/place/details/json';
|
|
20
5
|
const BASE_URL_GEOCODING = 'https://maps.googleapis.com/maps/api/geocode/json';
|
|
@@ -22,44 +7,40 @@ const latLngRegex = /^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/;
|
|
|
22
7
|
/**
|
|
23
8
|
* Retrieves detailed information for a specific Google Place.
|
|
24
9
|
*/
|
|
25
|
-
const retrievePlaceDetails = (placeId, apiKey) =>
|
|
26
|
-
|
|
27
|
-
const response = yield axios_1.default.get(BASE_URL_DETAILS, {
|
|
10
|
+
export const retrievePlaceDetails = async (placeId, apiKey) => {
|
|
11
|
+
const response = await axios.get(BASE_URL_DETAILS, {
|
|
28
12
|
params: {
|
|
29
13
|
place_id: placeId,
|
|
30
14
|
key: apiKey,
|
|
31
15
|
},
|
|
32
16
|
});
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
exports.retrievePlaceDetails = retrievePlaceDetails;
|
|
17
|
+
return response?.data?.result;
|
|
18
|
+
};
|
|
36
19
|
/**
|
|
37
20
|
* Retrieves places from Google Places API or Geocoding API.
|
|
38
21
|
* Supports both text search and lat/lng coordinates.
|
|
39
22
|
*/
|
|
40
|
-
const retrievePlaces = (params) =>
|
|
41
|
-
var _a, _b, _c, _d, _e;
|
|
23
|
+
export const retrievePlaces = async (params) => {
|
|
42
24
|
let response;
|
|
43
|
-
const inputWithoutSpaces =
|
|
44
|
-
const isLatLng = latLngRegex
|
|
25
|
+
const inputWithoutSpaces = params?.input?.replace(/\s/g, '') ?? '';
|
|
26
|
+
const isLatLng = latLngRegex?.test(inputWithoutSpaces);
|
|
45
27
|
if (isLatLng) {
|
|
46
|
-
response =
|
|
28
|
+
response = await axios?.get(BASE_URL_GEOCODING, { params: { latlng: params?.input, key: params?.key } });
|
|
47
29
|
}
|
|
48
30
|
else {
|
|
49
|
-
response =
|
|
31
|
+
response = await axios?.get(BASE_URL, { params });
|
|
50
32
|
}
|
|
51
|
-
let places =
|
|
52
|
-
if (params
|
|
53
|
-
const apiKey =
|
|
54
|
-
places =
|
|
55
|
-
const placeId = place
|
|
56
|
-
const details =
|
|
57
|
-
return
|
|
58
|
-
}))
|
|
33
|
+
let places = response?.data?.results || response?.data?.predictions;
|
|
34
|
+
if (params?.showDetails) {
|
|
35
|
+
const apiKey = params?.key ?? '';
|
|
36
|
+
places = await Promise.all(places?.map(async (place) => {
|
|
37
|
+
const placeId = place?.place_id;
|
|
38
|
+
const details = await retrievePlaceDetails(placeId, apiKey);
|
|
39
|
+
return { ...place, details };
|
|
40
|
+
}));
|
|
59
41
|
}
|
|
60
42
|
return places;
|
|
61
|
-
}
|
|
62
|
-
exports.retrievePlaces = retrievePlaces;
|
|
43
|
+
};
|
|
63
44
|
/**
|
|
64
45
|
* Hook that fetches Google Places using React Query.
|
|
65
46
|
* Automatically handles caching and refetching.
|
|
@@ -71,12 +52,11 @@ exports.retrievePlaces = retrievePlaces;
|
|
|
71
52
|
* showDetails: true
|
|
72
53
|
* })
|
|
73
54
|
*/
|
|
74
|
-
const usePlaces = (params) => {
|
|
75
|
-
const places =
|
|
55
|
+
export const usePlaces = (params) => {
|
|
56
|
+
const places = useQuery({
|
|
76
57
|
queryKey: ['places', params],
|
|
77
|
-
queryFn: () =>
|
|
58
|
+
queryFn: () => retrievePlaces(params),
|
|
78
59
|
});
|
|
79
60
|
return places;
|
|
80
61
|
};
|
|
81
|
-
exports.usePlaces = usePlaces;
|
|
82
62
|
//# sourceMappingURL=usePlaces.js.map
|
package/dist/usePlaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePlaces.js","sourceRoot":"","sources":["../src/usePlaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePlaces.js","sourceRoot":"","sources":["../src/usePlaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,MAAM,QAAQ,GAAG,8DAA8D,CAAA;AAC/E,MAAM,gBAAgB,GAAG,yDAAyD,CAAA;AAClF,MAAM,kBAAkB,GAAG,mDAAmD,CAAA;AAE9E,MAAM,WAAW,GAAG,+BAA+B,CAAA;AAQnD;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,OAAe,EAAE,MAAc,EAAE,EAAE;IAC5E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,gBAAgB,EAAE;QACjD,MAAM,EAAE;YACN,QAAQ,EAAE,OAAO;YACjB,GAAG,EAAE,MAAM;SACZ;KACF,CAAC,CAAA;IAEF,OAAO,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAA;AAC/B,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;IACrD,IAAI,QAAQ,CAAA;IACZ,MAAM,kBAAkB,GAAG,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,CAAA;IAClE,MAAM,QAAQ,GAAG,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAA;IAEtD,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,GAAG,MAAM,KAAK,EAAE,GAAG,CAAC,kBAAkB,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;IAC1G,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,MAAM,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;IACnD,CAAC;IAED,IAAI,MAAM,GAAG,QAAQ,EAAE,IAAI,EAAE,OAAO,IAAI,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAA;IAEnE,IAAI,MAAM,EAAE,WAAW,EAAE,CAAC;QACxB,MAAM,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,CAAA;QAChC,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CACxB,MAAM,EAAE,GAAG,CAAC,KAAK,EAAE,KAAU,EAAE,EAAE;YAC/B,MAAM,OAAO,GAAG,KAAK,EAAE,QAAQ,CAAA;YAC/B,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YAC3D,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAA;QAC9B,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAID;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,EAAE;IAC1C,MAAM,MAAM,GAAG,QAAQ,CAAC;QACtB,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC5B,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC;KACtC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.usePlacesAutocompleteUtils = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const types_1 = require("@codeleap/types");
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TypeGuards } from '@codeleap/types';
|
|
9
3
|
/**
|
|
10
4
|
* Hook that manages address autocomplete state with debounced input handling.
|
|
11
5
|
* Useful for Google Places autocomplete implementations.
|
|
@@ -22,15 +16,15 @@ const types_1 = require("@codeleap/types");
|
|
|
22
16
|
* onPress: (addr, item) => console.log('Selected:', item)
|
|
23
17
|
* })
|
|
24
18
|
*/
|
|
25
|
-
const usePlacesAutocompleteUtils = (props) => {
|
|
19
|
+
export const usePlacesAutocompleteUtils = (props) => {
|
|
26
20
|
const { debounce = 250, onValueChange, onPress, } = props;
|
|
27
|
-
const [address, setAddress] =
|
|
28
|
-
const [isTyping, setIsTyping] =
|
|
29
|
-
const setSearchTimeout =
|
|
21
|
+
const [address, setAddress] = React.useState('');
|
|
22
|
+
const [isTyping, setIsTyping] = React.useState(false);
|
|
23
|
+
const setSearchTimeout = React.useRef(null);
|
|
30
24
|
const handleChangeAddress = (address) => {
|
|
31
25
|
setAddress(address);
|
|
32
|
-
if (
|
|
33
|
-
onValueChange
|
|
26
|
+
if (TypeGuards.isNil(debounce)) {
|
|
27
|
+
onValueChange?.(address);
|
|
34
28
|
setTimeout(() => setIsTyping(false), 250);
|
|
35
29
|
}
|
|
36
30
|
else {
|
|
@@ -39,18 +33,18 @@ const usePlacesAutocompleteUtils = (props) => {
|
|
|
39
33
|
setSearchTimeout.current = null;
|
|
40
34
|
}
|
|
41
35
|
setSearchTimeout.current = setTimeout(() => {
|
|
42
|
-
onValueChange
|
|
36
|
+
onValueChange?.(address);
|
|
43
37
|
setIsTyping(false);
|
|
44
|
-
}, debounce
|
|
38
|
+
}, debounce ?? 0);
|
|
45
39
|
}
|
|
46
40
|
};
|
|
47
41
|
const handlePressAddress = (address, item) => {
|
|
48
42
|
setAddress(address);
|
|
49
|
-
onPress
|
|
43
|
+
onPress?.(address, item);
|
|
50
44
|
};
|
|
51
45
|
const handleClearAddress = () => {
|
|
52
46
|
setAddress('');
|
|
53
|
-
onValueChange
|
|
47
|
+
onValueChange?.('');
|
|
54
48
|
};
|
|
55
49
|
return {
|
|
56
50
|
handleChangeAddress,
|
|
@@ -61,5 +55,4 @@ const usePlacesAutocompleteUtils = (props) => {
|
|
|
61
55
|
setIsTyping,
|
|
62
56
|
};
|
|
63
57
|
};
|
|
64
|
-
exports.usePlacesAutocompleteUtils = usePlacesAutocompleteUtils;
|
|
65
58
|
//# sourceMappingURL=usePlacesAutocompleteUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePlacesAutocompleteUtils.js","sourceRoot":"","sources":["../src/usePlacesAutocompleteUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePlacesAutocompleteUtils.js","sourceRoot":"","sources":["../src/usePlacesAutocompleteUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAQ5C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAgC,KAAyC,EAAE,EAAE;IACrH,MAAM,EACJ,QAAQ,GAAG,GAAG,EACd,aAAa,EACb,OAAO,GACR,GAAG,KAAK,CAAA;IAET,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAChD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAErD,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAuC,IAAI,CAAC,CAAA;IAEjF,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAE,EAAE;QAC9C,UAAU,CAAC,OAAO,CAAC,CAAA;QAEnB,IAAI,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,aAAa,EAAE,CAAC,OAAO,CAAC,CAAA;YACxB,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAA;QAC3C,CAAC;aAAM,CAAC;YACN,IAAI,gBAAgB,CAAC,OAAO,EAAE,CAAC;gBAC7B,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;gBACtC,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAA;YACjC,CAAC;YAED,gBAAgB,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBACzC,aAAa,EAAE,CAAC,OAAO,CAAC,CAAA;gBACxB,WAAW,CAAC,KAAK,CAAC,CAAA;YACpB,CAAC,EAAE,QAAQ,IAAI,CAAC,CAAC,CAAA;QACnB,CAAC;IACH,CAAC,CAAA;IAED,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,IAAO,EAAE,EAAE;QACtD,UAAU,CAAC,OAAO,CAAC,CAAA;QACnB,OAAO,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC1B,CAAC,CAAA;IAED,MAAM,kBAAkB,GAAG,GAAG,EAAE;QAC9B,UAAU,CAAC,EAAE,CAAC,CAAA;QACd,aAAa,EAAE,CAAC,EAAE,CAAC,CAAA;IACrB,CAAC,CAAA;IAED,OAAO;QACL,mBAAmB;QACnB,kBAAkB;QAClB,kBAAkB;QAClB,OAAO;QACP,QAAQ;QACR,WAAW;KACZ,CAAA;AACH,CAAC,CAAA"}
|
package/dist/usePrevious.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePrevious = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Hook that returns the previous value of a variable.
|
|
7
4
|
* The value is updated after render is committed to the DOM.
|
|
@@ -12,12 +9,11 @@ const react_1 = require("react");
|
|
|
12
9
|
* // On first render: count=0, prevCount=null
|
|
13
10
|
* // After setCount(1): count=1, prevCount=0
|
|
14
11
|
*/
|
|
15
|
-
const usePrevious = (value) => {
|
|
16
|
-
const ref =
|
|
17
|
-
|
|
12
|
+
export const usePrevious = (value) => {
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
useEffect(() => {
|
|
18
15
|
ref.current = value;
|
|
19
16
|
});
|
|
20
17
|
return ref.current;
|
|
21
18
|
};
|
|
22
|
-
exports.usePrevious = usePrevious;
|
|
23
19
|
//# sourceMappingURL=usePrevious.js.map
|
package/dist/usePrevious.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePrevious.js","sourceRoot":"","sources":["../src/usePrevious.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePrevious.js","sourceRoot":"","sources":["../src/usePrevious.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAEzC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAI,KAAQ,EAAE,EAAE;IACzC,MAAM,GAAG,GAAG,MAAM,CAAI,IAAI,CAAC,CAAA;IAC3B,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAA;IACrB,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAC,OAAO,CAAA;AACpB,CAAC,CAAA"}
|
package/dist/usePromise.js
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.usePromise = void 0;
|
|
13
|
-
const react_1 = require("react");
|
|
14
|
-
const types_1 = require("@codeleap/types");
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { TypeGuards } from '@codeleap/types';
|
|
15
3
|
/**
|
|
16
4
|
* Hook that creates a deferred promise with manual resolve/reject control.
|
|
17
5
|
* Useful for coordinating asynchronous operations across component lifecycle.
|
|
@@ -25,34 +13,32 @@ const types_1 = require("@codeleap/types");
|
|
|
25
13
|
* // Later, from another callback:
|
|
26
14
|
* promise.resolve('success')
|
|
27
15
|
*/
|
|
28
|
-
const usePromise = (options) => {
|
|
29
|
-
const rejectRef =
|
|
30
|
-
const resolveRef =
|
|
31
|
-
const timeoutRef =
|
|
32
|
-
const reject = (err) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(_b = options === null || options === void 0 ? void 0 : options.onReject) === null || _b === void 0 ? void 0 : _b.call(options, err);
|
|
16
|
+
export const usePromise = (options) => {
|
|
17
|
+
const rejectRef = useRef(null);
|
|
18
|
+
const resolveRef = useRef(null);
|
|
19
|
+
const timeoutRef = useRef(null);
|
|
20
|
+
const reject = async (err) => {
|
|
21
|
+
await rejectRef.current?.(err);
|
|
22
|
+
options?.onReject?.(err);
|
|
36
23
|
if (timeoutRef.current)
|
|
37
24
|
clearTimeout(timeoutRef.current);
|
|
38
25
|
rejectRef.current = null;
|
|
39
|
-
}
|
|
40
|
-
const resolve = (value) =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(_b = options === null || options === void 0 ? void 0 : options.onResolve) === null || _b === void 0 ? void 0 : _b.call(options, value);
|
|
26
|
+
};
|
|
27
|
+
const resolve = async (value) => {
|
|
28
|
+
await resolveRef.current?.(value);
|
|
29
|
+
options?.onResolve?.(value);
|
|
44
30
|
if (timeoutRef.current)
|
|
45
31
|
clearTimeout(timeoutRef.current);
|
|
46
32
|
resolveRef.current = null;
|
|
47
|
-
}
|
|
33
|
+
};
|
|
48
34
|
const _await = () => {
|
|
49
35
|
return new Promise((resolve, reject) => {
|
|
50
36
|
rejectRef.current = reject;
|
|
51
37
|
resolveRef.current = resolve;
|
|
52
|
-
if (
|
|
38
|
+
if (TypeGuards.isNumber(options?.timeout) && options?.timeout > 0) {
|
|
53
39
|
timeoutRef.current = setTimeout(() => {
|
|
54
|
-
reject(new Error(`usePromise: ${
|
|
55
|
-
}, options
|
|
40
|
+
reject(new Error(`usePromise: ${options?.debugName || ''} timed out after ${options?.timeout}ms`));
|
|
41
|
+
}, options?.timeout);
|
|
56
42
|
}
|
|
57
43
|
});
|
|
58
44
|
};
|
|
@@ -62,5 +48,4 @@ const usePromise = (options) => {
|
|
|
62
48
|
reject,
|
|
63
49
|
};
|
|
64
50
|
};
|
|
65
|
-
exports.usePromise = usePromise;
|
|
66
51
|
//# sourceMappingURL=usePromise.js.map
|
package/dist/usePromise.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePromise.js","sourceRoot":"","sources":["../src/usePromise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePromise.js","sourceRoot":"","sources":["../src/usePromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAe,MAAM,iBAAiB,CAAA;AASzD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAU,OAA8B,EAAE,EAAE;IACpE,MAAM,SAAS,GAAG,MAAM,CAAc,IAAI,CAAC,CAAA;IAC3C,MAAM,UAAU,GAAG,MAAM,CAAe,IAAI,CAAC,CAAA;IAC7C,MAAM,UAAU,GAAG,MAAM,CAAuC,IAAI,CAAC,CAAA;IAErE,MAAM,MAAM,GAAG,KAAK,EAAE,GAAQ,EAAE,EAAE;QAChC,MAAM,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAA;QAC9B,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAA;QACxB,IAAI,UAAU,CAAC,OAAO;YAAE,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QACxD,SAAS,CAAC,OAAO,GAAG,IAAI,CAAA;IAC1B,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,KAAK,EAAE,KAAQ,EAAE,EAAE;QACjC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;QACjC,OAAO,EAAE,SAAS,EAAE,CAAC,KAAK,CAAC,CAAA;QAC3B,IAAI,UAAU,CAAC,OAAO;YAAE,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QACxD,UAAU,CAAC,OAAO,GAAG,IAAI,CAAA;IAC3B,CAAC,CAAA;IAED,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,SAAS,CAAC,OAAO,GAAG,MAAM,CAAA;YAC1B,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA;YAC5B,IAAI,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,OAAO,EAAE,OAAO,GAAG,CAAC,EAAE,CAAC;gBAClE,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;oBACnC,MAAM,CAAC,IAAI,KAAK,CAAC,eAAe,OAAO,EAAE,SAAS,IAAI,EAAE,oBAAoB,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC,CAAA;gBACpG,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;YACtB,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,OAAO;QACL,MAAM;QACN,OAAO;QACP,MAAM;KACP,CAAA;AACH,CAAC,CAAA"}
|
package/dist/useRenderCall.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRenderCall = useRenderCall;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useRef } from 'react';
|
|
5
2
|
/** Calls `fn` synchronously during render, capped at `maxRunCount` renders (default 1). Does not use effects — execution happens inline during the render phase. */
|
|
6
|
-
function useRenderCall(fn, maxRunCount = 1) {
|
|
7
|
-
const callCount =
|
|
3
|
+
export function useRenderCall(fn, maxRunCount = 1) {
|
|
4
|
+
const callCount = useRef(0);
|
|
8
5
|
if (callCount.current < maxRunCount) {
|
|
9
6
|
callCount.current++;
|
|
10
7
|
fn();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRenderCall.js","sourceRoot":"","sources":["../src/useRenderCall.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRenderCall.js","sourceRoot":"","sources":["../src/useRenderCall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAE9B,oKAAoK;AACpK,MAAM,UAAU,aAAa,CAAC,EAAc,EAAE,WAAW,GAAG,CAAC;IAC3D,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;IAC3B,IAAI,SAAS,CAAC,OAAO,GAAG,WAAW,EAAE,CAAC;QACpC,SAAS,CAAC,OAAO,EAAE,CAAA;QACnB,EAAE,EAAE,CAAA;IACN,CAAC;AACH,CAAC"}
|