@deephaven/jsapi-bootstrap 1.3.1-uri.5 → 1.4.1-beta.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.
@@ -15,6 +15,6 @@ export declare const DeferredApiContext: import("react").Context<typeof DhType |
15
15
  * @param widget The widget descriptor or URI to use to fetch the API
16
16
  * @returns A tuple with the API instance, and an error if one occurred.
17
17
  */
18
- export declare function useDeferredApi(widget: DhType.ide.VariableDescriptor | UriVariableDescriptor | null): [dh: typeof DhType | null, error: unknown | null];
18
+ export declare function useDeferredApi(widget: DhType.ide.VariableDescriptor | UriVariableDescriptor | null): [dh: typeof DhType | null, error: NonNullable<unknown> | null];
19
19
  export default useDeferredApi;
20
20
  //# sourceMappingURL=useDeferredApi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDeferredApi.d.ts","sourceRoot":"","sources":["../src/useDeferredApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,GAAG,qBAAqB,KAC9D,OAAO,CAAC,OAAO,MAAM,CAAC,CAAC;AAE5B,eAAO,MAAM,kBAAkB,oEAExB,CAAC;AAER;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,GACnE,CAAC,EAAE,EAAE,OAAO,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC,CAuDnD;AAED,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"useDeferredApi.d.ts","sourceRoot":"","sources":["../src/useDeferredApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,GAAG,qBAAqB,KAC9D,OAAO,CAAC,OAAO,MAAM,CAAC,CAAC;AAE5B,eAAO,MAAM,kBAAkB,oEAExB,CAAC;AAER;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,GACnE,CAAC,EAAE,EAAE,OAAO,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAuDhE;AAED,eAAe,cAAc,CAAC"}
@@ -54,7 +54,7 @@ export function useDeferredApi(widget) {
54
54
  } catch (e) {
55
55
  if (!isCancelled) {
56
56
  setApi(null);
57
- setError(e);
57
+ setError(e !== null && e !== void 0 ? e : new Error('Null error'));
58
58
  }
59
59
  }
