es-grid-template 1.9.63 → 1.9.64

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 (46) hide show
  1. package/es/ali-table/Grid.js +5 -2
  2. package/es/ali-table/InternalTable.js +499 -49
  3. package/es/ali-table/base-table/calculations.js +1 -1
  4. package/es/ali-table/base-table/cell/EditCell.js +14 -6
  5. package/es/ali-table/base-table/renderFilter.js +1 -1
  6. package/es/ali-table/interfaces.d.ts +2 -2
  7. package/es/ali-table/pipeline/features/columnCustom.d.ts +4 -2
  8. package/es/ali-table/pipeline/features/columnCustom.js +112 -48
  9. package/es/ali-table/utils/constants.d.ts +1 -0
  10. package/es/ali-table/utils/constants.js +1 -0
  11. package/es/ali-table/utils/convertColumnsChoose.d.ts +2 -2
  12. package/es/ali-table/utils/convertColumnsChoose.js +1 -2
  13. package/es/ali-table/utils/utility.d.ts +15 -1
  14. package/es/ali-table/utils/utility.js +399 -1
  15. package/es/grid-component/type.d.ts +2 -2
  16. package/es/group-component/hook/utils.d.ts +3 -3
  17. package/es/table-component/TableContainerEdit.js +148 -98
  18. package/es/table-component/body/EditableCell.js +9 -5
  19. package/es/table-component/body/TableBodyCellEdit.js +14 -8
  20. package/es/table-component/header/renderFilter.js +1 -1
  21. package/es/table-component/hook/utils.d.ts +1 -1
  22. package/es/table-component/hook/utils.js +2 -6
  23. package/es/table-component/useContext.d.ts +1 -1
  24. package/lib/ali-table/Grid.js +5 -2
  25. package/lib/ali-table/InternalTable.js +490 -45
  26. package/lib/ali-table/base-table/calculations.js +1 -1
  27. package/lib/ali-table/base-table/cell/EditCell.js +14 -6
  28. package/lib/ali-table/base-table/renderFilter.js +1 -1
  29. package/lib/ali-table/interfaces.d.ts +2 -2
  30. package/lib/ali-table/pipeline/features/columnCustom.d.ts +4 -2
  31. package/lib/ali-table/pipeline/features/columnCustom.js +106 -46
  32. package/lib/ali-table/utils/constants.d.ts +1 -0
  33. package/lib/ali-table/utils/constants.js +2 -1
  34. package/lib/ali-table/utils/convertColumnsChoose.d.ts +2 -2
  35. package/lib/ali-table/utils/convertColumnsChoose.js +1 -2
  36. package/lib/ali-table/utils/utility.d.ts +15 -1
  37. package/lib/ali-table/utils/utility.js +410 -2
  38. package/lib/grid-component/type.d.ts +2 -2
  39. package/lib/table-component/TableContainerEdit.js +148 -98
  40. package/lib/table-component/body/EditableCell.js +9 -5
  41. package/lib/table-component/body/TableBodyCellEdit.js +11 -7
  42. package/lib/table-component/header/renderFilter.js +1 -1
  43. package/lib/table-component/hook/utils.d.ts +1 -1
  44. package/lib/table-component/hook/utils.js +2 -6
  45. package/lib/table-component/useContext.d.ts +1 -1
  46. package/package.json +1 -1
@@ -296,6 +296,20 @@ const TableContainerEdit = props => {
296
296
  });
297
297
  }
298
298
  }, [onCellPaste, originData, triggerChangeData]);
299
+ const {
300
+ control,
301
+ handleSubmit,
302
+ setValue,
303
+ // trigger,
304
+ getValues,
305
+ reset,
306
+ formState: {
307
+ errors
308
+ }
309
+ } = (0, _reactHookForm.useForm)({
310
+ mode: 'onChange',
311
+ resolver: validate ? (0, _yup.yupResolver)(validate) : undefined
312
+ });
299
313
 
300
314
  // Copy
301
315
 
@@ -332,16 +346,144 @@ const TableContainerEdit = props => {
332
346
 
333
347
  copy(tsv).then(() => {}).catch(() => {});
334
348
  }, [startCell, endCell, table]);
