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
@@ -1,24 +1,26 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import React, { useContext } from "react";
3
- import { Button, DatePicker, Divider, Input, TimePicker } from "antd";
3
+ import { Button, ColorPicker, DatePicker, Divider, Input, TimePicker, Row, Col } from "antd";
4
4
  import { checkDecimalSeparator, checkThousandSeparator, checkFieldKey, convertArrayWithIndent, convertDateToDayjs,
5
5
  // convertDayjsToDate,
6
6
  convertLabelToTitle,
7
7
  // customWeekStartEndFormat,
8
- getDatepickerFormat, getTemplate, isDisable, isEmpty, isNullOrUndefined, customWeekStartEndFormat, convertDayjsToDate
8
+ getDatepickerFormat, getTemplate, isDisable, isEmpty, isNullOrUndefined, customWeekStartEndFormat, convertDayjsToDate, parseBooleanToValue, isColor, genPresets
9
9
  // convertDayjsToDate
10
10
  } from "./hooks";
11
11
  // import moment from "moment";
12
12
  // import dayjs from "dayjs";
13
13
  import { TreeSelect } from "antd";
14
- import { AsyncTableSelect } from "./async-table-select";
15
14
  import classNames from "classnames";
16
15
  import { NumericFormat } from "react-numeric-component";
17
16
  import { TableContext } from "./useContext";
18
17
  import dayjs from "dayjs";
19
18
  import moment from "moment";
20
19
  import { Controller } from "react-hook-form";
21
- import { Select } from "rc-master-ui";
20
+ import { Checkbox, Select } from "rc-master-ui";
21
+ import { AsyncSelect } from "./async-select";
22
+ import { AsyncTableSelect } from "./async-table-select";
23
+ import { cyan, green, red, blue } from '@ant-design/colors';
22
24
 
23
25
  // import moment from "moment";
24
26
 
@@ -52,56 +54,67 @@ const EditableCell = props => {
52
54
  format,
53
55
  control,
54
56
  getValues,
55
- handleCellChange
57
+ handleCellChange,
58
+ getRowKey
56
59
  } = useContext(TableContext);
57
60
  const datePickerRef = React.useRef(null);
58
61
  const dateTimePickerRef = React.useRef(null);
59
62
  // const timePickerRef = React.useRef(null);
60
63
 
