react-table-edit 1.4.17 → 1.4.18

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.
package/dist/index.mjs CHANGED
@@ -19269,6 +19269,77 @@ const FindNodeByPath = (tree, path) => {
19269
19269
  }
19270
19270
  return { parent: current, lastIndex: levels.at(-1), firstIndex: levels.length === 1 ? levels[0] : -1, node };
19271
19271
  };
19272
+ /**
19273
+ * Tính toán cấu trúc bảng từ dữ liệu column dạng cây:
19274
+ * - Tạo header dạng nhiều cấp (header theo chiều dọc)
19275
+ * - Chuyển cột thành dạng phẳng để render nội dung
19276
+ * - Tính toán vị trí cố định trái/phải (fixed column) để hiển thị sticky
19277
+ *
19278
+ * @param columns Mảng cấu trúc cây đại diện cho các cột của bảng
19279
+ * @returns {
19280
+ * levels: IHeaderColumnTable[][] // Các hàng header theo cấp
19281
+ * flat: IColumnVirtualizedTable[] // Danh sách cột phẳng
19282
+ * objWidthFixLeft: Record<number, number> // Offset trái cho cột fixed left
19283
+ * objWidthFixRight: Record<number, number> // Offset phải cho cột fixed right
19284
+ * lastObjWidthFixLeft: number // Chỉ số cột cuối cùng fixed left
19285
+ * fisrtObjWidthFixRight: number // Chỉ số cột đầu tiên fixed right
19286
+ * }
19287
+ */
19288
+ const calculateTableStructure = (columns) => {
19289
+ const levels = [];
19290
+ const flat = [];
19291
+ const objWidthFixLeft = {};
19292
+ const objWidthFixRight = {};
19293
+ let maxDepth = 0;
19294
+ // Tính depth tối đa
19295
+ const calculateDepth = (cols, depth = 1) => (Math.max(...cols.map(col => (col.columns?.length ? calculateDepth(col.columns, depth + 1) : depth))));
19296
+ maxDepth = calculateDepth(columns);
19297
+ let leftTotal = 0;
19298
+ let rightTotal = 0;
19299
+ const traverse = (cols, level = 0) => {
19300
+ levels[level] = levels[level] || [];
19301
+ return cols.reduce((colspanSum, col) => {
19302
+ const hasChildren = (col.columns?.length ?? 0) > 0;
19303
+ const colspan = hasChildren ? traverse(col.columns, level + 1) : 1;
19304
+ const cell = {
19305
+ ...col,
19306
+ columns: col.columns ?? [],
19307
+ colspan,
19308
+ rowspan: hasChildren ? 1 : maxDepth - level
19309
+ };
19310
+ levels[level].push(cell);
19311
+ if (!hasChildren) {
19312
+ const visible = col.visible !== false;
19313
+ const index = flat.length;
19314
+ const width = col.width ?? 40;
19315
+ cell.index = index;
19316
+ flat.push(cell);
19317
+ if (col.fixedType === 'left' && visible) {
19318
+ objWidthFixLeft[index] = leftTotal;
19319
+ leftTotal += width;
19320
+ }
19321
+ if (col.fixedType === 'right' && visible) {
19322
+ objWidthFixRight[index] = rightTotal;
19323
+ rightTotal += width;
19324
+ }
19325
+ }
19326
+ return colspanSum + colspan;
19327
+ }, 0);
19328
+ };
19329
+ traverse(columns);
19330
+ const flatVisble = flat.filter((e) => e.visible !== false);
19331
+ const lastObjWidthFixLeft = Math.max(...Object.keys(objWidthFixLeft).map(Number), 0);
19332
+ const fisrtObjWidthFixRight = Math.min(...Object.keys(objWidthFixRight).map(Number), flat.length);
19333
+ return {
19334
+ levels,
19335
+ flat,
19336
+ flatVisble,
19337
+ objWidthFixLeft,
19338
+ objWidthFixRight,
19339
+ lastObjWidthFixLeft,
19340
+ fisrtObjWidthFixRight
19341
+ };
19342
+ };
19272
19343
 
19273
19344
  var isCheckBoxInput = (element) => element.type === 'checkbox';
19274
19345
 
