@contrail/document-table 1.0.1 → 1.0.3
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/lib/table-constants.d.ts +0 -8
- package/lib/table-constants.js +1 -9
- package/lib/table-copy.service.js +9 -10
- package/lib/table-merge.service.js +9 -9
- package/lib/table-paste.service.js +23 -24
- package/lib/table.service.d.ts +2 -0
- package/lib/table.service.js +26 -0
- package/package.json +2 -2
package/lib/table-constants.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
export declare const TABLE_ROW_MIN_HEIGHT = 28;
|
|
2
2
|
export declare const TABLE_COLUMN_MIN_WIDTH = 28;
|
|
3
|
-
export declare const TABLE_DRAG_HANDLE_WIDTH = 40;
|
|
4
|
-
export declare const TABLE_DRAG_HANDLE_HEIGHT = 20;
|
|
5
|
-
export declare const TABLE_DRAG_HANDLE_PADDING = 40;
|
|
6
|
-
export declare const TABLE_DRAG_HANDLE_RADIUS = 20;
|
|
7
|
-
export declare const TABLE_DRAG_HANDLE_ARROW_X = 3;
|
|
8
|
-
export declare const TABLE_DRAG_HANDLE_ARROW_Y = 4;
|
|
9
|
-
export declare const TABLE_DRAG_HANDLE_ARROW_LENGTH = 7;
|
|
10
|
-
export declare const TABLE_DRAG_HANDLE_ARROW_LINE_WIDTH = 2;
|
|
11
3
|
export declare const TABLE_CELL_WIDTH = 200;
|
|
12
4
|
export declare const TABLE_CELL_HEIGHT = 120;
|
|
13
5
|
export declare const TABLE_TEXT_PADDING = 5;
|
package/lib/table-constants.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TEXT_ALIGN = exports.TEXT_VALIGN = exports.DEFAULT_TEXT_FONT_SIZE = exports.DEFAULT_TEXT_FONT_FAMILY = exports.TRANSPARENT_COLOR = exports.TABLE_TEXT_PADDING = exports.TABLE_CELL_HEIGHT = exports.TABLE_CELL_WIDTH = exports.
|
|
3
|
+
exports.TEXT_ALIGN = exports.TEXT_VALIGN = exports.DEFAULT_TEXT_FONT_SIZE = exports.DEFAULT_TEXT_FONT_FAMILY = exports.TRANSPARENT_COLOR = exports.TABLE_TEXT_PADDING = exports.TABLE_CELL_HEIGHT = exports.TABLE_CELL_WIDTH = exports.TABLE_COLUMN_MIN_WIDTH = exports.TABLE_ROW_MIN_HEIGHT = void 0;
|
|
4
4
|
exports.TABLE_ROW_MIN_HEIGHT = 28;
|
|
5
5
|
exports.TABLE_COLUMN_MIN_WIDTH = 28;
|
|
6
|
-
exports.TABLE_DRAG_HANDLE_WIDTH = 40;
|
|
7
|
-
exports.TABLE_DRAG_HANDLE_HEIGHT = 20;
|
|
8
|
-
exports.TABLE_DRAG_HANDLE_PADDING = 40;
|
|
9
|
-
exports.TABLE_DRAG_HANDLE_RADIUS = 20;
|
|
10
|
-
exports.TABLE_DRAG_HANDLE_ARROW_X = 3;
|
|
11
|
-
exports.TABLE_DRAG_HANDLE_ARROW_Y = 4;
|
|
12
|
-
exports.TABLE_DRAG_HANDLE_ARROW_LENGTH = 7;
|
|
13
|
-
exports.TABLE_DRAG_HANDLE_ARROW_LINE_WIDTH = 2;
|
|
14
6
|
exports.TABLE_CELL_WIDTH = 200;
|
|
15
7
|
exports.TABLE_CELL_HEIGHT = 120;
|
|
16
8
|
exports.TABLE_TEXT_PADDING = 5;
|
|
@@ -11,7 +11,7 @@ class TableCopyService {
|
|
|
11
11
|
static copy(tableElement, childElements) {
|
|
12
12
|
const copiedChildElementIds = new Map();
|
|
13
13
|
const childElementsMap = new Map();
|
|
14
|
-
childElements.forEach(element => {
|
|
14
|
+
childElements.forEach((element) => {
|
|
15
15
|
childElementsMap.set(element.id, element);
|
|
16
16
|
});
|
|
17
17
|
const rowIds = [];
|
|
@@ -55,16 +55,16 @@ class TableCopyService {
|
|
|
55
55
|
columnIds.push(newElement.id);
|
|
56
56
|
newChildElements.push(newElement);
|
|
57
57
|
}
|
|
58
|
-
const cellElements = childElements.filter(e => e.type === 'cell');
|
|
58
|
+
const cellElements = childElements.filter((e) => e.type === 'cell');
|
|
59
59
|
if (cellElements.length < tableElement.rowIds.length * tableElement.columnIds.length) {
|
|
60
60
|
for (let i = 0; i < tableElement.rowIds.length; i++) {
|
|
61
61
|
for (let j = 0; j < tableElement.columnIds.length; j++) {
|
|
62
62
|
const rowId = tableElement.rowIds[i];
|
|
63
63
|
const columnId = tableElement.columnIds[j];
|
|
64
|
-
const cellElement = cellElements.find(e => e.type === 'cell' && e.rowId === rowId && e.columnId === columnId);
|
|
64
|
+
const cellElement = cellElements.find((e) => e.type === 'cell' && e.rowId === rowId && e.columnId === columnId);
|
|
65
65
|
if (!cellElement) {
|
|
66
|
-
const row = childElements.find(e => e.id === rowId);
|
|
67
|
-
const column = childElements.find(e => e.id === columnId);
|
|
66
|
+
const row = childElements.find((e) => e.id === rowId);
|
|
67
|
+
const column = childElements.find((e) => e.id === columnId);
|
|
68
68
|
cellElements.push((0, table_service_1.createCell)({
|
|
69
69
|
rowId,
|
|
70
70
|
columnId,
|
|
@@ -110,7 +110,7 @@ class TableCopyService {
|
|
|
110
110
|
const tableId = (0, nanoid_1.nanoid)(16);
|
|
111
111
|
let width = 0, height = 0;
|
|
112
112
|
let startRow, endRow, startColumn, endColumn;
|
|
113
|
-
cells.forEach(cell => {
|
|
113
|
+
cells.forEach((cell) => {
|
|
114
114
|
const rowIndex = element.rowIds.indexOf(cell.rowId);
|
|
115
115
|
const columnIndex = element.columnIds.indexOf(cell.columnId);
|
|
116
116
|
const isNotSet = startRow == undefined;
|
|
@@ -124,8 +124,8 @@ class TableCopyService {
|
|
|
124
124
|
endColumn = columnIndex;
|
|
125
125
|
existingCellsMap.set(`${rowIndex}_${columnIndex}`, cell);
|
|
126
126
|
});
|
|
127
|
-
const skipRows = Array.from({ length: endRow - startRow + 1 }, (value, index) => startRow + index).filter(i => !Array.from(existingCellsMap.keys()).find(v => v.startsWith(`${i}_`)));
|
|
128
|
-
const skipColumns = Array.from({ length: endColumn - startColumn + 1 }, (value, index) => startColumn + index).filter(j => !Array.from(existingCellsMap.keys()).find(v => v.endsWith(`_${j}`)));
|
|
127
|
+
const skipRows = Array.from({ length: endRow - startRow + 1 }, (value, index) => startRow + index).filter((i) => !Array.from(existingCellsMap.keys()).find((v) => v.startsWith(`${i}_`)));
|
|
128
|
+
const skipColumns = Array.from({ length: endColumn - startColumn + 1 }, (value, index) => startColumn + index).filter((j) => !Array.from(existingCellsMap.keys()).find((v) => v.endsWith(`_${j}`)));
|
|
129
129
|
for (let i = startRow; i <= endRow; i++) {
|
|
130
130
|
if (skipRows.indexOf(i) !== -1)
|
|
131
131
|
continue;
|
|
@@ -275,8 +275,7 @@ class TableCopyService {
|
|
|
275
275
|
var _a, _b, _c, _d, _e, _f;
|
|
276
276
|
const fontFamily = `${(_c = (_b = (_a = cellElement.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.family) !== null && _c !== void 0 ? _c : table_constants_1.DEFAULT_TEXT_FONT_FAMILY}`;
|
|
277
277
|
const fontSize = `${(_f = (_e = (_d = cellElement.style) === null || _d === void 0 ? void 0 : _d.font) === null || _e === void 0 ? void 0 : _e.size) !== null && _f !== void 0 ? _f : table_constants_1.DEFAULT_TEXT_FONT_SIZE}pt`;
|
|
278
|
-
const size = table_service_1.TableService.getSize(cellElement.text, `width: ${cellElement.size.width -
|
|
279
|
-
table_constants_1.TABLE_TEXT_PADDING * 2}px; height: auto; font-family: ${fontFamily}; font-size: ${fontSize};`);
|
|
278
|
+
const size = table_service_1.TableService.getSize(cellElement.text, `width: ${cellElement.size.width - table_constants_1.TABLE_TEXT_PADDING * 2}px; height: auto; font-family: ${fontFamily}; font-size: ${fontSize};`);
|
|
280
279
|
const documentElement = {
|
|
281
280
|
isTextTool: true,
|
|
282
281
|
text: cellElement.text,
|
|
@@ -33,7 +33,7 @@ class TableMergeService {
|
|
|
33
33
|
const rowId = tableElement.rowIds[i];
|
|
34
34
|
for (let j = columnIndex; j < columnIndex + ((_b = cell.colspan) !== null && _b !== void 0 ? _b : 1); j++) {
|
|
35
35
|
const columnId = tableElement.columnIds[j];
|
|
36
|
-
const mergedCell = childElements.find(e => e.type === 'cell' && e.columnId === columnId && e.rowId === rowId);
|
|
36
|
+
const mergedCell = childElements.find((e) => e.type === 'cell' && e.columnId === columnId && e.rowId === rowId);
|
|
37
37
|
if (mergedCell) {
|
|
38
38
|
mergedCells.push(mergedCell);
|
|
39
39
|
}
|
|
@@ -45,7 +45,7 @@ class TableMergeService {
|
|
|
45
45
|
static isValidRangeToMerge(tableElement, childElements, tableRange) {
|
|
46
46
|
if (tableRange.singular())
|
|
47
47
|
return false;
|
|
48
|
-
const mergedRanges = TableMergeService.getMergedRanges(tableElement, childElements).filter(range => range.intersects(tableRange) && !range.within(tableRange));
|
|
48
|
+
const mergedRanges = TableMergeService.getMergedRanges(tableElement, childElements).filter((range) => range.intersects(tableRange) && !range.within(tableRange));
|
|
49
49
|
return mergedRanges.length === 0;
|
|
50
50
|
}
|
|
51
51
|
static merge(tableElement, childElements, tableRange) {
|
|
@@ -59,7 +59,7 @@ class TableMergeService {
|
|
|
59
59
|
tableRange.each((rowIndex, columnIndex) => {
|
|
60
60
|
const rowId = tableElement.rowIds[rowIndex];
|
|
61
61
|
const columnId = tableElement.columnIds[columnIndex];
|
|
62
|
-
const element = childElements.find(e => e.type === 'cell' && e.columnId === columnId && e.rowId === rowId);
|
|
62
|
+
const element = childElements.find((e) => e.type === 'cell' && e.columnId === columnId && e.rowId === rowId);
|
|
63
63
|
if (element) {
|
|
64
64
|
const elementUndo = util_1.ObjectUtil.cloneDeep(element);
|
|
65
65
|
element.colspan = 1;
|
|
@@ -67,9 +67,9 @@ class TableMergeService {
|
|
|
67
67
|
if (tableRange.isStart(rowIndex, columnIndex)) {
|
|
68
68
|
firstCell = element;
|
|
69
69
|
let width = 0;
|
|
70
|
-
tableRange.eachColumn(columnIndex => {
|
|
70
|
+
tableRange.eachColumn((columnIndex) => {
|
|
71
71
|
const columnId = tableElement.columnIds[columnIndex];
|
|
72
|
-
const column = childElements.find(e => e.type === 'column' && e.id === columnId);
|
|
72
|
+
const column = childElements.find((e) => e.type === 'column' && e.id === columnId);
|
|
73
73
|
width = width + column.size.width;
|
|
74
74
|
});
|
|
75
75
|
if (colspan > 1) {
|
|
@@ -96,7 +96,7 @@ class TableMergeService {
|
|
|
96
96
|
}
|
|
97
97
|
static unmerge(tableElement, childElements, tableRange) {
|
|
98
98
|
const mergedRanges = TableMergeService.getMergedRanges(tableElement, childElements);
|
|
99
|
-
if (!mergedRanges.find(range => range.equals(tableRange)))
|
|
99
|
+
if (!mergedRanges.find((range) => range.equals(tableRange)))
|
|
100
100
|
throw new Error(table_service_1.TABLE_ERROR.INVALID_RANGE_TO_UNMERGE);
|
|
101
101
|
const tableUndo = Object.assign(Object.assign({}, (0, table_service_1.tableData)(tableElement)), { size: Object.assign({}, tableElement.size) });
|
|
102
102
|
const elementsToUpdate = [];
|
|
@@ -104,9 +104,9 @@ class TableMergeService {
|
|
|
104
104
|
tableRange.each((rowIndex, columnIndex) => {
|
|
105
105
|
const rowId = tableElement.rowIds[rowIndex];
|
|
106
106
|
const columnId = tableElement.columnIds[columnIndex];
|
|
107
|
-
const element = childElements.find(e => e.type === 'cell' && e.columnId === columnId && e.rowId === rowId);
|
|
108
|
-
const column = childElements.find(e => e.type === 'column' && e.id === columnId);
|
|
109
|
-
const row = childElements.find(e => e.type === 'row' && e.id === rowId);
|
|
107
|
+
const element = childElements.find((e) => e.type === 'cell' && e.columnId === columnId && e.rowId === rowId);
|
|
108
|
+
const column = childElements.find((e) => e.type === 'column' && e.id === columnId);
|
|
109
|
+
const row = childElements.find((e) => e.type === 'row' && e.id === rowId);
|
|
110
110
|
if (element && column && row) {
|
|
111
111
|
const elementUndo = util_1.ObjectUtil.cloneDeep(element);
|
|
112
112
|
element.colspan = 1;
|
|
@@ -13,23 +13,23 @@ class TablePasteService {
|
|
|
13
13
|
}
|
|
14
14
|
static pasteRowsAndColumns(tableElement, childElements, elementsToPaste, targetRow, targetColumn) {
|
|
15
15
|
var _a, _b, _c;
|
|
16
|
-
const tableToPaste = elementsToPaste.find(e => e.type === 'table');
|
|
17
|
-
const rowsToPaste = elementsToPaste.filter(e => e.type === 'row');
|
|
18
|
-
const columnsToPaste = elementsToPaste.filter(e => e.type === 'column');
|
|
19
|
-
const cellsToPaste = elementsToPaste.filter(e => e.type === 'cell');
|
|
16
|
+
const tableToPaste = elementsToPaste.find((e) => e.type === 'table');
|
|
17
|
+
const rowsToPaste = elementsToPaste.filter((e) => e.type === 'row');
|
|
18
|
+
const columnsToPaste = elementsToPaste.filter((e) => e.type === 'column');
|
|
19
|
+
const cellsToPaste = elementsToPaste.filter((e) => e.type === 'cell');
|
|
20
20
|
const startRow = targetRow;
|
|
21
21
|
const endRow = startRow + tableToPaste.rowIds.length - 1;
|
|
22
22
|
const startColumn = targetColumn;
|
|
23
23
|
const endColumn = startColumn + tableToPaste.columnIds.length - 1;
|
|
24
|
-
const existingCells = childElements.filter(e => e.type === 'cell');
|
|
24
|
+
const existingCells = childElements.filter((e) => e.type === 'cell');
|
|
25
25
|
const elementsToCreate = [];
|
|
26
26
|
const elementsToUpdate = [];
|
|
27
27
|
let existingMergedRanges = table_merge_service_1.TableMergeService.getMergedRanges(tableElement, childElements);
|
|
28
28
|
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
|
|
29
29
|
const rowToPaste = rowsToPaste[rowIndex - targetRow];
|
|
30
30
|
let existingRowId = tableElement.rowIds[rowIndex];
|
|
31
|
-
let existingRow = childElements.find(e => e.type === 'row' && e.id === existingRowId) ||
|
|
32
|
-
elementsToCreate.find(e => e.type === 'row' && e.id === existingRowId);
|
|
31
|
+
let existingRow = childElements.find((e) => e.type === 'row' && e.id === existingRowId) ||
|
|
32
|
+
elementsToCreate.find((e) => e.type === 'row' && e.id === existingRowId);
|
|
33
33
|
this.log('current row', rowIndex, existingRowId, existingRow);
|
|
34
34
|
if (!existingRowId) {
|
|
35
35
|
const [newRow, ...newRowCells] = (_a = table_service_1.TableService.addRow(tableElement, [...existingCells, ...elementsToCreate], rowIndex, rowToPaste.size.height)) === null || _a === void 0 ? void 0 : _a.elementsToCreate;
|
|
@@ -46,8 +46,8 @@ class TablePasteService {
|
|
|
46
46
|
for (let columnIndex = startColumn; columnIndex <= endColumn; columnIndex++) {
|
|
47
47
|
const columnToPaste = columnsToPaste[columnIndex - targetColumn];
|
|
48
48
|
let existingColumnId = tableElement.columnIds[columnIndex];
|
|
49
|
-
let existingColumn = childElements.find(e => e.type === 'column' && e.id === existingColumnId) ||
|
|
50
|
-
elementsToCreate.find(e => e.type === 'column' && e.id === existingColumnId);
|
|
49
|
+
let existingColumn = childElements.find((e) => e.type === 'column' && e.id === existingColumnId) ||
|
|
50
|
+
elementsToCreate.find((e) => e.type === 'column' && e.id === existingColumnId);
|
|
51
51
|
this.log('current column', columnIndex, existingColumnId, existingColumn);
|
|
52
52
|
if (!tableElement.columnIds[columnIndex]) {
|
|
53
53
|
const [newColumn, ...newColumnCells] = (_b = table_service_1.TableService.addColumn(tableElement, [...existingCells, ...elementsToCreate], columnIndex, columnToPaste.size.width)) === null || _b === void 0 ? void 0 : _b.elementsToCreate;
|
|
@@ -58,22 +58,21 @@ class TablePasteService {
|
|
|
58
58
|
}
|
|
59
59
|
if (columnToPaste.size.width > existingColumn.size.width) {
|
|
60
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)
|
|
62
|
-
.elementsToUpdate;
|
|
61
|
+
const updatedRowAndCells = table_service_1.TableService.autoFitRows(tableElement, childElements, existingColumnId).elementsToUpdate;
|
|
63
62
|
const uniqueUpdatedRowAndCells = (0, documents_1.uniqueElementsToUpdate)(updatedRowAndCells, elementsToUpdate);
|
|
64
63
|
elementsToUpdate.push(updatedColumn);
|
|
65
64
|
elementsToUpdate.push(...uniqueUpdatedRowAndCells);
|
|
66
65
|
this.log('resized column', columnIndex, existingColumnId, existingColumn);
|
|
67
66
|
this.log('resized column cells and row', uniqueUpdatedRowAndCells, uniqueUpdatedRowAndCells);
|
|
68
67
|
}
|
|
69
|
-
const cellToPaste = cellsToPaste.find(e => e.rowId === rowToPaste.id && e.columnId === columnToPaste.id);
|
|
68
|
+
const cellToPaste = cellsToPaste.find((e) => e.rowId === rowToPaste.id && e.columnId === columnToPaste.id);
|
|
70
69
|
if (!cellToPaste)
|
|
71
70
|
continue;
|
|
72
71
|
const cellRange = new table_range_1.TableRange(rowIndex, rowIndex, columnIndex, columnIndex);
|
|
73
|
-
const mergedRange = existingMergedRanges.find(range => range.intersects(cellRange));
|
|
72
|
+
const mergedRange = existingMergedRanges.find((range) => range.intersects(cellRange));
|
|
74
73
|
const mergedRangeOther = mergedRange && !cellRange.equals(mergedRange.start());
|
|
75
74
|
if (mergedRange) {
|
|
76
|
-
existingMergedRanges = existingMergedRanges.filter(r => !r.equals(mergedRange));
|
|
75
|
+
existingMergedRanges = existingMergedRanges.filter((r) => !r.equals(mergedRange));
|
|
77
76
|
}
|
|
78
77
|
if (mergedRangeOther) {
|
|
79
78
|
const [updatedTable, ...unmergedCellAndRow] = (_c = table_merge_service_1.TableMergeService.unmerge(tableElement, childElements, mergedRange)) === null || _c === void 0 ? void 0 : _c.elementsToUpdate;
|
|
@@ -86,15 +85,15 @@ class TablePasteService {
|
|
|
86
85
|
return { elementsToCreate, elementsToUpdate };
|
|
87
86
|
}
|
|
88
87
|
static pasteTableCells(tableElement, childElements, elementsToPaste, targetRow, targetColumn) {
|
|
89
|
-
const tableToPaste = elementsToPaste.find(e => e.type === 'table');
|
|
90
|
-
const rowsToPaste = elementsToPaste.filter(e => e.type === 'row');
|
|
91
|
-
const columnsToPaste = elementsToPaste.filter(e => e.type === 'column');
|
|
92
|
-
const cellsToPaste = elementsToPaste.filter(e => e.type === 'cell');
|
|
88
|
+
const tableToPaste = elementsToPaste.find((e) => e.type === 'table');
|
|
89
|
+
const rowsToPaste = elementsToPaste.filter((e) => e.type === 'row');
|
|
90
|
+
const columnsToPaste = elementsToPaste.filter((e) => e.type === 'column');
|
|
91
|
+
const cellsToPaste = elementsToPaste.filter((e) => e.type === 'cell');
|
|
93
92
|
const startRow = targetRow;
|
|
94
93
|
const endRow = startRow + tableToPaste.rowIds.length - 1;
|
|
95
94
|
const startColumn = targetColumn;
|
|
96
95
|
const endColumn = startColumn + tableToPaste.columnIds.length - 1;
|
|
97
|
-
const existingCells = childElements.filter(e => e.type === 'cell');
|
|
96
|
+
const existingCells = childElements.filter((e) => e.type === 'cell');
|
|
98
97
|
const tableUndo = util_1.ObjectUtil.cloneDeep(tableElement);
|
|
99
98
|
const { elementsToUpdate, elementsToCreate } = TablePasteService.pasteRowsAndColumns(tableElement, childElements, elementsToPaste, targetRow, targetColumn);
|
|
100
99
|
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
|
|
@@ -103,13 +102,13 @@ class TablePasteService {
|
|
|
103
102
|
for (let columnIndex = startColumn; columnIndex <= endColumn; columnIndex++) {
|
|
104
103
|
const columnToPaste = columnsToPaste[columnIndex - targetColumn];
|
|
105
104
|
const existingColumnId = tableElement.columnIds[columnIndex];
|
|
106
|
-
const existingColumn = childElements.find(e => e.type === 'column' && e.id === existingColumnId) ||
|
|
107
|
-
elementsToCreate.find(e => e.type === 'column' && e.id === existingColumnId);
|
|
108
|
-
const cellToPaste = cellsToPaste.find(e => e.rowId === rowToPaste.id && e.columnId === columnToPaste.id);
|
|
105
|
+
const existingColumn = childElements.find((e) => e.type === 'column' && e.id === existingColumnId) ||
|
|
106
|
+
elementsToCreate.find((e) => e.type === 'column' && e.id === existingColumnId);
|
|
107
|
+
const cellToPaste = cellsToPaste.find((e) => e.rowId === rowToPaste.id && e.columnId === columnToPaste.id);
|
|
109
108
|
if (!cellToPaste)
|
|
110
109
|
continue;
|
|
111
|
-
const createdCell = elementsToCreate.find(e => e.type === 'cell' && e.rowId === existingRowId && e.columnId === existingColumnId);
|
|
112
|
-
const existingCell = existingCells.find(e => e.rowId === existingRowId && e.columnId === existingColumnId);
|
|
110
|
+
const createdCell = elementsToCreate.find((e) => e.type === 'cell' && e.rowId === existingRowId && e.columnId === existingColumnId);
|
|
111
|
+
const existingCell = existingCells.find((e) => e.rowId === existingRowId && e.columnId === existingColumnId);
|
|
113
112
|
const cell = createdCell !== null && createdCell !== void 0 ? createdCell : existingCell;
|
|
114
113
|
const cellUndo = util_1.ObjectUtil.cloneDeep(cell);
|
|
115
114
|
this.log('cell to paste', cellToPaste);
|
package/lib/table.service.d.ts
CHANGED
|
@@ -39,4 +39,6 @@ export declare class TableService {
|
|
|
39
39
|
static clearCell(element: DocumentElement): void;
|
|
40
40
|
static getCellSize(element: DocumentElement, text?: string): SizeDefinition;
|
|
41
41
|
static getSize(text: string, style: string): SizeDefinition;
|
|
42
|
+
getTableChildElements(tableId: string, elements: DocumentElement[]): DocumentElement[];
|
|
43
|
+
static updateCellText(tableElement: DocumentElement, childElements: DocumentElement[], rowIndex: number, columnIndex: number, text: string): DocumentElementChanges;
|
|
42
44
|
}
|
package/lib/table.service.js
CHANGED
|
@@ -615,6 +615,32 @@ class TableService {
|
|
|
615
615
|
div = null;
|
|
616
616
|
return { width, height };
|
|
617
617
|
}
|
|
618
|
+
getTableChildElements(tableId, elements) {
|
|
619
|
+
return elements.filter(e => e.tableId === tableId && ['cell', 'column', 'row'].indexOf(e.type) !== -1);
|
|
620
|
+
}
|
|
621
|
+
static updateCellText(tableElement, childElements, rowIndex, columnIndex, text) {
|
|
622
|
+
const rowId = tableElement.rowIds[rowIndex];
|
|
623
|
+
const columnId = tableElement.columnIds[columnIndex];
|
|
624
|
+
const cell = childElements.find(e => e.type === 'cell' && e.rowId === rowId && e.columnId === columnId);
|
|
625
|
+
const row = childElements.find(e => e.type === 'row' && e.id === rowId);
|
|
626
|
+
if (!rowId || !columnId || !cell || !row) {
|
|
627
|
+
throw new Error(TABLE_ERROR.INVALID_TABLE);
|
|
628
|
+
}
|
|
629
|
+
const elementsToUpdate = [];
|
|
630
|
+
const cellUndo = Object.assign(Object.assign({}, tableData(cell)), { text: cell.text, size: Object.assign({}, cell.size) });
|
|
631
|
+
cell.text = text;
|
|
632
|
+
cell.size.height = TableService.getCellSize(cell).height;
|
|
633
|
+
elementsToUpdate.push({
|
|
634
|
+
change: Object.assign(Object.assign({}, tableData(cell)), { text: cell.text, size: cell.size }),
|
|
635
|
+
undo: cellUndo,
|
|
636
|
+
});
|
|
637
|
+
if (cell.size.height > row.size.height) {
|
|
638
|
+
elementsToUpdate.push(...TableService.resizeRow(tableElement, childElements, rowId, cell.size.height).elementsToUpdate);
|
|
639
|
+
}
|
|
640
|
+
return {
|
|
641
|
+
elementsToUpdate,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
618
644
|
}
|
|
619
645
|
exports.TableService = TableService;
|
|
620
646
|
TableService.DEFAULT_CELL_STYLE = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/document-table",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Library for document tables",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@contrail/actions": "^1.0.14",
|
|
42
|
-
"@contrail/documents": "^1.0.
|
|
42
|
+
"@contrail/documents": "^1.0.109",
|
|
43
43
|
"@contrail/types": "^3.0.71",
|
|
44
44
|
"@contrail/util": "^1.0.65",
|
|
45
45
|
"reflect-metadata": "^0.1.13"
|