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