es-grid-template 1.2.8 → 1.2.9

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,9 +1,9 @@
1
- import type { ColumnTable, ColumnType, IFormat } from "../../type";
1
+ import type { ColumnTable, IFormat } from "../../type";
2
2
  import React from "react";
3
3
  import type { TableLocale } from "rc-master-ui/lib/table/interface";
4
4
  import type { ColumnsTable } from "../../type";
5
5
  export declare function flatColumns<RecordType>(columns: ColumnsTable<RecordType>, parentKey?: string): ColumnsTable<RecordType>;
6
6
  export declare function flatColumns2<RecordType>(columns: ColumnsTable<RecordType>): ColumnsTable<RecordType>;
7
- export declare const getValueCell: <T>(column: ColumnType<T>, value: any, format?: IFormat) => any;
8
- export declare const renderContent: (column: ColumnTable, value: any, record: any, index: number, format?: IFormat) => React.JSX.Element;
9
- export declare const renderFilter: <RecordType>(column: ColumnType<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any) => React.JSX.Element;
7
+ export declare const getValueCell: <T>(column: ColumnTable<T>, value: any, format?: IFormat) => any;
8
+ export declare const renderContent: <T>(column: ColumnTable<T>, value: any, record: any, index: number, format?: IFormat) => React.JSX.Element;
9
+ export declare const renderFilter: <RecordType>(column: ColumnTable<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any) => React.JSX.Element;
@@ -246,11 +246,12 @@ const useColumns = config => {
246
246
  width: col.width,
247
247
  onResize: handleResize?.(col)
248
248
  }),
