@xyo-network/react-payload-diviner 3.0.2 → 3.0.3
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/contexts/DivinedPayload/Context.d.ts +3 -0
- package/dist/browser/contexts/DivinedPayload/Context.d.ts.map +1 -0
- package/dist/browser/contexts/DivinedPayload/Provider.d.ts +9 -0
- package/dist/browser/contexts/DivinedPayload/Provider.d.ts.map +1 -0
- package/dist/browser/contexts/DivinedPayload/State.d.ts +9 -0
- package/dist/browser/contexts/DivinedPayload/State.d.ts.map +1 -0
- package/dist/browser/contexts/DivinedPayload/index.d.ts +5 -0
- package/dist/browser/contexts/DivinedPayload/index.d.ts.map +1 -0
- package/dist/browser/contexts/DivinedPayload/use.d.ts +2 -0
- package/dist/browser/contexts/DivinedPayload/use.d.ts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/Context.d.ts +4 -0
- package/dist/browser/contexts/PayloadDiviner/Context.d.ts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/Provider.d.ts +8 -0
- package/dist/browser/contexts/PayloadDiviner/Provider.d.ts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/State.d.ts +7 -0
- package/dist/browser/contexts/PayloadDiviner/State.d.ts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/index.d.ts +5 -0
- package/dist/browser/contexts/PayloadDiviner/index.d.ts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/use.d.ts +10 -0
- package/dist/browser/contexts/PayloadDiviner/use.d.ts.map +1 -0
- package/dist/browser/contexts/index.d.ts +3 -0
- package/dist/browser/contexts/index.d.ts.map +1 -0
- package/dist/browser/index.d.ts +2 -47
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.mjs +12 -7
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +51 -46
- package/src/contexts/DivinedPayload/Provider.tsx +15 -4
- package/src/contexts/PayloadDiviner/Provider.tsx +9 -3
- package/xy.config.ts +1 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,eAAO,MAAM,qBAAqB,mGAAyC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WithChildren } from '@xylabs/react-shared';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface DivinedPayloadProviderProps extends WithChildren {
|
|
4
|
+
hash?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps>;
|
|
7
|
+
export declare const DivinedPayloadWithHandleInner: React.FC<WithChildren>;
|
|
8
|
+
export declare const DivinedPayloadWithHandleProvider: React.FC<DivinedPayloadProviderProps>;
|
|
9
|
+
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAIxD,OAAO,KAAkB,MAAM,OAAO,CAAA;AAOtC,MAAM,WAAW,2BAA4B,SAAQ,YAAY;IAC/D,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,YAAY,CAehE,CAAA;AAED,eAAO,MAAM,gCAAgC,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAMlF,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Payload } from '@xyo-network/payload-model';
|
|
2
|
+
import type { ContextExState } from '@xyo-network/react-shared';
|
|
3
|
+
import type { Dispatch } from 'react';
|
|
4
|
+
export interface DivinedPayloadState extends ContextExState {
|
|
5
|
+
payload?: Payload | null;
|
|
6
|
+
payloadError?: Error;
|
|
7
|
+
setPayload?: Dispatch<Payload | null | undefined>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=State.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/State.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAErC,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/use.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,uHAAoE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/Context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,QAAA,MAAM,qBAAqB,mGAAyC,CAAA;AAEpE,OAAO,EAAE,qBAAqB,EAAE,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract';
|
|
2
|
+
import type { ContextExProviderProps } from '@xyo-network/react-shared';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export type PayloadDivinerProviderProps = ContextExProviderProps<{
|
|
5
|
+
diviner?: PayloadDiviner;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps>;
|
|
8
|
+
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAC3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AACvE,OAAO,KAEN,MAAM,OAAO,CAAA;AAId,MAAM,MAAM,2BAA2B,GAAG,sBAAsB,CAAC;IAE/D,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB,CAAC,CAAA;AAEF,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CA0BxE,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract';
|
|
2
|
+
import type { Dispatch } from 'react';
|
|
3
|
+
export interface PayloadDivinerState {
|
|
4
|
+
diviner?: PayloadDiviner;
|
|
5
|
+
setDiviner?: Dispatch<PayloadDiviner>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=State.d.ts.map
|
|
@@ -0,0 +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,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,UAAU,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAA;CACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Payload } from '@xyo-network/payload-model';
|
|
2
|
+
import type { Dispatch } from 'react';
|
|
3
|
+
export declare const usePayloadDiviner: (required?: boolean) => Omit<import("./State.ts").PayloadDivinerState & import("@xyo-network/react-shared").ContextExState, "provided">;
|
|
4
|
+
export declare const useDivinePayload: <T extends Payload = {
|
|
5
|
+
schema: string;
|
|
6
|
+
} & import("@xyo-network/payload-model").PayloadFields>(huri?: string) => [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined];
|
|
7
|
+
export declare const useDivinePayloads: <T extends Payload = {
|
|
8
|
+
schema: string;
|
|
9
|
+
} & import("@xyo-network/payload-model").PayloadFields>(huriList: string[]) => [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined];
|
|
10
|
+
//# sourceMappingURL=use.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/use.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAY,MAAM,4BAA4B,CAAA;AAEnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAKrC,eAAO,MAAM,iBAAiB,yIAE7B,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO;;+DACzC,MAAM,KACZ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS,CA+B1E,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,OAAO;;kEACvC,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,CA0CpF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA"}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,47 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import * as _xyo_network_react_shared from '@xyo-network/react-shared';
|
|
4
|
-
import { ContextExState, ContextExProviderProps } from '@xyo-network/react-shared';
|
|
5
|
-
import * as _xyo_network_payload_model from '@xyo-network/payload-model';
|
|
6
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
7
|
-
import { WithChildren } from '@xylabs/react-shared';
|
|
8
|
-
import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract';
|
|
9
|
-
|
|
10
|
-
interface DivinedPayloadState extends ContextExState {
|
|
11
|
-
payload?: Payload | null;
|
|
12
|
-
payloadError?: Error;
|
|
13
|
-
setPayload?: Dispatch<Payload | null | undefined>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
declare const DivinedPayloadContext: React.Context<DivinedPayloadState & _xyo_network_react_shared.ContextExState>;
|
|
17
|
-
|
|
18
|
-
interface DivinedPayloadProviderProps extends WithChildren {
|
|
19
|
-
hash?: string;
|
|
20
|
-
}
|
|
21
|
-
declare const DivinedPayloadProvider: React__default.FC<DivinedPayloadProviderProps>;
|
|
22
|
-
declare const DivinedPayloadWithHandleInner: React__default.FC<WithChildren>;
|
|
23
|
-
declare const DivinedPayloadWithHandleProvider: React__default.FC<DivinedPayloadProviderProps>;
|
|
24
|
-
|
|
25
|
-
declare const useDivinedPayload: () => Omit<DivinedPayloadState & _xyo_network_react_shared.ContextExState, "provided">;
|
|
26
|
-
|
|
27
|
-
interface PayloadDivinerState {
|
|
28
|
-
diviner?: PayloadDiviner;
|
|
29
|
-
setDiviner?: Dispatch<PayloadDiviner>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare const PayloadDivinerContext: React.Context<PayloadDivinerState & _xyo_network_react_shared.ContextExState>;
|
|
33
|
-
|
|
34
|
-
type PayloadDivinerProviderProps = ContextExProviderProps<{
|
|
35
|
-
diviner?: PayloadDiviner;
|
|
36
|
-
}>;
|
|
37
|
-
declare const PayloadDivinerProvider: React__default.FC<PayloadDivinerProviderProps>;
|
|
38
|
-
|
|
39
|
-
declare const usePayloadDiviner: (required?: boolean) => Omit<PayloadDivinerState & _xyo_network_react_shared.ContextExState, "provided">;
|
|
40
|
-
declare const useDivinePayload: <T extends Payload = {
|
|
41
|
-
schema: string;
|
|
42
|
-
} & _xyo_network_payload_model.PayloadFields>(huri?: string) => [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined];
|
|
43
|
-
declare const useDivinePayloads: <T extends Payload = {
|
|
44
|
-
schema: string;
|
|
45
|
-
} & _xyo_network_payload_model.PayloadFields>(huriList: string[]) => [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined];
|
|
46
|
-
|
|
47
|
-
export { DivinedPayloadContext, DivinedPayloadProvider, type DivinedPayloadProviderProps, type DivinedPayloadState, DivinedPayloadWithHandleInner, DivinedPayloadWithHandleProvider, PayloadDivinerContext, PayloadDivinerProvider, type PayloadDivinerProviderProps, type PayloadDivinerState, useDivinePayload, useDivinePayloads, useDivinedPayload, usePayloadDiviner };
|
|
1
|
+
export * from './contexts/index.ts';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ var DivinedPayloadContext = createContextEx();
|
|
|
9
9
|
import { ModuleErrorSchema } from "@xyo-network/payload-model";
|
|
10
10
|
import { ErrorRender } from "@xyo-network/react-error";
|
|
11
11
|
import { useBuildHuri } from "@xyo-network/react-payload-huri";
|
|
12
|
-
import React2 from "react";
|
|
12
|
+
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
|
|
@@ -163,13 +163,18 @@ var DivinedPayloadProvider = /* @__PURE__ */ __name(({ children, hash }) => {
|
|
|
163
163
|
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
164
164
|
const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam;
|
|
165
165
|
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
166
|
+
const value = useMemo2(() => ({
|
|
167
|
+
payload,
|
|
168
|
+
payloadError,
|
|
169
|
+
provided: true,
|
|
170
|
+
setPayload
|
|
171
|
+
}), [
|
|
172
|
+
payload,
|
|
173
|
+
payloadError,
|
|
174
|
+
setPayload
|
|
175
|
+
]);
|
|
166
176
|
return /* @__PURE__ */ React2.createElement(DivinedPayloadContext.Provider, {
|
|
167
|
-
value
|
|
168
|
-
payload,
|
|
169
|
-
payloadError,
|
|
170
|
-
provided: true,
|
|
171
|
-
setPayload
|
|
172
|
-
}
|
|
177
|
+
value
|
|
173
178
|
}, children);
|
|
174
179
|
}, "DivinedPayloadProvider");
|
|
175
180
|
var DivinedPayloadWithHandleInner = /* @__PURE__ */ __name(({ children }) => {
|
|
@@ -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 type { WithChildren } from '@xylabs/react-shared'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { ErrorRender } from '@xyo-network/react-error'\nimport { useBuildHuri } from '@xyo-network/react-payload-huri'\nimport React 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 WithChildren {\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 // eslint-disable-next-line @eslint-react/no-unstable-context-value\n return <DivinedPayloadContext.Provider value={{ payload, payloadError, provided: true, setPayload }}>{children}</DivinedPayloadContext.Provider>\n}\n\nexport const DivinedPayloadWithHandleInner: React.FC<WithChildren> = ({ children }) => {\n const { payloadError } = useDivinedPayload()\n\n return (\n <ErrorRender\n error={payloadError ? { message: payloadError.message, schema: ModuleErrorSchema, sources: [] } : 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 type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport type { ContextExProviderProps } from '@xyo-network/react-shared'\nimport React, { useEffect, useMemo, useState } 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> = ({ diviner: divinerProp, required = false, children }) => {\n const [diviner, setDiviner] = useState<PayloadDiviner | undefined>(divinerProp)\n\n useEffect(() => {\n if (divinerProp) {\n setDiviner(divinerProp)\n }\n }, [divinerProp])\n\n const value = useMemo(() => ({ diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner }), [diviner, divinerProp, setDiviner])\n\n return (\n <PayloadDivinerContext.Provider\n value={value}\n >\n {diviner\n ? children\n : required\n ? null\n : children}\n </PayloadDivinerContext.Provider>\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, WithMeta } 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 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 WithMeta<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 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;;;ACHrC,SAASE,yBAAyB;AAClC,SAASC,mBAAmB;AAC5B,SAASC,oBAAoB;AAC7B,OAAOC,YAAW;AAClB,SAASC,WAAWC,uBAAuB;;;ACL3C,SAASC,mBAAAA,wBAAuB;AAIhC,IAAMC,wBAAwBD,iBAAAA;;;ACF9B,OAAOE,SAASC,WAAWC,SAASC,gBAAgB;AAS7C,IAAMC,yBAAgE,wBAAC,EAAEC,SAASC,aAAaC,WAAW,OAAOC,SAAQ,MAAE;AAChI,QAAM,CAACH,SAASI,UAAAA,IAAcC,SAAqCJ,WAAAA;AAEnEK,YAAU,MAAA;AACR,QAAIL,aAAa;AACfG,iBAAWH,WAAAA;IACb;EACF,GAAG;IAACA;GAAY;AAEhB,QAAMM,QAAQC,QAAQ,OAAO;IAAER,SAASA,YAAYC,cAAcD,UAAUS;IAAWC,UAAU;IAAMN;EAAW,IAAI;IAACJ;IAASC;IAAaG;GAAW;AAExJ,SACE,sBAAA,cAACO,sBAAsBC,UAAQ;IAC7BL;KAECP,UACGG,WACAD,WACE,OACAC,QAAAA;AAGZ,GAtB6E;;;ACX7E,SAASU,cAAc;AACvB,SAASC,sBAAsB;AAE/B,SAASC,kBAAkB;AAE3B,SAASC,oBAAoB;AAE7B,SAASC,aAAAA,YAAWC,YAAAA,iBAAgB;AAI7B,IAAMC,oBAAoB,wBAACC,WAAW,UAAK;AAChD,SAAOC,aAAaC,uBAAuB,kBA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ACnE,QAAMI,UAAUX,QAAQS,oBAAoBN;AAE5C,QAAM,CAACS,SAASC,YAAYC,YAAAA,IAAgBC,iBAAiBJ,OAAAA;AAG7D,SAAO,gBAAAK,OAAA,cAACC,sBAAsBC,UAAQ;IAACC,OAAO;MAAEP;MAASE;MAAcM,UAAU;MAAMP;IAAW;KAAId,QAAAA;AACxG,GAd6E;AAgBtE,IAAMsB,gCAAwD,wBAAC,EAAEtB,SAAQ,MAAE;AAChF,QAAM,EAAEe,aAAY,IAAKQ,kBAAAA;AAEzB,SACE,gBAAAN,OAAA,cAACO,aAAAA;IACCC,OAAOV,eAAe;MAAEW,SAASX,aAAaW;MAASC,QAAQC;MAAmBC,SAAS,CAAA;IAAG,IAAIC;IAClGC,cAAa;KAEZ/B,QAAAA;AAGP,GAXqE;AAa9D,IAAMgC,mCAA0E,wBAAC,EAAEhC,UAAU,GAAGiC,MAAAA,MAAO;AAC5G,SACE,gBAAAhB,OAAA,cAAClB,wBAA2BkC,OAC1B,gBAAAhB,OAAA,cAACK,+BAAAA,MAA+BtB,QAAAA,CAAAA;AAGtC,GANuF;","names":["createContextEx","DivinedPayloadContext","ModuleErrorSchema","ErrorRender","useBuildHuri","React","useParams","useSearchParams","createContextEx","PayloadDivinerContext","React","useEffect","useMemo","useState","PayloadDivinerProvider","diviner","divinerProp","required","children","setDiviner","useState","useEffect","value","useMemo","undefined","provided","PayloadDivinerContext","Provider","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","React","DivinedPayloadContext","Provider","value","provided","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 '@xyo-network/react-shared'\n\nimport type { DivinedPayloadState } from './State.ts'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n","import type { WithChildren } from '@xylabs/react-shared'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { ErrorRender } from '@xyo-network/react-error'\nimport { useBuildHuri } from '@xyo-network/react-payload-huri'\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 WithChildren {\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.Provider value={value}>\n {children}\n </DivinedPayloadContext.Provider>\n )\n}\n\nexport const DivinedPayloadWithHandleInner: React.FC<WithChildren> = ({ 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 type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport type { ContextExProviderProps } from '@xyo-network/react-shared'\nimport React, {\n useEffect, useMemo, useState,\n} 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] = useState<PayloadDiviner | undefined>(divinerProp)\n\n useEffect(() => {\n if (divinerProp) {\n setDiviner(divinerProp)\n }\n }, [divinerProp])\n\n const value = useMemo(() => ({\n diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner,\n }), [diviner, divinerProp, setDiviner])\n\n return (\n <PayloadDivinerContext.Provider\n value={value}\n >\n {diviner\n ? children\n : required\n ? null\n : children}\n </PayloadDivinerContext.Provider>\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, WithMeta } 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 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 WithMeta<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 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;;;ACHrC,SAASE,yBAAyB;AAClC,SAASC,mBAAmB;AAC5B,SAASC,oBAAoB;AAC7B,OAAOC,UAASC,WAAAA,gBAAe;AAC/B,SAASC,WAAWC,uBAAuB;;;ACL3C,SAASC,mBAAAA,wBAAuB;AAIhC,IAAMC,wBAAwBD,iBAAAA;;;ACF9B,OAAOE,SACLC,WAAWC,SAASC,gBACf;AASA,IAAMC,yBAAgE,wBAAC,EAC5EC,SAASC,aAAaC,WAAW,OAAOC,SAAQ,MACjD;AACC,QAAM,CAACH,SAASI,UAAAA,IAAcC,SAAqCJ,WAAAA;AAEnEK,YAAU,MAAA;AACR,QAAIL,aAAa;AACfG,iBAAWH,WAAAA;IACb;EACF,GAAG;IAACA;GAAY;AAEhB,QAAMM,QAAQC,QAAQ,OAAO;IAC3BR,SAASA,YAAYC,cAAcD,UAAUS;IAAWC,UAAU;IAAMN;EAC1E,IAAI;IAACJ;IAASC;IAAaG;GAAW;AAEtC,SACE,sBAAA,cAACO,sBAAsBC,UAAQ;IAC7BL;KAECP,UACGG,WACAD,WACE,OACAC,QAAAA;AAGZ,GA1B6E;;;ACb7E,SAASU,cAAc;AACvB,SAASC,sBAAsB;AAE/B,SAASC,kBAAkB;AAE3B,SAASC,oBAAoB;AAE7B,SAASC,aAAAA,YA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AAA;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,QAAQC,SAAQ,OAAO;IAC3BL;IAASE;IAAcI,UAAU;IAAML;EACzC,IAAI;IAACD;IAASE;IAAcD;GAAW;AAEvC,SACE,gBAAAM,OAAA,cAACC,sBAAsBC,UAAQ;IAACL;KAC7BjB,QAAAA;AAGP,GArB6E;AAuBtE,IAAMuB,gCAAwD,wBAAC,EAAEvB,SAAQ,MAAE;AAChF,QAAM,EAAEe,aAAY,IAAKS,kBAAAA;AAEzB,SACE,gBAAAJ,OAAA,cAACK,aAAAA;IACCC,OAAOX,eACH;MACEY,SAASZ,aAAaY;MAASC,QAAQC;MAAmBC,SAAS,CAAA;IACrE,IACAC;IACJC,cAAa;KAEZhC,QAAAA;AAGP,GAfqE;AAiB9D,IAAMiC,mCAA0E,wBAAC,EAAEjC,UAAU,GAAGkC,MAAAA,MAAO;AAC5G,SACE,gBAAAd,OAAA,cAACrB,wBAA2BmC,OAC1B,gBAAAd,OAAA,cAACG,+BAAAA,MAA+BvB,QAAAA,CAAAA;AAGtC,GANuF;","names":["createContextEx","DivinedPayloadContext","ModuleErrorSchema","ErrorRender","useBuildHuri","React","useMemo","useParams","useSearchParams","createContextEx","PayloadDivinerContext","React","useEffect","useMemo","useState","PayloadDivinerProvider","diviner","divinerProp","required","children","setDiviner","useState","useEffect","value","useMemo","undefined","provided","PayloadDivinerContext","Provider","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","Provider","DivinedPayloadWithHandleInner","useDivinedPayload","ErrorRender","error","message","schema","ModuleErrorSchema","sources","undefined","errorContext","DivinedPayloadWithHandleProvider","props"]}
|
package/package.json
CHANGED
|
@@ -1,28 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/react-payload-diviner",
|
|
3
|
+
"version": "3.0.3",
|
|
4
|
+
"description": "Common React library for all XYO projects that use React",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"xyo",
|
|
7
|
+
"utility",
|
|
8
|
+
"typescript",
|
|
9
|
+
"react"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://xyo.network",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues",
|
|
14
|
+
"email": "support@xyo.network"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "LGPL-3.0-only",
|
|
3
21
|
"author": {
|
|
4
|
-
"email": "support@xyo.network",
|
|
5
22
|
"name": "XYO Development Team",
|
|
23
|
+
"email": "support@xyo.network",
|
|
6
24
|
"url": "https://xyo.network"
|
|
7
25
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/browser/index.d.ts",
|
|
32
|
+
"default": "./dist/browser/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"types": "./dist/browser/index.d.ts",
|
|
35
|
+
"default": "./dist/browser/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"module": "dist/browser/index.mjs",
|
|
40
|
+
"types": "dist/browser/index.d.ts",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\"",
|
|
43
|
+
"lint-pkg": "npmPkgJsonLint ."
|
|
11
44
|
},
|
|
12
45
|
"dependencies": {
|
|
13
|
-
"@xylabs/exists": "^4.0.
|
|
46
|
+
"@xylabs/exists": "^4.0.5",
|
|
14
47
|
"@xylabs/react-async-effect": "^4.0.3",
|
|
15
48
|
"@xylabs/react-shared": "^4.0.3",
|
|
16
|
-
"@xyo-network/diviner-huri": "^3.0.
|
|
17
|
-
"@xyo-network/diviner-payload-abstract": "^3.0.
|
|
18
|
-
"@xyo-network/payload-model": "^3.0.
|
|
19
|
-
"@xyo-network/react-error": "^3.0.
|
|
20
|
-
"@xyo-network/react-payload-huri": "^3.0.
|
|
21
|
-
"@xyo-network/react-shared": "^3.0.
|
|
49
|
+
"@xyo-network/diviner-huri": "^3.0.15",
|
|
50
|
+
"@xyo-network/diviner-payload-abstract": "^3.0.15",
|
|
51
|
+
"@xyo-network/payload-model": "^3.0.15",
|
|
52
|
+
"@xyo-network/react-error": "^3.0.3",
|
|
53
|
+
"@xyo-network/react-payload-huri": "^3.0.3",
|
|
54
|
+
"@xyo-network/react-shared": "^3.0.3",
|
|
22
55
|
"react-router-dom": "^6.26.1"
|
|
23
56
|
},
|
|
24
57
|
"devDependencies": {
|
|
25
|
-
"@
|
|
58
|
+
"@mui/icons-material": "^5.16.7",
|
|
59
|
+
"@mui/material": "^5.16.7",
|
|
60
|
+
"@mui/styles": "^5.16.7",
|
|
61
|
+
"@xylabs/ts-scripts-yarn3": "^4.0.7",
|
|
62
|
+
"react": "^18.3.1",
|
|
63
|
+
"react-dom": "^18.3.1",
|
|
26
64
|
"typescript": "^5.5.4"
|
|
27
65
|
},
|
|
28
66
|
"peerDependencies": {
|
|
@@ -32,41 +70,8 @@
|
|
|
32
70
|
"react": "^18",
|
|
33
71
|
"react-dom": "^18"
|
|
34
72
|
},
|
|
35
|
-
"description": "Common React library for all XYO projects that use React",
|
|
36
|
-
"docs": "dist/docs.json",
|
|
37
|
-
"exports": {
|
|
38
|
-
".": {
|
|
39
|
-
"import": {
|
|
40
|
-
"types": "./dist/browser/index.d.ts",
|
|
41
|
-
"default": "./dist/browser/index.mjs"
|
|
42
|
-
},
|
|
43
|
-
"types": "./dist/browser/index.d.ts",
|
|
44
|
-
"default": "./dist/browser/index.mjs"
|
|
45
|
-
},
|
|
46
|
-
"./package.json": "./package.json"
|
|
47
|
-
},
|
|
48
|
-
"module": "dist/browser/index.mjs",
|
|
49
|
-
"homepage": "https://xyo.network",
|
|
50
|
-
"keywords": [
|
|
51
|
-
"xyo",
|
|
52
|
-
"utility",
|
|
53
|
-
"typescript",
|
|
54
|
-
"react"
|
|
55
|
-
],
|
|
56
|
-
"license": "LGPL-3.0-only",
|
|
57
73
|
"publishConfig": {
|
|
58
74
|
"access": "public"
|
|
59
75
|
},
|
|
60
|
-
"
|
|
61
|
-
"type": "git",
|
|
62
|
-
"url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
|
|
63
|
-
},
|
|
64
|
-
"scripts": {
|
|
65
|
-
"lint-pkg": "npmPkgJsonLint .",
|
|
66
|
-
"license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\""
|
|
67
|
-
},
|
|
68
|
-
"sideEffects": false,
|
|
69
|
-
"types": "dist/browser/index.d.ts",
|
|
70
|
-
"version": "3.0.2",
|
|
71
|
-
"type": "module"
|
|
76
|
+
"docs": "dist/docs.json"
|
|
72
77
|
}
|
|
@@ -2,7 +2,7 @@ import type { WithChildren } from '@xylabs/react-shared'
|
|
|
2
2
|
import { ModuleErrorSchema } from '@xyo-network/payload-model'
|
|
3
3
|
import { ErrorRender } from '@xyo-network/react-error'
|
|
4
4
|
import { useBuildHuri } from '@xyo-network/react-payload-huri'
|
|
5
|
-
import React from 'react'
|
|
5
|
+
import React, { useMemo } from 'react'
|
|
6
6
|
import { useParams, useSearchParams } from 'react-router-dom'
|
|
7
7
|
|
|
8
8
|
import { useDivinePayload } from '../PayloadDiviner/index.ts'
|
|
@@ -25,8 +25,15 @@ export const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps> = ({
|
|
|
25
25
|
|
|
26
26
|
const [payload, setPayload, payloadError] = useDivinePayload(huriUri)
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const value = useMemo(() => ({
|
|
29
|
+
payload, payloadError, provided: true, setPayload,
|
|
30
|
+
}), [payload, payloadError, setPayload])
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<DivinedPayloadContext.Provider value={value}>
|
|
34
|
+
{children}
|
|
35
|
+
</DivinedPayloadContext.Provider>
|
|
36
|
+
)
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
export const DivinedPayloadWithHandleInner: React.FC<WithChildren> = ({ children }) => {
|
|
@@ -34,7 +41,11 @@ export const DivinedPayloadWithHandleInner: React.FC<WithChildren> = ({ children
|
|
|
34
41
|
|
|
35
42
|
return (
|
|
36
43
|
<ErrorRender
|
|
37
|
-
error={payloadError
|
|
44
|
+
error={payloadError
|
|
45
|
+
? {
|
|
46
|
+
message: payloadError.message, schema: ModuleErrorSchema, sources: [],
|
|
47
|
+
}
|
|
48
|
+
: undefined}
|
|
38
49
|
errorContext="Divined Payload Provider"
|
|
39
50
|
>
|
|
40
51
|
{children}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
|
|
2
2
|
import type { ContextExProviderProps } from '@xyo-network/react-shared'
|
|
3
|
-
import React, {
|
|
3
|
+
import React, {
|
|
4
|
+
useEffect, useMemo, useState,
|
|
5
|
+
} from 'react'
|
|
4
6
|
|
|
5
7
|
import { PayloadDivinerContext } from './Context.ts'
|
|
6
8
|
|
|
@@ -9,7 +11,9 @@ export type PayloadDivinerProviderProps = ContextExProviderProps<{
|
|
|
9
11
|
diviner?: PayloadDiviner
|
|
10
12
|
}>
|
|
11
13
|
|
|
12
|
-
export const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({
|
|
14
|
+
export const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({
|
|
15
|
+
diviner: divinerProp, required = false, children,
|
|
16
|
+
}) => {
|
|
13
17
|
const [diviner, setDiviner] = useState<PayloadDiviner | undefined>(divinerProp)
|
|
14
18
|
|
|
15
19
|
useEffect(() => {
|
|
@@ -18,7 +22,9 @@ export const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({
|
|
|
18
22
|
}
|
|
19
23
|
}, [divinerProp])
|
|
20
24
|
|
|
21
|
-
const value = useMemo(() => ({
|
|
25
|
+
const value = useMemo(() => ({
|
|
26
|
+
diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner,
|
|
27
|
+
}), [diviner, divinerProp, setDiviner])
|
|
22
28
|
|
|
23
29
|
return (
|
|
24
30
|
<PayloadDivinerContext.Provider
|