@contrail/document-table 1.0.6 → 1.0.14

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.
@@ -102,7 +102,10 @@ class TableMergeService {
102
102
  }
103
103
  else {
104
104
  element.style = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(table_service_1.TableService.DEFAULT_CELL_STYLE), firstCell.style);
105
- element.rotate = Object.assign({}, firstCell.rotate);
105
+ if (firstCell.rotate) {
106
+ element.rotate = Object.assign({}, firstCell.rotate);
107
+ elementUndo.rotate = elementUndo.rotate || (firstCell.rotate.angle === 270 ? { angle: 0 } : { angle: 270 });
108
+ }
106
109
  table_service_1.TableService.clearCell(element);
107
110
  }
108
111
  elementsToUpdate.push({ change: element, undo: elementUndo });
@@ -173,7 +176,10 @@ class TableMergeService {
173
176
  }
174
177
  for (const [rowId, height] of rowHeightsToUpdate) {
175
178
  const updatedRow = table_service_1.TableService.resizeRow(tableElement, childElements, rowId, height).elementsToUpdate[1];
179
+ const updatedColumnAndCells = table_service_1.TableService.autoFitColumns(tableElement, childElements, rowId).elementsToUpdate;
180
+ const uniqueUpdatedColumnAndCells = (0, documents_1.uniqueElementsToUpdate)(updatedColumnAndCells, elementsToUpdate);
176
181
  elementsToUpdate.push(updatedRow);
182
+ elementsToUpdate.push(...uniqueUpdatedColumnAndCells);
177
183
  }
