@contrail/document-table 1.0.19 → 1.0.20-beta.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.
- package/lib/table-copy.service.js +10 -11
- package/lib/table-member-paste.service.js +56 -96
- package/lib/table-paste.service.js +27 -27
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ class TableCopyService {
|
|
|
12
12
|
static copy(tableElement, childElements) {
|
|
13
13
|
const copiedChildElementIds = new Map();
|
|
14
14
|
const childElementsMap = new Map();
|
|
15
|
-
childElements.forEach(element => {
|
|
15
|
+
childElements.forEach((element) => {
|
|
16
16
|
childElementsMap.set(element.id, element);
|
|
17
17
|
});
|
|
18
18
|
const rowIds = [];
|
|
@@ -56,16 +56,16 @@ class TableCopyService {
|
|
|
56
56
|
columnIds.push(newElement.id);
|
|
57
57
|
newChildElements.push(newElement);
|
|
58
58
|
}
|
|
59
|
-
const cellElements = childElements.filter(e => e.type === 'cell');
|
|
59
|
+
const cellElements = childElements.filter((e) => e.type === 'cell');
|
|
60
60
|
if (cellElements.length < tableElement.rowIds.length * tableElement.columnIds.length) {
|
|
61
61
|
for (let i = 0; i < tableElement.rowIds.length; i++) {
|
|
62
62
|
for (let j = 0; j < tableElement.columnIds.length; j++) {
|
|
63
63
|
const rowId = tableElement.rowIds[i];
|
|
64
64
|
const columnId = tableElement.columnIds[j];
|
|
65
|
-
const cellElement = cellElements.find(e => e.type === 'cell' && e.rowId === rowId && e.columnId === columnId);
|
|
65
|
+
const cellElement = cellElements.find((e) => e.type === 'cell' && e.rowId === rowId && e.columnId === columnId);
|
|
66
66
|
if (!cellElement) {
|
|
67
|
-
const row = childElements.find(e => e.id === rowId);
|
|
68
|
-
const column = childElements.find(e => e.id === columnId);
|
|
67
|
+
const row = childElements.find((e) => e.id === rowId);
|
|
68
|
+
const column = childElements.find((e) => e.id === columnId);
|
|
69
69
|
cellElements.push((0, table_service_1.createCell)({
|
|
70
70
|
rowId,
|
|
71
71
|
columnId,
|
|
@@ -112,7 +112,7 @@ class TableCopyService {
|
|
|
112
112
|
const tableId = (0, nanoid_1.nanoid)(16);
|
|
113
113
|
let width = 0, height = 0;
|
|
114
114
|
let startRow, endRow, startColumn, endColumn;
|
|
115
|
-
cells.forEach(cell => {
|
|
115
|
+
cells.forEach((cell) => {
|
|
116
116
|
const rowIndex = element.rowIds.indexOf(cell.rowId);
|
|
117
117
|
const columnIndex = element.columnIds.indexOf(cell.columnId);
|
|
118
118
|
const isNotSet = startRow == undefined;
|
|
@@ -126,8 +126,8 @@ class TableCopyService {
|
|
|
126
126
|
endColumn = columnIndex;
|
|
127
127
|
existingCellsMap.set(`${rowIndex}_${columnIndex}`, cell);
|
|
128
128
|
});
|
|
129
|
-
const skipRows = Array.from({ length: endRow - startRow + 1 }, (value, index) => startRow + index).filter(i => !Array.from(existingCellsMap.keys()).find(v => v.startsWith(`${i}_`)));
|
|
130
|
-
const skipColumns = Array.from({ length: endColumn - startColumn + 1 }, (value, index) => startColumn + index).filter(j => !Array.from(existingCellsMap.keys()).find(v => v.endsWith(`_${j}`)));
|
|
129
|
+
const skipRows = Array.from({ length: endRow - startRow + 1 }, (value, index) => startRow + index).filter((i) => !Array.from(existingCellsMap.keys()).find((v) => v.startsWith(`${i}_`)));
|
|
130
|
+
const skipColumns = Array.from({ length: endColumn - startColumn + 1 }, (value, index) => startColumn + index).filter((j) => !Array.from(existingCellsMap.keys()).find((v) => v.endsWith(`_${j}`)));
|
|
131
131
|
for (let i = startRow; i <= endRow; i++) {
|
|
132
132
|
if (skipRows.indexOf(i) !== -1)
|
|
133
133
|
continue;
|
|
@@ -197,7 +197,7 @@ class TableCopyService {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
-
const { columns: existingColumns, rows: existingRows } = table_state_service_1.TableStateService.buildChildElementsState(element, new Map([...columns, ...rows].map(e => [e.id, e])), []);
|
|
200
|
+
const { columns: existingColumns, rows: existingRows } = table_state_service_1.TableStateService.buildChildElementsState(element, new Map([...columns, ...rows].map((e) => [e.id, e])), []);
|
|
201
201
|
const tableElement = {
|
|
202
202
|
type: 'table',
|
|
203
203
|
id: tableId,
|
|
@@ -282,8 +282,7 @@ class TableCopyService {
|
|
|
282
282
|
var _a, _b, _c, _d, _e, _f;
|
|
283
283
|
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}`;
|
|
284
284
|
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`;
|
|
285
|
-
const size = table_service_1.TableService.getSize(cellElement.text, `width: ${cellElement.size.width -
|
|
286
|
-
table_constants_1.TABLE_TEXT_PADDING * 2}px; height: auto; font-family: ${fontFamily}; font-size: ${fontSize};`);
|
|
285
|
+
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};`);
|
|
287
286
|
const documentElement = {
|
|
288
287
|
isTextTool: true,
|
|
289
288
|
text: cellElement.text,
|
|
@@ -1,100 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TableMemberPasteService = void 0;
|
|
4
|
-
const table_merge_service_1 = require("./table-merge.service");
|
|
5
4
|
const table_state_service_1 = require("./table-state.service");
|
|
6
|
-
const
|
|
7
|
-
const nanoid_1 = require("nanoid");
|
|
5
|
+
const documents_1 = require("@contrail/documents");
|
|
8
6
|
class TableMemberPasteService {
|
|
9
7
|
static detectMemberships(tableEl, structureEls, memberCandidates) {
|
|
10
8
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
11
9
|
const result = new Map();
|
|
12
10
|
if (!tableEl || !memberCandidates.length)
|
|
13
11
|
return result;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const tableY = (_f = (_e = tableEl.position) === null || _e === void 0 ? void 0 : _e.y) !== null && _f !== void 0 ? _f : 0;
|
|
21
|
-
const rowIds = (_g = tableEl.rowIds) !== null && _g !== void 0 ? _g : [];
|
|
22
|
-
const columnIds = (_h = tableEl.columnIds) !== null && _h !== void 0 ? _h : [];
|
|
12
|
+
const tableState = table_state_service_1.TableStateService.createTableState(tableEl, structureEls, 0);
|
|
13
|
+
const rowIds = (_a = tableEl.rowIds) !== null && _a !== void 0 ? _a : [];
|
|
14
|
+
const columnIds = (_b = tableEl.columnIds) !== null && _b !== void 0 ? _b : [];
|
|
15
|
+
const scale = (_d = (_c = tableEl.scale) === null || _c === void 0 ? void 0 : _c.x) !== null && _d !== void 0 ? _d : 1;
|
|
16
|
+
const tableX = (_f = (_e = tableEl.position) === null || _e === void 0 ? void 0 : _e.x) !== null && _f !== void 0 ? _f : 0;
|
|
17
|
+
const tableY = (_h = (_g = tableEl.position) === null || _g === void 0 ? void 0 : _g.y) !== null && _h !== void 0 ? _h : 0;
|
|
23
18
|
for (const member of memberCandidates) {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
let cy;
|
|
27
|
-
let anchorX;
|
|
28
|
-
let anchorY;
|
|
29
|
-
if (isLine && member.lineDefinition) {
|
|
30
|
-
const { x1, y1, x2, y2 } = member.lineDefinition;
|
|
31
|
-
cx = (x1 + x2) / 2;
|
|
32
|
-
cy = (y1 + y2) / 2;
|
|
33
|
-
anchorX = x1;
|
|
34
|
-
anchorY = y1;
|
|
35
|
-
}
|
|
36
|
-
else if (member.position && member.size) {
|
|
37
|
-
cx = member.position.x + member.size.width / 2;
|
|
38
|
-
cy = member.position.y + member.size.height / 2;
|
|
39
|
-
anchorX = member.position.x;
|
|
40
|
-
anchorY = member.position.y;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
19
|
+
const viewBox = documents_1.DocumentElementFactory.getBoundingClientRect(member);
|
|
20
|
+
if (!viewBox)
|
|
43
21
|
continue;
|
|
22
|
+
const elementBox = table_state_service_1.TableStateService.getTableMemberCoordinateBox(viewBox);
|
|
23
|
+
const cellEl = table_state_service_1.TableStateService.getOverlappedCell(tableState, elementBox);
|
|
24
|
+
if (!cellEl)
|
|
25
|
+
continue;
|
|
26
|
+
const gridRow = rowIds.indexOf(cellEl.rowId);
|
|
27
|
+
const gridCol = columnIds.indexOf(cellEl.columnId);
|
|
28
|
+
if (gridRow === -1 || gridCol === -1)
|
|
29
|
+
continue;
|
|
30
|
+
const cellState = tableState.cells.get(cellEl.id);
|
|
31
|
+
if (!cellState)
|
|
32
|
+
continue;
|
|
33
|
+
const isLine = member.type === 'line' && !!member.lineDefinition;
|
|
34
|
+
const anchorX = isLine ? member.lineDefinition.x1 : viewBox.x;
|
|
35
|
+
const anchorY = isLine ? member.lineDefinition.y1 : viewBox.y;
|
|
36
|
+
const offsetX = (anchorX - tableX) / scale - cellState.x;
|
|
37
|
+
const offsetY = (anchorY - tableY) / scale - cellState.y;
|
|
38
|
+
const entry = { gridRow, gridCol, offsetX, offsetY };
|
|
39
|
+
if (isLine) {
|
|
40
|
+
entry.lineDx = member.lineDefinition.x2 - member.lineDefinition.x1;
|
|
41
|
+
entry.lineDy = member.lineDefinition.y2 - member.lineDefinition.y1;
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
if (cellState.isMerged)
|
|
47
|
-
continue;
|
|
48
|
-
const cellLeft = tableX + cellState.x * scale;
|
|
49
|
-
const cellRight = cellLeft + cellState.width * scale;
|
|
50
|
-
const cellTop = tableY + cellState.y * scale;
|
|
51
|
-
const cellBottom = cellTop + cellState.height * scale;
|
|
52
|
-
const inBox = cx > cellLeft && cx < cellRight && cy > cellTop && cy < cellBottom;
|
|
53
|
-
if (!inBox)
|
|
54
|
-
continue;
|
|
55
|
-
const cellEl = childElementsMap.get(cellId);
|
|
56
|
-
if (!cellEl)
|
|
57
|
-
break;
|
|
58
|
-
const gridRow = rowIds.indexOf(cellEl.rowId);
|
|
59
|
-
const gridCol = columnIds.indexOf(cellEl.columnId);
|
|
60
|
-
if (gridRow === -1 || gridCol === -1)
|
|
61
|
-
break;
|
|
62
|
-
const unscaledAnchorX = (anchorX - tableX) / scale;
|
|
63
|
-
const unscaledAnchorY = (anchorY - tableY) / scale;
|
|
64
|
-
const offsetX = unscaledAnchorX - cellState.x;
|
|
65
|
-
const offsetY = unscaledAnchorY - cellState.y;
|
|
66
|
-
const entry = { gridRow, gridCol, offsetX, offsetY };
|
|
67
|
-
if (isLine && member.lineDefinition) {
|
|
68
|
-
entry.lineDx = member.lineDefinition.x2 - member.lineDefinition.x1;
|
|
69
|
-
entry.lineDy = member.lineDefinition.y2 - member.lineDefinition.y1;
|
|
70
|
-
}
|
|
71
|
-
result.set(member.id, entry);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
43
|
+
result.set(member.id, entry);
|
|
74
44
|
}
|
|
75
45
|
return result;
|
|
76
46
|
}
|
|
77
47
|
static resolveMemberPositions(memberships, memberElements, targetTableEl, targetChildEls, targetRow, targetCol) {
|
|
78
48
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
79
|
-
const newElements = [];
|
|
80
49
|
if (!memberships.size)
|
|
81
|
-
return
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
cellByRowCol.set(`${el.rowId}-${el.columnId}`, el);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
for (const member of memberElements) {
|
|
50
|
+
return [];
|
|
51
|
+
const tableState = table_state_service_1.TableStateService.createTableState(targetTableEl, targetChildEls, 0);
|
|
52
|
+
const rowIds = (_a = targetTableEl.rowIds) !== null && _a !== void 0 ? _a : [];
|
|
53
|
+
const columnIds = (_b = targetTableEl.columnIds) !== null && _b !== void 0 ? _b : [];
|
|
54
|
+
const scale = (_d = (_c = targetTableEl.scale) === null || _c === void 0 ? void 0 : _c.x) !== null && _d !== void 0 ? _d : 1;
|
|
55
|
+
const tableX = (_f = (_e = targetTableEl.position) === null || _e === void 0 ? void 0 : _e.x) !== null && _f !== void 0 ? _f : 0;
|
|
56
|
+
const tableY = (_h = (_g = targetTableEl.position) === null || _g === void 0 ? void 0 : _g.y) !== null && _h !== void 0 ? _h : 0;
|
|
57
|
+
const eligibleMembers = memberElements.filter((m) => memberships.has(m.id));
|
|
58
|
+
const { newElements } = documents_1.DocumentElementFactory.copyElements(eligibleMembers, targetTableEl.documentId);
|
|
59
|
+
const result = [];
|
|
60
|
+
for (let i = 0; i < eligibleMembers.length; i++) {
|
|
61
|
+
const member = eligibleMembers[i];
|
|
62
|
+
const newEl = newElements[i];
|
|
98
63
|
const entry = memberships.get(member.id);
|
|
99
64
|
if (!entry)
|
|
100
65
|
continue;
|
|
@@ -103,32 +68,27 @@ class TableMemberPasteService {
|
|
|
103
68
|
const targetColId = columnIds[targetCol + gridCol];
|
|
104
69
|
if (!targetRowId || !targetColId)
|
|
105
70
|
continue;
|
|
106
|
-
const
|
|
107
|
-
if (!
|
|
71
|
+
const cellEl = tableState.childElementsMap.get(`${targetRowId}-${targetColId}`);
|
|
72
|
+
if (!cellEl)
|
|
108
73
|
continue;
|
|
109
|
-
const
|
|
110
|
-
if (!
|
|
74
|
+
const cellState = tableState.cells.get(cellEl.id);
|
|
75
|
+
if (!cellState)
|
|
111
76
|
continue;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (isLine && member.lineDefinition) {
|
|
116
|
-
const newX1 = tableX + (targetCellState.x + offsetX) * scale;
|
|
117
|
-
const newY1 = tableY + (targetCellState.y + offsetY) * scale;
|
|
77
|
+
if (member.type === 'line' && member.lineDefinition) {
|
|
78
|
+
const newX1 = tableX + (cellState.x + offsetX) * scale;
|
|
79
|
+
const newY1 = tableY + (cellState.y + offsetY) * scale;
|
|
118
80
|
const newX2 = newX1 + ((_j = entry.lineDx) !== null && _j !== void 0 ? _j : 0);
|
|
119
81
|
const newY2 = newY1 + ((_k = entry.lineDy) !== null && _k !== void 0 ? _k : 0);
|
|
120
82
|
newEl.lineDefinition = Object.assign(Object.assign({}, newEl.lineDefinition), { x1: newX1, y1: newY1, x2: newX2, y2: newY2 });
|
|
121
83
|
if ((_l = newEl.points) === null || _l === void 0 ? void 0 : _l.length) {
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const dx = newX1 - oldX1;
|
|
125
|
-
const dy = newY1 - oldY1;
|
|
84
|
+
const dx = newX1 - member.lineDefinition.x1;
|
|
85
|
+
const dy = newY1 - member.lineDefinition.y1;
|
|
126
86
|
newEl.points = newEl.points.map((p) => [p[0] + dx, p[1] + dy]);
|
|
127
87
|
}
|
|
128
88
|
}
|
|
129
89
|
else {
|
|
130
|
-
const newX = tableX + (
|
|
131
|
-
const newY = tableY + (
|
|
90
|
+
const newX = tableX + (cellState.x + offsetX) * scale;
|
|
91
|
+
const newY = tableY + (cellState.y + offsetY) * scale;
|
|
132
92
|
if (((_m = newEl.points) === null || _m === void 0 ? void 0 : _m.length) && member.position) {
|
|
133
93
|
const dx = newX - member.position.x;
|
|
134
94
|
const dy = newY - member.position.y;
|
|
@@ -136,9 +96,9 @@ class TableMemberPasteService {
|
|
|
136
96
|
}
|
|
137
97
|
newEl.position = { x: newX, y: newY };
|
|
138
98
|
}
|
|
139
|
-
|
|
99
|
+
result.push(newEl);
|
|
140
100
|
}
|
|
141
|
-
return
|
|
101
|
+
return result;
|
|
142
102
|
}
|
|
143
103
|
}
|
|
144
104
|
exports.TableMemberPasteService = TableMemberPasteService;
|
|
@@ -16,15 +16,15 @@ class TablePasteService {
|
|
|
16
16
|
}
|
|
17
17
|
static pasteRowsAndColumns(tableElement, childElements, elementsToPaste, targetRow, targetColumn) {
|
|
18
18
|
var _a, _b, _c;
|
|
19
|
-
const tableToPaste = elementsToPaste.find(e => e.type === 'table');
|
|
20
|
-
const rowsToPaste = elementsToPaste.filter(e => e.type === 'row');
|
|
21
|
-
const columnsToPaste = elementsToPaste.filter(e => e.type === 'column');
|
|
22
|
-
const cellsToPaste = elementsToPaste.filter(e => e.type === 'cell');
|
|
19
|
+
const tableToPaste = elementsToPaste.find((e) => e.type === 'table');
|
|
20
|
+
const rowsToPaste = elementsToPaste.filter((e) => e.type === 'row');
|
|
21
|
+
const columnsToPaste = elementsToPaste.filter((e) => e.type === 'column');
|
|
22
|
+
const cellsToPaste = elementsToPaste.filter((e) => e.type === 'cell');
|
|
23
23
|
const startRow = targetRow;
|
|
24
24
|
const endRow = startRow + tableToPaste.rowIds.length - 1;
|
|
25
25
|
const startColumn = targetColumn;
|
|
26
26
|
const endColumn = startColumn + tableToPaste.columnIds.length - 1;
|
|
27
|
-
const existingCells = childElements.filter(e => e.type === 'cell');
|
|
27
|
+
const existingCells = childElements.filter((e) => e.type === 'cell');
|
|
28
28
|
const elementsToCreate = [];
|
|
29
29
|
const elementsToUpdate = [];
|
|
30
30
|
const columnWidthsToUpdate = new Map();
|
|
@@ -33,8 +33,8 @@ class TablePasteService {
|
|
|
33
33
|
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
|
|
34
34
|
const rowToPaste = rowsToPaste[rowIndex - targetRow];
|
|
35
35
|
let existingRowId = tableElement.rowIds[rowIndex];
|
|
36
|
-
let existingRow = childElements.find(e => e.type === 'row' && e.id === existingRowId) ||
|
|
37
|
-
elementsToCreate.find(e => e.type === 'row' && e.id === existingRowId);
|
|
36
|
+
let existingRow = childElements.find((e) => e.type === 'row' && e.id === existingRowId) ||
|
|
37
|
+
elementsToCreate.find((e) => e.type === 'row' && e.id === existingRowId);
|
|
38
38
|
this.log('current row', rowIndex, existingRowId, existingRow);
|
|
39
39
|
if (!existingRowId) {
|
|
40
40
|
const [newRow, ...newRowCells] = (_a = table_service_1.TableService.addRow(tableElement, [...existingCells, ...elementsToCreate], rowIndex, rowToPaste.size.height)) === null || _a === void 0 ? void 0 : _a.elementsToCreate;
|
|
@@ -50,8 +50,8 @@ class TablePasteService {
|
|
|
50
50
|
for (let columnIndex = startColumn; columnIndex <= endColumn; columnIndex++) {
|
|
51
51
|
const columnToPaste = columnsToPaste[columnIndex - targetColumn];
|
|
52
52
|
let existingColumnId = tableElement.columnIds[columnIndex];
|
|
53
|
-
let existingColumn = childElements.find(e => e.type === 'column' && e.id === existingColumnId) ||
|
|
54
|
-
elementsToCreate.find(e => e.type === 'column' && e.id === existingColumnId);
|
|
53
|
+
let existingColumn = childElements.find((e) => e.type === 'column' && e.id === existingColumnId) ||
|
|
54
|
+
elementsToCreate.find((e) => e.type === 'column' && e.id === existingColumnId);
|
|
55
55
|
this.log('current column', columnIndex, existingColumnId, existingColumn);
|
|
56
56
|
if (!tableElement.columnIds[columnIndex]) {
|
|
57
57
|
const [newColumn, ...newColumnCells] = (_b = table_service_1.TableService.addColumn(tableElement, [...existingCells, ...elementsToCreate], columnIndex, columnToPaste.size.width)) === null || _b === void 0 ? void 0 : _b.elementsToCreate;
|
|
@@ -65,14 +65,14 @@ class TablePasteService {
|
|
|
65
65
|
columnWidthsToUpdate.get(existingColumnId) < columnToPaste.size.width)) {
|
|
66
66
|
columnWidthsToUpdate.set(existingColumnId, columnToPaste.size.width);
|
|
67
67
|
}
|
|
68
|
-
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);
|
|
69
69
|
if (!cellToPaste)
|
|
70
70
|
continue;
|
|
71
71
|
const cellRange = new table_range_1.TableRange(rowIndex, rowIndex, columnIndex, columnIndex);
|
|
72
|
-
const mergedRange = existingMergedRanges.find(range => range.intersects(cellRange));
|
|
72
|
+
const mergedRange = existingMergedRanges.find((range) => range.intersects(cellRange));
|
|
73
73
|
const mergedRangeOther = mergedRange && !cellRange.equals(mergedRange.start());
|
|
74
74
|
if (mergedRange) {
|
|
75
|
-
existingMergedRanges = existingMergedRanges.filter(r => !r.equals(mergedRange));
|
|
75
|
+
existingMergedRanges = existingMergedRanges.filter((r) => !r.equals(mergedRange));
|
|
76
76
|
}
|
|
77
77
|
if (mergedRangeOther) {
|
|
78
78
|
const [updatedTable, ...unmergedCellAndRow] = (_c = table_merge_service_1.TableMergeService.unmerge(tableElement, childElements, mergedRange)) === null || _c === void 0 ? void 0 : _c.elementsToUpdate;
|
|
@@ -100,34 +100,34 @@ class TablePasteService {
|
|
|
100
100
|
return { elementsToCreate, elementsToUpdate };
|
|
101
101
|
}
|
|
102
102
|
static pasteTableCells(tableElement, childElements, elementsToPaste, targetRow, targetColumn) {
|
|
103
|
-
const memberCandidates = elementsToPaste.filter(e => table_state_service_1.TableStateService.isValidTableMember(e));
|
|
104
|
-
const structureElements = elementsToPaste.filter(e => !table_state_service_1.TableStateService.isValidTableMember(e));
|
|
105
|
-
const tableToPaste = structureElements.find(e => e.type === 'table');
|
|
106
|
-
const rowsToPaste = structureElements.filter(e => e.type === 'row');
|
|
107
|
-
const columnsToPaste = structureElements.filter(e => e.type === 'column');
|
|
108
|
-
const cellsToPaste = structureElements.filter(e => e.type === 'cell');
|
|
103
|
+
const memberCandidates = elementsToPaste.filter((e) => table_state_service_1.TableStateService.isValidTableMember(e));
|
|
104
|
+
const structureElements = elementsToPaste.filter((e) => !table_state_service_1.TableStateService.isValidTableMember(e));
|
|
105
|
+
const tableToPaste = structureElements.find((e) => e.type === 'table');
|
|
106
|
+
const rowsToPaste = structureElements.filter((e) => e.type === 'row');
|
|
107
|
+
const columnsToPaste = structureElements.filter((e) => e.type === 'column');
|
|
108
|
+
const cellsToPaste = structureElements.filter((e) => e.type === 'cell');
|
|
109
109
|
const startRow = targetRow;
|
|
110
110
|
const endRow = startRow + tableToPaste.rowIds.length - 1;
|
|
111
111
|
const startColumn = targetColumn;
|
|
112
112
|
const endColumn = startColumn + tableToPaste.columnIds.length - 1;
|
|
113
|
-
const existingCells = childElements.filter(e => e.type === 'cell');
|
|
113
|
+
const existingCells = childElements.filter((e) => e.type === 'cell');
|
|
114
114
|
const tableUndo = util_1.ObjectUtil.cloneDeep(tableElement);
|
|
115
115
|
const { elementsToUpdate, elementsToCreate } = TablePasteService.pasteRowsAndColumns(tableElement, childElements, structureElements, targetRow, targetColumn);
|
|
116
116
|
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
|
|
117
117
|
const rowToPaste = rowsToPaste[rowIndex - targetRow];
|
|
118
118
|
const existingRowId = tableElement.rowIds[rowIndex];
|
|
119
|
-
const existingRow = childElements.find(e => e.type === 'row' && e.id === existingRowId) ||
|
|
120
|
-
elementsToCreate.find(e => e.type === 'row' && e.id === existingRowId);
|
|
119
|
+
const existingRow = childElements.find((e) => e.type === 'row' && e.id === existingRowId) ||
|
|
120
|
+
elementsToCreate.find((e) => e.type === 'row' && e.id === existingRowId);
|
|
121
121
|
for (let columnIndex = startColumn; columnIndex <= endColumn; columnIndex++) {
|
|
122
122
|
const columnToPaste = columnsToPaste[columnIndex - targetColumn];
|
|
123
123
|
const existingColumnId = tableElement.columnIds[columnIndex];
|
|
124
|
-
const existingColumn = childElements.find(e => e.type === 'column' && e.id === existingColumnId) ||
|
|
125
|
-
elementsToCreate.find(e => e.type === 'column' && e.id === existingColumnId);
|
|
126
|
-
const cellToPaste = cellsToPaste.find(e => e.rowId === rowToPaste.id && e.columnId === columnToPaste.id);
|
|
124
|
+
const existingColumn = childElements.find((e) => e.type === 'column' && e.id === existingColumnId) ||
|
|
125
|
+
elementsToCreate.find((e) => e.type === 'column' && e.id === existingColumnId);
|
|
126
|
+
const cellToPaste = cellsToPaste.find((e) => e.rowId === rowToPaste.id && e.columnId === columnToPaste.id);
|
|
127
127
|
if (!cellToPaste)
|
|
128
128
|
continue;
|
|
129
|
-
const createdCell = elementsToCreate.find(e => e.type === 'cell' && e.rowId === existingRowId && e.columnId === existingColumnId);
|
|
130
|
-
const existingCell = existingCells.find(e => e.rowId === existingRowId && e.columnId === existingColumnId);
|
|
129
|
+
const createdCell = elementsToCreate.find((e) => e.type === 'cell' && e.rowId === existingRowId && e.columnId === existingColumnId);
|
|
130
|
+
const existingCell = existingCells.find((e) => e.rowId === existingRowId && e.columnId === existingColumnId);
|
|
131
131
|
const cell = createdCell !== null && createdCell !== void 0 ? createdCell : existingCell;
|
|
132
132
|
const cellUndo = util_1.ObjectUtil.cloneDeep(cell);
|
|
133
133
|
this.log('cell to paste', cellToPaste);
|
|
@@ -172,7 +172,7 @@ class TablePasteService {
|
|
|
172
172
|
if (memberships.size > 0) {
|
|
173
173
|
const allTargetChildren = [
|
|
174
174
|
...childElements,
|
|
175
|
-
...elementsToCreate.filter(e => table_constants_1.TABLE_STRUCTURE_TYPES.includes(e.type)),
|
|
175
|
+
...elementsToCreate.filter((e) => table_constants_1.TABLE_STRUCTURE_TYPES.includes(e.type)),
|
|
176
176
|
];
|
|
177
177
|
const newMembers = table_member_paste_service_1.TableMemberPasteService.resolveMemberPositions(memberships, memberCandidates, tableElement, allTargetChildren, targetRow, targetColumn);
|
|
178
178
|
elementsToCreate.push(...newMembers);
|