@xyo-network/react-payload-diviner 7.5.0 → 7.5.1
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
CHANGED
|
@@ -36,9 +36,9 @@ var PayloadDivinerProvider = /* @__PURE__ */ __name(({ diviner: divinerProp, req
|
|
|
36
36
|
}, "PayloadDivinerProvider");
|
|
37
37
|
|
|
38
38
|
// src/contexts/PayloadDiviner/use.ts
|
|
39
|
-
import { exists } from "@xylabs/exists";
|
|
40
39
|
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
41
40
|
import { useContextEx } from "@xylabs/react-shared";
|
|
41
|
+
import { exists } from "@xylabs/sdk-js";
|
|
42
42
|
import { HuriSchema } from "@xyo-network/diviner-huri";
|
|
43
43
|
import { useEffect, useState } from "react";
|
|
44
44
|
var usePayloadDiviner = /* @__PURE__ */ __name((required = false) => {
|
|
@@ -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 '@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 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 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,cAA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A;IAAUC;IAAaC;;AACjC,GA7CiC;;;ACnDjC,SAASiB,gBAAAA,qBAAoB;AAItB,IAAMC,oBAAoB,6BAAMC,cAAaC,uBAAuB,kBAAkB,IAAA,GAA5D;;;AJY1B,IAAMC,yBAAgE,wBAAC,EAAEC,UAAUC,KAAI,MAAE;AAC9F,QAAM,EAAEA,MAAMC,UAAS,IAAKC,UAAAA;AAE5B,QAAMC,oBAAoBC,aAAaH,SAAAA;AAEvC,QAAM,CAACI,MAAAA,IAAUC,gBAAAA;AACjB,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
|
+
{"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 { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { useContextEx } from '@xylabs/react-shared'\nimport { exists } from '@xylabs/sdk-js'\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 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 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,WAA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loadContext","ErrorRender","ModuleErrorSchema","useBuildHuri","React","useMemo","useParams","useSearchParams","createContextEx","PayloadDivinerContext","useResetState","React","useMemo","PayloadDivinerProvider","diviner","divinerProp","required","children","setDiviner","useResetState","value","useMemo","undefined","provided","PayloadDivinerContext","useAsyncEffect","useContextEx","exists","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/react-payload-diviner",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.1",
|
|
4
4
|
"description": "Common React library for all XYO projects that use React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xyo",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
"src"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@xylabs/
|
|
47
|
-
"@xylabs/react-
|
|
48
|
-
"@xylabs/react-
|
|
49
|
-
"@xylabs/react-
|
|
50
|
-
"@xylabs/
|
|
46
|
+
"@xylabs/react-async-effect": "~7.1.12",
|
|
47
|
+
"@xylabs/react-error": "~7.1.12",
|
|
48
|
+
"@xylabs/react-hooks": "~7.1.12",
|
|
49
|
+
"@xylabs/react-shared": "~7.1.12",
|
|
50
|
+
"@xylabs/sdk-js": "~5.0.64",
|
|
51
51
|
"@xyo-network/diviner-huri": "~5.3.2",
|
|
52
52
|
"@xyo-network/diviner-payload-abstract": "~5.3.2",
|
|
53
53
|
"@xyo-network/payload-model": "~5.3.2",
|
|
54
|
-
"@xyo-network/react-payload-huri": "7.5.
|
|
54
|
+
"@xyo-network/react-payload-huri": "7.5.1",
|
|
55
55
|
"react-router-dom": "^7.13.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
@@ -61,13 +61,15 @@
|
|
|
61
61
|
"@xylabs/ts-scripts-yarn3": "~7.3.2",
|
|
62
62
|
"react": "^19.2.4",
|
|
63
63
|
"react-dom": "^19.2.4",
|
|
64
|
-
"typescript": "^5.9.3"
|
|
64
|
+
"typescript": "^5.9.3",
|
|
65
|
+
"zod": "^4.3.6"
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
68
|
"@mui/icons-material": ">=6 <8",
|
|
68
69
|
"@mui/material": ">=6 <8",
|
|
69
70
|
"react": "^19",
|
|
70
|
-
"react-dom": "^19"
|
|
71
|
+
"react-dom": "^19",
|
|
72
|
+
"zod": "^4.3.6"
|
|
71
73
|
},
|
|
72
74
|
"publishConfig": {
|
|
73
75
|
"access": "public"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { exists } from '@xylabs/exists'
|
|
2
1
|
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
3
2
|
import { useContextEx } from '@xylabs/react-shared'
|
|
3
|
+
import { exists } from '@xylabs/sdk-js'
|
|
4
4
|
import type { HuriPayload } from '@xyo-network/diviner-huri'
|
|
5
5
|
import { HuriSchema } from '@xyo-network/diviner-huri'
|
|
6
6
|
import type { Payload } from '@xyo-network/payload-model'
|