60
60
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"useDeferredApi.js","names":["createContext","useContext","useEffect","useState","ApiContext","DeferredApiContext","useDeferredApi","widget","api","setApi","error","setError","deferredApi","contextApi","Error","isCancelled","loadApi","_loadApi","apply","arguments","_asyncToGenerator","newApi","e"],"sources":["../src/useDeferredApi.ts"],"sourcesContent":["import { createContext, useContext, useEffect, useState } from 'react';\nimport type { dh as DhType } from '@deephaven/jsapi-types';\nimport { ApiContext } from './ApiBootstrap';\nimport { type UriVariableDescriptor } from './useObjectFetcher';\n\n/**\n * Function to fetch an API based on a provided descriptor object.\n * Depending on the context there may be more properties on the descriptor,\n * providing more information about the object, such as a session ID.\n * @param descriptor Descriptor object or URI to fetch the API from.\n * @returns A promise that resolves to the API instance for the provided variable descriptor.\n */\nexport type DeferredApiFetcher = (\n descriptor: DhType.ide.VariableDescriptor | UriVariableDescriptor\n) => Promise<typeof DhType>;\n\nexport const DeferredApiContext = createContext<\n typeof DhType | DeferredApiFetcher | null\n>(null);\n\n/**\n * Retrieve the API for the current context, given the widget provided.\n * The API may need to be loaded, and will return `null` until it is ready.\n * @param widget The widget descriptor or URI to use to fetch the API\n * @returns A tuple with the API instance, and an error if one occurred.\n */\nexport function useDeferredApi(\n widget: DhType.ide.VariableDescriptor | UriVariableDescriptor | null\n): [dh: typeof DhType | null, error: unknown | null] {\n const [api, setApi] = useState<typeof DhType | null>(null);\n const [error, setError] = useState<unknown | null>(null);\n const deferredApi = useContext(DeferredApiContext);\n const contextApi = useContext(ApiContext);\n\n useEffect(() => {\n if (deferredApi == null) {\n if (contextApi != null) {\n setApi(contextApi);\n setError(null);\n return;\n }\n setApi(null);\n setError(\n new Error(\n 'No API available in useDeferredApi. Was code wrapped in ApiBootstrap or DeferredApiContext.Provider?'\n )\n );\n return;\n }\n let isCancelled = false;\n\n async function loadApi() {\n if (widget == null) {\n if (!isCancelled) {\n setApi(null);\n setError(new Error('No widget provided to useDeferredApi'));\n }\n } else if (typeof deferredApi === 'function') {\n try {\n const newApi = await deferredApi(widget);\n if (!isCancelled) {\n setApi(newApi);\n setError(null);\n }\n } catch (e) {\n if (!isCancelled) {\n setApi(null);\n setError(e);\n }\n }\n } else {\n setApi(deferredApi);\n }\n }\n\n loadApi();\n\n return () => {\n isCancelled = true;\n };\n }, [contextApi, deferredApi, widget]);\n\n return [api, error];\n}\n\nexport default useDeferredApi;\n"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAAC,SAE9DC,UAAU;AAGnB;AACA;AACA;AACA;AACA;AACA;AACA;AAKA,OAAO,IAAMC,kBAAkB,gBAAGL,aAAa,CAE7C,IAAI,CAAC;;AAEP;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM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AAC;YACb;UACF;QACF,CAAC,MAAM;UACLb,MAAM,CAACG,WAAW,CAAC;QACrB;MACF,CAAC;MAAA,OAAAK,QAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IAEDH,OAAO,CAAC,CAAC;IAET,OAAO,MAAM;MACXD,WAAW,GAAG,IAAI;IACpB,CAAC;EACH,CAAC,EAAE,CAACF,UAAU,EAAED,WAAW,EAAEL,MAAM,CAAC,CAAC;EAErC,OAAO,CAACC,GAAG,EAAEE,KAAK,CAAC;AACrB;AAEA,eAAeJ,cAAc"}
1
+ {"version":3,"file":"useDeferredApi.js","names":["createContext","useContext","useEffect","useState","ApiContext","DeferredApiContext","useDeferredApi","widget","api","setApi","error","setError","deferredApi","contextApi","Error","isCancelled","loadApi","_loadApi","apply","arguments","_asyncToGenerator","newApi","e"],"sources":["../src/useDeferredApi.ts"],"sourcesContent":["import { createContext, useContext, useEffect, useState } from 'react';\nimport type { dh as DhType } from '@deephaven/jsapi-types';\nimport { ApiContext } from './ApiBootstrap';\nimport { type UriVariableDescriptor } from './useObjectFetcher';\n\n/**\n * Function to fetch an API based on a provided descriptor object.\n * Depending on the context there may be more properties on the descriptor,\n * providing more information about the object, such as a session ID.\n * @param descriptor Descriptor object or URI to fetch the API from.\n * @returns A promise that resolves to the API instance for the provided variable descriptor.\n */\nexport type DeferredApiFetcher = (\n descriptor: DhType.ide.VariableDescriptor | UriVariableDescriptor\n) => Promise<typeof DhType>;\n\nexport const DeferredApiContext = createContext<\n typeof DhType | DeferredApiFetcher | null\n>(null);\n\n/**\n * Retrieve the API for the current context, given the widget provided.\n * The API may need to be loaded, and will return `null` until it is ready.\n * @param widget The widget descriptor or URI to use to fetch the API\n * @returns A tuple with the API instance, and an error if one occurred.\n */\nexport function useDeferredApi(\n widget: DhType.ide.VariableDescriptor | UriVariableDescriptor | null\n): [dh: typeof DhType | null, error: NonNullable<unknown> | null] {\n const [api, setApi] = useState<typeof DhType | null>(null);\n const [error, setError] = useState<NonNullable<unknown> | null>(null);\n const deferredApi = useContext(DeferredApiContext);\n const contextApi = useContext(ApiContext);\n\n useEffect(() => {\n if (deferredApi == null) {\n if (contextApi != null) {\n setApi(contextApi);\n setError(null);\n return;\n }\n setApi(null);\n setError(\n new Error(\n 'No API available in useDeferredApi. Was code wrapped in ApiBootstrap or DeferredApiContext.Provider?'\n )\n );\n return;\n }\n let isCancelled = false;\n\n async function loadApi() {\n if (widget == null) {\n if (!isCancelled) {\n setApi(null);\n setError(new Error('No widget provided to useDeferredApi'));\n }\n } else if (typeof deferredApi === 'function') {\n try {\n const newApi = await deferredApi(widget);\n if (!isCancelled) {\n setApi(newApi);\n setError(null);\n }\n } catch (e) {\n if (!isCancelled) {\n setApi(null);\n setError(e ?? new Error('Null error'));\n }\n }\n } else {\n setApi(deferredApi);\n }\n }\n\n loadApi();\n\n return () => {\n isCancelled = true;\n };\n }, [contextApi, deferredApi, widget]);\n\n return [api, error];\n}\n\nexport default useDeferredApi;\n"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAAC,SAE9DC,UAAU;AAGnB;AACA;AACA;AACA;AACA;AACA;AACA;AAKA,OAAO,IAAMC,kBAAkB,gBAAGL,aAAa,CAE7C,IAAI,CAAC;;AAEP;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,cAAcA,CAC5BC,MAAoE,EACJ;EAChE,IAAM,CAACC,GAAG,EAAEC,MAAM,CAAC,GAAGN,QAAQ,CAAuB,IAAI,CAAC;EAC1D,IAAM,CAACO,KAAK,EAAEC,QAAQ,CAAC,GAAGR,QAAQ,CAA8B,IAAI,CAAC;EACrE,IAAMS,WAAW,GAAGX,UAAU,CAACI,kBAAkB,CAAC;EAClD,IAAMQ,UAAU,GAAGZ,UAAU,CAACG,UAAU,CAAC;EAEzCF,SAAS,CAAC,MAAM;IACd,IAAIU,WAAW,IAAI,IAAI,EAAE;MACvB,IAAIC,UAAU,IAAI,IAAI,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AAEA,eAAeJ,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../src/useWidget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAKjD,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAMhE;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,EAAE,CAAC,KAAK,GACR,EAAE,CAAC,SAAS,GACZ,EAAE,CAAC,gBAAgB,GACnB,EAAE,CAAC,IAAI,CAAC,MAAM,GACd,EAAE,CAAC,MAAM,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,EAAE,CAAC,MAAM,IAAI;IAC7D,gCAAgC;IAChC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAEjB,8CAA8C;IAC9C,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEtB,6DAA6D;IAC7D,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CACpC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,EAAE,CAAC,MAAM,EACzD,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,GAAG,qBAAqB,GAC5D,aAAa,CAAC,CAAC,CAAC,CAgFlB;AAED,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../src/useWidget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAKjD,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAMhE;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,EAAE,CAAC,KAAK,GACR,EAAE,CAAC,SAAS,GACZ,EAAE,CAAC,gBAAgB,GACnB,EAAE,CAAC,IAAI,CAAC,MAAM,GACd,EAAE,CAAC,MAAM,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,EAAE,CAAC,MAAM,IAAI;IAC7D,gCAAgC;IAChC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAEjB,8CAA8C;IAC9C,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEtB,6DAA6D;IAC7D,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CACpC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,EAAE,CAAC,MAAM,EACzD,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,GAAG,qBAAqB,GAC5D,aAAa,CAAC,CAAC,CAAC,CA+ElB;AAED,eAAe,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useWidget.js","names":["Log","assertNotNull","useEffect","useMemo","useState","useObjectFetch","useDeferredApi","useApi","log","module","useWidget","descriptor","wrapper","setWrapper","widget","error","objectFetch","descriptorApi","descriptorApiError","defaultApi","api","loadWidget","debug","status","fetch","isCancelled","loadWidgetInternal","_loadWidgetInternal","apply","arguments","_asyncToGenerator","newWidget","debug2","close","exportedObjects","forEach","exportedObject","e","Error","wrapperWithApi","_wrapper$error","_objectSpread"],"sources":["../src/useWidget.ts"],"sourcesContent":["import type { dh } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport { assertNotNull } from '@deephaven/utils';\nimport { useEffect, useMemo, useState } from 'react';\nimport { useObjectFetch } from './useObjectFetch';\nimport { type UriVariableDescriptor } from './useObjectFetcher';\nimport useDeferredApi from './useDeferredApi';\nimport useApi from './useApi';\n\nconst log = Log.module('useWidget');\n\n/**\n * Types of widgets that can be fetched with this hook.\n */\nexport type WidgetTypes =\n | dh.Table\n | dh.TreeTable\n | dh.PartitionedTable\n | dh.plot.Figure\n | dh.Widget;\n\n/**\n * Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.\n */\nexport type WidgetWrapper<T extends WidgetTypes = dh.Widget> = {\n /** Widget object to retrieve */\n widget: T | null;\n\n /** Deephaven JS API to use for this widget */\n api: typeof dh | null;\n\n /** Error status if there was an issue fetching the widget */\n error: NonNullable<unknown> | null;\n};\n\n/**\n * Retrieve a widget for the given variable descriptor. Note that if the widget is successfully fetched, ownership of the widget is passed to the consumer and will need to close the object as well.\n * @param descriptor Descriptor or URI to get the widget for. Should be stable to avoid infinite re-fetching.\n * @returns A WidgetWrapper object that contains the widget and JS API, or an error status if there was an issue fetching the widget. Will contain nulls if still loading.\n */\nexport function useWidget<T extends WidgetTypes = dh.Widget>(\n descriptor: dh.ide.VariableDescriptor | UriVariableDescriptor\n): WidgetWrapper<T> {\n const [wrapper, setWrapper] = useState<\n Omit<WidgetWrapper<T>, 'api' | 'ApiProvider'>\n >(() => ({\n widget: null,\n error: null,\n }));\n const objectFetch = useObjectFetch<T>(descriptor);\n const [descriptorApi, descriptorApiError] = useDeferredApi(descriptor);\n const defaultApi = useApi();\n\n const api = descriptorApi ?? defaultApi;\n\n useEffect(\n function loadWidget() {\n log.debug('loadWidget', descriptor);\n\n const { status } = objectFetch;\n\n if (status === 'error') {\n // We can't fetch if there's an error getting the fetcher, just return an error\n setWrapper({ widget: null, error: objectFetch.error });\n return;\n }\n\n if (status === 'loading') {\n // Still loading\n setWrapper({ widget: null, error: null });\n return;\n }\n\n const { fetch } = objectFetch;\n // We should be able to load the widget. Load it asynchronously, and set the widget when it's done.\n // If we get cancelled before the fetch is done, we should close the widget and its exported objects.\n // If not though, the consumer of the widget is expected to take ownership and close the widget appropriately.\n let isCancelled = false;\n async function loadWidgetInternal() {\n try {\n assertNotNull(fetch);\n const newWidget = await fetch();\n if (isCancelled) {\n log.debug2('loadWidgetInternal cancelled', descriptor, newWidget);\n newWidget.close();\n if ('exportedObjects' in newWidget) {\n newWidget.exportedObjects.forEach(exportedObject => {\n exportedObject.close();\n });\n }\n return;\n }\n log.debug('loadWidgetInternal done', descriptor, newWidget);\n\n setWrapper({ widget: newWidget, error: null });\n } catch (e) {\n if (isCancelled) {\n return;\n }\n log.error('loadWidgetInternal error', descriptor, e);\n setWrapper({ widget: null, error: e ?? new Error('Null error') });\n }\n }\n loadWidgetInternal();\n return () => {\n isCancelled = true;\n };\n },\n [descriptor, objectFetch]\n );\n\n const wrapperWithApi = useMemo(\n () => ({\n ...wrapper,\n error:\n wrapper.error ?? (descriptorApiError as NonNullable<unknown> | null),\n api: wrapper.widget != null ? api : null,\n }),\n [wrapper, api, descriptorApiError]\n );\n\n return wrapperWithApi;\n}\n\nexport default useWidget;\n"],"mappings":";;;;;;;AACA,OAAOA,GAAG,MAAM,gBAAgB;AAChC,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAAC,SAC5CC,cAAc;AAAA,OAEhBC,cAAc;AAAA,OACdC,MAAM;AAEb,IAAMC,GAAG,GAAGR,GAAG,CAACS,MAAM,CAAC,WAAW,CAAC;;AAEnC;AACA;AACA;;AAQA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CACvBC,UAA6D,EAC3C;EAClB,IAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGT,QAAQ,CAEpC,OAAO;IACPU,MAAM,EAAE,IAAI;IACZC,KAAK,EAAE;EACT,CAAC,CAAC,CAAC;EACH,IAAMC,WAAW,GAAGX,cAAc,CAAIM,UAAU,CAAC;EACjD,IAAM,CAACM,aAAa,EAAEC,kBAAkB,CAAC,GAAGZ,cAAc,CAACK,UAAU,CAAC;EACtE,IAAMQ,UAAU,GAAGZ,MAAM,CAAC,CAAC;EAE3B,IAAMa,GAAG,GAAGH,aAAa,aAAbA,aAAa,cAAbA,aAAa,GAAIE,UAAU;EAEvCjB,SAAS,CACP,SAASmB,UAAUA,CAAA,E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,WAAW,EAAE;YACf;UACF;UACAjB,GAAG,CAACO,KAAK,CAAC,0BAA0B,EAAEJ,UAAU,EAAE0B,CAAC,CAAC;UACpDxB,UAAU,CAAC;YAAEC,MAAM,EAAE,IAAI;YAAEC,KAAK,EAAEsB,CAAC,aAADA,CAAC,cAADA,CAAC,GAAI,IAAIC,KAAK,CAAC,YAAY;UAAE,CAAC,CAAC;QACnE;MACF,CAAC;MAAA,OAAAX,mBAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IACDH,kBAAkB,CAAC,CAAC;IACpB,OAAO,MAAM;MACXD,WAAW,GAAG,IAAI;IACpB,CAAC;EACH,CAAC,EACD,CAACd,UAAU,EAAEK,WAAW,CAC1B,CAAC;EAED,IAAMuB,cAAc,GAAGpC,OAAO,CAC5B;IAAA,IAAAqC,cAAA;IAAA,OAAAC,aAAA,CAAAA,aAAA,KACK7B,OAAO;MACVG,KAAK,GAAAyB,cAAA,GACH5B,OAAO,CAACG,KAAK,cAAAyB,cAAA,cAAAA,cAAA,GAAKtB,kBAAkD;MACtEE,GAAG,EAAER,OAAO,CAACE,MAAM,IAAI,IAAI,GAAGM,GAAG,GAAG;IAAI;EAAA,CACxC,EACF,CAACR,OAAO,EAAEQ,GAAG,EAAEF,kBAAkB,CACnC,CAAC;EAED,OAAOqB,cAAc;AACvB;AAEA,eAAe7B,SAAS"}
1
+ {"version":3,"file":"useWidget.js","names":["Log","assertNotNull","useEffect","useMemo","useState","useObjectFetch","useDeferredApi","useApi","log","module","useWidget","descriptor","wrapper","setWrapper","widget","error","objectFetch","descriptorApi","descriptorApiError","defaultApi","api","loadWidget","debug","status","fetch","isCancelled","loadWidgetInternal","_loadWidgetInternal","apply","arguments","_asyncToGenerator","newWidget","debug2","close","exportedObjects","forEach","exportedObject","e","Error","wrapperWithApi","_wrapper$error","_objectSpread"],"sources":["../src/useWidget.ts"],"sourcesContent":["import type { dh } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport { assertNotNull } from '@deephaven/utils';\nimport { useEffect, useMemo, useState } from 'react';\nimport { useObjectFetch } from './useObjectFetch';\nimport { type UriVariableDescriptor } from './useObjectFetcher';\nimport useDeferredApi from './useDeferredApi';\nimport useApi from './useApi';\n\nconst log = Log.module('useWidget');\n\n/**\n * Types of widgets that can be fetched with this hook.\n */\nexport type WidgetTypes =\n | dh.Table\n | dh.TreeTable\n | dh.PartitionedTable\n | dh.plot.Figure\n | dh.Widget;\n\n/**\n * Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.\n */\nexport type WidgetWrapper<T extends WidgetTypes = dh.Widget> = {\n /** Widget object to retrieve */\n widget: T | null;\n\n /** Deephaven JS API to use for this widget */\n api: typeof dh | null;\n\n /** Error status if there was an issue fetching the widget */\n error: NonNullable<unknown> | null;\n};\n\n/**\n * Retrieve a widget for the given variable descriptor. Note that if the widget is successfully fetched, ownership of the widget is passed to the consumer and will need to close the object as well.\n * @param descriptor Descriptor or URI to get the widget for. Should be stable to avoid infinite re-fetching.\n * @returns A WidgetWrapper object that contains the widget and JS API, or an error status if there was an issue fetching the widget. Will contain nulls if still loading.\n */\nexport function useWidget<T extends WidgetTypes = dh.Widget>(\n descriptor: dh.ide.VariableDescriptor | UriVariableDescriptor\n): WidgetWrapper<T> {\n const [wrapper, setWrapper] = useState<\n Omit<WidgetWrapper<T>, 'api' | 'ApiProvider'>\n >(() => ({\n widget: null,\n error: null,\n }));\n const objectFetch = useObjectFetch<T>(descriptor);\n const [descriptorApi, descriptorApiError] = useDeferredApi(descriptor);\n const defaultApi = useApi();\n\n const api = descriptorApi ?? defaultApi;\n\n useEffect(\n function loadWidget() {\n log.debug('loadWidget', descriptor);\n\n const { status } = objectFetch;\n\n if (status === 'error') {\n // We can't fetch if there's an error getting the fetcher, just return an error\n setWrapper({ widget: null, error: objectFetch.error });\n return;\n }\n\n if (status === 'loading') {\n // Still loading\n setWrapper({ widget: null, error: null });\n return;\n }\n\n const { fetch } = objectFetch;\n // We should be able to load the widget. Load it asynchronously, and set the widget when it's done.\n // If we get cancelled before the fetch is done, we should close the widget and its exported objects.\n // If not though, the consumer of the widget is expected to take ownership and close the widget appropriately.\n let isCancelled = false;\n async function loadWidgetInternal() {\n try {\n assertNotNull(fetch);\n const newWidget = await fetch();\n if (isCancelled) {\n log.debug2('loadWidgetInternal cancelled', descriptor, newWidget);\n newWidget.close();\n if ('exportedObjects' in newWidget) {\n newWidget.exportedObjects.forEach(exportedObject => {\n exportedObject.close();\n });\n }\n return;\n }\n log.debug('loadWidgetInternal done', descriptor, newWidget);\n\n setWrapper({ widget: newWidget, error: null });\n } catch (e) {\n if (isCancelled) {\n return;\n }\n log.error('loadWidgetInternal error', descriptor, e);\n setWrapper({ widget: null, error: e ?? new Error('Null error') });\n }\n }\n loadWidgetInternal();\n return () => {\n isCancelled = true;\n };\n },\n [descriptor, objectFetch]\n );\n\n const wrapperWithApi = useMemo(\n () => ({\n ...wrapper,\n error: wrapper.error ?? descriptorApiError,\n api: wrapper.widget != null ? api : null,\n }),\n [wrapper, api, descriptorApiError]\n );\n\n return wrapperWithApi;\n}\n\nexport default useWidget;\n"],"mappings":";;;;;;;AACA,OAAOA,GAAG,MAAM,gBAAgB;AAChC,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAAC,SAC5CC,cAAc;AAAA,OAEhBC,cAAc;AAAA,OACdC,MAAM;AAEb,IAAMC,GAAG,GAAGR,GAAG,CAACS,MAAM,CAAC,WAAW,CAAC;;AAEnC;AACA;AACA;;AAQA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CACvBC,UAA6D,EAC3C;EAClB,IAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGT,QAAQ,CAEpC,OAAO;IACPU,MAAM,EAAE,IAAI;IACZC,KAAK,EAAE;EACT,CAAC,CAAC,CAAC;EACH,IAAMC,WAAW,GAAGX,cAAc,CAAIM,UA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4
  "description": "Deephaven JSAPI Bootstrap",
5
5
  "author": "Deephaven Data Labs LLC",
6
6
  "license": "Apache-2.0",
@@ -22,14 +22,14 @@
22
22
  "build:sass": "sass --embed-sources --load-path=../../node_modules ./src:./dist"
23
23
  },
24
24
  "dependencies": {
25
- "@deephaven/components": "^1.3.1-uri.5+18323c82",
25
+ "@deephaven/components": "^1.4.1-beta.0+a155da69",
26
26
  "@deephaven/jsapi-types": "^1.0.0-dev0.39.4",
27
- "@deephaven/log": "^1.3.1-uri.5+18323c82",
28
- "@deephaven/react-hooks": "^1.3.1-uri.5+18323c82",
29
- "@deephaven/utils": "^1.3.1-uri.5+18323c82"
27
+ "@deephaven/log": "^1.4.1-beta.0+a155da69",
28
+ "@deephaven/react-hooks": "^1.4.1-beta.0+a155da69",
29
+ "@deephaven/utils": "^1.4.1-beta.0+a155da69"
30
30
  },
31
31
  "devDependencies": {
32
- "@deephaven/test-utils": "^1.3.1-uri.5+18323c82",
32
+ "@deephaven/test-utils": "^1.4.1-beta.0+a155da69",
33
33
  "react": "^17.x"
34
34
  },
35
35
  "peerDependencies": {
@@ -42,5 +42,5 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "18323c82bf67c3fa247cef63e30253b8fe793f4e"
45
+ "gitHead": "a155da691eed1c03f3c4d719737d7b34abf16822"
46
46
  }