es-grid-template 1.5.17 → 1.6.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 (53) hide show
  1. package/es/grid-component/CheckboxFilter2.js +0 -4
  2. package/es/grid-component/ColumnsChoose.js +9 -4
  3. package/es/grid-component/ColumnsGroup/ColumnsGroup.js +11 -4
  4. package/es/grid-component/EditableCell.js +26 -9
  5. package/es/grid-component/InternalTable.js +79 -27
  6. package/es/grid-component/TableGrid.js +39 -107
  7. package/es/grid-component/hooks/columns/index.d.ts +3 -2
  8. package/es/grid-component/hooks/columns/index.js +84 -8
  9. package/es/grid-component/hooks/content/ControlCheckbox.d.ts +13 -0
  10. package/es/grid-component/hooks/content/ControlCheckbox.js +87 -0
  11. package/es/grid-component/hooks/content/HeaderContent.d.ts +1 -1
  12. package/es/grid-component/hooks/content/HeaderContent.js +9 -4
  13. package/es/grid-component/hooks/useColumns.js +5 -5
  14. package/es/grid-component/hooks/utils.d.ts +28 -3
  15. package/es/grid-component/hooks/utils.js +544 -12
  16. package/es/grid-component/styles.scss +50 -1
  17. package/es/grid-component/table/Grid.d.ts +3 -0
  18. package/es/grid-component/table/GridEdit.d.ts +3 -0
  19. package/es/grid-component/table/GridEdit.js +349 -324
  20. package/es/grid-component/table/Group.d.ts +3 -0
  21. package/es/grid-component/table/InfiniteTable.d.ts +3 -0
  22. package/es/grid-component/table/InfiniteTable.js +4 -2
  23. package/es/grid-component/type.d.ts +1 -0
  24. package/es/index.d.ts +2 -0
  25. package/es/index.js +1 -0
  26. package/es/select/index.d.ts +1 -1
  27. package/lib/grid-component/CheckboxFilter2.js +0 -4
  28. package/lib/grid-component/ColumnsChoose.js +9 -4
  29. package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +11 -4
  30. package/lib/grid-component/EditableCell.js +26 -9
  31. package/lib/grid-component/InternalTable.js +78 -26
  32. package/lib/grid-component/TableGrid.js +37 -105
  33. package/lib/grid-component/hooks/columns/index.d.ts +3 -2
  34. package/lib/grid-component/hooks/columns/index.js +86 -9
  35. package/lib/grid-component/hooks/content/ControlCheckbox.d.ts +13 -0
  36. package/lib/grid-component/hooks/content/ControlCheckbox.js +95 -0
  37. package/lib/grid-component/hooks/content/HeaderContent.d.ts +1 -1
  38. package/lib/grid-component/hooks/content/HeaderContent.js +9 -4
  39. package/lib/grid-component/hooks/useColumns.js +5 -5
  40. package/lib/grid-component/hooks/utils.d.ts +28 -3
  41. package/lib/grid-component/hooks/utils.js +565 -19
  42. package/lib/grid-component/styles.scss +50 -1
  43. package/lib/grid-component/table/Grid.d.ts +3 -0
  44. package/lib/grid-component/table/GridEdit.d.ts +3 -0
  45. package/lib/grid-component/table/GridEdit.js +339 -322
  46. package/lib/grid-component/table/Group.d.ts +3 -0
  47. package/lib/grid-component/table/InfiniteTable.d.ts +3 -0
  48. package/lib/grid-component/table/InfiniteTable.js +4 -2
  49. package/lib/grid-component/type.d.ts +1 -0
  50. package/lib/index.d.ts +2 -0
  51. package/lib/index.js +7 -0
  52. package/lib/select/index.d.ts +1 -1
  53. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { checkDecimalSeparator, checkThousandSeparator, convertDateToDayjs, convertDayjsToDate, convertFormat, getDatepickerFormat, getDateRangeFormat, getDateString, getFormat, getTypeFilter, isColor, isEmpty } from "../utils";
1
+ import { checkDecimalSeparator, checkThousandSeparator, convertDateToDayjs, convertDayjsToDate, convertFormat, getDatepickerFormat, getDateRangeFormat, getDateString, getEditType, getFormat, getTypeFilter, isColor, isEmpty } from "../utils";
2
2
  import { numericFormatter } from "react-numeric-component";
3
3
  import dayjs from "dayjs";
4
4
  import moment from "moment/moment";
@@ -8,6 +8,7 @@ import CheckboxFilter from "../../CheckboxFilter";
8
8
  import { SELECTION_COLUMN } from "rc-master-ui/es/table/hooks/useSelection";
