@xyo-network/react-schema 2.64.9 → 2.65.0

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 (160) hide show
  1. package/dist/browser/hooks/useGetSchema.d.cts +3 -3
  2. package/dist/browser/hooks/useGetSchema.d.mts +3 -3
  3. package/dist/browser/hooks/useGetSchema.d.ts +3 -3
  4. package/dist/node/hooks/useGetSchema.d.cts +3 -3
  5. package/dist/node/hooks/useGetSchema.d.mts +3 -3
  6. package/dist/node/hooks/useGetSchema.d.ts +3 -3
  7. package/package.json +26 -26
  8. package/dist/browser/components/Property/SchemaProperty.cjs +0 -76
  9. package/dist/browser/components/Property/SchemaProperty.cjs.map +0 -1
  10. package/dist/browser/components/Property/SchemaProperty.js +0 -55
  11. package/dist/browser/components/Property/SchemaProperty.js.map +0 -1
  12. package/dist/browser/components/Property/index.cjs +0 -78
  13. package/dist/browser/components/Property/index.cjs.map +0 -1
  14. package/dist/browser/components/Property/index.js +0 -55
  15. package/dist/browser/components/Property/index.js.map +0 -1
  16. package/dist/browser/components/SelectEx/SchemaSelectEx.cjs +0 -68
  17. package/dist/browser/components/SelectEx/SchemaSelectEx.cjs.map +0 -1
  18. package/dist/browser/components/SelectEx/SchemaSelectEx.js +0 -47
  19. package/dist/browser/components/SelectEx/SchemaSelectEx.js.map +0 -1
  20. package/dist/browser/components/SelectEx/index.cjs +0 -70
  21. package/dist/browser/components/SelectEx/index.cjs.map +0 -1
  22. package/dist/browser/components/SelectEx/index.js +0 -47
  23. package/dist/browser/components/SelectEx/index.js.map +0 -1
  24. package/dist/browser/components/index.cjs +0 -123
  25. package/dist/browser/components/index.cjs.map +0 -1
  26. package/dist/browser/components/index.js +0 -100
  27. package/dist/browser/components/index.js.map +0 -1
  28. package/dist/browser/contexts/Schema/Context.cjs +0 -28
  29. package/dist/browser/contexts/Schema/Context.cjs.map +0 -1
  30. package/dist/browser/contexts/Schema/Context.js +0 -7
  31. package/dist/browser/contexts/Schema/Context.js.map +0 -1
  32. package/dist/browser/contexts/Schema/Provider/Memory.cjs +0 -94
  33. package/dist/browser/contexts/Schema/Provider/Memory.cjs.map +0 -1
  34. package/dist/browser/contexts/Schema/Provider/Memory.js +0 -73
  35. package/dist/browser/contexts/Schema/Provider/Memory.js.map +0 -1
  36. package/dist/browser/contexts/Schema/Provider/Props.cjs +0 -19
  37. package/dist/browser/contexts/Schema/Provider/Props.cjs.map +0 -1
  38. package/dist/browser/contexts/Schema/Provider/Props.js +0 -1
  39. package/dist/browser/contexts/Schema/Provider/Props.js.map +0 -1
  40. package/dist/browser/contexts/Schema/Provider/Route.cjs +0 -144
  41. package/dist/browser/contexts/Schema/Provider/Route.cjs.map +0 -1
  42. package/dist/browser/contexts/Schema/Provider/Route.js +0 -123
  43. package/dist/browser/contexts/Schema/Provider/Route.js.map +0 -1
  44. package/dist/browser/contexts/Schema/Provider/index.cjs +0 -147
  45. package/dist/browser/contexts/Schema/Provider/index.cjs.map +0 -1
  46. package/dist/browser/contexts/Schema/Provider/index.js +0 -124
  47. package/dist/browser/contexts/Schema/Provider/index.js.map +0 -1
  48. package/dist/browser/contexts/Schema/State.cjs +0 -19
  49. package/dist/browser/contexts/Schema/State.cjs.map +0 -1
  50. package/dist/browser/contexts/Schema/State.js +0 -1
  51. package/dist/browser/contexts/Schema/State.js.map +0 -1
  52. package/dist/browser/contexts/Schema/index.cjs +0 -149
  53. package/dist/browser/contexts/Schema/index.cjs.map +0 -1
  54. package/dist/browser/contexts/Schema/index.js +0 -126
  55. package/dist/browser/contexts/Schema/index.js.map +0 -1
  56. package/dist/browser/contexts/Schema/use.cjs +0 -36
  57. package/dist/browser/contexts/Schema/use.cjs.map +0 -1
  58. package/dist/browser/contexts/Schema/use.js +0 -15
  59. package/dist/browser/contexts/Schema/use.js.map +0 -1
  60. package/dist/browser/contexts/index.cjs +0 -149
  61. package/dist/browser/contexts/index.cjs.map +0 -1
  62. package/dist/browser/contexts/index.js +0 -126
  63. package/dist/browser/contexts/index.js.map +0 -1
  64. package/dist/browser/hooks/index.cjs +0 -189
  65. package/dist/browser/hooks/index.cjs.map +0 -1
  66. package/dist/browser/hooks/index.js +0 -166
  67. package/dist/browser/hooks/index.js.map +0 -1
  68. package/dist/browser/hooks/useGetSchema.cjs +0 -69
  69. package/dist/browser/hooks/useGetSchema.cjs.map +0 -1
  70. package/dist/browser/hooks/useGetSchema.js +0 -48
  71. package/dist/browser/hooks/useGetSchema.js.map +0 -1
  72. package/dist/browser/hooks/useSchemaDefinitions.cjs +0 -47
  73. package/dist/browser/hooks/useSchemaDefinitions.cjs.map +0 -1
  74. package/dist/browser/hooks/useSchemaDefinitions.js +0 -26
  75. package/dist/browser/hooks/useSchemaDefinitions.js.map +0 -1
  76. package/dist/browser/hooks/useSchemaList.cjs +0 -69
  77. package/dist/browser/hooks/useSchemaList.cjs.map +0 -1
  78. package/dist/browser/hooks/useSchemaList.js +0 -48
  79. package/dist/browser/hooks/useSchemaList.js.map +0 -1
  80. package/dist/browser/hooks/useSchemaStats.cjs +0 -71
  81. package/dist/browser/hooks/useSchemaStats.cjs.map +0 -1
  82. package/dist/browser/hooks/useSchemaStats.js +0 -50
  83. package/dist/browser/hooks/useSchemaStats.js.map +0 -1
  84. package/dist/docs.json +0 -2071
  85. package/dist/node/components/Property/SchemaProperty.cjs +0 -81
  86. package/dist/node/components/Property/SchemaProperty.cjs.map +0 -1
  87. package/dist/node/components/Property/SchemaProperty.js +0 -56
  88. package/dist/node/components/Property/SchemaProperty.js.map +0 -1
  89. package/dist/node/components/Property/index.cjs +0 -83
  90. package/dist/node/components/Property/index.cjs.map +0 -1
  91. package/dist/node/components/Property/index.js +0 -56
  92. package/dist/node/components/Property/index.js.map +0 -1
  93. package/dist/node/components/SelectEx/SchemaSelectEx.cjs +0 -72
  94. package/dist/node/components/SelectEx/SchemaSelectEx.cjs.map +0 -1
  95. package/dist/node/components/SelectEx/SchemaSelectEx.js +0 -47
  96. package/dist/node/components/SelectEx/SchemaSelectEx.js.map +0 -1
  97. package/dist/node/components/SelectEx/index.cjs +0 -74
  98. package/dist/node/components/SelectEx/index.cjs.map +0 -1
  99. package/dist/node/components/SelectEx/index.js +0 -47
  100. package/dist/node/components/SelectEx/index.js.map +0 -1
  101. package/dist/node/components/index.cjs +0 -129
  102. package/dist/node/components/index.cjs.map +0 -1
  103. package/dist/node/components/index.js +0 -101
  104. package/dist/node/components/index.js.map +0 -1
  105. package/dist/node/contexts/Schema/Context.cjs +0 -32
  106. package/dist/node/contexts/Schema/Context.cjs.map +0 -1
  107. package/dist/node/contexts/Schema/Context.js +0 -7
  108. package/dist/node/contexts/Schema/Context.js.map +0 -1
  109. package/dist/node/contexts/Schema/Provider/Memory.cjs +0 -98
  110. package/dist/node/contexts/Schema/Provider/Memory.cjs.map +0 -1
  111. package/dist/node/contexts/Schema/Provider/Memory.js +0 -73
  112. package/dist/node/contexts/Schema/Provider/Memory.js.map +0 -1
  113. package/dist/node/contexts/Schema/Provider/Props.cjs +0 -19
  114. package/dist/node/contexts/Schema/Provider/Props.cjs.map +0 -1
  115. package/dist/node/contexts/Schema/Provider/Props.js +0 -1
  116. package/dist/node/contexts/Schema/Provider/Props.js.map +0 -1
  117. package/dist/node/contexts/Schema/Provider/Route.cjs +0 -148
  118. package/dist/node/contexts/Schema/Provider/Route.cjs.map +0 -1
  119. package/dist/node/contexts/Schema/Provider/Route.js +0 -123
  120. package/dist/node/contexts/Schema/Provider/Route.js.map +0 -1
  121. package/dist/node/contexts/Schema/Provider/index.cjs +0 -152
  122. package/dist/node/contexts/Schema/Provider/index.cjs.map +0 -1
  123. package/dist/node/contexts/Schema/Provider/index.js +0 -124
  124. package/dist/node/contexts/Schema/Provider/index.js.map +0 -1
  125. package/dist/node/contexts/Schema/State.cjs +0 -19
  126. package/dist/node/contexts/Schema/State.cjs.map +0 -1
  127. package/dist/node/contexts/Schema/State.js +0 -1
  128. package/dist/node/contexts/Schema/State.js.map +0 -1
  129. package/dist/node/contexts/Schema/index.cjs +0 -156
  130. package/dist/node/contexts/Schema/index.cjs.map +0 -1
  131. package/dist/node/contexts/Schema/index.js +0 -126
  132. package/dist/node/contexts/Schema/index.js.map +0 -1
  133. package/dist/node/contexts/Schema/use.cjs +0 -40
  134. package/dist/node/contexts/Schema/use.cjs.map +0 -1
  135. package/dist/node/contexts/Schema/use.js +0 -15
  136. package/dist/node/contexts/Schema/use.js.map +0 -1
  137. package/dist/node/contexts/index.cjs +0 -156
  138. package/dist/node/contexts/index.cjs.map +0 -1
  139. package/dist/node/contexts/index.js +0 -126
  140. package/dist/node/contexts/index.js.map +0 -1
  141. package/dist/node/hooks/index.cjs +0 -199
  142. package/dist/node/hooks/index.cjs.map +0 -1
  143. package/dist/node/hooks/index.js +0 -169
  144. package/dist/node/hooks/index.js.map +0 -1
  145. package/dist/node/hooks/useGetSchema.cjs +0 -73
  146. package/dist/node/hooks/useGetSchema.cjs.map +0 -1
  147. package/dist/node/hooks/useGetSchema.js +0 -48
  148. package/dist/node/hooks/useGetSchema.js.map +0 -1
  149. package/dist/node/hooks/useSchemaDefinitions.cjs +0 -54
  150. package/dist/node/hooks/useSchemaDefinitions.cjs.map +0 -1
  151. package/dist/node/hooks/useSchemaDefinitions.js +0 -29
  152. package/dist/node/hooks/useSchemaDefinitions.js.map +0 -1
  153. package/dist/node/hooks/useSchemaList.cjs +0 -73
  154. package/dist/node/hooks/useSchemaList.cjs.map +0 -1
  155. package/dist/node/hooks/useSchemaList.js +0 -48
  156. package/dist/node/hooks/useSchemaList.js.map +0 -1
  157. package/dist/node/hooks/useSchemaStats.cjs +0 -75
  158. package/dist/node/hooks/useSchemaStats.cjs.map +0 -1
  159. package/dist/node/hooks/useSchemaStats.js +0 -50
  160. package/dist/node/hooks/useSchemaStats.js.map +0 -1
