@deephaven/jsapi-components 1.23.1-legacy-table-plugin.bbf55c8.0 → 1.26.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.
@@ -1,4 +1,5 @@
1
1
  import type { dh } from '@deephaven/jsapi-types';
2
+ import { type OnTableUpdatedEvent } from '@deephaven/jsapi-utils';
2
3
  /**
3
4
  * Creates a callback function that will set a Table viewport. The callback has
4
5
  * a closure over the Table, a desired viewport size, and additional padding.
@@ -10,8 +11,10 @@ import type { dh } from '@deephaven/jsapi-types';
10
11
  * @param viewportSubscriptionOptions The viewport subscription options to use. If provided and
11
12
  * the table is not a `TreeTable`, the data will be requested using a `TableViewportSubscription`.
12
13
  * Rows and columns are filled in when the subscription is created if they are missing.
14
+ * @param onUpdated Optional handler for TABLE_UPDATED events. When provided, it is
15
+ * registered on the table or directly on the subscription
13
16
  * @returns A callback function for setting the viewport.
14
17
  */
15
- export declare function useSetPaddedViewportCallback(table: dh.Table | dh.TreeTable | null, viewportSize: number, viewportPadding: number, viewportSubscriptionOptions?: Partial<dh.ViewportSubscriptionOptions> | null): (firstRow: number) => void;
18
+ export declare function useSetPaddedViewportCallback(table: dh.Table | dh.TreeTable | null, viewportSize: number, viewportPadding: number, viewportSubscriptionOptions?: Partial<dh.ViewportSubscriptionOptions> | null, onUpdated?: (event: OnTableUpdatedEvent) => void): (firstRow: number) => void;
16
19
  export default useSetPaddedViewportCallback;
17
20
  //# sourceMappingURL=useSetPaddedViewportCallback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSetPaddedViewportCallback.d.ts","sourceRoot":"","sources":["../src/useSetPaddedViewportCallback.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAOjD;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,GAAG,IAAI,EACrC,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,EACvB,2BAA2B,GAAE,OAAO,CAAC,EAAE,CAAC,2BAA2B,CAAC,GAAG,IAAW,GACjF,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAmE5B;AAED,eAAe,4BAA4B,CAAC"}
