@xyo-network/react-embed 2.64.0 → 2.64.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/browser/components/EmbedPlugin.js +203 -11
- package/dist/browser/components/EmbedPlugin.js.map +1 -1
- package/dist/browser/components/EmbedResolver.js +13 -3
- package/dist/browser/components/EmbedResolver.js.map +1 -1
- package/dist/browser/components/controls/EmbedFormControl.js +3 -2
- package/dist/browser/components/controls/EmbedFormControl.js.map +1 -1
- package/dist/browser/components/controls/ListModeSelect.js +23 -11
- package/dist/browser/components/controls/ListModeSelect.js.map +1 -1
- package/dist/browser/components/controls/RenderSelect.js +26 -7
- package/dist/browser/components/controls/RenderSelect.js.map +1 -1
- package/dist/browser/components/controls/index.js +63 -3
- package/dist/browser/components/controls/index.js.map +1 -1
- package/dist/browser/components/embed-card/EmbedCardResolver.js +52 -5
- package/dist/browser/components/embed-card/EmbedCardResolver.js.map +1 -1
- package/dist/browser/components/embed-card/EmbedPluginCard.js +429 -11
- package/dist/browser/components/embed-card/EmbedPluginCard.js.map +1 -1
- package/dist/browser/components/embed-card/card/BusyCard.js +3 -2
- package/dist/browser/components/embed-card/card/BusyCard.js.map +1 -1
- package/dist/browser/components/embed-card/card/EmbedCardHeader.js +61 -10
- package/dist/browser/components/embed-card/card/EmbedCardHeader.js.map +1 -1
- package/dist/browser/components/embed-card/card/EmbedPluginCard.js +168 -13
- package/dist/browser/components/embed-card/card/EmbedPluginCard.js.map +1 -1
- package/dist/browser/components/embed-card/card/index.js +182 -3
- package/dist/browser/components/embed-card/card/index.js.map +1 -1
- package/dist/browser/components/embed-card/error-handling/EmbedCardApiErrorRenderer.js +26 -6
- package/dist/browser/components/embed-card/error-handling/EmbedCardApiErrorRenderer.js.map +1 -1
- package/dist/browser/components/embed-card/error-handling/EmbedErrorCard.js +4 -3
- package/dist/browser/components/embed-card/error-handling/EmbedErrorCard.js.map +1 -1
- package/dist/browser/components/embed-card/error-handling/index.js +33 -2
- package/dist/browser/components/embed-card/error-handling/index.js.map +1 -1
- package/dist/browser/components/embed-card/index.js +481 -2
- package/dist/browser/components/embed-card/index.js.map +1 -1
- package/dist/browser/components/embed-card/menu/EmbedMenu.js +30 -6
- package/dist/browser/components/embed-card/menu/EmbedMenu.js.map +1 -1
- package/dist/browser/components/embed-card/menu/JsonMenuItem.js +13 -3
- package/dist/browser/components/embed-card/menu/JsonMenuItem.js.map +1 -1
- package/dist/browser/components/embed-card/menu/index.js +46 -1
- package/dist/browser/components/embed-card/menu/index.js.map +1 -1
- package/dist/browser/components/embed-plugin-stories/storyPayload.js +2 -1
- package/dist/browser/components/embed-plugin-stories/storyPayload.js.map +1 -1
- package/dist/browser/components/embed-plugin-stories/storyShared.js +480 -5
- package/dist/browser/components/embed-plugin-stories/storyShared.js.map +1 -1
- package/dist/browser/components/index.js +482 -2
- package/dist/browser/components/index.js.map +1 -1
- package/dist/browser/components/validation-alerts/ValidatePayload.js +13 -3
- package/dist/browser/components/validation-alerts/ValidatePayload.js.map +1 -1
- package/dist/browser/components/validation-alerts/ValidatePlugins.js +21 -3
- package/dist/browser/components/validation-alerts/ValidatePlugins.js.map +1 -1
- package/dist/browser/components/validation-alerts/index.js +59 -2
- package/dist/browser/components/validation-alerts/index.js.map +1 -1
- package/dist/browser/contexts/EmbedPluginContext/Context.js +2 -1
- package/dist/browser/contexts/EmbedPluginContext/Context.js.map +1 -1
- package/dist/browser/contexts/EmbedPluginContext/Provider.js +9 -3
- package/dist/browser/contexts/EmbedPluginContext/Provider.js.map +1 -1
- package/dist/browser/contexts/EmbedPluginContext/index.js +44 -4
- package/dist/browser/contexts/EmbedPluginContext/index.js.map +1 -1
- package/dist/browser/contexts/EmbedPluginContext/use.js +8 -2
- package/dist/browser/contexts/EmbedPluginContext/use.js.map +1 -1
- package/dist/browser/contexts/RefreshPayloadContext/Context.js +2 -1
- package/dist/browser/contexts/RefreshPayloadContext/Context.js.map +1 -1
- package/dist/browser/contexts/RefreshPayloadContext/Provider.js +9 -3
- package/dist/browser/contexts/RefreshPayloadContext/Provider.js.map +1 -1
- package/dist/browser/contexts/RefreshPayloadContext/index.js +21 -3
- package/dist/browser/contexts/RefreshPayloadContext/index.js.map +1 -1
- package/dist/browser/contexts/RefreshPayloadContext/use.js +8 -2
- package/dist/browser/contexts/RefreshPayloadContext/use.js.map +1 -1
- package/dist/browser/contexts/ResolvePayloadContext/Context.js +2 -1
- package/dist/browser/contexts/ResolvePayloadContext/Context.js.map +1 -1
- package/dist/browser/contexts/ResolvePayloadContext/Provider.js +17 -4
- package/dist/browser/contexts/ResolvePayloadContext/Provider.js.map +1 -1
- package/dist/browser/contexts/ResolvePayloadContext/index.js +72 -4
- package/dist/browser/contexts/ResolvePayloadContext/index.js.map +1 -1
- package/dist/browser/contexts/ResolvePayloadContext/use.js +8 -2
- package/dist/browser/contexts/ResolvePayloadContext/use.js.map +1 -1
- package/dist/browser/contexts/ValidatePayloadContext/Context.js +2 -1
- package/dist/browser/contexts/ValidatePayloadContext/Context.js.map +1 -1
- package/dist/browser/contexts/ValidatePayloadContext/Provider.js +17 -4
- package/dist/browser/contexts/ValidatePayloadContext/Provider.js.map +1 -1
- package/dist/browser/contexts/ValidatePayloadContext/index.js +49 -3
- package/dist/browser/contexts/ValidatePayloadContext/index.js.map +1 -1
- package/dist/browser/contexts/ValidatePayloadContext/use.js +8 -2
- package/dist/browser/contexts/ValidatePayloadContext/use.js.map +1 -1
- package/dist/browser/contexts/index.js +165 -4
- package/dist/browser/contexts/index.js.map +1 -1
- package/dist/browser/index.js +492 -3
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/types/index.js +0 -1
- package/dist/browser/types/index.js.map +1 -1
- package/dist/docs.json +109 -109
- package/package.json +15 -15
@@ -1,4 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
// src/contexts/ValidatePayloadContext/Provider.tsx
|
2
|
+
import { Chip } from "@mui/material";
|
3
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
4
|
+
import { SchemaCache } from "@xyo-network/schema-cache";
|
5
|
+
import { useState } from "react";
|
6
|
+
|
7
|
+
// src/contexts/ResolvePayloadContext/Context.ts
|
8
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
9
|
+
var ResolvePayloadContext = createContextEx();
|
10
|
+
|
11
|
+
// src/contexts/ResolvePayloadContext/use.tsx
|
12
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
13
|
+
var useResolvePayload = () => useContextEx(ResolvePayloadContext, "ResolvePayload", true);
|
14
|
+
|
15
|
+
// src/contexts/ValidatePayloadContext/Context.ts
|
16
|
+
import { createContextEx as createContextEx2 } from "@xyo-network/react-shared";
|
17
|
+
var ValidatePayloadContext = createContextEx2();
|
18
|
+
|
19
|
+
// src/contexts/ValidatePayloadContext/Provider.tsx
|
20
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
21
|
+
var ValidatePayloadProvider = ({ children, enabled = false }) => {
|
22
|
+
const { payload } = useResolvePayload();
|
23
|
+
const [initialized, setInitialized] = useState(false);
|
24
|
+
const [valid, setValid] = useState();
|
25
|
+
useAsyncEffect(
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
27
|
+
async () => {
|
28
|
+
if (payload && enabled) {
|
29
|
+
await SchemaCache.instance.get(payload.schema);
|
30
|
+
const possibleKnownSchema = payload.schema;
|
31
|
+
if (SchemaCache.instance.validators[possibleKnownSchema]) {
|
32
|
+
const validator = SchemaCache.instance.validators[possibleKnownSchema];
|
33
|
+
setValid(validator?.(payload));
|
34
|
+
}
|
35
|
+
setInitialized(true);
|
36
|
+
}
|
37
|
+
},
|
38
|
+
[payload, enabled]
|
39
|
+
);
|
40
|
+
return /* @__PURE__ */ jsx(ValidatePayloadContext.Provider, { value: { enabled, provided: true, schema: payload?.schema, validPayload: valid }, children: enabled ? /* @__PURE__ */ jsx(Fragment, { children: initialized ? children : /* @__PURE__ */ jsx(Chip, { label: "Validating Payload..." }) }) : children });
|
41
|
+
};
|
42
|
+
|
43
|
+
// src/contexts/ValidatePayloadContext/use.tsx
|
44
|
+
import { useContextEx as useContextEx2 } from "@xyo-network/react-shared";
|
45
|
+
var useValidatePayload = () => useContextEx2(ValidatePayloadContext, "ValidateSchema", true);
|
46
|
+
export {
|
47
|
+
ValidatePayloadProvider,
|
48
|
+
useValidatePayload
|
49
|
+
};
|
4
50
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/ValidatePayloadContext/
|
1
|
+
{"version":3,"sources":["../../../../src/contexts/ValidatePayloadContext/Provider.tsx","../../../../src/contexts/ResolvePayloadContext/Context.ts","../../../../src/contexts/ResolvePayloadContext/use.tsx","../../../../src/contexts/ValidatePayloadContext/Context.ts","../../../../src/contexts/ValidatePayloadContext/use.tsx"],"sourcesContent":["import { Chip } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { SchemaCache, SchemaNameToValidatorMap } from '@xyo-network/schema-cache'\nimport { useState } from 'react'\n\nimport { useResolvePayload } from '../ResolvePayloadContext'\nimport { ValidatePayloadContext } from './Context'\n\nexport interface ValidatePayloadProviderProps {\n // Opt-in flag to validate payloads for the plugin(s)\n enabled?: boolean\n}\n\nexport const ValidatePayloadProvider: React.FC<WithChildren<ValidatePayloadProviderProps>> = ({ children, enabled = false }) => {\n const { payload } = useResolvePayload()\n const [initialized, setInitialized] = useState(false)\n const [valid, setValid] = useState<boolean>()\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async () => {\n if (payload && enabled) {\n await SchemaCache.instance.get(payload.schema)\n\n const possibleKnownSchema = payload.schema as keyof SchemaNameToValidatorMap\n\n if (SchemaCache.instance.validators[possibleKnownSchema]) {\n const validator = SchemaCache.instance.validators[possibleKnownSchema]\n setValid(validator?.(payload))\n }\n setInitialized(true)\n }\n },\n [payload, enabled],\n )\n\n return (\n <ValidatePayloadContext.Provider value={{ enabled, provided: true, schema: payload?.schema, validPayload: valid }}>\n {enabled ? <>{initialized ? children : <Chip label=\"Validating Payload...\" />}</> : children}\n </ValidatePayloadContext.Provider>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { ResolvePayloadState } from './State'\n\nexport const ResolvePayloadContext = createContextEx<ResolvePayloadState>()\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { ResolvePayloadContext } from './Context'\n\nexport const useResolvePayload = () => useContextEx(ResolvePayloadContext, 'ResolvePayload', true)\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { ValidatePayloadState } from './State'\n\nexport const ValidatePayloadContext = createContextEx<ValidatePayloadState>()\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { ValidatePayloadContext } from './Context'\n\nexport const useValidatePayload = () => useContextEx(ValidatePayloadContext, 'ValidateSchema', true)\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,sBAAsB;AAE/B,SAAS,mBAA6C;AACtD,SAAS,gBAAgB;;;ACJzB,SAAS,uBAAuB;AAIzB,IAAM,wBAAwB,gBAAqC;;;ACJ1E,SAAS,oBAAoB;AAItB,IAAM,oBAAoB,MAAM,aAAa,uBAAuB,kBAAkB,IAAI;;;ACJjG,SAAS,mBAAAA,wBAAuB;AAIzB,IAAM,yBAAyBA,iBAAsC;;;AHmC3D,mBAA4B,WAA5B;AAzBV,IAAM,0BAAgF,CAAC,EAAE,UAAU,UAAU,MAAM,MAAM;AAC9H,QAAM,EAAE,QAAQ,IAAI,kBAAkB;AACtC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AACpD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkB;AAE5C;AAAA;AAAA,IAEE,YAAY;AACV,UAAI,WAAW,SAAS;AACtB,cAAM,YAAY,SAAS,IAAI,QAAQ,MAAM;AAE7C,cAAM,sBAAsB,QAAQ;AAEpC,YAAI,YAAY,SAAS,WAAW,mBAAmB,GAAG;AACxD,gBAAM,YAAY,YAAY,SAAS,WAAW,mBAAmB;AACrE,mBAAS,YAAY,OAAO,CAAC;AAAA,QAC/B;AACA,uBAAe,IAAI;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EACnB;AAEA,SACE,oBAAC,uBAAuB,UAAvB,EAAgC,OAAO,EAAE,SAAS,UAAU,MAAM,QAAQ,SAAS,QAAQ,cAAc,MAAM,GAC7G,oBAAU,gCAAG,wBAAc,WAAW,oBAAC,QAAK,OAAM,yBAAwB,GAAG,IAAM,UACtF;AAEJ;;;AI1CA,SAAS,gBAAAC,qBAAoB;AAItB,IAAM,qBAAqB,MAAMC,cAAa,wBAAwB,kBAAkB,IAAI;","names":["createContextEx","useContextEx","useContextEx"]}
|
@@ -1,6 +1,12 @@
|
|
1
|
+
// src/contexts/ValidatePayloadContext/use.tsx
|
1
2
|
import { useContextEx } from "@xyo-network/react-shared";
|
2
|
-
|
3
|
-
|
3
|
+
|
4
|
+
// src/contexts/ValidatePayloadContext/Context.ts
|
5
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
6
|
+
var ValidatePayloadContext = createContextEx();
|
7
|
+
|
8
|
+
// src/contexts/ValidatePayloadContext/use.tsx
|
9
|
+
var useValidatePayload = () => useContextEx(ValidatePayloadContext, "ValidateSchema", true);
|
4
10
|
export {
|
5
11
|
useValidatePayload
|
6
12
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/ValidatePayloadContext/use.tsx"],"sourcesContent":["import { useContextEx } from '@xyo-network/react-shared'\n\nimport { ValidatePayloadContext } from './Context'\n\nexport const useValidatePayload = () => useContextEx(ValidatePayloadContext, 'ValidateSchema', true)\n"],"mappings":"AAAA,SAAS,oBAAoB
|
1
|
+
{"version":3,"sources":["../../../../src/contexts/ValidatePayloadContext/use.tsx","../../../../src/contexts/ValidatePayloadContext/Context.ts"],"sourcesContent":["import { useContextEx } from '@xyo-network/react-shared'\n\nimport { ValidatePayloadContext } from './Context'\n\nexport const useValidatePayload = () => useContextEx(ValidatePayloadContext, 'ValidateSchema', true)\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { ValidatePayloadState } from './State'\n\nexport const ValidatePayloadContext = createContextEx<ValidatePayloadState>()\n"],"mappings":";AAAA,SAAS,oBAAoB;;;ACA7B,SAAS,uBAAuB;AAIzB,IAAM,yBAAyB,gBAAsC;;;ADArE,IAAM,qBAAqB,MAAM,aAAa,wBAAwB,kBAAkB,IAAI;","names":[]}
|
@@ -1,5 +1,166 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
// src/contexts/EmbedPluginContext/Context.tsx
|
2
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
3
|
+
var EmbedPluginContext = createContextEx();
|
4
|
+
|
5
|
+
// src/contexts/EmbedPluginContext/Provider.tsx
|
6
|
+
import { useEffect, useState } from "react";
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
8
|
+
var EmbedPluginProvider = ({
|
9
|
+
children,
|
10
|
+
refreshTitle,
|
11
|
+
timestampLabel,
|
12
|
+
hideElementsConfig,
|
13
|
+
plugins,
|
14
|
+
embedPluginConfig
|
15
|
+
}) => {
|
16
|
+
const [activePlugin, setActivePlugin] = useState(plugins ? plugins[0] : void 0);
|
17
|
+
useEffect(() => {
|
18
|
+
setActivePlugin(plugins ? plugins[0] : void 0);
|
19
|
+
}, [plugins]);
|
20
|
+
return /* @__PURE__ */ jsx(
|
21
|
+
EmbedPluginContext.Provider,
|
22
|
+
{
|
23
|
+
value: {
|
24
|
+
activePlugin,
|
25
|
+
embedPluginConfig,
|
26
|
+
hideElementsConfig,
|
27
|
+
provided: true,
|
28
|
+
refreshTitle,
|
29
|
+
setActivePlugin,
|
30
|
+
timestampLabel
|
31
|
+
},
|
32
|
+
children
|
33
|
+
}
|
34
|
+
);
|
35
|
+
};
|
36
|
+
|
37
|
+
// src/contexts/EmbedPluginContext/use.tsx
|
38
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
39
|
+
var useEmbedPluginState = () => useContextEx(EmbedPluginContext, "EmbedPlugin", true);
|
40
|
+
|
41
|
+
// src/contexts/RefreshPayloadContext/Provider.tsx
|
42
|
+
import { useState as useState2 } from "react";
|
43
|
+
|
44
|
+
// src/contexts/RefreshPayloadContext/Context.tsx
|
45
|
+
import { createContextEx as createContextEx2 } from "@xyo-network/react-shared";
|
46
|
+
var RefreshPayloadContext = createContextEx2();
|
47
|
+
|
48
|
+
// src/contexts/RefreshPayloadContext/Provider.tsx
|
49
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
50
|
+
var RefreshPayloadProvider = ({ children, onRefresh, refreshPayload }) => {
|
51
|
+
const [localRefreshPayload, setRefreshPayload] = useState2(refreshPayload);
|
52
|
+
return /* @__PURE__ */ jsx2(RefreshPayloadContext.Provider, { value: { onRefresh, provided: true, refreshPayload: localRefreshPayload, setRefreshPayload }, children });
|
53
|
+
};
|
54
|
+
|
55
|
+
// src/contexts/RefreshPayloadContext/use.tsx
|
56
|
+
import { useContextEx as useContextEx2 } from "@xyo-network/react-shared";
|
57
|
+
var useRefreshPayload = () => useContextEx2(RefreshPayloadContext, "RefreshPayload", true);
|
58
|
+
|
59
|
+
// src/contexts/ResolvePayloadContext/Context.ts
|
60
|
+
import { createContextEx as createContextEx3 } from "@xyo-network/react-shared";
|
61
|
+
var ResolvePayloadContext = createContextEx3();
|
62
|
+
|
63
|
+
// src/contexts/ResolvePayloadContext/Provider.tsx
|
64
|
+
import { delay } from "@xylabs/delay";
|
65
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
66
|
+
import { Huri } from "@xyo-network/huri";
|
67
|
+
import { ModuleErrorSchema } from "@xyo-network/payload-model";
|
68
|
+
import { useEffect as useEffect2, useState as useState3 } from "react";
|
69
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
70
|
+
var ResolvePayloadProvider = ({ children, huriPayload }) => {
|
71
|
+
const [payload, setPayload] = useState3();
|
72
|
+
const [huri, setHuri] = useState3();
|
73
|
+
const { refreshPayload, setRefreshPayload, onRefresh } = useRefreshPayload();
|
74
|
+
useEffect2(() => {
|
75
|
+
typeof huriPayload === "string" ? setHuri(huriPayload) : void 0;
|
76
|
+
if (typeof huriPayload === "object") {
|
77
|
+
setPayload(huriPayload);
|
78
|
+
setRefreshPayload?.(true);
|
79
|
+
}
|
80
|
+
}, [huriPayload, setRefreshPayload]);
|
81
|
+
const [notFound, setNotFound] = useState3();
|
82
|
+
const [huriError, setHuriError] = useState3();
|
83
|
+
useAsyncEffect(
|
84
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
85
|
+
async (mounted) => {
|
86
|
+
if (huri && !refreshPayload) {
|
87
|
+
try {
|
88
|
+
const huriInstance = new Huri(huri);
|
89
|
+
const result = await huriInstance.fetch();
|
90
|
+
await delay(500);
|
91
|
+
if (mounted()) {
|
92
|
+
setNotFound(result === null);
|
93
|
+
setPayload(result);
|
94
|
+
setRefreshPayload?.(true);
|
95
|
+
}
|
96
|
+
} catch (e) {
|
97
|
+
const error = e;
|
98
|
+
setHuriError({ message: error.message, schema: ModuleErrorSchema, sources: [] });
|
99
|
+
}
|
100
|
+
}
|
101
|
+
},
|
102
|
+
[huri, payload, refreshPayload, setRefreshPayload]
|
103
|
+
);
|
104
|
+
const refreshHuri = () => {
|
105
|
+
onRefresh?.();
|
106
|
+
if (huri) {
|
107
|
+
setRefreshPayload?.(false);
|
108
|
+
}
|
109
|
+
};
|
110
|
+
return /* @__PURE__ */ jsx3(ResolvePayloadContext.Provider, { value: { huri, huriError, notFound, payload, provided: true, refreshHuri, setPayload }, children });
|
111
|
+
};
|
112
|
+
|
113
|
+
// src/contexts/ResolvePayloadContext/use.tsx
|
114
|
+
import { useContextEx as useContextEx3 } from "@xyo-network/react-shared";
|
115
|
+
var useResolvePayload = () => useContextEx3(ResolvePayloadContext, "ResolvePayload", true);
|
116
|
+
|
117
|
+
// src/contexts/ValidatePayloadContext/Provider.tsx
|
118
|
+
import { Chip } from "@mui/material";
|
119
|
+
import { useAsyncEffect as useAsyncEffect2 } from "@xylabs/react-async-effect";
|
120
|
+
import { SchemaCache } from "@xyo-network/schema-cache";
|
121
|
+
import { useState as useState4 } from "react";
|
122
|
+
|
123
|
+
// src/contexts/ValidatePayloadContext/Context.ts
|
124
|
+
import { createContextEx as createContextEx4 } from "@xyo-network/react-shared";
|
125
|
+
var ValidatePayloadContext = createContextEx4();
|
126
|
+
|
127
|
+
// src/contexts/ValidatePayloadContext/Provider.tsx
|
128
|
+
import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
|
129
|
+
var ValidatePayloadProvider = ({ children, enabled = false }) => {
|
130
|
+
const { payload } = useResolvePayload();
|
131
|
+
const [initialized, setInitialized] = useState4(false);
|
132
|
+
const [valid, setValid] = useState4();
|
133
|
+
useAsyncEffect2(
|
134
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
135
|
+
async () => {
|
136
|
+
if (payload && enabled) {
|
137
|
+
await SchemaCache.instance.get(payload.schema);
|
138
|
+
const possibleKnownSchema = payload.schema;
|
139
|
+
if (SchemaCache.instance.validators[possibleKnownSchema]) {
|
140
|
+
const validator = SchemaCache.instance.validators[possibleKnownSchema];
|
141
|
+
setValid(validator?.(payload));
|
142
|
+
}
|
143
|
+
setInitialized(true);
|
144
|
+
}
|
145
|
+
},
|
146
|
+
[payload, enabled]
|
147
|
+
);
|
148
|
+
return /* @__PURE__ */ jsx4(ValidatePayloadContext.Provider, { value: { enabled, provided: true, schema: payload?.schema, validPayload: valid }, children: enabled ? /* @__PURE__ */ jsx4(Fragment, { children: initialized ? children : /* @__PURE__ */ jsx4(Chip, { label: "Validating Payload..." }) }) : children });
|
149
|
+
};
|
150
|
+
|
151
|
+
// src/contexts/ValidatePayloadContext/use.tsx
|
152
|
+
import { useContextEx as useContextEx4 } from "@xyo-network/react-shared";
|
153
|
+
var useValidatePayload = () => useContextEx4(ValidatePayloadContext, "ValidateSchema", true);
|
154
|
+
export {
|
155
|
+
EmbedPluginContext,
|
156
|
+
EmbedPluginProvider,
|
157
|
+
RefreshPayloadProvider,
|
158
|
+
ResolvePayloadContext,
|
159
|
+
ResolvePayloadProvider,
|
160
|
+
ValidatePayloadProvider,
|
161
|
+
useEmbedPluginState,
|
162
|
+
useRefreshPayload,
|
163
|
+
useResolvePayload,
|
164
|
+
useValidatePayload
|
165
|
+
};
|
5
166
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/contexts/index.ts"],"sourcesContent":["export * from './EmbedPluginContext'\nexport * from './RefreshPayloadContext'\nexport * from './ResolvePayloadContext'\nexport * from './ValidatePayloadContext'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
1
|
+
{"version":3,"sources":["../../../src/contexts/EmbedPluginContext/Context.tsx","../../../src/contexts/EmbedPluginContext/Provider.tsx","../../../src/contexts/EmbedPluginContext/use.tsx","../../../src/contexts/RefreshPayloadContext/Provider.tsx","../../../src/contexts/RefreshPayloadContext/Context.tsx","../../../src/contexts/RefreshPayloadContext/use.tsx","../../../src/contexts/ResolvePayloadContext/Context.ts","../../../src/contexts/ResolvePayloadContext/Provider.tsx","../../../src/contexts/ResolvePayloadContext/use.tsx","../../../src/contexts/ValidatePayloadContext/Provider.tsx","../../../src/contexts/ValidatePayloadContext/Context.ts","../../../src/contexts/ValidatePayloadContext/use.tsx"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { EmbedPluginState } from './State'\n\nexport const EmbedPluginContext = createContextEx<EmbedPluginState>()\n","import { WithChildren } from '@xylabs/react-shared'\nimport { PayloadRenderPlugin } from '@xyo-network/react-payload-plugin'\nimport { useEffect, useState } from 'react'\n\nimport { EmbedPluginContext } from './Context'\nimport { EmbedPluginBase } from './State'\n\nexport type EmbedPluginProviderProps = EmbedPluginBase\n\n/** Expose passed embed plugin props via context */\nexport const EmbedPluginProvider: React.FC<WithChildren<EmbedPluginProviderProps>> = ({\n children,\n refreshTitle,\n timestampLabel,\n hideElementsConfig,\n plugins,\n embedPluginConfig,\n}) => {\n const [activePlugin, setActivePlugin] = useState<PayloadRenderPlugin | undefined>(plugins ? plugins[0] : undefined)\n\n useEffect(() => {\n setActivePlugin(plugins ? plugins[0] : undefined)\n }, [plugins])\n\n return (\n <EmbedPluginContext.Provider\n value={{\n activePlugin,\n embedPluginConfig,\n hideElementsConfig,\n provided: true,\n refreshTitle,\n setActivePlugin,\n timestampLabel,\n }}\n >\n {children}\n </EmbedPluginContext.Provider>\n )\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { EmbedPluginContext } from './Context'\n\nexport const useEmbedPluginState = () => useContextEx(EmbedPluginContext, 'EmbedPlugin', true)\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useState } from 'react'\n\nimport { RefreshPayloadContext } from './Context'\n\nexport interface RefreshPayloadProps {\n onRefresh?: () => void\n refreshPayload?: boolean\n}\n\nexport const RefreshPayloadProvider: React.FC<WithChildren<RefreshPayloadProps>> = ({ children, onRefresh, refreshPayload }) => {\n const [localRefreshPayload, setRefreshPayload] = useState(refreshPayload)\n\n return (\n <RefreshPayloadContext.Provider value={{ onRefresh, provided: true, refreshPayload: localRefreshPayload, setRefreshPayload }}>\n {children}\n </RefreshPayloadContext.Provider>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { RefreshPayloadState } from './State'\n\nexport const RefreshPayloadContext = createContextEx<RefreshPayloadState>()\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { RefreshPayloadContext } from './Context'\n\nexport const useRefreshPayload = () => useContextEx(RefreshPayloadContext, 'RefreshPayload', true)\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { ResolvePayloadState } from './State'\n\nexport const ResolvePayloadContext = createContextEx<ResolvePayloadState>()\n","import { delay } from '@xylabs/delay'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { Huri } from '@xyo-network/huri'\nimport { ModuleError, ModuleErrorSchema, Payload } from '@xyo-network/payload-model'\nimport { useEffect, useState } from 'react'\n\nimport { useRefreshPayload } from '../RefreshPayloadContext'\nimport { ResolvePayloadContext } from './Context'\nimport { ResolvePayloadState } from './State'\n\nexport type ResolvePayloadProviderProps = Omit<ResolvePayloadState, 'provided'>\n\nexport const ResolvePayloadProvider: React.FC<WithChildren<ResolvePayloadProviderProps>> = ({ children, huriPayload }) => {\n const [payload, setPayload] = useState<Payload>()\n const [huri, setHuri] = useState<string>()\n const { refreshPayload, setRefreshPayload, onRefresh } = useRefreshPayload()\n\n useEffect(() => {\n typeof huriPayload === 'string' ? setHuri(huriPayload) : undefined\n if (typeof huriPayload === 'object') {\n setPayload(huriPayload)\n setRefreshPayload?.(true)\n }\n }, [huriPayload, setRefreshPayload])\n\n const [notFound, setNotFound] = useState<boolean>()\n const [huriError, setHuriError] = useState<ModuleError>()\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n if (huri && !refreshPayload) {\n try {\n const huriInstance = new Huri(huri)\n const result = await huriInstance.fetch()\n // ensure the busy state can stay for a moment to avoid flashing too quickly\n await delay(500)\n\n if (mounted()) {\n setNotFound(result === null)\n setPayload(result)\n setRefreshPayload?.(true)\n }\n } catch (e) {\n const error = e as Error\n setHuriError({ message: error.message, schema: ModuleErrorSchema, sources: [] })\n }\n }\n },\n [huri, payload, refreshPayload, setRefreshPayload],\n )\n\n const refreshHuri = () => {\n onRefresh?.()\n if (huri) {\n setRefreshPayload?.(false)\n }\n }\n\n return (\n <ResolvePayloadContext.Provider value={{ huri, huriError, notFound, payload, provided: true, refreshHuri, setPayload }}>\n {children}\n </ResolvePayloadContext.Provider>\n )\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { ResolvePayloadContext } from './Context'\n\nexport const useResolvePayload = () => useContextEx(ResolvePayloadContext, 'ResolvePayload', true)\n","import { Chip } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { SchemaCache, SchemaNameToValidatorMap } from '@xyo-network/schema-cache'\nimport { useState } from 'react'\n\nimport { useResolvePayload } from '../ResolvePayloadContext'\nimport { ValidatePayloadContext } from './Context'\n\nexport interface ValidatePayloadProviderProps {\n // Opt-in flag to validate payloads for the plugin(s)\n enabled?: boolean\n}\n\nexport const ValidatePayloadProvider: React.FC<WithChildren<ValidatePayloadProviderProps>> = ({ children, enabled = false }) => {\n const { payload } = useResolvePayload()\n const [initialized, setInitialized] = useState(false)\n const [valid, setValid] = useState<boolean>()\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async () => {\n if (payload && enabled) {\n await SchemaCache.instance.get(payload.schema)\n\n const possibleKnownSchema = payload.schema as keyof SchemaNameToValidatorMap\n\n if (SchemaCache.instance.validators[possibleKnownSchema]) {\n const validator = SchemaCache.instance.validators[possibleKnownSchema]\n setValid(validator?.(payload))\n }\n setInitialized(true)\n }\n },\n [payload, enabled],\n )\n\n return (\n <ValidatePayloadContext.Provider value={{ enabled, provided: true, schema: payload?.schema, validPayload: valid }}>\n {enabled ? <>{initialized ? children : <Chip label=\"Validating Payload...\" />}</> : children}\n </ValidatePayloadContext.Provider>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { ValidatePayloadState } from './State'\n\nexport const ValidatePayloadContext = createContextEx<ValidatePayloadState>()\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { ValidatePayloadContext } from './Context'\n\nexport const useValidatePayload = () => useContextEx(ValidatePayloadContext, 'ValidateSchema', true)\n"],"mappings":";AAAA,SAAS,uBAAuB;AAIzB,IAAM,qBAAqB,gBAAkC;;;ACFpE,SAAS,WAAW,gBAAgB;AAuBhC;AAfG,IAAM,sBAAwE,CAAC;AAAA,EACpF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,CAAC,cAAc,eAAe,IAAI,SAA0C,UAAU,QAAQ,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AIzB,IAAM,yBAAyBA,iBAAsC;;;ADmC3D,mBAA4B,OAAAC,YAA5B;AAzBV,IAAM,0BAAgF,CAAC,EAAE,UAAU,UAAU,MAAM,MAAM;AAC9H,QAAM,EAAE,QAAQ,IAAI,kBAAkB;AACtC,QAAM,CAAC,aAAa,cAAc,IAAIC,UAAS,KAAK;AACpD,QAAM,CAAC,OAAO,QAAQ,IAAIA,UAAkB;AAE5C,EAAAC;AAAA;AAAA,IAEE,YAAY;AACV,UAAI,WAAW,SAAS;AACtB,cAAM,YAAY,SAAS,IAAI,QAAQ,MAAM;AAE7C,cAAM,sBAAsB,QAAQ;AAEpC,YAAI,YAAY,SAAS,WAAW,mBAAmB,GAAG;AACxD,gBAAM,YAAY,YAAY,SAAS,WAAW,mBAAmB;AACrE,mBAAS,YAAY,OAAO,CAAC;AAAA,QAC/B;AACA,uBAAe,IAAI;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EACnB;AAEA,SACE,gBAAAF,KAAC,uBAAuB,UAAvB,EAAgC,OAAO,EAAE,SAAS,UAAU,MAAM,QAAQ,SAAS,QAAQ,cAAc,MAAM,GAC7G,oBAAU,gBAAAA,KAAA,YAAG,wBAAc,WAAW,gBAAAA,KAAC,QAAK,OAAM,yBAAwB,GAAG,IAAM,UACtF;AAEJ;;;AE1CA,SAAS,gBAAAG,qBAAoB;AAItB,IAAM,qBAAqB,MAAMC,cAAa,wBAAwB,kBAAkB,IAAI;","names":["useState","createContextEx","jsx","useState","useContextEx","useContextEx","createContextEx","useEffect","useState","jsx","useState","useEffect","useContextEx","useContextEx","useAsyncEffect","useState","createContextEx","jsx","useState","useAsyncEffect","useContextEx","useContextEx"]}
|