@xyo-network/react-payload-diviner 5.3.0 → 5.3.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.
- package/dist/browser/index.mjs +4 -4
- package/dist/browser/index.mjs.map +1 -1
- package/dist/types/contexts/DivinedPayload/Context.d.ts +7 -2
- package/dist/types/contexts/DivinedPayload/Context.d.ts.map +1 -1
- package/dist/types/contexts/DivinedPayload/Provider.d.ts.map +1 -1
- package/dist/types/contexts/DivinedPayload/State.d.ts +3 -3
- package/dist/types/contexts/DivinedPayload/State.d.ts.map +1 -1
- package/dist/types/contexts/DivinedPayload/use.d.ts +7 -1
- package/dist/types/contexts/DivinedPayload/use.d.ts.map +1 -1
- package/dist/types/contexts/PayloadDiviner/Context.d.ts +6 -2
- package/dist/types/contexts/PayloadDiviner/Context.d.ts.map +1 -1
- package/dist/types/contexts/PayloadDiviner/Provider.d.ts +1 -1
- package/dist/types/contexts/PayloadDiviner/Provider.d.ts.map +1 -1
- package/dist/types/contexts/PayloadDiviner/State.d.ts +3 -2
- package/dist/types/contexts/PayloadDiviner/State.d.ts.map +1 -1
- package/dist/types/contexts/PayloadDiviner/use.d.ts +6 -1
- package/dist/types/contexts/PayloadDiviner/use.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/contexts/DivinedPayload/Context.ts +1 -1
- package/src/contexts/DivinedPayload/Provider.tsx +2 -1
- package/src/contexts/DivinedPayload/State.ts +3 -3
- package/src/contexts/DivinedPayload/use.ts +1 -1
- package/src/contexts/PayloadDiviner/Context.ts +1 -1
- package/src/contexts/PayloadDiviner/Provider.tsx +3 -2
- package/src/contexts/PayloadDiviner/State.ts +3 -2
- package/src/contexts/PayloadDiviner/use.ts +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/contexts/DivinedPayload/Context.ts
|
|
5
|
-
import { createContextEx } from "@
|
|
5
|
+
import { createContextEx } from "@xylabs/react-shared";
|
|
6
6
|
var DivinedPayloadContext = createContextEx();
|
|
7
7
|
|
|
8
8
|
// src/contexts/DivinedPayload/Provider.tsx
|
|
@@ -13,7 +13,7 @@ import React2, { useMemo as useMemo2 } from "react";
|
|
|
13
13
|
import { useParams, useSearchParams } from "react-router-dom";
|
|
14
14
|
|
|
15
15
|
// src/contexts/PayloadDiviner/Context.ts
|
|
16
|
-
import { createContextEx as createContextEx2 } from "@
|
|
16
|
+
import { createContextEx as createContextEx2 } from "@xylabs/react-shared";
|
|
17
17
|
var PayloadDivinerContext = createContextEx2();
|
|
18
18
|
|
|
19
19
|
// src/contexts/PayloadDiviner/Provider.tsx
|
|
@@ -38,8 +38,8 @@ var PayloadDivinerProvider = /* @__PURE__ */ __name(({ diviner: divinerProp, req
|
|
|
38
38
|
// src/contexts/PayloadDiviner/use.ts
|
|
39
39
|
import { exists } from "@xylabs/exists";
|
|
40
40
|
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
41
|
+
import { useContextEx } from "@xylabs/react-shared";
|
|
41
42
|
import { HuriSchema } from "@xyo-network/diviner-huri";
|
|
42
|
-
import { useContextEx } from "@xyo-network/react-shared";
|
|
43
43
|
import { useEffect, useState } from "react";
|
|
44
44
|
var usePayloadDiviner = /* @__PURE__ */ __name((required = false) => {
|
|
45
45
|
return useContextEx(PayloadDivinerContext, "PayloadDiviner", required);
|
|
@@ -145,7 +145,7 @@ var useDivinePayloads = /* @__PURE__ */ __name((huriList) => {
|
|
|
145
145
|
}, "useDivinePayloads");
|
|
146
146
|
|
|
147
147
|
// src/contexts/DivinedPayload/use.ts
|
|
148
|
-
import { useContextEx as useContextEx2 } from "@
|
|
148
|
+
import { useContextEx as useContextEx2 } from "@xylabs/react-shared";
|
|
149
149
|
var useDivinedPayload = /* @__PURE__ */ __name(() => useContextEx2(DivinedPayloadContext, "DivinedPayload", true), "useDivinedPayload");
|
|
150
150
|
|
|
151
151
|
// src/contexts/DivinedPayload/Provider.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contexts/DivinedPayload/Context.ts","../../src/contexts/DivinedPayload/Provider.tsx","../../src/contexts/PayloadDiviner/Context.ts","../../src/contexts/PayloadDiviner/Provider.tsx","../../src/contexts/PayloadDiviner/use.ts","../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport type { DivinedPayloadState } from './State.ts'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n","import { ErrorRender } from '@xylabs/react-error'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { useBuildHuri } from '@xyo-network/react-payload-huri'\nimport type { PropsWithChildren } from 'react'\nimport React, { useMemo } from 'react'\nimport { useParams, useSearchParams } from 'react-router-dom'\n\nimport { useDivinePayload } from '../PayloadDiviner/index.ts'\nimport { DivinedPayloadContext } from './Context.ts'\nimport { useDivinedPayload } from './use.ts'\n\nexport interface DivinedPayloadProviderProps extends PropsWithChildren {\n hash?: string\n}\n\nexport const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps> = ({ children, hash }) => {\n const { hash: hashParam } = useParams()\n\n const huriFromHashParam = useBuildHuri(hashParam)\n\n const [params] = useSearchParams()\n const huriSearchParameter = params.get('huri')\n const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? '')\n const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam\n\n const [payload, setPayload, payloadError] = useDivinePayload(huriUri)\n\n const value = useMemo(() => ({\n payload, payloadError, provided: true, setPayload,\n }), [payload, payloadError, setPayload])\n\n return (\n <DivinedPayloadContext value={value}>\n {children}\n </DivinedPayloadContext>\n )\n}\n\nexport const DivinedPayloadWithHandleInner: React.FC<PropsWithChildren> = ({ children }) => {\n const { payloadError } = useDivinedPayload()\n\n return (\n <ErrorRender\n error={payloadError\n ? {\n message: payloadError.message, schema: ModuleErrorSchema, sources: [],\n }\n : undefined}\n errorContext=\"Divined Payload Provider\"\n >\n {children}\n </ErrorRender>\n )\n}\n\nexport const DivinedPayloadWithHandleProvider: React.FC<DivinedPayloadProviderProps> = ({ children, ...props }) => {\n return (\n <DivinedPayloadProvider {...props}>\n <DivinedPayloadWithHandleInner>{children}</DivinedPayloadWithHandleInner>\n </DivinedPayloadProvider>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport type { PayloadDivinerState } from './State.ts'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { useResetState } from '@xylabs/react-hooks'\nimport type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport type { ContextExProviderProps } from '@xyo-network/react-shared'\nimport React, { useMemo } from 'react'\n\nimport { PayloadDivinerContext } from './Context.ts'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: PayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({\n diviner: divinerProp, required = false, children,\n}) => {\n const [diviner, setDiviner] = useResetState<PayloadDiviner | undefined>(divinerProp)\n\n const value = useMemo(() => ({\n diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner,\n }), [diviner, divinerProp, setDiviner])\n\n return (\n <PayloadDivinerContext\n value={value}\n >\n {diviner\n ? children\n : required\n ? null\n : children}\n </PayloadDivinerContext>\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport type { HuriPayload } from '@xyo-network/diviner-huri'\nimport { HuriSchema } from '@xyo-network/diviner-huri'\nimport type { Payload } from '@xyo-network/payload-model'\nimport { useContextEx } from '@xyo-network/react-shared'\nimport type { Dispatch } from 'react'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context.ts'\n\nexport const usePayloadDiviner = (required = false) => {\n return useContextEx(PayloadDivinerContext, 'PayloadDiviner', required)\n}\n\nexport const useDivinePayload = <T extends Payload = Payload>(\n huri?: string,\n): [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payload, setPayload] = useState<T | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n // we do this to clear the payload when the diviner changes\n if (diviner) {\n // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\n setPayload(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n async (mounted) => {\n if (huri && diviner && payload === undefined) {\n try {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n if (mounted()) {\n setPayload(payload ? (payload as T) : null)\n }\n } catch (ex) {\n if (mounted()) {\n setError(ex as Error)\n }\n }\n }\n },\n [diviner, huri, payload],\n )\n\n return [payload, setPayload, error]\n}\n\nexport const useDivinePayloads = <T extends Payload = Payload>(\n huriList: string[],\n): [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payloads, setPayloads] = useState<(T | null)[]>()\n const [errors, setErrors] = useState<Error[]>()\n\n useEffect(() => {\n if (diviner) {\n // clear payloads when diviner changes\n // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\n setPayloads(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n async (mounted) => {\n console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`)\n const payloads = await Promise.allSettled(\n huriList.map(async (huri) => {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n return payload\n }),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n (\n [...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))\n ).filter(exists),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n (\n [...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))\n ).filter(exists),\n )\n }\n }\n },\n [diviner, huriList, payloads],\n )\n\n return [payloads, setPayloads, errors]\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadContext } from './Context.ts'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n"],"mappings":";;;;AAAA,SAASA,uBAAuB;AAIzB,IAAMC,wBAAwBD,gBAAAA;;;ACJrC,SAASE,mBAAmB;AAC5B,SAASC,yBAAyB;AAClC,SAASC,oBAAoB;AAE7B,OAAOC,UAASC,WAAAA,gBAAe;AAC/B,SAASC,WAAWC,uBAAuB;;;ACL3C,SAASC,mBAAAA,wBAAuB;AAIhC,IAAMC,wBAAwBD,iBAAAA;;;ACJ9B,SAASE,qBAAqB;AAG9B,OAAOC,SAASC,eAAe;AASxB,IAAMC,yBAAgE,wBAAC,EAC5EC,SAASC,aAAaC,WAAW,OAAOC,SAAQ,MACjD;AACC,QAAM,CAACH,SAASI,UAAAA,IAAcC,cAA0CJ,WAAAA;AAExE,QAAMK,QAAQC,QAAQ,OAAO;IAC3BP,SAASA,YAAYC,cAAcD,UAAUQ;IAAWC,UAAU;IAAML;EAC1E,IAAI;IAACJ;IAASC;IAAaG;GAAW;AAEtC,SACE,sBAAA,cAACM,uBAAAA;IACCJ;KAECN,UACGG,WACAD,WACE,OACAC,QAAAA;AAGZ,GApB6E;;;ACZ7E,SAASQ,cAAc;AACvB,SAASC,sBAAsB;AAE/B,SAASC,kBAAkB;AAE3B,SAASC,oBAAoB;AAE7B,SAASC,WAAWC,gBAAgB;AAI7B,IAAMC,oBAAoB,wBAACC,WAAW,UAAK;AAChD,SAAOC,aAAaC,uBAAuB,kBAAkBF,QAAAA;AAC/D,GAFiC;AAI1B,IAAMG,mBAAmB,wBAC9BC,SAAAA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AAgBC,iBAAiBJ,OAAAA;AAE7D,QAAMK,QAAQC,SAAQ,OAAO;IAC3BL;IAASE;IAAcI,UAAU;IAAML;EACzC,IAAI;IAACD;IAASE;IAAcD;GAAW;AAEvC,SACE,gBAAAM,OAAA,cAACC,uBAAAA;IAAsBJ;KACpBjB,QAAAA;AAGP,GArB6E;AAuBtE,IAAMsB,gCAA6D,wBAAC,EAAEtB,SAAQ,MAAE;AACrF,QAAM,EAAEe,aAAY,IAAKQ,kBAAAA;AAEzB,SACE,gBAAAH,OAAA,cAACI,aAAAA;IACCC,OAAOV,eACH;MACEW,SAASX,aAAaW;MAASC,QAAQC;MAAmBC,SAAS,CAAA;IACrE,IACAC;IACJC,cAAa;KAEZ/B,QAAAA;AAGP,GAf0E;AAiBnE,IAAMgC,mCAA0E,wBAAC,EAAEhC,UAAU,GAAGiC,MAAAA,MAAO;AAC5G,SACE,gBAAAb,OAAA,cAACrB,wBAA2BkC,OAC1B,gBAAAb,OAAA,cAACE,+BAAAA,MAA+BtB,QAAAA,CAAAA;AAGtC,GANuF;","names":["createContextEx","DivinedPayloadContext","ErrorRender","ModuleErrorSchema","useBuildHuri","React","useMemo","useParams","useSearchParams","createContextEx","PayloadDivinerContext","useResetState","React","useMemo","PayloadDivinerProvider","diviner","divinerProp","required","children","setDiviner","useResetState","value","useMemo","undefined","provided","PayloadDivinerContext","exists","useAsyncEffect","HuriSchema","useContextEx","useEffect","useState","usePayloadDiviner","required","useContextEx","PayloadDivinerContext","useDivinePayload","huri","diviner","payload","setPayload","useState","error","setError","useEffect","undefined","useAsyncEffect","mounted","huriPayload","schema","HuriSchema","divine","ex","useDivinePayloads","huriList","payloads","setPayloads","errors","setErrors","console","log","JSON","stringify","Promise","allSettled","map","values","value","status","Error","cause","reason","filter","exists","useContextEx","useDivinedPayload","useContextEx","DivinedPayloadContext","DivinedPayloadProvider","children","hash","hashParam","useParams","huriFromHashParam","useBuildHuri","params","useSearchParams","huriSearchParameter","get","decodedHuriParam","decodeURIComponent","huriUri","payload","setPayload","payloadError","useDivinePayload","value","useMemo","provided","React","DivinedPayloadContext","DivinedPayloadWithHandleInner","useDivinedPayload","ErrorRender","error","message","schema","ModuleErrorSchema","sources","undefined","errorContext","DivinedPayloadWithHandleProvider","props"]}
|
|
1
|
+
{"version":3,"sources":["../../src/contexts/DivinedPayload/Context.ts","../../src/contexts/DivinedPayload/Provider.tsx","../../src/contexts/PayloadDiviner/Context.ts","../../src/contexts/PayloadDiviner/Provider.tsx","../../src/contexts/PayloadDiviner/use.ts","../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["import { createContextEx } from '@xylabs/react-shared'\n\nimport type { DivinedPayloadState } from './State.ts'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n","import { ErrorRender } from '@xylabs/react-error'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { useBuildHuri } from '@xyo-network/react-payload-huri'\nimport type { PropsWithChildren } from 'react'\nimport React, { useMemo } from 'react'\nimport { useParams, useSearchParams } from 'react-router-dom'\n\nimport { useDivinePayload } from '../PayloadDiviner/index.ts'\nimport { DivinedPayloadContext } from './Context.ts'\nimport type { DivinedPayloadState } from './State.ts'\nimport { useDivinedPayload } from './use.ts'\n\nexport interface DivinedPayloadProviderProps extends PropsWithChildren {\n hash?: string\n}\n\nexport const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps> = ({ children, hash }) => {\n const { hash: hashParam } = useParams()\n\n const huriFromHashParam = useBuildHuri(hashParam)\n\n const [params] = useSearchParams()\n const huriSearchParameter = params.get('huri')\n const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? '')\n const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam\n\n const [payload, setPayload, payloadError] = useDivinePayload(huriUri)\n\n const value: DivinedPayloadState = useMemo(() => ({\n payload, payloadError, provided: true, setPayload,\n }), [payload, payloadError, setPayload])\n\n return (\n <DivinedPayloadContext value={value}>\n {children}\n </DivinedPayloadContext>\n )\n}\n\nexport const DivinedPayloadWithHandleInner: React.FC<PropsWithChildren> = ({ children }) => {\n const { payloadError } = useDivinedPayload()\n\n return (\n <ErrorRender\n error={payloadError\n ? {\n message: payloadError.message, schema: ModuleErrorSchema, sources: [],\n }\n : undefined}\n errorContext=\"Divined Payload Provider\"\n >\n {children}\n </ErrorRender>\n )\n}\n\nexport const DivinedPayloadWithHandleProvider: React.FC<DivinedPayloadProviderProps> = ({ children, ...props }) => {\n return (\n <DivinedPayloadProvider {...props}>\n <DivinedPayloadWithHandleInner>{children}</DivinedPayloadWithHandleInner>\n </DivinedPayloadProvider>\n )\n}\n","import { createContextEx } from '@xylabs/react-shared'\n\nimport type { PayloadDivinerState } from './State.ts'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { useResetState } from '@xylabs/react-hooks'\nimport type { ContextExProviderProps } from '@xylabs/react-shared'\nimport type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport React, { useMemo } from 'react'\n\nimport { PayloadDivinerContext } from './Context.ts'\nimport type { PayloadDivinerState } from './State.ts'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: PayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({\n diviner: divinerProp, required = false, children,\n}) => {\n const [diviner, setDiviner] = useResetState<PayloadDiviner | undefined>(divinerProp)\n\n const value: PayloadDivinerState = useMemo(() => ({\n diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner,\n }), [diviner, divinerProp, setDiviner])\n\n return (\n <PayloadDivinerContext\n value={value}\n >\n {diviner\n ? children\n : required\n ? null\n : children}\n </PayloadDivinerContext>\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { useContextEx } from '@xylabs/react-shared'\nimport type { HuriPayload } from '@xyo-network/diviner-huri'\nimport { HuriSchema } from '@xyo-network/diviner-huri'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type { Dispatch } from 'react'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context.ts'\n\nexport const usePayloadDiviner = (required = false) => {\n return useContextEx(PayloadDivinerContext, 'PayloadDiviner', required)\n}\n\nexport const useDivinePayload = <T extends Payload = Payload>(\n huri?: string,\n): [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payload, setPayload] = useState<T | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n // we do this to clear the payload when the diviner changes\n if (diviner) {\n // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\n setPayload(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n async (mounted) => {\n if (huri && diviner && payload === undefined) {\n try {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n if (mounted()) {\n setPayload(payload ? (payload as T) : null)\n }\n } catch (ex) {\n if (mounted()) {\n setError(ex as Error)\n }\n }\n }\n },\n [diviner, huri, payload],\n )\n\n return [payload, setPayload, error]\n}\n\nexport const useDivinePayloads = <T extends Payload = Payload>(\n huriList: string[],\n): [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payloads, setPayloads] = useState<(T | null)[]>()\n const [errors, setErrors] = useState<Error[]>()\n\n useEffect(() => {\n if (diviner) {\n // clear payloads when diviner changes\n // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\n setPayloads(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n async (mounted) => {\n console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`)\n const payloads = await Promise.allSettled(\n huriList.map(async (huri) => {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n return payload\n }),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n (\n [...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))\n ).filter(exists),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n (\n [...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))\n ).filter(exists),\n )\n }\n }\n },\n [diviner, huriList, payloads],\n )\n\n return [payloads, setPayloads, errors]\n}\n","import { useContextEx } from '@xylabs/react-shared'\n\nimport { DivinedPayloadContext } from './Context.ts'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n"],"mappings":";;;;AAAA,SAASA,uBAAuB;AAIzB,IAAMC,wBAAwBD,gBAAAA;;;ACJrC,SAASE,mBAAmB;AAC5B,SAASC,yBAAyB;AAClC,SAASC,oBAAoB;AAE7B,OAAOC,UAASC,WAAAA,gBAAe;AAC/B,SAASC,WAAWC,uBAAuB;;;ACL3C,SAASC,mBAAAA,wBAAuB;AAIhC,IAAMC,wBAAwBD,iBAAAA;;;ACJ9B,SAASE,qBAAqB;AAG9B,OAAOC,SAASC,eAAe;AAUxB,IAAMC,yBAAgE,wBAAC,EAC5EC,SAASC,aAAaC,WAAW,OAAOC,SAAQ,MACjD;AACC,QAAM,CAACH,SAASI,UAAAA,IAAcC,cAA0CJ,WAAAA;AAExE,QAAMK,QAA6BC,QAAQ,OAAO;IAChDP,SAASA,YAAYC,cAAcD,UAAUQ;IAAWC,UAAU;IAAML;EAC1E,IAAI;IAACJ;IAASC;IAAaG;GAAW;AAEtC,SACE,sBAAA,cAACM,uBAAAA;IACCJ;KAECN,UACGG,WACAD,WACE,OACAC,QAAAA;AAGZ,GApB6E;;;ACb7E,SAASQ,cAAc;AACvB,SAASC,sBAAsB;AAC/B,SAASC,oBAAoB;AAE7B,SAASC,kBAAkB;AAG3B,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,QAAMC,sBAAsBF,OAAOG,IAAI,MAAA;AACvC,QAAMC,mBAAmBC,mBAAmBH,uBAAuB,EAAA;AACnE,QAAMI,UAAUX,QAAQS,oBAAoBN;AAE5C,QAAM,CAACS,SAASC,YAAYC,YAAAA,IAAgBC,iBAAiBJ,OAAAA;AAE7D,QAAMK,QAA6BC,SAAQ,OAAO;IAChDL;IAASE;IAAcI,UAAU;IAAML;EACzC,IAAI;IAACD;IAASE;IAAcD;GAAW;AAEvC,SACE,gBAAAM,OAAA,cAACC,uBAAAA;IAAsBJ;KACpBjB,QAAAA;AAGP,GArB6E;AAuBtE,IAAMsB,gCAA6D,wBAAC,EAAEtB,SAAQ,MAAE;AACrF,QAAM,EAAEe,aAAY,IAAKQ,kBAAAA;AAEzB,SACE,gBAAAH,OAAA,cAACI,aAAAA;IACCC,OAAOV,eACH;MACEW,SAASX,aAAaW;MAASC,QAAQC;MAAmBC,SAAS,CAAA;IACrE,IACAC;IACJC,cAAa;KAEZ/B,QAAAA;AAGP,GAf0E;AAiBnE,IAAMgC,mCAA0E,wBAAC,EAAEhC,UAAU,GAAGiC,MAAAA,MAAO;AAC5G,SACE,gBAAAb,OAAA,cAACrB,wBAA2BkC,OAC1B,gBAAAb,OAAA,cAACE,+BAAAA,MAA+BtB,QAAAA,CAAAA;AAGtC,GANuF;","names":["createContextEx","DivinedPayloadContext","ErrorRender","ModuleErrorSchema","useBuildHuri","React","useMemo","useParams","useSearchParams","createContextEx","PayloadDivinerContext","useResetState","React","useMemo","PayloadDivinerProvider","diviner","divinerProp","required","children","setDiviner","useResetState","value","useMemo","undefined","provided","PayloadDivinerContext","exists","useAsyncEffect","useContextEx","HuriSchema","useEffect","useState","usePayloadDiviner","required","useContextEx","PayloadDivinerContext","useDivinePayload","huri","diviner","payload","setPayload","useState","error","setError","useEffect","undefined","useAsyncEffect","mounted","huriPayload","schema","HuriSchema","divine","ex","useDivinePayloads","huriList","payloads","setPayloads","errors","setErrors","console","log","JSON","stringify","Promise","allSettled","map","values","value","status","Error","cause","reason","filter","exists","useContextEx","useDivinedPayload","useContextEx","DivinedPayloadContext","DivinedPayloadProvider","children","hash","hashParam","useParams","huriFromHashParam","useBuildHuri","params","useSearchParams","huriSearchParameter","get","decodedHuriParam","decodeURIComponent","huriUri","payload","setPayload","payloadError","useDivinePayload","value","useMemo","provided","React","DivinedPayloadContext","DivinedPayloadWithHandleInner","useDivinedPayload","ErrorRender","error","message","schema","ModuleErrorSchema","sources","undefined","errorContext","DivinedPayloadWithHandleProvider","props"]}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare const DivinedPayloadContext: import("react").Context<{
|
|
2
|
+
payload?: import("@xyo-network/payload-model").Payload | null;
|
|
3
|
+
payloadError?: Error;
|
|
4
|
+
setPayload?: import("react").Dispatch<import("@xyo-network/payload-model").Payload | null | undefined>;
|
|
5
|
+
} & {
|
|
6
|
+
provided: true;
|
|
7
|
+
}>;
|
|
3
8
|
//# sourceMappingURL=Context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Context.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,qBAAqB;;;;;;EAAyC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Provider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,KAAkB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Provider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,KAAkB,MAAM,OAAO,CAAA;AAQtC,MAAM,WAAW,2BAA4B,SAAQ,iBAAiB;IACpE,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAqBxE,CAAA;AAED,eAAO,MAAM,6BAA6B,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAerE,CAAA;AAED,eAAO,MAAM,gCAAgC,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAMlF,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { ContextExState } from '@xylabs/react-shared';
|
|
1
2
|
import type { Payload } from '@xyo-network/payload-model';
|
|
2
|
-
import type { ContextExState } from '@xyo-network/react-shared';
|
|
3
3
|
import type { Dispatch } from 'react';
|
|
4
|
-
export
|
|
4
|
+
export type DivinedPayloadState = ContextExState<{
|
|
5
5
|
payload?: Payload | null;
|
|
6
6
|
payloadError?: Error;
|
|
7
7
|
setPayload?: Dispatch<Payload | null | undefined>;
|
|
8
|
-
}
|
|
8
|
+
}>;
|
|
9
9
|
//# sourceMappingURL=State.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/State.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/State.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAErC,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACxB,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,UAAU,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;CAClD,CAAC,CAAA"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
export declare const useDivinedPayload: () => Omit<
|
|
1
|
+
export declare const useDivinedPayload: () => Omit<{
|
|
2
|
+
payload?: import("@xyo-network/payload-model").Payload | null;
|
|
3
|
+
payloadError?: Error;
|
|
4
|
+
setPayload?: import("react").Dispatch<import("@xyo-network/payload-model").Payload | null | undefined>;
|
|
5
|
+
} & {
|
|
6
|
+
provided: true;
|
|
7
|
+
}, "provided"> | Omit<never, "provided">;
|
|
2
8
|
//# sourceMappingURL=use.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/use.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/use.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB;;;;;;wCAAoE,CAAA"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare const PayloadDivinerContext: import("react").Context<{
|
|
2
|
+
diviner?: import("@xyo-network/diviner-payload-abstract").PayloadDiviner;
|
|
3
|
+
setDiviner?: import("react").Dispatch<import("@xyo-network/diviner-payload-abstract").PayloadDiviner>;
|
|
4
|
+
} & {
|
|
5
|
+
provided: true;
|
|
6
|
+
}>;
|
|
3
7
|
export { PayloadDivinerContext };
|
|
4
8
|
//# sourceMappingURL=Context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/Context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/Context.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,qBAAqB;;;;;EAAyC,CAAA;AAEpE,OAAO,EAAE,qBAAqB,EAAE,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { ContextExProviderProps } from '@xylabs/react-shared';
|
|
1
2
|
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract';
|
|
2
|
-
import type { ContextExProviderProps } from '@xyo-network/react-shared';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
export type PayloadDivinerProviderProps = ContextExProviderProps<{
|
|
5
5
|
/** Required */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/Provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/Provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAC3E,OAAO,KAAkB,MAAM,OAAO,CAAA;AAKtC,MAAM,MAAM,2BAA2B,GAAG,sBAAsB,CAAC;IAC/D,eAAe;IACf,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB,CAAC,CAAA;AAEF,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAoBxE,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { ContextExState } from '@xylabs/react-shared';
|
|
1
2
|
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract';
|
|
2
3
|
import type { Dispatch } from 'react';
|
|
3
|
-
export
|
|
4
|
+
export type PayloadDivinerState = ContextExState<{
|
|
4
5
|
diviner?: PayloadDiviner;
|
|
5
6
|
setDiviner?: Dispatch<PayloadDiviner>;
|
|
6
|
-
}
|
|
7
|
+
}>;
|
|
7
8
|
//# sourceMappingURL=State.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/State.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAErC,MAAM,
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/State.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAErC,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC;IAC/C,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,UAAU,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAA;CACtC,CAAC,CAAA"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Payload } from '@xyo-network/payload-model';
|
|
2
2
|
import type { Dispatch } from 'react';
|
|
3
|
-
export declare const usePayloadDiviner: (required?: boolean) => Omit<
|
|
3
|
+
export declare const usePayloadDiviner: (required?: boolean) => Omit<{
|
|
4
|
+
diviner?: import("@xyo-network/diviner-payload-abstract").PayloadDiviner;
|
|
5
|
+
setDiviner?: Dispatch<import("@xyo-network/diviner-payload-abstract").PayloadDiviner>;
|
|
6
|
+
} & {
|
|
7
|
+
provided: true;
|
|
8
|
+
}, "provided"> | Omit<never, "provided">;
|
|
4
9
|
export declare const useDivinePayload: <T extends Payload = Payload>(huri?: string) => [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined];
|
|
5
10
|
export declare const useDivinePayloads: <T extends Payload = Payload>(huriList: string[]) => [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined];
|
|
6
11
|
//# sourceMappingURL=use.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/use.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/use.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAKrC,eAAO,MAAM,iBAAiB,GAAI,kBAAgB;;;;;wCAEjD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO,GAAG,OAAO,EAC1D,OAAO,MAAM,KACZ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS,CAiC1E,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,OAAO,GAAG,OAAO,EAC3D,UAAU,MAAM,EAAE,KACjB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,SAAS,CA4CpF,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/react-payload-diviner",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.2",
|
|
4
4
|
"description": "Common React library for all XYO projects that use React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xyo",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"@xylabs/react-async-effect": "^6.3.0",
|
|
44
44
|
"@xylabs/react-error": "^6.3.0",
|
|
45
45
|
"@xylabs/react-hooks": "^6.3.0",
|
|
46
|
+
"@xylabs/react-shared": "^6.3.0",
|
|
46
47
|
"@xyo-network/diviner-huri": "^3.15.5",
|
|
47
48
|
"@xyo-network/diviner-payload-abstract": "^3.15.5",
|
|
48
49
|
"@xyo-network/payload-model": "^3.15.5",
|
|
49
|
-
"@xyo-network/react-payload-huri": "^5.3.
|
|
50
|
-
"@xyo-network/react-shared": "^5.3.0",
|
|
50
|
+
"@xyo-network/react-payload-huri": "^5.3.2",
|
|
51
51
|
"react-router-dom": "^7.6.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
@@ -7,6 +7,7 @@ import { useParams, useSearchParams } from 'react-router-dom'
|
|
|
7
7
|
|
|
8
8
|
import { useDivinePayload } from '../PayloadDiviner/index.ts'
|
|
9
9
|
import { DivinedPayloadContext } from './Context.ts'
|
|
10
|
+
import type { DivinedPayloadState } from './State.ts'
|
|
10
11
|
import { useDivinedPayload } from './use.ts'
|
|
11
12
|
|
|
12
13
|
export interface DivinedPayloadProviderProps extends PropsWithChildren {
|
|
@@ -25,7 +26,7 @@ export const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps> = ({
|
|
|
25
26
|
|
|
26
27
|
const [payload, setPayload, payloadError] = useDivinePayload(huriUri)
|
|
27
28
|
|
|
28
|
-
const value = useMemo(() => ({
|
|
29
|
+
const value: DivinedPayloadState = useMemo(() => ({
|
|
29
30
|
payload, payloadError, provided: true, setPayload,
|
|
30
31
|
}), [payload, payloadError, setPayload])
|
|
31
32
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { ContextExState } from '@xylabs/react-shared'
|
|
1
2
|
import type { Payload } from '@xyo-network/payload-model'
|
|
2
|
-
import type { ContextExState } from '@xyo-network/react-shared'
|
|
3
3
|
import type { Dispatch } from 'react'
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export type DivinedPayloadState = ContextExState<{
|
|
6
6
|
payload?: Payload | null
|
|
7
7
|
payloadError?: Error
|
|
8
8
|
setPayload?: Dispatch<Payload | null | undefined>
|
|
9
|
-
}
|
|
9
|
+
}>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useResetState } from '@xylabs/react-hooks'
|
|
2
|
+
import type { ContextExProviderProps } from '@xylabs/react-shared'
|
|
2
3
|
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
|
|
3
|
-
import type { ContextExProviderProps } from '@xyo-network/react-shared'
|
|
4
4
|
import React, { useMemo } from 'react'
|
|
5
5
|
|
|
6
6
|
import { PayloadDivinerContext } from './Context.ts'
|
|
7
|
+
import type { PayloadDivinerState } from './State.ts'
|
|
7
8
|
|
|
8
9
|
export type PayloadDivinerProviderProps = ContextExProviderProps<{
|
|
9
10
|
/** Required */
|
|
@@ -15,7 +16,7 @@ export const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({
|
|
|
15
16
|
}) => {
|
|
16
17
|
const [diviner, setDiviner] = useResetState<PayloadDiviner | undefined>(divinerProp)
|
|
17
18
|
|
|
18
|
-
const value = useMemo(() => ({
|
|
19
|
+
const value: PayloadDivinerState = useMemo(() => ({
|
|
19
20
|
diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner,
|
|
20
21
|
}), [diviner, divinerProp, setDiviner])
|
|
21
22
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { ContextExState } from '@xylabs/react-shared'
|
|
1
2
|
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
|
|
2
3
|
import type { Dispatch } from 'react'
|
|
3
4
|
|
|
4
|
-
export
|
|
5
|
+
export type PayloadDivinerState = ContextExState<{
|
|
5
6
|
diviner?: PayloadDiviner
|
|
6
7
|
setDiviner?: Dispatch<PayloadDiviner>
|
|
7
|
-
}
|
|
8
|
+
}>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { exists } from '@xylabs/exists'
|
|
2
2
|
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
3
|
+
import { useContextEx } from '@xylabs/react-shared'
|
|
3
4
|
import type { HuriPayload } from '@xyo-network/diviner-huri'
|
|
4
5
|
import { HuriSchema } from '@xyo-network/diviner-huri'
|
|
5
6
|
import type { Payload } from '@xyo-network/payload-model'
|
|
6
|
-
import { useContextEx } from '@xyo-network/react-shared'
|
|
7
7
|
import type { Dispatch } from 'react'
|
|
8
8
|
import { useEffect, useState } from 'react'
|
|
9
9
|
|