@codeleap/hooks 7.0.0 → 7.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 (63) hide show
  1. package/dist/index.js +58 -0
  2. package/dist/index.js.map +1 -0
  3. package/dist/onMount.js +20 -0
  4. package/dist/onMount.js.map +1 -0
  5. package/dist/onUpdate.js +19 -0
  6. package/dist/onUpdate.js.map +1 -0
  7. package/dist/useBooleanToggle.js +25 -0
  8. package/dist/useBooleanToggle.js.map +1 -0
  9. package/dist/useComponentTestId.js +47 -0
  10. package/dist/useComponentTestId.js.map +1 -0
  11. package/dist/useConditionalState.js +27 -0
  12. package/dist/useConditionalState.js.map +1 -0
  13. package/dist/useDebounce.js +28 -0
  14. package/dist/useDebounce.js.map +1 -0
  15. package/dist/useDebounceCallback.js +42 -0
  16. package/dist/useDebounceCallback.js.map +1 -0
  17. package/dist/useDerivedRef.js +20 -0
  18. package/dist/useDerivedRef.js.map +1 -0
  19. package/dist/useDerivedState.js +28 -0
  20. package/dist/useDerivedState.js.map +1 -0
  21. package/dist/useEffectOnce.js +18 -0
  22. package/dist/useEffectOnce.js.map +1 -0
  23. package/dist/useFilteredList.js +24 -0
  24. package/dist/useFilteredList.js.map +1 -0
  25. package/dist/useForceRender.js +16 -0
  26. package/dist/useForceRender.js.map +1 -0
  27. package/dist/useId.js +18 -0
  28. package/dist/useId.js.map +1 -0
  29. package/dist/useInterval.js +49 -0
  30. package/dist/useInterval.js.map +1 -0
  31. package/dist/useIsMounted.js +39 -0
  32. package/dist/useIsMounted.js.map +1 -0
  33. package/dist/useLazyStore.js +20 -0
  34. package/dist/useLazyStore.js.map +1 -0
  35. package/dist/useModal.js +34 -0
  36. package/dist/useModal.js.map +1 -0
  37. package/dist/useOptions.js +28 -0
  38. package/dist/useOptions.js.map +1 -0
  39. package/dist/usePartialState.js +26 -0
  40. package/dist/usePartialState.js.map +1 -0
  41. package/dist/usePlaces.js +82 -0
  42. package/dist/usePlaces.js.map +1 -0
  43. package/dist/usePlacesAutocompleteUtils.js +65 -0
  44. package/dist/usePlacesAutocompleteUtils.js.map +1 -0
  45. package/dist/usePrevious.js +23 -0
  46. package/dist/usePrevious.js.map +1 -0
  47. package/dist/usePromise.js +66 -0
  48. package/dist/usePromise.js.map +1 -0
  49. package/dist/useRenderCall.js +13 -0
  50. package/dist/useRenderCall.js.map +1 -0
  51. package/dist/useSearch/index.js +83 -0
  52. package/dist/useSearch/index.js.map +1 -0
  53. package/dist/useSearch/types.js +3 -0
  54. package/dist/useSearch/types.js.map +1 -0
  55. package/dist/useStableReference.js +15 -0
  56. package/dist/useStableReference.js.map +1 -0
  57. package/dist/useToggle.js +21 -0
  58. package/dist/useToggle.js.map +1 -0
  59. package/dist/useUncontrolled.js +58 -0
  60. package/dist/useUncontrolled.js.map +1 -0
  61. package/dist/useUnmount.js +23 -0
  62. package/dist/useUnmount.js.map +1 -0
  63. package/package.json +9 -9
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.useReducer = exports.useDebugValue = exports.useLayoutEffect = exports.useContext = exports.useCallback = exports.useMemo = exports.useImperativeHandle = exports.useState = exports.useRef = exports.useEffect = void 0;
18
+ const react_1 = require("react");
19
+ Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return react_1.useEffect; } });
20
+ Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return react_1.useRef; } });
21
+ Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return react_1.useState; } });
22
+ Object.defineProperty(exports, "useImperativeHandle", { enumerable: true, get: function () { return react_1.useImperativeHandle; } });
23
+ Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return react_1.useMemo; } });
24
+ Object.defineProperty(exports, "useCallback", { enumerable: true, get: function () { return react_1.useCallback; } });
25
+ Object.defineProperty(exports, "useContext", { enumerable: true, get: function () { return react_1.useContext; } });
26
+ Object.defineProperty(exports, "useLayoutEffect", { enumerable: true, get: function () { return react_1.useLayoutEffect; } });
27
+ Object.defineProperty(exports, "useDebugValue", { enumerable: true, get: function () { return react_1.useDebugValue; } });
28
+ Object.defineProperty(exports, "useReducer", { enumerable: true, get: function () { return react_1.useReducer; } });
29
+ __exportStar(require("./useConditionalState"), exports);
30
+ __exportStar(require("./usePromise"), exports);
31
+ __exportStar(require("./useUncontrolled"), exports);
32
+ __exportStar(require("./useForceRender"), exports);
33
+ __exportStar(require("./useDebounce"), exports);
34
+ __exportStar(require("./useInterval"), exports);
35
+ __exportStar(require("./onMount"), exports);
36
+ __exportStar(require("./onUpdate"), exports);
37
+ __exportStar(require("./usePrevious"), exports);
38
+ __exportStar(require("./useToggle"), exports);
39
+ __exportStar(require("./useBooleanToggle"), exports);
40
+ __exportStar(require("./useModal"), exports);
41
+ __exportStar(require("./usePlaces"), exports);
42
+ __exportStar(require("./usePlacesAutocompleteUtils"), exports);
43
+ __exportStar(require("./useEffectOnce"), exports);
44
+ __exportStar(require("./useUnmount"), exports);
45
+ __exportStar(require("./useSearch"), exports);
46
+ __exportStar(require("./usePartialState"), exports);
47
+ __exportStar(require("./useIsMounted"), exports);
48
+ __exportStar(require("./useComponentTestId"), exports);
49
+ __exportStar(require("./useId"), exports);
50
+ __exportStar(require("./useDebounceCallback"), exports);
51
+ __exportStar(require("./useDerivedRef"), exports);
52
+ __exportStar(require("./useDerivedState"), exports);
53
+ __exportStar(require("./useFilteredList"), exports);
54
+ __exportStar(require("./useLazyStore"), exports);
55
+ __exportStar(require("./useStableReference"), exports);
56
+ __exportStar(require("./useOptions"), exports);
57
+ __exportStar(require("./useRenderCall"), exports);
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAWc;AAiCZ,0FA3CA,iBAAS,OA2CA;AACT,uFA3CA,cAAM,OA2CA;AACN,yFA3CA,gBAAQ,OA2CA;AACR,oGA3CA,2BAAmB,OA2CA;AACnB,wFA3CA,eAAO,OA2CA;AACP,4FA3CA,mBAAW,OA2CA;AACX,2FA3CA,kBAAU,OA2CA;AACV,gGA3CA,uBAAe,OA2CA;AACf,8FA3CA,qBAAa,OA2CA;AACb,2FA3CA,kBAAU,OA2CA;AAxCZ,wDAAqC;AACrC,+CAA4B;AAC5B,oDAAiC;AACjC,mDAAgC;AAChC,gDAA6B;AAC7B,gDAA6B;AAC7B,4CAAyB;AACzB,6CAA0B;AAC1B,gDAA6B;AAC7B,8CAA2B;AAC3B,qDAAkC;AAClC,6CAA0B;AAC1B,8CAA2B;AAC3B,+DAA4C;AAC5C,kDAA+B;AAC/B,+CAA4B;AAC5B,8CAA2B;AAC3B,oDAAiC;AACjC,iDAA8B;AAC9B,uDAAoC;AACpC,0CAAuB;AACvB,wDAAqC;AACrC,kDAA+B;AAC/B,oDAAiC;AACjC,oDAAiC;AACjC,iDAA8B;AAC9B,uDAAoC;AACpC,+CAA4B;AAC5B,kDAA+B"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onMount = void 0;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that runs a function once when the component mounts.
7
+ *
8
+ * @example
9
+ * onMount(() => {
10
+ * console.log('Component mounted')
11
+ * return () => console.log('Component unmounted')
12
+ * })
13
+ */
14
+ const onMount = (func) => {
15
+ (0, react_1.useEffect)(() => {
16
+ return func();
17
+ }, []);
18
+ };
19
+ exports.onMount = onMount;
20
+ //# sourceMappingURL=onMount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onMount.js","sourceRoot":"","sources":["../src/onMount.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAGjC;;;;;;;;GAQG;AACI,MAAM,OAAO,GAAG,CAAC,IAAiB,EAAE,EAAE;IAC3C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AAJY,QAAA,OAAO,WAInB"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onUpdate = void 0;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that runs a function when specified dependencies change.
7
+ *
8
+ * @example
9
+ * onUpdate(() => {
10
+ * console.log('Count changed:', count)
11
+ * }, [count])
12
+ */
13
+ const onUpdate = (func, listeners = []) => {
14
+ (0, react_1.useEffect)(() => {
15
+ return func();
16
+ }, listeners);
17
+ };
18
+ exports.onUpdate = onUpdate;
19
+ //# sourceMappingURL=onUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onUpdate.js","sourceRoot":"","sources":["../src/onUpdate.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAGjC;;;;;;;GAOG;AACI,MAAM,QAAQ,GAAG,CAAC,IAAiB,EAAE,SAAS,GAAG,EAAE,EAAE,EAAE;IAC5D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,EAAE,SAAS,CAAC,CAAA;AACf,CAAC,CAAA;AAJY,QAAA,QAAQ,YAIpB"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useBooleanToggle = useBooleanToggle;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that manages a boolean state with toggle functionality.
7
+ *
8
+ * @example
9
+ * const [isOpen, toggleOpen] = useBooleanToggle(false)
10
+ * toggleOpen() // Toggles the value
11
+ * toggleOpen(true) // Sets to true
12
+ */
13
+ function useBooleanToggle(initial) {
14
+ const [v, setV] = (0, react_1.useState)(initial);
15
+ function toggleOrSet(value) {
16
+ if (typeof value === 'boolean') {
17
+ setV(value);
18
+ }
19
+ else {
20
+ setV((previous) => !previous);
21
+ }
22
+ }
23
+ return [v, toggleOrSet];
24
+ }
25
+ //# sourceMappingURL=useBooleanToggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBooleanToggle.js","sourceRoot":"","sources":["../src/useBooleanToggle.ts"],"names":[],"mappings":";;AAUA,4CAYC;AAtBD,iCAAgC;AAEhC;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAAC,OAAgB;IAC/C,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAA;IAEnC,SAAS,WAAW,CAAC,KAAe;QAClC,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,KAAK,CAAC,CAAA;QACb,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAC,EAAE,WAAW,CAAU,CAAA;AAClC,CAAC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useComponentTestId = void 0;
4
+ const react_1 = require("react");
5
+ const simpleHash = (str) => {
6
+ let hash = 0;
7
+ for (let i = 0; i < str.length; i++) {
8
+ hash = (hash << 5) - hash + str.charCodeAt(i);
9
+ hash |= 0;
10
+ }
11
+ return Math.abs(hash).toString();
12
+ };
13
+ const normalizeProps = (props, keys) => {
14
+ return keys.reduce((acc, key) => {
15
+ if (key === 'children') {
16
+ acc[key] = react_1.Children.map(props[key], (child) => typeof child === 'object' ? '[Component]' : child);
17
+ }
18
+ else {
19
+ acc[key] = props[key];
20
+ }
21
+ return acc;
22
+ }, {});
23
+ };
24
+ const normalizeDebugName = (debugName) => {
25
+ return debugName.trim().replace(/\s+/g, '-').toLowerCase();
26
+ };
27
+ const generateComponentTestId = (componentName, props, keys) => {
28
+ const hasDebugName = typeof (props === null || props === void 0 ? void 0 : props.debugName) === 'string';
29
+ if (hasDebugName)
30
+ return `${componentName}:${normalizeDebugName(props === null || props === void 0 ? void 0 : props.debugName)}`;
31
+ const extractedProps = normalizeProps(props, keys);
32
+ return `${componentName}:${simpleHash(JSON.stringify(extractedProps))}`;
33
+ };
34
+ /**
35
+ * Hook that generates a stable test ID for a component based on its props.
36
+ * Uses debugName if available, otherwise generates a hash from specified prop keys.
37
+ *
38
+ * @example
39
+ * const testId = useComponentTestId(Button, props, ['label', 'variant'])
40
+ * // Returns: "Button:debug-name" or "Button:123456"
41
+ */
42
+ const useComponentTestId = (Component, props, keys) => {
43
+ const testIdRef = (0, react_1.useRef)(generateComponentTestId(Component.styleRegistryName, props, keys));
44
+ return testIdRef.current;
45
+ };
46
+ exports.useComponentTestId = useComponentTestId;
47
+ //# sourceMappingURL=useComponentTestId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComponentTestId.js","sourceRoot":"","sources":["../src/useComponentTestId.ts"],"names":[],"mappings":";;;AACA,iCAAwC;AAExC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAU,EAAE;IACzC,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAC7C,IAAI,IAAI,CAAC,CAAA;IACX,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;AAClC,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,CAAsB,KAAQ,EAAE,IAAoB,EAAc,EAAE;IACzF,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;YACvB,GAAG,CAAC,GAAG,CAAC,GAAG,gBAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAC/F,CAAA;QACH,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;QACvB,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAgB,CAAC,CAAA;AACtB,CAAC,CAAA;AAED,MAAM,kBAAkB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC/C,OAAO,SAAS,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAA;AAC5D,CAAC,CAAA;AAED,MAAM,uBAAuB,GAAG,CAAsB,aAAqB,EAAE,KAAQ,EAAE,IAAoB,EAAE,EAAE;IAC7G,MAAM,YAAY,GAAG,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAA,KAAK,QAAQ,CAAA;IACzD,IAAI,YAAY;QAAE,OAAO,GAAG,aAAa,IAAI,kBAAkB,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAC,EAAE,CAAA;IACnF,MAAM,cAAc,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAClD,OAAO,GAAG,aAAa,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,EAAE,CAAA;AACzE,CAAC,CAAA;AAED;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAAG,CAChC,SAAc,EACd,KAAQ,EACR,IAAoB,EACpB,EAAE;IACF,MAAM,SAAS,GAAG,IAAA,cAAM,EAAC,uBAAuB,CAAC,SAAS,CAAC,iBAAiB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;IAC3F,OAAO,SAAS,CAAC,OAAO,CAAA;AAC1B,CAAC,CAAA;AAPY,QAAA,kBAAkB,sBAO9B"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useConditionalState = void 0;
4
+ const react_1 = require("react");
5
+ const useBooleanToggle_1 = require("./useBooleanToggle");
6
+ /**
7
+ * Hook that uses external state if provided, otherwise creates internal state.
8
+ * Useful for creating controlled/uncontrolled component patterns.
9
+ *
10
+ * @example
11
+ * // Controlled mode
12
+ * const [value, setValue] = useConditionalState(props.value, props.onChange)
13
+ *
14
+ * // Uncontrolled mode
15
+ * const [value, setValue] = useConditionalState(undefined, undefined, { initialValue: 'default' })
16
+ */
17
+ const useConditionalState = (value, setter, options = {}) => {
18
+ const state = (options === null || options === void 0 ? void 0 : options.isBooleanToggle)
19
+ ? (0, useBooleanToggle_1.useBooleanToggle)(options === null || options === void 0 ? void 0 : options.initialValue)
20
+ : (0, react_1.useState)(options === null || options === void 0 ? void 0 : options.initialValue);
21
+ if (typeof value !== 'undefined' && typeof setter === 'function') {
22
+ return [value, setter];
23
+ }
24
+ return state;
25
+ };
26
+ exports.useConditionalState = useConditionalState;
27
+ //# sourceMappingURL=useConditionalState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConditionalState.js","sourceRoot":"","sources":["../src/useConditionalState.ts"],"names":[],"mappings":";;;AAAA,iCAA0D;AAE1D,yDAAqD;AASrD;;;;;;;;;;GAUG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAoB,EACpB,MAAmB,EACnB,UAAyC,EAAE,EACzB,EAAE;IACpB,MAAM,KAAK,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe;QACpC,CAAC,CAAC,IAAA,mCAAgB,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAuB,CAAC;QACpD,CAAC,CAAC,IAAA,gBAAQ,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAC,CAAA;IAEnC,IAAI,OAAO,KAAK,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IACxB,CAAC;IAED,OAAO,KAAoC,CAAA;AAC7C,CAAC,CAAA;AAdY,QAAA,mBAAmB,uBAc/B"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDebounce = useDebounce;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that debounces a value, updating it after a specified delay.
7
+ *
8
+ * @example
9
+ * const [debouncedSearch, resetDebounce] = useDebounce(searchTerm, 500)
10
+ * // debouncedSearch updates 500ms after searchTerm stops changing
11
+ */
12
+ function useDebounce(value, debounce) {
13
+ const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(value);
14
+ const timeoutRef = (0, react_1.useRef)(null);
15
+ const reset = () => {
16
+ if (timeoutRef.current) {
17
+ clearTimeout(timeoutRef.current);
18
+ }
19
+ };
20
+ (0, react_1.useEffect)(() => {
21
+ timeoutRef.current = setTimeout(() => {
22
+ setDebouncedValue(value);
23
+ }, debounce);
24
+ return reset;
25
+ }, [value]);
26
+ return [debouncedValue, reset];
27
+ }
28
+ //# sourceMappingURL=useDebounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.js","sourceRoot":"","sources":["../src/useDebounce.ts"],"names":[],"mappings":";;AASA,kCAsBC;AA/BD,iCAAmD;AAEnD;;;;;;GAMG;AACH,SAAgB,WAAW,CACzB,KAAQ,EACR,QAAgB;IAEhB,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAA;IAE3D,MAAM,UAAU,GAAG,IAAA,cAAM,EAAuC,IAAI,CAAC,CAAA;IAErE,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACvB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QAClC,CAAC;IACH,CAAC,CAAA;IACD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACnC,iBAAiB,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC,EAAE,QAAQ,CAAC,CAAA;QAEZ,OAAO,KAAK,CAAA;IACd,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;AAChC,CAAC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDebounceCallback = useDebounceCallback;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that creates debounced, flush, and cancel functions for a callback.
7
+ *
8
+ * @example
9
+ * const { debounce, flush, cancel } = useDebounceCallback((value) => {
10
+ * console.log(value)
11
+ * }, 500)
12
+ *
13
+ * debounce('hello') // Will call callback after 500ms
14
+ * flush('immediate') // Calls callback immediately
15
+ * cancel() // Cancels pending debounced call
16
+ */
17
+ function useDebounceCallback(callback, delay = 1000) {
18
+ const timeoutRef = (0, react_1.useRef)(null);
19
+ const debounce = (0, react_1.useCallback)((...args) => {
20
+ cancel();
21
+ timeoutRef.current = setTimeout(() => {
22
+ callback(...args);
23
+ timeoutRef.current = null;
24
+ }, delay);
25
+ }, [callback]);
26
+ const flush = (0, react_1.useCallback)((...args) => {
27
+ cancel();
28
+ callback(...args);
29
+ }, [callback]);
30
+ const cancel = (0, react_1.useCallback)(() => {
31
+ if (timeoutRef.current) {
32
+ clearTimeout(timeoutRef.current);
33
+ timeoutRef.current = null;
34
+ }
35
+ }, []);
36
+ return {
37
+ debounce,
38
+ flush,
39
+ cancel,
40
+ };
41
+ }
42
+ //# sourceMappingURL=useDebounceCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounceCallback.js","sourceRoot":"","sources":["../src/useDebounceCallback.ts"],"names":[],"mappings":";;AAcA,kDAgCC;AA9CD,iCAA2C;AAE3C;;;;;;;;;;;GAWG;AACH,SAAgB,mBAAmB,CACjC,QAA8B,EAC9B,KAAK,GAAG,IAAI;IAEZ,MAAM,UAAU,GAAG,IAAA,cAAM,EAAuC,IAAI,CAAC,CAAA;IAErE,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,IAAO,EAAE,EAAE;QAC1C,MAAM,EAAE,CAAA;QAER,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACnC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAA;YACjB,UAAU,CAAC,OAAO,GAAG,IAAI,CAAA;QAC3B,CAAC,EAAE,KAAK,CAAC,CAAA;IACX,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEd,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,IAAO,EAAE,EAAE;QACvC,MAAM,EAAE,CAAA;QACR,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAA;IACnB,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEd,MAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC9B,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACvB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;YAChC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAA;QAC3B,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,QAAQ;QACR,KAAK;QACL,MAAM;KACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDerivedRef = void 0;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that creates a ref that automatically updates when a derived value changes.
7
+ *
8
+ * @example
9
+ * const userNameRef = useDerivedRef(user, (u) => u.name)
10
+ * // userNameRef.current will always contain the latest user name
11
+ */
12
+ const useDerivedRef = (derivedValue, getValue) => {
13
+ const ref = (0, react_1.useRef)(getValue(derivedValue));
14
+ (0, react_1.useEffect)(() => {
15
+ ref.current = getValue(derivedValue);
16
+ }, [derivedValue]);
17
+ return ref;
18
+ };
19
+ exports.useDerivedRef = useDerivedRef;
20
+ //# sourceMappingURL=useDerivedRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDerivedRef.js","sourceRoot":"","sources":["../src/useDerivedRef.ts"],"names":[],"mappings":";;;AAAA,iCAAyC;AAEzC;;;;;;GAMG;AACI,MAAM,aAAa,GAAG,CAC3B,YAAe,EACf,QAAgC,EACL,EAAE;IAC7B,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAA;IAE1C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAA;IACtC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IAElB,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAXY,QAAA,aAAa,iBAWzB"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDerivedState = void 0;
4
+ const utils_1 = require("@codeleap/utils");
5
+ const react_1 = require("react");
6
+ /**
7
+ * Hook that creates a state that synchronizes with a derived value, with customizable equality check.
8
+ *
9
+ * @example
10
+ * const [state, setState] = useDerivedState(props.value, {
11
+ * getValue: (v) => v.id,
12
+ * areEqual: (a, b) => a === b.id
13
+ * })
14
+ */
15
+ const useDerivedState = (derivedValue, options = {}) => {
16
+ const { getValue = (value) => value, transform = (value) => value, areEqual = (currentState, derivedValue) => (0, utils_1.deepEqual)(currentState, derivedValue), } = options;
17
+ const [state, setState] = (0, react_1.useState)(() => getValue(derivedValue));
18
+ (0, react_1.useEffect)(() => {
19
+ const newValue = getValue(derivedValue);
20
+ const stateAreEqual = areEqual(transform(state), transform(derivedValue));
21
+ if (!stateAreEqual) {
22
+ setState(newValue);
23
+ }
24
+ }, [derivedValue]);
25
+ return [state, setState];
26
+ };
27
+ exports.useDerivedState = useDerivedState;
28
+ //# sourceMappingURL=useDerivedState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDerivedState.js","sourceRoot":"","sources":["../src/useDerivedState.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAC3C,iCAA2C;AAQ3C;;;;;;;;GAQG;AACI,MAAM,eAAe,GAAG,CAC7B,YAAe,EACf,UAAyB,EAAE,EACmB,EAAE;IAChD,MAAM,EACJ,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,KAAU,EACrC,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAC5B,QAAQ,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,EAAE,CAAC,IAAA,iBAAS,EAAC,YAAY,EAAE,YAAY,CAAC,GACjF,GAAG,OAAO,CAAA;IAEX,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAA;IAEnE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAA;QAEvC,MAAM,aAAa,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,CAAA;QAEzE,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IAElB,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAC1B,CAAC,CAAA;AAvBY,QAAA,eAAe,mBAuB3B"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useEffectOnce = void 0;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that runs an effect only once when the component mounts.
7
+ *
8
+ * @example
9
+ * useEffectOnce(() => {
10
+ * console.log('Runs only once on mount')
11
+ * return () => console.log('Cleanup on unmount')
12
+ * })
13
+ */
14
+ const useEffectOnce = (effect) => {
15
+ (0, react_1.useEffect)(effect, []);
16
+ };
17
+ exports.useEffectOnce = useEffectOnce;
18
+ //# sourceMappingURL=useEffectOnce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEffectOnce.js","sourceRoot":"","sources":["../src/useEffectOnce.ts"],"names":[],"mappings":";;;AAAA,iCAAiD;AAEjD;;;;;;;;GAQG;AACI,MAAM,aAAa,GAAG,CAAC,MAAsB,EAAE,EAAE;IACtD,IAAA,iBAAS,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AACvB,CAAC,CAAA;AAFY,QAAA,aAAa,iBAEzB"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFilteredList = useFilteredList;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that filters out the first item from a list that matches a predicate.
7
+ *
8
+ * @example
9
+ * const filteredUsers = useFilteredList(users, (user) => user.id === deletedId)
10
+ * // Returns users array without the first user matching the predicate
11
+ */
12
+ function useFilteredList(list, predicate) {
13
+ return (0, react_1.useMemo)(() => {
14
+ if (!list)
15
+ return [];
16
+ const index = list.findIndex(predicate);
17
+ if (index === -1)
18
+ return list;
19
+ const newList = [...list];
20
+ newList.splice(index, 1);
21
+ return newList;
22
+ }, [list, predicate]);
23
+ }
24
+ //# sourceMappingURL=useFilteredList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFilteredList.js","sourceRoot":"","sources":["../src/useFilteredList.ts"],"names":[],"mappings":";;AASA,0CAWC;AApBD,iCAA+B;AAE/B;;;;;;GAMG;AACH,SAAgB,eAAe,CAAI,IAAS,EAAE,SAA+B;IAC3E,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE;QAClB,IAAI,CAAC,IAAI;YAAE,OAAO,EAAE,CAAA;QAEpB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;QACvC,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,OAAO,IAAI,CAAA;QAE7B,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;QACzB,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QACxB,OAAO,OAAO,CAAA;IAChB,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAA;AACvB,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useForceRender = useForceRender;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that returns a function to force a component re-render.
7
+ *
8
+ * @example
9
+ * const forceRender = useForceRender()
10
+ * forceRender() // Forces component to re-render
11
+ */
12
+ function useForceRender() {
13
+ const [_, forceRender] = (0, react_1.useReducer)((x) => x + 1, 0);
14
+ return forceRender;
15
+ }
16
+ //# sourceMappingURL=useForceRender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useForceRender.js","sourceRoot":"","sources":["../src/useForceRender.ts"],"names":[],"mappings":";;AASA,wCAGC;AAZD,iCAAkC;AAElC;;;;;;GAMG;AACH,SAAgB,cAAc;IAC5B,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,IAAA,kBAAU,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IACpD,OAAO,WAAW,CAAA;AACpB,CAAC"}
package/dist/useId.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useId = useId;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that returns a stable ID, using provided ID if available or generating one.
7
+ *
8
+ * @example
9
+ * const id = useId('custom-id') // Returns 'custom-id'
10
+ * const id = useId() // Returns generated ID like ':r1:'
11
+ */
12
+ function useId(id) {
13
+ var _a;
14
+ const defaultId = (0, react_1.useId)();
15
+ const idRef = (0, react_1.useRef)(id);
16
+ return (_a = idRef.current) !== null && _a !== void 0 ? _a : defaultId;
17
+ }
18
+ //# sourceMappingURL=useId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useId.js","sourceRoot":"","sources":["../src/useId.ts"],"names":[],"mappings":";;AASA,sBAKC;AAdD,iCAA+C;AAE/C;;;;;;GAMG;AACH,SAAgB,KAAK,CAAI,EAAM;;IAC7B,MAAM,SAAS,GAAG,IAAA,aAAM,GAAE,CAAA;IAC1B,MAAM,KAAK,GAAG,IAAA,cAAM,EAAC,EAAE,CAAC,CAAA;IAExB,OAAO,MAAA,KAAK,CAAC,OAAO,mCAAI,SAAS,CAAA;AACnC,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useInterval = useInterval;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook that manages an interval with start and clear controls.
7
+ * The handler receives a clear function to stop the interval from within.
8
+ *
9
+ * @example
10
+ * const { start, clear } = useInterval((clearFn) => {
11
+ * console.log('Tick')
12
+ * if (shouldStop) clearFn()
13
+ * }, 1000)
14
+ *
15
+ * start() // Starts the interval
16
+ * clear() // Stops the interval
17
+ */
18
+ function useInterval(handler, interval) {
19
+ const intervalRef = (0, react_1.useRef)(null);
20
+ const handlerRef = (0, react_1.useRef)(handler);
21
+ (0, react_1.useEffect)(() => {
22
+ handlerRef.current = handler;
23
+ }, [handler]);
24
+ const clear = (0, react_1.useCallback)(() => {
25
+ if (intervalRef.current != null) {
26
+ clearInterval(intervalRef.current);
27
+ intervalRef.current = null;
28
+ }
29
+ }, []);
30
+ const start = (0, react_1.useCallback)(() => {
31
+ clear();
32
+ if (intervalRef.current == null) {
33
+ intervalRef.current = setInterval(() => {
34
+ handlerRef.current(clear);
35
+ }, interval);
36
+ }
37
+ }, []);
38
+ (0, react_1.useEffect)(() => {
39
+ return () => {
40
+ clear();
41
+ };
42
+ }, [clear]);
43
+ return {
44
+ clear,
45
+ start,
46
+ interval: intervalRef.current,
47
+ };
48
+ }
49
+ //# sourceMappingURL=useInterval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInterval.js","sourceRoot":"","sources":["../src/useInterval.ts"],"names":[],"mappings":";;AAkBA,kCAoCC;AAtDD,iCAAsD;AAKtD;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CAAC,OAA2B,EAAE,QAAgB;IACvE,MAAM,WAAW,GAAG,IAAA,cAAM,EAAwC,IAAI,CAAC,CAAA;IACvE,MAAM,UAAU,GAAG,IAAA,cAAM,EAAqB,OAAO,CAAC,CAAA;IAEtD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA;IAC9B,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,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,IAAA,mBAAW,EAAC,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,IAAA,iBAAS,EAAC,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"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useIsMounted = useIsMounted;
4
+ exports.useIsClient = useIsClient;
5
+ const react_1 = require("react");
6
+ const isReactNativeOrServer = typeof navigator !== 'undefined';
7
+ const useIsomorphicLayoutEffect = isReactNativeOrServer ? react_1.useLayoutEffect : react_1.useEffect;
8
+ /**
9
+ * Hook to check if the component has mounted. SSR safe.
10
+ *
11
+ * @example
12
+ * const isMounted = useIsMounted()
13
+ * if (isMounted) {
14
+ * // Safe to use browser APIs
15
+ * }
16
+ */
17
+ function useIsMounted() {
18
+ const [mounted, setMounted] = (0, react_1.useState)(false);
19
+ useIsomorphicLayoutEffect(() => {
20
+ setMounted(true);
21
+ }, []);
22
+ return mounted;
23
+ }
24
+ /**
25
+ * Hook to check if the code is running on the client-side.
26
+ * NOTE: This is just a mirror of `useIsMounted` for retrocompatibility reasons
27
+ *
28
+ * @example
29
+ * const { isClient } = useIsClient()
30
+ * if (isClient) {
31
+ * // Safe to use browser APIs
32
+ * }
33
+ */
34
+ function useIsClient() {
35
+ return {
36
+ isClient: useIsMounted(),
37
+ };
38
+ }
39
+ //# sourceMappingURL=useIsMounted.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsMounted.js","sourceRoot":"","sources":["../src/useIsMounted.ts"],"names":[],"mappings":";;AAgBA,oCAQC;AAYD,kCAIC;AAxCD,iCAA4D;AAE5D,MAAM,qBAAqB,GAAG,OAAO,SAAS,KAAK,WAAW,CAAA;AAE9D,MAAM,yBAAyB,GAC7B,qBAAqB,CAAC,CAAC,CAAC,uBAAe,CAAC,CAAC,CAAC,iBAAS,CAAA;AAErD;;;;;;;;GAQG;AACH,SAAgB,YAAY;IAC1B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,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,SAAgB,WAAW;IACzB,OAAO;QACL,QAAQ,EAAE,YAAY,EAAE;KACzB,CAAA;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useLazyStore = useLazyStore;
4
+ const store_1 = require("@codeleap/store");
5
+ const react_1 = require("react");
6
+ /**
7
+ * Hook that lazily creates a global store with an initial value.
8
+ * The store is created only once and persists across re-renders.
9
+ *
10
+ * @example
11
+ * const counterStore = useLazyStore(0)
12
+ * // Store is created once and can be used across components
13
+ */
14
+ function useLazyStore(initialValue) {
15
+ const store = (0, react_1.useMemo)(() => {
16
+ return (0, store_1.globalState)(initialValue);
17
+ }, []);
18
+ return store;
19
+ }
20
+ //# sourceMappingURL=useLazyStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLazyStore.js","sourceRoot":"","sources":["../src/useLazyStore.ts"],"names":[],"mappings":";;AAWA,oCAMC;AAjBD,2CAA6C;AAC7C,iCAA+B;AAE/B;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAI,YAAe;IAC7C,MAAM,KAAK,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QACzB,OAAO,IAAA,mBAAW,EAAC,YAAY,CAAC,CAAA;IAClC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useModal = useModal;
4
+ const types_1 = require("@codeleap/types");
5
+ const react_1 = require("react");
6
+ /**
7
+ * Hook that manages modal visibility state with open, close, and toggle functions.
8
+ *
9
+ * @example
10
+ * const modal = useModal()
11
+ * modal.open() // Opens modal
12
+ * modal.close() // Closes modal
13
+ * modal.toggle() // Toggles visibility
14
+ * modal.toggle(true) // Forces open
15
+ */
16
+ function useModal(startsOpen = false) {
17
+ const [visible, setVisible] = (0, react_1.useState)(startsOpen);
18
+ function open() {
19
+ setVisible(true);
20
+ }
21
+ function close() {
22
+ setVisible(false);
23
+ }
24
+ function toggle(forceVisible) {
25
+ setVisible(prev => types_1.TypeGuards.isBoolean(forceVisible) ? forceVisible : !prev);
26
+ }
27
+ return {
28
+ visible,
29
+ toggle,
30
+ open,
31
+ close,
32
+ };
33
+ }
34
+ //# sourceMappingURL=useModal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useModal.js","sourceRoot":"","sources":["../src/useModal.ts"],"names":[],"mappings":";;AAaA,4BAqBC;AAlCD,2CAA4C;AAC5C,iCAAgC;AAEhC;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,UAAU,GAAG,KAAK;IACzC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,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,kBAAU,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"}