@kheopskit/react 0.0.10 → 0.0.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @kheopskit/react
2
2
 
3
+ ## 0.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`9d4f86e`](https://github.com/kheopskit/kheopskit/commit/9d4f86e7632843fad089ce930b209aee9b9e2b41)]:
8
+ - @kheopskit/core@0.0.11
9
+
3
10
  ## 0.0.10
4
11
 
5
12
  ### Patch Changes
@@ -0,0 +1,11 @@
1
+ import * as _kheopskit_core from '@kheopskit/core';
2
+ import { KheopskitConfig } from '@kheopskit/core';
3
+ import { FC, PropsWithChildren } from 'react';
4
+
5
+ declare const useWallets: () => _kheopskit_core.KheopskitState;
6
+
7
+ declare const KheopskitProvider: FC<PropsWithChildren & {
8
+ config?: Partial<KheopskitConfig>;
9
+ }>;
10
+
11
+ export { KheopskitProvider, useWallets };
@@ -0,0 +1,11 @@
1
+ import * as _kheopskit_core from '@kheopskit/core';
2
+ import { KheopskitConfig } from '@kheopskit/core';
3
+ import { FC, PropsWithChildren } from 'react';
4
+
5
+ declare const useWallets: () => _kheopskit_core.KheopskitState;
6
+
7
+ declare const KheopskitProvider: FC<PropsWithChildren & {
8
+ config?: Partial<KheopskitConfig>;
9
+ }>;
10
+
11
+ export { KheopskitProvider, useWallets };
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ KheopskitProvider: () => KheopskitProvider,
24
+ useWallets: () => useWallets
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/useWallets.ts
29
+ var import_react2 = require("react");
30
+
31
+ // src/context.ts
32
+ var import_react = require("react");
33
+ var KheopskitContext = (0, import_react.createContext)(null);
34
+
35
+ // src/useWallets.ts
36
+ var useWallets = () => {
37
+ const ctx = (0, import_react2.useContext)(KheopskitContext);
38
+ if (!ctx)
39
+ throw new Error("useWallets can't be used without a KheopskitProvider");
40
+ return ctx.state;
41
+ };
42
+
43
+ // src/KheopskitProvider.tsx
44
+ var import_core = require("@kheopskit/core");
45
+ var import_react3 = require("react");
46
+
47
+ // src/createStore.ts
48
+ var import_rxjs = require("rxjs");
49
+ var createStore = (observable$, initialValue) => {
50
+ const subject = new import_rxjs.BehaviorSubject(initialValue);
51
+ const sub = observable$.subscribe((value) => {
52
+ subject.next(value);
53
+ });
54
+ const getSnapshot = () => subject.getValue();
55
+ const subscribe = (callback) => {
56
+ const sub2 = subject.subscribe(callback);
57
+ return () => {
58
+ sub2.unsubscribe();
59
+ };
60
+ };
61
+ const destroy = () => {
62
+ sub.unsubscribe();
63
+ };
64
+ return {
65
+ getSnapshot,
66
+ subscribe,
67
+ destroy
68
+ };
69
+ };
70
+
71
+ // src/KheopskitProvider.tsx
72
+ var import_jsx_runtime = require("react/jsx-runtime");
73
+ var KheopskitProvider = ({ children, config }) => {
74
+ const defaultValue = (0, import_react3.useMemo)(
75
+ () => ({
76
+ wallets: [],
77
+ accounts: [],
78
+ config: (0, import_core.resolveConfig)(config)
79
+ }),
80
+ [config]
81
+ );
82
+ const store = (0, import_react3.useMemo)(
83
+ () => createStore((0, import_core.getKheopskit$)(config), defaultValue),
84
+ [config, defaultValue]
85
+ );
86
+ const state = (0, import_react3.useSyncExternalStore)(store.subscribe, store.getSnapshot);
87
+ const value = (0, import_react3.useMemo)(() => ({ state }), [state]);
88
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(KheopskitContext.Provider, { value, children });
89
+ };
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ KheopskitProvider,
93
+ useWallets
94
+ });
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/useWallets.ts","../src/context.ts","../src/KheopskitProvider.tsx","../src/createStore.ts"],"sourcesContent":["export * from \"./useWallets\";\nexport * from \"./KheopskitProvider\";\n","import { useContext } from \"react\";\nimport { KheopskitContext } from \"./context\";\n\nexport const useWallets = () => {\n const ctx = useContext(KheopskitContext);\n\n // useEffect(() => {\n // console.debug(\n // \"useWallets wallets:%s accounts:%s\",\n // ctx?.state.wallets.length ?? 0,\n // ctx?.state.accounts.length ?? 0,\n // );\n // }, [ctx?.state]);\n\n if (!ctx)\n throw new Error(\"useWallets can't be used without a KheopskitProvider\");\n\n return ctx.state;\n};\n","import type { KheopskitState } from \"@kheopskit/core\";\nimport { createContext } from \"react\";\n\nexport const KheopskitContext = createContext<{\n state: KheopskitState;\n} | null>(null);\n","import {\n type KheopskitConfig,\n type KheopskitState,\n getKheopskit$,\n resolveConfig,\n} from \"@kheopskit/core\";\nimport {\n type FC,\n type PropsWithChildren,\n useMemo,\n useSyncExternalStore,\n} from \"react\";\nimport { KheopskitContext } from \"./context\";\nimport { createStore } from \"./createStore\";\n\nexport const KheopskitProvider: FC<\n PropsWithChildren & { config?: Partial<KheopskitConfig> }\n> = ({ children, config }) => {\n const defaultValue = useMemo<KheopskitState>(\n () => ({\n wallets: [],\n accounts: [],\n config: resolveConfig(config),\n }),\n [config],\n );\n\n const store = useMemo(\n () => createStore(getKheopskit$(config), defaultValue),\n [config, defaultValue],\n );\n\n const state = useSyncExternalStore(store.subscribe, store.getSnapshot);\n\n const value = useMemo(() => ({ state }), [state]);\n\n return (\n <KheopskitContext.Provider value={value}>\n {children}\n </KheopskitContext.Provider>\n );\n};\n","import { BehaviorSubject, type Observable } from \"rxjs\";\n\nexport const createStore = <T>(observable$: Observable<T>, initialValue: T) => {\n const subject = new BehaviorSubject<T>(initialValue);\n\n const sub = observable$.subscribe((value) => {\n subject.next(value);\n });\n\n const getSnapshot = () => subject.getValue();\n\n const subscribe = (callback: (value: T) => void) => {\n const sub = subject.subscribe(callback);\n\n return () => {\n sub.unsubscribe();\n };\n };\n\n const destroy = () => {\n sub.unsubscribe();\n };\n\n return {\n getSnapshot,\n subscribe,\n destroy,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA2B;;;ACC3B,mBAA8B;AAEvB,IAAM,uBAAmB,4BAEtB,IAAI;;;ADFP,IAAM,aAAa,MAAM;AAC9B,QAAM,UAAM,0BAAW,gBAAgB;AAUvC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,sDAAsD;AAExE,SAAO,IAAI;AACb;;;AElBA,kBAKO;AACP,IAAAC,gBAKO;;;ACXP,kBAAiD;AAE1C,IAAM,cAAc,CAAI,aAA4B,iBAAoB;AAC7E,QAAM,UAAU,IAAI,4BAAmB,YAAY;AAEnD,QAAM,MAAM,YAAY,UAAU,CAAC,UAAU;AAC3C,YAAQ,KAAK,KAAK;AAAA,EACpB,CAAC;AAED,QAAM,cAAc,MAAM,QAAQ,SAAS;AAE3C,QAAM,YAAY,CAAC,aAAiC;AAClD,UAAMC,OAAM,QAAQ,UAAU,QAAQ;AAEtC,WAAO,MAAM;AACX,MAAAA,KAAI,YAAY;AAAA,IAClB;AAAA,EACF;AAEA,QAAM,UAAU,MAAM;AACpB,QAAI,YAAY;AAAA,EAClB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;ADSI;AAtBG,IAAM,oBAET,CAAC,EAAE,UAAU,OAAO,MAAM;AAC5B,QAAM,mBAAe;AAAA,IACnB,OAAO;AAAA,MACL,SAAS,CAAC;AAAA,MACV,UAAU,CAAC;AAAA,MACX,YAAQ,2BAAc,MAAM;AAAA,IAC9B;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AAEA,QAAM,YAAQ;AAAA,IACZ,MAAM,gBAAY,2BAAc,MAAM,GAAG,YAAY;AAAA,IACrD,CAAC,QAAQ,YAAY;AAAA,EACvB;AAEA,QAAM,YAAQ,oCAAqB,MAAM,WAAW,MAAM,WAAW;AAErE,QAAM,YAAQ,uBAAQ,OAAO,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC;AAEhD,SACE,4CAAC,iBAAiB,UAAjB,EAA0B,OACxB,UACH;AAEJ;","names":["import_react","import_react","sub"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,73 @@
1
+ // src/useWallets.ts
2
+ import { useContext } from "react";
3
+
4
+ // src/context.ts
5
+ import { createContext } from "react";
6
+ var KheopskitContext = createContext(null);
7
+
8
+ // src/useWallets.ts
9
+ var useWallets = () => {
10
+ const ctx = useContext(KheopskitContext);
11
+ if (!ctx)
12
+ throw new Error("useWallets can't be used without a KheopskitProvider");
13
+ return ctx.state;
14
+ };
15
+
16
+ // src/KheopskitProvider.tsx
17
+ import {
18
+ getKheopskit$,
19
+ resolveConfig
20
+ } from "@kheopskit/core";
21
+ import {
22
+ useMemo,
23
+ useSyncExternalStore
24
+ } from "react";
25
+
26
+ // src/createStore.ts
27
+ import { BehaviorSubject } from "rxjs";
28
+ var createStore = (observable$, initialValue) => {
29
+ const subject = new BehaviorSubject(initialValue);
30
+ const sub = observable$.subscribe((value) => {
31
+ subject.next(value);
32
+ });
33
+ const getSnapshot = () => subject.getValue();
34
+ const subscribe = (callback) => {
35
+ const sub2 = subject.subscribe(callback);
36
+ return () => {
37
+ sub2.unsubscribe();
38
+ };
39
+ };
40
+ const destroy = () => {
41
+ sub.unsubscribe();
42
+ };
43
+ return {
44
+ getSnapshot,
45
+ subscribe,
46
+ destroy
47
+ };
48
+ };
49
+
50
+ // src/KheopskitProvider.tsx
51
+ import { jsx } from "react/jsx-runtime";
52
+ var KheopskitProvider = ({ children, config }) => {
53
+ const defaultValue = useMemo(
54
+ () => ({
55
+ wallets: [],
56
+ accounts: [],
57
+ config: resolveConfig(config)
58
+ }),
59
+ [config]
60
+ );
61
+ const store = useMemo(
62
+ () => createStore(getKheopskit$(config), defaultValue),
63
+ [config, defaultValue]
64
+ );
65
+ const state = useSyncExternalStore(store.subscribe, store.getSnapshot);
66
+ const value = useMemo(() => ({ state }), [state]);
67
+ return /* @__PURE__ */ jsx(KheopskitContext.Provider, { value, children });
68
+ };
69
+ export {
70
+ KheopskitProvider,
71
+ useWallets
72
+ };
73
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useWallets.ts","../src/context.ts","../src/KheopskitProvider.tsx","../src/createStore.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { KheopskitContext } from \"./context\";\n\nexport const useWallets = () => {\n const ctx = useContext(KheopskitContext);\n\n // useEffect(() => {\n // console.debug(\n // \"useWallets wallets:%s accounts:%s\",\n // ctx?.state.wallets.length ?? 0,\n // ctx?.state.accounts.length ?? 0,\n // );\n // }, [ctx?.state]);\n\n if (!ctx)\n throw new Error(\"useWallets can't be used without a KheopskitProvider\");\n\n return ctx.state;\n};\n","import type { KheopskitState } from \"@kheopskit/core\";\nimport { createContext } from \"react\";\n\nexport const KheopskitContext = createContext<{\n state: KheopskitState;\n} | null>(null);\n","import {\n type KheopskitConfig,\n type KheopskitState,\n getKheopskit$,\n resolveConfig,\n} from \"@kheopskit/core\";\nimport {\n type FC,\n type PropsWithChildren,\n useMemo,\n useSyncExternalStore,\n} from \"react\";\nimport { KheopskitContext } from \"./context\";\nimport { createStore } from \"./createStore\";\n\nexport const KheopskitProvider: FC<\n PropsWithChildren & { config?: Partial<KheopskitConfig> }\n> = ({ children, config }) => {\n const defaultValue = useMemo<KheopskitState>(\n () => ({\n wallets: [],\n accounts: [],\n config: resolveConfig(config),\n }),\n [config],\n );\n\n const store = useMemo(\n () => createStore(getKheopskit$(config), defaultValue),\n [config, defaultValue],\n );\n\n const state = useSyncExternalStore(store.subscribe, store.getSnapshot);\n\n const value = useMemo(() => ({ state }), [state]);\n\n return (\n <KheopskitContext.Provider value={value}>\n {children}\n </KheopskitContext.Provider>\n );\n};\n","import { BehaviorSubject, type Observable } from \"rxjs\";\n\nexport const createStore = <T>(observable$: Observable<T>, initialValue: T) => {\n const subject = new BehaviorSubject<T>(initialValue);\n\n const sub = observable$.subscribe((value) => {\n subject.next(value);\n });\n\n const getSnapshot = () => subject.getValue();\n\n const subscribe = (callback: (value: T) => void) => {\n const sub = subject.subscribe(callback);\n\n return () => {\n sub.unsubscribe();\n };\n };\n\n const destroy = () => {\n sub.unsubscribe();\n };\n\n return {\n getSnapshot,\n subscribe,\n destroy,\n };\n};\n"],"mappings":";AAAA,SAAS,kBAAkB;;;ACC3B,SAAS,qBAAqB;AAEvB,IAAM,mBAAmB,cAEtB,IAAI;;;ADFP,IAAM,aAAa,MAAM;AAC9B,QAAM,MAAM,WAAW,gBAAgB;AAUvC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,sDAAsD;AAExE,SAAO,IAAI;AACb;;;AElBA;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAGE;AAAA,EACA;AAAA,OACK;;;ACXP,SAAS,uBAAwC;AAE1C,IAAM,cAAc,CAAI,aAA4B,iBAAoB;AAC7E,QAAM,UAAU,IAAI,gBAAmB,YAAY;AAEnD,QAAM,MAAM,YAAY,UAAU,CAAC,UAAU;AAC3C,YAAQ,KAAK,KAAK;AAAA,EACpB,CAAC;AAED,QAAM,cAAc,MAAM,QAAQ,SAAS;AAE3C,QAAM,YAAY,CAAC,aAAiC;AAClD,UAAMA,OAAM,QAAQ,UAAU,QAAQ;AAEtC,WAAO,MAAM;AACX,MAAAA,KAAI,YAAY;AAAA,IAClB;AAAA,EACF;AAEA,QAAM,UAAU,MAAM;AACpB,QAAI,YAAY;AAAA,EAClB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;ADSI;AAtBG,IAAM,oBAET,CAAC,EAAE,UAAU,OAAO,MAAM;AAC5B,QAAM,eAAe;AAAA,IACnB,OAAO;AAAA,MACL,SAAS,CAAC;AAAA,MACV,UAAU,CAAC;AAAA,MACX,QAAQ,cAAc,MAAM;AAAA,IAC9B;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AAEA,QAAM,QAAQ;AAAA,IACZ,MAAM,YAAY,cAAc,MAAM,GAAG,YAAY;AAAA,IACrD,CAAC,QAAQ,YAAY;AAAA,EACvB;AAEA,QAAM,QAAQ,qBAAqB,MAAM,WAAW,MAAM,WAAW;AAErE,QAAM,QAAQ,QAAQ,OAAO,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC;AAEhD,SACE,oBAAC,iBAAiB,UAAjB,EAA0B,OACxB,UACH;AAEJ;","names":["sub"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kheopskit/react",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -29,7 +29,7 @@
29
29
  "rxjs": ">=7.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "@kheopskit/core": "0.0.10"
32
+ "@kheopskit/core": "0.0.11"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/react": "^19.1.5",