@xyo-network/react-schema 2.23.7
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/LICENSE +165 -0
- package/README.md +69 -0
- package/babel.config.json +5 -0
- package/dist/cjs/components/SelectEx/SchemaSelectEx.d.ts +4 -0
- package/dist/cjs/components/SelectEx/SchemaSelectEx.js +24 -0
- package/dist/cjs/components/SelectEx/SchemaSelectEx.js.map +1 -0
- package/dist/cjs/components/SelectEx/index.d.ts +1 -0
- package/dist/cjs/components/SelectEx/index.js +5 -0
- package/dist/cjs/components/SelectEx/index.js.map +1 -0
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +5 -0
- package/dist/cjs/components/index.js.map +1 -0
- package/dist/cjs/contexts/Schema/Context.d.ts +3 -0
- package/dist/cjs/contexts/Schema/Context.js +6 -0
- package/dist/cjs/contexts/Schema/Context.js.map +1 -0
- package/dist/cjs/contexts/Schema/Hooks/index.d.ts +3 -0
- package/dist/cjs/contexts/Schema/Hooks/index.js +7 -0
- package/dist/cjs/contexts/Schema/Hooks/index.js.map +1 -0
- package/dist/cjs/contexts/Schema/Hooks/useSchemaDefinitions.d.ts +2 -0
- package/dist/cjs/contexts/Schema/Hooks/useSchemaDefinitions.js +27 -0
- package/dist/cjs/contexts/Schema/Hooks/useSchemaDefinitions.js.map +1 -0
- package/dist/cjs/contexts/Schema/Hooks/useSchemaList.d.ts +2 -0
- package/dist/cjs/contexts/Schema/Hooks/useSchemaList.js +26 -0
- package/dist/cjs/contexts/Schema/Hooks/useSchemaList.js.map +1 -0
- package/dist/cjs/contexts/Schema/Hooks/useSchemaStats.d.ts +2 -0
- package/dist/cjs/contexts/Schema/Hooks/useSchemaStats.js +26 -0
- package/dist/cjs/contexts/Schema/Hooks/useSchemaStats.js.map +1 -0
- package/dist/cjs/contexts/Schema/Provider/Memory.d.ts +4 -0
- package/dist/cjs/contexts/Schema/Provider/Memory.js +16 -0
- package/dist/cjs/contexts/Schema/Provider/Memory.js.map +1 -0
- package/dist/cjs/contexts/Schema/Provider/Props.d.ts +4 -0
- package/dist/cjs/contexts/Schema/Provider/Props.js +3 -0
- package/dist/cjs/contexts/Schema/Provider/Props.js.map +1 -0
- package/dist/cjs/contexts/Schema/Provider/Route.d.ts +4 -0
- package/dist/cjs/contexts/Schema/Provider/Route.js +51 -0
- package/dist/cjs/contexts/Schema/Provider/Route.js.map +1 -0
- package/dist/cjs/contexts/Schema/Provider/index.d.ts +3 -0
- package/dist/cjs/contexts/Schema/Provider/index.js +7 -0
- package/dist/cjs/contexts/Schema/Provider/index.js.map +1 -0
- package/dist/cjs/contexts/Schema/State.d.ts +12 -0
- package/dist/cjs/contexts/Schema/State.js +3 -0
- package/dist/cjs/contexts/Schema/State.js.map +1 -0
- package/dist/cjs/contexts/Schema/index.d.ts +5 -0
- package/dist/cjs/contexts/Schema/index.js +9 -0
- package/dist/cjs/contexts/Schema/index.js.map +1 -0
- package/dist/cjs/contexts/Schema/use.d.ts +2 -0
- package/dist/cjs/contexts/Schema/use.js +10 -0
- package/dist/cjs/contexts/Schema/use.js.map +1 -0
- package/dist/cjs/contexts/index.d.ts +1 -0
- package/dist/cjs/contexts/index.js +5 -0
- package/dist/cjs/contexts/index.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/docs.json +695 -0
- package/dist/esm/components/SelectEx/SchemaSelectEx.d.ts +4 -0
- package/dist/esm/components/SelectEx/SchemaSelectEx.js +18 -0
- package/dist/esm/components/SelectEx/SchemaSelectEx.js.map +1 -0
- package/dist/esm/components/SelectEx/index.d.ts +1 -0
- package/dist/esm/components/SelectEx/index.js +2 -0
- package/dist/esm/components/SelectEx/index.js.map +1 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/components/index.js.map +1 -0
- package/dist/esm/contexts/Schema/Context.d.ts +3 -0
- package/dist/esm/contexts/Schema/Context.js +3 -0
- package/dist/esm/contexts/Schema/Context.js.map +1 -0
- package/dist/esm/contexts/Schema/Hooks/index.d.ts +3 -0
- package/dist/esm/contexts/Schema/Hooks/index.js +4 -0
- package/dist/esm/contexts/Schema/Hooks/index.js.map +1 -0
- package/dist/esm/contexts/Schema/Hooks/useSchemaDefinitions.d.ts +2 -0
- package/dist/esm/contexts/Schema/Hooks/useSchemaDefinitions.js +22 -0
- package/dist/esm/contexts/Schema/Hooks/useSchemaDefinitions.js.map +1 -0
- package/dist/esm/contexts/Schema/Hooks/useSchemaList.d.ts +2 -0
- package/dist/esm/contexts/Schema/Hooks/useSchemaList.js +21 -0
- package/dist/esm/contexts/Schema/Hooks/useSchemaList.js.map +1 -0
- package/dist/esm/contexts/Schema/Hooks/useSchemaStats.d.ts +2 -0
- package/dist/esm/contexts/Schema/Hooks/useSchemaStats.js +21 -0
- package/dist/esm/contexts/Schema/Hooks/useSchemaStats.js.map +1 -0
- package/dist/esm/contexts/Schema/Provider/Memory.d.ts +4 -0
- package/dist/esm/contexts/Schema/Provider/Memory.js +10 -0
- package/dist/esm/contexts/Schema/Provider/Memory.js.map +1 -0
- package/dist/esm/contexts/Schema/Provider/Props.d.ts +4 -0
- package/dist/esm/contexts/Schema/Provider/Props.js +2 -0
- package/dist/esm/contexts/Schema/Provider/Props.js.map +1 -0
- package/dist/esm/contexts/Schema/Provider/Route.d.ts +4 -0
- package/dist/esm/contexts/Schema/Provider/Route.js +45 -0
- package/dist/esm/contexts/Schema/Provider/Route.js.map +1 -0
- package/dist/esm/contexts/Schema/Provider/index.d.ts +3 -0
- package/dist/esm/contexts/Schema/Provider/index.js +4 -0
- package/dist/esm/contexts/Schema/Provider/index.js.map +1 -0
- package/dist/esm/contexts/Schema/State.d.ts +12 -0
- package/dist/esm/contexts/Schema/State.js +2 -0
- package/dist/esm/contexts/Schema/State.js.map +1 -0
- package/dist/esm/contexts/Schema/index.d.ts +5 -0
- package/dist/esm/contexts/Schema/index.js +6 -0
- package/dist/esm/contexts/Schema/index.js.map +1 -0
- package/dist/esm/contexts/Schema/use.d.ts +2 -0
- package/dist/esm/contexts/Schema/use.js +6 -0
- package/dist/esm/contexts/Schema/use.js.map +1 -0
- package/dist/esm/contexts/index.d.ts +1 -0
- package/dist/esm/contexts/index.js +2 -0
- package/dist/esm/contexts/index.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +138 -0
- package/src/components/SelectEx/SchemaSelectEx.tsx +39 -0
- package/src/components/SelectEx/index.ts +1 -0
- package/src/components/index.ts +1 -0
- package/src/contexts/Schema/Context.ts +5 -0
- package/src/contexts/Schema/Hooks/index.ts +3 -0
- package/src/contexts/Schema/Hooks/useSchemaDefinitions.tsx +28 -0
- package/src/contexts/Schema/Hooks/useSchemaList.tsx +25 -0
- package/src/contexts/Schema/Hooks/useSchemaStats.tsx +26 -0
- package/src/contexts/Schema/Provider/Memory.tsx +13 -0
- package/src/contexts/Schema/Provider/Props.tsx +4 -0
- package/src/contexts/Schema/Provider/Route.tsx +62 -0
- package/src/contexts/Schema/Provider/index.ts +3 -0
- package/src/contexts/Schema/State.ts +13 -0
- package/src/contexts/Schema/index.ts +5 -0
- package/src/contexts/Schema/use.ts +8 -0
- package/src/contexts/index.ts +1 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WithChildren } from '@xylabs/sdk-react'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { SchemaContext } from '../Context'
|
|
5
|
+
import { useSchemaList } from '../Hooks'
|
|
6
|
+
import { SchemaProviderProps } from './Props'
|
|
7
|
+
|
|
8
|
+
export const SchemaMemoryProvider: React.FC<WithChildren<SchemaProviderProps>> = ({ defaultSchema, knownSchemaList = [], ...props }) => {
|
|
9
|
+
const [schema, setSchema] = useState(defaultSchema)
|
|
10
|
+
const [schemaList, setSchemaList] = useSchemaList(knownSchemaList)
|
|
11
|
+
|
|
12
|
+
return <SchemaContext.Provider value={{ provided: true, schema, schemaList, setSchema, setSchemaList }} {...props} />
|
|
13
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { WithChildren } from '@xylabs/sdk-react'
|
|
2
|
+
import { useCallback, useEffect } from 'react'
|
|
3
|
+
import { useSearchParams } from 'react-router-dom'
|
|
4
|
+
|
|
5
|
+
import { SchemaContext } from '../Context'
|
|
6
|
+
import { useSchema } from '../use'
|
|
7
|
+
import { SchemaMemoryProvider } from './Memory'
|
|
8
|
+
import { SchemaProviderProps } from './Props'
|
|
9
|
+
|
|
10
|
+
const SchemaRouteProviderInner: React.FC<WithChildren> = ({ children }) => {
|
|
11
|
+
const { schema, setSchema, schemaList } = useSchema()
|
|
12
|
+
|
|
13
|
+
const [params, setParams] = useSearchParams()
|
|
14
|
+
|
|
15
|
+
const routeSchema = params.get('schema')
|
|
16
|
+
|
|
17
|
+
//update the network stored in the route
|
|
18
|
+
const setSchemaParam = useCallback(
|
|
19
|
+
(schema?: string) => {
|
|
20
|
+
if (schema) {
|
|
21
|
+
params.set('schema', schema)
|
|
22
|
+
setParams(params, { replace: true })
|
|
23
|
+
setSchema?.(schema)
|
|
24
|
+
} else {
|
|
25
|
+
params.delete('network')
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
[params, setParams, setSchema]
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
//if the network is actively changed, update both memory and route
|
|
32
|
+
const setSchemaLocal = useCallback(
|
|
33
|
+
(schema: string) => {
|
|
34
|
+
setSchemaParam(schema)
|
|
35
|
+
setSchema?.(schema)
|
|
36
|
+
},
|
|
37
|
+
[setSchemaParam, setSchema]
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
//sync memory and route storage of network
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (routeSchema !== schema) {
|
|
43
|
+
if (routeSchema === undefined && schema !== undefined) {
|
|
44
|
+
//if the route does not have a network selected, use what is in the memory context
|
|
45
|
+
setSchemaLocal(schema)
|
|
46
|
+
} else if (routeSchema) {
|
|
47
|
+
//if the route has a selection and it is different from memory, update memory
|
|
48
|
+
setSchema?.(routeSchema)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, [routeSchema, schema, setSchemaParam, setSchema, setSchemaLocal])
|
|
52
|
+
|
|
53
|
+
return <SchemaContext.Provider value={{ provided: true, schema, schemaList, setSchema: setSchemaLocal }}>{children}</SchemaContext.Provider>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const SchemaRouteProvider: React.FC<WithChildren<SchemaProviderProps>> = ({ knownSchemaList, defaultSchema, ...props }) => {
|
|
57
|
+
return (
|
|
58
|
+
<SchemaMemoryProvider knownSchemaList={knownSchemaList} defaultSchema={defaultSchema}>
|
|
59
|
+
<SchemaRouteProviderInner {...props} />
|
|
60
|
+
</SchemaMemoryProvider>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ContextExState } from '@xyo-network/react-shared'
|
|
2
|
+
import { Dispatch } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface SchemaContextState extends ContextExState {
|
|
5
|
+
/** @field The currently selected XYO Schema */
|
|
6
|
+
schema?: string
|
|
7
|
+
/** @field The list of known available schema */
|
|
8
|
+
schemaList?: string[]
|
|
9
|
+
/** @field Function to set the selected Schema */
|
|
10
|
+
setSchema?: Dispatch<string>
|
|
11
|
+
/** @field Function to set the list of known available schema */
|
|
12
|
+
setSchemaList?: Dispatch<string[]>
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useContextEx } from '@xyo-network/react-shared'
|
|
2
|
+
|
|
3
|
+
import { SchemaContext } from './Context'
|
|
4
|
+
import { SchemaContextState } from './State'
|
|
5
|
+
|
|
6
|
+
export const useSchema = (required = false) => {
|
|
7
|
+
return useContextEx<SchemaContextState>(SchemaContext, 'Schema', required)
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Schema'
|
package/src/index.ts
ADDED