@bigmi/react 0.7.1 → 0.8.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/dist/cjs/context.d.ts +15 -0
- package/dist/cjs/context.js +16 -0
- package/dist/cjs/context.js.map +1 -0
- package/dist/cjs/errors/context.d.ts +13 -0
- package/dist/cjs/errors/context.js +13 -0
- package/dist/cjs/errors/context.js.map +1 -0
- package/dist/cjs/hooks/useAccount.d.ts +11 -0
- package/dist/cjs/hooks/useAccount.js +26 -0
- package/dist/cjs/hooks/useAccount.js.map +1 -0
- package/dist/cjs/hooks/useConfig.d.ts +13 -0
- package/dist/cjs/hooks/useConfig.js +15 -0
- package/dist/cjs/hooks/useConfig.js.map +1 -0
- package/dist/cjs/hooks/useConnect.d.ts +20 -0
- package/dist/cjs/hooks/useConnect.js +32 -0
- package/dist/cjs/hooks/useConnect.js.map +1 -0
- package/dist/cjs/hooks/useConnectors.d.ts +11 -0
- package/dist/cjs/hooks/useConnectors.js +15 -0
- package/dist/cjs/hooks/useConnectors.js.map +1 -0
- package/dist/cjs/hooks/useReconnect.d.ts +7 -0
- package/dist/cjs/hooks/useReconnect.js +14 -0
- package/dist/cjs/hooks/useReconnect.js.map +1 -0
- package/dist/cjs/hooks/useSyncExternalStoreWithTracked.d.ts +5 -0
- package/dist/cjs/hooks/useSyncExternalStoreWithTracked.js +41 -0
- package/dist/cjs/hooks/useSyncExternalStoreWithTracked.js.map +1 -0
- package/dist/cjs/hydrate.d.ts +21 -0
- package/dist/cjs/hydrate.js +45 -0
- package/dist/cjs/hydrate.js.map +1 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +12 -0
- package/dist/cjs/types.js +0 -0
- package/dist/cjs/utils/query.d.ts +9 -0
- package/dist/cjs/utils/query.js +1 -0
- package/dist/cjs/version.d.ts +6 -0
- package/dist/cjs/version.js +9 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/context.d.ts +14 -9
- package/dist/esm/context.d.ts.map +1 -0
- package/dist/esm/context.js +12 -8
- package/dist/esm/context.js.map +1 -1
- package/dist/esm/errors/context.d.ts +11 -6
- package/dist/esm/errors/context.d.ts.map +1 -0
- package/dist/esm/errors/context.js +11 -7
- package/dist/esm/errors/context.js.map +1 -1
- package/dist/esm/hooks/useAccount.d.ts +11 -6
- package/dist/esm/hooks/useAccount.d.ts.map +1 -0
- package/dist/esm/hooks/useAccount.js +23 -7
- package/dist/esm/hooks/useAccount.js.map +1 -1
- package/dist/esm/hooks/useConfig.d.ts +12 -7
- package/dist/esm/hooks/useConfig.d.ts.map +1 -0
- package/dist/esm/hooks/useConfig.js +12 -11
- package/dist/esm/hooks/useConfig.js.map +1 -1
- package/dist/esm/hooks/useConnect.d.ts +18 -13
- package/dist/esm/hooks/useConnect.d.ts.map +1 -0
- package/dist/esm/hooks/useConnect.js +29 -28
- package/dist/esm/hooks/useConnect.js.map +1 -1
- package/dist/esm/hooks/useConnectors.d.ts +11 -6
- package/dist/esm/hooks/useConnectors.d.ts.map +1 -0
- package/dist/esm/hooks/useConnectors.js +12 -7
- package/dist/esm/hooks/useConnectors.js.map +1 -1
- package/dist/esm/hooks/useReconnect.d.ts +7 -2
- package/dist/esm/hooks/useReconnect.d.ts.map +1 -0
- package/dist/esm/hooks/useReconnect.js +11 -7
- package/dist/esm/hooks/useReconnect.js.map +1 -1
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.d.ts +5 -1
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.d.ts.map +1 -0
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.js +38 -42
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.js.map +1 -1
- package/dist/esm/hydrate.d.ts +17 -13
- package/dist/esm/hydrate.d.ts.map +1 -0
- package/dist/esm/hydrate.js +40 -58
- package/dist/esm/hydrate.js.map +1 -1
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +6 -6
- package/dist/esm/package.json +1 -0
- package/dist/esm/types.d.ts +11 -6
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +0 -1
- package/dist/esm/utils/query.d.ts +9 -4
- package/dist/esm/utils/query.d.ts.map +1 -0
- package/dist/esm/utils/query.js +1 -2
- package/dist/esm/version.d.ts +6 -2
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +6 -2
- package/dist/esm/version.js.map +1 -1
- package/package.json +3 -3
- package/src/context.ts +10 -5
- package/src/hooks/useAccount.ts +15 -1
- package/src/hooks/useConnectors.ts +3 -1
- package/src/hooks/useReconnect.ts +1 -1
- package/src/hooks/useSyncExternalStoreWithTracked.ts +1 -1
- package/src/hydrate.ts +5 -2
- package/src/version.ts +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utils/query.js.map +0 -1
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ResolvedRegister } from "../types.js";
|
|
2
|
+
import { ConfigParameter } from "./useConfig.js";
|
|
3
|
+
import { Config, GetAccountReturnType } from "@bigmi/client";
|
|
4
|
+
|
|
5
|
+
//#region src/hooks/useAccount.d.ts
|
|
6
|
+
type UseAccountParameters<config extends Config = Config> = ConfigParameter<config>;
|
|
7
|
+
type UseAccountReturnType<config extends Config = Config> = GetAccountReturnType<config>;
|
|
8
|
+
declare function useAccount<C extends Config = ResolvedRegister["config"]>(parameters?: UseAccountParameters<C>): UseAccountReturnType<C>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { UseAccountParameters, UseAccountReturnType, useAccount };
|
|
11
|
+
//# sourceMappingURL=useAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAccount.d.ts","names":[],"sources":["../../../src/hooks/useAccount.ts"],"mappings":";;;;;KAaY,oBAAA,gBAAoC,MAAA,GAAS,MAAA,IACvD,eAAA,CAAgB,MAAA;AAAA,KAEN,oBAAA,gBAAoC,MAAA,GAAS,MAAA,IACvD,oBAAA,CAAqB,MAAA;AAAA,iBAeP,UAAA,WAAqB,MAAA,GAAS,gBAAA,WAAA,CAC5C,UAAA,GAAY,oBAAA,CAAqB,CAAA,IAChC,oBAAA,CAAqB,CAAA"}
|
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { useConfig } from "./useConfig.js";
|
|
3
|
+
import { useSyncExternalStoreWithTracked } from "./useSyncExternalStoreWithTracked.js";
|
|
4
|
+
import { getAccount, watchAccount } from "@bigmi/client";
|
|
5
|
+
//#region src/hooks/useAccount.ts
|
|
6
|
+
const DISCONNECTED_ACCOUNT = {
|
|
7
|
+
account: void 0,
|
|
8
|
+
accounts: void 0,
|
|
9
|
+
chain: void 0,
|
|
10
|
+
chainId: void 0,
|
|
11
|
+
connector: void 0,
|
|
12
|
+
isConnected: false,
|
|
13
|
+
isConnecting: false,
|
|
14
|
+
isDisconnected: true,
|
|
15
|
+
isReconnecting: false,
|
|
16
|
+
status: "disconnected"
|
|
17
|
+
};
|
|
18
|
+
function useAccount(parameters = {}) {
|
|
19
|
+
const config = useConfig(parameters);
|
|
20
|
+
return useSyncExternalStoreWithTracked((onChange) => watchAccount(config, { onChange }), () => getAccount(config), () => DISCONNECTED_ACCOUNT);
|
|
8
21
|
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { useAccount };
|
|
24
|
+
|
|
9
25
|
//# sourceMappingURL=useAccount.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccount.js","
|
|
1
|
+
{"version":3,"file":"useAccount.js","names":[],"sources":["../../../src/hooks/useAccount.ts"],"sourcesContent":["'use client'\n\nimport {\n type Config,\n type GetAccountReturnType,\n getAccount,\n watchAccount,\n} from '@bigmi/client'\n\nimport type { ResolvedRegister } from '../types.js'\nimport { type ConfigParameter, useConfig } from './useConfig.js'\nimport { useSyncExternalStoreWithTracked } from './useSyncExternalStoreWithTracked.js'\n\nexport type UseAccountParameters<config extends Config = Config> =\n ConfigParameter<config>\n\nexport type UseAccountReturnType<config extends Config = Config> =\n GetAccountReturnType<config>\n\nconst DISCONNECTED_ACCOUNT: GetAccountReturnType = {\n account: undefined,\n accounts: undefined,\n chain: undefined,\n chainId: undefined,\n connector: undefined,\n isConnected: false,\n isConnecting: false,\n isDisconnected: true,\n isReconnecting: false,\n status: 'disconnected',\n}\n\nexport function useAccount<C extends Config = ResolvedRegister['config']>(\n parameters: UseAccountParameters<C> = {}\n): UseAccountReturnType<C> {\n const config = useConfig(parameters)\n\n return useSyncExternalStoreWithTracked(\n (onChange) => watchAccount(config, { onChange }),\n () => getAccount(config),\n () => DISCONNECTED_ACCOUNT as UseAccountReturnType<C>\n )\n}\n"],"mappings":";;;;;AAmBA,MAAM,uBAA6C;CACjD,SAAS,KAAA;CACT,UAAU,KAAA;CACV,OAAO,KAAA;CACP,SAAS,KAAA;CACT,WAAW,KAAA;CACX,aAAa;CACb,cAAc;CACd,gBAAgB;CAChB,gBAAgB;CAChB,QAAQ;CACT;AAED,SAAgB,WACd,aAAsC,EAAE,EACf;CACzB,MAAM,SAAS,UAAU,WAAW;AAEpC,QAAO,iCACJ,aAAa,aAAa,QAAQ,EAAE,UAAU,CAAC,QAC1C,WAAW,OAAO,QAClB,qBACP"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ResolvedRegister } from "../types.js";
|
|
2
|
+
import { Config } from "@bigmi/client";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/useConfig.d.ts
|
|
5
|
+
type ConfigParameter<config extends Config = Config> = {
|
|
6
|
+
config?: Config | config | undefined;
|
|
5
7
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
type UseConfigParameters<config extends Config = Config> = ConfigParameter<config>;
|
|
9
|
+
type UseConfigReturnType<config extends Config = Config> = config;
|
|
10
|
+
declare function useConfig<C extends Config = ResolvedRegister["config"]>(parameters?: UseConfigParameters<C>): UseConfigReturnType<C>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ConfigParameter, UseConfigParameters, UseConfigReturnType, useConfig };
|
|
13
|
+
//# sourceMappingURL=useConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConfig.d.ts","names":[],"sources":["../../../src/hooks/useConfig.ts"],"mappings":";;;;KAQY,eAAA,gBAA+B,MAAA,GAAS,MAAA;EAClD,MAAA,GAAS,MAAA,GAAS,MAAA;AAAA;AAAA,KAGR,mBAAA,gBAAmC,MAAA,GAAS,MAAA,IACtD,eAAA,CAAgB,MAAA;AAAA,KAEN,mBAAA,gBAAmC,MAAA,GAAS,MAAA,IAAU,MAAA;AAAA,iBAElD,SAAA,WAAoB,MAAA,GAAS,gBAAA,WAAA,CAC3C,UAAA,GAAY,mBAAA,CAAoB,CAAA,IAC/B,mBAAA,CAAoB,CAAA"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return config;
|
|
1
|
+
"use client";
|
|
2
|
+
import { BigmiContext } from "../context.js";
|
|
3
|
+
import { BigmiProviderNotFoundError } from "../errors/context.js";
|
|
4
|
+
import { useContext } from "react";
|
|
5
|
+
//#region src/hooks/useConfig.ts
|
|
6
|
+
function useConfig(parameters = {}) {
|
|
7
|
+
const config = parameters.config ?? useContext(BigmiContext);
|
|
8
|
+
if (!config) throw new BigmiProviderNotFoundError();
|
|
9
|
+
return config;
|
|
12
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useConfig };
|
|
13
|
+
|
|
13
14
|
//# sourceMappingURL=useConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConfig.js","
|
|
1
|
+
{"version":3,"file":"useConfig.js","names":[],"sources":["../../../src/hooks/useConfig.ts"],"sourcesContent":["'use client'\n\nimport type { Config } from '@bigmi/client'\nimport { useContext } from 'react'\nimport { BigmiContext } from '../context.js'\nimport { BigmiProviderNotFoundError } from '../errors/context.js'\nimport type { ResolvedRegister } from '../types.js'\n\nexport type ConfigParameter<config extends Config = Config> = {\n config?: Config | config | undefined\n}\n\nexport type UseConfigParameters<config extends Config = Config> =\n ConfigParameter<config>\n\nexport type UseConfigReturnType<config extends Config = Config> = config\n\nexport function useConfig<C extends Config = ResolvedRegister['config']>(\n parameters: UseConfigParameters<C> = {}\n): UseConfigReturnType<C> {\n // biome-ignore lint/correctness/useHookAtTopLevel: part of the hook\n const config = parameters.config ?? useContext(BigmiContext)\n if (!config) {\n throw new BigmiProviderNotFoundError()\n }\n return config as UseConfigReturnType<C>\n}\n"],"mappings":";;;;;AAiBA,SAAgB,UACd,aAAqC,EAAE,EACf;CAExB,MAAM,SAAS,WAAW,UAAU,WAAW,aAAa;AAC5D,KAAI,CAAC,OACH,OAAM,IAAI,4BAA4B;AAExC,QAAO"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ResolvedRegister } from "../types.js";
|
|
2
|
+
import { ConfigParameter } from "./useConfig.js";
|
|
3
|
+
import { UseMutationParameters, UseMutationReturnType } from "../utils/query.js";
|
|
4
|
+
import { UseConnectorsReturnType } from "./useConnectors.js";
|
|
5
|
+
import { Config, ConnectData, ConnectErrorType, ConnectMutate, ConnectMutateAsync, ConnectVariables } from "@bigmi/client";
|
|
6
|
+
import { Compute } from "@bigmi/core";
|
|
7
|
+
|
|
8
|
+
//#region src/hooks/useConnect.d.ts
|
|
9
|
+
type UseConnectParameters<config extends Config = Config, context = unknown> = Compute<ConfigParameter<config> & {
|
|
10
|
+
mutation?: UseMutationParameters<ConnectData<config>, ConnectErrorType, ConnectVariables<config, config["connectors"][number]>, context> | undefined;
|
|
9
11
|
}>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
type UseConnectReturnType<config extends Config = Config, context = unknown> = Compute<UseMutationReturnType<ConnectData<config>, ConnectErrorType, ConnectVariables<config, config["connectors"][number]>, context> & {
|
|
13
|
+
connect: ConnectMutate<config, context>;
|
|
14
|
+
connectAsync: ConnectMutateAsync<config, context>;
|
|
15
|
+
connectors: Compute<UseConnectorsReturnType> | config["connectors"];
|
|
14
16
|
}>;
|
|
15
|
-
|
|
17
|
+
declare function useConnect<config extends Config = ResolvedRegister["config"], context = unknown>(parameters?: UseConnectParameters<config, context>): UseConnectReturnType<config, context>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { UseConnectParameters, UseConnectReturnType, useConnect };
|
|
20
|
+
//# sourceMappingURL=useConnect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnect.d.ts","names":[],"sources":["../../../src/hooks/useConnect.ts"],"mappings":";;;;;;;;KAsBY,oBAAA,gBACK,MAAA,GAAS,MAAA,uBAEtB,OAAA,CACF,eAAA,CAAgB,MAAA;EACd,QAAA,GACI,qBAAA,CACE,WAAA,CAAY,MAAA,GACZ,gBAAA,EACA,gBAAA,CAAiB,MAAA,EAAQ,MAAA,yBACzB,OAAA;AAAA;AAAA,KAME,oBAAA,gBACK,MAAA,GAAS,MAAA,uBAEtB,OAAA,CACF,qBAAA,CACE,WAAA,CAAY,MAAA,GACZ,gBAAA,EACA,gBAAA,CAAiB,MAAA,EAAQ,MAAA,yBACzB,OAAA;EAEA,OAAA,EAAS,aAAA,CAAc,MAAA,EAAQ,OAAA;EAC/B,YAAA,EAAc,kBAAA,CAAmB,MAAA,EAAQ,OAAA;EACzC,UAAA,EAAY,OAAA,CAAQ,uBAAA,IAA2B,MAAA;AAAA;AAAA,iBAInC,UAAA,gBACC,MAAA,GAAS,gBAAA,8BAAA,CAGxB,UAAA,GAAY,oBAAA,CAAqB,MAAA,EAAQ,OAAA,IACxC,oBAAA,CAAqB,MAAA,EAAQ,OAAA"}
|
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useEffect } from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
connectors: useConnectors({ config }),
|
|
28
|
-
};
|
|
1
|
+
"use client";
|
|
2
|
+
import { useConfig } from "./useConfig.js";
|
|
3
|
+
import { useConnectors } from "./useConnectors.js";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
import { connectMutationOptions } from "@bigmi/client";
|
|
6
|
+
import { useMutation } from "@tanstack/react-query";
|
|
7
|
+
//#region src/hooks/useConnect.ts
|
|
8
|
+
function useConnect(parameters = {}) {
|
|
9
|
+
const { mutation } = parameters;
|
|
10
|
+
const config = useConfig(parameters);
|
|
11
|
+
const mutationOptions = connectMutationOptions(config);
|
|
12
|
+
const { mutate, mutateAsync, reset, ...result } = useMutation({
|
|
13
|
+
...mutation,
|
|
14
|
+
...mutationOptions
|
|
15
|
+
});
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
return config.subscribe(({ status }) => status, (status, previousStatus) => {
|
|
18
|
+
if (previousStatus === "connected" && status === "disconnected") reset();
|
|
19
|
+
});
|
|
20
|
+
}, [config, reset]);
|
|
21
|
+
return {
|
|
22
|
+
...result,
|
|
23
|
+
connect: mutate,
|
|
24
|
+
connectAsync: mutateAsync,
|
|
25
|
+
connectors: useConnectors({ config })
|
|
26
|
+
};
|
|
29
27
|
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { useConnect };
|
|
30
|
+
|
|
30
31
|
//# sourceMappingURL=useConnect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConnect.js","
|
|
1
|
+
{"version":3,"file":"useConnect.js","names":[],"sources":["../../../src/hooks/useConnect.ts"],"sourcesContent":["'use client'\n\nimport {\n type Config,\n type ConnectData,\n type ConnectErrorType,\n type ConnectMutate,\n type ConnectMutateAsync,\n type ConnectVariables,\n connectMutationOptions,\n} from '@bigmi/client'\nimport type { Compute } from '@bigmi/core'\nimport { useMutation } from '@tanstack/react-query'\nimport { useEffect } from 'react'\nimport type { ResolvedRegister } from '../types.js'\nimport type {\n UseMutationParameters,\n UseMutationReturnType,\n} from '../utils/query.js'\nimport { type ConfigParameter, useConfig } from './useConfig.js'\nimport { type UseConnectorsReturnType, useConnectors } from './useConnectors.js'\n\nexport type UseConnectParameters<\n config extends Config = Config,\n context = unknown,\n> = Compute<\n ConfigParameter<config> & {\n mutation?:\n | UseMutationParameters<\n ConnectData<config>,\n ConnectErrorType,\n ConnectVariables<config, config['connectors'][number]>,\n context\n >\n | undefined\n }\n>\n\nexport type UseConnectReturnType<\n config extends Config = Config,\n context = unknown,\n> = Compute<\n UseMutationReturnType<\n ConnectData<config>,\n ConnectErrorType,\n ConnectVariables<config, config['connectors'][number]>,\n context\n > & {\n connect: ConnectMutate<config, context>\n connectAsync: ConnectMutateAsync<config, context>\n connectors: Compute<UseConnectorsReturnType> | config['connectors']\n }\n>\n\nexport function useConnect<\n config extends Config = ResolvedRegister['config'],\n context = unknown,\n>(\n parameters: UseConnectParameters<config, context> = {}\n): UseConnectReturnType<config, context> {\n const { mutation } = parameters\n\n const config = useConfig(parameters)\n\n const mutationOptions = connectMutationOptions(config)\n const { mutate, mutateAsync, reset, ...result } = useMutation({\n ...mutation,\n ...mutationOptions,\n })\n\n // Reset mutation back to an idle state when the connector disconnects.\n useEffect(() => {\n return config.subscribe(\n ({ status }) => status,\n (status, previousStatus) => {\n if (previousStatus === 'connected' && status === 'disconnected') {\n reset()\n }\n }\n )\n }, [config, reset])\n\n type Return = UseConnectReturnType<config, context>\n return {\n ...(result as Return),\n connect: mutate as Return['connect'],\n connectAsync: mutateAsync as Return['connectAsync'],\n connectors: useConnectors({ config }),\n }\n}\n"],"mappings":";;;;;;;AAsDA,SAAgB,WAId,aAAoD,EAAE,EACf;CACvC,MAAM,EAAE,aAAa;CAErB,MAAM,SAAS,UAAU,WAAW;CAEpC,MAAM,kBAAkB,uBAAuB,OAAO;CACtD,MAAM,EAAE,QAAQ,aAAa,OAAO,GAAG,WAAW,YAAY;EAC5D,GAAG;EACH,GAAG;EACJ,CAAC;AAGF,iBAAgB;AACd,SAAO,OAAO,WACX,EAAE,aAAa,SACf,QAAQ,mBAAmB;AAC1B,OAAI,mBAAmB,eAAe,WAAW,eAC/C,QAAO;IAGZ;IACA,CAAC,QAAQ,MAAM,CAAC;AAGnB,QAAO;EACL,GAAI;EACJ,SAAS;EACT,cAAc;EACd,YAAY,cAAc,EAAE,QAAQ,CAAC;EACtC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ResolvedRegister } from "../types.js";
|
|
2
|
+
import { ConfigParameter } from "./useConfig.js";
|
|
3
|
+
import { Config, GetConnectorsReturnType } from "@bigmi/client";
|
|
4
|
+
|
|
5
|
+
//#region src/hooks/useConnectors.d.ts
|
|
6
|
+
type UseConnectorsParameters<config extends Config = Config> = ConfigParameter<config>;
|
|
7
|
+
type UseConnectorsReturnType<config extends Config = Config> = GetConnectorsReturnType<config>;
|
|
8
|
+
declare function useConnectors<config extends Config = ResolvedRegister["config"]>(parameters?: UseConnectorsParameters<config>): UseConnectorsReturnType<config>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { UseConnectorsParameters, UseConnectorsReturnType, useConnectors };
|
|
11
|
+
//# sourceMappingURL=useConnectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnectors.d.ts","names":[],"sources":["../../../src/hooks/useConnectors.ts"],"mappings":";;;;;KAYY,uBAAA,gBAAuC,MAAA,GAAS,MAAA,IAC1D,eAAA,CAAgB,MAAA;AAAA,KAEN,uBAAA,gBAAuC,MAAA,GAAS,MAAA,IAC1D,uBAAA,CAAwB,MAAA;AAAA,iBAIV,aAAA,gBACC,MAAA,GAAS,gBAAA,WAAA,CAExB,UAAA,GAAY,uBAAA,CAAwB,MAAA,IACnC,uBAAA,CAAwB,MAAA"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { useSyncExternalStore } from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { useConfig } from "./useConfig.js";
|
|
3
|
+
import { useSyncExternalStore } from "react";
|
|
4
|
+
import { getConnectors, watchConnectors } from "@bigmi/client";
|
|
5
|
+
//#region src/hooks/useConnectors.ts
|
|
6
|
+
const EMPTY_CONNECTORS = [];
|
|
7
|
+
function useConnectors(parameters = {}) {
|
|
8
|
+
const config = useConfig(parameters);
|
|
9
|
+
return useSyncExternalStore((onChange) => watchConnectors(config, { onChange }), () => getConnectors(config), () => EMPTY_CONNECTORS);
|
|
8
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useConnectors };
|
|
13
|
+
|
|
9
14
|
//# sourceMappingURL=useConnectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConnectors.js","
|
|
1
|
+
{"version":3,"file":"useConnectors.js","names":[],"sources":["../../../src/hooks/useConnectors.ts"],"sourcesContent":["'use client'\n\nimport {\n type Config,\n type GetConnectorsReturnType,\n getConnectors,\n watchConnectors,\n} from '@bigmi/client'\nimport { useSyncExternalStore } from 'react'\nimport type { ResolvedRegister } from '../types.js'\nimport { type ConfigParameter, useConfig } from './useConfig.js'\n\nexport type UseConnectorsParameters<config extends Config = Config> =\n ConfigParameter<config>\n\nexport type UseConnectorsReturnType<config extends Config = Config> =\n GetConnectorsReturnType<config>\n\nconst EMPTY_CONNECTORS: readonly [] = []\n\nexport function useConnectors<\n config extends Config = ResolvedRegister['config'],\n>(\n parameters: UseConnectorsParameters<config> = {}\n): UseConnectorsReturnType<config> {\n const config = useConfig(parameters)\n\n return useSyncExternalStore(\n (onChange) => watchConnectors(config, { onChange }),\n () => getConnectors(config),\n () => EMPTY_CONNECTORS as UseConnectorsReturnType<config>\n )\n}\n"],"mappings":";;;;;AAkBA,MAAM,mBAAgC,EAAE;AAExC,SAAgB,cAGd,aAA8C,EAAE,EACf;CACjC,MAAM,SAAS,UAAU,WAAW;AAEpC,QAAO,sBACJ,aAAa,gBAAgB,QAAQ,EAAE,UAAU,CAAC,QAC7C,cAAc,OAAO,QACrB,iBACP"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Config } from "@bigmi/client";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/useReconnect.d.ts
|
|
4
|
+
declare const useReconnect: (config: Config) => void;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { useReconnect };
|
|
7
|
+
//# sourceMappingURL=useReconnect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReconnect.d.ts","names":[],"sources":["../../../src/hooks/useReconnect.ts"],"mappings":";;;cAMa,YAAA,GAAgB,MAAA,EAAQ,MAAA"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { reconnect } from "@bigmi/client";
|
|
4
|
+
//#region src/hooks/useReconnect.ts
|
|
5
|
+
const useReconnect = (config) => {
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
reconnect(config);
|
|
8
|
+
}, [config]);
|
|
8
9
|
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { useReconnect };
|
|
12
|
+
|
|
9
13
|
//# sourceMappingURL=useReconnect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReconnect.js","
|
|
1
|
+
{"version":3,"file":"useReconnect.js","names":[],"sources":["../../../src/hooks/useReconnect.ts"],"sourcesContent":["'use client'\n\nimport { type Config, reconnect } from '@bigmi/client'\n\nimport { useEffect } from 'react'\n\nexport const useReconnect = (config: Config): void => {\n useEffect(() => {\n reconnect(config)\n }, [config])\n}\n"],"mappings":";;;;AAMA,MAAa,gBAAgB,WAAyB;AACpD,iBAAgB;AACd,YAAU,OAAO;IAChB,CAAC,OAAO,CAAC"}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/hooks/useSyncExternalStoreWithTracked.d.ts
|
|
2
|
+
declare function useSyncExternalStoreWithTracked<Snapshot extends Selection, Selection = Snapshot>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => Snapshot, getServerSnapshot?: (() => Snapshot) | undefined, isEqual?: (a: Selection, b: Selection) => boolean): Selection;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { useSyncExternalStoreWithTracked };
|
|
5
|
+
//# sourceMappingURL=useSyncExternalStoreWithTracked.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncExternalStoreWithTracked.d.ts","names":[],"sources":["../../../src/hooks/useSyncExternalStoreWithTracked.ts"],"mappings":";iBAOgB,+BAAA,kBACG,SAAA,cACL,QAAA,CAAA,CAEZ,SAAA,GAAY,aAAA,6BACZ,WAAA,QAAmB,QAAA,EACnB,iBAAA,UAA0B,QAAA,eAC1B,OAAA,IAAU,CAAA,EAAG,SAAA,EAAW,CAAA,EAAG,SAAA,eAC1B,SAAA"}
|
|
@@ -1,44 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const hasChanged = Array.from(trackedKeys.current).some((key) => !isEqual(result[key], previousResult.current[key]));
|
|
37
|
-
if (!hasChanged) {
|
|
38
|
-
return previousResult.current;
|
|
39
|
-
}
|
|
40
|
-
previousResult.current = result;
|
|
41
|
-
return result;
|
|
42
|
-
}, [result, isEqual]);
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import { deepEqual } from "@bigmi/core";
|
|
4
|
+
//#region src/hooks/useSyncExternalStoreWithTracked.ts
|
|
5
|
+
const isPlainObject = (obj) => typeof obj === "object" && !Array.isArray(obj);
|
|
6
|
+
function useSyncExternalStoreWithTracked(subscribe, getSnapshot, getServerSnapshot = getSnapshot, isEqual = deepEqual) {
|
|
7
|
+
const trackedKeys = useRef(/* @__PURE__ */ new Set());
|
|
8
|
+
const previousResult = useRef(void 0);
|
|
9
|
+
const snapshotCache = useRef(getSnapshot());
|
|
10
|
+
const snapshot = useSyncExternalStore((onChange) => subscribe(() => {
|
|
11
|
+
snapshotCache.current = getSnapshot();
|
|
12
|
+
onChange();
|
|
13
|
+
}), () => snapshotCache.current, getServerSnapshot);
|
|
14
|
+
const result = useMemo(() => {
|
|
15
|
+
if (!isPlainObject(snapshot)) return snapshot;
|
|
16
|
+
const trackedResult = { ...snapshot };
|
|
17
|
+
Object.defineProperties(trackedResult, Object.fromEntries(Object.entries(trackedResult).map(([key, value]) => [key, {
|
|
18
|
+
configurable: false,
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: () => {
|
|
21
|
+
trackedKeys.current.add(key);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
}])));
|
|
25
|
+
return trackedResult;
|
|
26
|
+
}, [snapshot]);
|
|
27
|
+
return useMemo(() => {
|
|
28
|
+
if (!trackedKeys.current.size || !previousResult.current) {
|
|
29
|
+
previousResult.current = result;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
if (!Array.from(trackedKeys.current).some((key) => !isEqual(result[key], previousResult.current[key]))) return previousResult.current;
|
|
33
|
+
previousResult.current = result;
|
|
34
|
+
return result;
|
|
35
|
+
}, [result, isEqual]);
|
|
43
36
|
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useSyncExternalStoreWithTracked };
|
|
39
|
+
|
|
44
40
|
//# sourceMappingURL=useSyncExternalStoreWithTracked.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSyncExternalStoreWithTracked.js","
|
|
1
|
+
{"version":3,"file":"useSyncExternalStoreWithTracked.js","names":[],"sources":["../../../src/hooks/useSyncExternalStoreWithTracked.ts"],"sourcesContent":["'use client'\nimport { deepEqual } from '@bigmi/core'\nimport { useMemo, useRef, useSyncExternalStore } from 'react'\n\nconst isPlainObject = (obj: unknown): obj is Record<string, any> =>\n typeof obj === 'object' && !Array.isArray(obj)\n\nexport function useSyncExternalStoreWithTracked<\n Snapshot extends Selection,\n Selection = Snapshot,\n>(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => Snapshot,\n getServerSnapshot: (() => Snapshot) | undefined = getSnapshot,\n isEqual: (a: Selection, b: Selection) => boolean = deepEqual\n): Selection {\n const trackedKeys = useRef<Set<string>>(new Set())\n const previousResult = useRef<Selection | undefined>(undefined)\n const snapshotCache = useRef(getSnapshot())\n\n const snapshot = useSyncExternalStore(\n (onChange) =>\n subscribe(() => {\n snapshotCache.current = getSnapshot()\n onChange()\n }),\n () => snapshotCache.current!,\n getServerSnapshot\n )\n\n const result = useMemo(() => {\n if (!isPlainObject(snapshot)) {\n return snapshot\n }\n\n const trackedResult = { ...snapshot }\n Object.defineProperties(\n trackedResult,\n Object.fromEntries(\n Object.entries(trackedResult).map(([key, value]) => [\n key,\n {\n configurable: false,\n enumerable: true,\n get: () => {\n trackedKeys.current.add(key)\n return value\n },\n },\n ])\n )\n )\n return trackedResult\n }, [snapshot])\n\n return useMemo(() => {\n if (!trackedKeys.current.size || !previousResult.current) {\n previousResult.current = result\n return result\n }\n\n const hasChanged = Array.from(trackedKeys.current).some(\n (key) =>\n !isEqual(\n (result as Record<string, Selection>)[key],\n (previousResult.current as Record<string, Selection>)[key]\n )\n )\n\n if (!hasChanged) {\n return previousResult.current\n }\n previousResult.current = result\n return result\n }, [result, isEqual])\n}\n"],"mappings":";;;;AAIA,MAAM,iBAAiB,QACrB,OAAO,QAAQ,YAAY,CAAC,MAAM,QAAQ,IAAI;AAEhD,SAAgB,gCAId,WACA,aACA,oBAAkD,aAClD,UAAmD,WACxC;CACX,MAAM,cAAc,uBAAoB,IAAI,KAAK,CAAC;CAClD,MAAM,iBAAiB,OAA8B,KAAA,EAAU;CAC/D,MAAM,gBAAgB,OAAO,aAAa,CAAC;CAE3C,MAAM,WAAW,sBACd,aACC,gBAAgB;AACd,gBAAc,UAAU,aAAa;AACrC,YAAU;GACV,QACE,cAAc,SACpB,kBACD;CAED,MAAM,SAAS,cAAc;AAC3B,MAAI,CAAC,cAAc,SAAS,CAC1B,QAAO;EAGT,MAAM,gBAAgB,EAAE,GAAG,UAAU;AACrC,SAAO,iBACL,eACA,OAAO,YACL,OAAO,QAAQ,cAAc,CAAC,KAAK,CAAC,KAAK,WAAW,CAClD,KACA;GACE,cAAc;GACd,YAAY;GACZ,WAAW;AACT,gBAAY,QAAQ,IAAI,IAAI;AAC5B,WAAO;;GAEV,CACF,CAAC,CACH,CACF;AACD,SAAO;IACN,CAAC,SAAS,CAAC;AAEd,QAAO,cAAc;AACnB,MAAI,CAAC,YAAY,QAAQ,QAAQ,CAAC,eAAe,SAAS;AACxD,kBAAe,UAAU;AACzB,UAAO;;AAWT,MAAI,CARe,MAAM,KAAK,YAAY,QAAQ,CAAC,MAChD,QACC,CAAC,QACE,OAAqC,MACrC,eAAe,QAAsC,KACvD,CACJ,CAGC,QAAO,eAAe;AAExB,iBAAe,UAAU;AACzB,SAAO;IACN,CAAC,QAAQ,QAAQ,CAAC"}
|
package/dist/esm/hydrate.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { ResolvedRegister } from "./types.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
import { Config, State } from "@bigmi/client";
|
|
4
|
+
|
|
5
|
+
//#region src/hydrate.d.ts
|
|
6
|
+
type HydrateProps = {
|
|
7
|
+
config: ResolvedRegister["config"];
|
|
8
|
+
initialState?: State | undefined;
|
|
9
|
+
reconnectOnMount?: boolean | undefined;
|
|
8
10
|
};
|
|
9
11
|
type HydrateParameters = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
initialState?: State | undefined;
|
|
13
|
+
reconnectOnMount?: boolean | undefined;
|
|
12
14
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
declare function hydrate(config: Config, parameters: HydrateParameters): {
|
|
16
|
+
onMount(): Promise<void>;
|
|
15
17
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
declare function Hydrate(parameters: React.PropsWithChildren<HydrateProps>): ReactElement;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Hydrate, HydrateProps, hydrate };
|
|
21
|
+
//# sourceMappingURL=hydrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate.d.ts","names":[],"sources":["../../src/hydrate.ts"],"mappings":";;;;;KAQY,YAAA;EACV,MAAA,EAAQ,gBAAA;EACR,YAAA,GAAe,KAAA;EACf,gBAAA;AAAA;AAAA,KAGG,iBAAA;EACH,YAAA,GAAe,KAAA;EACf,gBAAA;AAAA;AAAA,iBAGc,OAAA,CACd,MAAA,EAAQ,MAAA,EACR,UAAA,EAAY,iBAAA;EACT,OAAA,IAAW,OAAA;AAAA;AAAA,iBAiCA,OAAA,CAAQ,UAAA,EAAY,KAAA,CAAM,iBAAA,CAAkB,YAAA,IA6BvC,YAAA"}
|