es-grid-template 0.0.7 → 0.0.13

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 (116) hide show
  1. package/LICENSE +21 -19
  2. package/es/{CheckboxFilter.d.ts → grid-component/CheckboxFilter.d.ts} +1 -1
  3. package/es/{CheckboxFilter.js → grid-component/CheckboxFilter.js} +7 -11
  4. package/es/grid-component/ColumnsChoose.d.ts +9 -0
  5. package/es/{ColumnsChoose.js → grid-component/ColumnsChoose.js} +66 -70
  6. package/es/grid-component/EditableCell.d.ts +19 -0
  7. package/es/grid-component/EditableCell.js +842 -0
  8. package/es/{FilterSearch.js → grid-component/FilterSearch.js} +2 -2
  9. package/es/grid-component/GridStyle.d.ts +4 -0
  10. package/es/grid-component/GridStyle.js +5 -0
  11. package/es/grid-component/InternalTable.d.ts +6 -0
  12. package/es/grid-component/InternalTable.js +283 -0
  13. package/es/grid-component/LoadingSpinner.d.ts +3 -0
  14. package/es/grid-component/LoadingSpinner.js +20 -0
  15. package/es/grid-component/Message/Message.d.ts +2 -0
  16. package/es/grid-component/Message/Message.js +16 -0
  17. package/es/grid-component/Message/index.d.ts +1 -0
  18. package/es/grid-component/Message/index.js +1 -0
  19. package/es/grid-component/TableGrid.d.ts +10 -0
  20. package/es/grid-component/TableGrid.js +375 -0
  21. package/es/grid-component/async-table-select/index.d.ts +9 -0
  22. package/es/grid-component/async-table-select/index.js +37 -0
  23. package/es/{hooks → grid-component/hooks}/constant.d.ts +14 -0
  24. package/es/{hooks → grid-component/hooks}/constant.js +17 -2
  25. package/es/grid-component/hooks/useColumns/index.d.ts +6 -0
  26. package/es/grid-component/hooks/useColumns/index.js +422 -0
  27. package/es/grid-component/hooks/utils.d.ts +35 -0
  28. package/es/{hooks → grid-component/hooks}/utils.js +147 -19
  29. package/es/grid-component/index.d.ts +2 -0
  30. package/es/grid-component/index.js +2 -0
  31. package/es/grid-component/rc-table/Grid.d.ts +8 -0
  32. package/es/grid-component/rc-table/Grid.js +99 -0
  33. package/es/grid-component/rc-table/GridEdit.d.ts +9 -0
  34. package/es/grid-component/rc-table/GridEdit.js +706 -0
  35. package/es/grid-component/type.d.ts +225 -0
  36. package/es/grid-component/useContext.d.ts +27 -0
  37. package/es/grid-component/useContext.js +4 -0
  38. package/es/index.d.ts +1 -2
  39. package/es/index.js +2 -2
  40. package/es/table-grid/styles.scss +551 -0
  41. package/lib/{CheckboxFilter.d.ts → grid-component/CheckboxFilter.d.ts} +1 -1
  42. package/lib/{CheckboxFilter.js → grid-component/CheckboxFilter.js} +11 -14
  43. package/lib/grid-component/ColumnsChoose.d.ts +9 -0
  44. package/lib/{ColumnsChoose.js → grid-component/ColumnsChoose.js} +66 -70
  45. package/lib/grid-component/EditableCell.d.ts +19 -0
  46. package/lib/grid-component/EditableCell.js +844 -0
  47. package/lib/{FilterSearch.js → grid-component/FilterSearch.js} +3 -3
  48. package/lib/grid-component/GridStyle.d.ts +4 -0
  49. package/lib/grid-component/GridStyle.js +12 -0
  50. package/lib/grid-component/InternalTable.d.ts +6 -0
  51. package/lib/grid-component/InternalTable.js +292 -0
  52. package/lib/grid-component/LoadingSpinner.d.ts +3 -0
  53. package/lib/grid-component/LoadingSpinner.js +29 -0
  54. package/lib/grid-component/Message/Message.d.ts +2 -0
  55. package/lib/grid-component/Message/Message.js +25 -0
  56. package/lib/grid-component/Message/index.d.ts +1 -0
  57. package/lib/grid-component/Message/index.js +16 -0
  58. package/lib/grid-component/TableGrid.d.ts +10 -0
  59. package/lib/grid-component/TableGrid.js +382 -0
  60. package/lib/grid-component/async-table-select/index.d.ts +9 -0
  61. package/lib/grid-component/async-table-select/index.js +46 -0
  62. package/lib/{hooks → grid-component/hooks}/constant.d.ts +14 -0
  63. package/lib/{hooks → grid-component/hooks}/constant.js +18 -3
  64. package/lib/grid-component/hooks/useColumns/index.d.ts +6 -0
  65. package/lib/grid-component/hooks/useColumns/index.js +435 -0
  66. package/lib/grid-component/hooks/utils.d.ts +35 -0
  67. package/lib/{hooks → grid-component/hooks}/utils.js +164 -22
  68. package/lib/grid-component/index.d.ts +2 -0
  69. package/lib/grid-component/index.js +9 -0
  70. package/lib/grid-component/rc-table/Grid.d.ts +8 -0
  71. package/lib/grid-component/rc-table/Grid.js +108 -0
  72. package/lib/grid-component/rc-table/GridEdit.d.ts +9 -0
  73. package/lib/grid-component/rc-table/GridEdit.js +715 -0
  74. package/lib/grid-component/type.d.ts +225 -0
  75. package/lib/grid-component/useContext.d.ts +27 -0
  76. package/lib/grid-component/useContext.js +10 -0
  77. package/lib/index.d.ts +1 -2
  78. package/lib/index.js +7 -3
  79. package/lib/table-grid/styles.scss +551 -0
  80. package/package.json +17 -6
  81. package/es/ColumnsChoose.d.ts +0 -10
  82. package/es/GridTable.d.ts +0 -7
  83. package/es/GridTable.js +0 -927
  84. package/es/hooks/useColumns/index.d.ts +0 -2
  85. package/es/hooks/useColumns/index.js +0 -25
  86. package/es/hooks/utils.d.ts +0 -18
  87. package/es/styles.scss +0 -30
  88. package/es/type.d.ts +0 -88
  89. package/lib/ColumnsChoose.d.ts +0 -10
  90. package/lib/GridTable.d.ts +0 -7
  91. package/lib/GridTable.js +0 -936
  92. package/lib/hooks/useColumns/index.d.ts +0 -2
  93. package/lib/hooks/useColumns/index.js +0 -31
  94. package/lib/hooks/utils.d.ts +0 -18
  95. package/lib/styles.scss +0 -30
  96. package/lib/type.d.ts +0 -88
  97. /package/es/{ContextMenu.d.ts → grid-component/ContextMenu.d.ts} +0 -0
  98. /package/es/{ContextMenu.js → grid-component/ContextMenu.js} +0 -0
  99. /package/es/{FilterSearch.d.ts → grid-component/FilterSearch.d.ts} +0 -0
  100. /package/es/{hooks → grid-component/hooks}/index.d.ts +0 -0
  101. /package/es/{hooks → grid-component/hooks}/index.js +0 -0
  102. /package/es/{hooks → grid-component/hooks}/useIsOverflow.d.ts +0 -0
  103. /package/es/{hooks → grid-component/hooks}/useIsOverflow.js +0 -0
  104. /package/es/{hooks → grid-component/hooks}/useOnClickOutside.d.ts +0 -0
  105. /package/es/{hooks → grid-component/hooks}/useOnClickOutside.js +0 -0
  106. /package/es/{type.js → grid-component/type.js} +0 -0
  107. /package/lib/{ContextMenu.d.ts → grid-component/ContextMenu.d.ts} +0 -0
  108. /package/lib/{ContextMenu.js → grid-component/ContextMenu.js} +0 -0
  109. /package/lib/{FilterSearch.d.ts → grid-component/FilterSearch.d.ts} +0 -0
  110. /package/lib/{hooks → grid-component/hooks}/index.d.ts +0 -0
  111. /package/lib/{hooks → grid-component/hooks}/index.js +0 -0
  112. /package/lib/{hooks → grid-component/hooks}/useIsOverflow.d.ts +0 -0
  113. /package/lib/{hooks → grid-component/hooks}/useIsOverflow.js +0 -0
  114. /package/lib/{hooks → grid-component/hooks}/useOnClickOutside.d.ts +0 -0
  115. /package/lib/{hooks → grid-component/hooks}/useOnClickOutside.js +0 -0
  116. /package/lib/{type.js → grid-component/type.js} +0 -0