349
+ const onSubmit = formData => {
350
+ try {
351
+ // const record = (await form.validateFields()) as RecordType;
352
+ const row = {
353
+ ...formData
354
+ };
355
+
356
+ // const newData = [...dataSource]
357
+ const newData = [...originData];
358
+
359
+ // @ts-ignore
360
+ const index = (0, _utils.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
361
+ const rs = (0, _utils.updateArrayByKey)(newData, row, rowKey);
362
+ if (index > -1) {
363
+ triggerChangeData?.(rs, {
364
+ type: 'CellChange'
365
+ });
366
+ }
367
+ } catch (errInfo) {
368
+ console.log('Validate Failed:', errInfo);
369
+ }
370
+ };
371
+ const handleCellChange = args => {
372
+ const {
373
+ record,
374
+ type: changeType,
375
+ newState,
376
+ prevState,
377
+ option,
378
+ field,
379
+ indexCol,
380
+ indexRow,
381
+ key
382
+ } = args;
383
+ if (changeType === 'blur') {
384
+ const handleChangeCallback = callbackData => {
385
+ const callbackRecord = callbackData;
386
+ Object.entries(callbackRecord).forEach(([name, value]) => {
387
+ setValue(name, value);
388
+ });
389
+ onSubmit(callbackRecord);
390
+ };
391
+ if (onCellChange) {
392
+ if (onCellChange.length > 1) {
393
+ onCellChange({
394
+ field,
395
+ indexCol,
396
+ type: 'onChange',
397
+ value: newState,
398
+ option,
399
+ indexRow,
400
+ rowData: record,
401
+ rowId: key,
402
+ // rowsData: [...dataSource],
403
+ rowsData: [...originData],
404
+ sumValue: []
405
+ }, handleChangeCallback);
406
+ } else {
407
+ onCellChange({
408
+ field,
409
+ indexCol,
410
+ type: 'onChange',
411
+ option,
412
+ value: newState,
413
+ indexRow,
414
+ rowData: record,
415
+ rowId: key,
416
+ // rowsData: [...dataSource],
417
+ rowsData: [...originData],
418
+ sumValue: []
419
+ }, handleChangeCallback);
420
+ onSubmit(record);
421
+ }
422
+ }
423
+ }
424
+ if (prevState && newState && prevState !== newState && changeType === 'enter') {
425
+ onSubmit(record);
426
+ }
427
+ };
335
428
  _react.default.useEffect(() => {
336
429
  const handleKeyDown = e => {
337
430
  if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
338
431
  e.preventDefault();
339
432
  copySelectionToClipboard();
340
433
  }
434
+ if (e.ctrlKey && e.key === 'x' && startCell && endCell && !editingKey) {
435
+ e.preventDefault();
436
+ if (startCell && endCell) {
437
+ const tmpData = (0, _utils.flattenArray)(originData);
438
+ const rs = tmpData.map((row, index) => {
439
+ if (!rangeState?.rowRange.includes(row.rowId)) {
440
+ return row;
441
+ }
442
+ const updatedRow = {
443
+ ...row
444
+ };
445
+ for (const colId of rangeState.colRange) {
446
+ const column = table.getVisibleFlatColumns().find(it => it.id === colId)?.columnDef.meta;
447
+ const columnIndex = table.getVisibleFlatColumns().findIndex(it => it.id === colId);
448
+ if ((0, _utils.isEditable)(column, row)) {
449
+ let newValue = '';
450
+ if (column.type === 'number') {
451
+ newValue = 0;
452
+ }
453
+ if (column.type === 'boolean' || column.type === 'checkbox') {
454
+ newValue = false;
455
+ }
456
+ const cellEditType = (0, _utils.getEditType)(column, row);
457
+ if (column.type === 'date' || column.type === 'datetime' || column.type === 'time' || column.type === 'month' || column.type === 'week' || column.type === 'year' || column.type === 'quarter' || cellEditType === 'asyncSelect' || cellEditType === 'select' || cellEditType === 'treeSelect' || cellEditType === 'selectTable') {
458
+ newValue = undefined;
459
+ }
460
+ updatedRow[colId] = newValue;
461
+ handleCellChange({
462
+ key: row[rowKey],
463
+ field: column.field ?? column.dataIndex,
464
+ record: updatedRow,
465
+ prevState: row[column.field],
466
+ newState: newValue,
467
+ option: '',
468
+ indexCol: columnIndex,
469
+ indexRow: index,
470
+ type: 'blur'
471
+ });
472
+ }
473
+ }
474
+ return updatedRow;
475
+ });
476
+ const newData = (0, _utils.unFlattenData)(rs);
477
+ triggerChangeData?.(newData, {
478
+ type: 'DELETE_CONTENT'
479
+ });
480
+ }
481
+ copySelectionToClipboard();
482
+ }
341
483
  };
342
484
  document.addEventListener('keydown', handleKeyDown);
343
485
  return () => document.removeEventListener('keydown', handleKeyDown);
344
- }, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
486
+ }, [startCell, endCell, table, copySelectionToClipboard, editingKey, rangeState]);
345
487
 