9
9
  import NumberRange from "../../number-range";
10
10
  import NumberInput from "../../number";
11
+ import ControlCheckbox from "../content/ControlCheckbox";
11
12
  // import {Typography} from "antd";
12
13
  // const {RangePicker} = DatePicker
13
14
 
@@ -55,7 +56,67 @@ export const flatColumns2 = columns => {
55
56
  }];
56
57
  }, []);
57
58
  };
58
- export const getValueCell = (column, value, record, format) => {
59
+ export const getValueCell = (column, value, record, rowIndex, colIndex, format) => {
60
+ switch (column?.type) {
61
+ case 'number':
62
+ const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
63
+ const cellFormat = getFormat(colFormat, format);
64
+ const thousandSeparator = cellFormat?.thousandSeparator;
65
+ const decimalSeparator = cellFormat?.decimalSeparator;
66
+ const dec = cellFormat?.decimalScale;
67
+
68
+ // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? parseFloat(Number(value).toFixed(dec)).toString() : value.toString()) : '0'
69
+
70
+ const tmpval = typeof value === 'string' ? Number(value) : value;
71
+
72
+ // console.log('aaaaa', Number(value))
73
+
74
+ const numericFormatProps = {
75
+ thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
76
+ decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
77
+ allowNegative: cellFormat?.allowNegative ?? true,
78
+ prefix: cellFormat?.prefix,
79
+ suffix: cellFormat?.suffix,
80
+ decimalScale: dec,
81
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
82
+ };
83
+
84
+ // if ( typeof value === "string") {
85
+ // const ttt = removeNumericFormat(value, undefined, numericFormatProps )
86
+ //
87
+ // console.log('ttt', ttt)
88
+ // }
89
+
90
+ const contentNumber = !isEmpty(value) ? dec || dec === 0 ? parseFloat(tmpval.toFixed(dec)).toString() : tmpval.toString() : '0';
91
+ // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? tmpval.toString() : tmpval.toString()) : '0'
92
+
93
+ return !isEmpty(contentNumber) ? numericFormatter(contentNumber, numericFormatProps) : '';
94
+ case 'date':
95
+ return value ? dayjs(value).format(format?.dateFormat ?? 'DD/MM/YYYY') : '';
96
+ case 'time':
97
+ return value ? value : '';
98
+ case 'year':
99
+ const year = value ? moment(value).format('yyyy') : '';
100
+ return /*#__PURE__*/React.createElement(Fragment, null, year);
101
+ case 'datetime':
102
+ return value ? moment(value).format(format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm') : '';
103
+ case 'boolean':
104
+ return value ? 'true' : 'false';
105
+ case 'color':
106
+ return value;
107
+ case 'checkbox':
108
+ return typeof value === 'boolean' ? value ? 'true' : 'false' : value ? '1' : '0';
109
+ case 'file':
110
+ const nameFile = typeof value === 'object' && !Array.isArray(value) ? value.name : Array.isArray(value) ? value.map(it => typeof it === 'object' ? it.name : it).filter(Boolean).join(", ") : '';
111
+ return value ? nameFile : '';
112
+ default:
113
+ if (Array.isArray(value)) {
114
+ return value.join(', ');
115
+ }
116
+ return value;
117
+ }
118
+ };
119
+ export const renderValueCell = (column, value, record, rowIndex, colIndex, format, editAble) => {
59
120
  switch (column?.type) {
60
121
  case 'number':
61
122
  const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
@@ -112,10 +173,21 @@ export const getValueCell = (column, value, record, format) => {
112
173
  }
113
174
  }));
114
175
  case 'checkbox':
115
- return /*#__PURE__*/React.createElement(Input, {
176
+ // return (
177
+ // <Checkbox
178
+ // checked={!!value}
179
+ //
180
+ // />
181
+ // )
182
+
183
+ return /*#__PURE__*/React.createElement(ControlCheckbox, {
184
+ column: column,
185
+ record: record,
186
+ rowIndex: rowIndex,
187
+ colIndex: colIndex,
116
188
  checked: !!value,
117
- readOnly: true,
118
- type: "checkbox"
189
+ checkValue: value,
190
+ editAble: editAble
119
191
  });
120
192
  case 'file':
121
193
  const nameFile = typeof value === 'object' && !Array.isArray(value) ? value.name : Array.isArray(value) ? value.map(it => typeof it === 'object' ? it.name : it).filter(Boolean).join(", ") : '';
@@ -127,15 +199,19 @@ export const getValueCell = (column, value, record, format) => {
127
199
  return value;
128
200
  }
129
201
  };
130
- export const renderContent = (column, value, record, index, format) => {
202
+ export const renderContent = (column, value, record, index, colIndex, editAble, format, onClick) => {
131
203
  const cellValue = value instanceof Date ? getDateString(column, value) : value;
132
- const content = getValueCell(column, cellValue, record, format);
204
+ const content = renderValueCell(column, cellValue, record, index, colIndex, format, editAble);
205
+ const editType = getEditType(column, record);
133
206
  return /*#__PURE__*/React.createElement(Fragment, null, column?.template ? typeof column.template === "function" ? column.template({
134
207
  value,
135
208
  index,
136
209
  rowData: record,
137
210
  field: column.field
138
- }) : column.template : content);
211
+ }) : column.template : content, (editType === 'select' || editType === 'selectTable') && /*#__PURE__*/React.createElement("span", {
212
+ className: 'caret-down',
213
+ onClick: onClick
214
+ }));
139
215
  };