@@ -1,148 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/contexts/Schema/Provider/Route.tsx
21
- var Route_exports = {};
22
- __export(Route_exports, {
23
- SchemaRouteProvider: () => SchemaRouteProvider
24
- });
25
- module.exports = __toCommonJS(Route_exports);
26
- var import_react3 = require("react");
27
- var import_react_router_dom = require("react-router-dom");
28
-
29
- // src/contexts/Schema/Context.ts
30
- var import_react_shared = require("@xyo-network/react-shared");
31
- var SchemaContext = (0, import_react_shared.createContextEx)();
32
-
33
- // src/contexts/Schema/use.ts
34
- var import_react_shared2 = require("@xyo-network/react-shared");
35
- var useSchema = (required = false) => {
36
- return (0, import_react_shared2.useContextEx)(SchemaContext, "Schema", required);
37
- };
38
-
39
- // src/contexts/Schema/Provider/Memory.tsx
40
- var import_lodash = require("@xylabs/lodash");
41
- var import_react2 = require("react");
42
-
43
- // src/hooks/useSchemaStats.tsx
44
- var import_react_async_effect = require("@xylabs/react-async-effect");
45
- var import_diviner_schema_stats_model = require("@xyo-network/diviner-schema-stats-model");
46
- var import_node_core_types = require("@xyo-network/node-core-types");
47
- var import_react_diviner = require("@xyo-network/react-diviner");
48
- var import_react = require("react");
49
- var useSchemaStats = (statsAddress, nameOrAddress = import_node_core_types.TYPES.SchemaStatsDiviner.description) => {
50
- const [refresh, setRefresh] = (0, import_react.useState)(1);
51
- const [diviner, divinerError] = (0, import_react_diviner.useDivinerFromNode)(nameOrAddress);
52
- const [error, setError] = (0, import_react.useState)();
53
- const refreshHistory = () => setRefresh((previous) => previous + 1);
54
- const [schemaList, setSchemaList] = (0, import_react.useState)();
55
- const query = (0, import_react.useMemo)(
56
- () => ({
57
- address: statsAddress,
58
- schema: import_diviner_schema_stats_model.SchemaStatsQuerySchema
59
- }),
60
- [statsAddress]
61
- );
62
- (0, import_react_async_effect.useAsyncEffect)(
63
- // eslint-disable-next-line react-hooks/exhaustive-deps
64
- async (mounted) => {
65
- if (diviner) {
66
- if (divinerError) {
67
- if (mounted()) {
68
- setError(divinerError);
69
- setSchemaList(void 0);
70
- }
71
- } else {
72
- try {
73
- const schemas = (await diviner.divine([query])).filter(import_diviner_schema_stats_model.isSchemaStatsPayload);
74
- if (mounted()) {
75
- setSchemaList(schemas);
76
- setError(void 0);
77
- }
78
- } catch (ex) {
79
- setError(ex);
80
- setSchemaList(void 0);
81
- }
82
- }
83
- }
84
- },
85
- [diviner, refresh, divinerError, query]
86
- );
87
- return [schemaList, error, refreshHistory];
88
- };
89
-
90
- // src/contexts/Schema/Provider/Memory.tsx
91
- var import_jsx_runtime = require("react/jsx-runtime");
92
- var SchemaMemoryProvider = ({ defaultSchema, knownSchemaList = [], ...props }) => {
93
- const [schema, setSchema] = (0, import_react2.useState)(defaultSchema);
94
- const [schemaList, setSchemaList] = (0, import_react2.useState)(knownSchemaList);
95
- const [fetchedSchemaStats] = useSchemaStats();
96
- (0, import_react2.useEffect)(() => {
97
- if (fetchedSchemaStats) {
98
- const schemaList2 = (0, import_lodash.compact)(fetchedSchemaStats.map(({ name }) => name));
99
- setSchemaList(schemaList2);
100
- }
101
- }, [fetchedSchemaStats]);
102
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaContext.Provider, { value: { provided: true, schema, schemaList: knownSchemaList ?? schemaList, setSchema, setSchemaList }, ...props });
103
- };
104
-
105
- // src/contexts/Schema/Provider/Route.tsx
106
- var import_jsx_runtime2 = require("react/jsx-runtime");
107
- var SchemaRouteProviderInner = ({ children }) => {
108
- const { schema, setSchema, schemaList } = useSchema();
109
- const [params, setParams] = (0, import_react_router_dom.useSearchParams)();
110
- const routeSchema = params.get("schema");
111
- const setSchemaParam = (0, import_react3.useCallback)(
112
- (schema2) => {
113
- if (schema2) {
114
- params.set("schema", schema2);
115
- setParams(params, { replace: true });
116
- setSchema == null ? void 0 : setSchema(schema2);
117
- } else {
118
- params.delete("network");
119
- }
120
- },
121
- [params, setParams, setSchema]
122
- );
123
- const setSchemaLocal = (0, import_react3.useCallback)(
124
- (schema2) => {
125
- setSchemaParam(schema2);
126
- setSchema == null ? void 0 : setSchema(schema2);
127
- },
128
- [setSchemaParam, setSchema]
129
- );
130
- (0, import_react3.useEffect)(() => {
131
- if (routeSchema !== schema) {
132
- if (routeSchema === void 0 && schema !== void 0) {
133
- setSchemaLocal(schema);
134
- } else if (routeSchema) {
135
- setSchema == null ? void 0 : setSchema(routeSchema);
136
- }
137
- }
138
- }, [routeSchema, schema, setSchemaParam, setSchema, setSchemaLocal]);
139
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SchemaContext.Provider, { value: { provided: true, schema, schemaList, setSchema: setSchemaLocal }, children });
140
- };
141
- var SchemaRouteProvider = ({ knownSchemaList, defaultSchema, ...props }) => {
142
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SchemaMemoryProvider, { knownSchemaList, defaultSchema, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SchemaRouteProviderInner, { ...props }) });
143
- };
144
- // Annotate the CommonJS export names for ESM import in node:
145
- 0 && (module.exports = {
146
- SchemaRouteProvider
147
- });
148
- //# sourceMappingURL=Route.cjs.map
@@ -1 +0,0 @@
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, divinerError, query],\n )\n\n return [schemaList, error, refreshHistory]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,gBAAuC;AACvC,8BAAgC;;;ACFhC,0BAAgC;AAIzB,IAAM,oBAAgB,qCAAoC;;;ACJjE,IAAAC,uBAA6B;AAKtB,IAAM,YAAY,CAAC,WAAW,UAAU;AAC7C,aAAO,mCAAiC,eAAe,UAAU,QAAQ;AAC3E;;;ACPA,oBAAwB;AAExB,IAAAC,gBAAoC;;;ACFpC,gCAA+B;AAC/B,wCAA0G;AAC1G,6BAAsB;AACtB,2BAAmC;AACnC,mBAA4D;AAErD,IAAM,iBAAiB,CAC5B,cACA,gBAAgB,6BAAM,mBAAmB,gBACmD;AAC5F,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,CAAC;AACxC,QAAM,CAAC,SAAS,YAAY,QAAI,yCAAmB,aAAa;AAChE,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAgB;AAC1C,QAAM,iBAAiB,MAAM,WAAW,CAAC,aAAa,WAAW,CAAC;AAElE,QAAM,CAAC,YAAY,aAAa,QAAI,uBAA+B;AAEnE,QAAM,YAAiC;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,QAA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;AAAA,MACd,OAAO;AACL,eAAO,OAAO,SAAS;AAAA,MACzB;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,WAAW,SAAS;AAAA,EAC/B;AAGA,QAAM,qBAAiB;AAAA,IACrB,CAACA,YAAmB;AAClB,qBAAeA,OAAM;AACrB,6CAAYA;AAAA,IACd;AAAA,IACA,CAAC,gBAAgB,SAAS;AAAA,EAC5B;AAGA,+BAAU,MAAM;AACd,QAAI,gBAAgB,QAAQ;AAC1B,UAAI,gBAAgB,UAAa,WAAW,QAAW;AAErD,uBAAe,MAAM;AAAA,MACvB,WAAW,aAAa;AAEtB,+CAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,QAAQ,gBAAgB,WAAW,cAAc,CAAC;AAEnE,SAAO,6CAAC,cAAc,UAAd,EAAuB,OAAO,EAAE,UAAU,MAAM,QAAQ,YAAY,WAAW,eAAe,GAAI,UAAS;AACrH;AAEO,IAAM,sBAAmE,CAAC,EAAE,iBAAiB,eAAe,GAAG,MAAM,MAAM;AAChI,SACE,6CAAC,wBAAqB,iBAAkC,eACtD,uDAAC,4BAA0B,GAAG,OAAO,GACvC;AAEJ;","names":["import_react","import_react_shared","import_react","schemaList","import_jsx_runtime","schema"]}
@@ -1,123 +0,0 @@
1
- // src/contexts/Schema/Provider/Route.tsx
2
- import { useCallback, useEffect as useEffect2 } from "react";
3
- import { useSearchParams } from "react-router-dom";
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 }) => {
84
- const { schema, setSchema, schemaList } = useSchema();
85
- const [params, setParams] = useSearchParams();
86
- const routeSchema = params.get("schema");
87
- const setSchemaParam = useCallback(
88
- (schema2) => {
89
- if (schema2) {
90
- params.set("schema", schema2);
91
- setParams(params, { replace: true });
92
- setSchema == null ? void 0 : setSchema(schema2);
93
- } else {
94
- params.delete("network");
95
- }
96
- },
97
- [params, setParams, setSchema]
98
- );
99
- const setSchemaLocal = useCallback(
100
- (schema2) => {
101
- setSchemaParam(schema2);
102
- setSchema == null ? void 0 : setSchema(schema2);
103
- },
104
- [setSchemaParam, setSchema]
105
- );
106
- useEffect2(() => {
107
- if (routeSchema !== schema) {
108
- if (routeSchema === void 0 && schema !== void 0) {
109
- setSchemaLocal(schema);
110
- } else if (routeSchema) {
111
- setSchema == null ? void 0 : setSchema(routeSchema);
112
- }
113
- }
114
- }, [routeSchema, schema, setSchemaParam, setSchema, setSchemaLocal]);
115
- return /* @__PURE__ */ jsx2(SchemaContext.Provider, { value: { provided: true, schema, schemaList, setSchema: setSchemaLocal }, children });
116
- };
117
- var SchemaRouteProvider = ({ knownSchemaList, defaultSchema, ...props }) => {
118
- return /* @__PURE__ */ jsx2(SchemaMemoryProvider, { knownSchemaList, defaultSchema, children: /* @__PURE__ */ jsx2(SchemaRouteProviderInner, { ...props }) });
119
- };
120
- export {
121
- SchemaRouteProvider
122
- };
123
- //# sourceMappingURL=Route.js.map
@@ -1 +0,0 @@
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, divinerError, query],\n )\n\n return [schemaList, error, refreshHistory]\n}\n"],"mappings":";AACA,SAAS,aAAa,aAAAA,kBAAiB;AACvC,SAAS,uBAAuB;;;ACFhC,SAAS,uBAAuB;AAIzB,IAAM,gBAAgB,gBAAoC;;;ACJjE,SAAS,oBAAoB;AAKtB,IAAM,YAAY,CAAC,WAAW,UAAU;AAC7C,SAAO,aAAiC,eAAe,UAAU,QAAQ;AAC3E;;;ACPA,SAAS,eAAe;AAExB,SAAS,WAAW,YAAAC,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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,kBAAU,QAAQ,EAAE,SAAS,KAAK,CAAC;AACnC,+CAAYA;AAAA,MACd,OAAO;AACL,eAAO,OAAO,SAAS;AAAA,MACzB;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,WAAW,SAAS;AAAA,EAC/B;AAGA,QAAM,iBAAiB;AAAA,IACrB,CAACA,YAAmB;AAClB,qBAAeA,OAAM;AACrB,6CAAYA;AAAA,IACd;AAAA,IACA,CAAC,gBAAgB,SAAS;AAAA,EAC5B;AAGA,EAAAC,WAAU,MAAM;AACd,QAAI,gBAAgB,QAAQ;AAC1B,UAAI,gBAAgB,UAAa,WAAW,QAAW;AAErD,uBAAe,MAAM;AAAA,MACvB,WAAW,aAAa;AAEtB,+CAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,QAAQ,gBAAgB,WAAW,cAAc,CAAC;AAEnE,SAAO,gBAAAF,KAAC,cAAc,UAAd,EAAuB,OAAO,EAAE,UAAU,MAAM,QAAQ,YAAY,WAAW,eAAe,GAAI,UAAS;AACrH;AAEO,IAAM,sBAAmE,CAAC,EAAE,iBAAiB,eAAe,GAAG,MAAM,MAAM;AAChI,SACE,gBAAAA,KAAC,wBAAqB,iBAAkC,eACtD,0BAAAA,KAAC,4BAA0B,GAAG,OAAO,GACvC;AAEJ;","names":["useEffect","useState","useState","schemaList","jsx","schema","useEffect"]}
@@ -1,152 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/contexts/Schema/Provider/index.ts
21
- var Provider_exports = {};
22
- __export(Provider_exports, {
23
- SchemaMemoryProvider: () => SchemaMemoryProvider,
24
- SchemaRouteProvider: () => SchemaRouteProvider
25
- });
26
- module.exports = __toCommonJS(Provider_exports);
27
-
28
- // src/contexts/Schema/Provider/Memory.tsx
29
- var import_lodash = require("@xylabs/lodash");
30
- var import_react2 = require("react");
31
-
32
- // src/hooks/useSchemaStats.tsx
33
- var import_react_async_effect = require("@xylabs/react-async-effect");
34
- var import_diviner_schema_stats_model = require("@xyo-network/diviner-schema-stats-model");
35
- var import_node_core_types = require("@xyo-network/node-core-types");
36
- var import_react_diviner = require("@xyo-network/react-diviner");
37
- var import_react = require("react");
38
- var useSchemaStats = (statsAddress, nameOrAddress = import_node_core_types.TYPES.SchemaStatsDiviner.description) => {
39
- const [refresh, setRefresh] = (0, import_react.useState)(1);
40
- const [diviner, divinerError] = (0, import_react_diviner.useDivinerFromNode)(nameOrAddress);
41
- const [error, setError] = (0, import_react.useState)();
42
- const refreshHistory = () => setRefresh((previous) => previous + 1);
43
- const [schemaList, setSchemaList] = (0, import_react.useState)();
44
- const query = (0, import_react.useMemo)(
45
- () => ({
46
- address: statsAddress,
47
- schema: import_diviner_schema_stats_model.SchemaStatsQuerySchema
48
- }),
49
- [statsAddress]
50
- );
51
- (0, import_react_async_effect.useAsyncEffect)(
52
- // eslint-disable-next-line react-hooks/exhaustive-deps
53
- async (mounted) => {
54
- if (diviner) {
55
- if (divinerError) {
56
- if (mounted()) {
57
- setError(divinerError);
58
- setSchemaList(void 0);
59
- }
60
- } else {
61
- try {
62
- const schemas = (await diviner.divine([query])).filter(import_diviner_schema_stats_model.isSchemaStatsPayload);
63
- if (mounted()) {
64
- setSchemaList(schemas);
65
- setError(void 0);
66
- }
67
- } catch (ex) {
68
- setError(ex);
69
- setSchemaList(void 0);
70
- }
71
- }
72
- }
73
- },
74
- [diviner, refresh, divinerError, query]
75
- );
76
- return [schemaList, error, refreshHistory];
77
- };
78
-
79
- // src/contexts/Schema/Context.ts
80
- var import_react_shared = require("@xyo-network/react-shared");
81
- var SchemaContext = (0, import_react_shared.createContextEx)();
82
-
83
- // src/contexts/Schema/Provider/Memory.tsx
84
- var import_jsx_runtime = require("react/jsx-runtime");
85
- var SchemaMemoryProvider = ({ defaultSchema, knownSchemaList = [], ...props }) => {
86
- const [schema, setSchema] = (0, import_react2.useState)(defaultSchema);
87
- const [schemaList, setSchemaList] = (0, import_react2.useState)(knownSchemaList);
88
- const [fetchedSchemaStats] = useSchemaStats();
89
- (0, import_react2.useEffect)(() => {
90
- if (fetchedSchemaStats) {
91
- const schemaList2 = (0, import_lodash.compact)(fetchedSchemaStats.map(({ name }) => name));
92
- setSchemaList(schemaList2);
93
- }
94
- }, [fetchedSchemaStats]);
95
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaContext.Provider, { value: { provided: true, schema, schemaList: knownSchemaList ?? schemaList, setSchema, setSchemaList }, ...props });
96
- };
97
-
98
- // src/contexts/Schema/Provider/Route.tsx
99
- var import_react3 = require("react");
100
- var import_react_router_dom = require("react-router-dom");
101
-
102
- // src/contexts/Schema/use.ts
103
- var import_react_shared2 = require("@xyo-network/react-shared");
104
- var useSchema = (required = false) => {
105
- return (0, import_react_shared2.useContextEx)(SchemaContext, "Schema", required);
106
- };
107
-
108
- // src/contexts/Schema/Provider/Route.tsx
109
- var import_jsx_runtime2 = require("react/jsx-runtime");
110
- var SchemaRouteProviderInner = ({ children }) => {
111
- const { schema, setSchema, schemaList } = useSchema();
112
- const [params, setParams] = (0, import_react_router_dom.useSearchParams)();
113
- const routeSchema = params.get("schema");
114
- const setSchemaParam = (0, import_react3.useCallback)(
115
- (schema2) => {
116
- if (schema2) {
117
- params.set("schema", schema2);
118
- setParams(params, { replace: true });
119
- setSchema == null ? void 0 : setSchema(schema2);
120
- } else {
121
- params.delete("network");
122
- }
123
- },
124
- [params, setParams, setSchema]
125
- );
126
- const setSchemaLocal = (0, import_react3.useCallback)(
127
- (schema2) => {
128
- setSchemaParam(schema2);
129
- setSchema == null ? void 0 : setSchema(schema2);
130
- },
131
- [setSchemaParam, setSchema]
132
- );
133
- (0, import_react3.useEffect)(() => {
134
- if (routeSchema !== schema) {
135
- if (routeSchema === void 0 && schema !== void 0) {
136
- setSchemaLocal(schema);
137
- } else if (routeSchema) {
138
- setSchema == null ? void 0 : setSchema(routeSchema);
139
- }
140
- }
141
- }, [routeSchema, schema, setSchemaParam, setSchema, setSchemaLocal]);
142
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SchemaContext.Provider, { value: { provided: true, schema, schemaList, setSchema: setSchemaLocal }, children });
143
- };
144
- var SchemaRouteProvider = ({ knownSchemaList, defaultSchema, ...props }) => {
145
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SchemaMemoryProvider, { knownSchemaList, defaultSchema, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SchemaRouteProviderInner, { ...props }) });
146
- };
147
- // Annotate the CommonJS export names for ESM import in node:
148
- 0 && (module.exports = {
149
- SchemaMemoryProvider,
150
- SchemaRouteProvider
151
- });
152
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../src/contexts/Schema/Provider/index.ts","../../../../../src/contexts/Schema/Provider/Memory.tsx","../../../../../src/hooks/useSchemaStats.tsx","../../../../../src/contexts/Schema/Context.ts","../../../../../src/contexts/Schema/Provider/Route.tsx","../../../../../src/contexts/Schema/use.ts"],"sourcesContent":["export * from './Memory'\nexport * from './Props'\nexport * from './Route'\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, 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","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 { 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;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAwB;AAExB,IAAAA,gBAAoC;;;ACFpC,gCAA+B;AAC/B,wCAA0G;AAC1G,6BAAsB;AACtB,2BAAmC;AACnC,mBAA4D;AAErD,IAAM,iBAAiB,CAC5B,cACA,gBAAgB,6BAAM,mBAAmB,gBACmD;AAC5F,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,CAAC;AACxC,QAAM,CAAC,SAAS,YAAY,QAAI,yCAAmB,aAAa;AAChE,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAgB;AAC1C,QAAM,iBAAiB,MAAM,WAAW,CAAC,aAAa,WAAW,CAAC;AAElE,QAAM,CAAC,YAAY,aAAa,QAAI,uBAA+B;AAEnE,QAAM,YAAiC;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,sDAAoB;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;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ACA,CAAC,QAAQ,WAAW,SAAS;AAAA,EAC/B;AAGA,QAAM,qBAAiB;AAAA,IACrB,CAACA,YAAmB;AAClB,qBAAeA,OAAM;AACrB,6CAAYA;AAAA,IACd;AAAA,IACA,CAAC,gBAAgB,SAAS;AAAA,EAC5B;AAGA,+BAAU,MAAM;AACd,QAAI,gBAAgB,QAAQ;AAC1B,UAAI,gBAAgB,UAAa,WAAW,QAAW;AAErD,uBAAe,MAAM;AAAA,MACvB,WAAW,aAAa;AAEtB,+CAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,QAAQ,gBAAgB,WAAW,cAAc,CAAC;AAEnE,SAAO,6CAAC,cAAc,UAAd,EAAuB,OAAO,EAAE,UAAU,MAAM,QAAQ,YAAY,WAAW,eAAe,GAAI,UAAS;AACrH;AAEO,IAAM,sBAAmE,CAAC,EAAE,iBAAiB,eAAe,GAAG,MAAM,MAAM;AAChI,SACE,6CAAC,wBAAqB,iBAAkC,eACtD,uDAAC,4BAA0B,GAAG,OAAO,GACvC;AAEJ;","names":["import_react","schemaList","import_react","import_react_shared","import_jsx_runtime","schema"]}
@@ -1,124 +0,0 @@
1
- // src/contexts/Schema/Provider/Memory.tsx
2
- import { compact } from "@xylabs/lodash";
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);
61
- const [fetchedSchemaStats] = useSchemaStats();
62
- useEffect(() => {
63
- if (fetchedSchemaStats) {
64
- const schemaList2 = compact(fetchedSchemaStats.map(({ name }) => name));
65
- setSchemaList(schemaList2);
66
- }
67
- }, [fetchedSchemaStats]);
68
- return /* @__PURE__ */ jsx(SchemaContext.Provider, { value: { provided: true, schema, schemaList: knownSchemaList ?? schemaList, setSchema, setSchemaList }, ...props });
69
- };
70
-
71
- // src/contexts/Schema/Provider/Route.tsx
72
- import { useCallback, useEffect as useEffect2 } from "react";
73
- import { useSearchParams } from "react-router-dom";
74
-
75
- // src/contexts/Schema/use.ts
76
- import { useContextEx } from "@xyo-network/react-shared";
77
- var useSchema = (required = false) => {
78
- return useContextEx(SchemaContext, "Schema", required);
79
- };
80
-
81
- // src/contexts/Schema/Provider/Route.tsx
82
- import { jsx as jsx2 } from "react/jsx-runtime";
83
- var SchemaRouteProviderInner = ({ children }) => {
84
- const { schema, setSchema, schemaList } = useSchema();
85
- const [params, setParams] = useSearchParams();
86
- const routeSchema = params.get("schema");
87
- const setSchemaParam = useCallback(
88
- (schema2) => {
89
- if (schema2) {
90
- params.set("schema", schema2);
91
- setParams(params, { replace: true });
92
- setSchema == null ? void 0 : setSchema(schema2);
93
- } else {
94
- params.delete("network");
95
- }
96
- },
97
- [params, setParams, setSchema]
98
- );
99
- const setSchemaLocal = useCallback(
100
- (schema2) => {
101
- setSchemaParam(schema2);
102
- setSchema == null ? void 0 : setSchema(schema2);
103
- },
104
- [setSchemaParam, setSchema]
105
- );
106
- useEffect2(() => {
107
- if (routeSchema !== schema) {
108
- if (routeSchema === void 0 && schema !== void 0) {
109
- setSchemaLocal(schema);
110
- } else if (routeSchema) {
111
- setSchema == null ? void 0 : setSchema(routeSchema);
112
- }
113
- }
114
- }, [routeSchema, schema, setSchemaParam, setSchema, setSchemaLocal]);
115
- return /* @__PURE__ */ jsx2(SchemaContext.Provider, { value: { provided: true, schema, schemaList, setSchema: setSchemaLocal }, children });
116
- };
117
- var SchemaRouteProvider = ({ knownSchemaList, defaultSchema, ...props }) => {
118
- return /* @__PURE__ */ jsx2(SchemaMemoryProvider, { knownSchemaList, defaultSchema, children: /* @__PURE__ */ jsx2(SchemaRouteProviderInner, { ...props }) });
119
- };
120
- export {
121
- SchemaMemoryProvider,
122
- SchemaRouteProvider
123
- };
124
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../src/contexts/Schema/Provider/Memory.tsx","../../../../../src/hooks/useSchemaStats.tsx","../../../../../src/contexts/Schema/Context.ts","../../../../../src/contexts/Schema/Provider/Route.tsx","../../../../../src/contexts/Schema/use.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","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 { 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;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,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AYA;AAAA,MACd,OAAO;AACL,eAAO,OAAO,SAAS;AAAA,MACzB;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,WAAW,SAAS;AAAA,EAC/B;AAGA,QAAM,iBAAiB;AAAA,IACrB,CAACA,YAAmB;AAClB,qBAAeA,OAAM;AACrB,6CAAYA;AAAA,IACd;AAAA,IACA,CAAC,gBAAgB,SAAS;AAAA,EAC5B;AAGA,EAAAC,WAAU,MAAM;AACd,QAAI,gBAAgB,QAAQ;AAC1B,UAAI,gBAAgB,UAAa,WAAW,QAAW;AAErD,uBAAe,MAAM;AAAA,MACvB,WAAW,aAAa;AAEtB,+CAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,QAAQ,gBAAgB,WAAW,cAAc,CAAC;AAEnE,SAAO,gBAAAF,KAAC,cAAc,UAAd,EAAuB,OAAO,EAAE,UAAU,MAAM,QAAQ,YAAY,WAAW,eAAe,GAAI,UAAS;AACrH;AAEO,IAAM,sBAAmE,CAAC,EAAE,iBAAiB,eAAe,GAAG,MAAM,MAAM;AAChI,SACE,gBAAAA,KAAC,wBAAqB,iBAAkC,eACtD,0BAAAA,KAAC,4BAA0B,GAAG,OAAO,GACvC;AAEJ;","names":["useState","useState","schemaList","useEffect","jsx","schema","useEffect"]}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/contexts/Schema/State.ts
17
- var State_exports = {};
18
- module.exports = __toCommonJS(State_exports);
19
- //# sourceMappingURL=State.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/contexts/Schema/State.ts"],"sourcesContent":["import { ContextExState } from '@xyo-network/react-shared'\nimport { Dispatch } from 'react'\n\nexport interface SchemaContextState extends ContextExState {\n /** @field The currently selected XYO Schema */\n schema?: string\n /** @field The list of known available schema */\n schemaList?: string[]\n /** @field Function to set the selected Schema */\n setSchema?: Dispatch<string>\n /** @field Function to set the list of known available schema */\n setSchemaList?: Dispatch<string[]>\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}