@xyo-network/react-embed 7.5.7 → 7.5.11
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/embed-card/card/EmbedCardHeader.d.ts.map +1 -1
- package/dist/browser/contexts/EmbedPluginContext/Provider.d.ts.map +1 -1
- package/dist/browser/contexts/PluginPropsContext/Provider.d.ts.map +1 -1
- package/dist/browser/contexts/RefreshPayloadContext/Provider.d.ts.map +1 -1
- package/dist/browser/contexts/ResolvePayloadContext/Provider.d.ts.map +1 -1
- package/dist/browser/contexts/ValidatePayloadContext/Provider.d.ts.map +1 -1
- package/dist/browser/index.mjs +453 -391
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +176 -42
- package/src/components/EmbedPlugin.tsx +0 -66
- package/src/components/EmbedResolver.tsx +0 -17
- package/src/components/controls/EmbedFormControl.tsx +0 -20
- package/src/components/controls/ListModeSelect.tsx +0 -43
- package/src/components/controls/RenderSelect.tsx +0 -27
- package/src/components/controls/index.ts +0 -3
- package/src/components/embed-card/EmbedCardResolver.tsx +0 -38
- package/src/components/embed-card/EmbedPluginCard.tsx +0 -71
- package/src/components/embed-card/card/BusyCard.tsx +0 -43
- package/src/components/embed-card/card/EmbedCardHeader.tsx +0 -57
- package/src/components/embed-card/card/EmbedPluginCard.tsx +0 -47
- package/src/components/embed-card/card/index.ts +0 -3
- package/src/components/embed-card/error-handling/EmbedCardApiErrorRenderer.tsx +0 -29
- package/src/components/embed-card/error-handling/EmbedErrorCard.tsx +0 -60
- package/src/components/embed-card/error-handling/index.ts +0 -2
- package/src/components/embed-card/index.ts +0 -2
- package/src/components/embed-card/menu/EmbedMenu.tsx +0 -37
- package/src/components/embed-card/menu/JsonMenuItem.tsx +0 -28
- package/src/components/embed-card/menu/index.ts +0 -1
- package/src/components/index.ts +0 -2
- package/src/components/stories/XyoEmbedPlugin.examples.stories.tsx +0 -28
- package/src/components/stories/XyoEmbedPlugin.states.stories.tsx +0 -93
- package/src/components/stories/storyPayload.ts +0 -71
- package/src/components/stories/storyShared.tsx +0 -19
- package/src/components/stories/xyoEmbedStoryBase.ts +0 -9
- package/src/components/validation-alerts/ValidatePayload.tsx +0 -26
- package/src/components/validation-alerts/ValidatePlugins.tsx +0 -22
- package/src/components/validation-alerts/index.ts +0 -2
- package/src/contexts/EmbedPluginContext/Context.ts +0 -5
- package/src/contexts/EmbedPluginContext/Provider.tsx +0 -36
- package/src/contexts/EmbedPluginContext/State.ts +0 -37
- package/src/contexts/EmbedPluginContext/index.ts +0 -4
- package/src/contexts/EmbedPluginContext/use.ts +0 -5
- package/src/contexts/PluginPropsContext/Provider.tsx +0 -31
- package/src/contexts/PluginPropsContext/context.ts +0 -5
- package/src/contexts/PluginPropsContext/index.ts +0 -4
- package/src/contexts/PluginPropsContext/state.ts +0 -9
- package/src/contexts/PluginPropsContext/use.ts +0 -5
- package/src/contexts/RefreshPayloadContext/Context.ts +0 -5
- package/src/contexts/RefreshPayloadContext/Provider.tsx +0 -24
- package/src/contexts/RefreshPayloadContext/State.ts +0 -8
- package/src/contexts/RefreshPayloadContext/index.ts +0 -3
- package/src/contexts/RefreshPayloadContext/use.ts +0 -5
- package/src/contexts/ResolvePayloadContext/Context.ts +0 -5
- package/src/contexts/ResolvePayloadContext/Provider.tsx +0 -76
- package/src/contexts/ResolvePayloadContext/State.ts +0 -13
- package/src/contexts/ResolvePayloadContext/index.ts +0 -4
- package/src/contexts/ResolvePayloadContext/use.ts +0 -5
- package/src/contexts/ValidatePayloadContext/Context.ts +0 -5
- package/src/contexts/ValidatePayloadContext/Provider.stories.tsx +0 -87
- package/src/contexts/ValidatePayloadContext/Provider.tsx +0 -49
- package/src/contexts/ValidatePayloadContext/State.ts +0 -7
- package/src/contexts/ValidatePayloadContext/index.ts +0 -3
- package/src/contexts/ValidatePayloadContext/use.ts +0 -5
- package/src/contexts/index.ts +0 -5
- package/src/global.d.ts +0 -1
- package/src/index.ts +0 -3
- package/src/types/EmbedPluginProps.ts +0 -11
- package/src/types/index.ts +0 -1
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { asSchema } from '@xyo-network/payload-model'
|
|
2
|
-
|
|
3
|
-
export const payloadData = {
|
|
4
|
-
assets: {
|
|
5
|
-
ada: {
|
|
6
|
-
value: {
|
|
7
|
-
btc: '0.00002192', eth: '0.00031141', eur: '0.491867', usd: '0.502045',
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
btc: {
|
|
11
|
-
value: {
|
|
12
|
-
btc: '1', eth: '14.213346', eur: '22450', usd: '22914',
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
busd: {
|
|
16
|
-
value: {
|
|
17
|
-
btc: '0.00004369', eth: '0.00062074', eur: '0.980451', usd: '1.001',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
dai: { value: { usdc: '1.00004', xyo: '114.394' } },
|
|
21
|
-
doge: {
|
|
22
|
-
value: {
|
|
23
|
-
btc: '0.00000293', eth: '0.00004157', eur: '0.065655', usd: '0.067013',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
dot: {
|
|
27
|
-
value: {
|
|
28
|
-
btc: '0.00035508', eth: '0.00504454', eur: '7.97', usd: '8.13',
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
eth: {
|
|
32
|
-
value: {
|
|
33
|
-
btc: '0.0703878', eth: '1', eur: '1579.47', usd: '1612.16',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
frax: { value: { usdc: '0.999738' } },
|
|
37
|
-
link: { value: { xyo: '837.731' } },
|
|
38
|
-
sol: {
|
|
39
|
-
value: {
|
|
40
|
-
btc: '0.00169369', eth: '0.02406215', eur: '38.01', usd: '38.79',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
usdc: {
|
|
44
|
-
value: {
|
|
45
|
-
btc: '0.0000436965', dai: '0.999963', eth: '0.0006204464999999999', eur: '0.979419', frax: '1.00026', usd: '0.999732',
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
usdt: {
|
|
49
|
-
value: {
|
|
50
|
-
btc: '0.00004367', eth: '0.0006204', eur: '0.979881', usd: '1.001', usdc: '1.00022', xyo: '113.28',
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
wbtc: {
|
|
54
|
-
value: {
|
|
55
|
-
btc: '0.99903669', eth: '14.2015745', eur: '22418', usd: '22882', usdc: '22860.8', xyo: '2617950',
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
weth: {
|
|
59
|
-
value: {
|
|
60
|
-
btc: '0.0703735', usdc: '1610.82', xyo: '186652',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
xyo: {
|
|
64
|
-
value: {
|
|
65
|
-
btc: '3.79226e-7', dai: '0.00874169', eth: '0.000005353785', eur: '0.00844792', link: '0.0011937', usd: '0.00872519',
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
schema: asSchema('network.xyo.crypto.asset', true),
|
|
70
|
-
timestamp: 1_659_625_815_232,
|
|
71
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { StoryFn } from '@storybook/react-vite'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import { BrowserRouter } from 'react-router-dom'
|
|
4
|
-
|
|
5
|
-
import type { PluginProps } from '../../contexts/index.ts'
|
|
6
|
-
import { PluginPropsProvider } from '../../contexts/index.ts'
|
|
7
|
-
import { ApiEmbedPluginCard } from '../embed-card/index.ts'
|
|
8
|
-
|
|
9
|
-
const pluginProps: PluginProps = { foo: true }
|
|
10
|
-
|
|
11
|
-
export const Template: StoryFn<typeof ApiEmbedPluginCard> = (args) => {
|
|
12
|
-
return (
|
|
13
|
-
<PluginPropsProvider pluginProps={pluginProps}>
|
|
14
|
-
<BrowserRouter>
|
|
15
|
-
<ApiEmbedPluginCard {...args} />
|
|
16
|
-
</BrowserRouter>
|
|
17
|
-
</PluginPropsProvider>
|
|
18
|
-
)
|
|
19
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { AlertProps } from '@mui/material'
|
|
2
|
-
import { Alert } from '@mui/material'
|
|
3
|
-
import type { PropsWithChildren } from 'react'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
|
|
6
|
-
import { useValidatePayload } from '../../contexts/index.ts'
|
|
7
|
-
|
|
8
|
-
export const ValidatePayloadAlert: React.FC<PropsWithChildren<AlertProps>> = ({ children, ...props }) => {
|
|
9
|
-
const {
|
|
10
|
-
validPayload, enabled, schema,
|
|
11
|
-
} = useValidatePayload()
|
|
12
|
-
|
|
13
|
-
if (enabled && validPayload === false) {
|
|
14
|
-
return (
|
|
15
|
-
<Alert severity="error" title="Invalid Payload!" {...props}>
|
|
16
|
-
Payload schema claimed to be
|
|
17
|
-
{' '}
|
|
18
|
-
{schema}
|
|
19
|
-
{' '}
|
|
20
|
-
but failed to validate.
|
|
21
|
-
</Alert>
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return <>{children}</>
|
|
26
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { AlertProps } from '@mui/material'
|
|
2
|
-
import { Alert, AlertTitle } from '@mui/material'
|
|
3
|
-
import type { PropsWithChildren } from 'react'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
|
|
6
|
-
import { useEmbedPluginState, useResolvePayload } from '../../contexts/index.ts'
|
|
7
|
-
|
|
8
|
-
export const ValidatePluginsAlert: React.FC<PropsWithChildren<AlertProps>> = ({ children, ...props }) => {
|
|
9
|
-
const { payload } = useResolvePayload()
|
|
10
|
-
const { plugins } = useEmbedPluginState()
|
|
11
|
-
|
|
12
|
-
if (payload && plugins?.length === 0) {
|
|
13
|
-
return (
|
|
14
|
-
<Alert severity="warning" {...props}>
|
|
15
|
-
<AlertTitle>Missing plugins!</AlertTitle>
|
|
16
|
-
Payload found but no plugins were present.
|
|
17
|
-
</Alert>
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return <>{children}</>
|
|
22
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useResetState } from '@xylabs/react-hooks'
|
|
2
|
-
import type { PropsWithChildren } from 'react'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
|
|
5
|
-
import { EmbedPluginContext } from './Context.ts'
|
|
6
|
-
import type { EmbedPluginBase } from './State.ts'
|
|
7
|
-
|
|
8
|
-
export type EmbedPluginProviderProps = EmbedPluginBase
|
|
9
|
-
|
|
10
|
-
/** Expose passed embed plugin props via context */
|
|
11
|
-
export const EmbedPluginProvider: React.FC<PropsWithChildren<EmbedPluginProviderProps>> = ({
|
|
12
|
-
children,
|
|
13
|
-
refreshTitle,
|
|
14
|
-
timestampLabel,
|
|
15
|
-
hideElementsConfig,
|
|
16
|
-
plugins,
|
|
17
|
-
embedPluginConfig,
|
|
18
|
-
}) => {
|
|
19
|
-
const [activePlugin, setActivePlugin] = useResetState(plugins ? plugins[0] : undefined)
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<EmbedPluginContext
|
|
23
|
-
value={{
|
|
24
|
-
activePlugin,
|
|
25
|
-
embedPluginConfig,
|
|
26
|
-
hideElementsConfig,
|
|
27
|
-
provided: true,
|
|
28
|
-
refreshTitle,
|
|
29
|
-
setActivePlugin,
|
|
30
|
-
timestampLabel,
|
|
31
|
-
}}
|
|
32
|
-
>
|
|
33
|
-
{children}
|
|
34
|
-
</EmbedPluginContext>
|
|
35
|
-
)
|
|
36
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { ContextExState } from '@xylabs/react-shared'
|
|
2
|
-
import type { PayloadRenderPlugin } from '@xyo-network/react-payload-plugin'
|
|
3
|
-
import type { ListMode } from '@xyo-network/react-shared'
|
|
4
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
5
|
-
|
|
6
|
-
export interface EmbedPluginVisibilityConfig {
|
|
7
|
-
hideAvatar?: boolean
|
|
8
|
-
hideCardActions?: boolean
|
|
9
|
-
hideCardHeader?: boolean
|
|
10
|
-
hideErrorDetails?: boolean
|
|
11
|
-
hideRefreshButton?: boolean
|
|
12
|
-
hideTimestamp?: boolean
|
|
13
|
-
hideTitle?: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Extend for custom plugin configuration
|
|
18
|
-
*/
|
|
19
|
-
export interface PluginConfig {
|
|
20
|
-
listMode?: ListMode
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface EmbedPluginBase {
|
|
24
|
-
/** EmbedPlugin component configuration */
|
|
25
|
-
embedPluginConfig?: PluginConfig
|
|
26
|
-
hideElementsConfig?: EmbedPluginVisibilityConfig
|
|
27
|
-
/** @deprecated use huriPayload */
|
|
28
|
-
huri?: string
|
|
29
|
-
plugins?: PayloadRenderPlugin[]
|
|
30
|
-
refreshTitle?: string
|
|
31
|
-
timestampLabel?: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type EmbedPluginState = ContextExState<EmbedPluginBase & {
|
|
35
|
-
activePlugin?: PayloadRenderPlugin
|
|
36
|
-
setActivePlugin?: Dispatch<SetStateAction<PayloadRenderPlugin | undefined>>
|
|
37
|
-
}>
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { PropsWithChildren } from 'react'
|
|
2
|
-
import React, {
|
|
3
|
-
useEffect, useMemo, useState,
|
|
4
|
-
} from 'react'
|
|
5
|
-
|
|
6
|
-
import { PluginPropsContext } from './context.ts'
|
|
7
|
-
import type { PluginProps, PluginPropsState } from './state.ts'
|
|
8
|
-
|
|
9
|
-
export interface PluginPropsProviderProps extends PropsWithChildren {
|
|
10
|
-
pluginProps?: PluginProps
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const PluginPropsProvider: React.FC<PluginPropsProviderProps> = ({ children, pluginProps: pluginPropsProp }) => {
|
|
14
|
-
const [pluginProps, setPluginProps] = useState<PluginProps | undefined>(pluginPropsProp)
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
// needs to be in useEffect since we are in a provider
|
|
18
|
-
setPluginProps(pluginPropsProp)
|
|
19
|
-
}, [pluginPropsProp])
|
|
20
|
-
|
|
21
|
-
const value: PluginPropsState = useMemo(() => ({
|
|
22
|
-
pluginProps,
|
|
23
|
-
provided: true,
|
|
24
|
-
}), [pluginProps])
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<PluginPropsContext value={value}>
|
|
28
|
-
{children}
|
|
29
|
-
</PluginPropsContext>
|
|
30
|
-
)
|
|
31
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ContextExState } from '@xylabs/react-shared'
|
|
2
|
-
|
|
3
|
-
export type PluginProps = Record<string, unknown>
|
|
4
|
-
|
|
5
|
-
export interface PluginPropsStateFields {
|
|
6
|
-
pluginProps: PluginProps | undefined
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type PluginPropsState = ContextExState<PluginPropsStateFields>
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { PropsWithChildren } from 'react'
|
|
2
|
-
import React, { useState } from 'react'
|
|
3
|
-
|
|
4
|
-
import { RefreshPayloadContext } from './Context.ts'
|
|
5
|
-
|
|
6
|
-
export interface RefreshPayloadProps {
|
|
7
|
-
onRefresh?: () => void
|
|
8
|
-
refreshPayload?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const RefreshPayloadProvider: React.FC<PropsWithChildren<RefreshPayloadProps>> = ({
|
|
12
|
-
children, onRefresh, refreshPayload,
|
|
13
|
-
}) => {
|
|
14
|
-
const [localRefreshPayload, setLocalRefreshPayload] = useState(refreshPayload)
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<RefreshPayloadContext value={{
|
|
18
|
-
onRefresh, provided: true, refreshPayload: localRefreshPayload, setRefreshPayload: setLocalRefreshPayload,
|
|
19
|
-
}}
|
|
20
|
-
>
|
|
21
|
-
{children}
|
|
22
|
-
</RefreshPayloadContext>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ContextExState } from '@xylabs/react-shared'
|
|
2
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
3
|
-
|
|
4
|
-
export type RefreshPayloadState = ContextExState<{
|
|
5
|
-
onRefresh?: () => void
|
|
6
|
-
refreshPayload?: boolean
|
|
7
|
-
setRefreshPayload?: Dispatch<SetStateAction<boolean | undefined>>
|
|
8
|
-
}>
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
2
|
-
import { delay, isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import { Huri } from '@xyo-network/huri'
|
|
4
|
-
import type {
|
|
5
|
-
ModuleError, Payload, WithSources,
|
|
6
|
-
} from '@xyo-network/payload-model'
|
|
7
|
-
import { ModuleErrorSchema } from '@xyo-network/payload-model'
|
|
8
|
-
import type { PropsWithChildren } from 'react'
|
|
9
|
-
import React, { useEffect, useState } from 'react'
|
|
10
|
-
|
|
11
|
-
import { useRefreshPayload } from '../RefreshPayloadContext/index.ts'
|
|
12
|
-
import { ResolvePayloadContext } from './Context.ts'
|
|
13
|
-
import type { ResolvePayloadState } from './State.ts'
|
|
14
|
-
|
|
15
|
-
export type ResolvePayloadProviderProps = Omit<ResolvePayloadState, 'provided'>
|
|
16
|
-
|
|
17
|
-
export const ResolvePayloadProvider: React.FC<PropsWithChildren<ResolvePayloadProviderProps>> = ({ children, huriPayload }) => {
|
|
18
|
-
const [payload, setPayload] = useState<Payload>()
|
|
19
|
-
const [huri, setHuri] = useState<string>()
|
|
20
|
-
const {
|
|
21
|
-
refreshPayload, setRefreshPayload, onRefresh,
|
|
22
|
-
} = useRefreshPayload()
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
26
|
-
typeof huriPayload === 'string' ? setHuri(huriPayload) : undefined
|
|
27
|
-
if (typeof huriPayload === 'object') {
|
|
28
|
-
setPayload(huriPayload)
|
|
29
|
-
setRefreshPayload?.(true)
|
|
30
|
-
}
|
|
31
|
-
}, [huriPayload, setRefreshPayload])
|
|
32
|
-
|
|
33
|
-
const [notFound, setNotFound] = useState<boolean>()
|
|
34
|
-
const [huriError, setHuriError] = useState<WithSources<ModuleError>>()
|
|
35
|
-
|
|
36
|
-
useAsyncEffect(
|
|
37
|
-
async (mounted) => {
|
|
38
|
-
if (isDefined(huri) && !refreshPayload) {
|
|
39
|
-
try {
|
|
40
|
-
const huriInstance = new Huri(huri)
|
|
41
|
-
const result = await huriInstance.fetch()
|
|
42
|
-
// ensure the busy state can stay for a moment to avoid flashing too quickly
|
|
43
|
-
await delay(500)
|
|
44
|
-
|
|
45
|
-
if (mounted()) {
|
|
46
|
-
setNotFound(result === null)
|
|
47
|
-
setPayload(result)
|
|
48
|
-
setRefreshPayload?.(true)
|
|
49
|
-
}
|
|
50
|
-
} catch (e) {
|
|
51
|
-
const error = e as Error
|
|
52
|
-
setHuriError({
|
|
53
|
-
message: error.message, schema: ModuleErrorSchema, $sources: [],
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
[huri, payload, refreshPayload, setRefreshPayload],
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
const refreshHuri = () => {
|
|
62
|
-
onRefresh?.()
|
|
63
|
-
if (isDefined(huri)) {
|
|
64
|
-
setRefreshPayload?.(false)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<ResolvePayloadContext value={{
|
|
70
|
-
huri, huriError, notFound, payload, provided: true, refreshHuri, setPayload,
|
|
71
|
-
}}
|
|
72
|
-
>
|
|
73
|
-
{children}
|
|
74
|
-
</ResolvePayloadContext>
|
|
75
|
-
)
|
|
76
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ContextExState } from '@xylabs/react-shared'
|
|
2
|
-
import type { ModuleError, Payload } from '@xyo-network/payload-model'
|
|
3
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
4
|
-
|
|
5
|
-
export type ResolvePayloadState = ContextExState<{
|
|
6
|
-
huri?: string
|
|
7
|
-
huriError?: ModuleError
|
|
8
|
-
huriPayload?: string | Payload
|
|
9
|
-
notFound?: boolean
|
|
10
|
-
payload?: Payload
|
|
11
|
-
refreshHuri?: () => void
|
|
12
|
-
setPayload?: Dispatch<SetStateAction<Payload | undefined>>
|
|
13
|
-
}>
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { Typography } from '@mui/material'
|
|
2
|
-
import type {
|
|
3
|
-
Decorator, Meta, StoryFn,
|
|
4
|
-
} from '@storybook/react-vite'
|
|
5
|
-
import { asSchema } from '@xyo-network/payload-model'
|
|
6
|
-
import React from 'react'
|
|
7
|
-
|
|
8
|
-
import type { EmbedPluginState } from '../EmbedPluginContext/index.ts'
|
|
9
|
-
import { EmbedPluginContext } from '../EmbedPluginContext/index.ts'
|
|
10
|
-
import { RefreshPayloadProvider } from '../RefreshPayloadContext/index.ts'
|
|
11
|
-
import type { ResolvePayloadState } from '../ResolvePayloadContext/index.ts'
|
|
12
|
-
import { ResolvePayloadContext } from '../ResolvePayloadContext/index.ts'
|
|
13
|
-
import type { ValidatePayloadProviderProps } from './Provider.tsx'
|
|
14
|
-
import { ValidatePayloadProvider } from './Provider.tsx'
|
|
15
|
-
import { useValidatePayload } from './use.ts'
|
|
16
|
-
|
|
17
|
-
const EmbedDecorator: Decorator<ValidatePayloadProviderPropsEx> = (Story, { args }) => {
|
|
18
|
-
const {
|
|
19
|
-
xyoEmbedPluginContext, resolvePayloadContext, ...props
|
|
20
|
-
} = args
|
|
21
|
-
console.log(resolvePayloadContext)
|
|
22
|
-
if (resolvePayloadContext.provided && xyoEmbedPluginContext.provided) {
|
|
23
|
-
return (
|
|
24
|
-
<RefreshPayloadProvider>
|
|
25
|
-
<ResolvePayloadContext value={resolvePayloadContext}>
|
|
26
|
-
<EmbedPluginContext value={xyoEmbedPluginContext}>
|
|
27
|
-
<Story {...props} />
|
|
28
|
-
</EmbedPluginContext>
|
|
29
|
-
</ResolvePayloadContext>
|
|
30
|
-
</RefreshPayloadProvider>
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
return <></>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const StorybookEntry: Meta<ValidatePayloadProviderPropsEx> = {
|
|
37
|
-
component: ValidatePayloadProvider,
|
|
38
|
-
decorators: [EmbedDecorator],
|
|
39
|
-
title: 'embed/ValidatePayloadProvider',
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const ValidatePayloadState = () => {
|
|
43
|
-
const state = useValidatePayload()
|
|
44
|
-
return <pre>{JSON.stringify(state, null, 2)}</pre>
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface ValidatePayloadProviderPropsEx extends ValidatePayloadProviderProps {
|
|
48
|
-
resolvePayloadContext: ResolvePayloadState
|
|
49
|
-
xyoEmbedPluginContext: EmbedPluginState
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const Template: StoryFn<React.FC<ValidatePayloadProviderPropsEx>> = (props) => {
|
|
53
|
-
return (
|
|
54
|
-
<ValidatePayloadProvider {...props}>
|
|
55
|
-
<Typography>State:</Typography>
|
|
56
|
-
<ValidatePayloadState />
|
|
57
|
-
<Typography>Children</Typography>
|
|
58
|
-
</ValidatePayloadProvider>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const InvalidPayload = { schema: asSchema('network.xyo.schema', true) }
|
|
63
|
-
const ValidPayload = { definition: { $id: 'test.schema' }, schema: asSchema('network.xyo.schema', true) }
|
|
64
|
-
const stubProviderDefaultValue = { provided: true }
|
|
65
|
-
|
|
66
|
-
const Default = Template.bind({})
|
|
67
|
-
Default.args = { resolvePayloadContext: stubProviderDefaultValue, xyoEmbedPluginContext: stubProviderDefaultValue }
|
|
68
|
-
|
|
69
|
-
const ValidationSucceeded = Template.bind({})
|
|
70
|
-
ValidationSucceeded.args = {
|
|
71
|
-
enabled: true,
|
|
72
|
-
resolvePayloadContext: { payload: ValidPayload, ...stubProviderDefaultValue } as ResolvePayloadState,
|
|
73
|
-
xyoEmbedPluginContext: stubProviderDefaultValue,
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const ValidationFailed = Template.bind({})
|
|
77
|
-
ValidationFailed.args = {
|
|
78
|
-
enabled: true,
|
|
79
|
-
resolvePayloadContext: { payload: InvalidPayload, ...stubProviderDefaultValue } as ResolvePayloadState,
|
|
80
|
-
xyoEmbedPluginContext: stubProviderDefaultValue,
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export {
|
|
84
|
-
Default, ValidationFailed, ValidationSucceeded,
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export default StorybookEntry
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Chip } from '@mui/material'
|
|
2
|
-
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
3
|
-
import type { SchemaNameToValidatorMap } from '@xyo-network/schema-cache'
|
|
4
|
-
import { SchemaCache } from '@xyo-network/schema-cache'
|
|
5
|
-
import type { PropsWithChildren } from 'react'
|
|
6
|
-
import React, { useState } from 'react'
|
|
7
|
-
|
|
8
|
-
import { useResolvePayload } from '../ResolvePayloadContext/index.ts'
|
|
9
|
-
import { ValidatePayloadContext } from './Context.ts'
|
|
10
|
-
|
|
11
|
-
export interface ValidatePayloadProviderProps {
|
|
12
|
-
// Opt-in flag to validate payloads for the plugin(s)
|
|
13
|
-
enabled?: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const ValidatePayloadProvider: React.FC<PropsWithChildren<ValidatePayloadProviderProps>> = ({ children, enabled = false }) => {
|
|
17
|
-
const { payload } = useResolvePayload()
|
|
18
|
-
const [initialized, setInitialized] = useState(false)
|
|
19
|
-
const [valid, setValid] = useState<boolean>()
|
|
20
|
-
|
|
21
|
-
useAsyncEffect(
|
|
22
|
-
async () => {
|
|
23
|
-
if (payload && enabled) {
|
|
24
|
-
await SchemaCache.instance.get(payload.schema)
|
|
25
|
-
|
|
26
|
-
const possibleKnownSchema = payload.schema as keyof SchemaNameToValidatorMap
|
|
27
|
-
|
|
28
|
-
if (SchemaCache.instance.validators[possibleKnownSchema]) {
|
|
29
|
-
const validator = SchemaCache.instance.validators[possibleKnownSchema]
|
|
30
|
-
// TODO: Fix Types
|
|
31
|
-
// setValid(validator?.(payload))
|
|
32
|
-
}
|
|
33
|
-
setInitialized(true)
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
[payload, enabled],
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<ValidatePayloadContext value={{
|
|
41
|
-
enabled, provided: true, schema: payload?.schema, validPayload: valid,
|
|
42
|
-
}}
|
|
43
|
-
>
|
|
44
|
-
{enabled
|
|
45
|
-
? <>{initialized ? children : <Chip label="Validating Payload..." />}</>
|
|
46
|
-
: children}
|
|
47
|
-
</ValidatePayloadContext>
|
|
48
|
-
)
|
|
49
|
-
}
|
package/src/contexts/index.ts
DELETED
package/src/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@mui/material/themeCssVarsAugmentation'
|
package/src/index.ts
DELETED