178
184
  return {
179
185
  elementsToUpdate: [
@@ -24,6 +24,8 @@ class TablePasteService {
24
24
  const existingCells = childElements.filter((e) => e.type === 'cell');
25
25
  const elementsToCreate = [];
26
26
  const elementsToUpdate = [];
27
+ const columnWidthsToUpdate = new Map();
28
+ const rowHeightsToUpdate = new Map();
27
29
  let existingMergedRanges = table_merge_service_1.TableMergeService.getMergedRanges(tableElement, childElements);
28
30
  for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
29
31
  const rowToPaste = rowsToPaste[rowIndex - targetRow];
@@ -38,10 +40,9 @@ class TablePasteService {
38
40
  existingRow = newRow;
39
41
  this.log('added row', rowIndex, existingRowId, existingRow);
40
42
  }
41
- if (rowToPaste.size.height > existingRow.size.height) {
42
- this.log('resized row', rowIndex, existingRowId, existingRow);
43
- elementsToUpdate.push(table_service_1.TableService.resizeRow(tableElement, childElements, existingRowId, rowToPaste.size.height)
44
- .elementsToUpdate[1]);
43
+ if (rowToPaste.size.height > existingRow.size.height &&
44
+ (!rowHeightsToUpdate.has(existingRowId) || rowHeightsToUpdate.get(existingRowId) < rowToPaste.size.height)) {
45
+ rowHeightsToUpdate.set(existingRowId, rowToPaste.size.height);
45
46
  }
46
47
  for (let columnIndex = startColumn; columnIndex <= endColumn; columnIndex++) {
47
48
  const columnToPaste = columnsToPaste[columnIndex - targetColumn];
@@ -56,14 +57,10 @@ class TablePasteService {
56
57
  existingColumn = newColumn;
57
58
  this.log('added column', columnIndex, existingColumnId, existingColumn);
58
59
  }
59
- if (columnToPaste.size.width > existingColumn.size.width) {
60
- const updatedColumn = table_service_1.TableService.resizeColumn(tableElement, childElements, existingColumnId, columnToPaste.size.width).elementsToUpdate[1];
61
- const updatedRowAndCells = table_service_1.TableService.autoFitRows(tableElement, childElements, existingColumnId).elementsToUpdate;
62
- const uniqueUpdatedRowAndCells = (0, documents_1.uniqueElementsToUpdate)(updatedRowAndCells, elementsToUpdate);
63
- elementsToUpdate.push(updatedColumn);
64
- elementsToUpdate.push(...uniqueUpdatedRowAndCells);
65
- this.log('resized column', columnIndex, existingColumnId, existingColumn);
66
- this.log('resized column cells and row', uniqueUpdatedRowAndCells, uniqueUpdatedRowAndCells);
60
+ if (columnToPaste.size.width > existingColumn.size.width &&
61
+ (!columnWidthsToUpdate.has(existingColumnId) ||
62
+ columnWidthsToUpdate.get(existingColumnId) < columnToPaste.size.width)) {
63
+ columnWidthsToUpdate.set(existingColumnId, columnToPaste.size.width);
67
64
  }
68
65
  const cellToPaste = cellsToPaste.find((e) => e.rowId === rowToPaste.id && e.columnId === columnToPaste.id);
69
66
  if (!cellToPaste)
@@ -82,6 +79,20 @@ class TablePasteService {
82
79
  }
83
80
  }
84
81
  }
82
+ for (const [columnId, width] of columnWidthsToUpdate) {
83
+ const updatedColumn = table_service_1.TableService.resizeColumn(tableElement, childElements, columnId, width).elementsToUpdate[1];
84
+ const updatedRowAndCells = table_service_1.TableService.autoFitRows(tableElement, childElements, columnId).elementsToUpdate;
85
+ const uniqueUpdatedRowAndCells = (0, documents_1.uniqueElementsToUpdate)(updatedRowAndCells, elementsToUpdate);
86
+ elementsToUpdate.push(updatedColumn);
87
+ elementsToUpdate.push(...uniqueUpdatedRowAndCells);
88
+ }
89
+ for (const [rowId, height] of rowHeightsToUpdate) {
90
+ const updatedRow = table_service_1.TableService.resizeRow(tableElement, childElements, rowId, height).elementsToUpdate[1];
91
+ const updatedColumnAndCells = table_service_1.TableService.autoFitColumns(tableElement, childElements, rowId).elementsToUpdate;
92
+ const uniqueUpdatedColumnAndCells = (0, documents_1.uniqueElementsToUpdate)(updatedColumnAndCells, elementsToUpdate);
93
+ elementsToUpdate.push(updatedRow);
94
+ elementsToUpdate.push(...uniqueUpdatedColumnAndCells);
95
+ }
85
96
  return { elementsToCreate, elementsToUpdate };
86
97
  }
87
98
  static pasteTableCells(tableElement, childElements, elementsToPaste, targetRow, targetColumn) {
@@ -120,8 +131,10 @@ class TablePasteService {
120
131
  cell.style = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(table_service_1.TableService.DEFAULT_CELL_STYLE), util_1.ObjectUtil.cloneDeep(cellToPaste.style));
121
132
  cell.colspan = cellToPaste.colspan > 1 ? cellToPaste.colspan : 1;
122
133
  cell.rowspan = cellToPaste.rowspan > 1 ? cellToPaste.rowspan : 1;
123
- if (cellToPaste.rotate)
134
+ if (cellToPaste.rotate) {
124
135
  cell.rotate = Object.assign({}, cellToPaste.rotate);
136
+ cellUndo.rotate = cellUndo.rotate || (cellToPaste.rotate.angle === 270 ? { angle: 0 } : { angle: 270 });
137
+ }
125
138
  const cellMergedRanged = table_merge_service_1.TableMergeService.getMergedRange(tableElement, cell);
126
139
  if (table_service_1.TableService.isVerticalCell(cell)) {
127
140
  cell.size.height = cellMergedRanged
@@ -17,6 +17,7 @@ class TableRotateService {
17
17
  const cellUndo = util_1.ObjectUtil.cloneDeep(cell);
18
18
  cell.rotate = { angle };
19
19
  if (angle === 270) {
20
+ cellUndo.rotate = cellUndo.rotate || { angle: 0 };
20
21
  cell.size.height = row.size.height;
21
22
  cell.size.width = table_service_1.TableService.getCellSize(cell).height;
22
23
  if (cell.size.width > column.size.width) {
@@ -26,6 +27,7 @@ class TableRotateService {
26
27
  }
27
28
  }
28
29
  else {
30
+ cellUndo.rotate = cellUndo.rotate || { angle: 270 };
29
31
  cell.size.width = column.size.width;
30
32
  cell.size.height = table_service_1.TableService.getCellSize(cell).height;
31
33
  if (cell.size.height > row.size.height) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/document-table",
3
- "version": "1.0.6",
3
+ "version": "1.0.14",
4
4
  "description": "Library for document tables",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",