@w3ux/hooks 1.4.0 → 1.5.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/cjs/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./useEffectIgnoreInitial";
2
2
  export * from "./useOnResize";
3
3
  export * from "./useOutsideAlerter";
4
+ export * from "./useSafeContext";
4
5
  export * from "./useSize";
5
6
  export * from "./useTimeLeft";
package/cjs/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./useEffectIgnoreInitial"), exports);
18
18
  __exportStar(require("./useOnResize"), exports);
19
19
  __exportStar(require("./useOutsideAlerter"), exports);
20
+ __exportStar(require("./useSafeContext"), exports);
20
21
  __exportStar(require("./useSize"), exports);
21
22
  __exportStar(require("./useTimeLeft"), exports);
22
23
 
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,2DAAyC;AACzC,gDAA8B;AAC9B,sDAAoC;AACpC,4CAA0B;AAC1B,gDAA8B","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from \"./useEffectIgnoreInitial\";\nexport * from \"./useOnResize\";\nexport * from \"./useOutsideAlerter\";\nexport * from \"./useSize\";\nexport * from \"./useTimeLeft\";\n"]}
1
+ {"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,2DAAyC;AACzC,gDAA8B;AAC9B,sDAAoC;AACpC,mDAAiC;AACjC,4CAA0B;AAC1B,gDAA8B","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from \"./useEffectIgnoreInitial\";\nexport * from \"./useOnResize\";\nexport * from \"./useOutsideAlerter\";\nexport * from \"./useSafeContext\";\nexport * from \"./useSize\";\nexport * from \"./useTimeLeft\";\n"]}
@@ -0,0 +1,3 @@
1
+ import type { Context } from "react";
2
+ export declare const useSafeContext: <T>(ctx: T | null | undefined) => T;
3
+ export declare const createSafeContext: <T>() => [Context<T | null>, () => T];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSafeContext = exports.useSafeContext = void 0;
4
+ const react_1 = require("react");
5
+ const useSafeContext = (ctx) => {
6
+ if (ctx === null || ctx === undefined) {
7
+ throw new Error("Context value is null or undefined. Please ensure the context Provider is used correctly.");
8
+ }
9
+ return ctx;
10
+ };
11
+ exports.useSafeContext = useSafeContext;
12
+ const createSafeContext = () => {
13
+ const Context = (0, react_1.createContext)(null);
14
+ const useHook = () => (0, exports.useSafeContext)((0, react_1.useContext)(Context));
15
+ return [Context, useHook];
16
+ };
17
+ exports.createSafeContext = createSafeContext;
18
+
19
+ //# sourceMappingURL=useSafeContext.js.map
20
+
21
+ //# sourceMappingURL=useSafeContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useSafeContext.tsx"],"names":[],"mappings":";;;AAIA,iCAAkD;AAE3C,MAAM,cAAc,GAAG,CAAK,GAAyB,EAAK,EAAE;IACjE,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAPW,QAAA,cAAc,kBAOzB;AAEK,MAAM,iBAAiB,GAAG,GAAqC,EAAE;IACtE,MAAM,OAAO,GAAG,IAAA,qBAAa,EAAW,IAAI,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAA,sBAAc,EAAI,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC,CAAC;AAJW,QAAA,iBAAiB,qBAI5B","file":"useSafeContext.js","sourcesContent":["// Copyright 2025 @polkadot-cloud/polkadot-staking-dashboard authors & contributors\n// SPDX-License-Identifier: GPL-3.0-only\n\nimport type { Context } from \"react\";\nimport { createContext, useContext } from \"react\";\n\nexport const useSafeContext = <T,>(ctx: T | null | undefined): T => {\n if (ctx === null || ctx === undefined) {\n throw new Error(\n \"Context value is null or undefined. Please ensure the context Provider is used correctly.\"\n );\n }\n return ctx;\n};\n\nexport const createSafeContext = <T,>(): [Context<T | null>, () => T] => {\n const Context = createContext<T | null>(null);\n const useHook = () => useSafeContext<T>(useContext(Context));\n return [Context, useHook];\n};\n"]}
package/mjs/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./useEffectIgnoreInitial";
2
2
  export * from "./useOnResize";
3
3
  export * from "./useOutsideAlerter";
4
+ export * from "./useSafeContext";
4
5
  export * from "./useSize";
5
6
  export * from "./useTimeLeft";
package/mjs/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./useEffectIgnoreInitial";
2
2
  export * from "./useOnResize";
3
3
  export * from "./useOutsideAlerter";
4
+ export * from "./useSafeContext";
4
5
  export * from "./useSize";
5
6
  export * from "./useTimeLeft";
6
7
 
package/mjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":"AAGA,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from \"./useEffectIgnoreInitial\";\nexport * from \"./useOnResize\";\nexport * from \"./useOutsideAlerter\";\nexport * from \"./useSize\";\nexport * from \"./useTimeLeft\";\n"]}
1
+ {"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":"AAGA,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from \"./useEffectIgnoreInitial\";\nexport * from \"./useOnResize\";\nexport * from \"./useOutsideAlerter\";\nexport * from \"./useSafeContext\";\nexport * from \"./useSize\";\nexport * from \"./useTimeLeft\";\n"]}
@@ -0,0 +1,3 @@
1
+ import type { Context } from "react";
2
+ export declare const useSafeContext: <T>(ctx: T | null | undefined) => T;
3
+ export declare const createSafeContext: <T>() => [Context<T | null>, () => T];
@@ -0,0 +1,16 @@
1
+ import { createContext, useContext } from "react";
2
+ export const useSafeContext = (ctx) => {
3
+ if (ctx === null || ctx === undefined) {
4
+ throw new Error("Context value is null or undefined. Please ensure the context Provider is used correctly.");
5
+ }
6
+ return ctx;
7
+ };
8
+ export const createSafeContext = () => {
9
+ const Context = createContext(null);
10
+ const useHook = () => useSafeContext(useContext(Context));
11
+ return [Context, useHook];
12
+ };
13
+
14
+ //# sourceMappingURL=useSafeContext.js.map
15
+
16
+ //# sourceMappingURL=useSafeContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useSafeContext.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAElD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAK,GAAyB,EAAK,EAAE;IACjE,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAqC,EAAE;IACtE,MAAM,OAAO,GAAG,aAAa,CAAW,IAAI,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,cAAc,CAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC,CAAC","file":"useSafeContext.js","sourcesContent":["// Copyright 2025 @polkadot-cloud/polkadot-staking-dashboard authors & contributors\n// SPDX-License-Identifier: GPL-3.0-only\n\nimport type { Context } from \"react\";\nimport { createContext, useContext } from \"react\";\n\nexport const useSafeContext = <T,>(ctx: T | null | undefined): T => {\n if (ctx === null || ctx === undefined) {\n throw new Error(\n \"Context value is null or undefined. Please ensure the context Provider is used correctly.\"\n );\n }\n return ctx;\n};\n\nexport const createSafeContext = <T,>(): [Context<T | null>, () => T] => {\n const Context = createContext<T | null>(null);\n const useHook = () => useSafeContext<T>(useContext(Context));\n return [Context, useHook];\n};\n"]}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@w3ux/hooks",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "license": "GPL-3.0-only",
5
5
  "dependencies": {
6
- "@w3ux/utils": "^1.1.1-beta.9",
6
+ "@w3ux/utils": "^1.2.0",
7
7
  "date-fns": "^4.1.0"
8
8
  },
9
9
  "main": "cjs/index.js",