@@ -23037,7 +23108,6 @@ const EditForm = forwardRef((props, ref) => {
23037
23108
  const { innerWidth } = window;
23038
23109
  const inputRef = useRef(null);
23039
23110
  const editFormRef = useRef(null);
23040
- const buttonRef = useRef(null);
23041
23111
  const [dropdownOpen, setDropdownOpen] = useState(false);
23042
23112
  const [isFocus, setIsFocus] = useState(false);
23043
23113
  const [itemsField, setItemsField] = useState([]);
@@ -23223,7 +23293,7 @@ const EditForm = forwardRef((props, ref) => {
23223
23293
  }, children: jsxs(DropdownItem$1, { className: 'p-0', style: { borderRadius: '6px' }, tag: 'div', header: true, children: [jsx("div", { onKeyDown: (e) => formKeyDown(e, handleSubmit(handleOnSubmit)), className: 'p-1', style: {
23224
23294
  maxHeight: menuHeight ? menuHeight : 300,
23225
23295
  overflow: "auto"
23226
- }, children: itemsField ? renderForm(itemsField) : '' }), jsxs("div", { className: "d-flex justify-content-between p-50", style: { boxShadow: "0 4px 24px 0 rgb(34 41 47 / 10%)" }, children: [jsx("div", { className: "text-primary py-25", style: { fontSize: 12 }, children: footerTemplate ? footerTemplate(rowData) : '' }), !onChangeField ? jsxs("div", { className: "d-flex justify-content-end", children: [isClearable && jsx(Button$1, { ref: buttonRef, className: 'btn me-50 py-25 px-50', outline: true, onClick: () => {
23296
+ }, children: itemsField ? renderForm(itemsField) : '' }), jsxs("div", { className: "d-flex justify-content-between p-50", style: { boxShadow: "0 4px 24px 0 rgb(34 41 47 / 10%)" }, children: [jsx("div", { className: "text-primary py-25", style: { fontSize: 12 }, children: footerTemplate ? footerTemplate(rowData) : '' }), !onChangeField ? jsxs("div", { className: "d-flex justify-content-end", children: [isClearable && jsx(Button$1, { className: 'btn me-50 py-25 px-50', outline: true, onClick: () => {
23227
23297
  itemsField.forEach((e) => {
23228
23298
  if (e.type === 'numeric') {
23229
23299
  setValue(e.name, 0);
@@ -23236,7 +23306,7 @@ const EditForm = forwardRef((props, ref) => {
23236
23306
  if (e.code === 'Tab') {
23237
23307
  closeMenu();
23238
23308
  }
23239
- }, children: t('Clear') }), jsx(Button$1, { ref: buttonRef, color: 'primary', className: 'btn btn-primary py-25 px-50', onClick: handleSubmit(handleOnSubmit), onKeyDown: (e) => {
23309
+ }, children: t('Clear') }), jsx(Button$1, { color: 'primary', className: 'btn btn-primary py-25 px-50', onClick: handleSubmit(handleOnSubmit), onKeyDown: (e) => {
23240
23310
  if (e.code === 'Tab') {
23241
23311
  closeMenu();
23242
23312
  }
@@ -23490,7 +23560,9 @@ const CommandElement = (props) => {
23490
23560
  }), color: item.color ? item.color : '#000', onClick: (e) => {
23491
23561
  handleCommandClick(item.id, rowData, indexRow);
23492
23562
  if (indexRow === indexFocus) {
23493
- setIndexFocus(-1);
23563
+ if (setIndexFocus) {
23564
+ setIndexFocus(-1);
23565
+ }
23494
23566
  }
23495
23567
  e.preventDefault();
23496
23568
  }, children: [item.icon && jsx(IconCustom, { iconName: item.icon, size: 16 }), jsx(UncontrolledTooltip, { className: "r-tooltip", target: `command-item-${indexRow}-${index}`, place: "top", children: t(item.tooltip ?? '') })] }, `command-${index}`));
@@ -42602,24 +42674,6 @@ const TableEdit = forwardRef((props, ref) => {
42602
42674
  setHeaderColumns(arrHeaderColumns);
42603
42675
  setContentColumns(arrContentColumns);
42604
42676
  }, [columns]);
42605
- useEffect(() => {
42606
- const arrHeaderColumns = [];
42607
- const arrContentColumns = [];
42608
- let headerLevelRow = 0;
42609
- if (levelCol) {
42610
- headerLevelRow = levelCol;
42611
- }
42612
- else {
42613
- headerLevelRow = stretchColumn(columns, 0);
42614
- setLevelCol(headerLevelRow);
42615
- }
42616
- for (let i = 0; i < headerLevelRow; i++) {
42617
- arrHeaderColumns.push([]);
42618
- }
42619
- getNestedChildren(columns, arrHeaderColumns, arrContentColumns, 0, headerLevelRow);
42620
- setHeaderColumns(arrHeaderColumns);
42621
- setContentColumns(arrContentColumns);
42622
- }, [columns]);
42623
42677
  const getNestedChildren = (array, arrHeaderColumns, arrContentColumns, level, maxLevelRow) => {
42624
42678
  array.forEach((item) => {
42625
42679
  const ele = { ...item, visible: item.visible, rowspan: 1, index: 0 };
@@ -65324,5 +65378,5 @@ const ImportExcelComponent = (props) => {
65324
65378
  ] }) }));
65325
65379
  };
65326
65380
 
65327
- export { ExportExcelComponent, FindNodeByPath, ImportExcelComponent, InputStyleComponent, SelectTable, SelectTableTree, TabsMenuComponent, Wizard, checkDecimalSeparator, checkThousandSeparator, TableEdit as default, formartNumberic, formatDateTime, generateUUID, isNullOrUndefined$1 as isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, roundNumber, useOnClickOutside };
65381
+ export { ExportExcelComponent, FindNodeByPath, ImportExcelComponent, InputStyleComponent, SelectTable, SelectTableTree, TabsMenuComponent, Wizard, calculateTableStructure, checkDecimalSeparator, checkThousandSeparator, TableEdit as default, formartNumberic, formatDateTime, generateUUID, isNullOrUndefined$1 as isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, roundNumber, useOnClickOutside };
65328
65382
  //# sourceMappingURL=index.mjs.map