@xyo-network/react-payload 2.26.32 → 2.26.35

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.
Files changed (53) hide show
  1. package/README.md +2 -1
  2. package/dist/cjs/components/Details/ValidationDetails/ValidationDetails.js +4 -5
  3. package/dist/cjs/components/Details/ValidationDetails/ValidationDetails.js.map +1 -1
  4. package/dist/cjs/components/Details/ValidationDetails/ValidationDetailsProps.d.ts +0 -1
  5. package/dist/docs.json +10 -1
  6. package/dist/esm/components/Details/ValidationDetails/ValidationDetails.js +2 -3
  7. package/dist/esm/components/Details/ValidationDetails/ValidationDetails.js.map +1 -1
  8. package/dist/esm/components/Details/ValidationDetails/ValidationDetailsProps.d.ts +0 -1
  9. package/package.json +15 -15
  10. package/babel.config.json +0 -5
  11. package/dist/cjs/hooks/usePayload.d.ts +0 -3
  12. package/dist/cjs/hooks/usePayload.js +0 -42
  13. package/dist/cjs/hooks/usePayload.js.map +0 -1
  14. package/dist/esm/hooks/usePayload.d.ts +0 -2
  15. package/dist/esm/hooks/usePayload.js +0 -52
  16. package/dist/esm/hooks/usePayload.js.map +0 -1
  17. package/src/components/Details/DataDetails.tsx +0 -65
  18. package/src/components/Details/Details.stories.tsx +0 -62
  19. package/src/components/Details/Details.tsx +0 -27
  20. package/src/components/Details/HashSourceDetails.tsx +0 -41
  21. package/src/components/Details/JsonDetails.tsx +0 -44
  22. package/src/components/Details/MetaDetails.tsx +0 -38
  23. package/src/components/Details/ValidationDetails/ValidationDetails.stories.tsx +0 -55
  24. package/src/components/Details/ValidationDetails/ValidationDetails.tsx +0 -43
  25. package/src/components/Details/ValidationDetails/ValidationDetailsProps.ts +0 -9
  26. package/src/components/Details/ValidationDetails/index.ts +0 -2
  27. package/src/components/Details/index.ts +0 -5
  28. package/src/components/Table/PayloadTableColumnConfig.ts +0 -28
  29. package/src/components/Table/Table.stories.tsx +0 -43
  30. package/src/components/Table/Table.tsx +0 -60
  31. package/src/components/Table/TableRow.tsx +0 -104
  32. package/src/components/Table/index.ts +0 -3
  33. package/src/components/index.ts +0 -2
  34. package/src/contexts/Payload/Context.ts +0 -5
  35. package/src/contexts/Payload/Provider.tsx +0 -31
  36. package/src/contexts/Payload/State.ts +0 -8
  37. package/src/contexts/Payload/index.ts +0 -4
  38. package/src/contexts/Payload/use.ts +0 -7
  39. package/src/contexts/index.ts +0 -1
  40. package/src/hooks/ResolvePayloadArgs.ts +0 -6
  41. package/src/hooks/index.ts +0 -6
  42. package/src/hooks/lib/FetchHuriHashOptions.ts +0 -3
  43. package/src/hooks/lib/findHuriNetwork.ts +0 -13
  44. package/src/hooks/lib/index.ts +0 -2
  45. package/src/hooks/useGetSchema.stories.tsx +0 -70
  46. package/src/hooks/useGetSchema.tsx +0 -51
  47. package/src/hooks/useHuriHash.stories.tsx +0 -108
  48. package/src/hooks/useHuriHash.tsx +0 -38
  49. package/src/hooks/useLoadPayload.stories.tsx +0 -69
  50. package/src/hooks/useLoadPayload.tsx +0 -60
  51. package/src/hooks/useResolveHuri.tsx +0 -74
  52. package/src/index.ts +0 -3
  53. package/src/types/images.d.ts +0 -5