@@ -0,0 +1,422 @@
1
+ // import * as React from 'react'
2
+
3
+ import { checkDecimalSeparator, checkThousandSeparator, convertDateToDayjs, convertDayjsToDate, getDatepickerFormat, getDateString, getTypeFilter, isColor, isEmpty } from "../utils";
4
+ import { NumericFormat, numericFormatter } from "react-numeric-component";
5
+ import dayjs from "dayjs";
6
+ import moment from "moment/moment";
7
+ import React, { Fragment } from "react";
8
+ import { DatePicker, Input, Select } from "rc-master-ui";
9
+ import CheckboxFilter from "../../CheckboxFilter";
10
+ const {
11
+ RangePicker
12
+ } = DatePicker;
13
+ export function flatColumns(columns, parentKey = 'key') {
14
+ // @ts-ignore
15
+ return columns.filter(column => column && typeof column === 'object').reduce((list, column, index) => {
16
+ const {
17
+ fixed
18
+ } = column;
19
+ // Convert `fixed='true'` to `fixed='left'` instead
20
+ const parsedFixed = fixed === true ? 'left' : fixed;
21
+ const mergedKey = `${parentKey}-${index}`;
22
+ const subColumns = column.children;
23
+ if (subColumns && subColumns.length > 0) {
24
+ return [...list, ...flatColumns(subColumns, mergedKey).map(subColum => ({
25
+ fixed: parsedFixed,
26
+ ...subColum
27
+ }))];
28
+ }
29
+ return [...list, {
30
+ key: mergedKey,
31
+ ...column,
32
+ fixed: parsedFixed
33
+ }];
34
+ }, []);
35
+ }
36
+ export const getValueCell = (column, value, format) => {
37
+ switch (column?.type) {
38
+ case 'number':
39
+ const thousandSeparator = column?.format?.thousandSeparator ? column?.format?.thousandSeparator : format?.thousandSeparator;
40
+ const decimalSeparator = column?.format?.decimalSeparator ? column?.format?.decimalSeparator : format?.decimalSeparator;
41
+ const dec = column?.format?.decimalScale || column?.format?.decimalScale === 0 ? column?.format?.decimalScale : format?.decimalScale;
42
+ const content = !isEmpty(value) ? dec || dec === 0 ? parseFloat(Number(value).toFixed(dec)).toString() : value.toString() : '0';
43
+ const numericFormatProps = {
44
+ thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
45
+ decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
46
+ allowNegative: (column?.format?.allowNegative ? column?.format?.allowNegative : format?.allowNegative) ?? true,
47
+ prefix: column?.format?.prefix ? column?.format?.prefix : format?.prefix,
48
+ suffix: column?.format?.suffix ? column?.format?.suffix : format?.suffix,
49
+ decimalScale: column?.format?.decimalScale || column?.format?.decimalScale === 0 ? column?.format?.decimalScale : format?.decimalScale,
50
+ fixedDecimalScale: (column?.format?.fixedDecimalScale ? column?.format?.fixedDecimalScale : format?.fixedDecimalScale) ?? false
51
+ };
52
+ return !isEmpty(content) ? numericFormatter(content, numericFormatProps) : '';
53
+ case 'date':
54
+ return value ? dayjs(value).format(column?.format?.dateFormat ?? format?.dateFormat ?? 'DD/MM/YYYY') : '';
55
+ case 'time':
56
+ return value ? value : '';
57
+ case 'year':
58
+ const year = value ? moment(value).format('yyyy') : '';
59
+ return /*#__PURE__*/React.createElement(Fragment, null, year);
60
+ case 'datetime':
61
+ return value ? moment(value).format(column?.format?.datetimeFormat ?? format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm') : '';
62
+ case 'boolean':
63
+ return value ? 'true' : 'false';
64
+ case 'color':
65
+ return /*#__PURE__*/React.createElement(Fragment, null, isColor(value) ? /*#__PURE__*/React.createElement("div", {
66
+ className: 'w-100 h-100',
67
+ style: {
68
+ backgroundColor: value,
69
+ border: '1px solid #f0f0f0'
70
+ }
71
+ }) : '');
72
+ case 'checkbox':
73
+ return /*#__PURE__*/React.createElement(Input, {
74
+ checked: !!content,
75
+ readOnly: true,
76
+ type: "checkbox"
77
+ });
78
+ case 'file':
79
+ 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(", ") : '';
80
+ return value ? nameFile : '';
81
+ default:
82
+ if (Array.isArray(value)) {
83
+ return value.join(', ');
84
+ }
85
+ return value;
86
+ }
87
+ };
88
+ export const renderContent = (column, value, record, index, format) => {
89
+ const cellValue = value instanceof Date ? getDateString(column, value) : value;
90
+ const content = getValueCell(column, cellValue, format);
91
+ return /*#__PURE__*/React.createElement(Fragment, null, column?.template ? typeof column.template === "function" ? column.template(value, record, index) : column.template : content);
92
+ };
93
+ export const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, dataSourceFilter, buddhistLocale) => {
94
+ const type = getTypeFilter(column);
95
+ const dateFormat = getDatepickerFormat(column?.typeFilter ?? column?.type, column) ?? 'DD/MM/YYYY';
96
+ const dateRangeFormat = getDatepickerFormat(column?.type, column) ?? 'DD/MM/YYYY';
97
+ const find = dataSourceFilter?.find(it => it.key === column?.key);
98
+ const options = find ? find.data : [];
99
+ switch (type) {
100
+ case 'Number':
101
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
102
+ className: 'mb-1'
103
+ }, /*#__PURE__*/React.createElement(NumericFormat, {
104
+ value: selectedKeys[0]
105
+ // thousandSeparator={checkThousandSeparator(thousandSeparator, decimalSeparator)}
106
+ // decimalSeparator={checkDecimalSeparator(thousandSeparator, decimalSeparator)}
107
+ // allowNegative={col.format && col.format.allowNegative === true}
108
+ ,
109
+ allowNegative: true,
110
+ customInput: Input,
111
+ className: ' rounded-0 input-element form-control',
112
+ onValueChange: values => {
113
+ // onChangeValueFilter(type, values.floatValue)
114
+ setSelectedKeys(values.floatValue || values.floatValue === 0 ? [values.floatValue] : []);
115
+ }
116
+ }))));
117
+ case 'NumberRange':
118
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
119
+ className: 'mb-1 d-flex flex-column gap-1'
120
+ }, /*#__PURE__*/React.createElement("div", {
121
+ style: {
122
+ marginBottom: 8
123
+ }
124
+ }, /*#__PURE__*/React.createElement(NumericFormat, {
125
+ value: selectedKeys[0]
126
+ // thousandSeparator={checkThousandSeparator(thousandSeparator, decimalSeparator)}
127
+ // decimalSeparator={checkDecimalSeparator(thousandSeparator, decimalSeparator)}
128
+ ,
129
+ allowNegative: true,
130
+ customInput: Input,
131
+ className: ' rounded-0 input-element form-control'
132
+ // onValueChange={(values: any) => {
133
+ // onChangeValueFilter(type, values.floatValue, 'min')
134
+ // }}
135
+ ,
136
+ placeholder: 'Min',
137
+ autoFocus: true
138
+ })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(NumericFormat, {
139
+ value: selectedKeys[1]
140
+ // thousandSeparator={checkThousandSeparator(thousandSeparator, decimalSeparator)}
141
+ // decimalSeparator={checkDecimalSeparator(thousandSeparator, decimalSeparator)}
142
+ ,
143
+ allowNegative: true,
144
+ customInput: Input,
145
+ className: ' rounded-0 input-element form-control',
146
+ onValueChange: () => {
147
+ // onChangeValueFilter(type, values.floatValue, 'max')
148
+ },
149
+ placeholder: 'Max'
150
+ })))));
151
+ case 'Date':
152
+ const dateValue = selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateFormat) : null;
153
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
154
+ className: 'mb-1'
155
+ }, /*#__PURE__*/React.createElement(DatePicker, {
156
+ format: {
157
+ format: dateFormat,
158
+ type: 'mask'
159
+ },
160
+ locale: buddhistLocale,
161
+ style: {
162
+ width: '100%',
163
+ height: '100%'
164
+ },
165
+ value: dateValue,
166
+ defaultValue: dateValue,
167
+ placeholder: column?.placeholder,
168
+ onChange: (date, dateString) => {
169
+ const newDateValue = dateString ? moment(convertDayjsToDate(dateString, dateFormat)).format() : null;
170
+ setSelectedKeys(newDateValue ? [newDateValue] : []);
171
+ }
172
+ }))));
173
+ case 'DateRange':
174
+ const dateRangeValue = [selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateRangeFormat) : '', selectedKeys[1] ? convertDateToDayjs(new Date(selectedKeys[1]), dateRangeFormat) : ''];
175
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
176
+ className: 'mb-1'
177
+ }, /*#__PURE__*/React.createElement(RangePicker, {
178
+ format: {
179
+ format: dateRangeFormat,
180
+ type: 'mask'
181
+ }
182
+ // defaultValue={dateRangeValue}
183
+ ,
184
+ value: dateRangeValue,
185
+ placeholder: ['Ngày bắt đầu', 'Ngày kết thúc'],
186
+ popupStyle: {
187
+ zIndex: 9999
188
+ },
189
+ onChange: (value, dateString) => {
190
+ const newDateRangeValue = dateString[0] ? [dateString[0] ? moment(convertDayjsToDate(dateString[0], dateRangeFormat)).format() : '', dateString[1] ? moment(convertDayjsToDate(dateString[1], dateRangeFormat)).format() : ''] : '';
191
+
192
+ // setSelectedKeys(newDateValue ? [newDateValue] : [])
193
+ setSelectedKeys(newDateRangeValue);
194
+ },
195
+ style: {
196
+ width: '100%'
197
+ }
198
+ // popupClassName={'adv-popup-container'}
199
+ // getPopupContainer={() => menuRef.current}
200
+ }))));
201
+ case 'Week':
202
+ const weekValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], dateFormat) : null;
203
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
204
+ className: 'mb-1'
205
+ }, /*#__PURE__*/React.createElement(DatePicker, {
206
+ format: {
207
+ format: dateFormat,
208
+ type: 'mask'
209
+ },
210
+ picker: 'week',
211
+ locale: buddhistLocale,
212
+ style: {
213
+ width: '100%',
214
+ height: '100%'
215
+ },
216
+ value: weekValue,
217
+ defaultValue: weekValue,
218
+ placeholder: column?.placeholder,
219
+ onChange: (date, dateString) => {
220
+ const newDateValue = dateString ?? null;
221
+ setSelectedKeys(newDateValue ? [newDateValue] : []);
222
+ }
223
+ }))));
224
+ case 'Month':
225
+ const monthValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], dateFormat) : null;
226
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
227
+ className: 'mb-1'
228
+ }, /*#__PURE__*/React.createElement(DatePicker, {
229
+ format: {
230
+ format: dateFormat,
231
+ type: 'mask'
232
+ },
233
+ picker: 'month',
234
+ locale: buddhistLocale,
235
+ style: {
236
+ width: '100%',
237
+ height: '100%'
238
+ },
239
+ value: monthValue,
240
+ defaultValue: monthValue,
241
+ placeholder: column?.placeholder,
242
+ onChange: (date, dateString) => {
243
+ const newDateValue = dateString ?? null;
244
+ setSelectedKeys(newDateValue ? [newDateValue] : []);
245
+ }
246
+ })));
247
+
248
+ // case 'Quarter':
249
+ //
250
+ // // const monthValue = selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateFormat) : null
251
+ //
252
+ // const pickerFormat = getDatepickerFormat(getEditType(col) as IEditType, col)
253
+ // const pickerValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], pickerFormat) : null
254
+ //
255
+ // return (
256
+ // <Fragment>
257
+ // <div>
258
+ //
259
+ //
260
+ // <div className={'mb-1'}>
261
+ //
262
+ // <DatePicker
263
+ // format={{
264
+ // format: dateFormat,
265
+ // type: 'mask'
266
+ // }}
267
+ // locale={buddhistLocale}
268
+ // style={{width: '100%', height: '100%'}}
269
+ // value={pickerValue}
270
+ // defaultValue={pickerValue}
271
+ // placeholder={column.placeholder}
272
+ // onChange={(date, dateString) => {
273
+ // const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
274
+ // setSelectedKeys(newDateValue ? [newDateValue] : [])
275
+ //
276
+ // }}
277
+ //
278
+ // />
279
+ // </div>
280
+ //
281
+ //
282
+ // </div>
283
+ // </Fragment>
284
+ // )
285
+ //
286
+ // case 'Year':
287
+ //
288
+ // // const monthValue = selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateFormat) : null
289
+ //
290
+ // const pickerFormat = getDatepickerFormat(getEditType(col) as IEditType, col)
291
+ // const pickerValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], pickerFormat) : null
292
+ //
293
+ // return (
294
+ // <Fragment>
295
+ // <div>
296
+ //
297
+ //
298
+ // <div className={'mb-1'}>
299
+ //
300
+ // <DatePicker
301
+ // format={{
302
+ // format: dateFormat,
303
+ // type: 'mask'
304
+ // }}
305
+ // locale={buddhistLocale}
306
+ // style={{width: '100%', height: '100%'}}
307
+ // value={pickerValue}
308
+ // defaultValue={pickerValue}
309
+ // placeholder={column.placeholder}
310
+ // onChange={(date, dateString) => {
311
+ // const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
312
+ // setSelectedKeys(newDateValue ? [newDateValue] : [])
313
+ //
314
+ // }}
315
+ //
316
+ // />
317
+ // </div>
318
+ //
319
+ //
320
+ // </div>
321
+ // </Fragment>
322
+ // )
323
+
324
+ case 'Dropdown':
325
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
326
+ className: 'mb-1'
327
+ }, /*#__PURE__*/React.createElement(Select
328
+ // options={translateOption(numberOperator, t)}
329
+ , {
330
+ options: options,
331
+ style: {
332
+ width: '100%',
333
+ marginBottom: 8
334
+ },
335
+ value: selectedKeys[0],
336
+ onChange: val => {
337
+ // setOperatorKey(val)
338
+ setSelectedKeys(val ? [val] : []);
339
+ },
340
+ showSearch: true,
341
+ allowClear: true
342
+ }))));
343
+
344
+ // case 'DropTree':
345
+ // return (
346
+ // <Fragment>
347
+ // <div>
348
+ // {col.filterOption && col.filterOption.showOperator === false ? (
349
+ // ''
350
+ // ) : (
351
+ // <div className={'mb-1'}>
352
+ // <Select
353
+ // options={translateOption(numberOperator, t)}
354
+ // // options={t ? numberOperator.map((it: any) => ({...it, label: t(it.label)})) : numberOperator}
355
+ //
356
+ // classNamePrefix='select'
357
+ // className={`react-select`}
358
+ // value={translateOption(numberOperator, t).find(
359
+ // ope => ope.value === (operator ? operator : getDefaultOperator(col))
360
+ // )}
361
+ // onChange={(val: any) => {
362
+ // setCurrentFilter((prevState: any) => ({ ...prevState, operator: val.value }))
363
+ // }}
364
+ // />
365
+ // </div>
366
+ // )}
367
+ //
368
+ // <div className={'mb-1'}>
369
+ // <Input
370
+ // placeholder={'Nhập giá trị'}
371
+ // value={value}
372
+ // onChange={(val: any) => {
373
+ // onChangeValueFilter(type, val.value)
374
+ // }}
375
+ // />
376
+ // </div>
377
+ //
378
+ // <div className={'d-flex justify-content-end'}>
379
+ // <Button color='flat-primary' className={'me-1 be-button'} onClick={(e: any) => handleOnFilter(e)}>
380
+ // {t ? t('Filter') : 'Filter'}
381
+ // </Button>
382
+ // <Button color='flat-secondary' className={'be-button'} onClick={(e: any) => handleClearFilter(e)}>
383
+ // {t ? t('Delete') : 'Delete'}
384
+ // </Button>
385
+ // </div>
386
+ // </div>
387
+ // </Fragment>
388
+ // )
389
+ //
390
+ case 'Checkbox':
391
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
392
+ className: 'mb-1'
393
+ }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(CheckboxFilter
394
+ // column={column}
395
+ , {
396
+ locale: {
397
+ filterTitle: 'Chọn tất cả',
398
+ filterCheckall: 'Chọn tất cả'
399
+ },
400
+ selectedKeys: selectedKeys,
401
+ onSelect: setSelectedKeys,
402
+ options: options,
403
+ filterMultiple: true,
404
+ open: visible,
405
+ searchValue: searchValue,
406
+ setSearchValue: setSearchValue
407
+ })))));
408
+ case 'Text':
409
+ default:
410
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
411
+ className: 'mb-1'
412
+ }, /*#__PURE__*/React.createElement(Input, {
413
+ placeholder: `Search ${column?.dataIndex}`,
414
+ value: selectedKeys[0],
415
+ onChange: e => setSelectedKeys(e.target.value ? [e.target.value] : [])
416
+ // onPressEnter={() => handleSearch(selectedKeys as string[], confirm)}
417
+ ,
418
+ onPressEnter: () => confirm(),
419
+ allowClear: true
420
+ }))));
421
+ }
422
+ };
@@ -0,0 +1,35 @@
1
+ import type * as React from "react";
2
+ import dayjs from "dayjs";
3
+ import type { EditType, IColumnType, TypeFilter } from "rc-master-ui";
4
+ import type { ColumnEditType, ColumnsType, ColumnTable } from "../type";
5
+ import type { SelectionSettings } from "../type";
6
+ import type { AnyObject } from "../type";
7
+ export declare const newGuid: () => any;
8
+ export declare const sumDataByField: (data: any[], field: string) => any;
9
+ export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
10
+ export declare const checkDecimalSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
11
+ export declare const isEmpty: (d: any) => boolean;
12
+ export declare const isNullOrUndefined: (d: any) => boolean;
13
+ export declare const convertDayjsToDate: (dateString: string, format?: string) => Date;
14
+ export declare const convertDateToDayjs: (date: Date | undefined, format?: string) => dayjs.Dayjs;
15
+ export declare const isNameColor: (strColor: string) => boolean;
16
+ export declare const isColor: (value: string) => boolean;
17
+ export declare const getAllVisibleKeys: (columns: any[]) => any[];
18
+ export declare const getVisibleColumnKeys: (columns: any[]) => string[];
19
+ export declare function getHiddenParentKeys(columns: any[], parentKeys?: string[]): string[];
20
+ export declare const updateColumns: (columns: any[], includes: string[]) => any[];
21
+ export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, col: ColumnTable<any>) => string;
22
+ export declare const customWeekStartEndFormat: (value: any, weekFormat: string) => string;
23
+ export declare const getTypeFilter: (col: ColumnTable<any>) => TypeFilter;
24
+ export declare const updateArrayByKey: (arr: any[], element: any, key: string) => any[];
25
+ export declare const getDateString: <T>(column: ColumnTable<T>, value: any) => string;
26
+ export declare const getEditType: <T>(column: ColumnEditType<T>, rowData?: any) => EditType | ((rowData?: any) => EditType);
27
+ export declare const isDisable: <T>(column: ColumnEditType<T>, rowData?: any) => boolean;
28
+ export declare const checkFieldKey: (key: string | undefined) => string;
29
+ export declare const convertLabelToTitle: (data: any[]) => any[];
30
+ export declare const convertArrayWithIndent: (inputArray: any[], parentIndent?: number) => any[];
31
+ export declare const getTemplate: (template: any) => React.ReactNode | React.ReactElement;
32
+ export declare const totalFixedWidth: <T>(columns: ColumnsType<T>, type: 'left' | 'right', selectionSettings?: SelectionSettings) => number;
33
+ export declare const isObjEmpty: (obj: any) => boolean;
34
+ export declare const getColumnsVisible: <T>(columns: ColumnsType<T>, index: number) => import("../type").ColumnType<T>[];
35
+ export declare const updateData: <Record_1 = AnyObject>(initData: Record_1[], rows: Record_1[], key: keyof Record_1) => Record_1[];
@@ -1,4 +1,13 @@
1
1
  import dayjs from "dayjs";
