@deephaven/jsapi-bootstrap 0.80.1-beta.1 → 0.80.2-alpha-radio-props.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,5 +4,7 @@ export * from './DeferredApiBootstrap';
4
4
  export * from './useApi';
5
5
  export * from './useClient';
6
6
  export * from './useDeferredApi';
7
+ export * from './useObjectFetch';
7
8
  export * from './useObjectFetcher';
9
+ export * from './useWidget';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -4,5 +4,7 @@ export * from "./DeferredApiBootstrap.js";
4
4
  export * from "./useApi.js";
5
5
  export * from "./useClient.js";
6
6
  export * from "./useDeferredApi.js";
7
+ export * from "./useObjectFetch.js";
7
8
  export * from "./useObjectFetcher.js";
9
+ export * from "./useWidget.js";
8
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './ApiBootstrap';\nexport * from './ClientBootstrap';\nexport * from './DeferredApiBootstrap';\nexport * from './useApi';\nexport * from './useClient';\nexport * from './useDeferredApi';\nexport * from './useObjectFetcher';\n"],"mappings":""}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './ApiBootstrap';\nexport * from './ClientBootstrap';\nexport * from './DeferredApiBootstrap';\nexport * from './useApi';\nexport * from './useClient';\nexport * from './useDeferredApi';\nexport * from './useObjectFetch';\nexport * from './useObjectFetcher';\nexport * from './useWidget';\n"],"mappings":""}
@@ -0,0 +1,49 @@
1
+ /// <reference types="react" />
2
+ import type { dh } from '@deephaven/jsapi-types';
3
+ /** Function for unsubscribing from a given subscription */
4
+ export type UnsubscribeFunction = () => void;
5
+ /** Update when the ObjectFetch is still loading */
6
+ export type ObjectFetchLoading = {
7
+ status: 'loading';
8
+ };
9
+ /** Update when the ObjectFetch has errored */
10
+ export type ObjectFetchError = {
11
+ error: NonNullable<unknown>;
12
+ status: 'error';
13
+ };
14
+ /** Update when the object is ready */
15
+ export type ObjectFetchReady<T> = {
16
+ fetch: () => Promise<T>;
17
+ status: 'ready';
18
+ };
19
+ /**
20
+ * Update with the current `fetch` function and status of the object.
21
+ * - If both `fetch` and `error` are `null`, it is still loading the fetcher
22
+ * - If `fetch` is not `null`, the object is ready to be fetched
23
+ * - If `error` is not `null`, there was an error loading the object
24
+ */
25
+ export type ObjectFetchUpdate<T = unknown> = ObjectFetchLoading | ObjectFetchError | ObjectFetchReady<T>;
26
+ export type ObjectFetchUpdateCallback<T = unknown> = (update: ObjectFetchUpdate<T>) => void;
27
+ /** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */
28
+ export type ObjectFetchManager = {
29
+ /**
30
+ * Subscribe to the fetch function for an object using a variable descriptor.
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.
32
+ *
33
+ * @param descriptor Descriptor object of the object to fetch. Can be extended by a specific implementation to include more details necessary for the ObjectManager.
34
+ * @param onUpdate Callback function to be called when the object is updated.
35
+ * @returns An unsubscribe function to stop listening for fetch updates and clean up the object.
36
+ */
37
+ subscribe: <T = unknown>(descriptor: dh.ide.VariableDescriptor, onUpdate: ObjectFetchUpdateCallback<T>) => UnsubscribeFunction;
38
+ };
39
+ /** Context for tracking an implementation of the ObjectFetchManager. */
40
+ export declare const ObjectFetchManagerContext: import("react").Context<ObjectFetchManager | null>;
41
+ /**
42
+ * Retrieve a `fetch` function for the given variable descriptor.
43
+ *
44
+ * @param descriptor Descriptor to get the `fetch` function for
45
+ * @returns An object with the current `fetch` function, OR an error status set if there was an issue fetching the object.
46
+ * Retrying is left up to the ObjectManager implementation used from this context.
47
+ */
48
+ export declare function useObjectFetch<T = unknown>(descriptor: dh.ide.VariableDescriptor): ObjectFetchUpdate<T>;
49
+ //# sourceMappingURL=useObjectFetch.d.ts.map
@@ -0,0 +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,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,EACrC,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,GACpC,iBAAiB,CAAC,CAAC,CAAC,CAuBtB"}
@@ -0,0 +1,51 @@
1
+ import { createContext, useContext, useEffect, useState } from 'react';
2
+
3
+ /** Function for unsubscribing from a given subscription */
4
+
5
+ /** Update when the ObjectFetch is still loading */
6
+
7
+ /** Update when the ObjectFetch has errored */
8
+
9
+ /** Update when the object is ready */
10
+
11
+ /**
12
+ * Update with the current `fetch` function and status of the object.
13
+ * - If both `fetch` and `error` are `null`, it is still loading the fetcher
14
+ * - If `fetch` is not `null`, the object is ready to be fetched
15
+ * - If `error` is not `null`, there was an error loading the object
16
+ */
17
+
18
+ /** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */
19
+
20
+ /** Context for tracking an implementation of the ObjectFetchManager. */
21
+ export var ObjectFetchManagerContext = /*#__PURE__*/createContext(null);
22
+
23
+ /**
24
+ * Retrieve a `fetch` function for the given variable descriptor.
25
+ *
26
+ * @param descriptor Descriptor to get the `fetch` function for
27
+ * @returns An object with the current `fetch` function, OR an error status set if there was an issue fetching the object.
28
+ * Retrying is left up to the ObjectManager implementation used from this context.
29
+ */
30
+ export function useObjectFetch(descriptor) {
31
+ var [currentUpdate, setCurrentUpdate] = useState({
32
+ status: 'loading'
33
+ });
34
+ var objectFetchManager = useContext(ObjectFetchManagerContext);
35
+ useEffect(() => {
36
+ if (objectFetchManager == null) {
37
+ setCurrentUpdate({
38
+ error: new Error('No ObjectFetchManager available in context'),
39
+ status: 'error'
40
+ });
41
+ return;
42
+ }
43
+ // Update to signal we're still loading, if we're not already in a loading state.
44
+ setCurrentUpdate(oldUpdate => oldUpdate.status === 'loading' ? oldUpdate : {
45
+ status: 'loading'
46
+ });
47
+ return objectFetchManager.subscribe(descriptor, setCurrentUpdate);
48
+ }, [descriptor, objectFetchManager]);
49
+ return currentUpdate;
50
+ }
51
+ //# sourceMappingURL=useObjectFetch.js.map
@@ -0,0 +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"}
@@ -0,0 +1,22 @@
1
+ import type { dh } from '@deephaven/jsapi-types';
2
+ /**
3
+ * Types of widgets that can be fetched with this hook.
4
+ */
5
+ type WidgetTypes = dh.Table | dh.TreeTable | dh.PartitionedTable | dh.plot.Figure | dh.Widget;
6
+ /**
7
+ * Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.
8
+ */
9
+ type WidgetWrapper<T extends WidgetTypes = dh.Widget> = {
10
+ /** Widget object to retrieve */
11
+ widget: T | null;
12
+ /** Error status if there was an issue fetching the widget */
13
+ error: NonNullable<unknown> | null;
14
+ };
15
+ /**
16
+ * 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.
19
+ */
20
+ export declare function useWidget<T extends WidgetTypes = dh.Widget>(descriptor: dh.ide.VariableDescriptor): WidgetWrapper<T>;
21
+ export default useWidget;
22
+ //# sourceMappingURL=useWidget.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,100 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
2
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
3
+ import Log from '@deephaven/log';
4
+ import { assertNotNull } from '@deephaven/utils';
5
+ import { useEffect, useState } from 'react';
6
+ import { useObjectFetch } from "./useObjectFetch.js";
7
+ var log = Log.module('useWidget');
8
+
9
+ /**
10
+ * Types of widgets that can be fetched with this hook.
11
+ */
12
+
13
+ /**
14
+ * Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.
15
+ */
16
+
17
+ /**
18
+ * 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.
21
+ */
22
+ export function useWidget(descriptor) {
23
+ var [wrapper, setWrapper] = useState(() => ({
24
+ widget: null,
25
+ error: null
26
+ }));
27
+ var objectFetch = useObjectFetch(descriptor);
28
+ useEffect(function loadWidget() {
29
+ log.debug('loadWidget', descriptor);
30
+ var {
31
+ status
32
+ } = objectFetch;
33
+ if (status === 'error') {
34
+ // We can't fetch if there's an error getting the fetcher, just return an error
35
+ setWrapper({
36
+ widget: null,
37
+ error: objectFetch.error
38
+ });
39
+ return;
40
+ }
41
+ if (status === 'loading') {
42
+ // Still loading
43
+ setWrapper({
44
+ widget: null,
45
+ error: null
46
+ });
47
+ return;
48
+ }
49
+ var {
50
+ fetch
51
+ } = objectFetch;
52
+ // We should be able to load the widget. Load it asynchronously, and set the widget when it's done.
53
+ // If we get cancelled before the fetch is done, we should close the widget and its exported objects.
54
+ // If not though, the consumer of the widget is expected to take ownership and close the widget appropriately.
55
+ var isCancelled = false;
56
+ function loadWidgetInternal() {
57
+ return _loadWidgetInternal.apply(this, arguments);
58
+ }
59
+ function _loadWidgetInternal() {
60
+ _loadWidgetInternal = _asyncToGenerator(function* () {
61
+ try {
62
+ assertNotNull(fetch);
63
+ var newWidget = yield fetch();
64
+ if (isCancelled) {
65
+ log.debug2('loadWidgetInternal cancelled', descriptor, newWidget);
66
+ newWidget.close();
67
+ if ('exportedObjects' in newWidget) {
68
+ newWidget.exportedObjects.forEach(exportedObject => {
69
+ exportedObject.close();
70
+ });
71
+ }
72
+ return;
73
+ }
74
+ log.debug('loadWidgetInternal done', descriptor, newWidget);
75
+ setWrapper({
76
+ widget: newWidget,
77
+ error: null
78
+ });
79
+ } catch (e) {
80
+ if (isCancelled) {
81
+ return;
82
+ }
83
+ log.error('loadWidgetInternal error', descriptor, e);
84
+ setWrapper({
85
+ widget: null,
86
+ error: e !== null && e !== void 0 ? e : new Error('Null error')
87
+ });
88
+ }
89
+ });
90
+ return _loadWidgetInternal.apply(this, arguments);
91
+ }
92
+ loadWidgetInternal();
93
+ return () => {
94
+ isCancelled = true;
95
+ };
96
+ }, [descriptor, objectFetch]);
97
+ return wrapper;
98
+ }
99
+ export default useWidget;
100
+ //# sourceMappingURL=useWidget.js.map
@@ -0,0 +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,GAAG,KAAK;IAAC,SACTC,kBAAkBA,CAAA;MAAA,OAAAC,mBAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IAAA,SAAAF,oBAAA;MAAAA,mBAAA,GAAAG,iBAAA,CAAjC,aAAoC;QAClC,IAAI;UACFtB,aAAa,CAACgB,KAAK,CAAC;UACpB,IAAMO,SAAS,SAASP,KAAK,CAAC,CAAC;UAC/B,IAAIC,WAAW,EAAE;YACfb,GAAG,CAACoB,MAAM,CAAC,8BAA8B,EAAEjB,UAAU,EAAEgB,SAAS,CAAC;YACjEA,SAAS,CAACE,KAAK,CAAC,CAAC;YACjB,IAAI,iBAAiB,IAAIF,SAAS,EAAE;cAClCA,SAAS,CAACG,eAAe,CAACC,OAAO,CAACC,cAAc,IAAI;gBAClDA,cAAc,CAACH,KAAK,CAAC,CAAC;cACxB,CAAC,CAAC;YACJ;YACA;UACF;UACArB,GAAG,CAACU,KAAK,CAAC,yBAAyB,EAAEP,UAAU,EAAEgB,SAAS,CAAC;UAE3Dd,UAAU,CAAC;YAAEC,MAAM,EAAEa,SAAS;YAAEZ,KAAK,EAAE;UAAK,CAAC,CAAC;QAChD,CAAC,CAAC,OAAOkB,CAAC,EAAE;UACV,IAAIZ,WAAW,EAAE;YACf;UACF;UACAb,GAAG,CAACO,KAAK,CAAC,0BAA0B,EAAEJ,UAAU,EAAEsB,CAAC,CAAC;UACpDpB,UAAU,CAAC;YAAEC,MAAM,EAAE,IAAI;YAAEC,KAAK,EAAEkB,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,CAACV,UAAU,EAAEK,WAAW,CAC1B,CAAC;EAED,OAAOJ,OAAO;AAChB;AAEA,eAAeF,SAAS"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven/jsapi-bootstrap",
3
- "version": "0.80.1-beta.1+03934f64",
3
+ "version": "0.80.2-alpha-radio-props.1+450a7e36",
4
4
  "description": "Deephaven JSAPI Bootstrap",
