gm-datagrid 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +351 -0
  3. package/dist/GMDatagrid.d.ts +10 -0
  4. package/dist/GMDatagridInner.d.ts +4 -0
  5. package/dist/GMGridContainer.d.ts +19 -0
  6. package/dist/assets/clipboard.worker-B1pvzQ3O.js +2 -0
  7. package/dist/cells/EditCell.d.ts +16 -0
  8. package/dist/cells/ImageCell.d.ts +10 -0
  9. package/dist/cells/LabelsCell.d.ts +9 -0
  10. package/dist/cells/ProgressCell.d.ts +10 -0
  11. package/dist/cells/StatusCell.d.ts +11 -0
  12. package/dist/cells/ViewCell.d.ts +17 -0
  13. package/dist/components/GMGridEmptyState.d.ts +12 -0
  14. package/dist/context/GridContext.d.ts +23 -0
  15. package/dist/core_engine-Cnhrb_In.js +360 -0
  16. package/dist/dataset/useGMDataSet.d.ts +34 -0
  17. package/dist/engine/useEngineSync.d.ts +19 -0
  18. package/dist/engine/useGridEngine.d.ts +15 -0
  19. package/dist/features/useClipboard.d.ts +12 -0
  20. package/dist/features/useColumnResize.d.ts +16 -0
  21. package/dist/features/useExport.d.ts +12 -0
  22. package/dist/features/useInlineEdit.d.ts +24 -0
  23. package/dist/features/useKeyboardNav.d.ts +23 -0
  24. package/dist/features/useSelection.d.ts +19 -0
  25. package/dist/features/useVirtualization.d.ts +20 -0
  26. package/dist/gm-datagrid.js +4391 -0
  27. package/dist/gm-datagrid.umd.cjs +32 -0
  28. package/dist/index.d.ts +6 -0
  29. package/dist/toolbar/GridToolbar.d.ts +20 -0
  30. package/dist/toolbar/MobileToolbar.d.ts +18 -0
  31. package/dist/toolbar/ToolbarButtons.d.ts +14 -0
  32. package/dist/types/index.d.ts +123 -0
  33. package/dist/wasm/core_engine.d.ts +146 -0
  34. package/dist/workers/clipboard.worker.d.ts +1 -0
  35. package/package.json +72 -0
