@deephaven/jsapi-bootstrap 1.3.1-beta.0 → 1.3.1-uri.5

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,19 +1,20 @@
1
1
  import type { dh as DhType } from '@deephaven/jsapi-types';
2
+ import { type UriVariableDescriptor } from './useObjectFetcher';
2
3
  /**
3
4
  * Function to fetch an API based on a provided descriptor object.
4
5
  * Depending on the context there may be more properties on the descriptor,
5
6
  * providing more information about the object, such as a session ID.
6
- * @param descriptor Descriptor object to fetch the API from.
7
+ * @param descriptor Descriptor object or URI to fetch the API from.
7
8
  * @returns A promise that resolves to the API instance for the provided variable descriptor.
8
9
  */
9
- export type DeferredApiFetcher = (descriptor: DhType.ide.VariableDescriptor) => Promise<typeof DhType>;
10
+ export type DeferredApiFetcher = (descriptor: DhType.ide.VariableDescriptor | UriVariableDescriptor) => Promise<typeof DhType>;
10
11
  export declare const DeferredApiContext: import("react").Context<typeof DhType | DeferredApiFetcher | null>;
11
12
  /**
12
13
  * Retrieve the API for the current context, given the widget provided.
13
14
  * The API may need to be loaded, and will return `null` until it is ready.
14
- * @param widget The widget descriptor to use to fetch the API
15
+ * @param widget The widget descriptor or URI to use to fetch the API
15
16
  * @returns A tuple with the API instance, and an error if one occurred.
16
17
  */
17
- export declare function useDeferredApi(widget: DhType.ide.VariableDescriptor | null): [dh: typeof DhType | null, error: unknown | null];
18
+ export declare function useDeferredApi(widget: DhType.ide.VariableDescriptor | UriVariableDescriptor | null): [dh: typeof DhType | null, error: unknown | null];
18
19
  export default useDeferredApi;
19
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;AAG3D;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,KACtC,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,IAAI,GAC3C,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,OAAO,GAAG,IAAI,CAAC,CAuDnD;AAED,eAAe,cAAc,CAAC"}
@@ -6,7 +6,7 @@ import { ApiContext } from "./ApiBootstrap.js";
6
6
  * Function to fetch an API based on a provided descriptor object.
7
7
  * Depending on the context there may be more properties on the descriptor,
8
8
  * providing more information about the object, such as a session ID.
9
- * @param descriptor Descriptor object to fetch the API from.
9
+ * @param descriptor Descriptor object or URI to fetch the API from.
10
10
  * @returns A promise that resolves to the API instance for the provided variable descriptor.
11
11
  */
12
12
  export var DeferredApiContext = /*#__PURE__*/createContext(null);
@@ -14,7 +14,7 @@ export var DeferredApiContext = /*#__PURE__*/createContext(null);
14
14
  /**
15
15
  * Retrieve the API for the current context, given the widget provided.
16
16
  * The API may need to be loaded, and will return `null` until it is ready.
17
- * @param widget The widget descriptor to use to fetch the API
17
+ * @param widget The widget descriptor or URI to use to fetch the API
18
18
  * @returns A tuple with the API instance, and an error if one occurred.
19
19
  */
