gm-datagrid 0.1.3 → 0.1.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,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
- import { Row } from '../types';
2
+ import { GroupHeader, Row } from '../types';
3
3
  import { DataSetState } from '../dataset/useGMDataSet';
4
4
  interface GridContextValue extends DataSetState {
5
5
  pageRows: Row[];
@@ -12,6 +12,12 @@ interface GridContextValue extends DataSetState {
12
12
  engineReady: boolean;
13
13
  engineError: Error | null;
14
14
  retryEngine: () => void;
15
+ groupBy: string | null;
16
+ setGroupBy: (field: string | null) => void;
17
+ groups: GroupHeader[];
18
+ expandedGroups: Set<string>;
19
+ groupRows: Record<string, Row[]>;
20
+ toggleGroup: (key: string) => void;
15
21
  }
16
22
  interface GridProviderProps {
17
23
  dataset: DataSetState;
@@ -1,4 +1,4 @@
1
- import { ColumnDef, FilterGroup, Row, SortKey } from '../types';
1
+ import { ColumnDef, FilterGroup, GroupHeader, Row, SortKey } from '../types';
2
2
  interface UseEngineSyncProps {
3
3
  engine: any;
4
4
  ready: boolean;
@@ -12,17 +12,23 @@ interface UseEngineSyncProps {
12
12
  sortStack?: SortKey[];
13
13
  filterGroup?: FilterGroup | null;
14
14
  quickFilterText?: string;
15
+ /** When set, calls engine.set_group_by() and fires onGroups with the resulting headers. */
16
+ groupBy?: string | null;
17
+ onGroups?: (groups: GroupHeader[]) => void;
15
18
  }
16
19
  /**
17
20
  * Syncs React state → Wasm engine (push) and pulls page data + subtotals back.
18
21
  *
19
- * Sort, filter and quick-filter are applied INSIDE this hook immediately after
20
- * engine.load_data(), which guarantees the engine's memory is initialised before
21
- * any method is called. This prevents the "memory access out of bounds" WASM
22
- * crash that occurs when those calls are made from a render-body side-effect.
22
+ * IMPORTANT: push and pull are intentionally in ONE effect, not two.
23
+ * wasm-bindgen wraps GridEngine methods with a runtime borrow-check on `&mut self`.
24
+ * Two separate effects that both call engine methods can fire in the same
25
+ * synchronous React flush — the second effect starts before wasm-bindgen has
26
+ * released the `&mut` borrow from the first, triggering:
27
+ * "recursive use of an object detected which would lead to unsafe aliasing in rust"
23
28
  *
24
- * Uses a `dataVersion` ref to skip redundant pulls on re-renders where
25
- * nothing has actually changed in the engine.
29
+ * Keeping everything in a single effect guarantees all engine calls are sequential
30
+ * within one borrow, and the pull (get_page / get_subtotals) always sees the
31
+ * data that was just loaded.
26
32
  */
27
- export declare function useEngineSync({ engine, ready, rows, columns, onSynced, page, pageSize, onPageData, sortStack, filterGroup, quickFilterText, }: UseEngineSyncProps): void;
33
+ export declare function useEngineSync({ engine, ready, rows, columns, onSynced, page, pageSize, onPageData, sortStack, filterGroup, quickFilterText, groupBy, onGroups, }: UseEngineSyncProps): void;
28
34
  export {};