@xyo-network/react-schema 2.25.18 → 2.25.21
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/cjs/components/Property/SchemaProperty.d.ts +7 -0
- package/dist/cjs/components/Property/SchemaProperty.js +34 -0
- package/dist/cjs/components/Property/SchemaProperty.js.map +1 -0
- package/dist/cjs/components/Property/index.d.ts +1 -0
- package/dist/cjs/components/Property/index.js +5 -0
- package/dist/cjs/components/Property/index.js.map +1 -0
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/docs.json +25099 -134
- package/dist/esm/components/Property/SchemaProperty.d.ts +7 -0
- package/dist/esm/components/Property/SchemaProperty.js +28 -0
- package/dist/esm/components/Property/SchemaProperty.js.map +1 -0
- package/dist/esm/components/Property/index.d.ts +1 -0
- package/dist/esm/components/Property/index.js +2 -0
- package/dist/esm/components/Property/index.js.map +1 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/Property/SchemaProperty.stories.tsx +33 -0
- package/src/components/Property/SchemaProperty.tsx +63 -0
- package/src/components/Property/index.ts +1 -0
- package/src/components/index.ts +1 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PropertyProps } from '@xyo-network/react-property';
|
|
3
|
+
export interface SchemaPropertyProps extends PropertyProps {
|
|
4
|
+
value?: string;
|
|
5
|
+
viewSchemaUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const SchemaProperty: React.FC<SchemaPropertyProps>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import NewReleasesIcon from '@mui/icons-material/NewReleases';
|
|
3
|
+
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
|
4
|
+
import VerifiedIcon from '@mui/icons-material/Verified';
|
|
5
|
+
import { IconButton } from '@mui/material';
|
|
6
|
+
import { LinkEx, useAsyncEffect } from '@xylabs/sdk-react';
|
|
7
|
+
import { Property, PropertyValue } from '@xyo-network/react-property';
|
|
8
|
+
import { XyoSchemaCache } from '@xyo-network/utils';
|
|
9
|
+
import { useState } from 'react';
|
|
10
|
+
const useResolveSchema = (schema) => {
|
|
11
|
+
const [entry, setEntry] = useState();
|
|
12
|
+
useAsyncEffect(
|
|
13
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
|
+
async (mounted) => {
|
|
15
|
+
if (schema) {
|
|
16
|
+
const entry = await XyoSchemaCache.instance.get(schema);
|
|
17
|
+
if (mounted()) {
|
|
18
|
+
setEntry(entry);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}, [schema]);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
export const SchemaProperty = ({ value, viewSchemaUrl = 'https://explore.xyo.network/' }) => {
|
|
25
|
+
const resolvedSchema = useResolveSchema(value);
|
|
26
|
+
return (_jsxs(Property, { flexGrow: 1, title: "Schema", value: value, tip: "Schema sent with the payload", children: [value ? (resolvedSchema === null ? (_jsx(IconButton, { rel: "noopener noreferrer", size: "small", target: "_blank", href: `${viewSchemaUrl}${value}`, children: _jsx(NewReleasesIcon, { color: "error", fontSize: "inherit" }) })) : resolvedSchema === undefined ? (_jsx(IconButton, { rel: "noopener noreferrer", size: "small", target: "_blank", href: `${viewSchemaUrl}${value}`, children: _jsx(NewReleasesIcon, { color: "disabled", fontSize: "inherit" }) })) : (_jsx(IconButton, { rel: "noopener noreferrer", size: "small", target: "_blank", href: resolvedSchema?.huri?.href ?? '', children: _jsx(VerifiedIcon, { color: "success", fontSize: "inherit" }) }))) : null, value ? (_jsx(LinkEx, { marginX: 1, flexGrow: 1, alignItems: "center", href: `${viewSchemaUrl}${value}`, rel: "noopener noreferrer", display: "flex", children: _jsx(PropertyValue, { value: value, title: "view schema in new window" }) })) : null, value ? (_jsx(LinkEx, { marginX: 1, alignItems: "center", href: `${viewSchemaUrl}${value}`, target: "_blank", rel: "noopener noreferrer", display: "flex", children: _jsx(OpenInNewIcon, { fontSize: "inherit" }) })) : null] }));
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=SchemaProperty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaProperty.js","sourceRoot":"","sources":["../../../../src/components/Property/SchemaProperty.tsx"],"names":[],"mappings":";AAAA,OAAO,eAAe,MAAM,iCAAiC,CAAA;AAC7D,OAAO,aAAa,MAAM,+BAA+B,CAAA;AACzD,OAAO,YAAY,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAiB,aAAa,EAAE,MAAM,6BAA6B,CAAA;AACpF,OAAO,EAAE,cAAc,EAAuB,MAAM,oBAAoB,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAOhC,MAAM,gBAAgB,GAAG,CAAC,MAAe,EAAE,EAAE;IAC3C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAA8B,CAAA;IAChE,cAAc;IACZ,uDAAuD;IACvD,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IAAI,MAAM,EAAE;YACV,MAAM,KAAK,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YACvD,IAAI,OAAO,EAAE,EAAE;gBACb,QAAQ,CAAC,KAAK,CAAC,CAAA;aAChB;SACF;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAA;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc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AC,QAAQ,EAAC,IAAI,EAAE,GAAG,aAAa,GAAG,KAAK,EAAE,EAAE,GAAG,EAAC,qBAAqB,EAAC,OAAO,EAAC,MAAM,YAC7H,KAAC,aAAa,IAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC,2BAA2B,GAAG,GAC1D,CACV,CAAC,CAAC,CAAC,IAAI,EACP,KAAK,CAAC,CAAC,CAAC,CACP,KAAC,MAAM,IAAC,OAAO,EAAE,CAAC,EAAE,UAAU,EAAC,QAAQ,EAAC,IAAI,EAAE,GAAG,aAAa,GAAG,KAAK,EAAE,EAAE,MAAM,EAAC,QAAQ,EAAC,GAAG,EAAC,qBAAqB,EAAC,OAAO,EAAC,MAAM,YAChI,KAAC,aAAa,IAAC,QAAQ,EAAC,SAAS,GAAG,GAC7B,CACV,CAAC,CAAC,CAAC,IAAI,IACC,CACZ,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SchemaProperty';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Property/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
|
package/package.json
CHANGED
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"@xylabs/sdk-react": "^2.12.8",
|
|
17
17
|
"@xyo-network/api": "^2.20.33",
|
|
18
18
|
"@xyo-network/core": "^2.20.33",
|
|
19
|
-
"@xyo-network/react-archive": "^2.25.
|
|
20
|
-
"@xyo-network/react-archivist-api": "^2.25.
|
|
21
|
-
"@xyo-network/react-shared": "^2.25.
|
|
22
|
-
"@xyo-network/react-theme": "^2.25.
|
|
19
|
+
"@xyo-network/react-archive": "^2.25.21",
|
|
20
|
+
"@xyo-network/react-archivist-api": "^2.25.21",
|
|
21
|
+
"@xyo-network/react-shared": "^2.25.21",
|
|
22
|
+
"@xyo-network/react-theme": "^2.25.21",
|
|
23
23
|
"@xyo-network/utils": "^2.20.33",
|
|
24
24
|
"lodash": "^4.17.21",
|
|
25
25
|
"react": "^18.1.0",
|
|
@@ -104,6 +104,6 @@
|
|
|
104
104
|
},
|
|
105
105
|
"sideEffects": false,
|
|
106
106
|
"types": "dist/esm/index.d.ts",
|
|
107
|
-
"version": "2.25.
|
|
107
|
+
"version": "2.25.21",
|
|
108
108
|
"packageManager": "yarn@3.1.1"
|
|
109
109
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ComponentStory, Meta } from '@storybook/react'
|
|
2
|
+
|
|
3
|
+
import { appThemeDecorator } from '../../.storybook'
|
|
4
|
+
import { SchemaProperty } from './SchemaProperty'
|
|
5
|
+
|
|
6
|
+
const StorybookEntry: Meta = {
|
|
7
|
+
argTypes: {},
|
|
8
|
+
args: {},
|
|
9
|
+
component: SchemaProperty,
|
|
10
|
+
decorators: [appThemeDecorator],
|
|
11
|
+
parameters: {
|
|
12
|
+
docs: {
|
|
13
|
+
page: null,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
title: 'Schema/SchemaProperty',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const Template: ComponentStory<typeof SchemaProperty> = (args) => <SchemaProperty {...args} />
|
|
20
|
+
|
|
21
|
+
const Default = Template.bind({})
|
|
22
|
+
Default.args = {}
|
|
23
|
+
|
|
24
|
+
const WithVerfiedValue = Template.bind({})
|
|
25
|
+
WithVerfiedValue.args = { value: 'network.xyo.schema' }
|
|
26
|
+
|
|
27
|
+
const WithUnverfiedValue = Template.bind({})
|
|
28
|
+
WithUnverfiedValue.args = { value: 'network.xyo.blahblah' }
|
|
29
|
+
|
|
30
|
+
export { Default, WithUnverfiedValue, WithVerfiedValue }
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line import/no-default-export
|
|
33
|
+
export default StorybookEntry
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import NewReleasesIcon from '@mui/icons-material/NewReleases'
|
|
2
|
+
import OpenInNewIcon from '@mui/icons-material/OpenInNew'
|
|
3
|
+
import VerifiedIcon from '@mui/icons-material/Verified'
|
|
4
|
+
import { IconButton } from '@mui/material'
|
|
5
|
+
import { LinkEx, useAsyncEffect } from '@xylabs/sdk-react'
|
|
6
|
+
import { Property, PropertyProps, PropertyValue } from '@xyo-network/react-property'
|
|
7
|
+
import { XyoSchemaCache, XyoSchemaCacheEntry } from '@xyo-network/utils'
|
|
8
|
+
import { useState } from 'react'
|
|
9
|
+
|
|
10
|
+
export interface SchemaPropertyProps extends PropertyProps {
|
|
11
|
+
value?: string
|
|
12
|
+
viewSchemaUrl?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const useResolveSchema = (schema?: string) => {
|
|
16
|
+
const [entry, setEntry] = useState<XyoSchemaCacheEntry | null>()
|
|
17
|
+
useAsyncEffect(
|
|
18
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
|
+
async (mounted) => {
|
|
20
|
+
if (schema) {
|
|
21
|
+
const entry = await XyoSchemaCache.instance.get(schema)
|
|
22
|
+
if (mounted()) {
|
|
23
|
+
setEntry(entry)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
[schema]
|
|
28
|
+
)
|
|
29
|
+
return entry
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const SchemaProperty: React.FC<SchemaPropertyProps> = ({ value, viewSchemaUrl = 'https://explore.xyo.network/' }) => {
|
|
33
|
+
const resolvedSchema = useResolveSchema(value)
|
|
34
|
+
return (
|
|
35
|
+
<Property flexGrow={1} title="Schema" value={value} tip="Schema sent with the payload">
|
|
36
|
+
{value ? (
|
|
37
|
+
resolvedSchema === null ? (
|
|
38
|
+
<IconButton rel="noopener noreferrer" size="small" target="_blank" href={`${viewSchemaUrl}${value}`}>
|
|
39
|
+
<NewReleasesIcon color="error" fontSize="inherit" />
|
|
40
|
+
</IconButton>
|
|
41
|
+
) : resolvedSchema === undefined ? (
|
|
42
|
+
<IconButton rel="noopener noreferrer" size="small" target="_blank" href={`${viewSchemaUrl}${value}`}>
|
|
43
|
+
<NewReleasesIcon color="disabled" fontSize="inherit" />
|
|
44
|
+
</IconButton>
|
|
45
|
+
) : (
|
|
46
|
+
<IconButton rel="noopener noreferrer" size="small" target="_blank" href={resolvedSchema?.huri?.href ?? ''}>
|
|
47
|
+
<VerifiedIcon color="success" fontSize="inherit" />
|
|
48
|
+
</IconButton>
|
|
49
|
+
)
|
|
50
|
+
) : null}
|
|
51
|
+
{value ? (
|
|
52
|
+
<LinkEx marginX={1} flexGrow={1} alignItems="center" href={`${viewSchemaUrl}${value}`} rel="noopener noreferrer" display="flex">
|
|
53
|
+
<PropertyValue value={value} title="view schema in new window" />
|
|
54
|
+
</LinkEx>
|
|
55
|
+
) : null}
|
|
56
|
+
{value ? (
|
|
57
|
+
<LinkEx marginX={1} alignItems="center" href={`${viewSchemaUrl}${value}`} target="_blank" rel="noopener noreferrer" display="flex">
|
|
58
|
+
<OpenInNewIcon fontSize="inherit" />
|
|
59
|
+
</LinkEx>
|
|
60
|
+
) : null}
|
|
61
|
+
</Property>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SchemaProperty'
|
package/src/components/index.ts
CHANGED