@@ -1,38 +0,0 @@
1
- import { Huri } from '@xyo-network/payload'
2
- import { useCallback } from 'react'
3
-
4
- import { FetchHuriHashOptions } from './lib'
5
- import { UseHuriOrHash } from './ResolvePayloadArgs'
6
- import { useLoadPayload } from './useLoadPayload'
7
- import { useResolveHuri } from './useResolveHuri'
8
-
9
- /**
10
- * Resolve a hash or a huri regardless of network
11
- */
12
- const useHuriHash = (huriOrHash?: string | Huri, huriUri?: string, options?: FetchHuriHashOptions): UseHuriOrHash => {
13
- const hash = useCallback((huriOrHash?: string | Huri) => {
14
- if (huriOrHash) {
15
- if (typeof huriOrHash === 'string') {
16
- return huriOrHash
17
- }
18
- if (huriOrHash instanceof Huri) {
19
- return huriOrHash.hash
20
- }
21
- }
22
- }, [])
23
-
24
- const providedHash = hash(huriOrHash)
25
-
26
- // Optimistically try to grab the has from the current network and archive
27
- const [payload, notFound, apiError] = useLoadPayload(providedHash)
28
-
29
- // if a huriUri was passed, we can safely override the notFound from the hash only query
30
- const notFoundOverride = huriUri ? true : notFound
31
-
32
- // If payload isn't found, fallback to the huriUri
33
- const [huriPayload, huriPayloadNotFound, huriApiError, networkNotFound] = useResolveHuri(huriUri, notFoundOverride, options)
34
-
35
- return [payload ?? huriPayload, huriPayloadNotFound, apiError ?? huriApiError, networkNotFound]
36
- }
37
-
38
- export { useHuriHash }
@@ -1,69 +0,0 @@
1
- /* eslint-disable import/no-internal-modules */
2
- import { ComponentStory, Meta } from '@storybook/react'
3
- import { ButtonEx } from '@xylabs/react-button'
4
- import { FlexCol } from '@xylabs/react-flexbox'
5
- import { ArchivistApiProvider, useArchivistApi } from '@xyo-network/react-archivist-api'
6
- import { lazy, Suspense, useState } from 'react'
7
-
8
- import { useLoadPayload } from './useLoadPayload'
9
-
10
- const JsonView = lazy(() => import(/* webpackChunkName: "jsonView" */ 'react-json-view'))
11
-
12
- const apiDomain = 'https://beta.api.archivist.xyo.network'
13
- const hash = '5605fabad11b10bb5fb86b309ca0970894eda8f22362dda1a489817723bca992'
14
-
15
- const Wrapper: React.FC<{ hash?: string }> = ({ hash }) => (
16
- <ArchivistApiProvider apiDomain={apiDomain}>
17
- <UsePayloadComponent hash={hash} />
18
- </ArchivistApiProvider>
19
- )
20
-
21
- const UsePayloadComponent: React.FC<{ hash?: string }> = ({ hash }) => {
22
- const { api } = useArchivistApi()
23
- const [trigger, setTrigger] = useState<string>()
24
- const [payload, notFound] = useLoadPayload(trigger)
25
-
26
- return (
27
- <>
28
- {api ? (
29
- <>
30
- <ButtonEx variant="contained" marginBottom={2} onClick={() => setTrigger(hash)}>
31
- Fetch Payload
32
- </ButtonEx>
33
- <ButtonEx variant="contained" onClick={() => setTrigger('foo')}>
34
- Fetch Not Found
35
- </ButtonEx>
36
- </>
37
- ) : null}
38
- <FlexCol my={3}>
39
- <Suspense fallback={<FlexCol busy />}>
40
- {notFound ? 'Not Found' : null}
41
- <JsonView src={payload || {}} />
42
- </Suspense>
43
- </FlexCol>
44
- </>
45
- )
46
- }
47
-
48
- const StorybookEntry: Meta = {
49
- argTypes: {},
50
- component: UsePayloadComponent,
51
- parameters: {
52
- docs: {
53
- page: null,
54
- },
55
- },
56
- title: 'payload/usePayload',
57
- }
58
-
59
- const Template: ComponentStory<typeof UsePayloadComponent> = (props) => {
60
- return <Wrapper {...props} />
61
- }
62
-
63
- const Default = Template.bind({})
64
- Default.args = { hash }
65
-
66
- export { Default }
67
-
68
- // eslint-disable-next-line import/no-default-export
69
- export default StorybookEntry
@@ -1,60 +0,0 @@
1
- import { useAsyncEffect } from '@xylabs/react-shared'
2
- import { XyoApiError } from '@xyo-network/api'
3
- import { XyoPayload } from '@xyo-network/payload'
4
- import { useArchive } from '@xyo-network/react-archive'
5
- import { useArchivistApi } from '@xyo-network/react-archivist-api'
6
- import { useEffect, useState } from 'react'
7
-
8
- import { UsePayload } from './ResolvePayloadArgs'
9
-
10
- // I hate this name, would prefer loadPayload, but need use prefix to make it a 'hook'
11
- export const useLoadPayload = (hash?: string): UsePayload => {
12
- const { api } = useArchivistApi()
13
- const { archive } = useArchive()
14
- const [localHash, setLocalHash] = useState<string>()
15
- const [notFound, setNotFound] = useState<boolean>()
16
- const [apiError, setApiError] = useState<XyoApiError>()
17
- const [payload, setPayload] = useState<XyoPayload>()
18
-
19
- const reset = () => {
20
- setPayload(undefined)
21
- setApiError(undefined)
22
- setNotFound(undefined)
23
- }
24
-
25
- // allow for hash changes to retrigger the api call
26
- useEffect(() => {
27
- if (hash !== localHash) {
28
- setLocalHash(hash)
29
- reset()
30
- }
31
- }, [hash, localHash])
32
-
33
- useAsyncEffect(
34
- // eslint-disable-next-line react-hooks/exhaustive-deps
35
- async (mounted) => {
36
- if (api && localHash && localHash.length > 0 && notFound === undefined) {
37
- reset()
38
- try {
39
- const result = await api?.archive(archive).payload.hash(localHash).get()
40
- if (mounted()) {
41
- if (result?.length) {
42
- setPayload(result[0])
43
- setNotFound(false)
44
- } else if (result?.length === 0) {
45
- setNotFound(true)
46
- setPayload(undefined)
47
- }
48
- }
49
- } catch (e) {
50
- reset()
51
- setNotFound(false)
52
- setApiError(e as XyoApiError)
53
- console.error(e)
54
- }
55
- }
56
- },
57
- [hash, api, archive, payload, notFound, localHash]
58
- )
59
- return [payload, notFound, apiError]
60
- }
@@ -1,74 +0,0 @@
1
- import { useAsyncEffect } from '@xylabs/react-shared'
2
- import { XyoApiError } from '@xyo-network/api'
3
- import { Huri, XyoPayload } from '@xyo-network/payload'
4
- import { useNetwork } from '@xyo-network/react-network'
5
- import { useEffect, useState } from 'react'
6
-
7
- import { FetchHuriHashOptions, findHuriNetwork } from './lib'
8
- import { UseHuriOrHash } from './ResolvePayloadArgs'
9
-
10
- const useResolveHuri = (huriUri?: string, dependentNotFound?: boolean, options?: FetchHuriHashOptions): UseHuriOrHash => {
11
- const { network, networks, setNetwork } = useNetwork()
12
- const [huriPayload, setHuriPayload] = useState<XyoPayload>()
13
- const [huriPayloadNotFound, setHuriPayloadNotFound] = useState<boolean>()
14
- const [huriNetworkNotFound, setHuriNetworkNotFound] = useState<boolean>()
15
- const [huriApiError, setHuriApiError] = useState<XyoApiError>()
16
-
17
- const { changeActiveNetwork } = options ?? {}
18
-
19
- const reset = () => {
20
- setHuriPayload(undefined)
21
- setHuriPayloadNotFound(undefined)
22
- setHuriApiError(undefined)
23
- }
24
-
25
- useEffect(() => {
26
- // Initially, sync local not found with dependent's status
27
- setHuriPayloadNotFound(dependentNotFound)
28
- }, [dependentNotFound])
29
-
30
- useAsyncEffect(
31
- // eslint-disable-next-line react-hooks/exhaustive-deps
32
- async (mounted) => {
33
- // if dependent value is resolved, don't do anything, if not resolved, try to resolve huriUri
34
- if (dependentNotFound && huriUri) {
35
- reset()
36
- const huriInstance = new Huri(huriUri)
37
-
38
- const foundHuriNetwork = findHuriNetwork(huriInstance, networks)
39
-
40
- if (foundHuriNetwork && mounted()) {
41
- if (network !== foundHuriNetwork && changeActiveNetwork) {
42
- setNetwork?.(foundHuriNetwork)
43
- return
44
- }
45
-
46
- try {
47
- const huriPayload = await huriInstance.fetch()
48
- if (mounted()) {
49
- if (huriPayload) {
50
- setHuriPayload(huriPayload)
51
- setHuriPayloadNotFound(false)
52
- } else {
53
- setHuriPayloadNotFound(true)
54
- }
55
- }
56
- } catch (e) {
57
- if (mounted()) {
58
- setHuriPayloadNotFound(false)
59
- setHuriPayload(undefined)
60
- setHuriApiError(e as XyoApiError)
61
- }
62
- }
63
- } else {
64
- setHuriNetworkNotFound(true)
65
- }
66
- }
67
- },
68
- [huriUri, network, networks, dependentNotFound, setNetwork, changeActiveNetwork]
69
- )
70
-
71
- return [huriPayload, huriPayloadNotFound, huriApiError, huriNetworkNotFound]
72
- }
73
-
74
- export { useResolveHuri }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './components'
2
- export * from './contexts'
3
- export * from './hooks'
@@ -1,5 +0,0 @@
1
- declare module '*.png'
2
- declare module '*.jpg'
3
- declare module '*.svg'
4
- declare module '*.gif'
5
- declare module '*.webp'