5
5
  "author": "Deephaven Data Labs LLC",
6
6
  "license": "Apache-2.0",
@@ -22,10 +22,11 @@
22
22
  "build:sass": "sass --embed-sources --load-path=../../node_modules ./src:./dist"
23
23
  },
24
24
  "dependencies": {
25
- "@deephaven/components": "^0.80.1-beta.1+03934f64",
25
+ "@deephaven/components": "^0.80.2-alpha-radio-props.1+450a7e36",
26
26
  "@deephaven/jsapi-types": "1.0.0-dev0.34.0",
27
- "@deephaven/log": "^0.80.1-beta.1+03934f64",
28
- "@deephaven/react-hooks": "^0.80.1-beta.1+03934f64"
27
+ "@deephaven/log": "^0.80.2-alpha-radio-props.1+450a7e36",
28
+ "@deephaven/react-hooks": "^0.80.2-alpha-radio-props.1+450a7e36",
29
+ "@deephaven/utils": "^0.80.2-alpha-radio-props.1+450a7e36"
29
30
  },
30
31
  "devDependencies": {
31
32
  "react": "^17.x"
@@ -40,5 +41,5 @@
40
41
  "publishConfig": {
41
42
  "access": "public"
42
43
  },
43
- "gitHead": "03934f6453a2cf302bd9489dcac08845da99feb3"
44
+ "gitHead": "450a7e36aa7262b82a67ff99eb4e5c8a4d4593ee"
44
45
  }