@xyo-network/react-schema 2.64.0 → 2.64.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/components/Property/SchemaProperty.js +4 -3
- package/dist/browser/components/Property/SchemaProperty.js.map +1 -1
- package/dist/browser/components/Property/index.js +54 -1
- package/dist/browser/components/Property/index.js.map +1 -1
- package/dist/browser/components/SelectEx/SchemaSelectEx.js +15 -3
- package/dist/browser/components/SelectEx/SchemaSelectEx.js.map +1 -1
- package/dist/browser/components/SelectEx/index.js +46 -1
- package/dist/browser/components/SelectEx/index.js.map +1 -1
- package/dist/browser/components/index.js +99 -2
- package/dist/browser/components/index.js.map +1 -1
- package/dist/browser/contexts/Schema/Context.js +2 -1
- package/dist/browser/contexts/Schema/Context.js.map +1 -1
- package/dist/browser/contexts/Schema/Provider/Memory.js +59 -7
- package/dist/browser/contexts/Schema/Provider/Memory.js.map +1 -1
- package/dist/browser/contexts/Schema/Provider/Route.js +86 -10
- package/dist/browser/contexts/Schema/Provider/Route.js.map +1 -1
- package/dist/browser/contexts/Schema/Provider/index.js +123 -3
- package/dist/browser/contexts/Schema/Provider/index.js.map +1 -1
- package/dist/browser/contexts/Schema/index.js +125 -4
- package/dist/browser/contexts/Schema/index.js.map +1 -1
- package/dist/browser/contexts/Schema/use.js +8 -2
- package/dist/browser/contexts/Schema/use.js.map +1 -1
- package/dist/browser/contexts/index.js +125 -1
- package/dist/browser/contexts/index.js.map +1 -1
- package/dist/browser/hooks/index.js +165 -4
- package/dist/browser/hooks/index.js.map +1 -1
- package/dist/browser/hooks/useGetSchema.js +2 -1
- package/dist/browser/hooks/useGetSchema.js.map +1 -1
- package/dist/browser/hooks/useSchemaDefinitions.js +2 -1
- package/dist/browser/hooks/useSchemaDefinitions.js.map +1 -1
- package/dist/browser/hooks/useSchemaList.js +2 -1
- package/dist/browser/hooks/useSchemaList.js.map +1 -1
- package/dist/browser/hooks/useSchemaStats.js +2 -1
- package/dist/browser/hooks/useSchemaStats.js.map +1 -1
- package/dist/browser/index.js +330 -3
- package/dist/browser/index.js.map +1 -1
- package/dist/docs.json +38 -38
- package/package.json +26 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/components/Property/SchemaProperty.tsx
|
|
2
2
|
import { NewReleases as NewReleasesIcon, OpenInNew as OpenInNewIcon, Verified as VerifiedIcon } from "@mui/icons-material";
|
|
3
3
|
import { IconButton } from "@mui/material";
|
|
4
4
|
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
@@ -7,7 +7,8 @@ import { useEvent } from "@xyo-network/react-event";
|
|
|
7
7
|
import { Property, PropertyValue } from "@xyo-network/react-property";
|
|
8
8
|
import { SchemaCache } from "@xyo-network/schema-cache";
|
|
9
9
|
import { forwardRef, useState } from "react";
|
|
10
|
-
|
|
10
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
var useResolveSchema = (schema) => {
|
|
11
12
|
const [entry, setEntry] = useState();
|
|
12
13
|
useAsyncEffect(
|
|
13
14
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -23,7 +24,7 @@ const useResolveSchema = (schema) => {
|
|
|
23
24
|
);
|
|
24
25
|
return entry;
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
+
var SchemaProperty = forwardRef(
|
|
27
28
|
({ showLinkNames = true, showOpenNewWindowLink = true, showStatusIcon = true, titleProps, value, ...props }, forwardedRef) => {
|
|
28
29
|
const resolvedSchema = useResolveSchema(value);
|
|
29
30
|
const [buttonRef, buttonDispatch] = useEvent(void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Property/SchemaProperty.tsx"],"sourcesContent":["import { NewReleases as NewReleasesIcon, OpenInNew as OpenInNewIcon, Verified as VerifiedIcon } from '@mui/icons-material'\nimport { IconButton } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { LinkEx } from '@xylabs/react-link'\nimport { EventDispatch, EventNoun, useEvent } from '@xyo-network/react-event'\nimport { Property, PropertyProps, PropertyValue } from '@xyo-network/react-property'\nimport { SchemaCache, SchemaCacheEntry } from '@xyo-network/schema-cache'\nimport { forwardRef, useState } from 'react'\n\nexport type SchemaPropertyProps = PropertyProps & {\n showLinkNames?: boolean\n showOpenNewWindowLink?: boolean\n showStatusIcon?: boolean\n value?: string\n}\n\nconst useResolveSchema = (schema?: string) => {\n const [entry, setEntry] = useState<SchemaCacheEntry | null>()\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n if (schema) {\n const entry = await SchemaCache.instance.get(schema)\n if (mounted()) {\n setEntry(entry)\n }\n }\n },\n [schema],\n )\n return entry\n}\n\nexport const SchemaProperty = forwardRef<HTMLDivElement, SchemaPropertyProps>(\n ({ showLinkNames = true, showOpenNewWindowLink = true, showStatusIcon = true, titleProps, value, ...props }, forwardedRef) => {\n const resolvedSchema = useResolveSchema(value)\n const [buttonRef, buttonDispatch] = useEvent<HTMLButtonElement>(undefined)\n const [divRef, divDispatch] = useEvent<HTMLDivElement>(undefined)\n\n const onClick = (dispatch?: EventDispatch<EventNoun, 'click', string>, openNewWindow = false) => {\n dispatch?.(\n 'schema',\n 'click',\n JSON.stringify({\n openNewWindow,\n schema: value,\n }),\n )\n }\n\n return (\n <Property ref={forwardedRef} title=\"Schema\" value={value} tip=\"Schema sent with the payload\" titleProps={titleProps} {...props}>\n {value && showStatusIcon ? (\n resolvedSchema === null ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"warning\" fontSize=\"inherit\" />\n </IconButton>\n ) : resolvedSchema === undefined ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"disabled\" fontSize=\"inherit\" />\n </IconButton>\n ) : (\n <IconButton rel=\"noopener noreferrer\" size=\"small\" target=\"_blank\" href={resolvedSchema?.huri?.href ?? ''}>\n <VerifiedIcon color=\"success\" fontSize=\"inherit\" />\n </IconButton>\n )\n ) : null}\n {value ? (\n <>\n {showLinkNames ? (\n <LinkEx display=\"block\" width=\"100%\" sx={{ cursor: 'pointer' }}>\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n </LinkEx>\n ) : (\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n )}\n {showOpenNewWindowLink ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch, true)}>\n <OpenInNewIcon fontSize=\"inherit\" />\n </IconButton>\n ) : null}\n </>\n ) : null}\n </Property>\n )\n },\n)\n\nSchemaProperty.displayName = 'SchemaProperty'\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Property/SchemaProperty.tsx"],"sourcesContent":["import { NewReleases as NewReleasesIcon, OpenInNew as OpenInNewIcon, Verified as VerifiedIcon } from '@mui/icons-material'\nimport { IconButton } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { LinkEx } from '@xylabs/react-link'\nimport { EventDispatch, EventNoun, useEvent } from '@xyo-network/react-event'\nimport { Property, PropertyProps, PropertyValue } from '@xyo-network/react-property'\nimport { SchemaCache, SchemaCacheEntry } from '@xyo-network/schema-cache'\nimport { forwardRef, useState } from 'react'\n\nexport type SchemaPropertyProps = PropertyProps & {\n showLinkNames?: boolean\n showOpenNewWindowLink?: boolean\n showStatusIcon?: boolean\n value?: string\n}\n\nconst useResolveSchema = (schema?: string) => {\n const [entry, setEntry] = useState<SchemaCacheEntry | null>()\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n if (schema) {\n const entry = await SchemaCache.instance.get(schema)\n if (mounted()) {\n setEntry(entry)\n }\n }\n },\n [schema],\n )\n return entry\n}\n\nexport const SchemaProperty = forwardRef<HTMLDivElement, SchemaPropertyProps>(\n ({ showLinkNames = true, showOpenNewWindowLink = true, showStatusIcon = true, titleProps, value, ...props }, forwardedRef) => {\n const resolvedSchema = useResolveSchema(value)\n const [buttonRef, buttonDispatch] = useEvent<HTMLButtonElement>(undefined)\n const [divRef, divDispatch] = useEvent<HTMLDivElement>(undefined)\n\n const onClick = (dispatch?: EventDispatch<EventNoun, 'click', string>, openNewWindow = false) => {\n dispatch?.(\n 'schema',\n 'click',\n JSON.stringify({\n openNewWindow,\n schema: value,\n }),\n )\n }\n\n return (\n <Property ref={forwardedRef} title=\"Schema\" value={value} tip=\"Schema sent with the payload\" titleProps={titleProps} {...props}>\n {value && showStatusIcon ? (\n resolvedSchema === null ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"warning\" fontSize=\"inherit\" />\n </IconButton>\n ) : resolvedSchema === undefined ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"disabled\" fontSize=\"inherit\" />\n </IconButton>\n ) : (\n <IconButton rel=\"noopener noreferrer\" size=\"small\" target=\"_blank\" href={resolvedSchema?.huri?.href ?? ''}>\n <VerifiedIcon color=\"success\" fontSize=\"inherit\" />\n </IconButton>\n )\n ) : null}\n {value ? (\n <>\n {showLinkNames ? (\n <LinkEx display=\"block\" width=\"100%\" sx={{ cursor: 'pointer' }}>\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n </LinkEx>\n ) : (\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n )}\n {showOpenNewWindowLink ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch, true)}>\n <OpenInNewIcon fontSize=\"inherit\" />\n </IconButton>\n ) : null}\n </>\n ) : null}\n </Property>\n )\n },\n)\n\nSchemaProperty.displayName = 'SchemaProperty'\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB,aAAa,eAAe,YA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AAK,SAAQ,SAAS,MAAM,QAAQ,cAAc,GAC5E,8BAAC,mBAAgB,OAAM,YAAW,UAAS,WAAU,GACvD,IAEA,oBAAC,cAAW,KAAI,uBAAsB,MAAK,SAAQ,QAAO,UAAS,MAAM,gBAAgB,MAAM,QAAQ,IACrG,8BAAC,gBAAa,OAAM,WAAU,UAAS,WAAU,GACnD,IAEA;AAAA,MACH,QACC,iCACG;AAAA,wBACC,oBAAC,UAAO,SAAQ,SAAQ,OAAM,QAAO,IAAI,EAAE,QAAQ,UAAU,GAC3D,8BAAC,iBAAc,KAAK,QAAQ,OAAc,OAAM,eAAc,SAAS,MAAM,QAAQ,WAAW,GAAG,GACrG,IAEA,oBAAC,iBAAc,KAAK,QAAQ,OAAc,OAAM,eAAc,SAAS,MAAM,QAAQ,WAAW,GAAG;AAAA,QAEpG,wBACC,oBAAC,cAAW,KAAK,WAAW,MAAK,SAAQ,SAAS,MAAM,QAAQ,gBAAgB,IAAI,GAClF,8BAAC,iBAAc,UAAS,WAAU,GACpC,IACE;AAAA,SACN,IACE;AAAA,OACN;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;","names":["entry"]}
|
|
@@ -1,2 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
// src/components/Property/SchemaProperty.tsx
|
|
2
|
+
import { NewReleases as NewReleasesIcon, OpenInNew as OpenInNewIcon, Verified as VerifiedIcon } from "@mui/icons-material";
|
|
3
|
+
import { IconButton } from "@mui/material";
|
|
4
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
5
|
+
import { LinkEx } from "@xylabs/react-link";
|
|
6
|
+
import { useEvent } from "@xyo-network/react-event";
|
|
7
|
+
import { Property, PropertyValue } from "@xyo-network/react-property";
|
|
8
|
+
import { SchemaCache } from "@xyo-network/schema-cache";
|
|
9
|
+
import { forwardRef, useState } from "react";
|
|
10
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
var useResolveSchema = (schema) => {
|
|
12
|
+
const [entry, setEntry] = useState();
|
|
13
|
+
useAsyncEffect(
|
|
14
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
15
|
+
async (mounted) => {
|
|
16
|
+
if (schema) {
|
|
17
|
+
const entry2 = await SchemaCache.instance.get(schema);
|
|
18
|
+
if (mounted()) {
|
|
19
|
+
setEntry(entry2);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
[schema]
|
|
24
|
+
);
|
|
25
|
+
return entry;
|
|
26
|
+
};
|
|
27
|
+
var SchemaProperty = forwardRef(
|
|
28
|
+
({ showLinkNames = true, showOpenNewWindowLink = true, showStatusIcon = true, titleProps, value, ...props }, forwardedRef) => {
|
|
29
|
+
const resolvedSchema = useResolveSchema(value);
|
|
30
|
+
const [buttonRef, buttonDispatch] = useEvent(void 0);
|
|
31
|
+
const [divRef, divDispatch] = useEvent(void 0);
|
|
32
|
+
const onClick = (dispatch, openNewWindow = false) => {
|
|
33
|
+
dispatch?.(
|
|
34
|
+
"schema",
|
|
35
|
+
"click",
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
openNewWindow,
|
|
38
|
+
schema: value
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
return /* @__PURE__ */ jsxs(Property, { ref: forwardedRef, title: "Schema", value, tip: "Schema sent with the payload", titleProps, ...props, children: [
|
|
43
|
+
value && showStatusIcon ? resolvedSchema === null ? /* @__PURE__ */ jsx(IconButton, { ref: buttonRef, size: "small", onClick: () => onClick(buttonDispatch), children: /* @__PURE__ */ jsx(NewReleasesIcon, { color: "warning", fontSize: "inherit" }) }) : resolvedSchema === void 0 ? /* @__PURE__ */ jsx(IconButton, { ref: buttonRef, size: "small", onClick: () => onClick(buttonDispatch), children: /* @__PURE__ */ jsx(NewReleasesIcon, { color: "disabled", fontSize: "inherit" }) }) : /* @__PURE__ */ jsx(IconButton, { rel: "noopener noreferrer", size: "small", target: "_blank", href: resolvedSchema?.huri?.href ?? "", children: /* @__PURE__ */ jsx(VerifiedIcon, { color: "success", fontSize: "inherit" }) }) : null,
|
|
44
|
+
value ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
45
|
+
showLinkNames ? /* @__PURE__ */ jsx(LinkEx, { display: "block", width: "100%", sx: { cursor: "pointer" }, children: /* @__PURE__ */ jsx(PropertyValue, { ref: divRef, value, title: "view schema", onClick: () => onClick(divDispatch) }) }) : /* @__PURE__ */ jsx(PropertyValue, { ref: divRef, value, title: "view schema", onClick: () => onClick(divDispatch) }),
|
|
46
|
+
showOpenNewWindowLink ? /* @__PURE__ */ jsx(IconButton, { ref: buttonRef, size: "small", onClick: () => onClick(buttonDispatch, true), children: /* @__PURE__ */ jsx(OpenInNewIcon, { fontSize: "inherit" }) }) : null
|
|
47
|
+
] }) : null
|
|
48
|
+
] });
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
SchemaProperty.displayName = "SchemaProperty";
|
|
52
|
+
export {
|
|
53
|
+
SchemaProperty
|
|
54
|
+
};
|
|
2
55
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Property/
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Property/SchemaProperty.tsx"],"sourcesContent":["import { NewReleases as NewReleasesIcon, OpenInNew as OpenInNewIcon, Verified as VerifiedIcon } from '@mui/icons-material'\nimport { IconButton } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { LinkEx } from '@xylabs/react-link'\nimport { EventDispatch, EventNoun, useEvent } from '@xyo-network/react-event'\nimport { Property, PropertyProps, PropertyValue } from '@xyo-network/react-property'\nimport { SchemaCache, SchemaCacheEntry } from '@xyo-network/schema-cache'\nimport { forwardRef, useState } from 'react'\n\nexport type SchemaPropertyProps = PropertyProps & {\n showLinkNames?: boolean\n showOpenNewWindowLink?: boolean\n showStatusIcon?: boolean\n value?: string\n}\n\nconst useResolveSchema = (schema?: string) => {\n const [entry, setEntry] = useState<SchemaCacheEntry | null>()\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n if (schema) {\n const entry = await SchemaCache.instance.get(schema)\n if (mounted()) {\n setEntry(entry)\n }\n }\n },\n [schema],\n )\n return entry\n}\n\nexport const SchemaProperty = forwardRef<HTMLDivElement, SchemaPropertyProps>(\n ({ showLinkNames = true, showOpenNewWindowLink = true, showStatusIcon = true, titleProps, value, ...props }, forwardedRef) => {\n const resolvedSchema = useResolveSchema(value)\n const [buttonRef, buttonDispatch] = useEvent<HTMLButtonElement>(undefined)\n const [divRef, divDispatch] = useEvent<HTMLDivElement>(undefined)\n\n const onClick = (dispatch?: EventDispatch<EventNoun, 'click', string>, openNewWindow = false) => {\n dispatch?.(\n 'schema',\n 'click',\n JSON.stringify({\n openNewWindow,\n schema: value,\n }),\n )\n }\n\n return (\n <Property ref={forwardedRef} title=\"Schema\" value={value} tip=\"Schema sent with the payload\" titleProps={titleProps} {...props}>\n {value && showStatusIcon ? (\n resolvedSchema === null ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"warning\" fontSize=\"inherit\" />\n </IconButton>\n ) : resolvedSchema === undefined ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"disabled\" fontSize=\"inherit\" />\n </IconButton>\n ) : (\n <IconButton rel=\"noopener noreferrer\" size=\"small\" target=\"_blank\" href={resolvedSchema?.huri?.href ?? ''}>\n <VerifiedIcon color=\"success\" fontSize=\"inherit\" />\n </IconButton>\n )\n ) : null}\n {value ? (\n <>\n {showLinkNames ? (\n <LinkEx display=\"block\" width=\"100%\" sx={{ cursor: 'pointer' }}>\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n </LinkEx>\n ) : (\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n )}\n {showOpenNewWindowLink ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch, true)}>\n <OpenInNewIcon fontSize=\"inherit\" />\n </IconButton>\n ) : null}\n </>\n ) : null}\n </Property>\n )\n },\n)\n\nSchemaProperty.displayName = 'SchemaProperty'\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB,aAAa,eAAe,YAAY,oBAAoB;AACrG,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAmC,gBAAgB;AACnD,SAAS,UAAyB,qBAAqB;AACvD,SAAS,mBAAqC;AAC9C,SAAS,YAAY,gBAAgB;AAgDvB,SAaJ,UAbI,KAaJ,YAbI;AAvCd,IAAM,mBAAmB,CAAC,WAAoB;AAC5C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkC;AAC5D;AAAA;AAAA,IAEE,OAAO,YAAY;AACjB,UAAI,QAAQ;AACV,cAAMA,SAAQ,MAAM,YAAY,SAAS,IAAI,MAAM;AACnD,YAAI,QAAQ,GAAG;AACb,mBAASA,MAAK;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACA,SAAO;AACT;AAEO,IAAM,iBAAiB;AAAA,EAC5B,CAAC,EAAE,gBAAgB,MAAM,wBAAwB,MAAM,iBAAiB,MAAM,YAAY,OAAO,GAAG,MAAM,GAAG,iBAAiB;AAC5H,UAAM,iBAAiB,iBAAiB,KAAK;AAC7C,UAAM,CAAC,WAAW,cAAc,IAAI,SAA4B,MAAS;AACzE,UAAM,CAAC,QAAQ,WAAW,IAAI,SAAyB,MAAS;AAEhE,UAAM,UAAU,CAAC,UAAsD,gBAAgB,UAAU;AAC/F;AAAA,QACE;AAAA,QACA;AAAA,QACA,KAAK,UAAU;AAAA,UACb;AAAA,UACA,QAAQ;AAAA,QACV,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WACE,qBAAC,YAAS,KAAK,cAAc,OAAM,UAAS,OAAc,KAAI,gCAA+B,YAAyB,GAAG,OACtH;AAAA,eAAS,iBACR,mBAAmB,OACjB,oBAAC,cAAW,KAAK,WAAW,MAAK,SAAQ,SAAS,MAAM,QAAQ,cAAc,GAC5E,8BAAC,mBAAgB,OAAM,WAAU,UAAS,WAAU,GACtD,IACE,mBAAmB,SACrB,oBAAC,cAAW,KAAK,WAAW,MAAK,SAAQ,SAAS,MAAM,QAAQ,cAAc,GAC5E,8BAAC,mBAAgB,OAAM,YAAW,UAAS,WAAU,GACvD,IAEA,oBAAC,cAAW,KAAI,uBAAsB,MAAK,SAAQ,QAAO,UAAS,MAAM,gBAAgB,MAAM,QAAQ,IACrG,8BAAC,gBAAa,OAAM,WAAU,UAAS,WAAU,GACnD,IAEA;AAAA,MACH,QACC,iCACG;AAAA,wBACC,oBAAC,UAAO,SAAQ,SAAQ,OAAM,QAAO,IAAI,EAAE,QAAQ,UAAU,GAC3D,8BAAC,iBAAc,KAAK,QAAQ,OAAc,OAAM,eAAc,SAAS,MAAM,QAAQ,WAAW,GAAG,GACrG,IAEA,oBAAC,iBAAc,KAAK,QAAQ,OAAc,OAAM,eAAc,SAAS,MAAM,QAAQ,WAAW,GAAG;AAAA,QAEpG,wBACC,oBAAC,cAAW,KAAK,WAAW,MAAK,SAAQ,SAAS,MAAM,QAAQ,gBAAgB,IAAI,GAClF,8BAAC,iBAAc,UAAS,WAAU,GACpC,IACE;AAAA,SACN,IACE;AAAA,OACN;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;","names":["entry"]}
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
// src/components/SelectEx/SchemaSelectEx.tsx
|
|
2
2
|
import { MenuItem, Typography } from "@mui/material";
|
|
3
3
|
import { SelectEx } from "@xylabs/react-select";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
// src/contexts/Schema/Context.ts
|
|
6
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
7
|
+
var SchemaContext = createContextEx();
|
|
8
|
+
|
|
9
|
+
// src/contexts/Schema/use.ts
|
|
10
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
11
|
+
var useSchema = (required = false) => {
|
|
12
|
+
return useContextEx(SchemaContext, "Schema", required);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/components/SelectEx/SchemaSelectEx.tsx
|
|
16
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
var SchemaSelectEx = ({ onChange, ...props }) => {
|
|
6
18
|
const { schema, setSchema, schemaList } = useSchema(false);
|
|
7
19
|
return /* @__PURE__ */ jsxs(
|
|
8
20
|
SelectEx,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/SelectEx/SchemaSelectEx.tsx"],"sourcesContent":["import { MenuItem, Typography } from '@mui/material'\nimport { SelectEx, SelectExProps } from '@xylabs/react-select'\n\nimport { useSchema } from '../../contexts'\n\nexport type SchemaSelectExProps = SelectExProps<string>\n\nexport const SchemaSelectEx: React.FC<SchemaSelectExProps> = ({ onChange, ...props }) => {\n const { schema, setSchema, schemaList } = useSchema(false)\n\n return (\n <SelectEx\n variant=\"outlined\"\n size=\"small\"\n value={schema ?? 'none'}\n onChange={(event, child) => {\n if (event.target.value !== schema) {\n onChange?.(event, child)\n setSchema?.(event.target.value)\n }\n }}\n renderValue={(value) => {\n return <Typography>{value === 'none' ? '- None -' : value}</Typography>\n }}\n {...props}\n >\n {schemaList?.map((schema, index) => {\n return (\n <MenuItem key={index} value={schema}>\n {schema}\n </MenuItem>\n )\n })}\n <MenuItem key=\"none\" value=\"none\">\n - None -\n </MenuItem>\n </SelectEx>\n )\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/SelectEx/SchemaSelectEx.tsx","../../../../src/contexts/Schema/Context.ts","../../../../src/contexts/Schema/use.ts"],"sourcesContent":["import { MenuItem, Typography } from '@mui/material'\nimport { SelectEx, SelectExProps } from '@xylabs/react-select'\n\nimport { useSchema } from '../../contexts'\n\nexport type SchemaSelectExProps = SelectExProps<string>\n\nexport const SchemaSelectEx: React.FC<SchemaSelectExProps> = ({ onChange, ...props }) => {\n const { schema, setSchema, schemaList } = useSchema(false)\n\n return (\n <SelectEx\n variant=\"outlined\"\n size=\"small\"\n value={schema ?? 'none'}\n onChange={(event, child) => {\n if (event.target.value !== schema) {\n onChange?.(event, child)\n setSchema?.(event.target.value)\n }\n }}\n renderValue={(value) => {\n return <Typography>{value === 'none' ? '- None -' : value}</Typography>\n }}\n {...props}\n >\n {schemaList?.map((schema, index) => {\n return (\n <MenuItem key={index} value={schema}>\n {schema}\n </MenuItem>\n )\n })}\n <MenuItem key=\"none\" value=\"none\">\n - None -\n </MenuItem>\n </SelectEx>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContextState } from './State'\n\nexport const SchemaContext = createContextEx<SchemaContextState>()\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContext } from './Context'\nimport { SchemaContextState } from './State'\n\nexport const useSchema = (required = false) => {\n return useContextEx<SchemaContextState>(SchemaContext, 'Schema', required)\n}\n"],"mappings":";AAAA,SAAS,UAAU,kBAAkB;AACrC,SAAS,gBAA+B;;;ACDxC,SAAS,uBAAuB;AAIzB,IAAM,gBAAgB,gBAAoC;;;ACJjE,SAAS,oBAAoB;AAKtB,IAAM,YAAY,CAAC,WAAW,UAAU;AAC7C,SAAO,aAAiC,eAAe,UAAU,QAAQ;AAC3E;;;AFII,SAWW,KAXX;AAJG,IAAM,iBAAgD,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM;AACvF,QAAM,EAAE,QAAQ,WAAW,WAAW,IAAI,UAAU,KAAK;AAEzD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAQ;AAAA,MACR,MAAK;AAAA,MACL,OAAO,UAAU;AAAA,MACjB,UAAU,CAAC,OAAO,UAAU;AAC1B,YAAI,MAAM,OAAO,UAAU,QAAQ;AACjC,qBAAW,OAAO,KAAK;AACvB,sBAAY,MAAM,OAAO,KAAK;AAAA,QAChC;AAAA,MACF;AAAA,MACA,aAAa,CAAC,UAAU;AACtB,eAAO,oBAAC,cAAY,oBAAU,SAAS,aAAa,OAAM;AAAA,MAC5D;AAAA,MACC,GAAG;AAAA,MAEH;AAAA,oBAAY,IAAI,CAACA,SAAQ,UAAU;AAClC,iBACE,oBAAC,YAAqB,OAAOA,SAC1B,UAAAA,WADY,KAEf;AAAA,QAEJ,CAAC;AAAA,QACD,oBAAC,YAAoB,OAAM,QAAO,wBAApB,MAEd;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["schema"]}
|
|
@@ -1,2 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
// src/components/SelectEx/SchemaSelectEx.tsx
|
|
2
|
+
import { MenuItem, Typography } from "@mui/material";
|
|
3
|
+
import { SelectEx } from "@xylabs/react-select";
|
|
4
|
+
|
|
5
|
+
// src/contexts/Schema/Context.ts
|
|
6
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
7
|
+
var SchemaContext = createContextEx();
|
|
8
|
+
|
|
9
|
+
// src/contexts/Schema/use.ts
|
|
10
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
11
|
+
var useSchema = (required = false) => {
|
|
12
|
+
return useContextEx(SchemaContext, "Schema", required);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/components/SelectEx/SchemaSelectEx.tsx
|
|
16
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
var SchemaSelectEx = ({ onChange, ...props }) => {
|
|
18
|
+
const { schema, setSchema, schemaList } = useSchema(false);
|
|
19
|
+
return /* @__PURE__ */ jsxs(
|
|
20
|
+
SelectEx,
|
|
21
|
+
{
|
|
22
|
+
variant: "outlined",
|
|
23
|
+
size: "small",
|
|
24
|
+
value: schema ?? "none",
|
|
25
|
+
onChange: (event, child) => {
|
|
26
|
+
if (event.target.value !== schema) {
|
|
27
|
+
onChange?.(event, child);
|
|
28
|
+
setSchema?.(event.target.value);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
renderValue: (value) => {
|
|
32
|
+
return /* @__PURE__ */ jsx(Typography, { children: value === "none" ? "- None -" : value });
|
|
33
|
+
},
|
|
34
|
+
...props,
|
|
35
|
+
children: [
|
|
36
|
+
schemaList?.map((schema2, index) => {
|
|
37
|
+
return /* @__PURE__ */ jsx(MenuItem, { value: schema2, children: schema2 }, index);
|
|
38
|
+
}),
|
|
39
|
+
/* @__PURE__ */ jsx(MenuItem, { value: "none", children: "- None -" }, "none")
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
SchemaSelectEx
|
|
46
|
+
};
|
|
2
47
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/SelectEx/
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/SelectEx/SchemaSelectEx.tsx","../../../../src/contexts/Schema/Context.ts","../../../../src/contexts/Schema/use.ts"],"sourcesContent":["import { MenuItem, Typography } from '@mui/material'\nimport { SelectEx, SelectExProps } from '@xylabs/react-select'\n\nimport { useSchema } from '../../contexts'\n\nexport type SchemaSelectExProps = SelectExProps<string>\n\nexport const SchemaSelectEx: React.FC<SchemaSelectExProps> = ({ onChange, ...props }) => {\n const { schema, setSchema, schemaList } = useSchema(false)\n\n return (\n <SelectEx\n variant=\"outlined\"\n size=\"small\"\n value={schema ?? 'none'}\n onChange={(event, child) => {\n if (event.target.value !== schema) {\n onChange?.(event, child)\n setSchema?.(event.target.value)\n }\n }}\n renderValue={(value) => {\n return <Typography>{value === 'none' ? '- None -' : value}</Typography>\n }}\n {...props}\n >\n {schemaList?.map((schema, index) => {\n return (\n <MenuItem key={index} value={schema}>\n {schema}\n </MenuItem>\n )\n })}\n <MenuItem key=\"none\" value=\"none\">\n - None -\n </MenuItem>\n </SelectEx>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContextState } from './State'\n\nexport const SchemaContext = createContextEx<SchemaContextState>()\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContext } from './Context'\nimport { SchemaContextState } from './State'\n\nexport const useSchema = (required = false) => {\n return useContextEx<SchemaContextState>(SchemaContext, 'Schema', required)\n}\n"],"mappings":";AAAA,SAAS,UAAU,kBAAkB;AACrC,SAAS,gBAA+B;;;ACDxC,SAAS,uBAAuB;AAIzB,IAAM,gBAAgB,gBAAoC;;;ACJjE,SAAS,oBAAoB;AAKtB,IAAM,YAAY,CAAC,WAAW,UAAU;AAC7C,SAAO,aAAiC,eAAe,UAAU,QAAQ;AAC3E;;;AFII,SAWW,KAXX;AAJG,IAAM,iBAAgD,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM;AACvF,QAAM,EAAE,QAAQ,WAAW,WAAW,IAAI,UAAU,KAAK;AAEzD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAQ;AAAA,MACR,MAAK;AAAA,MACL,OAAO,UAAU;AAAA,MACjB,UAAU,CAAC,OAAO,UAAU;AAC1B,YAAI,MAAM,OAAO,UAAU,QAAQ;AACjC,qBAAW,OAAO,KAAK;AACvB,sBAAY,MAAM,OAAO,KAAK;AAAA,QAChC;AAAA,MACF;AAAA,MACA,aAAa,CAAC,UAAU;AACtB,eAAO,oBAAC,cAAY,oBAAU,SAAS,aAAa,OAAM;AAAA,MAC5D;AAAA,MACC,GAAG;AAAA,MAEH;AAAA,oBAAY,IAAI,CAACA,SAAQ,UAAU;AAClC,iBACE,oBAAC,YAAqB,OAAOA,SAC1B,UAAAA,WADY,KAEf;AAAA,QAEJ,CAAC;AAAA,QACD,oBAAC,YAAoB,OAAM,QAAO,wBAApB,MAEd;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["schema"]}
|
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/components/Property/SchemaProperty.tsx
|
|
2
|
+
import { NewReleases as NewReleasesIcon, OpenInNew as OpenInNewIcon, Verified as VerifiedIcon } from "@mui/icons-material";
|
|
3
|
+
import { IconButton } from "@mui/material";
|
|
4
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
5
|
+
import { LinkEx } from "@xylabs/react-link";
|
|
6
|
+
import { useEvent } from "@xyo-network/react-event";
|
|
7
|
+
import { Property, PropertyValue } from "@xyo-network/react-property";
|
|
8
|
+
import { SchemaCache } from "@xyo-network/schema-cache";
|
|
9
|
+
import { forwardRef, useState } from "react";
|
|
10
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
var useResolveSchema = (schema) => {
|
|
12
|
+
const [entry, setEntry] = useState();
|
|
13
|
+
useAsyncEffect(
|
|
14
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
15
|
+
async (mounted) => {
|
|
16
|
+
if (schema) {
|
|
17
|
+
const entry2 = await SchemaCache.instance.get(schema);
|
|
18
|
+
if (mounted()) {
|
|
19
|
+
setEntry(entry2);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
[schema]
|
|
24
|
+
);
|
|
25
|
+
return entry;
|
|
26
|
+
};
|
|
27
|
+
var SchemaProperty = forwardRef(
|
|
28
|
+
({ showLinkNames = true, showOpenNewWindowLink = true, showStatusIcon = true, titleProps, value, ...props }, forwardedRef) => {
|
|
29
|
+
const resolvedSchema = useResolveSchema(value);
|
|
30
|
+
const [buttonRef, buttonDispatch] = useEvent(void 0);
|
|
31
|
+
const [divRef, divDispatch] = useEvent(void 0);
|
|
32
|
+
const onClick = (dispatch, openNewWindow = false) => {
|
|
33
|
+
dispatch?.(
|
|
34
|
+
"schema",
|
|
35
|
+
"click",
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
openNewWindow,
|
|
38
|
+
schema: value
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
return /* @__PURE__ */ jsxs(Property, { ref: forwardedRef, title: "Schema", value, tip: "Schema sent with the payload", titleProps, ...props, children: [
|
|
43
|
+
value && showStatusIcon ? resolvedSchema === null ? /* @__PURE__ */ jsx(IconButton, { ref: buttonRef, size: "small", onClick: () => onClick(buttonDispatch), children: /* @__PURE__ */ jsx(NewReleasesIcon, { color: "warning", fontSize: "inherit" }) }) : resolvedSchema === void 0 ? /* @__PURE__ */ jsx(IconButton, { ref: buttonRef, size: "small", onClick: () => onClick(buttonDispatch), children: /* @__PURE__ */ jsx(NewReleasesIcon, { color: "disabled", fontSize: "inherit" }) }) : /* @__PURE__ */ jsx(IconButton, { rel: "noopener noreferrer", size: "small", target: "_blank", href: resolvedSchema?.huri?.href ?? "", children: /* @__PURE__ */ jsx(VerifiedIcon, { color: "success", fontSize: "inherit" }) }) : null,
|
|
44
|
+
value ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
45
|
+
showLinkNames ? /* @__PURE__ */ jsx(LinkEx, { display: "block", width: "100%", sx: { cursor: "pointer" }, children: /* @__PURE__ */ jsx(PropertyValue, { ref: divRef, value, title: "view schema", onClick: () => onClick(divDispatch) }) }) : /* @__PURE__ */ jsx(PropertyValue, { ref: divRef, value, title: "view schema", onClick: () => onClick(divDispatch) }),
|
|
46
|
+
showOpenNewWindowLink ? /* @__PURE__ */ jsx(IconButton, { ref: buttonRef, size: "small", onClick: () => onClick(buttonDispatch, true), children: /* @__PURE__ */ jsx(OpenInNewIcon, { fontSize: "inherit" }) }) : null
|
|
47
|
+
] }) : null
|
|
48
|
+
] });
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
SchemaProperty.displayName = "SchemaProperty";
|
|
52
|
+
|
|
53
|
+
// src/components/SelectEx/SchemaSelectEx.tsx
|
|
54
|
+
import { MenuItem, Typography } from "@mui/material";
|
|
55
|
+
import { SelectEx } from "@xylabs/react-select";
|
|
56
|
+
|
|
57
|
+
// src/contexts/Schema/Context.ts
|
|
58
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
59
|
+
var SchemaContext = createContextEx();
|
|
60
|
+
|
|
61
|
+
// src/contexts/Schema/use.ts
|
|
62
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
63
|
+
var useSchema = (required = false) => {
|
|
64
|
+
return useContextEx(SchemaContext, "Schema", required);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/components/SelectEx/SchemaSelectEx.tsx
|
|
68
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
69
|
+
var SchemaSelectEx = ({ onChange, ...props }) => {
|
|
70
|
+
const { schema, setSchema, schemaList } = useSchema(false);
|
|
71
|
+
return /* @__PURE__ */ jsxs2(
|
|
72
|
+
SelectEx,
|
|
73
|
+
{
|
|
74
|
+
variant: "outlined",
|
|
75
|
+
size: "small",
|
|
76
|
+
value: schema ?? "none",
|
|
77
|
+
onChange: (event, child) => {
|
|
78
|
+
if (event.target.value !== schema) {
|
|
79
|
+
onChange?.(event, child);
|
|
80
|
+
setSchema?.(event.target.value);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
renderValue: (value) => {
|
|
84
|
+
return /* @__PURE__ */ jsx2(Typography, { children: value === "none" ? "- None -" : value });
|
|
85
|
+
},
|
|
86
|
+
...props,
|
|
87
|
+
children: [
|
|
88
|
+
schemaList?.map((schema2, index) => {
|
|
89
|
+
return /* @__PURE__ */ jsx2(MenuItem, { value: schema2, children: schema2 }, index);
|
|
90
|
+
}),
|
|
91
|
+
/* @__PURE__ */ jsx2(MenuItem, { value: "none", children: "- None -" }, "none")
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
export {
|
|
97
|
+
SchemaProperty,
|
|
98
|
+
SchemaSelectEx
|
|
99
|
+
};
|
|
3
100
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Property/SchemaProperty.tsx","../../../src/components/SelectEx/SchemaSelectEx.tsx","../../../src/contexts/Schema/Context.ts","../../../src/contexts/Schema/use.ts"],"sourcesContent":["import { NewReleases as NewReleasesIcon, OpenInNew as OpenInNewIcon, Verified as VerifiedIcon } from '@mui/icons-material'\nimport { IconButton } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { LinkEx } from '@xylabs/react-link'\nimport { EventDispatch, EventNoun, useEvent } from '@xyo-network/react-event'\nimport { Property, PropertyProps, PropertyValue } from '@xyo-network/react-property'\nimport { SchemaCache, SchemaCacheEntry } from '@xyo-network/schema-cache'\nimport { forwardRef, useState } from 'react'\n\nexport type SchemaPropertyProps = PropertyProps & {\n showLinkNames?: boolean\n showOpenNewWindowLink?: boolean\n showStatusIcon?: boolean\n value?: string\n}\n\nconst useResolveSchema = (schema?: string) => {\n const [entry, setEntry] = useState<SchemaCacheEntry | null>()\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n if (schema) {\n const entry = await SchemaCache.instance.get(schema)\n if (mounted()) {\n setEntry(entry)\n }\n }\n },\n [schema],\n )\n return entry\n}\n\nexport const SchemaProperty = forwardRef<HTMLDivElement, SchemaPropertyProps>(\n ({ showLinkNames = true, showOpenNewWindowLink = true, showStatusIcon = true, titleProps, value, ...props }, forwardedRef) => {\n const resolvedSchema = useResolveSchema(value)\n const [buttonRef, buttonDispatch] = useEvent<HTMLButtonElement>(undefined)\n const [divRef, divDispatch] = useEvent<HTMLDivElement>(undefined)\n\n const onClick = (dispatch?: EventDispatch<EventNoun, 'click', string>, openNewWindow = false) => {\n dispatch?.(\n 'schema',\n 'click',\n JSON.stringify({\n openNewWindow,\n schema: value,\n }),\n )\n }\n\n return (\n <Property ref={forwardedRef} title=\"Schema\" value={value} tip=\"Schema sent with the payload\" titleProps={titleProps} {...props}>\n {value && showStatusIcon ? (\n resolvedSchema === null ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"warning\" fontSize=\"inherit\" />\n </IconButton>\n ) : resolvedSchema === undefined ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"disabled\" fontSize=\"inherit\" />\n </IconButton>\n ) : (\n <IconButton rel=\"noopener noreferrer\" size=\"small\" target=\"_blank\" href={resolvedSchema?.huri?.href ?? ''}>\n <VerifiedIcon color=\"success\" fontSize=\"inherit\" />\n </IconButton>\n )\n ) : null}\n {value ? (\n <>\n {showLinkNames ? (\n <LinkEx display=\"block\" width=\"100%\" sx={{ cursor: 'pointer' }}>\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n </LinkEx>\n ) : (\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n )}\n {showOpenNewWindowLink ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch, true)}>\n <OpenInNewIcon fontSize=\"inherit\" />\n </IconButton>\n ) : null}\n </>\n ) : null}\n </Property>\n )\n },\n)\n\nSchemaProperty.displayName = 'SchemaProperty'\n","import { MenuItem, Typography } from '@mui/material'\nimport { SelectEx, SelectExProps } from '@xylabs/react-select'\n\nimport { useSchema } from '../../contexts'\n\nexport type SchemaSelectExProps = SelectExProps<string>\n\nexport const SchemaSelectEx: React.FC<SchemaSelectExProps> = ({ onChange, ...props }) => {\n const { schema, setSchema, schemaList } = useSchema(false)\n\n return (\n <SelectEx\n variant=\"outlined\"\n size=\"small\"\n value={schema ?? 'none'}\n onChange={(event, child) => {\n if (event.target.value !== schema) {\n onChange?.(event, child)\n setSchema?.(event.target.value)\n }\n }}\n renderValue={(value) => {\n return <Typography>{value === 'none' ? '- None -' : value}</Typography>\n }}\n {...props}\n >\n {schemaList?.map((schema, index) => {\n return (\n <MenuItem key={index} value={schema}>\n {schema}\n </MenuItem>\n )\n })}\n <MenuItem key=\"none\" value=\"none\">\n - None -\n </MenuItem>\n </SelectEx>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContextState } from './State'\n\nexport const SchemaContext = createContextEx<SchemaContextState>()\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContext } from './Context'\nimport { SchemaContextState } from './State'\n\nexport const useSchema = (required = false) => {\n return useContextEx<SchemaContextState>(SchemaContext, 'Schema', required)\n}\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB,aAAa,eAAe,YAAY,oBAAoB;AACrG,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAmC,gBAAgB;AACnD,SAAS,UAAyB,qBAAqB;AACvD,SAAS,mBAAqC;AAC9C,SAAS,YAAY,gBAAgB;AAgDvB,SAaJ,UAbI,KAaJ,YAbI;AAvCd,IAAM,mBAAmB,CAAC,WAAoB;AAC5C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkC;AAC5D;AAAA;AAAA,IAEE,OAAO,YAAY;AACjB,UAAI,QAAQ;AACV,cAAMA,SAAQ,MAAM,YAAY,SAAS,IAAI,MAAM;AACnD,YAAI,QAAQ,GAAG;AACb,mBAASA,MAAK;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACA,SAAO;AACT;AAEO,IAAM,iBAAiB;AAAA,EAC5B,CAAC,EAAE,gBAAgB,MAAM,wBAAwB,MAAM,iBAAiB,MAAM,YAAY,OAAO,GAAG,MAAM,GAAG,iBAAiB;AAC5H,UAAM,iBAAiB,iBAAiB,KAAK;AAC7C,UAAM,CAAC,WAAW,cAAc,IAAI,SAA4B,MAAS;AACzE,UAAM,CAAC,QAAQ,WAAW,IAAI,SAAyB,MAAS;AAEhE,UAAM,UAAU,CAAC,UAAsD,gBAAgB,UAAU;AAC/F;AAAA,QACE;AAAA,QACA;AAAA,QACA,KAAK,UAAU;AAAA,UACb;AAAA,UACA,QA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Q;AAC3E;;;AFII,SAWW,OAAAC,MAXX,QAAAC,aAAA;AAJG,IAAM,iBAAgD,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM;AACvF,QAAM,EAAE,QAAQ,WAAW,WAAW,IAAI,UAAU,KAAK;AAEzD,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC,SAAQ;AAAA,MACR,MAAK;AAAA,MACL,OAAO,UAAU;AAAA,MACjB,UAAU,CAAC,OAAO,UAAU;AAC1B,YAAI,MAAM,OAAO,UAAU,QAAQ;AACjC,qBAAW,OAAO,KAAK;AACvB,sBAAY,MAAM,OAAO,KAAK;AAAA,QAChC;AAAA,MACF;AAAA,MACA,aAAa,CAAC,UAAU;AACtB,eAAO,gBAAAD,KAAC,cAAY,oBAAU,SAAS,aAAa,OAAM;AAAA,MAC5D;AAAA,MACC,GAAG;AAAA,MAEH;AAAA,oBAAY,IAAI,CAACE,SAAQ,UAAU;AAClC,iBACE,gBAAAF,KAAC,YAAqB,OAAOE,SAC1B,UAAAA,WADY,KAEf;AAAA,QAEJ,CAAC;AAAA,QACD,gBAAAF,KAAC,YAAoB,OAAM,QAAO,wBAApB,MAEd;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["entry","jsx","jsxs","schema"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/Schema/Context.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContextState } from './State'\n\nexport const SchemaContext = createContextEx<SchemaContextState>()\n"],"mappings":"AAAA,SAAS,uBAAuB;AAIzB,
|
|
1
|
+
{"version":3,"sources":["../../../../src/contexts/Schema/Context.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContextState } from './State'\n\nexport const SchemaContext = createContextEx<SchemaContextState>()\n"],"mappings":";AAAA,SAAS,uBAAuB;AAIzB,IAAM,gBAAgB,gBAAoC;","names":[]}
|
|
@@ -1,11 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
// src/contexts/Schema/Provider/Memory.tsx
|
|
2
2
|
import { compact } from "@xylabs/lodash";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { useEffect, useState as useState2 } from "react";
|
|
4
|
+
|
|
5
|
+
// src/hooks/useSchemaStats.tsx
|
|
6
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
7
|
+
import { isSchemaStatsPayload, SchemaStatsQuerySchema } from "@xyo-network/diviner-schema-stats-model";
|
|
8
|
+
import { TYPES } from "@xyo-network/node-core-types";
|
|
9
|
+
import { useDivinerFromNode } from "@xyo-network/react-diviner";
|
|
10
|
+
import { useMemo, useState } from "react";
|
|
11
|
+
var useSchemaStats = (statsAddress, nameOrAddress = TYPES.SchemaStatsDiviner.description) => {
|
|
12
|
+
const [refresh, setRefresh] = useState(1);
|
|
13
|
+
const [diviner, divinerError] = useDivinerFromNode(nameOrAddress);
|
|
14
|
+
const [error, setError] = useState();
|
|
15
|
+
const refreshHistory = () => setRefresh((previous) => previous + 1);
|
|
16
|
+
const [schemaList, setSchemaList] = useState();
|
|
17
|
+
const query = useMemo(
|
|
18
|
+
() => ({
|
|
19
|
+
address: statsAddress,
|
|
20
|
+
schema: SchemaStatsQuerySchema
|
|
21
|
+
}),
|
|
22
|
+
[statsAddress]
|
|
23
|
+
);
|
|
24
|
+
useAsyncEffect(
|
|
25
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
|
+
async (mounted) => {
|
|
27
|
+
if (diviner) {
|
|
28
|
+
if (divinerError) {
|
|
29
|
+
if (mounted()) {
|
|
30
|
+
setError(divinerError);
|
|
31
|
+
setSchemaList(void 0);
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
try {
|
|
35
|
+
const schemas = (await diviner.divine([query])).filter(isSchemaStatsPayload);
|
|
36
|
+
if (mounted()) {
|
|
37
|
+
setSchemaList(schemas);
|
|
38
|
+
setError(void 0);
|
|
39
|
+
}
|
|
40
|
+
} catch (ex) {
|
|
41
|
+
setError(ex);
|
|
42
|
+
setSchemaList(void 0);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[diviner, refresh, divinerError, query]
|
|
48
|
+
);
|
|
49
|
+
return [schemaList, error, refreshHistory];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/contexts/Schema/Context.ts
|
|
53
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
54
|
+
var SchemaContext = createContextEx();
|
|
55
|
+
|
|
56
|
+
// src/contexts/Schema/Provider/Memory.tsx
|
|
57
|
+
import { jsx } from "react/jsx-runtime";
|
|
58
|
+
var SchemaMemoryProvider = ({ defaultSchema, knownSchemaList = [], ...props }) => {
|
|
59
|
+
const [schema, setSchema] = useState2(defaultSchema);
|
|
60
|
+
const [schemaList, setSchemaList] = useState2(knownSchemaList);
|
|
9
61
|
const [fetchedSchemaStats] = useSchemaStats();
|
|
10
62
|
useEffect(() => {
|
|
11
63
|
if (fetchedSchemaStats) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/contexts/Schema/Provider/Memory.tsx"],"sourcesContent":["import { compact } from '@xylabs/lodash'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { useSchemaStats } from '../../../hooks'\nimport { SchemaContext } from '../Context'\nimport { SchemaProviderProps } from './Props'\n\nexport const SchemaMemoryProvider: React.FC<WithChildren<SchemaProviderProps>> = ({ defaultSchema, knownSchemaList = [], ...props }) => {\n const [schema, setSchema] = useState(defaultSchema)\n const [schemaList, setSchemaList] = useState<string[] | undefined>(knownSchemaList)\n const [fetchedSchemaStats] = useSchemaStats()\n\n useEffect(() => {\n if (fetchedSchemaStats) {\n const schemaList = compact(fetchedSchemaStats.map(({ name }) => name))\n setSchemaList(schemaList)\n }\n }, [fetchedSchemaStats])\n\n return <SchemaContext.Provider value={{ provided: true, schema, schemaList: knownSchemaList ?? schemaList, setSchema, setSchemaList }} {...props} />\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/contexts/Schema/Provider/Memory.tsx","../../../../../src/hooks/useSchemaStats.tsx","../../../../../src/contexts/Schema/Context.ts"],"sourcesContent":["import { compact } from '@xylabs/lodash'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { useSchemaStats } from '../../../hooks'\nimport { SchemaContext } from '../Context'\nimport { SchemaProviderProps } from './Props'\n\nexport const SchemaMemoryProvider: React.FC<WithChildren<SchemaProviderProps>> = ({ defaultSchema, knownSchemaList = [], ...props }) => {\n const [schema, setSchema] = useState(defaultSchema)\n const [schemaList, setSchemaList] = useState<string[] | undefined>(knownSchemaList)\n const [fetchedSchemaStats] = useSchemaStats()\n\n useEffect(() => {\n if (fetchedSchemaStats) {\n const schemaList = compact(fetchedSchemaStats.map(({ name }) => name))\n setSchemaList(schemaList)\n }\n }, [fetchedSchemaStats])\n\n return <SchemaContext.Provider value={{ provided: true, schema, schemaList: knownSchemaList ?? schemaList, setSchema, setSchemaList }} {...props} />\n}\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { isSchemaStatsPayload, SchemaStatsPayload, SchemaStatsQueryPayload, SchemaStatsQuerySchema } from '@xyo-network/diviner-schema-stats-model'\nimport { TYPES } from '@xyo-network/node-core-types'\nimport { useDivinerFromNode } from '@xyo-network/react-diviner'\nimport { Dispatch, SetStateAction, useMemo, useState } from 'react'\n\nexport const useSchemaStats = (\n statsAddress?: string,\n nameOrAddress = TYPES.SchemaStatsDiviner.description,\n): [SchemaStatsPayload[] | undefined, Error | undefined, Dispatch<SetStateAction<number>>] => {\n const [refresh, setRefresh] = useState(1)\n const [diviner, divinerError] = useDivinerFromNode(nameOrAddress)\n const [error, setError] = useState<Error>()\n const refreshHistory = () => setRefresh((previous) => previous + 1)\n\n const [schemaList, setSchemaList] = useState<SchemaStatsPayload[]>()\n\n const query: SchemaStatsQueryPayload = useMemo(\n () => ({\n address: statsAddress,\n schema: SchemaStatsQuerySchema,\n }),\n [statsAddress],\n )\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n if (diviner) {\n if (divinerError) {\n if (mounted()) {\n setError(divinerError)\n setSchemaList(undefined)\n }\n } else {\n try {\n const schemas = (await diviner.divine([query])).filter(isSchemaStatsPayload)\n if (mounted()) {\n setSchemaList(schemas)\n setError(undefined)\n }\n } catch (ex) {\n setError(ex as Error)\n setSchemaList(undefined)\n }\n }\n }\n },\n [diviner, refresh, divinerError, query],\n )\n\n return [schemaList, error, refreshHistory]\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContextState } from './State'\n\nexport const SchemaContext = createContextEx<SchemaContextState>()\n"],"mappings":";AAAA,SAAS,eAAe;AAExB,SAAS,WAAW,YAAAA,iBAAgB;;;ACFpC,SAAS,sBAAsB;AAC/B,SAAS,sBAAmE,8BAA8B;AAC1G,SAAS,aAAa;AACtB,SAAS,0BAA0B;AACnC,SAAmC,SAAS,gBAAgB;AAErD,IAAM,iBAAiB,CAC5B,cACA,gBAAgB,MAAM,mBAAmB,gBACmD;AAC5F,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,CAAC;AACxC,QAAM,CAAC,SAAS,YAAY,IAAI,mBAAmB,aAAa;AAChE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAgB;AAC1C,QAAM,iBAAiB,MAAM,WAAW,CAAC,aAAa,WAAW,CAAC;AAElE,QAAM,CAAC,YAAY,aAAa,IAAI,SAA+B;AAEnE,QAAM,QAAiC;AAAA,IACrC,OAAO;AAAA,MACL,SAAS;AAAA,MACT,QAAQ;AAAA,IACV;AAAA,IACA,CAAC,YAAY;AAAA,EACf;AAEA;AAAA;AAAA,IAEE,OAAO,YAAY;AACjB,UAAI,SAAS;AACX,YAAI,cAAc;AAChB,cAAI,QAAQ,GAAG;AACb,qBAAS,YAAY;AACrB,0BAAc,MAAS;AAAA,UACzB;AAAA,QACF,OAAO;AACL,cAAI;AACF,kBAAM,WAAW,MAAM,QAAQ,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,oBAAoB;AAC3E,gBAAI,QAAQ,GAAG;AACb,4BAAc,OAAO;AACrB,uBAAS,MAAS;AAAA,YACpB;AAAA,UACF,SAAS,IAAI;AACX,qBAAS,EAAW;AACpB,0BAAc,MAAS;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,SAAS,SAAS,cAAc,KAAK;AAAA,EACxC;AAEA,SAAO,CAAC,YAAY,OAAO,cAAc;AAC3C;;;ACpDA,SAAS,uBAAuB;AAIzB,IAAM,gBAAgB,gBAAoC;;;AFgBxD;AAZF,IAAM,uBAAoE,CAAC,EAAE,eAAe,kBAAkB,CAAC,GAAG,GAAG,MAAM,MAAM;AACtI,QAAM,CAAC,QAAQ,SAAS,IAAIC,UAAS,aAAa;AAClD,QAAM,CAAC,YAAY,aAAa,IAAIA,UAA+B,eAAe;AAClF,QAAM,CAAC,kBAAkB,IAAI,eAAe;AAE5C,YAAU,MAAM;AACd,QAAI,oBAAoB;AACtB,YAAMC,cAAa,QAAQ,mBAAmB,IAAI,CAAC,EAAE,KAAK,MAAM,IAAI,CAAC;AACrE,oBAAcA,WAAU;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,kBAAkB,CAAC;AAEvB,SAAO,oBAAC,cAAc,UAAd,EAAuB,OAAO,EAAE,UAAU,MAAM,QAAQ,YAAY,mBAAmB,YAAY,WAAW,cAAc,GAAI,GAAG,OAAO;AACpJ;","names":["useState","useState","schemaList"]}
|
|
@@ -1,10 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
import { useCallback, useEffect } from "react";
|
|
1
|
+
// src/contexts/Schema/Provider/Route.tsx
|
|
2
|
+
import { useCallback, useEffect as useEffect2 } from "react";
|
|
3
3
|
import { useSearchParams } from "react-router-dom";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
4
|
+
|
|
5
|
+
// src/contexts/Schema/Context.ts
|
|
6
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
7
|
+
var SchemaContext = createContextEx();
|
|
8
|
+
|
|
9
|
+
// src/contexts/Schema/use.ts
|
|
10
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
11
|
+
var useSchema = (required = false) => {
|
|
12
|
+
return useContextEx(SchemaContext, "Schema", required);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/contexts/Schema/Provider/Memory.tsx
|
|
16
|
+
import { compact } from "@xylabs/lodash";
|
|
17
|
+
import { useEffect, useState as useState2 } from "react";
|
|
18
|
+
|
|
19
|
+
// src/hooks/useSchemaStats.tsx
|
|
20
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
21
|
+
import { isSchemaStatsPayload, SchemaStatsQuerySchema } from "@xyo-network/diviner-schema-stats-model";
|
|
22
|
+
import { TYPES } from "@xyo-network/node-core-types";
|
|
23
|
+
import { useDivinerFromNode } from "@xyo-network/react-diviner";
|
|
24
|
+
import { useMemo, useState } from "react";
|
|
25
|
+
var useSchemaStats = (statsAddress, nameOrAddress = TYPES.SchemaStatsDiviner.description) => {
|
|
26
|
+
const [refresh, setRefresh] = useState(1);
|
|
27
|
+
const [diviner, divinerError] = useDivinerFromNode(nameOrAddress);
|
|
28
|
+
const [error, setError] = useState();
|
|
29
|
+
const refreshHistory = () => setRefresh((previous) => previous + 1);
|
|
30
|
+
const [schemaList, setSchemaList] = useState();
|
|
31
|
+
const query = useMemo(
|
|
32
|
+
() => ({
|
|
33
|
+
address: statsAddress,
|
|
34
|
+
schema: SchemaStatsQuerySchema
|
|
35
|
+
}),
|
|
36
|
+
[statsAddress]
|
|
37
|
+
);
|
|
38
|
+
useAsyncEffect(
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
async (mounted) => {
|
|
41
|
+
if (diviner) {
|
|
42
|
+
if (divinerError) {
|
|
43
|
+
if (mounted()) {
|
|
44
|
+
setError(divinerError);
|
|
45
|
+
setSchemaList(void 0);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
try {
|
|
49
|
+
const schemas = (await diviner.divine([query])).filter(isSchemaStatsPayload);
|
|
50
|
+
if (mounted()) {
|
|
51
|
+
setSchemaList(schemas);
|
|
52
|
+
setError(void 0);
|
|
53
|
+
}
|
|
54
|
+
} catch (ex) {
|
|
55
|
+
setError(ex);
|
|
56
|
+
setSchemaList(void 0);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
[diviner, refresh, divinerError, query]
|
|
62
|
+
);
|
|
63
|
+
return [schemaList, error, refreshHistory];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/contexts/Schema/Provider/Memory.tsx
|
|
67
|
+
import { jsx } from "react/jsx-runtime";
|
|
68
|
+
var SchemaMemoryProvider = ({ defaultSchema, knownSchemaList = [], ...props }) => {
|
|
69
|
+
const [schema, setSchema] = useState2(defaultSchema);
|
|
70
|
+
const [schemaList, setSchemaList] = useState2(knownSchemaList);
|
|
71
|
+
const [fetchedSchemaStats] = useSchemaStats();
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (fetchedSchemaStats) {
|
|
74
|
+
const schemaList2 = compact(fetchedSchemaStats.map(({ name }) => name));
|
|
75
|
+
setSchemaList(schemaList2);
|
|
76
|
+
}
|
|
77
|
+
}, [fetchedSchemaStats]);
|
|
78
|
+
return /* @__PURE__ */ jsx(SchemaContext.Provider, { value: { provided: true, schema, schemaList: knownSchemaList ?? schemaList, setSchema, setSchemaList }, ...props });
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/contexts/Schema/Provider/Route.tsx
|
|
82
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
83
|
+
var SchemaRouteProviderInner = ({ children }) => {
|
|
8
84
|
const { schema, setSchema, schemaList } = useSchema();
|
|
9
85
|
const [params, setParams] = useSearchParams();
|
|
10
86
|
const routeSchema = params.get("schema");
|
|
@@ -27,7 +103,7 @@ const SchemaRouteProviderInner = ({ children }) => {
|
|
|
27
103
|
},
|
|
28
104
|
[setSchemaParam, setSchema]
|
|
29
105
|
);
|
|
30
|
-
|
|
106
|
+
useEffect2(() => {
|
|
31
107
|
if (routeSchema !== schema) {
|
|
32
108
|
if (routeSchema === void 0 && schema !== void 0) {
|
|
33
109
|
setSchemaLocal(schema);
|
|
@@ -36,10 +112,10 @@ const SchemaRouteProviderInner = ({ children }) => {
|
|
|
36
112
|
}
|
|
37
113
|
}
|
|
38
114
|
}, [routeSchema, schema, setSchemaParam, setSchema, setSchemaLocal]);
|
|
39
|
-
return /* @__PURE__ */
|
|
115
|
+
return /* @__PURE__ */ jsx2(SchemaContext.Provider, { value: { provided: true, schema, schemaList, setSchema: setSchemaLocal }, children });
|
|
40
116
|
};
|
|
41
|
-
|
|
42
|
-
return /* @__PURE__ */
|
|
117
|
+
var SchemaRouteProvider = ({ knownSchemaList, defaultSchema, ...props }) => {
|
|
118
|
+
return /* @__PURE__ */ jsx2(SchemaMemoryProvider, { knownSchemaList, defaultSchema, children: /* @__PURE__ */ jsx2(SchemaRouteProviderInner, { ...props }) });
|
|
43
119
|
};
|
|
44
120
|
export {
|
|
45
121
|
SchemaRouteProvider
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/contexts/Schema/Provider/Route.tsx"],"sourcesContent":["import type { WithChildren } from '@xylabs/react-shared'\nimport { useCallback, useEffect } from 'react'\nimport { useSearchParams } from 'react-router-dom'\n\nimport { SchemaContext } from '../Context'\nimport { useSchema } from '../use'\nimport { SchemaMemoryProvider } from './Memory'\nimport { SchemaProviderProps } from './Props'\n\nconst SchemaRouteProviderInner: React.FC<WithChildren> = ({ children }) => {\n const { schema, setSchema, schemaList } = useSchema()\n\n const [params, setParams] = useSearchParams()\n\n const routeSchema = params.get('schema')\n\n //update the network stored in the route\n const setSchemaParam = useCallback(\n (schema?: string) => {\n if (schema) {\n params.set('schema', schema)\n setParams(params, { replace: true })\n setSchema?.(schema)\n } else {\n params.delete('network')\n }\n },\n [params, setParams, setSchema],\n )\n\n //if the network is actively changed, update both memory and route\n const setSchemaLocal = useCallback(\n (schema: string) => {\n setSchemaParam(schema)\n setSchema?.(schema)\n },\n [setSchemaParam, setSchema],\n )\n\n //sync memory and route storage of network\n useEffect(() => {\n if (routeSchema !== schema) {\n if (routeSchema === undefined && schema !== undefined) {\n //if the route does not have a network selected, use what is in the memory context\n setSchemaLocal(schema)\n } else if (routeSchema) {\n //if the route has a selection and it is different from memory, update memory\n setSchema?.(routeSchema)\n }\n }\n }, [routeSchema, schema, setSchemaParam, setSchema, setSchemaLocal])\n\n return <SchemaContext.Provider value={{ provided: true, schema, schemaList, setSchema: setSchemaLocal }}>{children}</SchemaContext.Provider>\n}\n\nexport const SchemaRouteProvider: React.FC<WithChildren<SchemaProviderProps>> = ({ knownSchemaList, defaultSchema, ...props }) => {\n return (\n <SchemaMemoryProvider knownSchemaList={knownSchemaList} defaultSchema={defaultSchema}>\n <SchemaRouteProviderInner {...props} />\n </SchemaMemoryProvider>\n )\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/contexts/Schema/Provider/Route.tsx","../../../../../src/contexts/Schema/Context.ts","../../../../../src/contexts/Schema/use.ts","../../../../../src/contexts/Schema/Provider/Memory.tsx","../../../../../src/hooks/useSchemaStats.tsx"],"sourcesContent":["import type { WithChildren } from '@xylabs/react-shared'\nimport { useCallback, useEffect } from 'react'\nimport { useSearchParams } from 'react-router-dom'\n\nimport { SchemaContext } from '../Context'\nimport { useSchema } from '../use'\nimport { SchemaMemoryProvider } from './Memory'\nimport { SchemaProviderProps } from './Props'\n\nconst SchemaRouteProviderInner: React.FC<WithChildren> = ({ children }) => {\n const { schema, setSchema, schemaList } = useSchema()\n\n const [params, setParams] = useSearchParams()\n\n const routeSchema = params.get('schema')\n\n //update the network stored in the route\n const setSchemaParam = useCallback(\n (schema?: string) => {\n if (schema) {\n params.set('schema', schema)\n setParams(params, { replace: true })\n setSchema?.(schema)\n } else {\n params.delete('network')\n }\n },\n [params, setParams, setSchema],\n )\n\n //if the network is actively changed, update both memory and route\n const setSchemaLocal = useCallback(\n (schema: string) => {\n setSchemaParam(schema)\n setSchema?.(schema)\n },\n [setSchemaParam, setSchema],\n )\n\n //sync memory and route storage of network\n useEffect(() => {\n if (routeSchema !== schema) {\n if (routeSchema === undefined && schema !== undefined) {\n //if the route does not have a network selected, use what is in the memory context\n setSchemaLocal(schema)\n } else if (routeSchema) {\n //if the route has a selection and it is different from memory, update memory\n setSchema?.(routeSchema)\n }\n }\n }, [routeSchema, schema, setSchemaParam, setSchema, setSchemaLocal])\n\n return <SchemaContext.Provider value={{ provided: true, schema, schemaList, setSchema: setSchemaLocal }}>{children}</SchemaContext.Provider>\n}\n\nexport const SchemaRouteProvider: React.FC<WithChildren<SchemaProviderProps>> = ({ knownSchemaList, defaultSchema, ...props }) => {\n return (\n <SchemaMemoryProvider knownSchemaList={knownSchemaList} defaultSchema={defaultSchema}>\n <SchemaRouteProviderInner {...props} />\n </SchemaMemoryProvider>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContextState } from './State'\n\nexport const SchemaContext = createContextEx<SchemaContextState>()\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { SchemaContext } from './Context'\nimport { SchemaContextState } from './State'\n\nexport const useSchema = (required = false) => {\n return useContextEx<SchemaContextState>(SchemaContext, 'Schema', required)\n}\n","import { compact } from '@xylabs/lodash'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { useSchemaStats } from '../../../hooks'\nimport { SchemaContext } from '../Context'\nimport { SchemaProviderProps } from './Props'\n\nexport const SchemaMemoryProvider: React.FC<WithChildren<SchemaProviderProps>> = ({ defaultSchema, knownSchemaList = [], ...props }) => {\n const [schema, setSchema] = useState(defaultSchema)\n const [schemaList, setSchemaList] = useState<string[] | undefined>(knownSchemaList)\n const [fetchedSchemaStats] = useSchemaStats()\n\n useEffect(() => {\n if (fetchedSchemaStats) {\n const schemaList = compact(fetchedSchemaStats.map(({ name }) => name))\n setSchemaList(schemaList)\n }\n }, [fetchedSchemaStats])\n\n return <SchemaContext.Provider value={{ provided: true, schema, schemaList: knownSchemaList ?? schemaList, setSchema, setSchemaList }} {...props} />\n}\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { isSchemaStatsPayload, SchemaStatsPayload, SchemaStatsQueryPayload, SchemaStatsQuerySchema } from '@xyo-network/diviner-schema-stats-model'\nimport { TYPES } from '@xyo-network/node-core-types'\nimport { useDivinerFromNode } from '@xyo-network/react-diviner'\nimport { Dispatch, SetStateAction, useMemo, useState } from 'react'\n\nexport const useSchemaStats = (\n statsAddress?: string,\n nameOrAddress = TYPES.SchemaStatsDiviner.description,\n): [SchemaStatsPayload[] | undefined, Error | undefined, Dispatch<SetStateAction<number>>] => {\n const [refresh, setRefresh] = useState(1)\n const [diviner, divinerError] = useDivinerFromNode(nameOrAddress)\n const [error, setError] = useState<Error>()\n const refreshHistory = () => setRefresh((previous) => previous + 1)\n\n const [schemaList, setSchemaList] = useState<SchemaStatsPayload[]>()\n\n const query: SchemaStatsQueryPayload = useMemo(\n () => ({\n address: statsAddress,\n schema: SchemaStatsQuerySchema,\n }),\n [statsAddress],\n )\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n if (diviner) {\n if (divinerError) {\n if (mounted()) {\n setError(divinerError)\n setSchemaList(undefined)\n }\n } else {\n try {\n const schemas = (await diviner.divine([query])).filter(isSchemaStatsPayload)\n if (mounted()) {\n setSchemaList(schemas)\n setError(undefined)\n }\n } catch (ex) {\n setError(ex as Error)\n setSchemaList(undefined)\n }\n }\n }\n },\n [diviner, refresh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