@xyo-network/react-schema 3.0.15 → 3.0.17

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaProperty.d.ts","sourceRoot":"","sources":["../../../../src/components/Property/SchemaProperty.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAIhE,OAAO,KAA+B,MAAM,OAAO,CAAA;AAEnD,MAAM,MAAM,mBAAmB,GAAG,aAAa,GAAG;IAChD,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAkBD,eAAO,MAAM,cAAc;;;;;;;;;oBAtBT,OAAO;4BACC,OAAO;qBACd,OAAO;YAChB,MAAM;;;;;;;;;;;;;;oBAHE,OAAO;4BACC,OAAO;qBACd,OAAO;YAChB,MAAM;iDAmFf,CAAA"}
1
+ {"version":3,"file":"SchemaProperty.d.ts","sourceRoot":"","sources":["../../../../src/components/Property/SchemaProperty.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAIhE,OAAO,KAA+B,MAAM,OAAO,CAAA;AAEnD,MAAM,MAAM,mBAAmB,GAAG,aAAa,GAAG;IAChD,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAkBD,eAAO,MAAM,cAAc;;;;;;;;;oBAtBT,OAAO;4BACC,OAAO;qBACd,OAAO;YAChB,MAAM;;;;;;;;;;gBAuCwG,MAChH,WAAI;;;;oBA3CM,OAAO;4BACC,OAAO;qBACd,OAAO;YAChB,MAAM;iDAmFf,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSchemaList.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSchemaList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,KAAK,EAAE,iBAAiB,EAA0B,MAAM,wCAAwC,CAAA;AAQvG,eAAO,MAAM,aAAa,aAAc,OAAO,6BAAwC,CAAC,iBAAiB,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CA4C9I,CAAA"}
1
+ {"version":3,"file":"useSchemaList.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSchemaList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,KAAK,EAAE,iBAAiB,EAA0B,MAAM,wCAAwC,CAAA;AAMvG,eAAO,MAAM,aAAa,aAAc,OAAO,6BAAwC,CAAC,iBAAiB,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CA2B9I,CAAA"}
@@ -100,7 +100,7 @@ var SchemaContext = createContextEx();
100
100
 
101
101
  // src/contexts/Schema/Provider/Memory.tsx
102
102
  import { exists } from "@xylabs/exists";
103
- import React2, { useEffect as useEffect2, useMemo as useMemo3, useState as useState6 } from "react";
103
+ import React2, { useEffect, useMemo as useMemo3, useState as useState5 } from "react";
104
104
 
105
105
  // src/hooks/useGetSchema.tsx
106
106
  import { useAsyncEffect as useAsyncEffect2 } from "@xylabs/react-async-effect";
@@ -173,13 +173,11 @@ var useSchemaDefinitions = /* @__PURE__ */ __name((schemaList) => {
173
173
  }, "useSchemaDefinitions");
174
174
 
175
175
  // src/hooks/useSchemaList.tsx
176
- import { useAsyncEffect as useAsyncEffect4 } from "@xylabs/react-async-effect";
176
+ import { usePromise } from "@xylabs/react-promise";
177
177
  import { SchemaListQuerySchema } from "@xyo-network/diviner-schema-list-model";
178
178
  import { useWeakDivinerFromNode } from "@xyo-network/react-diviner";
179
- import { useEffect, useMemo, useState as useState4 } from "react";
179
+ import { useMemo } from "react";
180
180
  var useSchemaList = /* @__PURE__ */ __name((address, nameOrAddress = "SchemaListDiviner") => {
181
- const [schemaList, setSchemaList] = useState4();
182
- const [error, setError] = useState4();
183
181
  const [diviner, divinerError] = useWeakDivinerFromNode(nameOrAddress);
184
182
  const query = useMemo(() => address ? [
185
183
  {
@@ -189,27 +187,11 @@ var useSchemaList = /* @__PURE__ */ __name((address, nameOrAddress = "SchemaList
189
187
  ] : void 0, [
190
188
  address
191
189
  ]);
192
- useEffect(() => {
193
- if (diviner === null) {
194
- setSchemaList(null);
195
- setError(void 0);
196
- }
197
- }, [
198
- diviner
199
- ]);
200
- useAsyncEffect4(async (mounted) => {
190
+ const [schemaList, error] = usePromise(async () => {
201
191
  const divinerInstance = diviner?.deref();
202
192
  if (divinerInstance) {
203
- try {
204
- const response = await divinerInstance.divine(query);
205
- if (mounted()) {
206
- setSchemaList(response?.[0]);
207
- setError(void 0);
208
- }
209
- } catch (e) {
210
- setError(e);
211
- setSchemaList(void 0);
212
- }
193
+ const response = await divinerInstance.divine(query);
194
+ return response.at(0);
213
195
  }
214
196
  }, [
215
197
  diviner,
@@ -223,25 +205,25 @@ var useSchemaList = /* @__PURE__ */ __name((address, nameOrAddress = "SchemaList
223
205
  }, "useSchemaList");
224
206
 
225
207
  // src/hooks/useSchemaStats.tsx
226
- import { useAsyncEffect as useAsyncEffect5 } from "@xylabs/react-async-effect";
208
+ import { useAsyncEffect as useAsyncEffect4 } from "@xylabs/react-async-effect";
227
209
  import { SchemaStatsDivinerSchema, SchemaStatsQuerySchema } from "@xyo-network/diviner-schema-stats-model";
228
210
  import { TYPES } from "@xyo-network/node-core-types";
229
211
  import { isPayloadOfSchemaTypeWithMeta } from "@xyo-network/payload-model";
230
212
  import { useWeakDivinerFromNode as useWeakDivinerFromNode2 } from "@xyo-network/react-diviner";
231
- import { useMemo as useMemo2, useState as useState5 } from "react";
213
+ import { useMemo as useMemo2, useState as useState4 } from "react";
232
214
  var useSchemaStats = /* @__PURE__ */ __name((statsAddress, nameOrAddress = TYPES.SchemaStatsDiviner) => {
233
- const [refresh, setRefresh] = useState5(1);
215
+ const [refresh, setRefresh] = useState4(1);
234
216
  const [diviner, divinerError] = useWeakDivinerFromNode2(nameOrAddress);
235
- const [error, setError] = useState5();
217
+ const [error, setError] = useState4();
236
218
  const refreshHistory = /* @__PURE__ */ __name(() => setRefresh((previous) => previous + 1), "refreshHistory");
237
- const [schemaList, setSchemaList] = useState5();
219
+ const [schemaList, setSchemaList] = useState4();
238
220
  const query = useMemo2(() => ({
239
221
  address: statsAddress,
240
222
  schema: SchemaStatsQuerySchema
241
223
  }), [
242
224
  statsAddress
243
225
  ]);
244
- useAsyncEffect5(async (mounted) => {
226
+ useAsyncEffect4(async (mounted) => {
245
227
  const instance = diviner?.deref();
246
228
  if (instance) {
247
229
  if (divinerError) {
@@ -279,10 +261,10 @@ var useSchemaStats = /* @__PURE__ */ __name((statsAddress, nameOrAddress = TYPES
279
261
 
280
262
  // src/contexts/Schema/Provider/Memory.tsx
281
263
  var SchemaMemoryProvider = /* @__PURE__ */ __name(({ defaultSchema, knownSchemaList, ...props }) => {
282
- const [schema, setSchema] = useState6(defaultSchema);
283
- const [schemaList, setSchemaList] = useState6(knownSchemaList);
264
+ const [schema, setSchema] = useState5(defaultSchema);
265
+ const [schemaList, setSchemaList] = useState5(knownSchemaList);
284
266
  const [fetchedSchemaStats] = useSchemaStats();
285
- useEffect2(() => {
267
+ useEffect(() => {
286
268
  if (fetchedSchemaStats) {
287
269
  const schemaList2 = fetchedSchemaStats.map(({ name }) => name).filter(exists);
288
270
  setSchemaList(schemaList2);
@@ -308,7 +290,7 @@ var SchemaMemoryProvider = /* @__PURE__ */ __name(({ defaultSchema, knownSchemaL
308
290
  }, "SchemaMemoryProvider");
309
291
 
310
292
  // src/contexts/Schema/Provider/Route.tsx
311
- import React3, { useCallback, useEffect as useEffect3, useMemo as useMemo4 } from "react";
293
+ import React3, { useCallback, useEffect as useEffect2, useMemo as useMemo4 } from "react";
312
294
  import { useSearchParams } from "react-router-dom";
313
295
 
314
296
  // src/contexts/Schema/use.ts
@@ -344,7 +326,7 @@ var SchemaRouteProviderInner = /* @__PURE__ */ __name(({ children }) => {
344
326
  setSchemaParam,
345
327
  setSchema
346
328
  ]);
347
- useEffect3(() => {
329
+ useEffect2(() => {
348
330
  if (routeSchema !== schema) {
349
331
  if (routeSchema === void 0 && schema !== void 0) {
350
332
  setSchemaLocal(schema);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/Property/SchemaProperty.tsx","../../src/components/SelectEx/SchemaSelectEx.tsx","../../src/contexts/Schema/Context.ts","../../src/contexts/Schema/Provider/Memory.tsx","../../src/hooks/useGetSchema.tsx","../../src/hooks/useSchemaDefinitions.tsx","../../src/hooks/useSchemaList.tsx","../../src/hooks/useSchemaStats.tsx","../../src/contexts/Schema/Provider/Route.tsx","../../src/contexts/Schema/use.ts"],"sourcesContent":["import {\n NewReleases as NewReleasesIcon, OpenInNew as OpenInNewIcon, Verified as VerifiedIcon,\n} from '@mui/icons-material'\nimport { IconButton } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { LinkEx } from '@xylabs/react-link'\nimport type { EventDispatch, EventNoun } from '@xyo-network/react-event'\nimport { useEvent } from '@xyo-network/react-event'\nimport type { PropertyProps } from '@xyo-network/react-property'\nimport { Property, PropertyValue } from '@xyo-network/react-property'\nimport type { SchemaCacheEntry } from '@xyo-network/schema-cache'\nimport { SchemaCache } from '@xyo-network/schema-cache'\nimport React, { forwardRef, useState } from 'react'\n\nexport type SchemaPropertyProps = PropertyProps & {\n showLinkNames?: boolean\n showOpenNewWindowLink?: boolean\n showStatusIcon?: boolean\n value?: string\n}\n\nconst useResolveSchema = (schema?: string) => {\n const [entry, setEntry] = useState<SchemaCacheEntry | null>()\n useAsyncEffect(\n async (mounted) => {\n if (schema) {\n const entry = await SchemaCache.instance.get(schema)\n if (mounted()) {\n setEntry(entry)\n }\n }\n },\n [schema],\n )\n return entry\n}\n\nexport const SchemaProperty = forwardRef<HTMLDivElement, SchemaPropertyProps>(\n ({\n showLinkNames = true, showOpenNewWindowLink = true, showStatusIcon = true, titleProps, value, ...props\n }, ref) => {\n const resolvedSchema = useResolveSchema(value)\n const [buttonRef, buttonDispatch] = useEvent<HTMLButtonElement>()\n const [divRef, divDispatch] = useEvent<HTMLDivElement>()\n\n const onClick = (dispatch?: EventDispatch<EventNoun, 'click', string>, openNewWindow = false) => {\n dispatch?.(\n 'schema',\n 'click',\n JSON.stringify({\n openNewWindow,\n schema: value,\n }),\n )\n }\n\n return (\n <Property ref={ref} title=\"Schema\" value={value} tip=\"Schema sent with the payload\" titleProps={titleProps} {...props}>\n {value && showStatusIcon\n ? resolvedSchema === null\n ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"warning\" fontSize=\"inherit\" />\n </IconButton>\n )\n : resolvedSchema === undefined\n ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"disabled\" fontSize=\"inherit\" />\n </IconButton>\n )\n : (\n <IconButton rel=\"noopener noreferrer\" size=\"small\" target=\"_blank\" href={resolvedSchema?.huri?.href ?? ''}>\n <VerifiedIcon color=\"success\" fontSize=\"inherit\" />\n </IconButton>\n )\n\n : null}\n {value\n ? (\n <>\n {showLinkNames\n ? (\n <LinkEx display=\"block\" width=\"100%\" sx={{ cursor: 'pointer' }}>\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n </LinkEx>\n )\n : <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />}\n {showOpenNewWindowLink\n ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch, true)}>\n <OpenInNewIcon fontSize=\"inherit\" />\n </IconButton>\n )\n : null}\n </>\n )\n : null}\n </Property>\n )\n },\n)\n\nSchemaProperty.displayName = 'SchemaProperty'\n","import { MenuItem, Typography } from '@mui/material'\nimport type { SelectExProps } from '@xylabs/react-select'\nimport { SelectEx } from '@xylabs/react-select'\nimport React from 'react'\n\nimport { useSchema } from '../../contexts/index.ts'\n\nexport type SchemaSelectExProps = SelectExProps<string>\n\nexport const SchemaSelectEx: React.FC<SchemaSelectExProps> = ({\n onChange, variant = 'outlined', ...props\n}) => {\n const {\n schema, setSchema, schemaList,\n } = useSchema(false)\n\n return (\n <SelectEx\n variant={variant}\n size=\"small\"\n value={schema ?? 'none'}\n onChange={(event, child) => {\n if (event.target.value !== schema) {\n onChange?.(event, child)\n setSchema?.(event.target.value)\n }\n }}\n renderValue={(value) => {\n return <Typography>{value === 'none' ? '- None -' : value}</Typography>\n }}\n {...props}\n >\n {schemaList?.map((schema, index) => {\n return (\n <MenuItem key={index} value={schema}>\n {schema}\n </MenuItem>\n )\n })}\n <MenuItem key=\"none\" value=\"none\">\n - None -\n </MenuItem>\n </SelectEx>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport type { SchemaContextState } from './State.ts'\n\nexport const SchemaContext = createContextEx<SchemaContextState>()\n","import { exists } from '@xylabs/exists'\nimport type { WithChildren } from '@xylabs/react-shared'\nimport React, {\n useEffect, useMemo, useState,\n} from 'react'\n\nimport { useSchemaStats } from '../../../hooks/index.ts'\nimport { SchemaContext } from '../Context.ts'\nimport type { SchemaProviderProps } from './Props.ts'\n\nexport const SchemaMemoryProvider: React.FC<WithChildren<SchemaProviderProps>> = ({\n defaultSchema, knownSchemaList, ...props\n}) => {\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 = (fetchedSchemaStats.map(({ name }) => name)).filter(exists)\n setSchemaList(schemaList)\n }\n }, [fetchedSchemaStats])\n\n const value = useMemo(() => ({\n provided: true, schema, schemaList: knownSchemaList ?? schemaList, setSchema, setSchemaList,\n }), [schema, schemaList, knownSchemaList])\n\n return <SchemaContext.Provider value={value} {...props} />\n}\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { ModuleError } from '@xyo-network/payload-model'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport type { SchemaCacheEntry } from '@xyo-network/schema-cache'\nimport { SchemaCache } from '@xyo-network/schema-cache'\nimport type { SchemaPayload } from '@xyo-network/schema-payload-plugin'\nimport { useState } from 'react'\n\n/**\n * Gets a Huri and schema payload from a schema string\n */\nconst useGetSchemaPayload = (schema?: string) => {\n const [notFound, setNotFound] = useState(false)\n const [xyoError, setError] = useState<ModuleError>()\n const [schemaCacheEntry, setSchemaCacheEntry] = useState<SchemaCacheEntry | null | undefined>()\n const [schemaLocal, setSchemaLocal] = useState<string>()\n\n useAsyncEffect(\n async (mounted) => {\n const firstRequest = !notFound && !schemaCacheEntry && !xyoError\n const schemaChanged = schema !== schemaLocal\n\n if ((schema && firstRequest) || (schema && schemaChanged)) {\n try {\n const schemaCacheEntry = await SchemaCache.instance.get(schema)\n if (mounted()) {\n setSchemaCacheEntry(schemaCacheEntry)\n setNotFound(schemaCacheEntry === null || schemaCacheEntry === undefined)\n }\n } catch (e) {\n const error = e as Error\n console.error(e)\n if (mounted()) {\n setError({\n message: error.message, schema: ModuleErrorSchema, sources: [],\n })\n }\n }\n }\n if (schemaChanged) {\n setSchemaLocal(schema)\n }\n },\n [xyoError, notFound, schema, schemaLocal, schemaCacheEntry],\n )\n\n return {\n notFound,\n schemaHuri: schemaCacheEntry?.huri,\n schemaPayload:\n schemaCacheEntry ? new PayloadBuilder<SchemaPayload>(schemaCacheEntry?.payload).fields(schemaCacheEntry.payload).build() : schemaCacheEntry,\n xyoError,\n }\n}\n\nexport { useGetSchemaPayload }\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { SchemaCache } from '@xyo-network/schema-cache'\nimport type { SchemaPayload } from '@xyo-network/schema-payload-plugin'\nimport { useState } from 'react'\n\nexport type SchemaList = { name: string }\n\nexport const useSchemaDefinitions = (schemaList?: SchemaList[]): SchemaPayload[] | undefined => {\n const [schemaPayloads, setSchemaPayloads] = useState<SchemaPayload[]>()\n useAsyncEffect(\n async (mounted) => {\n if (schemaList) {\n const promiseResults = await Promise.allSettled(schemaList?.map(({ name }) => SchemaCache.instance.get(name)))\n if (mounted()) {\n setSchemaPayloads(\n promiseResults\n .map(result => (result.status === 'fulfilled' ? result.value?.payload : undefined))\n .filter(item => item !== undefined && item !== null) as SchemaPayload[],\n )\n }\n }\n },\n [schemaList],\n )\n return schemaPayloads\n}\n","import type { Address } from '@xylabs/hex'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport type { SchemaListPayload, SchemaListQueryPayload } from '@xyo-network/diviner-schema-list-model'\nimport { SchemaListQuerySchema } from '@xyo-network/diviner-schema-list-model'\nimport type { WithMeta } from '@xyo-network/payload-model'\nimport { useWeakDivinerFromNode } from '@xyo-network/react-diviner'\nimport {\n useEffect, useMemo, useState,\n} from 'react'\n\nexport const useSchemaList = (address?: Address, nameOrAddress = 'SchemaListDiviner'): [SchemaListPayload | null | undefined, Error | undefined] => {\n const [schemaList, setSchemaList] = useState<SchemaListPayload | null>()\n const [error, setError] = useState<Error>()\n const [diviner, divinerError] = useWeakDivinerFromNode(nameOrAddress)\n\n const query: SchemaListQueryPayload[] | undefined = useMemo(\n () =>\n address\n ? [\n {\n address,\n schema: SchemaListQuerySchema,\n },\n ]\n : undefined,\n [address],\n )\n\n useEffect(() => {\n if (diviner === null) {\n setSchemaList(null)\n setError(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n async (mounted) => {\n const divinerInstance = diviner?.deref()\n if (divinerInstance) {\n try {\n const response = (await divinerInstance.divine(query)) as WithMeta<SchemaListPayload>[]\n if (mounted()) {\n setSchemaList(response?.[0])\n setError(undefined)\n }\n } catch (e) {\n setError(e as Error)\n setSchemaList(undefined)\n }\n }\n },\n [diviner, divinerError, query],\n )\n return [schemaList, error]\n}\n","import type { Address } from '@xylabs/hex'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport type {\n SchemaStatsPayload,\n SchemaStatsQueryPayload,\n} from '@xyo-network/diviner-schema-stats-model'\nimport {\n SchemaStatsDivinerSchema,\n SchemaStatsQuerySchema,\n} from '@xyo-network/diviner-schema-stats-model'\nimport { TYPES } from '@xyo-network/node-core-types'\nimport type { WithMeta, WithSources } from '@xyo-network/payload-model'\nimport { isPayloadOfSchemaTypeWithMeta } from '@xyo-network/payload-model'\nimport { useWeakDivinerFromNode } from '@xyo-network/react-diviner'\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useMemo, useState } from 'react'\n\nexport const useSchemaStats = (\n statsAddress?: Address,\n nameOrAddress = TYPES.SchemaStatsDiviner,\n): [SchemaStatsPayload[] | undefined, Error | undefined, Dispatch<SetStateAction<number>>] => {\n const [refresh, setRefresh] = useState(1)\n const [diviner, divinerError] = useWeakDivinerFromNode(nameOrAddress)\n const [error, setError] = useState<Error>()\n const refreshHistory = () => setRefresh(previous => previous + 1)\n\n const [schemaList, setSchemaList] = useState<WithSources<WithMeta<SchemaStatsPayload>>[]>()\n\n const query: SchemaStatsQueryPayload = useMemo(\n () => ({\n address: statsAddress,\n schema: SchemaStatsQuerySchema,\n }),\n [statsAddress],\n )\n\n useAsyncEffect(\n async (mounted) => {\n const instance = diviner?.deref()\n if (instance) {\n if (divinerError) {\n if (mounted()) {\n setError(divinerError)\n setSchemaList(undefined)\n }\n } else {\n try {\n const schemas = (await instance.divine([query])).filter(isPayloadOfSchemaTypeWithMeta(SchemaStatsDivinerSchema)) as WithSources<\n WithMeta<SchemaStatsPayload>\n >[]\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 type { WithChildren } from '@xylabs/react-shared'\nimport React, {\n useCallback, useEffect, useMemo,\n} from 'react'\nimport { useSearchParams } from 'react-router-dom'\n\nimport { SchemaContext } from '../Context.ts'\nimport { useSchema } from '../use.ts'\nimport { SchemaMemoryProvider } from './Memory.tsx'\nimport type { SchemaProviderProps } from './Props.ts'\n\nconst SchemaRouteProviderInner: React.FC<WithChildren> = ({ children }) => {\n const {\n schema, setSchema, schemaList,\n } = 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 const value = useMemo(() => ({\n provided: true, schema, schemaList, setSchema: setSchemaLocal,\n }), [schema, schemaList, setSchemaLocal])\n\n return <SchemaContext.Provider value={value}>{children}</SchemaContext.Provider>\n}\n\nexport const SchemaRouteProvider: React.FC<WithChildren<SchemaProviderProps>> = ({\n knownSchemaList, defaultSchema, ...props\n}) => {\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.ts'\nimport type { SchemaContextState } from './State.ts'\n\nexport const useSchema = (required = false) => {\n return useContextEx<SchemaContextState>(SchemaContext, 'Schema', required)\n}\n"],"mappings":";;;;AAAA,SACEA,eAAeC,iBAAiBC,aAAaC,eAAeC,YAAYC,oBACnE;AACP,SAASC,kBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,cAAc;AAEvB,SAASC,gBAAgB;AAEzB,SAASC,UAAUC,qBAAqB;AAExC,SAASC,mBAAmB;AAC5B,OAAOC,SAASC,YAAYC,gBAAgB;AAS5C,IAAMC,mBAAmB,wBAACC,WAAAA;AACxB,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAAA;AAC1BC,iBACE,OAAOC,YAAAA;AACL,QAAIL,QAAQ;AACV,YAAMC,SAAQ,MAAMK,YAAYC,SAASC,IAAIR,MAAAA;AAC7C,UAAIK,QAAAA,GAAW;AACbH,iBAASD,MAAAA;MACX;IACF;EACF,GACA;IAACD;GAAO;AAEV,SAAOC;AACT,GAdyB;AAgBlB,IAAMQ,iBAAiBC,2BAC5B,CAAC,EACCC,gBAAgB,MAAMC,wBAAwB,MAAMC,iBAAiB,MAAMC,YAAYC,OAAO,GAAGC,MAAAA,GAChGC,QAAAA;AACD,QAAMC,iBAAiBnB,iBAAiBgB,KAAAA;AACxC,QAAM,CAACI,WAAWC,cAAAA,IAAkBC,SAAAA;AACpC,QAAM,CAACC,QAAQC,WAAAA,IAAeF,SAAAA;AAE9B,QAAMG,UAAU,wBAACC,UAAsDC,gBAAgB,UAAK;AAC1FD,eACE,UACA,SACAE,KAAKC,UAAU;MACbF;MACA1B,QAAQe;IACV,CAAA,CAAA;EAEJ,GATgB;AAWhB,SACE,sBAAA,cAACc,UAAAA;IAASZ;IAAUa,OAAM;IAASf;IAAcgB,KAAI;IAA+BjB;IAAyB,GAAGE;KAC7GD,SAASF,iBACNK,mBAAmB,OAEf,sBAAA,cAACc,Y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,MAAME,OAAOH,UAAUP,QAAQ;AACjCH,mBAAWW,OAAOC,KAAAA;AAClBR,oBAAYO,MAAME,OAAOH,KAAK;MAChC;IACF,GALU;IAMVI,aAAa,wBAACJ,UAAAA;AACZ,aAAO,gBAAAH,OAAA,cAACQ,YAAAA,MAAYL,UAAU,SAAS,aAAaA,KAAAA;IACtD,GAFa;IAGZ,GAAGR;KAEHG,YAAYW,IAAI,CAACb,SAAQc,UAAAA;AACxB,WACE,gBAAAV,OAAA,cAACW,UAAAA;MAASC,KAAKF;MAAOP,OAAOP;OAC1BA,OAAAA;EAGP,CAAA,GACA,gBAAAI,OAAA,cAACW,UAAAA;IAASC,KAAI;IAAOT,OAAM;KAAO,UAAA,CAAA;AAKxC,GAnC6D;","names":["NewReleases","NewReleasesIcon","OpenInNew","OpenInNewIcon","Verified","VerifiedIcon","IconButton","useAsyncEffect","LinkEx","useEvent","Property","PropertyValue","SchemaCache","React","forwardRef","useState","useResolveSchema","schema","entry","setEntry","useState","useAsyncEffect","mounted","SchemaCache","instance","get","SchemaProperty","forwardRef","showLinkNames","showOpenNewWindowLink","showStatusIcon","titleProps","value","props","ref","resolvedSchema","buttonRef","buttonDispatch","useEvent","divRef","divDispatch","onClick","dispatch","openNewWindow","JSON","stringify","Property","title","tip","IconButton","size","NewReleasesIcon","color","fontSize","undefined","rel","target","href","huri","VerifiedIcon","LinkEx","display","width","sx","cursor","PropertyValue","OpenInNewIcon","displayName","MenuItem","Typography","SelectEx","React","createContextEx","SchemaContext","exists","React","useEffect","useMemo","useState","useAsyncEffect","PayloadBuilder","ModuleErrorSchema","SchemaCache","useState","useGetSchemaPayload","schema","notFound","setNotFound","useState","xyoError","setError","schemaCacheEntry","setSchemaCacheEntry","schemaLocal","setSchemaLocal","useAsyncEffect","mounted","firstRequest","schemaChanged","SchemaCache","instance","get","undefined","e","error","console","message","ModuleErrorSchema","sources","schemaHuri","huri","schemaPayload","PayloadBuilder","payload","fields","build","useAsyncEffect","SchemaCache","useState","useSchemaDefinitions","schemaList","schemaPayloads","setSchemaPayloads","useState","useAsyncEffect","mounted","promiseResults","Promise","allSettled","map","name","SchemaCache","instance","get","result","status","value","payload","undefined","filter","item","useAsyncEffect","SchemaListQuerySchema","useWeakDivinerFromNode","useEffect","useMemo","useState","useSchemaList","address","nameOrAddress","schemaList","setSchemaList","useState","error","setError","diviner","divinerError","useWeakDivinerFromNode","query","useMemo","schema","SchemaListQuerySchema","undefined","useEffect","useAsyncEffect","mounted","divinerInstance","deref","response","divine","e","useAsyncEffect","SchemaStatsDivinerSchema","SchemaStatsQuerySchema","TYPES","isPayloadOfSchemaTypeWithMeta","useWeakDivinerFromNode","useMemo","useState","useSchemaStats","statsAddress","nameOrAddress","TYPES","SchemaStatsDiviner","refresh","setRefresh","useState","diviner","divinerError","useWeakDivinerFromNode","error","setError","refreshHistory","previous","schemaList","setSchemaList","query","useMemo","address","schema","SchemaStatsQuerySchema","useAsyncEffect","mounted","instance","deref","undefined","schemas","divine","filter","isPayloadOfSchemaTypeWithMeta","SchemaStatsDivinerSchema","ex","SchemaMemoryProvider","defaultSchema","knownSchemaList","props","schema","setSchema","useState","schemaList","setSchemaList","fetchedSchemaStats","useSchemaStats","useEffect","map","name","filter","exists","value","useMemo","provided","React","SchemaContext","Provider","React","useCallback","useEffect","useMemo","useSearchParams","useContextEx","useSchema","required","useContextEx","SchemaContext","SchemaRouteProviderInner","children","schema","setSchema","schemaList","useSchema","params","setParams","useSearchParams","routeSchema","get","setSchemaParam","useCallback","set","replace","delete","setSchemaLocal","useEffect","undefined","value","useMemo","provided","React","SchemaContext","Provider","SchemaRouteProvider","knownSchemaList","defaultSchema","props","SchemaMemoryProvider","SchemaSelectEx","onChange","variant","props","schema","setSchema","schemaList","useSchema","React","SelectEx","size","value","event","child","target","renderValue","Typography","map","index","MenuItem","key"]}
1
+ {"version":3,"sources":["../../src/components/Property/SchemaProperty.tsx","../../src/components/SelectEx/SchemaSelectEx.tsx","../../src/contexts/Schema/Context.ts","../../src/contexts/Schema/Provider/Memory.tsx","../../src/hooks/useGetSchema.tsx","../../src/hooks/useSchemaDefinitions.tsx","../../src/hooks/useSchemaList.tsx","../../src/hooks/useSchemaStats.tsx","../../src/contexts/Schema/Provider/Route.tsx","../../src/contexts/Schema/use.ts"],"sourcesContent":["import {\n NewReleases as NewReleasesIcon, OpenInNew as OpenInNewIcon, Verified as VerifiedIcon,\n} from '@mui/icons-material'\nimport { IconButton } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { LinkEx } from '@xylabs/react-link'\nimport type { EventDispatch, EventNoun } from '@xyo-network/react-event'\nimport { useEvent } from '@xyo-network/react-event'\nimport type { PropertyProps } from '@xyo-network/react-property'\nimport { Property, PropertyValue } from '@xyo-network/react-property'\nimport type { SchemaCacheEntry } from '@xyo-network/schema-cache'\nimport { SchemaCache } from '@xyo-network/schema-cache'\nimport React, { forwardRef, useState } from 'react'\n\nexport type SchemaPropertyProps = PropertyProps & {\n showLinkNames?: boolean\n showOpenNewWindowLink?: boolean\n showStatusIcon?: boolean\n value?: string\n}\n\nconst useResolveSchema = (schema?: string) => {\n const [entry, setEntry] = useState<SchemaCacheEntry | null>()\n useAsyncEffect(\n async (mounted) => {\n if (schema) {\n const entry = await SchemaCache.instance.get(schema)\n if (mounted()) {\n setEntry(entry)\n }\n }\n },\n [schema],\n )\n return entry\n}\n\nexport const SchemaProperty = forwardRef<HTMLDivElement, SchemaPropertyProps>(\n ({\n showLinkNames = true, showOpenNewWindowLink = true, showStatusIcon = true, titleProps, value, ...props\n }, ref) => {\n const resolvedSchema = useResolveSchema(value)\n const [buttonRef, buttonDispatch] = useEvent<HTMLButtonElement>()\n const [divRef, divDispatch] = useEvent<HTMLDivElement>()\n\n const onClick = (dispatch?: EventDispatch<EventNoun, 'click', string>, openNewWindow = false) => {\n dispatch?.(\n 'schema',\n 'click',\n JSON.stringify({\n openNewWindow,\n schema: value,\n }),\n )\n }\n\n return (\n <Property ref={ref} title=\"Schema\" value={value} tip=\"Schema sent with the payload\" titleProps={titleProps} {...props}>\n {value && showStatusIcon\n ? resolvedSchema === null\n ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"warning\" fontSize=\"inherit\" />\n </IconButton>\n )\n : resolvedSchema === undefined\n ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch)}>\n <NewReleasesIcon color=\"disabled\" fontSize=\"inherit\" />\n </IconButton>\n )\n : (\n <IconButton rel=\"noopener noreferrer\" size=\"small\" target=\"_blank\" href={resolvedSchema?.huri?.href ?? ''}>\n <VerifiedIcon color=\"success\" fontSize=\"inherit\" />\n </IconButton>\n )\n\n : null}\n {value\n ? (\n <>\n {showLinkNames\n ? (\n <LinkEx display=\"block\" width=\"100%\" sx={{ cursor: 'pointer' }}>\n <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />\n </LinkEx>\n )\n : <PropertyValue ref={divRef} value={value} title=\"view schema\" onClick={() => onClick(divDispatch)} />}\n {showOpenNewWindowLink\n ? (\n <IconButton ref={buttonRef} size=\"small\" onClick={() => onClick(buttonDispatch, true)}>\n <OpenInNewIcon fontSize=\"inherit\" />\n </IconButton>\n )\n : null}\n </>\n )\n : null}\n </Property>\n )\n },\n)\n\nSchemaProperty.displayName = 'SchemaProperty'\n","import { MenuItem, Typography } from '@mui/material'\nimport type { SelectExProps } from '@xylabs/react-select'\nimport { SelectEx } from '@xylabs/react-select'\nimport React from 'react'\n\nimport { useSchema } from '../../contexts/index.ts'\n\nexport type SchemaSelectExProps = SelectExProps<string>\n\nexport const SchemaSelectEx: React.FC<SchemaSelectExProps> = ({\n onChange, variant = 'outlined', ...props\n}) => {\n const {\n schema, setSchema, schemaList,\n } = useSchema(false)\n\n return (\n <SelectEx\n variant={variant}\n size=\"small\"\n value={schema ?? 'none'}\n onChange={(event, child) => {\n if (event.target.value !== schema) {\n onChange?.(event, child)\n setSchema?.(event.target.value)\n }\n }}\n renderValue={(value) => {\n return <Typography>{value === 'none' ? '- None -' : value}</Typography>\n }}\n {...props}\n >\n {schemaList?.map((schema, index) => {\n return (\n <MenuItem key={index} value={schema}>\n {schema}\n </MenuItem>\n )\n })}\n <MenuItem key=\"none\" value=\"none\">\n - None -\n </MenuItem>\n </SelectEx>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport type { SchemaContextState } from './State.ts'\n\nexport const SchemaContext = createContextEx<SchemaContextState>()\n","import { exists } from '@xylabs/exists'\nimport type { WithChildren } from '@xylabs/react-shared'\nimport React, {\n useEffect, useMemo, useState,\n} from 'react'\n\nimport { useSchemaStats } from '../../../hooks/index.ts'\nimport { SchemaContext } from '../Context.ts'\nimport type { SchemaProviderProps } from './Props.ts'\n\nexport const SchemaMemoryProvider: React.FC<WithChildren<SchemaProviderProps>> = ({\n defaultSchema, knownSchemaList, ...props\n}) => {\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 = (fetchedSchemaStats.map(({ name }) => name)).filter(exists)\n setSchemaList(schemaList)\n }\n }, [fetchedSchemaStats])\n\n const value = useMemo(() => ({\n provided: true, schema, schemaList: knownSchemaList ?? schemaList, setSchema, setSchemaList,\n }), [schema, schemaList, knownSchemaList])\n\n return <SchemaContext.Provider value={value} {...props} />\n}\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { ModuleError } from '@xyo-network/payload-model'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport type { SchemaCacheEntry } from '@xyo-network/schema-cache'\nimport { SchemaCache } from '@xyo-network/schema-cache'\nimport type { SchemaPayload } from '@xyo-network/schema-payload-plugin'\nimport { useState } from 'react'\n\n/**\n * Gets a Huri and schema payload from a schema string\n */\nconst useGetSchemaPayload = (schema?: string) => {\n const [notFound, setNotFound] = useState(false)\n const [xyoError, setError] = useState<ModuleError>()\n const [schemaCacheEntry, setSchemaCacheEntry] = useState<SchemaCacheEntry | null | undefined>()\n const [schemaLocal, setSchemaLocal] = useState<string>()\n\n useAsyncEffect(\n async (mounted) => {\n const firstRequest = !notFound && !schemaCacheEntry && !xyoError\n const schemaChanged = schema !== schemaLocal\n\n if ((schema && firstRequest) || (schema && schemaChanged)) {\n try {\n const schemaCacheEntry = await SchemaCache.instance.get(schema)\n if (mounted()) {\n setSchemaCacheEntry(schemaCacheEntry)\n setNotFound(schemaCacheEntry === null || schemaCacheEntry === undefined)\n }\n } catch (e) {\n const error = e as Error\n console.error(e)\n if (mounted()) {\n setError({\n message: error.message, schema: ModuleErrorSchema, sources: [],\n })\n }\n }\n }\n if (schemaChanged) {\n setSchemaLocal(schema)\n }\n },\n [xyoError, notFound, schema, schemaLocal, schemaCacheEntry],\n )\n\n return {\n notFound,\n schemaHuri: schemaCacheEntry?.huri,\n schemaPayload:\n schemaCacheEntry ? new PayloadBuilder<SchemaPayload>(schemaCacheEntry?.payload).fields(schemaCacheEntry.payload).build() : schemaCacheEntry,\n xyoError,\n }\n}\n\nexport { useGetSchemaPayload }\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { SchemaCache } from '@xyo-network/schema-cache'\nimport type { SchemaPayload } from '@xyo-network/schema-payload-plugin'\nimport { useState } from 'react'\n\nexport type SchemaList = { name: string }\n\nexport const useSchemaDefinitions = (schemaList?: SchemaList[]): SchemaPayload[] | undefined => {\n const [schemaPayloads, setSchemaPayloads] = useState<SchemaPayload[]>()\n useAsyncEffect(\n async (mounted) => {\n if (schemaList) {\n const promiseResults = await Promise.allSettled(schemaList?.map(({ name }) => SchemaCache.instance.get(name)))\n if (mounted()) {\n setSchemaPayloads(\n promiseResults\n .map(result => (result.status === 'fulfilled' ? result.value?.payload : undefined))\n .filter(item => item !== undefined && item !== null) as SchemaPayload[],\n )\n }\n }\n },\n [schemaList],\n )\n return schemaPayloads\n}\n","import type { Address } from '@xylabs/hex'\nimport { usePromise } from '@xylabs/react-promise'\nimport type { SchemaListPayload, SchemaListQueryPayload } from '@xyo-network/diviner-schema-list-model'\nimport { SchemaListQuerySchema } from '@xyo-network/diviner-schema-list-model'\nimport type { WithMeta } from '@xyo-network/payload-model'\nimport { useWeakDivinerFromNode } from '@xyo-network/react-diviner'\nimport { useMemo } from 'react'\n\nexport const useSchemaList = (address?: Address, nameOrAddress = 'SchemaListDiviner'): [SchemaListPayload | null | undefined, Error | undefined] => {\n const [diviner, divinerError] = useWeakDivinerFromNode(nameOrAddress)\n\n const query: SchemaListQueryPayload[] | undefined = useMemo(\n () =>\n address\n ? [\n {\n address,\n schema: SchemaListQuerySchema,\n },\n ]\n : undefined,\n [address],\n )\n\n const [schemaList, error] = usePromise(\n async () => {\n const divinerInstance = diviner?.deref()\n if (divinerInstance) {\n const response = (await divinerInstance.divine(query)) as WithMeta<SchemaListPayload>[]\n return response.at(0)\n }\n },\n [diviner, divinerError, query],\n )\n return [schemaList, error]\n}\n","import type { Address } from '@xylabs/hex'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport type {\n SchemaStatsPayload,\n SchemaStatsQueryPayload,\n} from '@xyo-network/diviner-schema-stats-model'\nimport {\n SchemaStatsDivinerSchema,\n SchemaStatsQuerySchema,\n} from '@xyo-network/diviner-schema-stats-model'\nimport { TYPES } from '@xyo-network/node-core-types'\nimport type { WithMeta, WithSources } from '@xyo-network/payload-model'\nimport { isPayloadOfSchemaTypeWithMeta } from '@xyo-network/payload-model'\nimport { useWeakDivinerFromNode } from '@xyo-network/react-diviner'\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useMemo, useState } from 'react'\n\nexport const useSchemaStats = (\n statsAddress?: Address,\n nameOrAddress = TYPES.SchemaStatsDiviner,\n): [SchemaStatsPayload[] | undefined, Error | undefined, Dispatch<SetStateAction<number>>] => {\n const [refresh, setRefresh] = useState(1)\n const [diviner, divinerError] = useWeakDivinerFromNode(nameOrAddress)\n const [error, setError] = useState<Error>()\n const refreshHistory = () => setRefresh(previous => previous + 1)\n\n const [schemaList, setSchemaList] = useState<WithSources<WithMeta<SchemaStatsPayload>>[]>()\n\n const query: SchemaStatsQueryPayload = useMemo(\n () => ({\n address: statsAddress,\n schema: SchemaStatsQuerySchema,\n }),\n [statsAddress],\n )\n\n useAsyncEffect(\n async (mounted) => {\n const instance = diviner?.deref()\n if (instance) {\n if (divinerError) {\n if (mounted()) {\n setError(divinerError)\n setSchemaList(undefined)\n }\n } else {\n try {\n const schemas = (await instance.divine([query])).filter(isPayloadOfSchemaTypeWithMeta(SchemaStatsDivinerSchema)) as WithSources<\n WithMeta<SchemaStatsPayload>\n >[]\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 type { WithChildren } from '@xylabs/react-shared'\nimport React, {\n useCallback, useEffect, useMemo,\n} from 'react'\nimport { useSearchParams } from 'react-router-dom'\n\nimport { SchemaContext } from '../Context.ts'\nimport { useSchema } from '../use.ts'\nimport { SchemaMemoryProvider } from './Memory.tsx'\nimport type { SchemaProviderProps } from './Props.ts'\n\nconst SchemaRouteProviderInner: React.FC<WithChildren> = ({ children }) => {\n const {\n schema, setSchema, schemaList,\n } = 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 const value = useMemo(() => ({\n provided: true, schema, schemaList, setSchema: setSchemaLocal,\n }), [schema, schemaList, setSchemaLocal])\n\n return <SchemaContext.Provider value={value}>{children}</SchemaContext.Provider>\n}\n\nexport const SchemaRouteProvider: React.FC<WithChildren<SchemaProviderProps>> = ({\n knownSchemaList, defaultSchema, ...props\n}) => {\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.ts'\nimport type { SchemaContextState } from './State.ts'\n\nexport const useSchema = (required = false) => {\n return useContextEx<SchemaContextState>(SchemaContext, 'Schema', required)\n}\n"],"mappings":";;;;AAAA,SACEA,eAAeC,iBAAiBC,aAAaC,eAAeC,YAAYC,oBACnE;AACP,SAASC,kBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,cAAc;AAEvB,SAASC,gBAAgB;AAEzB,SAASC,UAAUC,qBAAqB;AAExC,SAASC,mBAAmB;AAC5B,OAAOC,SAASC,YAAYC,gBAAgB;AAS5C,IAAMC,mBAAmB,wBAACC,WAAAA;AACxB,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAAA;AAC1BC,iBACE,OAAOC,YAAAA;AACL,QAAIL,QAAQ;AACV,YAAMC,SAAQ,MAAMK,YAAYC,SAASC,IAAIR,MAAAA;AAC7C,UAAIK,QAAAA,GAAW;AACbH,iBAASD,MAAAA;MACX;IACF;EACF,GACA;IAACD;GAAO;AAEV,SAAOC;AACT,GAdyB;AAgBlB,IAAMQ,iBAAiBC,2BAC5B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,WAAU,IAC3BC,UAAU,KAAA;AAEd,SACE,gBAAAC,OAAA,cAACC,UAAAA;IACCP;IACAQ,MAAK;IACLC,OAAOP,UAAU;IACjBH,UAAU,wBAACW,OAAOC,UAAAA;AAChB,UAAID,MAAME,OAAOH,UAAUP,QAAQ;AACjCH,mBAAWW,OAAOC,KAAAA;AAClBR,oBAAYO,MAAME,OAAOH,KAAK;MAChC;IACF,GALU;IAMVI,aAAa,wBAACJ,UAAAA;AACZ,aAAO,gBAAAH,OAAA,cAACQ,YAAAA,MAAYL,UAAU,SAAS,aAAaA,KAAAA;IACtD,GAFa;IAGZ,GAAGR;KAEHG,YAAYW,IAAI,CAACb,SAAQc,UAAAA;AACxB,WACE,gBAAAV,OAAA,cAACW,UAAAA;MAASC,KAAKF;MAAOP,OAAOP;OAC1BA,OAAAA;EAGP,CAAA,GACA,gBAAAI,OAAA,cAACW,UAAAA;IAASC,KAAI;IAAOT,OAAM;KAAO,UAAA,CAAA;AAKxC,GAnC6D;","names":["NewReleases","NewReleasesIcon","OpenInNew","OpenInNewIcon","Verified","VerifiedIcon","IconButton","useAsyncEffect","LinkEx","useEvent","Property","PropertyValue","SchemaCache","React","forwardRef","useState","useResolveSchema","schema","entry","setEntry","useState","useAsyncEffect","mounted","SchemaCache","instance","get","SchemaProperty","forwardRef","showLinkNames","showOpenNewWindowLink","showStatusIcon","titleProps","value","props","ref","resolvedSchema","buttonRef","buttonDispatch","useEvent","divRef","divDispatch","onClick","dispatch","openNewWindow","JSON","stringify","Property","title","tip","IconButton","size","NewReleasesIcon","color","fontSize","undefined","rel","target","href","huri","VerifiedIcon","LinkEx","display","width","sx","cursor","PropertyValue","OpenInNewIcon","displayName","MenuItem","Typography","SelectEx","React","createContextEx","SchemaContext","exists","React","useEffect","useMemo","useState","useAsyncEffect","PayloadBuilder","ModuleErrorSchema","SchemaCache","useState","useGetSchemaPayload","schema","notFound","setNotFound","useState","xyoError","setError","schemaCacheEntry","setSchemaCacheEntry","schemaLocal","setSchemaLocal","useAsyncEffect","mounted","firstRequest","schemaChanged","SchemaCache","instance","get","undefined","e","error","console","message","ModuleErrorSchema","sources","schemaHuri","huri","schemaPayload","PayloadBuilder","payload","fields","build","useAsyncEffect","SchemaCache","useState","useSchemaDefinitions","schemaList","schemaPayloads","setSchemaPayloads","useState","useAsyncEffect","mounted","promiseResults","Promise","allSettled","map","name","SchemaCache","instance","get","result","status","value","payload","undefined","filter","item","usePromise","SchemaListQuerySchema","useWeakDivinerFromNode","useMemo","useSchemaList","address","nameOrAddress","diviner","divinerError","useWeakDivinerFromNode","query","useMemo","schema","SchemaListQuerySchema","undefined","schemaList","error","usePromise","divinerInstance","deref","response","divine","at","useAsyncEffect","SchemaStatsDivinerSchema","SchemaStatsQuerySchema","TYPES","isPayloadOfSchemaTypeWithMeta","useWeakDivinerFromNode","useMemo","useState","useSchemaStats","statsAddress","nameOrAddress","TYPES","SchemaStatsDiviner","refresh","setRefresh","useState","diviner","divinerError","useWeakDivinerFromNode","error","setError","refreshHistory","previous","schemaList","setSchemaList","query","useMemo","address","schema","SchemaStatsQuerySchema","useAsyncEffect","mounted","instance","deref","undefined","schemas","divine","filter","isPayloadOfSchemaTypeWithMeta","SchemaStatsDivinerSchema","ex","SchemaMemoryProvider","defaultSchema","knownSchemaList","props","schema","setSchema","useState","schemaList","setSchemaList","fetchedSchemaStats","useSchemaStats","useEffect","map","name","filter","exists","value","useMemo","provided","React","SchemaContext","Provider","React","useCallback","useEffect","useMemo","useSearchParams","useContextEx","useSchema","required","useContextEx","SchemaContext","SchemaRouteProviderInner","children","schema","setSchema","schemaList","useSchema","params","setParams","useSearchParams","routeSchema","get","setSchemaParam","useCallback","set","replace","delete","setSchemaLocal","useEffect","undefined","value","useMemo","provided","React","SchemaContext","Provider","SchemaRouteProvider","knownSchemaList","defaultSchema","props","SchemaMemoryProvider","SchemaSelectEx","onChange","variant","props","schema","setSchema","schemaList","useSchema","React","SelectEx","size","value","event","child","target","renderValue","Typography","map","index","MenuItem","key"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/react-schema",
3
- "version": "3.0.15",
3
+ "version": "3.0.17",
4
4
  "description": "Common React library for all XYO projects that use React",
5
5
  "keywords": [
6
6
  "xyo",
@@ -43,24 +43,25 @@
43
43
  "lint-pkg": "npmPkgJsonLint ."
44
44
  },
45
45
  "dependencies": {
46
- "@xylabs/exists": "^4.0.9",
47
- "@xylabs/hex": "^4.0.9",
48
- "@xylabs/react-async-effect": "^4.2.5",
49
- "@xylabs/react-link": "^4.2.5",
50
- "@xylabs/react-select": "^4.2.5",
51
- "@xylabs/react-shared": "^4.2.5",
46
+ "@xylabs/exists": "^4.0.10",
47
+ "@xylabs/hex": "^4.0.10",
48
+ "@xylabs/react-async-effect": "^4.2.12",
49
+ "@xylabs/react-link": "^4.2.12",
50
+ "@xylabs/react-promise": "^4.2.12",
51
+ "@xylabs/react-select": "^4.2.12",
52
+ "@xylabs/react-shared": "^4.2.12",
52
53
  "@xyo-network/diviner-schema-list-model": "^3.1.9",
53
54
  "@xyo-network/diviner-schema-stats-model": "^3.1.9",
54
55
  "@xyo-network/node-core-types": "^3.0.2",
55
56
  "@xyo-network/payload-builder": "^3.1.9",
56
57
  "@xyo-network/payload-model": "^3.1.9",
57
- "@xyo-network/react-diviner": "^3.0.15",
58
- "@xyo-network/react-event": "^3.0.15",
59
- "@xyo-network/react-property": "^3.0.15",
60
- "@xyo-network/react-shared": "^3.0.15",
58
+ "@xyo-network/react-diviner": "^3.0.17",
59
+ "@xyo-network/react-event": "^3.0.17",
60
+ "@xyo-network/react-property": "^3.0.17",
61
+ "@xyo-network/react-shared": "^3.0.17",
61
62
  "@xyo-network/schema-cache": "^3.1.9",
62
63
  "@xyo-network/schema-payload-plugin": "^3.1.9",
63
- "react-router-dom": "^6.26.1"
64
+ "react-router-dom": "^6.26.2"
64
65
  },
65
66
  "devDependencies": {
66
67
  "@emotion/react": "^11.13.3",
@@ -69,20 +70,21 @@
69
70
  "@mui/material": "^5.16.7",
70
71
  "@mui/styles": "^5.16.7",
71
72
  "@storybook/react": "^8.2.9",
72
- "@xylabs/react-flexbox": "^4.2.5",
73
+ "@xylabs/react-flexbox": "^4.2.12",
74
+ "@xylabs/react-hooks": "^4.2.12",
73
75
  "@xylabs/ts-scripts-yarn3": "^4.0.7",
74
76
  "@xylabs/tsconfig-react": "^4.0.7",
75
77
  "@xyo-network/bridge-http": "^3.1.9",
76
78
  "@xyo-network/node-memory": "^3.1.9",
77
79
  "@xyo-network/node-model": "^3.1.9",
78
- "@xyo-network/react-node": "^3.0.15",
79
- "@xyo-network/react-payload-raw-info": "^3.0.15",
80
- "@xyo-network/react-storybook": "^3.0.15",
81
- "@xyo-network/react-wallet": "^3.0.15",
80
+ "@xyo-network/react-node": "^3.0.17",
81
+ "@xyo-network/react-payload-raw-info": "^3.0.17",
82
+ "@xyo-network/react-storybook": "^3.0.17",
83
+ "@xyo-network/react-wallet": "^3.0.17",
82
84
  "react": "^18.3.1",
83
85
  "react-dom": "^18.3.1",
84
86
  "storybook": "^8.2.9",
85
- "typescript": "^5.5.4"
87
+ "typescript": "^5.6.2"
86
88
  },
87
89
  "peerDependencies": {
88
90
  "@emotion/react": "^11",
@@ -3,9 +3,10 @@ import {
3
3
  } from '@mui/material'
4
4
  import type { Meta, StoryFn } from '@storybook/react'
5
5
  import { FlexRow } from '@xylabs/react-flexbox'
6
+ import { useResetState } from '@xylabs/react-hooks'
6
7
  import { JsonViewerEx } from '@xyo-network/react-payload-raw-info'
7
8
  import { SchemaCache } from '@xyo-network/schema-cache'
8
- import React, { useEffect, useState } from 'react'
9
+ import React from 'react'
9
10
 
10
11
  import { useGetSchemaPayload } from './useGetSchema.tsx'
11
12
 
@@ -13,15 +14,9 @@ SchemaCache.instance.proxy = 'https://beta.api.archivist.xyo.network/domain'
13
14
 
14
15
  const UseGetSchemaComponent: React.FC<{ schema: string }> = ({ schema }) => {
15
16
  const exampleSchemas = ['network.xyo.domain', 'network.xyo.payload', 'network.xyo.schema']
16
- const [schemaFieldValue, setSchemaFieldValue] = useState('')
17
+ const [schemaFieldValue, setSchemaFieldValue] = useResetState(schema)
17
18
  const { schemaPayload } = useGetSchemaPayload(schemaFieldValue)
18
19
 
19
- useEffect(() => {
20
- if (schema) {
21
- setSchemaFieldValue(schema)
22
- }
23
- }, [schema])
24
-
25
20
  return (
26
21
  <>
27
22
  <Typography variant="body1" fontWeight="bold" mb={2}>
@@ -1,16 +1,12 @@
1
1
  import type { Address } from '@xylabs/hex'
2
- import { useAsyncEffect } from '@xylabs/react-async-effect'
2
+ import { usePromise } from '@xylabs/react-promise'
3
3
  import type { SchemaListPayload, SchemaListQueryPayload } from '@xyo-network/diviner-schema-list-model'
4
4
  import { SchemaListQuerySchema } from '@xyo-network/diviner-schema-list-model'
5
5
  import type { WithMeta } from '@xyo-network/payload-model'
6
6
  import { useWeakDivinerFromNode } from '@xyo-network/react-diviner'
7
- import {
8
- useEffect, useMemo, useState,
9
- } from 'react'
7
+ import { useMemo } from 'react'
10
8
 
11
9
  export const useSchemaList = (address?: Address, nameOrAddress = 'SchemaListDiviner'): [SchemaListPayload | null | undefined, Error | undefined] => {
12
- const [schemaList, setSchemaList] = useState<SchemaListPayload | null>()
13
- const [error, setError] = useState<Error>()
14
10
  const [diviner, divinerError] = useWeakDivinerFromNode(nameOrAddress)
15
11
 
16
12
  const query: SchemaListQueryPayload[] | undefined = useMemo(
@@ -26,27 +22,12 @@ export const useSchemaList = (address?: Address, nameOrAddress = 'SchemaListDivi
26
22
  [address],
27
23
  )
28
24
 
29
- useEffect(() => {
30
- if (diviner === null) {
31
- setSchemaList(null)
32
- setError(undefined)
33
- }
34
- }, [diviner])
35
-
36
- useAsyncEffect(
37
- async (mounted) => {
25
+ const [schemaList, error] = usePromise(
26
+ async () => {
38
27
  const divinerInstance = diviner?.deref()
39
28
  if (divinerInstance) {
40
- try {
41
- const response = (await divinerInstance.divine(query)) as WithMeta<SchemaListPayload>[]
42
- if (mounted()) {
43
- setSchemaList(response?.[0])
44
- setError(undefined)
45
- }
46
- } catch (e) {
47
- setError(e as Error)
48
- setSchemaList(undefined)
49
- }
29
+ const response = (await divinerInstance.divine(query)) as WithMeta<SchemaListPayload>[]
30
+ return response.at(0)
50
31
  }
51
32
  },
52
33
  [diviner, divinerError, query],