es-grid-template 0.1.0 → 0.1.2-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.
Files changed (63) hide show
  1. package/es/grid-component/ColumnsChoose.d.ts +3 -4
  2. package/es/grid-component/ColumnsChoose.js +28 -15
  3. package/es/grid-component/Command.d.ts +8 -0
  4. package/es/grid-component/Command.js +81 -0
  5. package/es/grid-component/ContextMenu.d.ts +2 -2
  6. package/es/grid-component/ContextMenu.js +1 -0
  7. package/es/grid-component/EditableCell.js +300 -314
  8. package/es/grid-component/GridStyle.js +1 -1
  9. package/es/grid-component/InternalTable.js +52 -28
  10. package/es/grid-component/TableGrid.d.ts +2 -1
  11. package/es/grid-component/TableGrid.js +64 -18
  12. package/es/grid-component/async-select/index.d.ts +9 -0
  13. package/es/grid-component/async-select/index.js +35 -0
  14. package/es/grid-component/hooks/constant.d.ts +10 -0
  15. package/es/grid-component/hooks/constant.js +11 -1
  16. package/es/grid-component/hooks/useColumns/index.js +7 -4
  17. package/es/grid-component/hooks/utils.d.ts +2 -0
  18. package/es/grid-component/hooks/utils.js +11 -0
  19. package/es/grid-component/index.d.ts +3 -0
  20. package/es/grid-component/styles.scss +282 -214
  21. package/es/grid-component/table/Grid.js +46 -59
  22. package/es/grid-component/table/GridEdit.d.ts +4 -0
  23. package/es/grid-component/table/GridEdit.js +106 -19
  24. package/es/grid-component/type.d.ts +32 -14
  25. package/es/grid-component/useContext.d.ts +11 -7
  26. package/es/grid-component/useContext.js +3 -0
  27. package/es/index.d.ts +1 -0
  28. package/lib/grid-component/ColumnsChoose.d.ts +3 -4
  29. package/lib/grid-component/ColumnsChoose.js +27 -14
  30. package/lib/grid-component/Command.d.ts +8 -0
  31. package/lib/grid-component/Command.js +90 -0
  32. package/lib/grid-component/ContextMenu.d.ts +2 -2
  33. package/lib/grid-component/ContextMenu.js +2 -0
  34. package/lib/grid-component/EditableCell.js +297 -311
  35. package/lib/grid-component/GridStyle.js +1 -1
  36. package/lib/grid-component/InternalTable.js +51 -27
  37. package/lib/grid-component/TableGrid.d.ts +2 -1
  38. package/lib/grid-component/TableGrid.js +63 -17
  39. package/lib/grid-component/async-select/index.d.ts +9 -0
  40. package/lib/grid-component/async-select/index.js +44 -0
  41. package/lib/grid-component/hooks/constant.d.ts +10 -0
  42. package/lib/grid-component/hooks/constant.js +12 -2
  43. package/lib/grid-component/hooks/useColumns/index.js +7 -4
  44. package/lib/grid-component/hooks/utils.d.ts +2 -0
  45. package/lib/grid-component/hooks/utils.js +16 -3
  46. package/lib/grid-component/index.d.ts +3 -0
  47. package/lib/grid-component/styles.scss +282 -214
  48. package/lib/grid-component/table/Grid.js +46 -59
  49. package/lib/grid-component/table/GridEdit.d.ts +4 -0
  50. package/lib/grid-component/table/GridEdit.js +106 -19
  51. package/lib/grid-component/type.d.ts +32 -14
  52. package/lib/grid-component/useContext.d.ts +11 -7
  53. package/lib/grid-component/useContext.js +2 -0
  54. package/lib/index.d.ts +1 -0
  55. package/package.json +102 -112
  56. /package/es/{grid-component/Message → Message}/Message.d.ts +0 -0
  57. /package/es/{grid-component/Message → Message}/Message.js +0 -0
  58. /package/es/{grid-component/Message → Message}/index.d.ts +0 -0
  59. /package/es/{grid-component/Message → Message}/index.js +0 -0
  60. /package/lib/{grid-component/Message → Message}/Message.d.ts +0 -0
  61. /package/lib/{grid-component/Message → Message}/Message.js +0 -0
  62. /package/lib/{grid-component/Message → Message}/index.d.ts +0 -0
  63. /package/lib/{grid-component/Message → Message}/index.js +0 -0