346
488
  // Paste
347
489
 
@@ -751,20 +893,6 @@ const TableContainerEdit = props => {
751
893
  observer.disconnect();
752
894
  };
753
895
  }, []);
754
- const {
755
- control,
756
- handleSubmit,
757
- setValue,
758
- // trigger,
759
- getValues,
760
- reset,
761
- formState: {
762
- errors
763
- }
764
- } = (0, _reactHookForm.useForm)({
765
- mode: 'onChange',
766
- resolver: validate ? (0, _yup.yupResolver)(validate) : undefined
767
- });
768
896
  const handleAddMulti = _react.default.useCallback((item, n, newId) => {
769
897
  if (item.onClick) {
770
898
  item.onClick({
@@ -789,28 +917,6 @@ const TableContainerEdit = props => {
789
917
  triggerChangeData?.(newData);
790
918
  }
791
919
  }, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
792
- const onSubmit = formData => {
793
- try {
794
- // const record = (await form.validateFields()) as RecordType;
795
- const row = {
796
- ...formData
797
- };
798
-
799
- // const newData = [...dataSource]
800
- const newData = [...originData];
801
-
802
- // @ts-ignore
803
- const index = (0, _utils.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
804
- const rs = (0, _utils.updateArrayByKey)(newData, row, rowKey);
805
- if (index > -1) {
806
- triggerChangeData?.(rs, {
807
- type: 'CellChange'
808
- });
809
- }
810
- } catch (errInfo) {
811
- console.log('Validate Failed:', errInfo);
812
- }
813
- };
814
920
  const onSubmit2 = (formData, newOriginData) => {
815
921
  try {
816
922
  // const record = (await form.validateFields()) as RecordType;
@@ -833,63 +939,6 @@ const TableContainerEdit = props => {
833
939
  console.log('Validate Failed:', errInfo);
834
940
  }
835
941
  };
836
- const handleCellChange = args => {
837
- const {
838
- record,
839
- type: changeType,
840
- newState,
841
- prevState,
842
- option,
843
- field,
844
- indexCol,
845
- indexRow,
846
- key
847
- } = args;
848
- if (changeType === 'blur') {
849
- const handleChangeCallback = callbackData => {
850
- const callbackRecord = callbackData;
851
- Object.entries(callbackRecord).forEach(([name, value]) => {
852
- setValue(name, value);
853
- });
854
- onSubmit(callbackRecord);
855
- };
856
- if (onCellChange) {
857
- if (onCellChange.length > 1) {
858
- onCellChange({
859
- field,
860
- indexCol,
861
- type: 'onChange',
862
- value: newState,
863
- option,
864
- indexRow,
865
- rowData: record,
866
- rowId: key,
867
- // rowsData: [...dataSource],
868
- rowsData: [...originData],
869
- sumValue: []
870
- }, handleChangeCallback);
871
- } else {
872
- onCellChange({
873
- field,
874
- indexCol,
875
- type: 'onChange',
876
- option,
877
- value: newState,
878
- indexRow,
879
- rowData: record,
880
- rowId: key,
881
- // rowsData: [...dataSource],
882
- rowsData: [...originData],
883
- sumValue: []
884
- }, handleChangeCallback);
885
- onSubmit(record);
886
- }
887
- }
888
- }
889
- if (prevState && newState && prevState !== newState && changeType === 'enter') {
890
- onSubmit(record);
891
- }
892
- };
893
942
  const handleCellChangeAndAddRow = args => {
894
943
  const {
895
944
  record,
@@ -999,7 +1048,7 @@ const TableContainerEdit = props => {
999
1048
  // không tính tree
1000
1049
 
1001
1050
  // Cập nhật data mới
1002
- const newData = (0, _utils.flattenArray)([...dataSource]);
1051
+ const newData = (0, _utils.flattenArray)(originData);
1003
1052
 
1004
1053
  // const duplicatedItems = rowsFocus.map(index => ({ ...newData[index], rowId: newGuid(), id: undefined, isDuplicate: true }))
1005
1054
 
@@ -1024,13 +1073,14 @@ const TableContainerEdit = props => {
1024
1073
  const rsFilter = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
1025
1074
 
1026
1075
  // const rs = updateOrInsertInOrder(originData, rsFilter)
1027
- const rs = (0, _utils.updateOrInsert)(originData, rsFilter);
1076
+ const rs = (0, _utils.updateOrInsert)(newData, rsFilter);
1028
1077
  // const rs2 = mergeWithFilter(originData, rsFilter)
1029
1078
 
1030
- triggerChangeData?.(rs, {
1079
+ const newDaa = (0, _utils.unFlattenData)(rs);
1080
+ triggerChangeData?.(newDaa, {
1031
1081
  type: 'DUPLICATE'
1032
1082
  });
1033
- }, [dataSource, focusedCell, originData, rowKey, table, triggerChangeData]);
1083
+ }, [focusedCell, originData, rowKey, table, triggerChangeData]);
1034
1084
 
1035
1085
  // thêm n dòng bên trên
1036
1086
  const handleInsertBefore = _react.default.useCallback((item, n) => {
@@ -476,7 +476,9 @@ const EditableCell = props => {
476
476
  align: colSelect.textAlign
477
477
  };
478
478
  });
479
- let valueSelectTable = formValues[dataIndex];
479
+
480
+ // let valueSelectTable = formValues[dataIndex]
481
+ let valueSelectTable = formValues[dataIndex] !== null ? formValues[dataIndex] : undefined;
480
482
  if (fieldValue) {
481
483
  // @ts-ignore
482
484
  valueSelectTable = record[fieldValue] ?? formValues[dataIndex];
@@ -625,14 +627,15 @@ const EditableCell = props => {
625
627
  "data-tooltip-id": `${id}-tooltip-error`
626
628
  });
627
629
  case 'select':
628
- let valueSelect = formValues[dataIndex];
630
+ // let valueSelect = formValues[dataIndex]
631
+ let valueSelect = formValues[dataIndex] !== null ? formValues[dataIndex] : undefined;
629
632
  if (fieldValue) {
630
633
  // @ts-ignore
631
634
  valueSelect = record[fieldValue] ?? formValues[dataIndex];
632
635
  }
633
636
  return /*#__PURE__*/_react.default.createElement(_rcMasterUi.Select, {
634
637
  options: options,
635
- value: valueSelect ?? '',
638
+ value: valueSelect,
636
639
  onChange: (val, option) => {
637
640
  onChange(val ?? '');
638
641
  const formState = getValues();
@@ -768,7 +771,8 @@ const EditableCell = props => {
768
771
  "data-tooltip-id": `${id}-tooltip-error`
769
772
  });
770
773
  case 'asyncSelect':
771
- let valueAsyncSelect = formValues[dataIndex];
774
+ // let valueAsyncSelect = formValues[dataIndex]
775
+ let valueAsyncSelect = formValues[dataIndex] !== null ? formValues[dataIndex] : undefined;
772
776
  if (fieldValue) {
773
777
  // @ts-ignore
774
778
  valueAsyncSelect = record[fieldValue] ?? formValues[dataIndex];
@@ -776,7 +780,7 @@ const EditableCell = props => {
776
780
  return /*#__PURE__*/_react.default.createElement(_asyncSelect.AsyncSelect, {
777
781
  options: options,
778
782
  defaultOptions: options,
779
- value: valueAsyncSelect ?? undefined,
783
+ value: valueAsyncSelect,
780
784
  onChange: (val, option) => {
781
785
  onChange(val ?? '');
782
786
  const formState = getValues();
@@ -258,6 +258,10 @@ const TableBodyCellEdit = props => {
258
258
  const isPinned = cell.column.getIsPinned();
259
259
  const isLastLeftPinnedColumn = isPinned === "left" && cell.column.getIsLastColumn("left");
260
260
  const isFirstRightPinnedColumn = isPinned === "right" && cell.column.getIsFirstColumn("right");
261
+
262
+ // const rowIds = getKeys(allRows, 'id' as any)
263
+ // const colIds = table.getVisibleLeafColumns().map(c => c.id);
264
+
261
265
  const selectRowIds = _react.default.useMemo(() => {
262
266
  return startCell && endCell ? (0, _utils.getRowIdsBetween)(table, startCell.rowId, endCell.rowId) : [];
263
267
  }, [endCell, startCell, table]);
@@ -265,19 +269,19 @@ const TableBodyCellEdit = props => {
265
269
  if (!startCell || !endCell) return false;
266
270
 
267
271
  // const rowIds = getRowIdsBetween(table, startCell.rowId, endCell.rowId);
268
- const colIds = (0, _utils.getColIdsBetween)(table, startCell.colId, endCell.colId);
269
- return selectRowIds.includes(cell.row.id) && colIds.includes(cell.column.id);
272
+ const colIdss = (0, _utils.getColIdsBetween)(table, startCell.colId, endCell.colId);
273
+ return selectRowIds.includes(cell.row.id) && colIdss.includes(cell.column.id);
270
274
  }, [cell.column.id, cell.row.id, endCell, selectRowIds, startCell, table]);
271
275
  const editType = typeof columnMeta.editType === 'function' ? columnMeta.editType(record) : columnMeta.editType;
272
276
  const {
273
277
  rowRange,
274
278
  colRange,
275
- rowIds,
276
- colIds,
277
279
  startColIndex,
278
280
  startRowIndex,
279
281
  endColIndex,
280
- endRowIndex
282
+ endRowIndex,
283
+ rowIds,
284
+ colIds
281
285
  } = rangeState ?? {};
282
286
  const pasteRangeState = (0, _utils.getSelectedCellMatrix)(table, startPasteCell, endPasteCell);
283
287
  const isInRange = colRange && rowRange && rowRange.includes(cell.row.id) && colRange.includes(cell.column.id);
@@ -287,8 +291,8 @@ const TableBodyCellEdit = props => {
287
291
 
288
292
  const rowIdx = rowIds ? rowIds.indexOf(cell.row.id) : -1;
289
293
  const colIdx = colIds ? colIds.indexOf(cell.column.id) : -1;
290
- const rowIdxPaste = pasteRangeState.rowIds.indexOf(cell.row.id);
291
- const colIdxPaste = pasteRangeState.colIds.indexOf(cell.column.id);
294
+ const rowIdxPaste = pasteRangeState?.rowIds ? pasteRangeState?.rowIds.indexOf(cell.row.id) : undefined;
295
+ const colIdxPaste = pasteRangeState?.colIds ? pasteRangeState?.colIds.indexOf(cell.column.id) : undefined;
292
296
  const isTop = rowIdx === startRowIndex;
293
297
  const isBottom = rowIdx === endRowIndex;
294
298
  const isLeft = colIdx === startColIndex;
@@ -325,7 +325,7 @@ const renderFilter = args => {
325
325
  ,
326
326
  placeholder: tableLocal?.search ?? `Search`,
327
327
  value: selectedKeys[0],
328
- onChange: e => setSelectedKeys(e.target.value ? [e.target.value] : [])
328
+ onChange: e => setSelectedKeys(e.target.value ? [e.target.value.trim()] : [])
329
329
  // onPressEnter={() => handleSearch(selectedKeys as string[], confirm)}
330
330
  ,
331
331
  onPressEnter: () => doFilter?.(true),
@@ -42,7 +42,7 @@ export declare function getDateValueType(value: unknown): DateValueType;
42
42
  export declare const convertToDate: (value?: string | Date | null, format?: string) => string;
43
43
  export declare const getTypeFilter: (col: any) => TypeFilter;
44
44
  export declare const addRowIdArray: (inputArray: any[]) => any[];
45
- export declare function groupArrayByColumns(arr: any[], columns: string[] | undefined): any;
45
+ export declare function groupArrayByColumns(arr: any[], columns: string[] | undefined): any[];
46
46
  export declare const flatColumns2: <RecordType>(columns: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
47
47
  export declare const flatColumnsWithoutParent: (columns: any[]) => any;
48
48
  export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
@@ -1607,16 +1607,14 @@ const getSelectedCellMatrix2 = (flatData, visibleLeafColumns, startCell, endCell
1607
1607
  endRowIndex,
1608
1608
  startColIndex,
1609
1609
  endColIndex,
1610
- rowIds,
1611
- colIds,
1610
+ // rowIds,
1611
+ // colIds,
1612
1612
  type
1613
1613
  };
1614
1614
  };
1615
1615
  exports.getSelectedCellMatrix2 = getSelectedCellMatrix2;
1616
1616
  const getSelectedCellMatrix1 = (flatData, visibleLeafColumns, startCell, endCell, type) => {
1617
1617
  if (!startCell || !endCell) return {
1618
- rowIds: [],
1619
- colIds: [],
1620
1618
  startRowIndex: undefined,
1621
1619
  endRowIndex: undefined,
1622
1620
  startColIndex: undefined,
@@ -1662,8 +1660,6 @@ const getSelectedCellMatrix1 = (flatData, visibleLeafColumns, startCell, endCell
1662
1660
  endRowIndex: normalizedEndRowIndex,
1663
1661
  startColIndex: normalizedStartColIndex,
1664
1662
  endColIndex: normalizedEndColIndex,
1665
- rowIds,
1666
- colIds,
1667
1663
  type
1668
1664
  };
1669
1665
  };
@@ -105,6 +105,6 @@ export type ContextCellChange = {
105
105
  indexCol: number;
106
106
  newState?: any;
107
107
  prevState?: any;
108
- type: 'enter' | 'blur' | 'outClick';
108
+ type: 'enter' | 'blur' | 'outClick' | string;
109
109
  addNewRow?: boolean;
110
110
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.9.63",
3
+ "version": "1.9.64",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",