2
+ import moment from "moment/moment";
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ export const newGuid = () => {
5
+ for (let i = 0; i < 20; i++) {
6
+ // @ts-ignore
7
+ // const id = crypto.randomUUID()
8
+ return uuidv4();
9
+ }
10
+ };
2
11
  export const sumDataByField = (data, field) => {
3
12
  if (data && data.length > 0) {
4
13
  return data.reduce((accumulator, currentValue) => {
@@ -43,16 +52,10 @@ export const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
43
52
  }
44
53
  };
45
54
  export const isEmpty = d => {
46
- if (d === null || d === undefined || d === '') {
47
- return true;
48
- }
49
- return false;
55
+ return d === null || d === undefined || d === '';
50
56
  };
51
57
  export const isNullOrUndefined = d => {
52
- if (d === null || d === undefined) {
53
- return true;
54
- }
55
- return false;
58
+ return d === null || d === undefined;
56
59
  };
57
60
  export const convertDayjsToDate = (dateString, format) => {
58
61
  const dayjsDate = dayjs(dateString, format); // Parse using the provided format
@@ -101,8 +104,7 @@ export const getAllVisibleKeys = columns => {
101
104
  export const getVisibleColumnKeys = columns => {
102
105
  const allKeys = getAllVisibleKeys(columns);
103
106
  const allParentKeys = getHiddenParentKeys(columns);
104
- const rs = allKeys.filter(item => !allParentKeys.includes(item));
105
- return rs;
107
+ return allKeys.filter(item => !allParentKeys.includes(item));
106
108
  };
107
109
  export function getHiddenParentKeys(columns, parentKeys = []) {
108
110
  const hiddenParents = new Set();
@@ -126,15 +128,14 @@ export const updateColumns = (columns, includes) => {
126
128
  ...column
127
129
  };
128
130
  let hasVisibleChild = false;
131
+ if (!column.key && !column.dataIndex) {
132
+ return column;
133
+ }
129
134
  if (newColumn.children) {
130
135
  newColumn.children = updateColumns(newColumn.children, includes);
131
136
  hasVisibleChild = newColumn.children.some(child => !child.hidden);
132
137
  }
133
- if (newColumn.key && !includes.includes(newColumn.key)) {
134
- newColumn.hidden = true;
135
- } else {
136
- newColumn.hidden = false;
137
- }
138
+ newColumn.hidden = newColumn.key && !includes.includes(newColumn.key);
138
139
  if (newColumn.children && newColumn.children.length > 0) {
139
140
  newColumn.hidden = !hasVisibleChild;
140
141
  }
@@ -160,14 +161,17 @@ export const getDatepickerFormat = (type, col) => {
160
161
  case "time":
161
162
  return col.format?.timeFormat ? col.format?.timeFormat : 'HH:mm';
162
163
  default:
163
- return undefined;
164
+ return 'DD/MM/YYYY';
164
165
  }
165
166
  };
167
+ export const customWeekStartEndFormat = (value, weekFormat) => {
168
+ return `${dayjs(value).startOf('week').format(weekFormat)} ~ ${dayjs(value).endOf('week').format(weekFormat)}`;
169
+ };
166
170
  export const getTypeFilter = col => {
167
- if (col.typeFilter) {
171
+ if (col?.typeFilter) {
168
172
  return col.typeFilter;
169
173
  }
170
- const type = col.type ?? '';
174
+ const type = col?.type ?? 'Text';
171
175
  switch (type) {
172
176
  case "number":
173
177
  return 'Number';
@@ -181,7 +185,7 @@ export const getTypeFilter = col => {
181
185
  return 'Checkbox';
182
186
 
183
187
  // case "week": return ''
184
- // case "month": return col.format?.monthFormat ? col.format?.monthFormat : 'MM/YYYY'
188
+ // case "month": return 'Month'
185
189
  // case "quarter": return col.format?.dateFormat ? col.format?.dateFormat : 'DD/MM/YYYY'
186
190
  // case "year": return col.format?.yearFormat ? col.format?.yearFormat : 'YYYY'
187
191
  // case "time": return col.format?.timeFormat ? col.format?.timeFormat : 'HH:mm'
@@ -189,4 +193,128 @@ export const getTypeFilter = col => {
189
193
  default:
190
194
  return 'Text';
191
195
  }
196
+ };
197
+ export const updateArrayByKey = (arr, element, key) => {
198
+ if (arr) {
199
+ return arr.map(item => {
200
+ if (item[key] === element[key]) {
201
+ return {
202
+ ...item,
203
+ ...element
204
+ };
205
+ } else if (item.children && item.children.length > 0) {
206
+ item.children = updateArrayByKey(item.children, element, key);
207
+ }
208
+ return item;
209
+ });
210
+ } else {
211
+ return [];
212
+ }
213
+ };
214
+ export const getDateString = (column, value) => {
215
+ if (value instanceof Date) {
216
+ return moment(value).format();
217
+ }
218
+ return value;
219
+ };
220
+ export const getEditType = (column, rowData) => {
221
+ if (column && typeof column.editType === 'function') {
222
+ return column.editType(rowData);
223
+ }
224
+ return column.editType;
225
+ };
226
+ export const isDisable = (column, rowData) => {
227
+ if (column && typeof column?.disable === 'function') {
228
+ return column.disable(rowData);
229
+ }
230
+ return !!column?.disable;
231
+ };
232
+ export const checkFieldKey = key => {
233
+ if (key) {
234
+ return key;
235
+ } else {
236
+ return 'value';
237
+ }
238
+ };
239
+ export const convertLabelToTitle = data => {
240
+ return data.map(item => {
241
+ const {
242
+ label,
243
+ title,
244
+ value,
245
+ ...rest
246
+ } = item;
247
+ const newItem = {
248
+ ...rest,
249
+ value,
250
+ key: value,
251
+ title: title ? title : label
252
+ };
253
+ if (item.children) {
254
+ newItem.children = convertLabelToTitle(item.children);
255
+ }
256
+ return newItem;
257
+ });
258
+ };
259
+ export const convertArrayWithIndent = (inputArray, parentIndent = 0) => {
260
+ if (inputArray) {
261
+ return inputArray.map(item => {
262
+ const indent = parentIndent;
263
+ if (item.children && item.children.length > 0) {
264
+ item.children = convertArrayWithIndent(item.children, indent + 1);
265
+ }
266
+ return {
267
+ ...item,
268
+ indent,
269
+ rowId: item.rowId ? item.rowId : item.id ? item.id : newGuid()
270
+ };
271
+ });
272
+ } else {
273
+ return [];
274
+ }
275
+ };
276
+ export const getTemplate = template => {
277
+ if (template && typeof template === 'function') {
278
+ return template();
279
+ }
280
+ return template;
281
+ };
282
+ export const totalFixedWidth = (columns, type, selectionSettings) => {
283
+ const totalFixedLeftWidth = columns.filter(column => column.fixed === type) // Lọc các cột có fixed
284
+ .reduce((sum, column) => {
285
+ const width = typeof column.width === 'number' ? column.width : parseInt(column.width, 10) || 0; // Chuyển từ chuỗi sang số, nếu không hợp lệ thì lấy 0
286
+ return sum + width;
287
+ }, 0);
288
+ const selectColumnWidth = !selectionSettings?.mode ? 0.0000001 : typeof selectionSettings?.columnWidth === 'number' ? selectionSettings?.columnWidth : parseInt(selectionSettings?.columnWidth, 10) || 50;
289
+ return totalFixedLeftWidth + selectColumnWidth;
290
+ };
291
+ export const isObjEmpty = obj => {
292
+ if (isNullOrUndefined(obj)) {
293
+ return true;
294
+ } else {
295
+ return Object.keys(obj).length === 0;
296
+ }
297
+ };
298
+ export const getColumnsVisible = (columns, index) => {
299
+ const itemsBeforeIndex = columns.slice(0, index);
300
+ const itemsAfterIndex = columns.slice(index);
301
+ itemsAfterIndex.map(it => {
302
+ if (it.hidden !== false) {
303
+ itemsBeforeIndex.push(it);
304
+ }
305
+ });
306
+ return itemsBeforeIndex;
307
+ };
308
+ export const updateData = (initData, rows, key) => {
309
+ const updatedData = initData.map(item => {
310
+ const newData = rows.find(row => row[key] === item[key]);
311
+ return newData ? {
312
+ ...item,
313
+ ...newData
314
+ } : item;
315
+ });
316
+
317
+ // Thêm các phần tử mới chưa có trong initialData
318
+ const newRows = rows.filter(row => !initData.some(item => item[key] === row[key]));
319
+ return [...updatedData, ...newRows];
192
320
  };
@@ -0,0 +1,2 @@
1
+ import InternalTable from './InternalTable';
2
+ export default InternalTable;
@@ -0,0 +1,2 @@
1
+ import InternalTable from "./InternalTable";
2
+ export default InternalTable;