1
+ {"version":3,"file":"useSetPaddedViewportCallback.d.ts","sourceRoot":"","sources":["../src/useSetPaddedViewportCallback.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,wBAAwB,CAAC;AAOhC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,GAAG,IAAI,EACrC,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,EACvB,2BAA2B,GAAE,OAAO,CAAC,EAAE,CAAC,2BAA2B,CAAC,GAAG,IAAW,EAClF,SAAS,GAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAyB,GACnE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAoG5B;AAED,eAAe,4BAA4B,CAAC"}
@@ -11,6 +11,9 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
11
11
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
12
12
  import { useCallback, useEffect, useRef } from 'react';
13
13
  import { getSize, padFirstAndLastRow, TableUtils } from '@deephaven/jsapi-utils';
14
+ import { useApi } from '@deephaven/jsapi-bootstrap';
15
+ import useTableListener from "./useTableListener.js"; // Stable no-op used as the useTableListener callback when onTableUpdated is null
16
+ var noopUpdatedHandler = _event => undefined;
14
17
 
15
18
  /**
16
19
  * Creates a callback function that will set a Table viewport. The callback has
@@ -23,14 +26,22 @@ import { getSize, padFirstAndLastRow, TableUtils } from '@deephaven/jsapi-utils'
23
26
  * @param viewportSubscriptionOptions The viewport subscription options to use. If provided and
24
27
  * the table is not a `TreeTable`, the data will be requested using a `TableViewportSubscription`.
25
28
  * Rows and columns are filled in when the subscription is created if they are missing.
29
+ * @param onUpdated Optional handler for TABLE_UPDATED events. When provided, it is
30
+ * registered on the table or directly on the subscription
26
31
  * @returns A callback function for setting the viewport.
27
32
  */
28
33
  export function useSetPaddedViewportCallback(table, viewportSize, viewportPadding) {
29
34
  var viewportSubscriptionOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
35
+ var onUpdated = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : noopUpdatedHandler;
36
+ var dh = useApi();
30
37
  var subscriptionRef = useRef(null);
38
+ var removeSubscriptionListenerRef = useRef(null);
31
39
  var prevTableRef = useRef(null);
32
40
  var prevViewportOptionsRef = useRef(null);
33
41
  var cleanupSubscription = () => {
42
+ var _removeSubscriptionLi;
43
+ (_removeSubscriptionLi = removeSubscriptionListenerRef.current) === null || _removeSubscriptionLi === void 0 || _removeSubscriptionLi.call(removeSubscriptionListenerRef);
44
+ removeSubscriptionListenerRef.current = null;
34
45
  if (subscriptionRef.current) {
35
46
  subscriptionRef.current.close();
36
47
  subscriptionRef.current = null;
@@ -42,6 +53,16 @@ export function useSetPaddedViewportCallback(table, viewportSize, viewportPaddin
42
53
  cleanupSubscription();
43
54
  }
44
55
  useEffect(() => cleanupSubscription, []);
56
+
57
+ // Only use a subscription when options are provided AND the table is not a
58
+ // TreeTable (which does not support createViewportSubscription).
59
+ var needsSubscription = viewportSubscriptionOptions != null && table != null && !TableUtils.isTreeTable(table);
60
+
61
+ // For the setViewport path (including TreeTable + options), register
62
+ // TABLE_UPDATED on the table directly.
63
+ // For the subscription path the listener is registered on the subscription
64
+ // inside setPaddedViewport when it is first created.
65
+ useTableListener(needsSubscription ? null : table, dh.Table.EVENT_UPDATED, onUpdated);
45
66
  return useCallback(function setPaddedViewport(firstRow) {
46
67
  if (table == null) {
47
68
  return;
@@ -50,7 +71,7 @@ export function useSetPaddedViewportCallback(table, viewportSize, viewportPaddin
50
71
  _padFirstAndLastRow2 = _slicedToArray(_padFirstAndLastRow, 2),
51
72
  first = _padFirstAndLastRow2[0],
52
73
  last = _padFirstAndLastRow2[1];
53
- if (subscriptionRef.current == null && viewportSubscriptionOptions != null && !TableUtils.isTreeTable(table)) {
74
+ if (subscriptionRef.current == null && needsSubscription) {
54
75
  var _viewportSubscription, _viewportSubscription2;
55
76
  var subscriptionOptions = _objectSpread(_objectSpread({}, viewportSubscriptionOptions), {}, {
56
77
  rows: (_viewportSubscription = viewportSubscriptionOptions.rows) !== null && _viewportSubscription !== void 0 ? _viewportSubscription : {
@@ -60,6 +81,10 @@ export function useSetPaddedViewportCallback(table, viewportSize, viewportPaddin
60
81
  columns: (_viewportSubscription2 = viewportSubscriptionOptions.columns) !== null && _viewportSubscription2 !== void 0 ? _viewportSubscription2 : table.columns
61
82
  });
62
83
  subscriptionRef.current = table.createViewportSubscription(subscriptionOptions);
84
+
85
+ // TABLE_UPDATED fires on the subscription rather than
86
+ // the table. Register the listener directly on the subscription.
87
+ removeSubscriptionListenerRef.current = subscriptionRef.current.addEventListener(dh.Table.EVENT_UPDATED, onUpdated);
63
88
  }
64
89
  if (subscriptionRef.current == null) {
65
90
  table.setViewport(first, last);
@@ -72,7 +97,7 @@ export function useSetPaddedViewportCallback(table, viewportSize, viewportPaddin
72
97
  },
73
98
  columns: table.columns
74
99
  });
75
- }, [table, viewportPadding, viewportSize, viewportSubscriptionOptions]);
100
+ }, [table, viewportPadding, viewportSize, viewportSubscriptionOptions, needsSubscription, onUpdated, dh.Table.EVENT_UPDATED]);
76
101
  }
77
102
  export default useSetPaddedViewportCallback;
78
103
  //# sourceMappingURL=useSetPaddedViewportCallback.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSetPaddedViewportCallback.js","names":["useCallback","useEffect","useRef","getSize","padFirstAndLastRow","TableUtils","useSetPaddedViewportCallback","table","viewportSize","viewportPadding","viewportSubscriptionOptions","arguments","length","undefined","subscriptionRef","prevTableRef","prevViewportOptionsRef","cleanupSubscription","current","close","setPaddedViewport","firstRow","_padFirstAndLastRow","_padFirstAndLastRow2","_slicedToArray","first","last","isTreeTable","_viewportSubscription","_viewportSubscription2","subscriptionOptions","_objectSpread","rows","columns","createViewportSubscription","setViewport","update"],"sources":["../src/useSetPaddedViewportCallback.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport type { dh } from '@deephaven/jsapi-types';\nimport {\n getSize,\n padFirstAndLastRow,\n TableUtils,\n} from '@deephaven/jsapi-utils';\n\n/**\n * Creates a callback function that will set a Table viewport. The callback has\n * a closure over the Table, a desired viewport size, and additional padding.\n * These will be combined with a first row index passed to the callback to\n * calculate the final viewport.\n * @param table The `Table` or `TreeTable` to retrieve data from.\n * @param viewportSize The desired viewport size.\n * @param viewportPadding The padding to add before and after the viewport.\n * @param viewportSubscriptionOptions The viewport subscription options to use. If provided and\n * the table is not a `TreeTable`, the data will be requested using a `TableViewportSubscription`.\n * Rows and columns are filled in when the subscription is created if they are missing.\n * @returns A callback function for setting the viewport.\n */\nexport function useSetPaddedViewportCallback(\n table: dh.Table | dh.TreeTable | null,\n viewportSize: number,\n viewportPadding: number,\n viewportSubscriptionOptions: Partial<dh.ViewportSubscriptionOptions> | null = null\n): (firstRow: number) => void {\n const subscriptionRef = useRef<dh.TableViewportSubscription | null>(null);\n const prevTableRef = useRef<dh.Table | dh.TreeTable | null>(null);\n const prevViewportOptionsRef =\n useRef<Partial<dh.ViewportSubscriptionOptions> | null>(null);\n\n const cleanupSubscription = () => {\n if (subscriptionRef.current) {\n subscriptionRef.current.close();\n subscriptionRef.current = null;\n }\n };\n\n if (\n prevTableRef.current !== table ||\n prevViewportOptionsRef.current !== viewportSubscriptionOptions\n ) {\n prevTableRef.current = table;\n prevViewportOptionsRef.current = viewportSubscriptionOptions;\n cleanupSubscription();\n }\n\n useEffect(() => cleanupSubscription, []);\n\n return useCallback(\n function setPaddedViewport(firstRow: number) {\n if (table == null) {\n return;\n }\n\n const [first, last] = padFirstAndLastRow(\n firstRow,\n viewportSize,\n viewportPadding,\n getSize(table)\n );\n\n if (\n subscriptionRef.current == null &&\n viewportSubscriptionOptions != null &&\n !TableUtils.isTreeTable(table)\n ) {\n const subscriptionOptions: dh.ViewportSubscriptionOptions = {\n ...viewportSubscriptionOptions,\n rows: viewportSubscriptionOptions.rows ?? { first, last },\n columns: viewportSubscriptionOptions.columns ?? table.columns,\n };\n\n subscriptionRef.current =\n table.createViewportSubscription(subscriptionOptions);\n }\n\n if (subscriptionRef.current == null) {\n table.setViewport(first, last);\n return;\n }\n\n subscriptionRef.current.update({\n rows: {\n first,\n last,\n },\n columns: table.columns,\n });\n },\n [table, viewportPadding, viewportSize, viewportSubscriptionOptions]\n );\n}\n\nexport default useSetPaddedViewportCallback;\n"],"mappings":";;;;;;;;;;;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAEtD,SACEC,OAAO,EACPC,kBAAkB,EAClBC,UAAU,QACL,wBAAwB;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,4BAA4BA,CAC1CC,KAAqC,EACrCC,YAAoB,EACpBC,eAAuB,EAEK;EAAA,IAD5BC,2BAA2E,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EAElF,IAAMG,eAAe,GAAGZ,MAAM,CAAsC,IAAI,CAAC;EACzE,IAAMa,YAAY,GAAGb,MAAM,CAAiC,IAAI,CAAC;EACjE,IAAMc,sBAAsB,GAC1Bd,MAAM,CAAiD,IAAI,CAAC;EAE9D,IAAMe,mBAAmB,GAAGA,CAAA,KAAM;IAChC,IAAIH,eAAe,CAACI,OAAO,EAAE;MAC3BJ,eAAe,CAACI,OAAO,CAACC,KAAK,CAAC,CAAC;MAC/BL,eAAe,CAACI,OAAO,GAA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CX,KAAK,CAAC4B,WAAW,CAACV,KAAK,EAAEC,IAAI,CAAC;MAC9B;IACF;IAEAZ,eAAe,CAACI,OAAO,CAACkB,MAAM,CAAC;MAC7BJ,IAAI,EAAE;QACJP,KAAK;QACLC;MACF,CAAC;MACDO,OAAO,EAAE1B,KAAK,CAAC0B;IACjB,CAAC,CAAC;EACJ,CAAC,EACD,CAAC1B,KAAK,EAAEE,eAAe,EAAED,YAAY,EAAEE,2BAA2B,CACpE,CAAC;AACH;AAEA,eAAeJ,4BAA4B","ignoreList":[]}
1
+ {"version":3,"file":"useSetPaddedViewportCallback.js","names":["useCallback","useEffect","useRef","getSize","padFirstAndLastRow","TableUtils","useApi","useTableListener","noopUpdatedHandler","_event","undefined","useSetPaddedViewportCallback","table","viewportSize","viewportPadding","viewportSubscriptionOptions","arguments","length","onUpdated","dh","subscriptionRef","removeSubscriptionListenerRef","prevTableRef","prevViewportOptionsRef","cleanupSubscription","_removeSubscriptionLi","current","call","close","needsSubscription","isTreeTable","Table","EVENT_UPDATED","setPaddedViewport","firstRow","_padFirstAndLastRow","_padFirstAndLastRow2","_slicedToArray","first","last","_viewportSubscription","_viewportSubscription2","subscriptionOptions","_objectSpread","rows","columns","createViewportSubscription","addEventListener","setViewport","update"],"sources":["../src/useSetPaddedViewportCallback.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport type { dh } from '@deephaven/jsapi-types';\nimport {\n getSize,\n padFirstAndLastRow,\n TableUtils,\n type OnTableUpdatedEvent,\n} from '@deephaven/jsapi-utils';\nimport { useApi } from '@deephaven/jsapi-bootstrap';\nimport useTableListener from './useTableListener';\n\n// Stable no-op used as the useTableListener callback when onTableUpdated is null\nconst noopUpdatedHandler = (_event: OnTableUpdatedEvent): void => undefined;\n\n/**\n * Creates a callback function that will set a Table viewport. The callback has\n * a closure over the Table, a desired viewport size, and additional padding.\n * These will be combined with a first row index passed to the callback to\n * calculate the final viewport.\n * @param table The `Table` or `TreeTable` to retrieve data from.\n * @param viewportSize The desired viewport size.\n * @param viewportPadding The padding to add before and after the viewport.\n * @param viewportSubscriptionOptions The viewport subscription options to use. If provided and\n * the table is not a `TreeTable`, the data will be requested using a `TableViewportSubscription`.\n * Rows and columns are filled in when the subscription is created if they are missing.\n * @param onUpdated Optional handler for TABLE_UPDATED events. When provided, it is\n * registered on the table or directly on the subscription\n * @returns A callback function for setting the viewport.\n */\nexport function useSetPaddedViewportCallback(\n table: dh.Table | dh.TreeTable | null,\n viewportSize: number,\n viewportPadding: number,\n viewportSubscriptionOptions: Partial<dh.ViewportSubscriptionOptions> | null = null,\n onUpdated: (event: OnTableUpdatedEvent) => void = noopUpdatedHandler\n): (firstRow: number) => void {\n const dh = useApi();\n const subscriptionRef = useRef<dh.TableViewportSubscription | null>(null);\n const removeSubscriptionListenerRef = useRef<(() => void) | null>(null);\n const prevTableRef = useRef<dh.Table | dh.TreeTable | null>(null);\n const prevViewportOptionsRef =\n useRef<Partial<dh.ViewportSubscriptionOptions> | null>(null);\n\n const cleanupSubscription = () => {\n removeSubscriptionListenerRef.current?.();\n removeSubscriptionListenerRef.current = null;\n if (subscriptionRef.current) {\n subscriptionRef.current.close();\n subscriptionRef.current = null;\n }\n };\n\n if (\n prevTableRef.current !== table ||\n prevViewportOptionsRef.current !== viewportSubscriptionOptions\n ) {\n prevTableRef.current = table;\n prevViewportOptionsRef.current = viewportSubscriptionOptions;\n cleanupSubscription();\n }\n\n useEffect(() => cleanupSubscription, []);\n\n // Only use a subscription when options are provided AND the table is not a\n // TreeTable (which does not support createViewportSubscription).\n const needsSubscription =\n viewportSubscriptionOptions != null &&\n table != null &&\n !TableUtils.isTreeTable(table);\n\n // For the setViewport path (including TreeTable + options), register\n // TABLE_UPDATED on the table directly.\n // For the subscription path the listener is registered on the subscription\n // inside setPaddedViewport when it is first created.\n useTableListener(\n needsSubscription ? null : table,\n dh.Table.EVENT_UPDATED,\n onUpdated\n );\n\n return useCallback(\n function setPaddedViewport(firstRow: number) {\n if (table == null) {\n return;\n }\n\n const [first, last] = padFirstAndLastRow(\n firstRow,\n viewportSize,\n viewportPadding,\n getSize(table)\n );\n\n if (subscriptionRef.current == null && needsSubscription) {\n const subscriptionOptions: dh.ViewportSubscriptionOptions = {\n ...viewportSubscriptionOptions,\n rows: viewportSubscriptionOptions.rows ?? { first, last },\n columns: viewportSubscriptionOptions.columns ?? table.columns,\n };\n\n subscriptionRef.current =\n table.createViewportSubscription(subscriptionOptions);\n\n // TABLE_UPDATED fires on the subscription rather than\n // the table. Register the listener directly on the subscription.\n removeSubscriptionListenerRef.current =\n subscriptionRef.current.addEventListener(\n dh.Table.EVENT_UPDATED,\n onUpdated\n );\n }\n\n if (subscriptionRef.current == null) {\n table.setViewport(first, last);\n return;\n }\n\n subscriptionRef.current.update({\n rows: {\n first,\n last,\n },\n columns: table.columns,\n });\n },\n [\n table,\n viewportPadding,\n viewportSize,\n viewportSubscriptionOptions,\n needsSubscription,\n onUpdated,\n dh.Table.EVENT_UPDATED,\n ]\n );\n}\n\nexport default useSetPaddedViewportCallback;\n"],"mappings":";;;;;;;;;;;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAEtD,SACEC,OAAO,EACPC,kBAAkB,EAClBC,UAAU,QAEL,wBAAwB;AAC/B,SAASC,MAAM,QAAQ,4BAA4B;AAAC,OAC7CC,gBAAgB,+BAEvB;AACA,IAAMC,kBAAkB,GAAIC,MAA2B,IAAWC,SAAS;;AAE3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,4BAA4BA,CAC1CC,KAAqC,EACrCC,YAAoB,EACpBC,eAAuB,EAGK;EAAA,IAF5BC,2BAA2E,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAN,SAAA,GAAAM,SAAA,MAAG,IAAI;EAAA,IAClFE,SAA+C,GAAAF,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAN,SAAA,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C,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;IACxC,2BAA2B,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,2BAA2B,CAAC,GAAG,IAAI,CAAC;CAC9E;AAED,MAAM,WAAW,qBAAqB,CACpC,KAAK,EACL,MAAM,SAAS,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS;IAEtC,gEAAgE;IAChE,YAAY,EAAE,gBAAgB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACjD,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IAEb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,0CAA0C;IAC1C,sBAAsB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,eAAe,EAAE,KAAK,IAAI,CAAC;IAChE,oCAAoC;IACpC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,mDAAmD;IACnD,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,SAAS,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,EAAE,EAC7E,KAAK,EACL,UAAc,EACd,cAAmC,EACnC,YAAiB,EACjB,eAAoB,EACpB,cAAuC,EACvC,uBAA+B,EAC/B,2BAAkC,GACnC,EAAE,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CAsF5E;AAED,eAAe,eAAe,CAAC"}
@@ -1,12 +1,10 @@
1
1
  import { useCallback, useEffect, useMemo, useRef } from 'react';
2
2
  import { defaultRowDeserializer, isClosed, createOnTableUpdatedHandler } from '@deephaven/jsapi-utils';
3
3
  import Log from '@deephaven/log';
4
- import { useApi } from '@deephaven/jsapi-bootstrap';
5
4
  import { useOnScrollOffsetChangeCallback } from '@deephaven/react-hooks';
6
5
  import useInitializeViewportData from "./useInitializeViewportData.js";
7
6
  import useSetPaddedViewportCallback from "./useSetPaddedViewportCallback.js";
8
7
  import useTableSize from "./useTableSize.js";
9
- import useTableListener from "./useTableListener.js";
10
8
  import { SCROLL_DEBOUNCE_MS } from "./Constants.js";
11
9
  var log = Log.module('useViewportData');
12
10
  /**
@@ -47,7 +45,18 @@ export function useViewportData(_ref) {
47
45
  viewportSubscriptionOptions = _ref$viewportSubscrip === void 0 ? null : _ref$viewportSubscrip;
48
46
  var currentViewportFirstRowRef = useRef(0);
49
47
  var viewportData = useInitializeViewportData(table, reuseItemsOnTableResize);
50
- var setPaddedViewport = useSetPaddedViewportCallback(table, viewportSize, viewportPadding, viewportSubscriptionOptions);
48
+
49
+ // Store the memoized callback in a ref so that changes to `viewportData`
50
+ // don't invalidate the memoization of `onTableUpdated`. This prevents
51
+ // `useTableListener` from unnecessarily re-subscribing to the same event over
52
+ // and over.
53
+ var onTableUpdatedRef = useRef();
54
+ onTableUpdatedRef.current = useMemo(() => createOnTableUpdatedHandler(viewportData, deserializeRow), [deserializeRow, viewportData]);
55
+ var onTableUpdated = useCallback(event => {
56
+ var _onTableUpdatedRef$cu;
57
+ (_onTableUpdatedRef$cu = onTableUpdatedRef.current) === null || _onTableUpdatedRef$cu === void 0 || _onTableUpdatedRef$cu.call(onTableUpdatedRef, event);
58
+ }, []);
59
+ var setPaddedViewport = useSetPaddedViewportCallback(table, viewportSize, viewportPadding, viewportSubscriptionOptions, onTableUpdated);
51
60
  var setViewport = useCallback(firstRow => {
52
61
  currentViewportFirstRowRef.current = firstRow;
53
62
  if (table && !isClosed(table)) {
@@ -64,19 +73,6 @@ export function useViewportData(_ref) {
64
73
  log.debug('applyFiltersAndRefresh called on closed table.', table);
65
74
  }
66
75
  }, [setViewport, table]);
67
- var dh = useApi();
68
-
69
- // Store the memoized callback in a ref so that changes to `viewportData`
70
- // don't invalidate the memoization of `onTableUpdated`. This prevents
71
- // `useTableListener` from unnecessarily re-subscribing to the same event over
72
- // and over.
73
- var onTableUpdatedRef = useRef();
74
- onTableUpdatedRef.current = useMemo(() => createOnTableUpdatedHandler(viewportData, deserializeRow), [deserializeRow, viewportData]);
75
- var onTableUpdated = useCallback(event => {
76
- var _onTableUpdatedRef$cu;
77
- (_onTableUpdatedRef$cu = onTableUpdatedRef.current) === null || _onTableUpdatedRef$cu === void 0 || _onTableUpdatedRef$cu.call(onTableUpdatedRef, event);
78
- }, []);
79
- useTableListener(table, dh.Table.EVENT_UPDATED, onTableUpdated);
80
76
  var size = useTableSize(table);
81
77
  useEffect(() => {
82
78
  log.debug('Initializing viewport');
@@ -1 +1 @@
1
- {"version":3,"file":"useViewportData.js","names":["useCallback","useEffect","useMemo","useRef","defaultRowDeserializer","isClosed","createOnTableUpdatedHandler","Log","useApi","useOnScrollOffsetChangeCallback","useInitializeViewportData","useSetPaddedViewportCallback","useTableSize","useTableListener","SCROLL_DEBOUNCE_MS","log","module","useViewportData","_ref","table","_ref$itemHeight","itemHeight","_ref$scrollDebounce","scrollDebounce","_ref$viewportSize","viewportSize","_ref$viewportPadding","viewportPadding","_ref$deserializeRow","deserializeRow","_ref$reuseItemsOnTabl","reuseItemsOnTableResize","_ref$viewportSubscrip","viewportSubscriptionOptions","currentViewportFirstRowRef","viewportData","setPaddedViewport","setViewport","firstRow","current","debug","applyFiltersAndRefresh","filters","applyFilter","dh","onTableUpdatedRef","onTableUpdated","event","_onTableUpdatedRef$cu","call","Table","EVENT_UPDATED","size","onScroll"],"sources":["../src/useViewportData.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef } from 'react';\nimport type { dh } from '@deephaven/jsapi-types';\nimport {\n type RowDeserializer,\n defaultRowDeserializer,\n isClosed,\n createOnTableUpdatedHandler,\n type OnTableUpdatedEvent,\n} from '@deephaven/jsapi-utils';\nimport Log from '@deephaven/log';\nimport { useApi } from '@deephaven/jsapi-bootstrap';\nimport {\n useOnScrollOffsetChangeCallback,\n type WindowedListData,\n} from '@deephaven/react-hooks';\nimport { type KeyedItem } from '@deephaven/utils';\nimport useInitializeViewportData from './useInitializeViewportData';\nimport useSetPaddedViewportCallback from './useSetPaddedViewportCallback';\nimport useTableSize from './useTableSize';\nimport useTableListener from './useTableListener';\nimport { SCROLL_DEBOUNCE_MS } from './Constants';\n\nconst log = Log.module('useViewportData');\n\nexport interface UseViewportDataProps<\n TItem,\n TTable extends dh.Table | dh.TreeTable,\n> {\n reuseItemsOnTableResize?: boolean;\n table: TTable | null;\n itemHeight?: number;\n scrollDebounce?: number;\n viewportPadding?: number;\n viewportSize?: number;\n deserializeRow?: RowDeserializer<TItem>;\n viewportSubscriptionOptions?: Partial<dh.ViewportSubscriptionOptions> | null;\n}\n\nexport interface UseViewportDataResult<\n TItem,\n TTable extends dh.Table | dh.TreeTable,\n> {\n /** Manages deserialized row items associated with a DH Table */\n viewportData: WindowedListData<KeyedItem<TItem>>;\n /** Size of the underlying Table */\n size: number;\n\n table: TTable | null;\n /** Apply filters and refresh viewport. */\n applyFiltersAndRefresh: (filters: dh.FilterCondition[]) => void;\n /** Set the viewport of the Table */\n setViewport: (firstRow: number) => void;\n /** Handler for scroll events to update viewport */\n onScroll: (event: Event) => void;\n}\n\n/**\n * Sets up state management for windowed Table viewports. Returns a ListData\n * instance for managing items associated with the Table + a `setViewport`\n * callback for changing the current viewport.\n *\n * IMPORTANT: this will create an empty KeyedItem object for every row in the\n * source table. This is intended for \"human\" sized tables such as those used in\n * admin panels. This is not suitable for \"machine\" scale with millions+ rows.\n * @param table The Table to viewport.\n * @param itemHeight The height of each item in the viewport.\n * @param scrollDebounce The number of milliseconds to debounce scroll events.\n * @param viewportSize The number of items to display in the viewport.\n * @param viewportPadding The number of items to fetch at start and end of the viewport.\n * @param deserializeRow A function to deserialize a row from the Table.\n * @param reuseItemsOnTableResize If true, existing items will be re-used when\n * @param viewportSubscriptionOptions The viewport subscription options to use. If provided and\n * the table is not a `TreeTable`, the data will be requested using a `TableViewportSubscription`.\n * Rows and columns are filled in when the subscription is created if they are missing.\n * @returns An object for managing Table viewport state.\n */\nexport function useViewportData<TItem, TTable extends dh.Table | dh.TreeTable>({\n table,\n itemHeight = 1,\n scrollDebounce = SCROLL_DEBOUNCE_MS,\n viewportSize = 10,\n viewportPadding = 50,\n deserializeRow = defaultRowDeserializer,\n reuseItemsOnTableResize = false,\n viewportSubscriptionOptions = null,\n}: UseViewportDataProps<TItem, TTable>): UseViewportDataResult<TItem, TTable> {\n const currentViewportFirstRowRef = useRef<number>(0);\n\n const viewportData = useInitializeViewportData<TItem>(\n table,\n reuseItemsOnTableResize\n );\n\n const setPaddedViewport = useSetPaddedViewportCallback(\n table,\n viewportSize,\n viewportPadding,\n viewportSubscriptionOptions\n );\n\n const setViewport = useCallback(\n (firstRow: number) => {\n currentViewportFirstRowRef.current = firstRow;\n\n if (table && !isClosed(table)) {\n setPaddedViewport(firstRow);\n } else {\n log.debug('setViewport called on closed table.', table);\n }\n },\n [table, setPaddedViewport]\n );\n\n const applyFiltersAndRefresh = useCallback(\n (filters: dh.FilterCondition[]) => {\n if (table && !isClosed(table)) {\n table.applyFilter(filters);\n setViewport(0);\n } else {\n log.debug('applyFiltersAndRefresh called on closed table.', table);\n }\n },\n [setViewport, table]\n );\n\n const dh = useApi();\n\n // Store the memoized callback in a ref so that changes to `viewportData`\n // don't invalidate the memoization of `onTableUpdated`. This prevents\n // `useTableListener` from unnecessarily re-subscribing to the same event over\n // and over.\n const onTableUpdatedRef = useRef<(event: OnTableUpdatedEvent) => void>();\n onTableUpdatedRef.current = useMemo(\n () => createOnTableUpdatedHandler(viewportData, deserializeRow),\n [deserializeRow, viewportData]\n );\n\n const onTableUpdated = useCallback((event: OnTableUpdatedEvent) => {\n onTableUpdatedRef.current?.(event);\n }, []);\n\n useTableListener(table, dh.Table.EVENT_UPDATED, onTableUpdated);\n\n const size = useTableSize(table);\n\n useEffect(() => {\n log.debug('Initializing viewport');\n\n // Hydrate the viewport with real data. This will fetch data from index\n // 0 to the end of the viewport + padding.\n setViewport(0);\n }, [table, setViewport]);\n\n useEffect(() => {\n setViewport(currentViewportFirstRowRef.current);\n }, [setViewport, size]);\n\n const onScroll = useOnScrollOffsetChangeCallback(\n itemHeight,\n setViewport,\n scrollDebounce\n );\n\n return useMemo(\n () => ({\n viewportData,\n size,\n table,\n applyFiltersAndRefresh,\n setViewport,\n onScroll,\n }),\n [applyFiltersAndRefresh, onScroll, setViewport, size, table, viewportData]\n );\n}\n\nexport default useViewportData;\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAE/D,SAEEC,sBAAsB,EACtBC,QAAQ,EACRC,2BAA2B,QAEtB,wBAAwB;AAC/B,OAAOC,GAAG,MAAM,gBAAgB;AAChC,SAASC,MAAM,QAAQ,4BAA4B;AACnD,SACEC,+BAA+B,QAE1B,wBAAwB;AAAC,OAEzBC,yBAAyB;AAAA,OACzBC,4BAA4B;AAAA,OAC5BC,YAAY;AAAA,OACZC,gBAAgB;AAAA,SACdC,kBAAkB;AAE3B,IAAMC,GAAG,GAAGR,GAAG,CAACS,MAAM,CAAC,iBAAiB,CAAC;AAkCzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAAAC,IAAA,EAS+C;EAAA,IAR5EC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAAC,eAAA,GAAAF,IAAA,CACLG,UAAU;IAAVA,UAAU,GAAAD,eAAA,cAAG,CAAC,GAAAA,eAAA;IAAAE,mBAAA,GAAAJ,IAAA,CACdK,cAAc;IAAdA,cAAc,GAAAD,mBAAA,cAAGR,kBAAkB,GAAAQ,mBAAA;IAAAE,iBAAA,GAAAN,IAAA,CACnCO,YAAY;IAAZA,YAAY,GAAAD,iBAAA,cAAG,EAAE,GAAAA,iBAAA;IAAAE,oBAAA,GAAAR,IAAA,CAC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,IAAI,EAAEjC,KAAK,EAAEgB,YAAY,CAC3E,CAAC;AACH;AAEA,eAAelB,eAAe","ignoreList":[]}
1
+ {"version":3,"file":"useViewportData.js","names":["useCallback","useEffect","useMemo","useRef","defaultRowDeserializer","isClosed","createOnTableUpdatedHandler","Log","useOnScrollOffsetChangeCallback","useInitializeViewportData","useSetPaddedViewportCallback","useTableSize","SCROLL_DEBOUNCE_MS","log","module","useViewportData","_ref","table","_ref$itemHeight","itemHeight","_ref$scrollDebounce","scrollDebounce","_ref$viewportSize","viewportSize","_ref$viewportPadding","viewportPadding","_ref$deserializeRow","deserializeRow","_ref$reuseItemsOnTabl","reuseItemsOnTableResize","_ref$viewportSubscrip","viewportSubscriptionOptions","currentViewportFirstRowRef","viewportData","onTableUpdatedRef","current","onTableUpdated","event","_onTableUpdatedRef$cu","call","setPaddedViewport","setViewport","firstRow","debug","applyFiltersAndRefresh","filters","applyFilter","size","onScroll"],"sources":["../src/useViewportData.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef } from 'react';\nimport type { dh } from '@deephaven/jsapi-types';\nimport {\n type RowDeserializer,\n defaultRowDeserializer,\n isClosed,\n createOnTableUpdatedHandler,\n type OnTableUpdatedEvent,\n} from '@deephaven/jsapi-utils';\nimport Log from '@deephaven/log';\nimport {\n useOnScrollOffsetChangeCallback,\n type WindowedListData,\n} from '@deephaven/react-hooks';\nimport { type KeyedItem } from '@deephaven/utils';\nimport useInitializeViewportData from './useInitializeViewportData';\nimport useSetPaddedViewportCallback from './useSetPaddedViewportCallback';\nimport useTableSize from './useTableSize';\nimport { SCROLL_DEBOUNCE_MS } from './Constants';\n\nconst log = Log.module('useViewportData');\n\nexport interface UseViewportDataProps<\n TItem,\n TTable extends dh.Table | dh.TreeTable,\n> {\n reuseItemsOnTableResize?: boolean;\n table: TTable | null;\n itemHeight?: number;\n scrollDebounce?: number;\n viewportPadding?: number;\n viewportSize?: number;\n deserializeRow?: RowDeserializer<TItem>;\n viewportSubscriptionOptions?: Partial<dh.ViewportSubscriptionOptions> | null;\n}\n\nexport interface UseViewportDataResult<\n TItem,\n TTable extends dh.Table | dh.TreeTable,\n> {\n /** Manages deserialized row items associated with a DH Table */\n viewportData: WindowedListData<KeyedItem<TItem>>;\n /** Size of the underlying Table */\n size: number;\n\n table: TTable | null;\n /** Apply filters and refresh viewport. */\n applyFiltersAndRefresh: (filters: dh.FilterCondition[]) => void;\n /** Set the viewport of the Table */\n setViewport: (firstRow: number) => void;\n /** Handler for scroll events to update viewport */\n onScroll: (event: Event) => void;\n}\n\n/**\n * Sets up state management for windowed Table viewports. Returns a ListData\n * instance for managing items associated with the Table + a `setViewport`\n * callback for changing the current viewport.\n *\n * IMPORTANT: this will create an empty KeyedItem object for every row in the\n * source table. This is intended for \"human\" sized tables such as those used in\n * admin panels. This is not suitable for \"machine\" scale with millions+ rows.\n * @param table The Table to viewport.\n * @param itemHeight The height of each item in the viewport.\n * @param scrollDebounce The number of milliseconds to debounce scroll events.\n * @param viewportSize The number of items to display in the viewport.\n * @param viewportPadding The number of items to fetch at start and end of the viewport.\n * @param deserializeRow A function to deserialize a row from the Table.\n * @param reuseItemsOnTableResize If true, existing items will be re-used when\n * @param viewportSubscriptionOptions The viewport subscription options to use. If provided and\n * the table is not a `TreeTable`, the data will be requested using a `TableViewportSubscription`.\n * Rows and columns are filled in when the subscription is created if they are missing.\n * @returns An object for managing Table viewport state.\n */\nexport function useViewportData<TItem, TTable extends dh.Table | dh.TreeTable>({\n table,\n itemHeight = 1,\n scrollDebounce = SCROLL_DEBOUNCE_MS,\n viewportSize = 10,\n viewportPadding = 50,\n deserializeRow = defaultRowDeserializer,\n reuseItemsOnTableResize = false,\n viewportSubscriptionOptions = null,\n}: UseViewportDataProps<TItem, TTable>): UseViewportDataResult<TItem, TTable> {\n const currentViewportFirstRowRef = useRef<number>(0);\n\n const viewportData = useInitializeViewportData<TItem>(\n table,\n reuseItemsOnTableResize\n );\n\n // Store the memoized callback in a ref so that changes to `viewportData`\n // don't invalidate the memoization of `onTableUpdated`. This prevents\n // `useTableListener` from unnecessarily re-subscribing to the same event over\n // and over.\n const onTableUpdatedRef = useRef<(event: OnTableUpdatedEvent) => void>();\n onTableUpdatedRef.current = useMemo(\n () => createOnTableUpdatedHandler(viewportData, deserializeRow),\n [deserializeRow, viewportData]\n );\n\n const onTableUpdated = useCallback((event: OnTableUpdatedEvent) => {\n onTableUpdatedRef.current?.(event);\n }, []);\n\n const setPaddedViewport = useSetPaddedViewportCallback(\n table,\n viewportSize,\n viewportPadding,\n viewportSubscriptionOptions,\n onTableUpdated\n );\n\n const setViewport = useCallback(\n (firstRow: number) => {\n currentViewportFirstRowRef.current = firstRow;\n\n if (table && !isClosed(table)) {\n setPaddedViewport(firstRow);\n } else {\n log.debug('setViewport called on closed table.', table);\n }\n },\n [table, setPaddedViewport]\n );\n\n const applyFiltersAndRefresh = useCallback(\n (filters: dh.FilterCondition[]) => {\n if (table && !isClosed(table)) {\n table.applyFilter(filters);\n setViewport(0);\n } else {\n log.debug('applyFiltersAndRefresh called on closed table.', table);\n }\n },\n [setViewport, table]\n );\n\n const size = useTableSize(table);\n\n useEffect(() => {\n log.debug('Initializing viewport');\n\n // Hydrate the viewport with real data. This will fetch data from index\n // 0 to the end of the viewport + padding.\n setViewport(0);\n }, [table, setViewport]);\n\n useEffect(() => {\n setViewport(currentViewportFirstRowRef.current);\n }, [setViewport, size]);\n\n const onScroll = useOnScrollOffsetChangeCallback(\n itemHeight,\n setViewport,\n scrollDebounce\n );\n\n return useMemo(\n () => ({\n viewportData,\n size,\n table,\n applyFiltersAndRefresh,\n setViewport,\n onScroll,\n }),\n [applyFiltersAndRefresh, onScroll, setViewport, size, table, viewportData]\n );\n}\n\nexport default useViewportData;\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAE/D,SAEEC,sBAAsB,EACtBC,QAAQ,EACRC,2BAA2B,QAEtB,wBAAwB;AAC/B,OA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AAM8B,IAAI,GAAGpC,YAAY,CAACM,KAAK,CAAC;EAEhChB,SAAS,CAAC,MAAM;IACdY,GAAG,CAAC8B,KAAK,CAAC,uBAAuB,CAAC;;IAElC;IACA;IACAF,WAAW,CAAC,CAAC,CAAC;EAChB,CAAC,EAAE,CAACxB,KAAK,EAAEwB,WAAW,CAAC,CAAC;EAExBxC,SAAS,CAAC,MAAM;IACdwC,WAAW,CAACT,0BAA0B,CAACG,OAAO,CAAC;EACjD,CAAC,EAAE,CAACM,WAAW,EAAEM,IAAI,CAAC,CAAC;EAEvB,IAAMC,QAAQ,GAAGxC,+BAA+B,CAC9CW,UAAU,EACVsB,WAAW,EACXpB,cACF,CAAC;EAED,OAAOnB,OAAO,CACZ,OAAO;IACL+B,YAAY;IACZc,IAAI;IACJ9B,KAAK;IACL2B,sBAAsB;IACtBH,WAAW;IACXO;EACF,CAAC,CAAC,EACF,CAACJ,sBAAsB,EAAEI,QAAQ,EAAEP,WAAW,EAAEM,IAAI,EAAE9B,KAAK,EAAEgB,YAAY,CAC3E,CAAC;AACH;AAEA,eAAelB,eAAe","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven/jsapi-components",
3
- "version": "1.23.1-legacy-table-plugin.bbf55c8.0+bbf55c8",
3
+ "version": "1.26.1",
4
4
  "description": "Deephaven JSAPI Components",
5
5
  "author": "Deephaven Data Labs LLC",
6
6
  "license": "Apache-2.0",
@@ -22,21 +22,21 @@
22
22
  "build:sass": "sass --embed-sources --load-path=../../node_modules ./src:./dist"
23
23
  },
24
24
  "dependencies": {
25
- "@deephaven/components": "^1.23.1-legacy-table-plugin.bbf55c8.0+bbf55c8",
26
- "@deephaven/jsapi-bootstrap": "^1.23.1-legacy-table-plugin.bbf55c8.0+bbf55c8",
25
+ "@deephaven/components": "^1.22.1",
26
+ "@deephaven/jsapi-bootstrap": "^1.23.0",
27
27
  "@deephaven/jsapi-types": "^1.0.0-dev0.40.4",
28
- "@deephaven/jsapi-utils": "^1.23.1-legacy-table-plugin.bbf55c8.0+bbf55c8",
29
- "@deephaven/log": "^1.23.1-legacy-table-plugin.bbf55c8.0+bbf55c8",
30
- "@deephaven/react-hooks": "^1.23.1-legacy-table-plugin.bbf55c8.0+bbf55c8",
31
- "@deephaven/utils": "^1.23.1-legacy-table-plugin.bbf55c8.0+bbf55c8",
28
+ "@deephaven/jsapi-utils": "^1.23.0",
29
+ "@deephaven/log": "^1.8.0",
30
+ "@deephaven/react-hooks": "^1.21.1",
31
+ "@deephaven/utils": "^1.10.0",
32
32
  "@types/js-cookie": "^3.0.3",
33
33
  "classnames": "^2.3.2",
34
34
  "js-cookie": "^3.0.5",
35
35
  "lodash.debounce": "^4.0.8"
36
36
  },
37
37
  "devDependencies": {
38
- "@deephaven/jsapi-shim": "^1.23.1-legacy-table-plugin.bbf55c8.0+bbf55c8",
39
- "@deephaven/test-utils": "^1.23.1-legacy-table-plugin.bbf55c8.0+bbf55c8"
38
+ "@deephaven/jsapi-shim": "^1.9.0",
39
+ "@deephaven/test-utils": "^1.8.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": ">=16.8.0"
@@ -50,5 +50,5 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "bbf55c8e8e005d3d1aa6bc4800a64499a6ad7288"
53
+ "gitHead": "9d0c4b05d92671e7690be73f7b7784656d75e0c5"
54
54
  }