@@ -2,7 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import React, { Fragment, useMemo } from 'react';
3
3
  import { GridStyle } from "../GridStyle";
4
4
  import TableGrid from "../TableGrid";
5
- import EditableCell from "../EditableCell";
5
+ import Command from "../Command";
6
+ import { renderContent } from "../hooks/useColumns";
6
7
  const Grid = props => {
7
8
  const {
8
9
  columns,
@@ -10,74 +11,61 @@ const Grid = props => {
10
11
  tableRef,
11
12
  className,
12
13
  components,
14
+ style,
15
+ format,
13
16
  ...rest
14
17
  } = props;
15
-
16
- // const transformColumns = React.useCallback((cols: ColumnsTable<RecordType>): ColumnsTable<RecordType> => {
17
- // return cols.map((column) => {
18
- //
19
- // if (column?.children && column?.children.length > 0) {
20
- // return {
21
- // ...column,
22
- // children: transformColumns(column?.children) // Xử lý đệ quy cho cấp con
23
- // }
24
- // }
25
- //
26
- // if (column.dataIndex === 'index' || column.field === 'index' || column.dataIndex === '#' || column.dataIndex === '#') {
27
- // return {
28
- // ...column,
29
- // render: (value: any, record: any, rowIndex: number) => {
30
- // return rowIndex + 1
31
- // }
32
- // }
33
- // }
34
- //
35
- // return {
36
- // ...column,
37
- // }
38
- // })
39
- // }, [])
40
- //
41
- //
42
- // const mergedColumns = useMemo(() => {
43
- //
44
- // // @ts-ignore
45
- // return transformColumns(columns ?? [])
46
- //
47
- // }, [transformColumns, columns])
48
-
49
- const addFilter = React.useCallback(cols => {
18
+ const transformColumns = React.useCallback(cols => {
19
+ // @ts-ignore
50
20
  return cols.map(column => {
51
- // @ts-ignore
52
- if (!column?.dataIndex && !column?.key) {
21
+ if (!column?.field && !column?.key) {
53
22
  return column;
54
23
  }
55
- // @ts-ignore
56
- if (column?.children && column?.children.length > 0) {
24
+
25
+ // Xử đệ quy cho children
26
+ if (column.children?.length) {
57
27
  return {
58
28
  ...column,
59
- // @ts-ignore
60
- children: addFilter(column?.children) // Xử lý đệ quy cho cấp con
29
+ children: transformColumns(column.children)
61
30
  };
62
31
  }
32
+ const transformedColumn = {
33
+ ...column,
34
+ dataIndex: column.field ?? column.dataIndex,
35
+ title: column.headerText ?? column.title,
36
+ ellipsis: column.ellipsis !== false,
37
+ align: column.textAlign ?? column.align,
38
+ fixed: column.frozen ? column.frozen.toLowerCase() : column.fixed
39
+ };
63
40
  // @ts-ignore
64
- if (column.dataIndex === 'index' || column.field === 'index' || column.dataIndex === '#' || column.dataIndex === '#') {
41
+ if (["index", "#"].includes(transformedColumn.dataIndex)) {
65
42
  return {
66
- ...column,
67
- render: (value, record, rowIndex) => {
68
- return rowIndex + 1;
69
- }
43
+ ...transformedColumn,
44
+ render: (_, __, rowIndex) => rowIndex + 1
45
+ };
46
+ }
47
+ if (transformedColumn.dataIndex === "command") {
48
+ return {
49
+ ...transformedColumn,
50
+ onCell: () => ({
51
+ className: "ui-rc-cell-command"
52
+ }),
53
+ render: () => /*#__PURE__*/React.createElement("div", {
54
+ className: "ui-rc-cell-command__content"
55
+ }, column.commandItems?.map((item, index) => item.visible !== false ? /*#__PURE__*/React.createElement(Command, {
56
+ key: `command-${index}`,
57
+ item: item,
58
+ onClick: e => e.preventDefault()
59
+ }) : null))
70
60
  };
71
61
  }
72
62
  return {
73
- ...column
63
+ ...transformedColumn,
64
+ render: (value, record, rowIndex) => renderContent(column, value, record, rowIndex, format)
74
65
  };
75
66
  });
76
67
  }, []);
77
- const tmpColumns = useMemo(() => {
78
- // @ts-ignore
79
- return addFilter(columns ?? []);
80
- }, [addFilter, columns]);
68
+ const mergedColumns = useMemo(() => transformColumns(columns ?? []), [transformColumns, columns]);
81
69
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
82
70
  heightTable: height,
83
71
  style: {
@@ -86,14 +74,13 @@ const Grid = props => {
86
74
  }, /*#__PURE__*/React.createElement(TableGrid, _extends({}, rest, {
87
75
  tableRef: tableRef,
88
76
  components: {
89
- ...components,
90
- body: {
91
- cell: EditableCell
92
- }
77
+ ...components
78
+ },
79
+ columns: mergedColumns,
80
+ style: {
81
+ ...style,
82
+ minHeight: height
93
83
  }
94
- // columns={mergedColumns}
95
- ,
96
- columns: tmpColumns
97
84
  }))));
98
85
  };
99
86
  export default Grid;
@@ -2,8 +2,12 @@ import React from 'react';
2
2
  import 'dayjs/locale/es';
3
3
  import 'dayjs/locale/vi';
4
4
  import type { TableEditProps } from "../type";
5
+ import type { GetRowKey } from "../type";
5
6
  type Props<RecordType> = TableEditProps<RecordType> & {
6
7
  tableRef: any;
8
+ triggerChangeColumns?: () => void;
9
+ triggerChangeData?: (newData: RecordType[], type: string) => void;
10
+ getRowKey: GetRowKey<RecordType>;
7
11
  };
8
12
  declare const GridEdit: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
9
13
  export default GridEdit;
@@ -14,7 +14,8 @@ import 'dayjs/locale/es';
14
14
  import 'dayjs/locale/vi';
15
15
  import TableGrid from "../TableGrid";
16
16
  import { getEditType, isObjEmpty, totalFixedWidth } from "../hooks";
17
- import Message from "./../Message/Message";
17
+ import Message from "../../Message/Message";
18
+ import Command from "../Command";
18
19
  dayjs.extend(customParseFormat);
19
20
  const toast = 'top-right';
20
21
  const GridEdit = props => {
@@ -23,17 +24,23 @@ const GridEdit = props => {
23
24
  t,
24
25
  columns,
25
26
  dataSource,
27
+ components,
26
28
  allowResizing,
27
29
  rowKey = 'id',
28
30
  selectionSettings,
29
31
  height,
30
32
  format,
31
- onDataChange,
33
+ // onDataChange,
34
+ triggerChangeData,
32
35
  onCellPaste,
33
36
  onCellChange,
34
- components,
37
+ style,
38
+ getRowKey,
35
39
  ...rest
36
40
  } = props;
41
+
42
+ // const forceUpdate = useForceUpdate();
43
+ const [updateKey, setUpdateKey] = useState(0);
37
44
  const isSelecting = useRef(false);
38
45
  const startCell = useRef(null);
39
46
  const isSelectingRow = useRef(false);
@@ -116,6 +123,30 @@ const GridEdit = props => {
116
123
  }
117
124
  setSelectedCells(newSelectedCells);
118
125
  };
126
+ const handleClickRowHeader = (row, col) => {
127
+ const newSelectedCells = new Set();
128
+ for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
129
+ for (let c = Math.min(columns.length, col) + 1; c <= Math.max(columns.length, col); c++) {
130
+ newSelectedCells.add(`${r}-${c}`);
131
+ }
132
+ }
133
+ setSelectedCells(newSelectedCells);
134
+ };
135
+ const handleClickColHeader = (column, indexColumn) => {
136
+ const newSelectedCells = new Set();
137
+ for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
138
+ for (let c = Math.min(indexColumn, indexColumn); c <= Math.max(indexColumn, indexColumn); c++) {
139
+ newSelectedCells.add(`${r}-${c}`);
140
+ }
141
+ }
142
+
143
+ // console.log('newSelectedCells', newSelectedCells)
144
+ // setSelectedCells(newSelectedCells)
145
+
146
+ setSelectedCells(new Set(newSelectedCells));
147
+ // forceUpdate();
148
+ setUpdateKey(prev => prev + 1); // Cập nhật key để trigger re-render
149
+ };
119
150
  const handleMouseDownColIndex = (row, col, e) => {
120
151
  if (e.button === 2) {
121
152
  e.stopPropagation();
@@ -318,6 +349,7 @@ const GridEdit = props => {
318
349
  ...item,
319
350
  ...row
320
351
  });
352
+ triggerChangeData?.(newData, 'onChange');
321
353
 
322
354
  // trigger DataChange
323
355
  // setData(newData);
@@ -338,14 +370,16 @@ const GridEdit = props => {
338
370
  record,
339
371
  type,
340
372
  newState,
341
- prevState
373
+ prevState,
374
+ option,
375
+ field
342
376
  } = args;
343
377
 
344
378
  // console.log('newState', newState)
345
379
  //
346
380
  // console.log('getValues()', getValues())
347
381
 
348
- // const record = getValues()
382
+ // const newRecord = getValues()
349
383
 
350
384
  if (type === 'enter') {
351
385
  console.log('aaaaaa enter');
@@ -357,18 +391,21 @@ const GridEdit = props => {
357
391
  // const newDataUpdate = updateData(data, callbackData, rowKey as any)
358
392
 
359
393
  console.log('callbackData', callbackData);
360
- const newRecord = callbackData;
361
- onSubmit(newRecord);
394
+ const callbackRecord = callbackData;
395
+ Object.entries(callbackRecord).forEach(([name, value]) => {
396
+ setValue(name, value);
397
+ });
398
+ onSubmit(callbackRecord);
362
399
  };
363
400
  if (onCellChange) {
364
401
  if (onCellChange.length > 1) {
365
402
  console.log('onCellChange Callback');
366
403
  onCellChange({
367
- field: '',
404
+ field,
368
405
  indexCol: 1,
369
406
  type: 'onChange',
370
- rows: [],
371
407
  value: newState,
408
+ option,
372
409
  indexRow: 1,
373
410
  rowData: record,
374
411
  rowId: '',
@@ -378,10 +415,10 @@ const GridEdit = props => {
378
415
  } else {
379
416
  console.log('onCellChange');
380
417
  onCellChange({
381
- field: '',
418
+ field,
382
419
  indexCol: 1,
383
420
  type: 'onChange',
384
- rows: [],
421
+ option,
385
422
  value: newState,
386
423
  indexRow: 1,
387
424
  rowData: record,
@@ -546,6 +583,7 @@ const GridEdit = props => {
546
583
  if (col.dataIndex === 'index' || col.field === 'index' || col.dataIndex === '#' || col.dataIndex === '#') {
547
584
  return {
548
585
  ...col,
586
+ className: 'rc-ui-cell-editable',
549
587
  render: (value, record, rowIndex) => {
550
588
  return /*#__PURE__*/React.createElement("div", {
551
589
  className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {
@@ -553,13 +591,45 @@ const GridEdit = props => {
553
591
  focus: selectedCells && Array.from(selectedCells).some(item => item.startsWith(`${rowIndex}-`))
554
592
  }),
555
593
  onMouseDown: event => handleMouseDownColIndex(rowIndex, colIndex, event),
556
- onMouseEnter: event => handleMouseEnterColIndex(rowIndex, colIndex, event)
594
+ onMouseEnter: event => handleMouseEnterColIndex(rowIndex, colIndex, event),
595
+ onClick: () => handleClickRowHeader(rowIndex, colIndex)
557
596
  }, /*#__PURE__*/React.createElement("div", {
558
597
  className: 'ui-rc_content'
559
598
  }, rowIndex + 1));
560
599
  }
561
600
  };
562
601
  }
602
+ if (col.dataIndex === 'command' || col.field === 'command') {
603
+ return {
604
+ ...col,
605
+ title: col.headerText ?? col.title,
606
+ ellipsis: col.ellipsis !== false,
607
+ onCell: () => ({
608
+ className: 'ui-rc-cell-command'
609
+ }),
610
+ // render: (value: any, record: any, rowIndex: number) => {
611
+ render: () => {
612
+ return /*#__PURE__*/React.createElement("div", {
613
+ className: classNames('ui-rc-cell-command__content', {})
614
+ }, col.commandItems && col.commandItems?.map((item, indexComm) => {
615
+ if (item.visible !== false) {
616
+ // return (
617
+ // <span>{item.title}</span>
618
+ // )
619
+
620
+ return /*#__PURE__*/React.createElement(Command, {
621
+ key: `command-${indexComm}`,
622
+ item: item,
623
+ onClick: e => {
624
+ e.preventDefault();
625
+ // handleCommandClick({command: item, rowData: record, index: rowIndex})
626
+ }
627
+ });
628
+ }
629
+ }));
630
+ }
631
+ };
632
+ }
563
633
  return {
564
634
  ...col,
565
635
  onCell: (record, rowIndex) => ({
@@ -619,12 +689,20 @@ const GridEdit = props => {
619
689
  handleEdit(record, col, col.editType, event);
620
690
  }
621
691
  },
692
+ // onMouseDown: (event) => {
693
+ // handleMouseDown(rowIndex, colIndex, event)
694
+ // },
695
+ //
696
+ // onMouseEnter: () => {
697
+ // handleMouseEnter(rowIndex, colIndex)
698
+ // },
699
+
622
700
  onClick: () => {
623
701
  if (record[rowKey] !== editingKey && editingKey !== '') {
624
702
  setEditingKey('');
625
703
  }
626
704
  },
627
- className: isEditing(record) ? 'cell-editing' : 'cell-editable',
705
+ className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable',
628
706
  record,
629
707
  column: col,
630
708
  editType: getEditType(col, record),
@@ -632,23 +710,28 @@ const GridEdit = props => {
632
710
  title: col.title,
633
711
  'data-col-index': colIndex,
634
712
  'data-row-index': rowIndex,
635
- colIndex: colIndex,
713
+ // colIndex: colIndex,
636
714
  indexCol: colIndex,
637
715
  indexRow: rowIndex,
638
716
  editing: isEditing(record),
639
717
  tabIndex: (rowIndex ?? 0) * columns.length + colIndex
640
718
  }),
719
+ onHeaderCell: data => ({
720
+ ...col.onHeaderCell(),
721
+ onClick: () => {
722
+ handleClickColHeader(data, colIndex);
723
+ }
724
+ }),
641
725
  render: (value, record, rowIndex) => {
642
726
  return /*#__PURE__*/React.createElement("div", {
643
727
  className: classNames('ui-rc_cell-content', {
644
728
  selected: selectedCells.has(`${rowIndex}-${colIndex}`)
645
729
  }),
646
730
  onMouseDown: event => handleMouseDown(rowIndex, colIndex, event),
647
- onMouseEnter: () => handleMouseEnter(rowIndex, colIndex),
648
- onMouseLeave: () => {}
731
+ onMouseEnter: () => handleMouseEnter(rowIndex, colIndex)
649
732
  }, /*#__PURE__*/React.createElement("div", {
650
733
  className: 'ui-rc_content'
651
- }, renderContent(col, value, record, rowIndex)));
734
+ }, renderContent(col, value, record, rowIndex, format)));
652
735
  }
653
736
  };
654
737
  });
@@ -668,12 +751,14 @@ const GridEdit = props => {
668
751
  control,
669
752
  trigger,
670
753
  getValues,
671
- handleCellChange
754
+ handleCellChange,
755
+ getRowKey
672
756
  }
673
757
  }, /*#__PURE__*/React.createElement("form", {
674
758
  onSubmit: handleSubmit(onSubmit)
675
759
  }, /*#__PURE__*/React.createElement(TableGrid, _extends({}, rest, {
676
760
  t: t,
761
+ key: updateKey,
677
762
  tableRef: tableRef,
678
763
  dataSource: dataSource,
679
764
  components: {
@@ -694,8 +779,10 @@ const GridEdit = props => {
694
779
  checkboxOnly: true
695
780
  } : undefined,
696
781
  style: {
782
+ ...style,
697
783
  minHeight: height
698
- }
784
+ },
785
+ rowHoverable: false
699
786
  }))))), /*#__PURE__*/React.createElement(Toaster, {
700
787
  position: toast,
701
788
  toastOptions: {
@@ -6,10 +6,13 @@ import type { FilterOperator, TableRowSelection } from "rc-master-ui/es/table/in
6
6
  import type { ToolbarItem } from "rc-master-ui/es/toolbar";
7
7
  import type { ItemType } from "rc-master-ui/es/menu/interface";
8
8
  import type { FieldNames, FilterFunc } from "rc-select/es/Select";
9
+ import type { ColorPickerProps } from "antd";
9
10
  export type IColumnType = "number" | "time" | "date" | "week" | "month" | "file" | "quarter" | "year" | "datetime" | "string" | "boolean" | "checkbox" | "color" | null | undefined;
10
11
  export type AnyObject = Record<PropertyKey, any>;
11
12
  export type SelectMode = 'checkbox' | 'radio' | undefined;
12
13
  export type ITextAlign = 'center' | 'left' | 'right';
14
+ export type Frozen = 'left' | 'right' | 'Left' | 'Right';
15
+ export type ContextMenuItem = ItemType & {};
13
16
  export type ITemplateColumn = {
14
17
  value: any;
15
18
  column: any;
@@ -39,6 +42,7 @@ export type ColumnSelectTable = {
39
42
  };
40
43
  export type IEditSelectSettings = {
41
44
  fieldKey?: string;
45
+ options: any[];
42
46
  /** get value form other field **/
43
47
  fieldValue?: string;
44
48
  /** get label form other field **/
@@ -46,7 +50,6 @@ export type IEditSelectSettings = {
46
50
  inputKey?: string;
47
51
  filterKey?: string[];
48
52
  selectMode?: SelectMode;
49
- options: any[];
50
53
  getPasteValue?: (value: any) => Record<string, any> | null;
51
54
  validateOption?: (rowData: any, field: string) => any[];
52
55
  defaultOptions?: any[];
@@ -84,14 +87,18 @@ export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTempl
84
87
  format?: IFormat;
85
88
  allowFiltering?: boolean;
86
89
  operator?: FilterOperator;
90
+ hideOperator?: boolean;
87
91
  placeholder?: string;
88
92
  showInColumnChoose?: boolean;
89
93
  typeFilter?: TypeFilter;
90
94
  headerText?: string;
95
+ textAlign?: ITextAlign;
96
+ frozen?: Frozen;
91
97
  template?: ReactNode | ReactElement | ((value: any, record: RecordType, index: number) => ReactNode | ReactElement);
92
98
  showTooltip?: boolean;
93
99
  tooltipDescription?: ReactNode | ReactElement | ((value: any, record: RecordType, index: number) => ReactNode | ReactElement);
94
100
  headerTemplate?: React.ReactNode | React.ReactElement | ((column: ColumnType<RecordType>) => React.ReactNode | React.ReactElement);
101
+ commandItems?: CommandItem[];
95
102
  children?: ColumnType<RecordType>[];
96
103
  };
97
104
  export type ColumnEditType<RecordType> = ColumnType<RecordType> & {
@@ -119,7 +126,7 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
119
126
  format?: IFormat;
120
127
  t?: any;
121
128
  lang?: string;
122
- contextMenuItems?: any[];
129
+ contextMenuItems?: ContextMenuItem[];
123
130
  contextMenuHidden?: string[] | ((args?: Omit<ContextInfo<RecordType>, 'item' | 'event'>) => string[]);
124
131
  contextMenuOpen?: (args: Omit<ContextInfo<RecordType>, 'item'>) => void;
125
132
  contextMenuClick?: (args: ContextInfo<RecordType>) => void;
@@ -140,7 +147,7 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
140
147
  direction: 'Ascending' | 'Descending' | null;
141
148
  }) => void;
142
149
  selectionSettings?: SelectionSettings;
143
- rowKey?: string;
150
+ rowKey?: string | keyof RecordType | GetRowKey<RecordType>;
144
151
  rowSelection?: RowSelection<RecordType>;
145
152
  rowSelected?: (args: {
146
153
  type: string;
@@ -148,7 +155,7 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
148
155
  selected: RecordType | RecordType[];
149
156
  }) => void;
150
157
  dataSourceFilter?: SourceFilter[];
151
- onFilterClick?: (column: ColumnType<RecordType>, callback: (key: string, data: any) => void) => void;
158
+ onFilterClick?: (column: ColumnTable<RecordType>, callback: (key: string, data: any) => void) => void;
152
159
  loading?: boolean;
153
160
  allowResizing?: boolean;
154
161
  onDataChange?: (data: RecordType[]) => void;
@@ -156,18 +163,30 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
156
163
  export interface TableEditProps<RecordType = AnyObject> extends Omit<TableProps<RecordType>, 'columns'> {
157
164
  columns: ColumnsTable<RecordType>;
158
165
  onCellPaste?: ICellPasteModel<RecordType>;
159
- onCellChange?: (args: CellChangeArgs, handleCallback: (rowData: any, index: any, value?: any) => void) => void;
166
+ onCellChange?: (args: CellChangeArgs<RecordType>, handleCallback: (rowData: any, index: any, value?: any) => void) => void;
160
167
  }
161
168
  export type GridTableProps<RecordType = AnyObject> = TableProps<RecordType> | TableEditProps<RecordType>;
162
- export type CellChangeArgs = {
169
+ export interface CommandItem {
170
+ id: string;
171
+ type?: string;
172
+ visible?: boolean;
173
+ title: string;
174
+ color?: 'blue' | 'purple' | 'cyan' | 'green' | 'magenta' | 'pink' | 'red' | 'orange' | 'yellow' | 'volcano' | 'geekblue' | 'lime' | 'gold';
175
+ tooltip?: string;
176
+ icon?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
177
+ template?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
178
+ client?: boolean;
179
+ confirmDialog?: boolean;
180
+ }
181
+ export type CellChangeArgs<T> = {
163
182
  type: 'onPaste' | 'onChange' | 'onCellPaste';
164
183
  value: any;
165
- rowData: any;
166
- rows: any[];
167
- rowsData: any[];
184
+ option: AnyObject;
185
+ rowData: T;
186
+ rowsData: T[];
168
187
  indexRow: number;
169
188
  rowId?: string;
170
- field: string;
189
+ field: string | undefined;
171
190
  indexCol: any;
172
191
  sumValue?: any[];
173
192
  };
@@ -188,13 +207,10 @@ export type SourceFilter = {
188
207
  loadOptions?: (search: string, callback: (newOptions: any[]) => void) => void;
189
208
  };
190
209
  export type RowSelection<RecordType> = Omit<TableRowSelection<RecordType>, 'type' | 'columnWidth' | 'hideSelectAll' | 'defaultSelectedRowKeys'>;
191
- export type SelectionSettings = {
210
+ export type SelectionSettings = Omit<TableRowSelection, 'type' | 'onChange' | 'onSelect' | 'onSelectAll' | 'onSelectNone' | 'onSelectMultiple'> & {
192
211
  mode?: 'checkbox' | 'radio';
193
212
  type?: 'single' | 'multiple';
194
213
  checkboxOnly?: boolean;
195
- hideSelectAll?: boolean;
196
- columnWidth?: number | string;
197
- defaultSelectedRowKeys?: Key[];
198
214
  };
199
215
  export type RecordDoubleClickEventArgs<RecordType> = {
200
216
  rowData: RecordType;
@@ -223,3 +239,5 @@ export type IFormat = {
223
239
  monthFormat?: string;
224
240
  yearFormat?: string;
225
241
  };
242
+ export type GetRowKey<RecordType> = (record: RecordType, index?: number) => Key;
243
+ export type Presets = Required<ColorPickerProps>['presets'][number];
@@ -1,12 +1,13 @@
1
1
  /// <reference types="react" />
2
- import type { IFormat } from "./type";
2
+ import type { AnyObject, IFormat } from "./type";
3
3
  import type { SubmitHandler } from "react-hook-form";
4
- export interface IContext {
4
+ import type { GetRowKey } from "./type";
5
+ export interface IContext<RecordType> {
5
6
  searchValue?: any;
6
7
  setSearchValue?: any;
7
8
  open?: boolean;
8
9
  setOpen?: any;
9
- rowKey: string;
10
+ rowKey: string | keyof RecordType | GetRowKey<RecordType>;
10
11
  onSave?: any;
11
12
  form?: any;
12
13
  format?: IFormat;
@@ -15,13 +16,16 @@ export interface IContext {
15
16
  handleSubmit?: any;
16
17
  onSubmit?: SubmitHandler<any>;
17
18
  getValues?: any;
18
- handleCellChange?: ({ key, record, type }: ContextCellChange) => void;
19
+ handleCellChange?: (args: ContextCellChange<RecordType>) => void;
20
+ getRowKey?: GetRowKey<RecordType>;
19
21
  }
20
- export type ContextCellChange = {
21
- key: string;
22
+ export type ContextCellChange<RecordType = AnyObject> = {
23
+ key: string | keyof RecordType | GetRowKey<RecordType>;
22
24
  record: any;
25
+ field: string | undefined;
26
+ option: any;
23
27
  newState?: any;
24
28
  prevState?: any;
25
29
  type: 'enter' | 'blur' | 'outClick';
26
30
  };
27
- export declare const TableContext: import("react").Context<IContext>;
31
+ export declare const TableContext: import("react").Context<IContext<any>>;
@@ -1,4 +1,7 @@
1
1
  import { createContext } from 'react';
2
+
3
+ // import {AnyObject} from "antd/es/_util/type";
4
+
2
5
  export const TableContext = /*#__PURE__*/createContext({
3
6
  rowKey: 'id'
4
7
  });
package/es/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { default as GridComponent } from './grid-component';
2
+ export type { ColumnsTable, TableProps, ColumnTable, CommandItem, ToolbarItem, ContextMenuItem } from './grid-component';
@@ -1,9 +1,8 @@
1
- import type { Dispatch, SetStateAction } from "react";
2
1
  import React from "react";
3
- import type { ColumnsType } from "./type";
2
+ import type { ColumnsTable } from "./type";
4
3
  export type IColumnsChoose<RecordType> = {
5
- columns: any[];
6
- setColumns: Dispatch<SetStateAction<ColumnsType<RecordType>>>;
4
+ columns: ColumnsTable<RecordType>;
5
+ triggerChangeColumns?: (columns: ColumnsTable<RecordType>) => void;
7
6
  t?: any;
8
7
  };
9
8
  export declare const ColumnsChoose: <RecordType extends object>(props: IColumnsChoose<RecordType>) => React.JSX.Element;