140
216
  export const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, dataSourceFilter, buddhistLocale, locale, t, format, dateRangeLocale) => {
141
217
  const cellFormat = column.format ? typeof column.format === 'function' ? column.format({}) : column.format : format;
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ import type { ColumnTable } from "../../type";
3
+ type Props = {
4
+ column: ColumnTable;
5
+ record?: any;
6
+ rowIndex: number;
7
+ colIndex: number;
8
+ checkValue: any;
9
+ checked: boolean;
10
+ editAble?: boolean;
11
+ };
12
+ declare const ControlCheckbox: (props: Props) => React.JSX.Element;
13
+ export default ControlCheckbox;
@@ -0,0 +1,87 @@
1
+ import React, { useContext } from "react";
2
+ import { isDisable, isEditable, parseBooleanToValue } from "../utils";
3
+ import { Checkbox } from "rc-master-ui";
4
+ import { TableContext } from "../../useContext";
5
+ const ControlCheckbox = props => {
6
+ const {
7
+ column,
8
+ record,
9
+ rowIndex,
10
+ colIndex,
11
+ checkValue,
12
+ editAble,
13
+ checked
14
+ } = props;
15
+ const {
16
+ handleCellChange,
17
+ getRowKey
18
+ } = useContext(TableContext);
19
+
20
+ // const isEdit = getEditType(column, record)
21
+
22
+ const isEdit = React.useMemo(() => {
23
+ return isEditable(column, record);
24
+ }, [column, record]);
25
+
26
+ // const [isHover, setIsHover] = useState(false)
27
+
28
+ const inputNode = value => {
29
+ return /*#__PURE__*/React.createElement(Checkbox, {
30
+ checked: Boolean(value),
31
+ defaultChecked: Boolean(checked)
32
+ // style={{ textAlign: column.align ?? 'left' }}
33
+ ,
34
+ onChange: val => {
35
+ const newVal = typeof checkValue === "number" ? parseBooleanToValue(val.target.checked, typeof value) : val.target.checked;
36
+
37
+ // onChange(newVal)
38
+
39
+ const key = getRowKey?.(record, rowIndex);
40
+ // const formState = getValues()
41
+
42
+ handleCellChange?.({
43
+ key: key,
44
+ // @ts-ignore
45
+ record: {
46
+ ...record,
47
+ [column.field]: newVal
48
+ },
49
+ option: value,
50
+ prevState: value,
51
+ newState: newVal,
52
+ field: column.field ?? column.dataIndex,
53
+ indexCol: colIndex,
54
+ indexRow: rowIndex,
55
+ type: 'blur'
56
+ });
57
+ },
58
+ disabled: isDisable(column, record) ?? false
59
+ });
60
+ };
61
+ return /*#__PURE__*/React.createElement("div", {
62
+ // onMouseEnter={() => {
63
+ // setIsHover(true)
64
+ // }}
65
+ //
66
+ // onMouseLeave={() => {
67
+ // setIsHover(false)
68
+ // }}
69
+ style: {
70
+ display: 'flex',
71
+ alignItems: 'center',
72
+ justifyContent: column.align ?? 'center',
73
+ paddingInline: 5,
74
+ height: '100%',
75
+ width: '100%'
76
+ }
77
+ }, editAble && isEdit !== false ? inputNode(checkValue) : /*#__PURE__*/React.createElement(Checkbox, {
78
+ checked: checked,
79
+ onChange: e => {
80
+ e.preventDefault();
81
+ },
82
+ style: {
83
+ textAlign: column.align ?? 'left'
84
+ }
85
+ }));
86
+ };
87
+ export default ControlCheckbox;
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import type { ColumnTable } from "../../type";
3
3
  import type { IWrapSettings } from "../../type";
4
- type Props = {
4
+ type Props = React.HTMLAttributes<HTMLDivElement> & {
5
5
  t?: any;
6
6
  id?: string;
7
7
  content?: string;
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import React, { Fragment } from "react";
2
3
  import classnames from "classnames";
3
4
  import { getTemplate } from "../utils";
@@ -10,7 +11,10 @@ const HeaderContent = props => {
10
11
  const {
11
12
  t,
12
13
  id,
13
- wrapSettings
14
+ wrapSettings,
15
+ column,
16
+ onCopy,
17
+ ...rest
14
18
  } = props;
15
19
  const {
16
20
  headerTooltip,
@@ -26,14 +30,15 @@ const HeaderContent = props => {
26
30
  const tooltip = React.useMemo(() => {
27
31
  return t ? t?.(headerTooltip ?? columnGroupText ?? headerText) : headerTooltip ?? columnGroupText ?? headerText;
28
32
  }, [columnGroupText, headerText, headerTooltip, t]);
29
- return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(HeaderStyle, {
33
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(HeaderStyle, _extends({}, rest, {
30
34
  className: classnames('', {
31
35
  'ui-rc-table-cell-ellipsis': ellipsis !== false && headerTextWrap !== true,
32
36
  'header-text-wrap': headerTextWrap ?? (wrapSettings?.wrapMode === 'Header' || wrapSettings?.wrapMode === 'Both')
33
37
  }),
34
38
  "data-tooltip-id": `${id}-tooltip-header`,
35
39
  "data-tooltip-content": tooltip,
36
- "data-tooltip-offset": 16
37
- }, headerTemplate ? getTemplate(headerTemplate) : t ? t(text) : text));
40
+ "data-tooltip-offset": 16,
41
+ onCopy: onCopy
42
+ }), headerTemplate ? getTemplate(headerTemplate, column) : t ? t(text) : text));
38
43
  };
39
44
  export default HeaderContent;
@@ -287,21 +287,21 @@ const useColumns = config => {
287
287
  const cellFormat = getFormat(colFormat, format);
288
288
  if (groupSetting && groupSetting.hiddenColumnGroup === false) {
289
289
  if (record.children) {
290
- return renderContent(col, value, record, rowIndex, cellFormat);
290
+ return renderContent(col, value, record, rowIndex, colIndex, false, cellFormat);
291
291
  }
292
292
  if (groupColumns?.includes(col.field)) {
293
293
  return '';
294
294
  }
295
- return renderContent(col, value, record, rowIndex, cellFormat);
295
+ return renderContent(col, value, record, rowIndex, colIndex, false, cellFormat);
296
296
  }
297
297
  if (col.field === firstNonGroupColumn?.field && record.children) {
298
298
  const currentGroupColumn = flatColumns2(cols).find(it => it.field === record.field);
299
299
  if (currentGroupColumn?.template) {
300
- return renderContent(currentGroupColumn, record[record.field], record, rowIndex, cellFormat);
300
+ return renderContent(currentGroupColumn, record[record.field], record, rowIndex, colIndex, false, cellFormat);
301
301
  }
302
- return /*#__PURE__*/React.createElement("span", null, currentGroupColumn?.headerText, ": ", renderContent(currentGroupColumn, record[record.field], record, rowIndex, cellFormat));
302
+ return /*#__PURE__*/React.createElement("span", null, currentGroupColumn?.headerText, ": ", renderContent(currentGroupColumn, record[record.field], record, rowIndex, colIndex, false, cellFormat));
303
303
  }
304
- return renderContent(col, value, record, rowIndex, cellFormat);
304
+ return renderContent(col, value, record, rowIndex, colIndex, false, cellFormat);
305
305
  },
306
306
  hidden: groupSetting && groupSetting.hiddenColumnGroup === false ? transformedColumn.hidden : groupAble && groupColumns && groupColumns.includes(col.field) ? true : transformedColumn.hidden
307
307
  };
@@ -11,6 +11,7 @@ export declare const sumDataByField: (data: any[], field: string) => any;
11
11
  export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
12
12
  export declare const checkDecimalSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
13
13
  export declare const isEmpty: (d: any) => boolean;
14
+ export declare const removeVietnameseTones: (str: any) => any;
14
15
  export declare const isNullOrUndefined: (d: any) => boolean;
15
16
  export declare const convertDayjsToDate: (dateString: string, format?: string) => Date;
16
17
  export declare const convertDateToDayjs: (date: Date | undefined, format?: string) => dayjs.Dayjs;
@@ -48,7 +49,7 @@ export declare const isDisable: <T>(column: ColumnTable<T>, rowData?: any) => bo
48
49
  export declare const checkFieldKey: (key: string | undefined) => string;
49
50
  export declare const convertLabelToTitle: (data: any[]) => any[];
50
51
  export declare const convertArrayWithIndent: (inputArray: any[], parentIndent?: number) => any[];
51
- export declare const getTemplate: (template: any) => React.ReactNode | React.ReactElement;
52
+ export declare const getTemplate: (template: any, column?: ColumnTable) => React.ReactNode | React.ReactElement;
52
53
  export declare const totalFixedWidth: <T>(columns: ColumnsTable<T>, type: 'left' | 'right', selectionSettings?: SelectionSettings) => number;
53
54
  export declare const isObjEmpty: (obj: any) => boolean;
54
55
  export declare const getColumnsVisible: <T>(columns: ColumnsTable<T>, index: number) => ColumnTable<T>[];
@@ -58,6 +59,7 @@ export declare const genPresets: (presets?: import("@ant-design/colors").Palette
58
59
  export declare function findAllChildrenKeys<RecordType>(data: readonly RecordType[], getRowKey: GetRowKey<RecordType>, childrenColumnName: string): Key[];
59
60
  export declare const flattenArray: <RecordType extends AnyObject = AnyObject>(arr: any[]) => RecordType[];
60
61
  export declare const flattenData: <RecordType extends AnyObject = AnyObject>(childrenColumnName: string, data?: RecordType[]) => RecordType[];
62
+ export declare const unFlattenData: <RecordType extends AnyObject = AnyObject>(data: RecordType[]) => RecordType[];
61
63
  export declare const countItemsBeforeIndex: (array: any[], index: number) => number;
62
64
  export declare const getRowNumber: (array: any[], rowKey: any, key: any) => number;
63
65
  export declare const getDefaultValue: (defaultValue: any) => AnyObject;
@@ -72,7 +74,21 @@ export declare const getFirstSelectCell: (selectCells: any) => {
72
74
  col: number;
73
75
  };
74
76
  export declare const getRowsPasteIndex: (pasteRows: any) => number[];
75
- export declare function addRows8(arr: any, n: number): {
77
+ export declare function addRowsDownWithCtrl(arr: any, n: number): {
78
+ combined: any;
79
+ addedRows: any[];
80
+ } | {
81
+ combined: any[];
82
+ addedRows: any[];
83
+ };
84
+ export declare function addRowsDown(arr: any, n: number): {
85
+ combined: any;
86
+ addedRows: any[];
87
+ } | {
88
+ combined: any[];
89
+ addedRows: any[];
90
+ };
91
+ export declare function addRowsUpWithCtrl(array: any, n: number): {
76
92
  combined: any;
77
93
  addedRows: any[];
78
94
  } | {
@@ -101,7 +117,7 @@ export declare const filterDataByColumns2: (data: any[], queries: any) => any[];
101
117
  export declare const removeFieldRecursive: (data: any[], field: string) => any[];
102
118
  export declare const filterDataByColumns3: (data: any[], queries: any[]) => any[];
103
119
  export declare const shouldInclude: (item: any, queries: any[]) => any;
104
- export declare function filterDataByColumns4(data: any[], queries: any[]): any[];
120
+ export declare function filterDataByColumns4(data: any[], queries: any[], keysFilter: string[] | undefined): any[];
105
121
  export declare function isDateString(str: any): boolean;
106
122
  export declare function compareDates(date1: any, date2: any): boolean;
107
123
  export declare function compareDate(itemValue: any, value: any): boolean;
@@ -149,3 +165,12 @@ export declare const detectSeparators: (str: string) => {
149
165
  thousandSeparator: string;
150
166
  decimalSeparator: string;
151
167
  };
168
+ export declare const convertFilters: (filters: any[]) => any[];
169
+ export declare const getAllRowKey: (data: any[]) => any[];
170
+ export declare function updateDataByFilter(tree: any[], filter: any[]): any[];
171
+ export declare function updateOrInsert(dataArray: any[], dataFilter: any[]): any[];
172
+ export declare function mergeWithFilter(dataArray: any[], dataFilter: any[]): any[];
173
+ export declare function mergeWithFilter2(dataArray: any[], dataFilter: any[]): any[];
174
+ export declare const removeInvisibleColumns: (columns: any[]) => any[];
175
+ export declare const sumByField: (data: any[], field: string) => number;
176
+ export declare const customFilterOption: (input: string, option: any) => any;