61
- const isInvalid = false;
62
- const keySelect = checkFieldKey(column?.editSelectSettings?.fieldKey);
63
- const inputKey = column?.editSelectSettings?.inputKey;
64
- const options = column?.editSelectSettings?.validateOption ? column?.editSelectSettings?.validateOption(record, column.dataIndex) : column?.editSelectSettings?.options ? column?.editSelectSettings?.options : [];
65
- const optionsTree = column?.editSelectSettings?.validateOption ? convertArrayWithIndent(column?.editSelectSettings?.validateOption(record, column.dataIndex)) : column?.editSelectSettings?.options ? convertArrayWithIndent(column?.editSelectSettings?.options) : [];
66
64
  const inputNode = (value, onChange) => {
67
65
  const dateFormat = getDatepickerFormat(editType, column);
68
66
  const date = !isEmpty(value) ? convertDateToDayjs(new Date(value), dateFormat) : null;
69
67
  const maxDate = convertDateToDayjs(column.maxDate, dateFormat) ?? undefined;
70
68
  const minDate = convertDateToDayjs(column.minDate, dateFormat) ?? undefined;
69
+ const {
70
+ fieldValue,
71
+ columns: selectColumns,
72
+ isMulti,
73
+ selectMode,
74
+ menuWidth,
75
+ fieldNames,
76
+ toolbarItems,
77
+ filterOption,
78
+ inputKey,
79
+ toolbarClick,
80
+ loadOptions,
81
+ validateOption,
82
+ options: selectOptions
83
+ } = column.editSelectSettings || {};
84
+ const isInvalid = false;
85
+ const keySelect = checkFieldKey(column?.editSelectSettings?.fieldKey);
86
+ const options = validateOption ? validateOption(record, column.dataIndex) : selectOptions ?? [];
87
+ const optionsTree = validateOption ? convertArrayWithIndent(validateOption(record, column.dataIndex)) : selectOptions ? convertArrayWithIndent(selectOptions) : [];
71
88
  switch (editType) {
72
89
  case 'date':
73
- return /*#__PURE__*/React.createElement(DatePicker
74
- // id={`col${indexCol}-record${indexRow}`}
75
- , {
90
+ return /*#__PURE__*/React.createElement(DatePicker, {
76
91
  ref: datePickerRef,
77
92
  format: {
78
93
  format: dateFormat,
79
94
  type: 'mask'
80
95
  }
81
-
82
96
  // locale={buddhistLocale}
83
97
  ,
84
98
  style: {
85
99
  width: '100%',
86
100
  height: '100%'
87
101
  },
88
- value: date
89
- // defaultValue={date}
90
- ,
91
-
102
+ value: date,
92
103
  onBlur: () => {
93
104
  const formState = getValues();
94
105
  const itemState = getValues(dataIndex);
95
106
  // @ts-ignore
96
107
  const prevState = record[dataIndex];
97
108
  const newState = itemState;
109
+ const key = getRowKey?.(record, index);
98
110
  if (newState !== prevState) {
99
- // @ts-ignore
100
111
  handleCellChange?.({
101
- key: record[rowKey],
112
+ key: key,
113
+ field: column.field ?? column.dataIndex,
102
114
  record: formState,
103
115
  prevState,
104
116
  newState,
117
+ option: newState,
105
118
  type: 'blur'
106
119
  });
107
120
  }
@@ -130,12 +143,6 @@ const EditableCell = props => {
130
143
  popupClassName: 'be-popup-container'
131
144
  });
132
145
  case 'datetime':
133
- // const dateTimeFormat = getDatepickerFormat(editType, column)
134
- // // @ts-ignore
135
- // // const dateTimeValue = !isEmpty(record[column.dataIndex]) ? convertDateToDayjs(new Date(record[column.dataIndex]), dateTimeFormat) : null
136
- // const maxDateTime = convertDateToDayjs(column.maxDate, dateTimeFormat) ?? undefined
137
- // const minDateTime = convertDateToDayjs(column.minDate, dateTimeFormat) ?? undefined
138
-
139
146
  return /*#__PURE__*/React.createElement(DatePicker
140
147
  // id={`col${indexCol}-record${indexRow}`}
141
148
  , {
@@ -158,6 +165,7 @@ const EditableCell = props => {
158
165
  minDate: minDate,
159
166
  onChange: (newDate, dateString) => {
160
167
  const newDateValue = dateString ? moment(convertDayjsToDate(dateString, dateFormat)).format() : null;
168
+ // console.log('newDateValue', newDateValue)
161
169
  onChange(newDateValue);
162
170
  setTimeout(() => {
163
171
  // @ts-ignore
@@ -170,13 +178,15 @@ const EditableCell = props => {
170
178
  // @ts-ignore
171
179
  const prevState = record[dataIndex];
172
180
  const newState = itemState;
181
+ const key = getRowKey?.(record, index);
173
182
  if (prevState !== newState) {
174
- // @ts-ignore
175
183
  handleCellChange?.({
176
- key: record[rowKey],
184
+ key: key,
185
+ field: column.field ?? column.dataIndex,
177
186
  record: formState,
178
187
  prevState,
179
188
  newState,
189
+ option: newState,
180
190
  type: 'blur'
181
191
  });
182
192
  }
@@ -187,8 +197,6 @@ const EditableCell = props => {
187
197
  case 'quarter':
188
198
  case 'year':
189
199
  const pickerFormat = getDatepickerFormat(editType, column);
190
- // @ts-ignore
191
- // const dateValue = !isEmpty(record[column.dataIndex]) ? dayjs(record[column.key], pickerFormat) : null
192
200
  const maxDateValue1 = !isEmpty(column.maxDate) ? dayjs(column.maxDate, pickerFormat) : undefined;
193
201
  const minDateValue1 = !isEmpty(column.minDate) ? dayjs(column.minDate, pickerFormat) : undefined;
194
202
  return /*#__PURE__*/React.createElement(DatePicker, {
@@ -200,28 +208,16 @@ const EditableCell = props => {
200
208
  style: {
201
209
  width: '100%',
202
210
  height: '100%'
203
- }
204
- // defaultValue={dateValue}
205
- ,
211
+ },
206
212
  picker: editType,
207
213
  placeholder: column.placeholder,
208
214
  disabled: isDisable(column, record) ?? false,
209
215
  maxDate: maxDateValue1,
210
- minDate: minDateValue1
211
- // onChange={(dValue, dateString) => {
212
- // const newDateValue = dateString ? dateString : null
213
- //
214
- // // record[column.dataIndex] = newDateValue
215
- // // handleCellChange(newDateValue, newDateValue, record, col, indexRow, indexCol)
216
- // }}
217
- ,
216
+ minDate: minDateValue1,
218
217
  popupClassName: 'be-popup-container'
219
218
  });
220
219
  case 'week':
221
220
  const weekFormat = getDatepickerFormat(editType, column);
222
-
223
- // @ts-ignore
224
- // const weekValue = !isEmpty(record[column.dataIndex]) ? dayjs(record[column.dataIndex], weekFormat) : null
225
221
  const maxWeekValue = !isEmpty(column.maxDate) ? dayjs(column.maxDate, weekFormat) : undefined;
226
222
  const minWeekValue = !isEmpty(column.minDate) ? dayjs(column.minDate, weekFormat) : undefined;
227
223
  return /*#__PURE__*/React.createElement(DatePicker, {
@@ -229,21 +225,12 @@ const EditableCell = props => {
229
225
  style: {
230
226
  width: '100%',
231
227
  height: '100%'
232
- }
233
- // defaultValue={weekValue}
234
- ,
228
+ },
235
229
  picker: editType,
236
230
  placeholder: column.placeholder,
237
231
  disabled: isDisable(column, record) ?? false,
238
232
  maxDate: maxWeekValue,
239
- minDate: minWeekValue
240
- // onChange={(dateValue, dateString) => {
241
- // const newDateValue = dateString ? dateString : null
242
- //
243
- // record[column.dataIndex] = newDateValue
244
- // handleCellChange(newDateValue, newDateValue, record, col, indexRow, indexCol)
245
- // }}
246
- ,
233
+ minDate: minWeekValue,
247
234
  popupClassName: 'be-popup-container'
248
235
  });
249
236
  case 'time':
@@ -259,22 +246,10 @@ const EditableCell = props => {
259
246
  format: {
260
247
  format: timeFormat,
261
248
  type: 'mask'
262
- }
263
- // defaultValue={timeValue}
264
- ,
249
+ },
265
250
  maxDate: maxTime,
266
251
  minDate: minTime,
267
- disabled: isDisable(column, record) ?? false
268
- // onChange={(values: any, timeString) => {
269
- // const newTimeValue = timeString ? timeString : null
270
- // const newrecordData = {
271
- // ...record,
272
- // // [column.dataIndex]: newTimeValue
273
- // }
274
- //
275
- // // handleCellChange(newTimeValue, newTimeValue, newrecordData, col, indexRow, indexCol)
276
- // }}
277
- ,
252
+ disabled: isDisable(column, record) ?? false,
278
253
  style: {
279
254
  width: '100%',
280
255
  height: '100%'
@@ -282,7 +257,7 @@ const EditableCell = props => {
282
257
  popupClassName: 'be-popup-container'
283
258
  });
284
259
  case 'selectTable':
285
- const rr = column?.editSelectSettings && column?.editSelectSettings.columns ? column?.editSelectSettings.columns : [];
260
+ const rr = selectColumns ?? [];
286
261
  const columnsTable = rr.map(colSelect => {
287
262
  return {
288
263
  title: colSelect.headerTemplate ? colSelect.headerTemplate : t ? t(colSelect.headerText) : colSelect.headerText,
@@ -301,90 +276,69 @@ const EditableCell = props => {
301
276
  align: colSelect.textAlign
302
277
  };
303
278
  });
304
-
305
- // let valueSelectTable
306
- //
307
- // if (column?.editSelectSettings?.isMulti || column?.editSelectSettings?.selectMode === 'checkbox') {
308
- // valueSelectTable = (!isNullOrUndefined(record[column.dataIndex]) && Array.isArray(record[column.dataIndex]) && record[column.dataIndex]?.length > 0) ? options.filter((val: any) => record[column.dataIndex]?.includes(val[keySelect])) : undefined
309
- // } else {
310
- // valueSelectTable = record[column?.editSelectSettings?.fieldValue ?? column.dataIndex] ?? ''
311
- // }
312
- //
313
- // if (!valueSelectTable && column?.editSelectSettings?.defaultValue?.(record[column.dataIndex], record)) {
314
- // valueSelectTable = column?.editSelectSettings?.defaultValue(record[column.dataIndex], record)
315
- // }
316
- //
317
- //
318
-
319
- let valueSelectTable;
320
- if (column?.editSelectSettings?.isMulti || column?.editSelectSettings?.selectMode === 'checkbox') {
279
+ let valueSelectTable = value;
280
+ if (fieldValue) {
321
281
  // @ts-ignore
322
- valueSelectTable = !isNullOrUndefined(record[column.dataIndex]) && Array.isArray(record[column.dataIndex]) && record[column.dataIndex]?.length > 0 ? options.filter(val => record[column.dataIndex]?.includes(val[keySelect])) : undefined;
323
- } else {
324
- // const find = (!isNullOrUndefined(record[column.dataIndex]) && record[column.dataIndex] !== '') ? options?.find((val: any) => val[keySelect] === record[column?.editSelectSettings?.fieldValue ?? column.dataIndex]) : ''
325
- // @ts-ignore
326
- const find = !isNullOrUndefined(record[column.dataIndex]) && record[column.dataIndex] !== '' ? options?.find(val => val[keySelect] === record[column.dataIndex]) : '';
327
- valueSelectTable = find ? {
328
- label: find[column?.editSelectSettings?.inputKey ?? column.dataIndex],
329
- // @ts-ignore
330
- [column.dataIndex]: find[column?.editSelectSettings?.fieldValue ?? keySelect],
331
- key: find[column?.editSelectSettings?.fieldValue ?? keySelect],
332
- [keySelect]: find[column?.editSelectSettings?.fieldValue ?? keySelect]
333
- } : '';
282
+ valueSelectTable = record[fieldValue] ?? value;
334
283
  }
335
- // @ts-ignore
336
- if (!valueSelectTable && column?.editSelectSettings?.defaultValue?.(record[column.dataIndex], record)) {
284
+ if (isMulti || selectMode === 'checkbox') {
337
285
  // @ts-ignore
338
- valueSelectTable = column?.editSelectSettings?.defaultValue(record[column.dataIndex], record);
286
+ valueSelectTable = !isNullOrUndefined(record[column.dataIndex]) && Array.isArray(record[column.dataIndex]) && record[column.dataIndex]?.length > 0 ? options.filter(val => record[column.dataIndex]?.includes(val[keySelect])) : undefined;
339
287
  }
340
- return /*#__PURE__*/React.createElement(AsyncTableSelect, {
341
- id: `col${indexCol}-record${indexRow}`,
288
+ return /*#__PURE__*/React.createElement(AsyncTableSelect
289
+ // id={`col${indexCol}-record${indexRow}`}
290
+ , {
342
291
  columns: columnsTable,
343
292
  options: options,
344
- defaultOptions: options
345
- // onChange={(val: any, option) => {
346
- // // const newValue = val && (column?.editSelectSettings?.isMulti || column?.editSelectSettings?.selectMode === 'checkbox') ? (val?.map((item: any) => item[keySelect]) ?? []) : (val ? val[keySelect] : null)
347
- // const newrecordData = {
348
- // ...record,
349
- // [column.dataIndex]: val
350
- // }
351
- //
352
- // // handleCellChange(option, val, newrecordData, col, indexRow, indexCol)
353
- // }}
354
- ,
293
+ defaultOptions: options,
294
+ value: valueSelectTable,
295
+ onChange: (val, option) => {
296
+ onChange(val ?? '');
297
+ const formState = getValues();
298
+ // const itemState = getValues(dataIndex)
299
+ // @ts-ignore
300
+ const prevState = record[dataIndex];
301
+ const newState = val;
302
+ handleCellChange?.({
303
+ key: getRowKey?.(record, index),
304
+ field: column.field ?? column.dataIndex,
305
+ record: formState,
306
+ prevState,
307
+ newState,
308
+ option: option,
309
+ type: 'blur'
310
+ });
311
+ },
355
312
  showSearch: true,
356
- mode: column?.editSelectSettings?.isMulti || column?.editSelectSettings?.selectMode === 'checkbox' ? 'multiple' : undefined,
357
- focusToSelectAll: true,
358
- selectMode: column?.editSelectSettings?.selectMode,
313
+ mode: isMulti || selectMode === 'checkbox' ? 'multiple' : undefined,
314
+ valueSelectAble: true,
315
+ selectMode: selectMode,
359
316
  style: {
360
317
  width: '100%',
361
318
  height: '100%'
362
319
  },
363
- value: valueSelectTable,
364
320
  placeholder: t ? t('Select') : 'Select',
365
321
  allowClear: column.isClearable ?? false,
366
322
  maxTagCount: 'responsive',
367
323
  rowKey: keySelect,
368
- popupMatchSelectWidth: column?.editSelectSettings?.menuWidth ? column?.editSelectSettings?.menuWidth + 10 : undefined,
324
+ popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
369
325
  optionFilterProp: "label",
370
- popupClassName: 'be-popup-container'
371
- // onPaste={(e: any) => handleOnCellPaste(e, indexRow, indexCol)}
372
- ,
373
- loadOptions: column?.editSelectSettings?.loadOptions,
326
+ popupClassName: 'be-popup-container',
327
+ loadOptions: loadOptions,
374
328
  status: isInvalid ? 'error' : undefined,
375
329
  dropdownRender: menu => {
376
- if (column?.editSelectSettings?.toolbarItems && column?.editSelectSettings?.toolbarItems.length > 0) {
330
+ if (toolbarItems && toolbarItems.length > 0) {
377
331
  return /*#__PURE__*/React.createElement(React.Fragment, null, menu, /*#__PURE__*/React.createElement(Divider, {
378
332
  style: {
379
333
  margin: '8px 0'
380
334
  }
381
335
  }), /*#__PURE__*/React.createElement("div", {
382
336
  className: 'toolbar-control d-flex justify-content-end'
383
- }, column?.editSelectSettings?.toolbarItems.map(it => {
337
+ }, toolbarItems.map(it => {
384
338
  return /*#__PURE__*/React.createElement("div", {
385
339
  key: it.key,
386
340
  className: 'toolbar-item',
387
- onClick: () => column?.editSelectSettings?.toolbarClick?.({
341
+ onClick: () => toolbarClick?.({
388
342
  item: it,
389
343
  column
390
344
  })
@@ -396,89 +350,151 @@ const EditableCell = props => {
396
350
  return /*#__PURE__*/React.createElement(React.Fragment, null, " ", menu);
397
351
  }
398
352
  },
399
- filterOption: column?.editSelectSettings?.filterOption,
400
- fieldNames: column?.editSelectSettings?.fieldNames ? column?.editSelectSettings?.fieldNames : {
353
+ filterOption: filterOption,
354
+ fieldNames: fieldNames ? fieldNames : {
401
355
  value: keySelect,
402
- label: column?.editSelectSettings?.inputKey ?? 'label'
356
+ label: inputKey ?? 'label'
403
357
  }
404
358
  });
405
359
  case 'select':
406
- // let valueCustomSelect
407
- // if (column?.editSelectSettings?.isMulti) {
408
- // valueCustomSelect = (!isNullOrUndefined(record[column.dataIndex]) && record[column.dataIndex]?.length > 0) ? options.filter((val: any) => record[column.dataIndex]?.includes(val[keySelect])) : []
409
- // } else {
410
- //
411
- // valueCustomSelect = (!isNullOrUndefined(record[column.dataIndex]) && record[column.dataIndex] !== '') ? options?.find((val: any) => val[keySelect] === record[column.dataIndex]) : ''
412
- //
413
- // }
414
- //
415
- // if (!valueCustomSelect && column?.editSelectSettings?.defaultValue) {
416
- //
417
- // if (column?.editSelectSettings.fieldLabel && record[column?.editSelectSettings.fieldLabel]) {
418
- //
419
- // // valueCustomSelect = {...column?.editSelectSettings?.defaultValue(record), label: record[column?.editSelectSettings.fieldLabel]}
420
- // valueCustomSelect = {...column?.editSelectSettings?.defaultValue(record[column.dataIndex], record), label: record[column?.editSelectSettings.fieldLabel]}
421
- //
422
- // } else {
423
- // valueCustomSelect = column?.editSelectSettings?.defaultValue(record[column.dataIndex], record)
424
- //
425
- // }
426
- //
427
- // }
428
-
360
+ let valueSelect = value;
361
+ if (fieldValue) {
362
+ // @ts-ignore
363
+ valueSelect = record[fieldValue] ?? value;
364
+ }
365
+ if (isMulti || selectMode === 'checkbox') {
366
+ // @ts-ignore
367
+ valueSelect = !isNullOrUndefined(record[column.dataIndex]) && Array.isArray(record[column.dataIndex]) && record[column.dataIndex]?.length > 0 ? options.filter(val => record[column.dataIndex]?.includes(val[keySelect])) : undefined;
368
+ }
429
369
  return /*#__PURE__*/React.createElement(Select, {
430
- id: `col${indexCol}-record${indexRow}`,
370
+ options: options,
371
+ value: valueSelect,
372
+ onChange: (val, option) => {
373
+ onChange(val ?? '');
374
+ const formState = getValues();
375
+ // const itemState = getValues(dataIndex)
376
+ // @ts-ignore
377
+ const prevState = record[dataIndex];
378
+ const newState = val;
379
+ handleCellChange?.({
380
+ key: getRowKey?.(record, index),
381
+ field: column.field ?? column.dataIndex,
382
+ record: formState,
383
+ prevState,
384
+ newState,
385
+ option: option,
386
+ type: 'blur'
387
+ });
388
+ },
431
389
  showSearch: true,
432
- valueSelectAble: true
433
-
434
- // isMulti={column?.editSelectSettings?.isMulti}
435
- ,
390
+ mode: isMulti || selectMode === 'checkbox' ? 'multiple' : undefined,
391
+ valueSelectAble: true,
436
392
  style: {
437
- width: '100%'
393
+ width: '100%',
394
+ height: '100%'
438
395
  },
439
- value: value
440
- // options={options}
441
- ,
442
- options: [{
443
- value: 'jack',
444
- label: 'Jack'
445
- }, {
446
- value: 'lucy',
447
- label: 'Lucy'
448
- }, {
449
- value: 'Yiminghe',
450
- label: 'yiminghe'
451
- }, {
452
- value: 'disabled',
453
- label: 'Disabled',
454
- disabled: true
455
- }],
456
396
  placeholder: t ? t('Select') : 'Select',
457
- onChange: (val, item) => {
458
- console.log('item', item);
459
- onChange(val);
460
- },
461
- onBlur: () => {
397
+ allowClear: column.isClearable ?? false,
398
+ maxTagCount: 'responsive',
399
+ popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
400
+ optionFilterProp: "label",
401
+ popupClassName: 'be-popup-container',
402
+ status: isInvalid ? 'error' : undefined,
403
+ filterOption: filterOption,
404
+ fieldNames: fieldNames ? fieldNames : {
405
+ value: keySelect,
406
+ label: inputKey ?? 'label'
407
+ }
408
+ });
409
+ case 'asyncSelect':
410
+ let valueAsyncSelect = value;
411
+ if (fieldValue) {
412
+ // @ts-ignore
413
+ valueAsyncSelect = record[fieldValue] ?? value;
414
+ }
415
+ if (isMulti || selectMode === 'checkbox') {
416
+ // @ts-ignore
417
+ valueAsyncSelect = !isNullOrUndefined(record[column.dataIndex]) && Array.isArray(record[column.dataIndex]) && record[column.dataIndex]?.length > 0 ? options.filter(val => record[column.dataIndex]?.includes(val[keySelect])) : undefined;
418
+ }
419
+ return /*#__PURE__*/React.createElement(AsyncSelect, {
420
+ options: options,
421
+ defaultOptions: options,
422
+ value: valueAsyncSelect,
423
+ onChange: (val, option) => {
424
+ onChange(val ?? '');
462
425
  const formState = getValues();
463
426
  // const itemState = getValues(dataIndex)
464
-
465
427
  // @ts-ignore
466
428
  const prevState = record[dataIndex];
467
- // const newState = value
468
-
469
- // console.log('prevState', prevState)
470
- // console.log('newState', newState)
471
- // console.log('itemState', itemState)
472
- if (value !== prevState) {
473
- // @ts-ignore
474
- handleCellChange?.({
475
- key: record[rowKey],
476
- record: formState,
477
- type: 'blur'
478
- });
479
- }
429
+ const newState = val;
430
+ handleCellChange?.({
431
+ key: getRowKey?.(record, index),
432
+ field: column.field ?? column.dataIndex,
433
+ record: formState,
434
+ prevState,
435
+ newState,
436
+ option: option,
437
+ type: 'blur'
438
+ });
480
439
  },
481
- popupClassName: 'be-popup-container'
440
+ showSearch: true,
441
+ mode: isMulti || selectMode === 'checkbox' ? 'multiple' : undefined,
442
+ valueSelectAble: true,
443
+ style: {
444
+ width: '100%',
445
+ height: '100%'
446
+ },
447
+ placeholder: t ? t('Select') : 'Select',
448
+ allowClear: column.isClearable ?? false,
449
+ maxTagCount: 'responsive',
450
+ popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
451
+ optionFilterProp: "label",
452
+ popupClassName: 'be-popup-container',
453
+ loadOptions: loadOptions,
454
+ status: isInvalid ? 'error' : undefined
455
+ // dropdownRender={(menu) => {
456
+ // if (toolbarItems && toolbarItems.length > 0) {
457
+ // return (
458
+ // <>
459
+ // {menu}
460
+ // <Divider style={{margin: '8px 0'}}/>
461
+ //
462
+ // <div
463
+ // className={'toolbar-control d-flex justify-content-end'}
464
+ // >
465
+ // {toolbarItems.map((it) => {
466
+ // return (
467
+ // <div
468
+ // key={it.key}
469
+ // className={'toolbar-item'}
470
+ // onClick={() => toolbarClick?.({item: it, column})}
471
+ // >
472
+ // {it.template ? getTemplate(it.template) : (
473
+ // <Button className='toolbar-item-btn'>
474
+ //
475
+ // {it.icon && getTemplate(it.icon)}
476
+ // {it.title}
477
+ // </Button>
478
+ // )}
479
+ //
480
+ // </div>
481
+ // )
482
+ // })}
483
+ //
484
+ // </div>
485
+ // </>
486
+ // )
487
+ // } else {
488
+ // return <> {menu}</>
489
+ // }
490
+ //
491
+ // }}
492
+ ,
493
+ filterOption: filterOption,
494
+ fieldNames: fieldNames ? fieldNames : {
495
+ value: keySelect,
496
+ label: inputKey ?? 'label'
497
+ }
482
498
  });
483
499
  case 'treeSelect':
484
500
  // let valueTreeSelect
@@ -528,22 +544,35 @@ const EditableCell = props => {
528
544
  status: isInvalid ? 'error' : undefined
529
545
  });
530
546
  case 'checkbox':
531
- return /*#__PURE__*/React.createElement(Input
532
- // @ts-ignore
533
- , {
534
- checked: record[column.dataIndex],
535
- id: `col${indexCol}-record${indexRow}`,
536
- type: "checkbox",
547
+ return /*#__PURE__*/React.createElement("div", {
537
548
  style: {
538
- textAlign: column.align ?? 'left'
549
+ display: 'flex',
550
+ alignItems: 'center',
551
+ justifyContent: column.align ?? 'left',
552
+ paddingInline: 5,
553
+ height: '100%'
539
554
  }
540
- // onChange={(val) => {
541
- // record[column.dataIndex] = val.currentTarget.checked
542
- // handleCellChange(val.currentTarget.checked, val.currentTarget.checked, record, col, indexRow, indexCol)
543
- // }}
555
+ }, /*#__PURE__*/React.createElement(Checkbox, {
556
+ checked: Boolean(value)
557
+ // style={{ textAlign: column.align ?? 'left' }}
544
558
  ,
559
+ onChange: val => {
560
+ const newVal = parseBooleanToValue(val.target.checked, typeof value);
561
+ onChange(newVal);
562
+ const key = getRowKey?.(record, index);
563
+ const formState = getValues();
564
+ handleCellChange?.({
565
+ key: key,
566
+ record: formState,
567
+ option: value,
568
+ prevState: value,
569
+ newState: newVal,
570
+ field: column.field ?? column.dataIndex,
571
+ type: 'blur'
572
+ });
573
+ },
545
574
  disabled: isDisable(column, record) ?? false
546
- });
575
+ }));
547
576
 
548
577
  // case 'form':
549
578
  //
@@ -603,28 +632,50 @@ const EditableCell = props => {
603
632
  // )
604
633
 
605
634
  case 'color':
606
- // const color = record[column.dataIndex]
607
-
608
- return /*#__PURE__*/React.createElement(Input, {
609
- type: 'color',
610
- id: `col${indexCol}-record${indexRow}`,
611
- style: {
612
- textAlign: column.align
613
- }
614
- // @ts-ignore
615
- ,
616
- value: !isNullOrUndefined(record[column.dataIndex]) ? record[column.dataIndex] : '',
617
- disabled: isDisable(column, record) ?? false,
618
- className: classNames('be-cell-editing rounded-0 input-element')
619
-
620
- // onChange={(val: any) => {
621
- // if (record[column.dataIndex] !== val.target?.value) {
622
- // record[column.dataIndex] = val.target?.value
623
- // }
624
- // }}
625
- // onBlur={(val: any) => {
626
- // handleCellChange(val, val.target?.value, record, col, indexRow, indexCol)
627
- // }}
635
+ const color = isColor(value) ? value : '#ffffff';
636
+ const presets = genPresets({
637
+ blue,
638
+ red,
639
+ green,
640
+ cyan
641
+ });
642
+ return /*#__PURE__*/React.createElement(ColorPicker, {
643
+ value: color,
644
+ allowClear: column.isClearable ?? true,
645
+ onChangeComplete: valueColor => {
646
+ onChange(`#${valueColor.toHex()}`);
647
+ const key = getRowKey?.(record, index);
648
+ const formState = getValues();
649
+ handleCellChange?.({
650
+ key: key,
651
+ field: column.field ?? column.dataIndex,
652
+ option: `#${valueColor.toHex()}`,
653
+ record: formState,
654
+ prevState: value,
655
+ newState: `#${valueColor.toHex()}`,
656
+ type: 'blur'
657
+ });
658
+ },
659
+ presets: presets,
660
+ panelRender: (_, {
661
+ components: {
662
+ Picker,
663
+ Presets
664
+ }
665
+ }) => /*#__PURE__*/React.createElement(Row, {
666
+ justify: "space-between",
667
+ wrap: false,
668
+ className: "custom-panel be-popup-container"
669
+ }, /*#__PURE__*/React.createElement(Col, {
670
+ span: 12
671
+ }, /*#__PURE__*/React.createElement(Presets, null)), /*#__PURE__*/React.createElement(Divider, {
672
+ type: "vertical",
673
+ style: {
674
+ height: 'auto'
675
+ }
676
+ }), /*#__PURE__*/React.createElement(Col, {
677
+ flex: "auto"
678
+ }, /*#__PURE__*/React.createElement(Picker, null)))
628
679
  });
629
680
 
630
681
  // case 'image':
@@ -679,13 +730,7 @@ const EditableCell = props => {
679
730
  'be-cell-edit-align-center': column.align === 'center',
680
731
  'be-cell-edit-align-left': column.align === 'left',
681
732
  'be-cell-edit-align-right': !column.align || column.align === 'right'
682
- })
683
-
684
- // onFocus={(e) => {
685
- // e.target.setSelectionRange(0, e.target.innerText.length - 1)
686
- // }}
687
- ,
688
-
733
+ }),
689
734
  onValueChange: values => {
690
735
  onChange(values?.floatValue);
691
736
  },
@@ -696,12 +741,13 @@ const EditableCell = props => {
696
741
  // @ts-ignore
697
742
  const prevState = record[dataIndex];
698
743
  const newState = value;
699
-
744
+ const key = getRowKey?.(record, index);
700
745
  // @ts-ignore
701
746
  if (itemState !== record[dataIndex]) {
702
- // @ts-ignore
703
747
  handleCellChange?.({
704
- key: record[rowKey],
748
+ key: key,
749
+ field: column.field ?? column.dataIndex,
750
+ option: newState,
705
751
  record: formState,
706
752
  prevState,
707
753
  newState,
@@ -709,26 +755,6 @@ const EditableCell = props => {
709
755
  });
710
756
  }
711
757
  }
712
-
713
- // onBlur={() => {
714
- // const tempValue = tempResource[indexRow][column.dataIndex]
715
- //
716
- // if (indexFocus !== -1 && tempValue !== valueNumeric) {
717
- // if (column.min || column.min === 0 || column.max || column.max === 0) {
718
- // handleCellChange(valueNumeric, valueNumeric, record, col, indexRow, indexCol)
719
- // } else {
720
- // handleCellChange(valueNumeric, valueNumeric, record, col, indexRow, indexCol)
721
- // }
722
- // }
723
- //
724
- // }}
725
-
726
- // onPaste={(e: any) => handleOnCellPaste(e, indexRow, indexCol)}
727
-
728
- // onKeyDown={(e: any) => {
729
- // onInputKeydown(e, floatValue, floatValue, record, col, indexRow, indexCol)
730
- //
731
- // }}
732
758
  }));
733
759
  default:
734
760
  return /*#__PURE__*/React.createElement(Input, {
@@ -744,30 +770,27 @@ const EditableCell = props => {
744
770
  value: !isNullOrUndefined(value) ? value : '',
745
771
  onBlur: () => {
746
772
  const formState = getValues();
747
- const itemState = getValues(dataIndex);
748
- // // @ts-ignore
749
- // const prevState = record[dataIndex]
750
- // const newState = value
773
+ // const itemState = getValues(dataIndex)
774
+ // @ts-ignore
775
+ const prevState = record[dataIndex];
776
+ const newState = value;
751
777
  //
752
778
  // console.log('newState', newState)
753
779
  // console.log('prevState', prevState)
754
-
780
+ const key = getRowKey?.(record, index);
755
781
  // @ts-ignore
756
- if (itemState !== record[dataIndex]) {
757
- // @ts-ignore
782
+ if (newState !== prevState) {
758
783
  handleCellChange?.({
759
- key: record[rowKey],
784
+ key: key,
760
785
  record: formState,
786
+ option: value,
787
+ prevState,
788
+ newState,
789
+ field: column.field ?? column.dataIndex,
761
790
  type: 'blur'
762
791
  });
763
792
  }
764
- }
765
-
766
- // onKeyDown={(e: any) => {
767
- // console.log('onKeyDown edit', e.key)
768
- // }}
769
- ,
770
-
793
+ },
771
794
  onPressEnter: () => {
772
795
  const formState = getValues();
773
796
  const newState = getValues(dataIndex);
@@ -786,49 +809,12 @@ const EditableCell = props => {
786
809
  // }
787
810
  },
788
811
  onChange: onChange
789
- // onFocus={(e) => {
790
- // e.target.setSelectionRange(0, e.target.innerText.length - 1)
791
- // }}
792
- // invalid={isInvalid}
793
812
 
794
- // onChange={(val: any) => {
795
- //
796
- // handleCellUpdate('text', val.target?.value, record, col, indexRow, indexCol)
797
- //
798
- // }}
799
- // onPaste={(e: any) => handleOnCellPaste(e, indexRow, indexCol)}
800
- // onBlur={(val: any) => {
801
- // const tempValue = tempResource[indexRow][column.dataIndex]
802
- //
803
- // if (indexFocus !== -1 && tempValue !== record[column.dataIndex]) {
804
- //
805
- // handleCellChange(val.target?.value, val.target?.value, record, col, indexRow, indexCol)
806
- //
807
- // }
808
- // }}
809
- // onKeyDown={(e: any) => {
810
- // onInputKeydown(e, e.target?.value, e.target?.value, record, col, indexRow, indexCol)
811
- // }}
813
+ // invalid={isInvalid}
812
814
  });
813
815
  }
814
816
  };
815
- return /*#__PURE__*/React.createElement("div", restProps, editing ?
816
- /*#__PURE__*/
817
- // <Form.Item
818
- // name={dataIndex}
819
- //
820
- // style={{ margin: 0 }}
821
- // // rules={[
822
- // // {
823
- // // required: true,
824
- // // message: ``,
825
- // //
826
- // // },
827
- // // ]}
828
- // >
829
- // {inputNode()}
830
- // </Form.Item>
831
- React.createElement(Controller, {
817
+ return /*#__PURE__*/React.createElement("div", restProps, editing ? /*#__PURE__*/React.createElement(Controller, {
832
818
  name: dataIndex,
833
819
  control: control,
834
820
  render: ({