@@ -0,0 +1,34 @@
1
+ import { ApiContext, ColumnDef, FilterGroup, Row, SortKey } from '../types';
2
+ interface UseGMDataSetProps {
3
+ columns: ColumnDef[];
4
+ sourceApi?: (params: Record<string, unknown>) => Promise<{
5
+ success: boolean;
6
+ data: Row[];
7
+ }>;
8
+ apiParameters?: Record<string, unknown>;
9
+ localData?: Row[];
10
+ apiContext?: ApiContext;
11
+ }
12
+ export interface DataSetState {
13
+ rows: Row[];
14
+ loading: boolean;
15
+ error: string | null;
16
+ ready: boolean;
17
+ columns: ColumnDef[];
18
+ handleRefresh: () => void;
19
+ setApiParameters: (params: Record<string, unknown>) => void;
20
+ /** Push a new sort stack to the Wasm engine ref held by GridContext. */
21
+ sortStack: SortKey[];
22
+ setSortStack: (stack: SortKey[]) => void;
23
+ filterGroup: FilterGroup | null;
24
+ setFilterGroup: (group: FilterGroup | null) => void;
25
+ quickFilterText: string;
26
+ setQuickFilterText: (text: string) => void;
27
+ }
28
+ /**
29
+ * Mirrors the legacy `useGMDataSet` hook API.
30
+ * Fetches data via `sourceApi` (or uses `localData`), merges `apiContext` into
31
+ * every call so `company_id` / auth tokens are never forgotten.
32
+ */
33
+ export declare function useGMDataSet(props: UseGMDataSetProps): DataSetState;
34
+ export {};
@@ -0,0 +1,19 @@
1
+ import { ColumnDef, Row } from '../types';
2
+ interface UseEngineSyncProps {
3
+ engine: any;
4
+ ready: boolean;
5
+ rows: Row[];
6
+ columns: ColumnDef[];
7
+ onSynced: (totalCount: number, subtotals: Record<string, number>) => void;
8
+ page: number;
9
+ pageSize: number;
10
+ onPageData: (rows: Row[]) => void;
11
+ }
12
+ /**
13
+ * Syncs React state → Wasm engine (push) and pulls page data + subtotals back.
14
+ *
15
+ * Uses a `dataVersion` ref to skip redundant pulls on re-renders where
16
+ * nothing has actually changed in the engine.
17
+ */
18
+ export declare function useEngineSync({ engine, ready, rows, columns, onSynced, page, pageSize, onPageData, }: UseEngineSyncProps): void;
19
+ export {};
@@ -0,0 +1,15 @@
1
+ type GridEngineInstance = any;
2
+ interface UseGridEngineResult {
3
+ engine: GridEngineInstance | null;
4
+ ready: boolean;
5
+ error: Error | null;
6
+ retry: () => void;
7
+ }
8
+ /**
9
+ * Loads the Rust/Wasm module once per mount.
10
+ * Exposes `engine` (GridEngine instance), `ready`, `error`, and `retry`.
11
+ *
12
+ * NEVER call engine methods before `ready === true`.
13
+ */
14
+ export declare function useGridEngine(): UseGridEngineResult;
15
+ export {};
@@ -0,0 +1,12 @@
1
+ import { CellRange, ColumnDef, Row } from '../types';
2
+ interface UseClipboardProps {
3
+ range: CellRange | null;
4
+ visibleRows: Row[];
5
+ columns: ColumnDef[];
6
+ engine: any;
7
+ engineReady: boolean;
8
+ onPasted: () => void;
9
+ }
10
+ /** Serializes selected range to TSV for Ctrl+C; parses TSV from Ctrl+V. */
11
+ export declare function useClipboard({ range, visibleRows, columns, engine, engineReady, onPasted, }: UseClipboardProps): void;
12
+ export {};
@@ -0,0 +1,16 @@
1
+ import { ColumnDef } from '../types';
2
+ interface UseColumnResizeProps {
3
+ columns: ColumnDef[];
4
+ gridTitle: string;
5
+ }
6
+ type WidthMap = Record<string, number>;
7
+ interface ColumnResizeState {
8
+ widths: WidthMap;
9
+ onResizeStart: (field: string, startX: number, startWidth: number) => void;
10
+ }
11
+ /**
12
+ * Interactive column resize with localStorage persistence.
13
+ * Widths are keyed by `gridTitle` to isolate different grid instances.
14
+ */
15
+ export declare function useColumnResize({ columns, gridTitle }: UseColumnResizeProps): ColumnResizeState;
16
+ export {};
@@ -0,0 +1,12 @@
1
+ import { GridEngine } from '../wasm/core_engine';
2
+ interface UseExportProps {
3
+ engineRef: React.RefObject<GridEngine | null>;
4
+ title: string;
5
+ }
6
+ /**
7
+ * Triggers a Wasm-side Excel export and downloads the result as a .xlsx file.
8
+ */
9
+ export declare function useExport({ engineRef, title }: UseExportProps): {
10
+ handleExport: () => void;
11
+ };
12
+ export {};
@@ -0,0 +1,24 @@
1
+ import { CellCoord, ColumnDef, Row } from '../types';
2
+ interface UseInlineEditProps {
3
+ visibleRows: Row[];
4
+ columns: ColumnDef[];
5
+ engine: any;
6
+ engineReady: boolean;
7
+ processRowUpdate?: (newRow: Row, oldRow: Row) => Row | Promise<Row>;
8
+ onCellError: (rowId: string, message: string) => void;
9
+ }
10
+ interface InlineEditState {
11
+ editingCell: CellCoord | null;
12
+ editValue: string;
13
+ startEditing: (cell: CellCoord, initialChar?: string) => void;
14
+ stopEditing: (save: boolean) => Promise<void>;
15
+ setEditValue: (v: string) => void;
16
+ cellErrors: Record<string, string>;
17
+ }
18
+ /**
19
+ * Manages Excel-like inline cell editing.
20
+ * On save: calls processRowUpdate (async), reverts on rejection.
21
+ * On escape: discards changes.
22
+ */
23
+ export declare function useInlineEdit({ visibleRows, columns, engine, engineReady, processRowUpdate, onCellError, }: UseInlineEditProps): InlineEditState;
24
+ export {};
@@ -0,0 +1,23 @@
1
+ import { CellCoord, ColumnDef } from '../types';
2
+ interface UseKeyboardNavProps {
3
+ focusedCell: CellCoord | null;
4
+ setFocusedCell: (cell: CellCoord | null) => void;
5
+ editingCell: CellCoord | null;
6
+ startEditing: (cell: CellCoord, initialChar?: string) => void;
7
+ stopEditing: (save: boolean) => Promise<void>;
8
+ totalRows: number;
9
+ columns: ColumnDef[];
10
+ containerRef: React.RefObject<HTMLDivElement>;
11
+ }
12
+ /**
13
+ * Keyboard navigation contract (Excel-like):
14
+ * - Arrow keys (view mode): move focused cell
15
+ * - Any printable char: enter edit mode, replace value with typed char
16
+ * - F2: enter edit mode, keep existing value
17
+ * - Enter: save, move focus one row down
18
+ * - Tab: save, move focus one column right
19
+ * - Shift+Tab: save, move focus one column left
20
+ * - Escape: discard, exit edit mode
21
+ */
22
+ export declare function useKeyboardNav({ focusedCell, setFocusedCell, editingCell, startEditing, stopEditing, totalRows, columns, }: UseKeyboardNavProps): void;
23
+ export {};
@@ -0,0 +1,19 @@
1
+ import { CellCoord, CellRange, ColumnDef, Row } from '../types';
2
+ interface UseSelectionProps {
3
+ visibleRows: Row[];
4
+ columns: ColumnDef[];
5
+ }
6
+ interface SelectionState {
7
+ range: CellRange | null;
8
+ focusedCell: CellCoord | null;
9
+ isSelecting: boolean;
10
+ handleMouseDown: (rowIndex: number, colIndex: number) => void;
11
+ handleMouseEnter: (rowIndex: number, colIndex: number) => void;
12
+ handleMouseUp: () => void;
13
+ setFocusedCell: (cell: CellCoord | null) => void;
14
+ clearSelection: () => void;
15
+ isCellSelected: (rowIndex: number, colIndex: number) => boolean;
16
+ }
17
+ /** Manages click-drag cell range selection (Excel-style). */
18
+ export declare function useSelection({ visibleRows: _rows, columns: _cols }: UseSelectionProps): SelectionState;
19
+ export {};
@@ -0,0 +1,20 @@
1
+ import { Row, GridDensity } from '../types';
2
+ interface UseVirtualizationProps {
3
+ rows: Row[];
4
+ containerRef: React.RefObject<HTMLDivElement>;
5
+ density: GridDensity;
6
+ overscan?: number;
7
+ }
8
+ interface VirtualizationState {
9
+ visibleStart: number;
10
+ visibleEnd: number;
11
+ offsetTop: number;
12
+ totalHeight: number;
13
+ }
14
+ /**
15
+ * Computes which rows are visible in the viewport.
16
+ * Uses a single rAF loop — never onScroll with synchronous setState.
17
+ * Always cancels the loop on unmount to prevent memory leaks.
18
+ */
19
+ export declare function useVirtualization({ rows, containerRef, density, overscan, }: UseVirtualizationProps): VirtualizationState;
20
+ export {};