m9-react-data-grid 7.0.0-beta.7.11

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/lib/index.d.ts ADDED
@@ -0,0 +1,336 @@
1
+ import { JSX as JSX_2 } from 'react';
2
+ import type { Key } from 'react';
3
+ import type { ReactElement } from 'react';
4
+ import type { RefAttributes } from 'react';
5
+
6
+ export declare interface CalculatedColumn<TRow, TSummaryRow = unknown> extends Column<TRow, TSummaryRow> {
7
+ readonly idx: number;
8
+ readonly resizable: boolean;
9
+ readonly sortable: boolean;
10
+ readonly frozen: boolean;
11
+ readonly isLastFrozenColumn: boolean;
12
+ readonly rowGroup: boolean;
13
+ readonly formatter: React.ComponentType<FormatterProps<TRow, TSummaryRow>>;
14
+ }
15
+
16
+ export declare type CellNavigationMode = 'NONE' | 'CHANGE_ROW' | 'LOOP_OVER_ROW';
17
+
18
+ export declare interface CellRendererProps<TRow, TSummaryRow> extends Pick<RowRendererProps<TRow, TSummaryRow>, 'onRowClick' | 'onRowDoubleClick' | 'selectCell'>, Omit_2<React.HTMLAttributes<HTMLDivElement>, 'style' | 'children'> {
19
+ column: CalculatedColumn<TRow, TSummaryRow>;
20
+ colSpan: number | undefined;
21
+ row: TRow;
22
+ rowIdx: number;
23
+ isCopied: boolean;
24
+ isDraggedOver: boolean;
25
+ isCellSelected: boolean;
26
+ dragHandle: ReactElement<React.HTMLAttributes<HTMLDivElement>> | undefined;
27
+ onRowChange: (newRow: TRow) => void;
28
+ }
29
+
30
+ export declare type ColSpanArgs<R, SR> = {
31
+ type: 'HEADER';
32
+ } | {
33
+ type: 'ROW';
34
+ row: R;
35
+ } | {
36
+ type: 'SUMMARY';
37
+ row: SR;
38
+ };
39
+
40
+ export declare interface Column<TRow, TSummaryRow = unknown> {
41
+ /** The name of the column. By default it will be displayed in the header cell */
42
+ readonly name: string | ReactElement;
43
+ /** A unique key to distinguish each column */
44
+ readonly key: string;
45
+ /** Column width. If not specified, it will be determined automatically based on grid width and specified widths of other columns */
46
+ readonly width?: Maybe<number | string>;
47
+ /** Minimum column width in px. */
48
+ readonly minWidth?: Maybe<number>;
49
+ /** Maximum column width in px. */
50
+ readonly maxWidth?: Maybe<number>;
51
+ readonly cellClass?: Maybe<string | ((row: TRow) => Maybe<string>)>;
52
+ readonly headerCellClass?: Maybe<string>;
53
+ readonly summaryCellClass?: Maybe<string | ((row: TSummaryRow) => Maybe<string>)>;
54
+ /** Formatter to be used to render the cell content */
55
+ readonly formatter?: Maybe<React.ComponentType<FormatterProps<TRow, TSummaryRow>>>;
56
+ /** Formatter to be used to render the summary cell content */
57
+ readonly summaryFormatter?: Maybe<React.ComponentType<SummaryFormatterProps<TSummaryRow, TRow>>>;
58
+ /** Formatter to be used to render the group cell content */
59
+ readonly groupFormatter?: Maybe<React.ComponentType<GroupFormatterProps<TRow, TSummaryRow>>>;
60
+ /** Enables cell editing. If set and no editor property specified, then a textinput will be used as the cell editor */
61
+ readonly editable?: Maybe<boolean | ((row: TRow) => boolean)>;
62
+ readonly colSpan?: Maybe<(args: ColSpanArgs<TRow, TSummaryRow>) => Maybe<number>>;
63
+ /** Determines whether column is frozen or not */
64
+ readonly frozen?: Maybe<boolean>;
65
+ /** Enable resizing of a column */
66
+ readonly resizable?: Maybe<boolean>;
67
+ /** Enable sorting of a column */
68
+ readonly sortable?: Maybe<boolean>;
69
+ /** Sets the column sort order to be descending instead of ascending the first time the column is sorted */
70
+ readonly sortDescendingFirst?: Maybe<boolean>;
71
+ /** Editor to be rendered when cell of column is being edited. If set, then the column is automatically set to be editable */
72
+ readonly editor?: Maybe<React.ComponentType<EditorProps<TRow, TSummaryRow>>>;
73
+ readonly editorOptions?: Maybe<{
74
+ /** @default false */
75
+ readonly renderFormatter?: Maybe<boolean>;
76
+ /** @default false */
77
+ readonly editOnClick?: Maybe<boolean>;
78
+ /** @default true */
79
+ readonly commitOnOutsideClick?: Maybe<boolean>;
80
+ /** Prevent default to cancel editing */
81
+ readonly onCellKeyDown?: Maybe<(event: React.KeyboardEvent<HTMLDivElement>) => void>;
82
+ /** Control the default cell navigation behavior while the editor is open */
83
+ readonly onNavigation?: Maybe<(event: React.KeyboardEvent<HTMLDivElement>) => boolean>;
84
+ }>;
85
+ /** Header renderer for each header cell */
86
+ readonly headerRenderer?: Maybe<React.ComponentType<HeaderRendererProps<TRow, TSummaryRow>>>;
87
+ }
88
+
89
+ export declare interface DataGridHandle {
90
+ element: HTMLDivElement | null;
91
+ scrollToColumn: (colIdx: number) => void;
92
+ scrollToRow: (rowIdx: number) => void;
93
+ selectCell: (position: Position, enableEditor?: Maybe<boolean>) => void;
94
+ }
95
+
96
+ export declare interface DataGridProps<R, SR = unknown, K extends Key = Key> extends SharedDivProps {
97
+ /**
98
+ * Grid and data Props
99
+ */
100
+ /** An array of objects representing each column on the grid */
101
+ columns: readonly Column<R, SR>[];
102
+ /** A function called for each rendered row that should return a plain key/value pair object */
103
+ rows: readonly R[];
104
+ /**
105
+ * Rows to be pinned at the bottom of the rows view for summary, the vertical scroll bar will not scroll these rows.
106
+ * Bottom horizontal scroll bar can move the row left / right. Or a customized row renderer can be used to disabled the scrolling support.
107
+ */
108
+ summaryRows?: Maybe<readonly SR[]>;
109
+ /** The getter should return a unique key for each row */
110
+ rowKeyGetter?: Maybe<(row: R) => K>;
111
+ onRowsChange?: Maybe<(rows: R[], data: RowsChangeData<R, SR>) => void>;
112
+ /**
113
+ * Dimensions props
114
+ */
115
+ /**
116
+ * The height of each row in pixels
117
+ * @default 35
118
+ */
119
+ rowHeight?: Maybe<number | ((args: RowHeightArgs<R>) => number)>;
120
+ /**
121
+ * The height of the header row in pixels
122
+ * @default 35
123
+ */
124
+ headerRowHeight?: Maybe<number>;
125
+ /**
126
+ * The height of each summary row in pixels
127
+ * @default 35
128
+ */
129
+ summaryRowHeight?: Maybe<number>;
130
+ /**
131
+ * Feature props
132
+ */
133
+ /** Set of selected row keys */
134
+ selectedRows?: Maybe<ReadonlySet<K>>;
135
+ /** Function called whenever row selection is changed */
136
+ onSelectedRowsChange?: Maybe<(selectedRows: Set<K>) => void>;
137
+ /** Used for multi column sorting */
138
+ sortColumns?: Maybe<readonly SortColumn[]>;
139
+ onSortColumnsChange?: Maybe<(sortColumns: SortColumn[]) => void>;
140
+ defaultColumnOptions?: Maybe<DefaultColumnOptions<R, SR>>;
141
+ groupBy?: Maybe<readonly string[]>;
142
+ rowGrouper?: Maybe<(rows: readonly R[], columnKey: string) => Record<string, readonly R[]>>;
143
+ expandedGroupIds?: Maybe<ReadonlySet<unknown>>;
144
+ onExpandedGroupIdsChange?: Maybe<(expandedGroupIds: Set<unknown>) => void>;
145
+ onFill?: Maybe<(event: FillEvent<R>) => R>;
146
+ onPaste?: Maybe<(event: PasteEvent<R>) => R>;
147
+ /**
148
+ * Event props
149
+ */
150
+ /** Function called whenever a row is clicked */
151
+ onRowClick?: Maybe<(row: R, column: CalculatedColumn<R, SR>) => void>;
152
+ /** Function called whenever a row is double clicked */
153
+ onRowDoubleClick?: Maybe<(row: R, column: CalculatedColumn<R, SR>) => void>;
154
+ /** Called when the grid is scrolled */
155
+ onScroll?: Maybe<(event: React.UIEvent<HTMLDivElement>) => void>;
156
+ /** Called when a column is resized */
157
+ onColumnResize?: Maybe<(idx: number, width: number) => void>;
158
+ /**
159
+ * Toggles and modes
160
+ */
161
+ /** @default 'NONE' */
162
+ cellNavigationMode?: Maybe<CellNavigationMode>;
163
+ /** @default true */
164
+ enableVirtualization?: Maybe<boolean>;
165
+ /**
166
+ * Miscellaneous
167
+ */
168
+ rowRenderer?: Maybe<React.ComponentType<RowRendererProps<R, SR>>>;
169
+ noRowsFallback?: React.ReactNode;
170
+ rowClass?: Maybe<(row: R) => Maybe<string>>;
171
+ 'data-testid'?: Maybe<string>;
172
+ editableRowIdxs?: Array<number>;
173
+ }
174
+
175
+ declare const _default: <R, SR = unknown, K extends Key = Key>(props: DataGridProps<R, SR, K> & RefAttributes<DataGridHandle>) => JSX.Element;
176
+ export default _default;
177
+
178
+ declare type DefaultColumnOptions<R, SR> = Pick<Column<R, SR>, 'formatter' | 'minWidth' | 'resizable' | 'sortable'>;
179
+
180
+ export declare interface EditorProps<TRow, TSummaryRow = unknown> {
181
+ column: CalculatedColumn<TRow, TSummaryRow>;
182
+ row: TRow;
183
+ onRowChange: (row: TRow, commitChanges?: boolean) => void;
184
+ onClose: (commitChanges?: boolean) => void;
185
+ }
186
+
187
+ export declare interface FillEvent<TRow> {
188
+ columnKey: string;
189
+ sourceRow: TRow;
190
+ targetRow: TRow;
191
+ }
192
+
193
+ export declare interface FormatterProps<TRow, TSummaryRow = unknown> {
194
+ column: CalculatedColumn<TRow, TSummaryRow>;
195
+ row: TRow;
196
+ rowIdx: number;
197
+ isCellSelected: boolean;
198
+ onRowChange: (row: TRow) => void;
199
+ }
200
+
201
+ export declare interface GroupFormatterProps<TRow, TSummaryRow = unknown> {
202
+ groupKey: unknown;
203
+ column: CalculatedColumn<TRow, TSummaryRow>;
204
+ row: GroupRow<TRow>;
205
+ childRows: readonly TRow[];
206
+ isExpanded: boolean;
207
+ isCellSelected: boolean;
208
+ toggleGroup: () => void;
209
+ }
210
+
211
+ declare interface GroupRow<TRow> {
212
+ readonly childRows: readonly TRow[];
213
+ readonly id: string;
214
+ readonly parentId: unknown;
215
+ readonly groupKey: unknown;
216
+ readonly isExpanded: boolean;
217
+ readonly level: number;
218
+ readonly posInSet: number;
219
+ readonly setSize: number;
220
+ readonly startRowIndex: number;
221
+ }
222
+
223
+ export declare interface HeaderRendererProps<TRow, TSummaryRow = unknown> {
224
+ column: CalculatedColumn<TRow, TSummaryRow>;
225
+ sortDirection: SortDirection | undefined;
226
+ priority: number | undefined;
227
+ onSort: (ctrlClick: boolean) => void;
228
+ allRowsSelected: boolean;
229
+ onAllRowsSelectionChange: (checked: boolean) => void;
230
+ isCellSelected: boolean;
231
+ }
232
+
233
+ declare type Maybe<T> = T | undefined | null;
234
+
235
+ declare type Omit_2<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
236
+
237
+ export declare interface PasteEvent<TRow> {
238
+ sourceColumnKey: string;
239
+ sourceRow: TRow;
240
+ targetColumnKey: string;
241
+ targetRow: TRow;
242
+ }
243
+
244
+ declare interface Position {
245
+ readonly idx: number;
246
+ readonly rowIdx: number;
247
+ }
248
+
249
+ declare interface Props<R, SR> extends SharedHeaderCellProps<R, SR> {
250
+ children: React.ReactNode;
251
+ }
252
+
253
+ export declare const Row: <R, SR>(props: RowRendererProps<R, SR> & RefAttributes<HTMLDivElement>) => JSX.Element;
254
+
255
+ export declare type RowHeightArgs<R> = {
256
+ type: 'ROW';
257
+ row: R;
258
+ } | {
259
+ type: 'GROUP';
260
+ row: GroupRow<R>;
261
+ };
262
+
263
+ export declare interface RowRendererProps<TRow, TSummaryRow = unknown> extends Omit_2<React.HTMLAttributes<HTMLDivElement>, 'style' | 'children'> {
264
+ viewportColumns: readonly CalculatedColumn<TRow, TSummaryRow>[];
265
+ row: TRow;
266
+ rowIdx: number;
267
+ selectedCellIdx: number | undefined;
268
+ copiedCellIdx: number | undefined;
269
+ draggedOverCellIdx: number | undefined;
270
+ lastFrozenColumnIndex: number;
271
+ isRowSelected: boolean;
272
+ top: number;
273
+ height: number;
274
+ selectedCellEditor: ReactElement<EditorProps<TRow>> | undefined;
275
+ selectedCellDragHandle: ReactElement<React.HTMLAttributes<HTMLDivElement>> | undefined;
276
+ onRowChange: (rowIdx: number, newRow: TRow) => void;
277
+ onRowClick: Maybe<(row: TRow, column: CalculatedColumn<TRow, TSummaryRow>) => void>;
278
+ onRowDoubleClick: Maybe<(row: TRow, column: CalculatedColumn<TRow, TSummaryRow>) => void>;
279
+ rowClass: Maybe<(row: TRow) => Maybe<string>>;
280
+ setDraggedOverRowIdx: ((overRowIdx: number) => void) | undefined;
281
+ selectCell: (row: TRow, column: CalculatedColumn<TRow, TSummaryRow>, enableEditor?: Maybe<boolean>) => void;
282
+ }
283
+
284
+ export declare interface RowsChangeData<R, SR = unknown> {
285
+ indexes: number[];
286
+ column: CalculatedColumn<R, SR>;
287
+ }
288
+
289
+ export declare const SELECT_COLUMN_KEY = "select-row";
290
+
291
+ export declare function SelectCellFormatter({ value, isCellSelected, disabled, onClick, onChange, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }: SelectCellFormatterProps): JSX_2.Element;
292
+
293
+ declare interface SelectCellFormatterProps extends SharedInputProps {
294
+ isCellSelected: boolean;
295
+ value: boolean;
296
+ onChange: (value: boolean, isShiftClick: boolean) => void;
297
+ }
298
+
299
+ export declare const SelectColumn: Column<any, any>;
300
+
301
+ export declare interface SelectRowEvent<TRow> {
302
+ row: TRow;
303
+ checked: boolean;
304
+ isShiftClick: boolean;
305
+ }
306
+
307
+ declare type SharedDivProps = Pick<React.HTMLAttributes<HTMLDivElement>, 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'className' | 'style'>;
308
+
309
+ declare type SharedHeaderCellProps<R, SR> = Pick<HeaderRendererProps<R, SR>, 'sortDirection' | 'onSort' | 'priority' | 'isCellSelected'>;
310
+
311
+ declare type SharedInputProps = Pick<React.InputHTMLAttributes<HTMLInputElement>, 'disabled' | 'onClick' | 'aria-label' | 'aria-labelledby'>;
312
+
313
+ export declare function SortableHeaderCell<R, SR>({ onSort, sortDirection, priority, children, isCellSelected }: Props<R, SR>): JSX_2.Element;
314
+
315
+ export declare interface SortColumn {
316
+ readonly columnKey: string;
317
+ readonly direction: SortDirection;
318
+ }
319
+
320
+ export declare type SortDirection = 'ASC' | 'DESC';
321
+
322
+ export declare interface SummaryFormatterProps<TSummaryRow, TRow = unknown> {
323
+ column: CalculatedColumn<TRow, TSummaryRow>;
324
+ row: TSummaryRow;
325
+ isCellSelected: boolean;
326
+ }
327
+
328
+ export declare function TextEditor<TRow, TSummaryRow>({ row, column, onRowChange, onClose }: EditorProps<TRow, TSummaryRow>): JSX_2.Element;
329
+
330
+ export declare function ToggleGroupFormatter<R, SR>({ groupKey, isExpanded, isCellSelected, toggleGroup }: GroupFormatterProps<R, SR>): JSX_2.Element;
331
+
332
+ export declare function useRowSelection<R>(): [boolean, (selectRowEvent: SelectRowEvent<R>) => void];
333
+
334
+ export declare function ValueFormatter<R, SR>(props: FormatterProps<R, SR>): JSX_2.Element | null;
335
+
336
+ export { }
package/package.json ADDED
@@ -0,0 +1,117 @@
1
+ {
2
+ "name": "m9-react-data-grid",
3
+ "version": "7.0.0-beta.7.11",
4
+ "license": "MIT",
5
+ "description": "Feature-rich and customizable data grid React component",
6
+ "keywords": [
7
+ "react",
8
+ "data grid"
9
+ ],
10
+ "repository": "github:adazzle/react-data-grid",
11
+ "bugs": "https://github.com/adazzle/react-data-grid/issues",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "module": "./lib/bundle.js",
16
+ "require": "./lib/bundle.cjs",
17
+ "default": "./lib/bundle.js"
18
+ }
19
+ },
20
+ "browser": "./lib/bundle.js",
21
+ "main": "./lib/bundle.cjs",
22
+ "module": "./lib/bundle.js",
23
+ "types": "./lib/index.d.ts",
24
+ "files": [
25
+ "lib"
26
+ ],
27
+ "sideEffects": false,
28
+ "scripts": {
29
+ "start": "webpack serve --mode=development",
30
+ "build:website": "webpack --mode=production",
31
+ "build": "rollup --config --no-stdin",
32
+ "build:types": "tsc && api-extractor run --local --verbose",
33
+ "test": "jest",
34
+ "test:watch": "jest --watch",
35
+ "eslint": "eslint --ext js,ts,tsx --max-warnings 0 -f codeframe --cache --color src test website",
36
+ "eslint:fix": "npm run eslint -- --fix",
37
+ "prettier:check": "prettier --check .",
38
+ "prettier:format": "prettier --write .",
39
+ "typecheck": "tsc -p tsconfig.all.json",
40
+ "prepublishOnly": "npm install && npm run build && npm run build:types",
41
+ "postpublish": "git push --follow-tags origin HEAD"
42
+ },
43
+ "dependencies": {
44
+ "clsx": "^1.1.1"
45
+ },
46
+ "devDependencies": {
47
+ "@babel/core": "^7.14.6",
48
+ "@babel/plugin-transform-runtime": "^7.14.5",
49
+ "@babel/preset-env": "^7.14.7",
50
+ "@babel/preset-react": "^7.14.5",
51
+ "@babel/preset-typescript": "^7.14.5",
52
+ "@babel/runtime": "^7.14.6",
53
+ "@linaria/babel-preset": "^3.0.0-beta.12",
54
+ "@linaria/core": "^3.0.0-beta.4",
55
+ "@linaria/rollup": "^3.0.0-beta.12",
56
+ "@linaria/shaker": "^3.0.0-beta.12",
57
+ "@linaria/webpack5-loader": "^3.0.0-beta.12",
58
+ "@microsoft/api-extractor": "^7.16.1",
59
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.0",
60
+ "@rollup/plugin-babel": "^5.3.0",
61
+ "@rollup/plugin-node-resolve": "^13.0.0",
62
+ "@testing-library/jest-dom": "^5.14.1",
63
+ "@testing-library/react": "^12.0.0",
64
+ "@testing-library/user-event": "^13.1.9",
65
+ "@types/faker": "^5.5.6",
66
+ "@types/hoist-non-react-statics": "^3.3.1",
67
+ "@types/jest": "^27.0.1",
68
+ "@types/lodash": "^4.14.172",
69
+ "@types/react": "^17.0.11",
70
+ "@types/react-dom": "^17.0.8",
71
+ "@types/react-router-dom": "^5.1.8",
72
+ "@typescript-eslint/eslint-plugin": "^4.28.0",
73
+ "@typescript-eslint/parser": "^4.28.0",
74
+ "babel-loader": "^8.2.2",
75
+ "babel-plugin-optimize-clsx": "^2.6.2",
76
+ "css-loader": "^6.2.0",
77
+ "css-minimizer-webpack-plugin": "^3.0.2",
78
+ "eslint": "^7.29.0",
79
+ "eslint-config-prettier": "^8.3.0",
80
+ "eslint-plugin-jest": "^24.3.6",
81
+ "eslint-plugin-jest-dom": "^3.9.0",
82
+ "eslint-plugin-node": "^11.1.0",
83
+ "eslint-plugin-react": "^7.24.0",
84
+ "eslint-plugin-react-hooks": "^4.2.0",
85
+ "eslint-plugin-sonarjs": "^0.10.0",
86
+ "faker": "^5.5.3",
87
+ "html-webpack-plugin": "^5.3.2",
88
+ "jest": "^27.0.5",
89
+ "jspdf": "^2.3.1",
90
+ "jspdf-autotable": "^3.5.14",
91
+ "lodash-es": "^4.17.21",
92
+ "mini-css-extract-plugin": "^2.2.2",
93
+ "postcss": "^8.3.6",
94
+ "postcss-loader": "^6.1.1",
95
+ "postcss-nested": "^5.0.6",
96
+ "prettier": "2.4.0",
97
+ "react": "^17.0.2",
98
+ "react-contextmenu": "^2.14.0",
99
+ "react-dnd": "^14.0.2",
100
+ "react-dnd-html5-backend": "^14.0.0",
101
+ "react-dom": "^17.0.2",
102
+ "react-refresh": "^0.10.0",
103
+ "react-router-dom": "^5.3.0",
104
+ "rollup": "^2.52.3",
105
+ "rollup-plugin-postcss": "^4.0.0",
106
+ "style-loader": "^3.2.1",
107
+ "typescript": "~4.4.2",
108
+ "webpack": "^5.52.1",
109
+ "webpack-cli": "^4.8.0",
110
+ "webpack-dev-server": "^4.2.0",
111
+ "xlsx": "^0.17.0"
112
+ },
113
+ "peerDependencies": {
114
+ "react": "^16.14 || ^17.0",
115
+ "react-dom": "^16.14 || ^17.0"
116
+ }
117
+ }