20
20
  export function useDeferredApi(widget) {
@@ -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';\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 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\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 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 | 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;AAEnB;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,MAA4C,EACO;EACnD,IAAM,CAACC,GAAG,EAAEC,MAAM,CAAC,GAAGN,QAAQ,CAAuB,IAAI,CAAC;EAC1D,IAAM,CAACO,KAAK,EAAEC,QAAQ,CAAC,GAAGR,QAAQ,CAAiB,IAAI,CAAC;EACxD,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,EAAE;QACtBJ,MAAM,CAACI,UAAU,CAAC;QAClBF,QAAQ,CAAC,IAAI,CAAC;QACd;MACF;MACAF,MAAM,CAAC,IAAI,CAAC;MACZE,QAAQ,CACN,IAAIG,KAAK,CACP,sGACF,CACF,CAAC;MACD;IACF;IACA,IAAIC,WAAW,GAAG,KAAK;IAAC,SAETC,OAAOA,CAAA;MAAA,OAAAC,QAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IAAA,SAAAF,SAAA;MAAAA,QAAA,GAAAG,iBAAA,CAAtB,aAAyB;QACvB,IAAIb,MAAM,IAAI,IAAI,EAAE;UAClB,IAAI,CAACQ,WAAW,EAAE;YAChBN,MAAM,CAAC,IAAI,CAAC;YACZE,QAAQ,CAAC,IAAIG,KAAK,CAAC,sCAAsC,CAAC,CAAC;UAC7D;QACF,CAAC,MAAM,IAAI,OAAOF,WAAW,KAAK,UAAU,EAAE;UAC5C,IAAI;YACF,IAAMS,MAAM,SAAST,WAAW,CAACL,MAAM,CAAC;YACxC,IAAI,CAACQ,WAAW,EAAE;cAChBN,MAAM,CAACY,MAAM,CAAC;cACdV,QAAQ,CAAC,IAAI,CAAC;YAChB;UACF,CAAC,CAAC,OAAOW,CAAC,EAAE;YACV,IAAI,CAACP,WAAW,EAAE;cAChBN,MAAM,CAAC,IAAI,CAAC;cACZE,QAAQ,CAACW,CAAC,CAAC;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: 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,cAAcA,CAC5BC,MAAoE,EACjB;EACnD,IAAM,CAACC,GAAG,EAAEC,MAAM,CAAC,GAAGN,QAAQ,CAAuB,IAAI,CAAC;EAC1D,IAAM,CAACO,KAAK,EAAEC,QAAQ,CAAC,GAAGR,QAAQ,CAAiB,IAAI,CAAC;EACxD,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,EAAE;QACtBJ,MAAM,CAACI,UAAU,CAAC;QAClBF,QAAQ,CAAC,IAAI,CAAC;QACd;MACF;MACAF,MAAM,CAAC,IAAI,CAAC;MACZE,QAAQ,CACN,IAAIG,KAAK,CACP,sGACF,CACF,CAAC;MACD;IACF;IACA,IAAIC,WAAW,GAAG,KAAK;IAAC,SAETC,OAAOA,CAAA;MAAA,OAAAC,QAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IAAA,SAAAF,SAAA;MAAAA,QAAA,GAAAG,iBAAA,CAAtB,aAAyB;QACvB,IAAIb,MAAM,IAAI,IAAI,EAAE;UAClB,IAAI,CAACQ,WAAW,EAAE;YAChBN,MAAM,CAAC,IAAI,CAAC;YACZE,QAAQ,CAAC,IAAIG,KAAK,CAAC,sCAAsC,CAAC,CAAC;UAC7D;QACF,CAAC,MAAM,IAAI,OAAOF,WAAW,KAAK,UAAU,EAAE;UAC5C,IAAI;YACF,IAAMS,MAAM,SAAST,WAAW,CAACL,MAAM,CAAC;YACxC,IAAI,CAACQ,WAAW,EAAE;cAChBN,MAAM,CAACY,MAAM,CAAC;cACdV,QAAQ,CAAC,IAAI,CAAC;YAChB;UACF,CAAC,CAAC,OAAOW,CAAC,EAAE;YACV,IAAI,CAACP,WAAW,EAAE;cAChBN,MAAM,CAAC,IAAI,CAAC;cACZE,QAAQ,CAACW,CAAC,CAAC;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,4 +1,5 @@
1
1
  import type { dh } from '@deephaven/jsapi-types';
2
+ import { type UriVariableDescriptor } from './useObjectFetcher';
2
3
  /** Function for unsubscribing from a given subscription */
3
4
  export type UnsubscribeFunction = () => void;
4
5
  /** Update when the ObjectFetch is still loading */
@@ -29,20 +30,20 @@ export type ObjectFetchManager = {
29
30
  * Subscribe to the fetch function for an object using a variable descriptor.
30
31
  * It's possible that the fetch function changes over time, due to disconnection/reconnection, starting/stopping of applications that the object may be associated with, etc.
31
32
  *
32
- * @param descriptor Descriptor object of the object to fetch. Can be extended by a specific implementation to include more details necessary for the ObjectManager.
33
+ * @param descriptor Descriptor object or URI of the object to fetch. Can be extended by a specific implementation to include more details necessary for the ObjectManager.
33
34
  * @param onUpdate Callback function to be called when the object is updated.
34
35
  * @returns An unsubscribe function to stop listening for fetch updates and clean up the object.
35
36
  */
36
- subscribe: <T = unknown>(descriptor: dh.ide.VariableDescriptor, onUpdate: ObjectFetchUpdateCallback<T>) => UnsubscribeFunction;
37
+ subscribe: <T = unknown>(descriptor: dh.ide.VariableDescriptor | UriVariableDescriptor, onUpdate: ObjectFetchUpdateCallback<T>) => UnsubscribeFunction;
37
38
  };
38
39
  /** Context for tracking an implementation of the ObjectFetchManager. */
39
40
  export declare const ObjectFetchManagerContext: import("react").Context<ObjectFetchManager | null>;
40
41
  /**
41
42
  * Retrieve a `fetch` function for the given variable descriptor.
42
43
  *
43
- * @param descriptor Descriptor to get the `fetch` function for
44
+ * @param descriptor Descriptor or URI to get the `fetch` function for
44
45
  * @returns An object with the current `fetch` function, OR an error status set if there was an issue fetching the object.
45
46
  * Retrying is left up to the ObjectManager implementation used from this context.
46
47
  */
47
- export declare function useObjectFetch<T = unknown>(descriptor: dh.ide.VariableDescriptor): ObjectFetchUpdate<T>;
48
+ export declare function useObjectFetch<T = unknown>(descriptor: dh.ide.VariableDescriptor | UriVariableDescriptor): ObjectFetchUpdate<T>;
48
49
  //# sourceMappingURL=useObjectFetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useObjectFetch.d.ts","sourceRoot":"","sources":["../src/useObjectFetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAEjD,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC;AAE7C,mDAAmD;AACnD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,8CAA8C;AAC9C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,sCAAsC;AACtC,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAChC,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;IACxB,M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EF,sCAAsC;AACtC,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAChC,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG,OAAO,IACrC,kBAAkB,GAClB,gBAAgB,GAChB,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAExB,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,OAAO,IAAI,CACnD,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,KACzB,IAAI,CAAC;AAEV,6FAA6F;AAC7F,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;;;OAOG;IACH,SAAS,EAAE,CAAC,CAAC,GAAG,OAAO,EACrB,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,GAAG,qBAAqB,EAC7D,QAAQ,EAAE,yBAAyB,CAAC,CAAC,CAAC,KACnC,mBAAmB,CAAC;CAC1B,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,oDACU,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EACxC,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,GAAG,qBAAqB,GAC5D,iBAAiB,CAAC,CAAC,CAAC,CAuBtB"}
@@ -23,7 +23,7 @@ export var ObjectFetchManagerContext = /*#__PURE__*/createContext(null);
23
23
  /**
24
24
  * Retrieve a `fetch` function for the given variable descriptor.
25
25
  *
26
- * @param descriptor Descriptor to get the `fetch` function for
26
+ * @param descriptor Descriptor or URI to get the `fetch` function for
27
27
  * @returns An object with the current `fetch` function, OR an error status set if there was an issue fetching the object.
28
28
  * Retrying is left up to the ObjectManager implementation used from this context.
29
29
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useObjectFetch.js","names":["createContext","useContext","useEffect","useState","ObjectFetchManagerContext","useObjectFetch","descriptor","currentUpdate","setCurrentUpdate","status","objectFetchManager","error","Error","oldUpdate","subscribe"],"sources":["../src/useObjectFetch.ts"],"sourcesContent":["import { createContext, useContext, useEffect, useState } from 'react';\nimport type { dh } from '@deephaven/jsapi-types';\n\n/** Function for unsubscribing from a given subscription */\nexport type UnsubscribeFunction = () => void;\n\n/** Update when the ObjectFetch is still loading */\nexport type ObjectFetchLoading = {\n status: 'loading';\n};\n\n/** Update when the ObjectFetch has errored */\nexport type ObjectFetchError = {\n error: NonNullable<unknown>;\n status: 'error';\n};\n\n/** Update when the object is ready */\nexport type ObjectFetchReady<T> = {\n fetch: () => Promise<T>;\n status: 'ready';\n};\n\n/**\n * Update with the current `fetch` function and status of the object.\n * - If both `fetch` and `error` are `null`, it is still loading the fetcher\n * - If `fetch` is not `null`, the object is ready to be fetched\n * - If `error` is not `null`, there was an error loading the object\n */\nexport type ObjectFetchUpdate<T = unknown> =\n | ObjectFetchLoading\n | ObjectFetchError\n | ObjectFetchReady<T>;\n\nexport type ObjectFetchUpdateCallback<T = unknown> = (\n update: ObjectFetchUpdate<T>\n) => void;\n\n/** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */\nexport type ObjectFetchManager = {\n /**\n * Subscribe to the fetch function for an object using a variable descriptor.\n * It's possible that the fetch function changes over time, due to disconnection/reconnection, starting/stopping of applications that the object may be associated with, etc.\n *\n * @param descriptor Descriptor object of the object to fetch. Can be extended by a specific implementation to include more details necessary for the ObjectManager.\n * @param onUpdate Callback function to be called when the object is updated.\n * @returns An unsubscribe function to stop listening for fetch updates and clean up the object.\n */\n subscribe: <T = unknown>(\n descriptor: dh.ide.VariableDescriptor,\n onUpdate: ObjectFetchUpdateCallback<T>\n ) => UnsubscribeFunction;\n};\n\n/** Context for tracking an implementation of the ObjectFetchManager. */\nexport const ObjectFetchManagerContext =\n createContext<ObjectFetchManager | null>(null);\n\n/**\n * Retrieve a `fetch` function for the given variable descriptor.\n *\n * @param descriptor Descriptor to get the `fetch` function for\n * @returns An object with the current `fetch` function, OR an error status set if there was an issue fetching the object.\n * Retrying is left up to the ObjectManager implementation used from this context.\n */\nexport function useObjectFetch<T = unknown>(\n descriptor: dh.ide.VariableDescriptor\n): ObjectFetchUpdate<T> {\n const [currentUpdate, setCurrentUpdate] = useState<ObjectFetchUpdate<T>>({\n status: 'loading',\n });\n\n const objectFetchManager = useContext(ObjectFetchManagerContext);\n\n useEffect(() => {\n if (objectFetchManager == null) {\n setCurrentUpdate({\n error: new Error('No ObjectFetchManager available in context'),\n status: 'error',\n });\n return;\n }\n // Update to signal we're still loading, if we're not already in a loading state.\n setCurrentUpdate(oldUpdate =>\n oldUpdate.status === 'loading' ? oldUpdate : { status: 'loading' }\n );\n return objectFetchManager.subscribe(descriptor, setCurrentUpdate);\n }, [descriptor, objectFetchManager]);\n\n return currentUpdate;\n}\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;;AAGtE;;AAGA;;AAKA;;AAMA;;AAMA;AACA;AACA;AACA;AACA;AACA;;AAUA;;AAgBA;AACA,OAAO,IAAMC,yBAAyB,gBACpCJ,aAAa,CAA4B,IAAI,CAAC;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,cAAcA,CAC5BC,UAAqC,EACf;EACtB,IAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGL,QAAQ,CAAuB;IACvEM,MAAM,EAAE;EACV,CAAC,CAAC;EAEF,IAAMC,kBAAkB,GAAGT,UAAU,CAACG,yBAAyB,CAAC;EAEhEF,SAAS,CAAC,MAAM;IACd,IAAIQ,kBAAkB,IAAI,IAAI,EAAE;MAC9BF,gBAAgB,CAAC;QACfG,KAAK,EAAE,IAAIC,KAAK,CAAC,4CAA4C,CAAC;QAC9DH,MAAM,EAAE;MACV,CAAC,CAAC;MACF;IACF;IACA;IACAD,gBAAgB,CAACK,SAAS,IACxBA,SAAS,CAACJ,MAAM,KAAK,SAAS,GAAGI,SAAS,GAAG;MAAEJ,MAAM,EAAE;IAAU,CACnE,CAAC;IACD,OAAOC,kBAAkB,CAACI,SAAS,CAACR,UAAU,EAAEE,gBAAgB,CAAC;EACnE,CAAC,EAAE,CAACF,UAAU,EAAEI,kBAAkB,CAAC,CAAC;EAEpC,OAAOH,aAAa;AACtB"}
1
+ {"version":3,"file":"useObjectFetch.js","names":["createContext","useContext","useEffect","useState","ObjectFetchManagerContext","useObjectFetch","descriptor","currentUpdate","setCurrentUpdate","status","objectFetchManager","error","Error","oldUpdate","subscribe"],"sources":["../src/useObjectFetch.ts"],"sourcesContent":["import { createContext, useContext, useEffect, useState } from 'react';\nimport type { dh } from '@deephaven/jsapi-types';\nimport { type UriVariableDescriptor } from './useObjectFetcher';\n\n/** Function for unsubscribing from a given subscription */\nexport type UnsubscribeFunction = () => void;\n\n/** Update when the ObjectFetch is still loading */\nexport type ObjectFetchLoading = {\n status: 'loading';\n};\n\n/** Update when the ObjectFetch has errored */\nexport type ObjectFetchError = {\n error: NonNullable<unknown>;\n status: 'error';\n};\n\n/** Update when the object is ready */\nexport type ObjectFetchReady<T> = {\n fetch: () => Promise<T>;\n status: 'ready';\n};\n\n/**\n * Update with the current `fetch` function and status of the object.\n * - If both `fetch` and `error` are `null`, it is still loading the fetcher\n * - If `fetch` is not `null`, the object is ready to be fetched\n * - If `error` is not `null`, there was an error loading the object\n */\nexport type ObjectFetchUpdate<T = unknown> =\n | ObjectFetchLoading\n | ObjectFetchError\n | ObjectFetchReady<T>;\n\nexport type ObjectFetchUpdateCallback<T = unknown> = (\n update: ObjectFetchUpdate<T>\n) => void;\n\n/** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */\nexport type ObjectFetchManager = {\n /**\n * Subscribe to the fetch function for an object using a variable descriptor.\n * It's possible that the fetch function changes over time, due to disconnection/reconnection, starting/stopping of applications that the object may be associated with, etc.\n *\n * @param descriptor Descriptor object or URI of the object to fetch. Can be extended by a specific implementation to include more details necessary for the ObjectManager.\n * @param onUpdate Callback function to be called when the object is updated.\n * @returns An unsubscribe function to stop listening for fetch updates and clean up the object.\n */\n subscribe: <T = unknown>(\n descriptor: dh.ide.VariableDescriptor | UriVariableDescriptor,\n onUpdate: ObjectFetchUpdateCallback<T>\n ) => UnsubscribeFunction;\n};\n\n/** Context for tracking an implementation of the ObjectFetchManager. */\nexport const ObjectFetchManagerContext =\n createContext<ObjectFetchManager | null>(null);\n\n/**\n * Retrieve a `fetch` function for the given variable descriptor.\n *\n * @param descriptor Descriptor or URI to get the `fetch` function for\n * @returns An object with the current `fetch` function, OR an error status set if there was an issue fetching the object.\n * Retrying is left up to the ObjectManager implementation used from this context.\n */\nexport function useObjectFetch<T = unknown>(\n descriptor: dh.ide.VariableDescriptor | UriVariableDescriptor\n): ObjectFetchUpdate<T> {\n const [currentUpdate, setCurrentUpdate] = useState<ObjectFetchUpdate<T>>({\n status: 'loading',\n });\n\n const objectFetchManager = useContext(ObjectFetchManagerContext);\n\n useEffect(() => {\n if (objectFetchManager == null) {\n setCurrentUpdate({\n error: new Error('No ObjectFetchManager available in context'),\n status: 'error',\n });\n return;\n }\n // Update to signal we're still loading, if we're not already in a loading state.\n setCurrentUpdate(oldUpdate =>\n oldUpdate.status === 'loading' ? oldUpdate : { status: 'loading' }\n );\n return objectFetchManager.subscribe(descriptor, setCurrentUpdate);\n }, [descriptor, objectFetchManager]);\n\n return currentUpdate;\n}\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;;AAItE;;AAGA;;AAKA;;AAMA;;AAMA;AACA;AACA;AACA;AACA;AACA;;AAUA;;AAgBA;AACA,OAAO,IAAMC,yBAAyB,gBACpCJ,aAAa,CAA4B,IAAI,CAAC;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,cAAcA,CAC5BC,UAA6D,EACvC;EACtB,IAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGL,QAAQ,CAAuB;IACvEM,MAAM,EAAE;EACV,CAAC,CAAC;EAEF,IAAMC,kBAAkB,GAAGT,UAAU,CAACG,yBAAyB,CAAC;EAEhEF,SAAS,CAAC,MAAM;IACd,IAAIQ,kBAAkB,IAAI,IAAI,EAAE;MAC9BF,gBAAgB,CAAC;QACfG,KAAK,EAAE,IAAIC,KAAK,CAAC,4CAA4C,CAAC;QAC9DH,MAAM,EAAE;MACV,CAAC,CAAC;MACF;IACF;IACA;IACAD,gBAAgB,CAACK,SAAS,IACxBA,SAAS,CAACJ,MAAM,KAAK,SAAS,GAAGI,SAAS,GAAG;MAAEJ,MAAM,EAAE;IAAU,CACnE,CAAC;IACD,OAAOC,kBAAkB,CAACI,SAAS,CAACR,UAAU,EAAEE,gBAAgB,CAAC;EACnE,CAAC,EAAE,CAACF,UAAU,EAAEI,kBAAkB,CAAC,CAAC;EAEpC,OAAOH,aAAa;AACtB"}
@@ -17,15 +17,16 @@ export type IdVariableDescriptor = {
17
17
  /** Id of the variable */
18
18
  id: string;
19
19
  };
20
+ export type UriVariableDescriptor = string;
20
21
  export declare function isNameVariableDescriptor(value: unknown): value is NameVariableDescriptor;
21
22
  export declare function isIdVariableDescriptor(value: unknown): value is IdVariableDescriptor;
22
23
  export declare function isVariableDescriptor(value: unknown): value is dh.ide.VariableDescriptor;
23
24
  /**
24
25
  * Function to fetch an object based on a provided descriptor object.
25
- * @param descriptor Descriptor object to fetch the object from. Can be extended by a specific implementation to
26
- * include additional fields (such as a session ID) to uniquely identify an object.
26
+ * @param descriptor Descriptor object or URI to fetch the object from. Can be extended by a specific implementation to
27
+ * include additional fields (such as a session ID) to uniquely identify an object.
27
28
  */
28
- export type ObjectFetcher = <T = unknown>(descriptor: dh.ide.VariableDescriptor) => Promise<T>;
29
+ export type ObjectFetcher = <T = unknown>(descriptor: dh.ide.VariableDescriptor | UriVariableDescriptor) => Promise<T>;
29
30
  export declare const ObjectFetcherContext: import("react").Context<ObjectFetcher | null>;
30
31
  /**
31
32
  * Gets a descriptor that only has the ID or name set, but not both.
@@ -1 +1 @@
1
- {"version":3,"file":"useObjectFetcher.d.ts","sourceRoot":"","sources":["../src/useObjectFetcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAIjD;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,sBAAsB,CAOjC;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,oBAAoB,CAO/B;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAEpC;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,GAAG,OAAO,EACtC,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,KAClC,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,eAAO,MAAM,oBAAoB,+CAA4C,CAAC;AAE9E;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,GAC7C,sBAAsB,GAAG,oBAAoB,CAe/C;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAA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B,CACnC,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACzD,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAM3B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD"}
@@ -21,8 +21,8 @@ export function isVariableDescriptor(value) {
21
21
 
22
22
  /**
23
23
  * Function to fetch an object based on a provided descriptor object.
24
- * @param descriptor Descriptor object to fetch the object from. Can be extended by a specific implementation to
25
- * include additional fields (such as a session ID) to uniquely identify an object.
24
+ * @param descriptor Descriptor object or URI to fetch the object from. Can be extended by a specific implementation to
25
+ * include additional fields (such as a session ID) to uniquely identify an object.
26
26
  */
27
27
 
28
28
  export var ObjectFetcherContext = /*#__PURE__*/createContext(null);
@@ -1 +1 @@
1
- {"version":3,"file":"useObjectFetcher.js","names":["useContextOrThrow","createContext","isNameVariableDescriptor","value","type","name","isIdVariableDescriptor","id","isVariableDescriptor","ObjectFetcherContext","sanitizeVariableDescriptor","descriptor","_descriptor$name","Error","concat","getVariableDescriptor","definition","_definition$type","_definition$title","title","useObjectFetcher"],"sources":["../src/useObjectFetcher.ts"],"sourcesContent":["import type { dh } from '@deephaven/jsapi-types';\nimport { useContextOrThrow } from '@deephaven/react-hooks';\nimport { createContext } from 'react';\n\n/**\n * Descriptor for a variable by name. Used when needed to fetch an object.\n */\nexport type NameVariableDescriptor = {\n /** Type of the variable */\n type: string;\n /** Name of the variable */\n name: string;\n};\n\n/**\n * Descriptor for a variable by id. Used when needed to fetch an object.\n */\nexport type IdVariableDescriptor = {\n /** Type of the variable */\n type: string;\n /** Id of the variable */\n id: string;\n};\n\nexport function isNameVariableDescriptor(\n value: unknown\n): value is NameVariableDescriptor {\n return (\n typeof value === 'object' &&\n value != null &&\n typeof (value as NameVariableDescriptor).type === 'string' &&\n (value as NameVariableDescriptor).name != null\n );\n}\n\nexport function isIdVariableDescriptor(\n value: unknown\n): value is IdVariableDescriptor {\n return (\n typeof value === 'object' &&\n value != null &&\n typeof (value as IdVariableDescriptor).type === 'string' &&\n (value as IdVariableDescriptor).id != null\n );\n}\n\nexport function isVariableDescriptor(\n value: unknown\n): value is dh.ide.VariableDescriptor {\n return isNameVariableDescriptor(value) || isIdVariableDescriptor(value);\n}\n\n/**\n * Function to fetch an object based on a provided descriptor object.\n * @param descriptor Descriptor object to fetch the object from. Can be extended by a specific implementation to\n * include additional fields (such as a session ID) to uniquely identify an object.\n */\nexport type ObjectFetcher = <T = unknown>(\n descriptor: dh.ide.VariableDescriptor\n) => Promise<T>;\n\nexport const ObjectFetcherContext = createContext<ObjectFetcher | null>(null);\n\n/**\n * Gets a descriptor that only has the ID or name set, but not both.\n * API will throw an error if both are set when fetching from the connection.\n * @param descriptor Variable descriptor to sanitize\n * @returns Descriptor object that has either the ID or name set, but not both.\n */\nexport function sanitizeVariableDescriptor(\n descriptor: Partial<dh.ide.VariableDescriptor>\n): NameVariableDescriptor | IdVariableDescriptor {\n // Can't use a spread operator because of how the GWT compiled code defines properties on the object: https://github.com/gwtproject/gwt/issues/9913\n if (isIdVariableDescriptor(descriptor)) {\n return {\n id: descriptor.id,\n type: descriptor.type,\n };\n }\n if (isNameVariableDescriptor(descriptor)) {\n return {\n name: descriptor.name ?? '',\n type: descriptor.type,\n };\n }\n throw new Error(`Invalid descriptor: ${descriptor}`);\n}\n\n/**\n * Get the variable descriptor for a definition.\n * @param definition Definition to get the variable descriptor from\n * @returns Serializable VariableDescriptor object\n */\nexport function getVariableDescriptor(\n definition: dh.ide.VariableDescriptor & { title?: string }\n): dh.ide.VariableDescriptor {\n return {\n type: definition.type ?? '',\n name: definition.title ?? definition.name,\n id: definition.id,\n };\n}\n\n/**\n * Use a function to fetch an object based on provided metadata\n * @returns Function to asynchronously fetch an object based on provided metadata\n */\nexport function useObjectFetcher(): ObjectFetcher {\n return useContextOrThrow(\n ObjectFetcherContext,\n 'No ObjectFetcher available in useObjectFetcher. Was code wrapped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AK,wBAAAC,MAAA,CAAwBH,UAAU,CAAE,CAAC;AACtD;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,qBAAqBA,CACnCC,UAA0D,EAC/B;EAAA,IAAAC,gBAAA,EAAAC,iBAAA;EAC3B,OAAO;IACLd,IAAI,GAAAa,gBAAA,GAAED,UAAU,CAACZ,IAAI,cAAAa,gBAAA,cAAAA,gBAAA,GAAI,EAAE;IAC3BZ,IAAI,GAAAa,iBAAA,GAAEF,UAAU,CAACG,KAAK,cAAAD,iBAAA,cAAAA,iBAAA,GAAIF,UAAU,CAACX,IAAI;IACzCE,EAAE,EAAES,UAAU,CAACT;EACjB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASa,gBAAgBA,CAAA,EAAkB;EAChD,OAAOpB,iBAAiB,CACtBS,oBAAoB,EACpB,oGACF,CAAC;AACH"}
1
+ {"version":3,"file":"useObjectFetcher.js","names":["useContextOrThrow","createContext","isNameVariableDescriptor","value","type","name","isIdVariableDescriptor","id","isVariableDescriptor","ObjectFetcherContext","sanitizeVariableDescriptor","descriptor","_descriptor$name","Error","concat","getVariableDescriptor","definition","_definition$type","_definition$title","title","useObjectFetcher"],"sources":["../src/useObjectFetcher.ts"],"sourcesContent":["import type { dh } from '@deephaven/jsapi-types';\nimport { useContextOrThrow } from '@deephaven/react-hooks';\nimport { createContext } from 'react';\n\n/**\n * Descriptor for a variable by name. Used when needed to fetch an object.\n */\nexport type NameVariableDescriptor = {\n /** Type of the variable */\n type: string;\n /** Name of the variable */\n name: string;\n};\n\n/**\n * Descriptor for a variable by id. Used when needed to fetch an object.\n */\nexport type IdVariableDescriptor = {\n /** Type of the variable */\n type: string;\n /** Id of the variable */\n id: string;\n};\n\nexport type UriVariableDescriptor = string;\n\nexport function isNameVariableDescriptor(\n value: unknown\n): value is NameVariableDescriptor {\n return (\n typeof value === 'object' &&\n value != null &&\n typeof (value as NameVariableDescriptor).type === 'string' &&\n (value as NameVariableDescriptor).name != null\n );\n}\n\nexport function isIdVariableDescriptor(\n value: unknown\n): value is IdVariableDescriptor {\n return (\n typeof value === 'object' &&\n value != null &&\n typeof (value as IdVariableDescriptor).type === 'string' &&\n (value as IdVariableDescriptor).id != null\n );\n}\n\nexport function isVariableDescriptor(\n value: unknown\n): value is dh.ide.VariableDescriptor {\n return isNameVariableDescriptor(value) || isIdVariableDescriptor(value);\n}\n\n/**\n * Function to fetch an object based on a provided descriptor object.\n * @param descriptor Descriptor object or URI to fetch the object from. Can be extended by a specific implementation to\n * include additional fields (such as a session ID) to uniquely identify an object.\n */\nexport type ObjectFetcher = <T = unknown>(\n descriptor: dh.ide.VariableDescriptor | UriVariableDescriptor\n) => Promise<T>;\n\nexport const ObjectFetcherContext = createContext<ObjectFetcher | null>(null);\n\n/**\n * Gets a descriptor that only has the ID or name set, but not both.\n * API will throw an error if both are set when fetching from the connection.\n * @param descriptor Variable descriptor to sanitize\n * @returns Descriptor object that has either the ID or name set, but not both.\n */\nexport function sanitizeVariableDescriptor(\n descriptor: Partial<dh.ide.VariableDescriptor>\n): NameVariableDescriptor | IdVariableDescriptor {\n // Can't use a spread operator because of how the GWT compiled code defines properties on the object: https://github.com/gwtproject/gwt/issues/9913\n if (isIdVariableDescriptor(descriptor)) {\n return {\n id: descriptor.id,\n type: descriptor.type,\n };\n }\n if (isNameVariableDescriptor(descriptor)) {\n return {\n name: descriptor.name ?? '',\n type: descriptor.type,\n };\n }\n throw new Error(`Invalid descriptor: ${descriptor}`);\n}\n\n/**\n * Get the variable descriptor for a definition.\n * @param definition Definition to get the variable descriptor from\n * @returns Serializable VariableDescriptor object\n */\nexport function getVariableDescriptor(\n definition: dh.ide.VariableDescriptor & { title?: string }\n): dh.ide.VariableDescriptor {\n return {\n type: definition.type ?? '',\n name: definition.title ?? definition.name,\n id: definition.id,\n };\n}\n\n/**\n * Use a function to fetch an object based on provided metadata\n * @returns Function to asynchronously fetch an object based on provided metadata\n */\nexport function useObjectFetcher(): ObjectFetcher {\n return useContextOrThrow(\n ObjectFetcherContext,\n 'No ObjectFetcher available in useObjectFetcher. Was code wrapped in ObjectFetcherContext.Provider?'\n );\n}\n"],"mappings":"AACA,SAASA,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,aAAa,QAAQ,OAAO;;AAErC;AACA;AACA;;AAQA;AACA;AACA;;AAUA,OAAO,SAASC,wBAAwBA,CACtCC,KAAc,EACmB;EACjC,OACE,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,IAAI,IAAI,IACb,OAAQA,KAAK,CAA4BC,IAAI,KAAK,QAAQ,IACzDD,KAAK,CAA4BE,IAAI,IAAI,IAAI;AAElD;AAEA,OAAO,SAASC,sBAAsBA,CACpCH,KAAc,EACiB;EAC/B,OACE,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,IAAI,IAAI,IACb,OAAQA,KAAK,CAA0BC,IAAI,KAAK,QAAQ,IACvDD,KAAK,CAA0BI,EAAE,IAAI,IAAI;AAE9C;AAEA,OAAO,SAASC,oBAAoBA,CAClCL,KAAc,EACsB;EACpC,OAAOD,wBAAwB,CAACC,KAAK,CAAC,IAAIG,sBAAsB,CAACH,KAAK,CAAC;AACzE;;AAEA;AACA;AACA;AACA;AACA;;AAKA,OAAO,IAAMM,oBAAoB,gBAAGR,aAAa,CAAuB,IAAI,CAAC;;AAE7E;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,0BAA0BA,CACxCC,UAA8C,EACC;EAC/C;EACA,IAAIL,sBAAsB,CAACK,UAAU,CAAC,EAAE;IACtC,OAAO;MACLJ,EAAE,EAAEI,UAAU,CAACJ,EAAE;MACjBH,IAAI,EAAEO,UAAU,CAACP;IACnB,CAAC;EACH;EACA,IAAIF,wBAAwB,CAACS,UAAU,CAAC,EAAE;IAAA,IAAAC,gBAAA;IACxC,OAAO;MACLP,IAAI,GAAAO,gBAAA,GAAED,UAAU,CAACN,IAAI,cAAAO,gBAAA,cAAAA,gBAAA,GAAI,EAAE;MAC3BR,IAAI,EAAEO,UAAU,CAACP;IACnB,CAAC;EACH;EACA,MAAM,IAAIS,KAAK,wBAAAC,MAAA,CAAwBH,UAAU,CAAE,CAAC;AACtD;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,qBAAqBA,CACnCC,UAA0D,EAC/B;EAAA,IAAAC,gBAAA,EAAAC,iBAAA;EAC3B,OAAO;IACLd,IAAI,GAAAa,gBAAA,GAAED,UAAU,CAACZ,IAAI,cAAAa,gBAAA,cAAAA,gBAAA,GAAI,EAAE;IAC3BZ,IAAI,GAAAa,iBAAA,GAAEF,UAAU,CAACG,KAAK,cAAAD,iBAAA,cAAAA,iBAAA,GAAIF,UAAU,CAACX,IAAI;IACzCE,EAAE,EAAES,UAAU,CAACT;EACjB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASa,gBAAgBA,CAAA,EAAkB;EAChD,OAAOpB,iBAAiB,CACtBS,oBAAoB,EACpB,oGACF,CAAC;AACH"}
@@ -1,22 +1,25 @@
1
1
  import type { dh } from '@deephaven/jsapi-types';
2
+ import { type UriVariableDescriptor } from './useObjectFetcher';
2
3
  /**
3
4
  * Types of widgets that can be fetched with this hook.
4
5
  */
5
- type WidgetTypes = dh.Table | dh.TreeTable | dh.PartitionedTable | dh.plot.Figure | dh.Widget;
6
+ export type WidgetTypes = dh.Table | dh.TreeTable | dh.PartitionedTable | dh.plot.Figure | dh.Widget;
6
7
  /**
7
8
  * Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.
8
9
  */
9
- type WidgetWrapper<T extends WidgetTypes = dh.Widget> = {
10
+ export type WidgetWrapper<T extends WidgetTypes = dh.Widget> = {
10
11
  /** Widget object to retrieve */
11
12
  widget: T | null;
13
+ /** Deephaven JS API to use for this widget */
14
+ api: typeof dh | null;
12
15
  /** Error status if there was an issue fetching the widget */
13
16
  error: NonNullable<unknown> | null;
14
17
  };
15
18
  /**
16
19
  * 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.
17
- * @param descriptor Descriptor to get the widget for. Should be stable to avoid infinite re-fetching.
18
- * @returns A WidgetWrapper object that contains the widget or an error status if there was an issue fetching the widget. Will contain nulls if still loading.
20
+ * @param descriptor Descriptor or URI to get the widget for. Should be stable to avoid infinite re-fetching.
21
+ * @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.
19
22
  */
20
- export declare function useWidget<T extends WidgetTypes = dh.Widget>(descriptor: dh.ide.VariableDescriptor): WidgetWrapper<T>;
23
+ export declare function useWidget<T extends WidgetTypes = dh.Widget>(descriptor: dh.ide.VariableDescriptor | UriVariableDescriptor): WidgetWrapper<T>;
21
24
  export default useWidget;
22
25
  //# sourceMappingURL=useWidget.d.ts.map
@@ -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;AAQjD;;GAEG;AACH,KAAK,WAAW,GACZ,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,KAAK,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,EAAE,CAAC,MAAM,IAAI;IACtD,gCAAgC;IAChC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAEjB,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,GACpC,aAAa,CAAC,CAAC,CAAC,CAgElB;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,CAgFlB;AAED,eAAe,SAAS,CAAC"}
package/dist/useWidget.js CHANGED
@@ -1,9 +1,16 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1
6
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
2
7
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
3
8
  import Log from '@deephaven/log';
4
9
  import { assertNotNull } from '@deephaven/utils';
5
- import { useEffect, useState } from 'react';
10
+ import { useEffect, useMemo, useState } from 'react';
6
11
  import { useObjectFetch } from "./useObjectFetch.js";
12
+ import useDeferredApi from "./useDeferredApi.js";
13
+ import useApi from "./useApi.js";
7
14
  var log = Log.module('useWidget');
8
15
 
9
16
  /**
@@ -16,8 +23,8 @@ var log = Log.module('useWidget');
16
23
 
17
24
  /**
18
25
  * 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.
19
- * @param descriptor Descriptor to get the widget for. Should be stable to avoid infinite re-fetching.
20
- * @returns A WidgetWrapper object that contains the widget or an error status if there was an issue fetching the widget. Will contain nulls if still loading.
26
+ * @param descriptor Descriptor or URI to get the widget for. Should be stable to avoid infinite re-fetching.
27
+ * @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.
21
28
  */
22
29
  export function useWidget(descriptor) {
23
30
  var [wrapper, setWrapper] = useState(() => ({
@@ -25,6 +32,9 @@ export function useWidget(descriptor) {
25
32
  error: null
26
33
  }));
27
34
  var objectFetch = useObjectFetch(descriptor);
35
+ var [descriptorApi, descriptorApiError] = useDeferredApi(descriptor);
36
+ var defaultApi = useApi();
37
+ var api = descriptorApi !== null && descriptorApi !== void 0 ? descriptorApi : defaultApi;
28
38
  useEffect(function loadWidget() {
29
39
  log.debug('loadWidget', descriptor);
30
40
  var {
@@ -94,7 +104,14 @@ export function useWidget(descriptor) {
94
104
  isCancelled = true;
95
105
  };
96
106
  }, [descriptor, objectFetch]);
97
- return wrapper;
107
+ var wrapperWithApi = useMemo(() => {
108
+ var _wrapper$error;
109
+ return _objectSpread(_objectSpread({}, wrapper), {}, {
110
+ error: (_wrapper$error = wrapper.error) !== null && _wrapper$error !== void 0 ? _wrapper$error : descriptorApiError,
111
+ api: wrapper.widget != null ? api : null
112
+ });
113
+ }, [wrapper, api, descriptorApiError]);
114
+ return wrapperWithApi;
98
115
  }
99
116
  export default useWidget;
100
117
  //# sourceMappingURL=useWidget.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useWidget.js","names":["Log","assertNotNull","useEffect","useState","useObjectFetch","log","module","useWidget","descriptor","wrapper","setWrapper","widget","error","objectFetch","loadWidget","debug","status","fetch","isCancelled","loadWidgetInternal","_loadWidgetInternal","apply","arguments","_asyncToGenerator","newWidget","debug2","close","exportedObjects","forEach","exportedObject","e","Error"],"sources":["../src/useWidget.ts"],"sourcesContent":["import type { dh } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport { assertNotNull } from '@deephaven/utils';\nimport { useEffect, useState } from 'react';\nimport { useObjectFetch } from './useObjectFetch';\n\nconst log = Log.module('useWidget');\n\n/**\n * Types of widgets that can be fetched with this hook.\n */\ntype 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 */\ntype WidgetWrapper<T extends WidgetTypes = dh.Widget> = {\n /** Widget object to retrieve */\n widget: T | 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 to get the widget for. Should be stable to avoid infinite re-fetching.\n * @returns A WidgetWrapper object that contains the widget 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\n): WidgetWrapper<T> {\n const [wrapper, setWrapper] = useState<WidgetWrapper<T>>(() => ({\n widget: null,\n error: null,\n }));\n const objectFetch = useObjectFetch<T>(descriptor);\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 return wrapper;\n}\n\nexport default useWidget;\n"],"mappings":";;AACA,OAAOA,GAAG,MAAM,gBAAgB;AAChC,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAAC,SACnCC,cAAc;AAEvB,IAAMC,GAAG,GAAGL,GAAG,CAACM,MAAM,CAAC,WAAW,CAAC;;AAEnC;AACA;AACA;;AAQA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CACvBC,UAAqC,EACnB;EAClB,IAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGP,QAAQ,CAAmB,OAAO;IAC9DQ,MAAM,EAAE,IAAI;IACZC,KAAK,EAAE;EACT,CAAC,CAAC,CAAC;EACH,IAAMC,WAAW,GAAGT,cAAc,CAAII,UAAU,CAAC;EAEjDN,SAAS,CACP,SAASY,UAAUA,CAAA,EAAG;IACpBT,GAAG,CAACU,KAAK,CAAC,YAAY,EAAEP,UAAU,CAAC;IAEnC,IAAM;MAAEQ;IAAO,CAAC,GAAGH,WAAW;IAE9B,IAAIG,MAAM,KAAK,OAAO,EAAE;MACtB;MACAN,UAAU,CAAC;QAAEC,MAAM,EAAE,IAAI;QAAEC,KAAK,EAAEC,WAAW,CAACD;MAAM,CAAC,CAAC;MACtD;IACF;IAEA,IAAII,MAAM,KAAK,SAAS,EAAE;MACxB;MACAN,UAAU,CAAC;QAAEC,MAAM,EAAE,IAAI;QAAEC,KAAK,EAAE;MAAK,CAAC,CAAC;MACzC;IACF;IAEA,IAAM;MAAEK;IAAM,CAAC,GAAGJ,WAAW;IAC7B;IACA;IACA;IACA,IAAIK,WAAW,GAA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A,eAAeF,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:\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,Q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VG,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven/jsapi-bootstrap",
3
- "version": "1.3.1-beta.0+d65ed406",
3
+ "version": "1.3.1-uri.5+18323c82",
4
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-beta.0+d65ed406",
25
+ "@deephaven/components": "^1.3.1-uri.5+18323c82",
26
26
  "@deephaven/jsapi-types": "^1.0.0-dev0.39.4",
27
- "@deephaven/log": "^1.3.1-beta.0+d65ed406",
28
- "@deephaven/react-hooks": "^1.3.1-beta.0+d65ed406",
29
- "@deephaven/utils": "^1.3.1-beta.0+d65ed406"
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"
30
30
  },
31
31
  "devDependencies": {
32
- "@deephaven/test-utils": "^1.3.1-beta.0+d65ed406",
32
+ "@deephaven/test-utils": "^1.3.1-uri.5+18323c82",
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": "d65ed4062477ccc16a1d09b3106d4256f772913b"
45
+ "gitHead": "18323c82bf67c3fa247cef63e30253b8fe793f4e"
46
46
  }