249
- onCell: data => {
249
+ onCell: (data, index) => {
250
250
  return {
251
251
  colSpan: groupColumns && data.children && col.field === firstNonGroupColumn?.field ? 2 : groupColumns && data.children && nonGroupColumns[1].field === col.field ? 0 : 1,
252
252
  zIndex: data.children && col.field === firstNonGroupColumn?.field ? 11 : undefined,
253
- className: classNames('', {
253
+ ...transformedColumn?.onCell?.(data, index),
254
+ className: classNames(transformedColumn?.onCell?.(data, index).className ?? '', {
254
255
  'cell-group': groupColumns && data.children,
255
256
  'cell-group-fixed': groupColumns && data.children && col.field === firstNonGroupColumn?.field
256
257
  })
@@ -1,7 +1,7 @@
1
1
  import type * as React from "react";
2
2
  import dayjs from "dayjs";
3
3
  import type { EditType, IColumnType, TypeFilter } from "rc-master-ui";
4
- import type { ColumnsType, ColumnTable, GetRowKey } from "../type";
4
+ import type { ColumnTable, GetRowKey } from "../type";
5
5
  import type { SelectionSettings } from "../type";
6
6
  import type { AnyObject } from "../type";
7
7
  import type { Key } from "react";
@@ -32,9 +32,9 @@ export declare const checkFieldKey: (key: string | undefined) => string;
32
32
  export declare const convertLabelToTitle: (data: any[]) => any[];
33
33
  export declare const convertArrayWithIndent: (inputArray: any[], parentIndent?: number) => any[];
34
34
  export declare const getTemplate: (template: any) => React.ReactNode | React.ReactElement;
35
- export declare const totalFixedWidth: <T>(columns: ColumnsType<T>, type: 'left' | 'right', selectionSettings?: SelectionSettings) => number;
35
+ export declare const totalFixedWidth: <T>(columns: ColumnsTable<T>, type: 'left' | 'right', selectionSettings?: SelectionSettings) => number;
36
36
  export declare const isObjEmpty: (obj: any) => boolean;
37
- export declare const getColumnsVisible: <T>(columns: ColumnsType<T>, index: number) => import("../type").ColumnType<T>[];
37
+ export declare const getColumnsVisible: <T>(columns: ColumnsTable<T>, index: number) => ColumnTable<T>[];
38
38
  export declare const updateData: <Record_1 = AnyObject>(initData: Record_1[], rows: Record_1[], key: keyof Record_1) => Record_1[];
39
39
  export declare const parseBooleanToValue: (value: boolean, type: 'boolean' | 'number') => number | boolean;
40
40
  export declare const genPresets: (presets?: import("@ant-design/colors").PalettesProps) => import("antd/es/color-picker/interface").PresetsItem[];
@@ -70,3 +70,4 @@ export declare const convertColumns: <RecordType>(cols: ColumnsTable<RecordType>
70
70
  export declare const checkChild: (inputArray: any[]) => boolean;
71
71
  export declare const isEditable: <RecordType>(column: ColumnTable, rowData: RecordType) => boolean | ((rowData: any) => boolean);
72
72
  export declare const isArraysEqual: (arr1: any[], arr2: any[]) => boolean;
73
+ export declare const editAbleColumns: <T>(columns: ColumnsTable<T>) => ColumnTable<T>[];
@@ -784,4 +784,7 @@ export const isArraysEqual = (arr1, arr2) => {
784
784
  return false;
785
785
  }
786
786
  return arr1.every((element, index) => element === arr2[index]);
787
+ };
788
+ export const editAbleColumns = columns => {
789
+ return columns.filter(col => col.field !== '#' && col.field !== 'index' && col.field !== 'command' && col.visible !== false);
787
790
  };
@@ -1,11 +1,10 @@
1
1
  import React from 'react';
2
2
  import 'dayjs/locale/es';
3
3
  import 'dayjs/locale/vi';
4
- import type { AnyObject } from "../type";
5
- import type { TableEditProps } from "../type";
4
+ import type { AnyObject, TableProps } from "../type";
6
5
  import type { ColumnsTable } from "../type";
7
6
  import type { GetRowKey } from "../type";
8
- type Props<RecordType> = TableEditProps<RecordType> & {
7
+ type Props<RecordType> = TableProps<RecordType> & {
9
8
  tableRef: any;
10
9
  triggerChangeColumns?: (columns: ColumnsTable<RecordType>, type: string) => void;
11
10
  triggerChangeData?: (newData: RecordType[], type: string) => void;
@@ -13,9 +13,8 @@ import dayjs from "dayjs";
13
13
  import 'dayjs/locale/es';
14
14
  import 'dayjs/locale/vi';
15
15
  import TableGrid from "../TableGrid";
16
- import { addRows8, checkChild, findAllChildrenKeys, findItemByKey, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isEditable, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
16
+ import { addRows8, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isEditable, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
17
17
  import Message from "../../Message/Message";
18
-
19
18
  // import Command from "../Command";
20
19
 
21
20
  import { Toolbar, ConfigProvider } from "rc-master-ui";
@@ -757,8 +756,9 @@ const GridEdit = props => {
757
756
  };
758
757
  const handleClickRowHeader = (row, col) => {
759
758
  const newSelectedCells = new Set();
759
+ const tCols = editAbleColumns(columns);
760
760
  for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
761
- for (let c = Math.min(columns.length, col) + 1; c <= Math.max(columns.length, col); c++) {
761
+ for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
762
762
  newSelectedCells.add(`${r}-${c}`);
763
763
  }
764
764
  }
@@ -1265,6 +1265,29 @@ const GridEdit = props => {
1265
1265
  return {
1266
1266
  ...column,
1267
1267
  className: 'rc-ui-cell-editable',
1268
+ onCell: (record, rowIndex) => {
1269
+ const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
1270
+ return {
1271
+ onPaste: event => {
1272
+ if (editingKey === '') {
1273
+ handlePaste(record, colIndex + 1, rowNumber, event);
1274
+ event.preventDefault();
1275
+ }
1276
+ },
1277
+ onCopy: e => {
1278
+ if (editingKey === '') {
1279
+ handleCopy(e);
1280
+ e.preventDefault();
1281
+ }
1282
+ },
1283
+ onClick: () => {
1284
+ if (record[rowKey] !== editingKey && editingKey !== '') {
1285
+ setEditingKey('');
1286
+ }
1287
+ },
1288
+ tabIndex: (rowIndex ?? 0) * columns.length + colIndex
1289
+ };
1290
+ },
1268
1291
  render: (value, record, rowIndex) => {
1269
1292
  const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
1270
1293
  return /*#__PURE__*/React.createElement("div", {
@@ -1294,7 +1317,7 @@ const GridEdit = props => {
1294
1317
  onKeyDown: event => {
1295
1318
  const key = getRowKey(record, dataSource.indexOf(record));
1296
1319
  if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
1297
- if (record[rowKey] !== editingKey) {
1320
+ if (record[rowKey] !== editingKey && isEditable(column, record)) {
1298
1321
  // ~~ khi editingKey = ''
1299
1322
  event.preventDefault();
1300
1323
  event.stopPropagation();
@@ -1370,14 +1393,14 @@ const GridEdit = props => {
1370
1393
  }
1371
1394
  },
1372
1395
  onDoubleClick: event => {
1373
- if (!isEditing(record) && record[rowKey] !== editingKey) {
1396
+ if (!isEditing(record) && record[rowKey] !== editingKey && isEditable(column, record)) {
1374
1397
  handleEdit(record, column, getEditType(column, record), event);
1375
1398
  handleCellClick(rowNumber, record, column);
1376
1399
  }
1377
1400
  },
1378
1401
  onClick: () => {
1379
1402
  if (record[rowKey] !== editingKey && editingKey !== '') {
1380
- // setEditingKey('')
1403
+ setEditingKey('');
1381
1404
  }
1382
1405
  },
1383
1406
  // className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable',
@@ -1389,8 +1412,9 @@ const GridEdit = props => {
1389
1412
  title: getValueCell(column, record[column.field], format),
1390
1413
  'data-col-index': colIndex,
1391
1414
  'data-row-index': rowNumber,
1392
- editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record) !== false,
1415
+ editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
1393
1416
  cellEditing,
1417
+ t,
1394
1418
  // editing: isEditing(record) && rowEditable?.(record) !== false,
1395
1419
  tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
1396
1420
  style: isPasteDragging ? {
@@ -1462,10 +1486,10 @@ const GridEdit = props => {
1462
1486
  width: '100%'
1463
1487
  },
1464
1488
  items: toolbarItemsBottom ?? [],
1465
- mode: 'scroll'
1466
- // onClick={({ item }) => {
1467
- // console.log('item', item)
1468
- // }}
1489
+ mode: 'scroll',
1490
+ onClick: ({}) => {
1491
+ setEditingKey('');
1492
+ }
1469
1493
  }));
1470
1494
  };
1471
1495
  const onSelectChange = keys => {
@@ -84,7 +84,7 @@ export type ToolbarClick = {
84
84
  item: any;
85
85
  column: any;
86
86
  };
87
- export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTemplate' | 'title'> & {
87
+ export type ColumnTable<RecordType = AnyObject> = Omit<RcColumnType<RecordType>, 'headerTemplate' | 'title'> & {
88
88
  field?: string;
89
89
  key?: any;
90
90
  type?: IColumnType;
@@ -111,9 +111,9 @@ export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTempl
111
111
  template?: ReactNode | ReactElement | ((args: ColumnTemplate<RecordType>) => ReactNode | ReactElement);
112
112
  showTooltip?: boolean;
113
113
  tooltipDescription?: ReactNode | ReactElement | ((value: any, record: RecordType, index: number) => ReactNode | ReactElement);
114
- headerTemplate?: React.ReactNode | React.ReactElement | ((column: ColumnType<RecordType>) => React.ReactNode | React.ReactElement);
114
+ headerTemplate?: React.ReactNode | React.ReactElement | ((column: ColumnTable<RecordType>) => React.ReactNode | React.ReactElement);
115
115
  commandItems?: CommandItem[];
116
- children?: ColumnType<RecordType>[];
116
+ children?: ColumnTable<RecordType>[];
117
117
  editType?: EditType | ((rowData?: RecordType) => EditType);
118
118
  disable?: boolean | ((rowData: any) => boolean);
119
119
  editEnable?: boolean | ((rowData: any) => boolean);
@@ -133,10 +133,8 @@ export type ColumnTemplate<RecordType> = {
133
133
  index: number;
134
134
  field: string;
135
135
  };
136
- export type ColumnsType<RecordType = AnyObject> = ColumnType<RecordType>[];
137
- export type ColumnTable<RecordType = AnyObject> = ColumnType<RecordType>;
138
136
  export type ColumnsTable<RecordType = AnyObject> = ColumnTable<RecordType>[];
139
- export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, 'columns' | 'rowSelection' | 'loading' | 'dataSource' | 'summary'> {
137
+ export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<RecordType>, 'columns' | 'rowSelection' | 'loading' | 'dataSource' | 'summary'> {
140
138
  editAble?: boolean;
141
139
  groupAble?: boolean;
142
140
  groupColumns?: string[];
@@ -166,7 +164,7 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
166
164
  value: any;
167
165
  }[]) => void;
168
166
  onSorter?: (args: {
169
- column: ColumnType<RecordType>;
167
+ column: ColumnTable<RecordType>;
170
168
  columnKey: string;
171
169
  field: string;
172
170
  direction: 'Ascending' | 'Descending' | null;
@@ -189,9 +187,6 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
189
187
  summary?: boolean | ((data: readonly RecordType[]) => React.ReactNode);
190
188
  showEmptyText?: boolean;
191
189
  commandSettings?: CommandSettings;
192
- }
193
- export interface TableEditProps<RecordType = AnyObject> extends Omit<TableProps<RecordType>, 'columns'> {
194
- columns: ColumnsTable<RecordType>;
195
190
  onCellPaste?: ICellPasteModel<RecordType>;
196
191
  onCellChange?: (args: CellChangeArgs<RecordType>, handleCallback: (rowData: any, index: any, value?: any) => void) => void;
197
192
  onCellClick?: (args: ICellClick, callback?: any) => void;
@@ -206,7 +201,7 @@ export type ICellClick = {
206
201
  cellValue: any;
207
202
  rowData: any;
208
203
  };
209
- export type GridTableProps<RecordType = AnyObject> = TableProps<RecordType> | TableEditProps<RecordType>;
204
+ export type GridTableProps<RecordType = AnyObject> = TableProps<RecordType>;
210
205
  export interface CommandItem {
211
206
  id: string;
212
207
  type?: string;
@@ -1,9 +1,9 @@
1
- import type { ColumnTable, ColumnType, IFormat } from "../../type";
1
+ import type { ColumnTable, IFormat } from "../../type";
2
2
  import React from "react";
3
3
  import type { TableLocale } from "rc-master-ui/lib/table/interface";
4
4
  import type { ColumnsTable } from "../../type";
5
5
  export declare function flatColumns<RecordType>(columns: ColumnsTable<RecordType>, parentKey?: string): ColumnsTable<RecordType>;
6
6
  export declare function flatColumns2<RecordType>(columns: ColumnsTable<RecordType>): ColumnsTable<RecordType>;
7
- export declare const getValueCell: <T>(column: ColumnType<T>, value: any, format?: IFormat) => any;
8
- export declare const renderContent: (column: ColumnTable, value: any, record: any, index: number, format?: IFormat) => React.JSX.Element;
9
- export declare const renderFilter: <RecordType>(column: ColumnType<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any) => React.JSX.Element;
7
+ export declare const getValueCell: <T>(column: ColumnTable<T>, value: any, format?: IFormat) => any;
8
+ export declare const renderContent: <T>(column: ColumnTable<T>, value: any, record: any, index: number, format?: IFormat) => React.JSX.Element;
9
+ export declare const renderFilter: <RecordType>(column: ColumnTable<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any) => React.JSX.Element;
@@ -257,11 +257,12 @@ const useColumns = config => {
257
257
  width: col.width,
258
258
  onResize: handleResize?.(col)
259
259
  }),
260
- onCell: data => {
260
+ onCell: (data, index) => {
261
261
  return {
262
262
  colSpan: groupColumns && data.children && col.field === firstNonGroupColumn?.field ? 2 : groupColumns && data.children && nonGroupColumns[1].field === col.field ? 0 : 1,
263
263
  zIndex: data.children && col.field === firstNonGroupColumn?.field ? 11 : undefined,
264
- className: (0, _classnames.default)('', {
264
+ ...transformedColumn?.onCell?.(data, index),
265
+ className: (0, _classnames.default)(transformedColumn?.onCell?.(data, index).className ?? '', {
265
266
  'cell-group': groupColumns && data.children,
266
267
  'cell-group-fixed': groupColumns && data.children && col.field === firstNonGroupColumn?.field
267
268
  })
@@ -1,7 +1,7 @@
1
1
  import type * as React from "react";
2
2
  import dayjs from "dayjs";
3
3
  import type { EditType, IColumnType, TypeFilter } from "rc-master-ui";
4
- import type { ColumnsType, ColumnTable, GetRowKey } from "../type";
4
+ import type { ColumnTable, GetRowKey } from "../type";
5
5
  import type { SelectionSettings } from "../type";
6
6
  import type { AnyObject } from "../type";
7
7
  import type { Key } from "react";
@@ -32,9 +32,9 @@ export declare const checkFieldKey: (key: string | undefined) => string;
32
32
  export declare const convertLabelToTitle: (data: any[]) => any[];
33
33
  export declare const convertArrayWithIndent: (inputArray: any[], parentIndent?: number) => any[];
34
34
  export declare const getTemplate: (template: any) => React.ReactNode | React.ReactElement;
35
- export declare const totalFixedWidth: <T>(columns: ColumnsType<T>, type: 'left' | 'right', selectionSettings?: SelectionSettings) => number;
35
+ export declare const totalFixedWidth: <T>(columns: ColumnsTable<T>, type: 'left' | 'right', selectionSettings?: SelectionSettings) => number;
36
36
  export declare const isObjEmpty: (obj: any) => boolean;
37
- export declare const getColumnsVisible: <T>(columns: ColumnsType<T>, index: number) => import("../type").ColumnType<T>[];
37
+ export declare const getColumnsVisible: <T>(columns: ColumnsTable<T>, index: number) => ColumnTable<T>[];
38
38
  export declare const updateData: <Record_1 = AnyObject>(initData: Record_1[], rows: Record_1[], key: keyof Record_1) => Record_1[];
39
39
  export declare const parseBooleanToValue: (value: boolean, type: 'boolean' | 'number') => number | boolean;
40
40
  export declare const genPresets: (presets?: import("@ant-design/colors").PalettesProps) => import("antd/es/color-picker/interface").PresetsItem[];
@@ -70,3 +70,4 @@ export declare const convertColumns: <RecordType>(cols: ColumnsTable<RecordType>
70
70
  export declare const checkChild: (inputArray: any[]) => boolean;
71
71
  export declare const isEditable: <RecordType>(column: ColumnTable, rowData: RecordType) => boolean | ((rowData: any) => boolean);
72
72
  export declare const isArraysEqual: (arr1: any[], arr2: any[]) => boolean;
73
+ export declare const editAbleColumns: <T>(columns: ColumnsTable<T>) => ColumnTable<T>[];
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.addRowIdArray = void 0;
8
8
  exports.addRows8 = addRows8;
9
- exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertFlatColumn = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertColumns = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = exports.checkChild = void 0;
9
+ exports.editAbleColumns = exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertFlatColumn = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertColumns = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = exports.checkChild = void 0;
10
10
  exports.findAllChildrenKeys = findAllChildrenKeys;
11
11
  exports.getFirstSelectCell = exports.getEditType = exports.getDefaultValue = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = exports.findItemByKey = void 0;
12
12
  exports.getHiddenParentKeys = getHiddenParentKeys;
@@ -846,4 +846,8 @@ const isArraysEqual = (arr1, arr2) => {
846
846
  }
847
847
  return arr1.every((element, index) => element === arr2[index]);
848
848
  };
849
- exports.isArraysEqual = isArraysEqual;
849
+ exports.isArraysEqual = isArraysEqual;
850
+ const editAbleColumns = columns => {
851
+ return columns.filter(col => col.field !== '#' && col.field !== 'index' && col.field !== 'command' && col.visible !== false);
852
+ };
853
+ exports.editAbleColumns = editAbleColumns;
@@ -1,11 +1,10 @@
1
1
  import React from 'react';
2
2
  import 'dayjs/locale/es';
3
3
  import 'dayjs/locale/vi';
4
- import type { AnyObject } from "../type";
5
- import type { TableEditProps } from "../type";
4
+ import type { AnyObject, TableProps } from "../type";
6
5
  import type { ColumnsTable } from "../type";
7
6
  import type { GetRowKey } from "../type";
8
- type Props<RecordType> = TableEditProps<RecordType> & {
7
+ type Props<RecordType> = TableProps<RecordType> & {
9
8
  tableRef: any;
10
9
  triggerChangeColumns?: (columns: ColumnsTable<RecordType>, type: string) => void;
11
10
  triggerChangeData?: (newData: RecordType[], type: string) => void;
@@ -764,8 +764,9 @@ const GridEdit = props => {
764
764
  };
765
765
  const handleClickRowHeader = (row, col) => {
766
766
  const newSelectedCells = new Set();
767
+ const tCols = (0, _hooks.editAbleColumns)(columns);
767
768
  for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
768
- for (let c = Math.min(columns.length, col) + 1; c <= Math.max(columns.length, col); c++) {
769
+ for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
769
770
  newSelectedCells.add(`${r}-${c}`);
770
771
  }
771
772
  }
@@ -1272,6 +1273,29 @@ const GridEdit = props => {
1272
1273
  return {
1273
1274
  ...column,
1274
1275
  className: 'rc-ui-cell-editable',
1276
+ onCell: (record, rowIndex) => {
1277
+ const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1278
+ return {
1279
+ onPaste: event => {
1280
+ if (editingKey === '') {
1281
+ handlePaste(record, colIndex + 1, rowNumber, event);
1282
+ event.preventDefault();
1283
+ }
1284
+ },
1285
+ onCopy: e => {
1286
+ if (editingKey === '') {
1287
+ handleCopy(e);
1288
+ e.preventDefault();
1289
+ }
1290
+ },
1291
+ onClick: () => {
1292
+ if (record[rowKey] !== editingKey && editingKey !== '') {
1293
+ setEditingKey('');
1294
+ }
1295
+ },
1296
+ tabIndex: (rowIndex ?? 0) * columns.length + colIndex
1297
+ };
1298
+ },
1275
1299
  render: (value, record, rowIndex) => {
1276
1300
  const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1277
1301
  return /*#__PURE__*/_react.default.createElement("div", {
@@ -1301,7 +1325,7 @@ const GridEdit = props => {
1301
1325
  onKeyDown: event => {
1302
1326
  const key = getRowKey(record, dataSource.indexOf(record));
1303
1327
  if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
1304
- if (record[rowKey] !== editingKey) {
1328
+ if (record[rowKey] !== editingKey && (0, _hooks.isEditable)(column, record)) {
1305
1329
  // ~~ khi editingKey = ''
1306
1330
  event.preventDefault();
1307
1331
  event.stopPropagation();
@@ -1377,14 +1401,14 @@ const GridEdit = props => {
1377
1401
  }
1378
1402
  },
1379
1403
  onDoubleClick: event => {
1380
- if (!isEditing(record) && record[rowKey] !== editingKey) {
1404
+ if (!isEditing(record) && record[rowKey] !== editingKey && (0, _hooks.isEditable)(column, record)) {
1381
1405
  handleEdit(record, column, (0, _hooks.getEditType)(column, record), event);
1382
1406
  handleCellClick(rowNumber, record, column);
1383
1407
  }
1384
1408
  },
1385
1409
  onClick: () => {
1386
1410
  if (record[rowKey] !== editingKey && editingKey !== '') {
1387
- // setEditingKey('')
1411
+ setEditingKey('');
1388
1412
  }
1389
1413
  },
1390
1414
  // className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable',
@@ -1396,8 +1420,9 @@ const GridEdit = props => {
1396
1420
  title: (0, _columns.getValueCell)(column, record[column.field], format),
1397
1421
  'data-col-index': colIndex,
1398
1422
  'data-row-index': rowNumber,
1399
- editing: isEditing(record) && rowEditable?.(record) !== false && (0, _hooks.isEditable)(column, record) !== false,
1423
+ editing: isEditing(record) && rowEditable?.(record) !== false && (0, _hooks.isEditable)(column, record),
1400
1424
  cellEditing,
1425
+ t,
1401
1426
  // editing: isEditing(record) && rowEditable?.(record) !== false,
1402
1427
  tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
1403
1428
  style: isPasteDragging ? {
@@ -1469,10 +1494,10 @@ const GridEdit = props => {
1469
1494
  width: '100%'
1470
1495
  },
1471
1496
  items: toolbarItemsBottom ?? [],
1472
- mode: 'scroll'
1473
- // onClick={({ item }) => {
1474
- // console.log('item', item)
1475
- // }}
1497
+ mode: 'scroll',
1498
+ onClick: ({}) => {
1499
+ setEditingKey('');
1500
+ }
1476
1501
  }));
1477
1502
  };
1478
1503
  const onSelectChange = keys => {
@@ -84,7 +84,7 @@ export type ToolbarClick = {
84
84
  item: any;
85
85
  column: any;
86
86
  };
87
- export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTemplate' | 'title'> & {
87
+ export type ColumnTable<RecordType = AnyObject> = Omit<RcColumnType<RecordType>, 'headerTemplate' | 'title'> & {
88
88
  field?: string;
89
89
  key?: any;
90
90
  type?: IColumnType;
@@ -111,9 +111,9 @@ export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTempl
111
111
  template?: ReactNode | ReactElement | ((args: ColumnTemplate<RecordType>) => ReactNode | ReactElement);
112
112
  showTooltip?: boolean;
113
113
  tooltipDescription?: ReactNode | ReactElement | ((value: any, record: RecordType, index: number) => ReactNode | ReactElement);
114
- headerTemplate?: React.ReactNode | React.ReactElement | ((column: ColumnType<RecordType>) => React.ReactNode | React.ReactElement);
114
+ headerTemplate?: React.ReactNode | React.ReactElement | ((column: ColumnTable<RecordType>) => React.ReactNode | React.ReactElement);
115
115
  commandItems?: CommandItem[];
116
- children?: ColumnType<RecordType>[];
116
+ children?: ColumnTable<RecordType>[];
117
117
  editType?: EditType | ((rowData?: RecordType) => EditType);
118
118
  disable?: boolean | ((rowData: any) => boolean);
119
119
  editEnable?: boolean | ((rowData: any) => boolean);
@@ -133,10 +133,8 @@ export type ColumnTemplate<RecordType> = {
133
133
  index: number;
134
134
  field: string;
135
135
  };
136
- export type ColumnsType<RecordType = AnyObject> = ColumnType<RecordType>[];
137
- export type ColumnTable<RecordType = AnyObject> = ColumnType<RecordType>;
138
136
  export type ColumnsTable<RecordType = AnyObject> = ColumnTable<RecordType>[];
139
- export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, 'columns' | 'rowSelection' | 'loading' | 'dataSource' | 'summary'> {
137
+ export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<RecordType>, 'columns' | 'rowSelection' | 'loading' | 'dataSource' | 'summary'> {
140
138
  editAble?: boolean;
141
139
  groupAble?: boolean;
142
140
  groupColumns?: string[];
@@ -166,7 +164,7 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
166
164
  value: any;
167
165
  }[]) => void;
168
166
  onSorter?: (args: {
169
- column: ColumnType<RecordType>;
167
+ column: ColumnTable<RecordType>;
170
168
  columnKey: string;
171
169
  field: string;
172
170
  direction: 'Ascending' | 'Descending' | null;
@@ -189,9 +187,6 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
189
187
  summary?: boolean | ((data: readonly RecordType[]) => React.ReactNode);
190
188
  showEmptyText?: boolean;
191
189
  commandSettings?: CommandSettings;
192
- }
193
- export interface TableEditProps<RecordType = AnyObject> extends Omit<TableProps<RecordType>, 'columns'> {
194
- columns: ColumnsTable<RecordType>;
195
190
  onCellPaste?: ICellPasteModel<RecordType>;
196
191
  onCellChange?: (args: CellChangeArgs<RecordType>, handleCallback: (rowData: any, index: any, value?: any) => void) => void;
197
192
  onCellClick?: (args: ICellClick, callback?: any) => void;
@@ -206,7 +201,7 @@ export type ICellClick = {
206
201
  cellValue: any;
207
202
  rowData: any;
208
203
  };
209
- export type GridTableProps<RecordType = AnyObject> = TableProps<RecordType> | TableEditProps<RecordType>;
204
+ export type GridTableProps<RecordType = AnyObject> = TableProps<RecordType>;
210
205
  export interface CommandItem {
211
206
  id: string;
212
207
  type?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",