@contrail/document-table 1.0.18 → 1.0.19
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/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/table-constants.d.ts +1 -0
- package/lib/table-constants.js +2 -1
- package/lib/table-copy.service.js +18 -11
- package/lib/table-member-paste.service.d.ts +14 -0
- package/lib/table-member-paste.service.js +144 -0
- package/lib/table-paste.service.js +41 -26
- package/lib/table-state.service.js +8 -8
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './table-border-ranges';
|
|
2
2
|
export * from './table-constants';
|
|
3
3
|
export * from './table-copy.service';
|
|
4
|
+
export * from './table-member-paste.service';
|
|
4
5
|
export * from './table-merge.service';
|
|
5
6
|
export * from './table-paste.service';
|
|
6
7
|
export * from './table-rotate.service';
|
package/lib/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./table-border-ranges"), exports);
|
|
18
18
|
__exportStar(require("./table-constants"), exports);
|
|
19
19
|
__exportStar(require("./table-copy.service"), exports);
|
|
20
|
+
__exportStar(require("./table-member-paste.service"), exports);
|
|
20
21
|
__exportStar(require("./table-merge.service"), exports);
|
|
21
22
|
__exportStar(require("./table-paste.service"), exports);
|
|
22
23
|
__exportStar(require("./table-rotate.service"), exports);
|
package/lib/table-constants.d.ts
CHANGED
package/lib/table-constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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.TABLE_COLUMN_MIN_WIDTH = exports.TABLE_ROW_MIN_HEIGHT = void 0;
|
|
3
|
+
exports.TABLE_STRUCTURE_TYPES = 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
6
|
exports.TABLE_CELL_WIDTH = 200;
|
|
@@ -11,3 +11,4 @@ exports.DEFAULT_TEXT_FONT_FAMILY = 'Roboto';
|
|
|
11
11
|
exports.DEFAULT_TEXT_FONT_SIZE = 11;
|
|
12
12
|
exports.TEXT_VALIGN = 'top';
|
|
13
13
|
exports.TEXT_ALIGN = 'left';
|
|
14
|
+
exports.TABLE_STRUCTURE_TYPES = ['table', 'column', 'row', 'cell'];
|
|
@@ -6,12 +6,13 @@ const util_1 = require("@contrail/util");
|
|
|
6
6
|
const nanoid_1 = require("nanoid");
|
|
7
7
|
const table_constants_1 = require("./table-constants");
|
|
8
8
|
const table_service_1 = require("./table.service");
|
|
9
|
+
const table_state_service_1 = require("./table-state.service");
|
|
9
10
|
class TableCopyService {
|
|
10
11
|
constructor() { }
|
|
11
12
|
static copy(tableElement, childElements) {
|
|
12
13
|
const copiedChildElementIds = new Map();
|
|
13
14
|
const childElementsMap = new Map();
|
|
14
|
-
childElements.forEach(
|
|
15
|
+
childElements.forEach(element => {
|
|
15
16
|
childElementsMap.set(element.id, element);
|
|
16
17
|
});
|
|
17
18
|
const rowIds = [];
|
|
@@ -55,20 +56,20 @@ class TableCopyService {
|
|
|
55
56
|
columnIds.push(newElement.id);
|
|
56
57
|
newChildElements.push(newElement);
|
|
57
58
|
}
|
|
58
|
-
const cellElements = childElements.filter(
|
|
59
|
+
const cellElements = childElements.filter(e => e.type === 'cell');
|
|
59
60
|
if (cellElements.length < tableElement.rowIds.length * tableElement.columnIds.length) {
|
|
60
61
|
for (let i = 0; i < tableElement.rowIds.length; i++) {
|
|
61
62
|
for (let j = 0; j < tableElement.columnIds.length; j++) {
|
|
62
63
|
const rowId = tableElement.rowIds[i];
|
|
63
64
|
const columnId = tableElement.columnIds[j];
|
|
64
|
-
const cellElement = cellElements.find(
|
|
65
|
+
const cellElement = cellElements.find(e => e.type === 'cell' && e.rowId === rowId && e.columnId === columnId);
|
|
65
66
|
if (!cellElement) {
|
|
66
|
-
const row = childElements.find(
|
|
67
|
-
const column = childElements.find(
|
|
67
|
+
const row = childElements.find(e => e.id === rowId);
|
|
68
|
+
const column = childElements.find(e => e.id === columnId);
|
|
68
69
|
cellElements.push((0, table_service_1.createCell)({
|
|
69
70
|
rowId,
|
|
70
71
|
columnId,
|
|
71
|
-
tableId:
|
|
72
|
+
tableId: newTableElement.id,
|
|
72
73
|
size: {
|
|
73
74
|
width: column.size.width,
|
|
74
75
|
height: row.size.height,
|
|
@@ -101,6 +102,7 @@ class TableCopyService {
|
|
|
101
102
|
return [newTableElement, ...newChildElements];
|
|
102
103
|
}
|
|
103
104
|
static createTableFromCells(element, rows, columns, cells) {
|
|
105
|
+
var _a, _b, _c, _d;
|
|
104
106
|
const rowElements = [];
|
|
105
107
|
const rowIds = new Map();
|
|
106
108
|
const columnElements = [];
|
|
@@ -110,7 +112,7 @@ class TableCopyService {
|
|
|
110
112
|
const tableId = (0, nanoid_1.nanoid)(16);
|
|
111
113
|
let width = 0, height = 0;
|
|
112
114
|
let startRow, endRow, startColumn, endColumn;
|
|
113
|
-
cells.forEach(
|
|
115
|
+
cells.forEach(cell => {
|
|
114
116
|
const rowIndex = element.rowIds.indexOf(cell.rowId);
|
|
115
117
|
const columnIndex = element.columnIds.indexOf(cell.columnId);
|
|
116
118
|
const isNotSet = startRow == undefined;
|
|
@@ -124,8 +126,8 @@ class TableCopyService {
|
|
|
124
126
|
endColumn = columnIndex;
|
|
125
127
|
existingCellsMap.set(`${rowIndex}_${columnIndex}`, cell);
|
|
126
128
|
});
|
|
127
|
-
const skipRows = Array.from({ length: endRow - startRow + 1 }, (value, index) => startRow + index).filter(
|
|
128
|
-
const skipColumns = Array.from({ length: endColumn - startColumn + 1 }, (value, index) => startColumn + index).filter(
|
|
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
131
|
for (let i = startRow; i <= endRow; i++) {
|
|
130
132
|
if (skipRows.indexOf(i) !== -1)
|
|
131
133
|
continue;
|
|
@@ -195,10 +197,14 @@ class TableCopyService {
|
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
}
|
|
200
|
+
const { columns: existingColumns, rows: existingRows } = table_state_service_1.TableStateService.buildChildElementsState(element, new Map([...columns, ...rows].map(e => [e.id, e])), []);
|
|
198
201
|
const tableElement = {
|
|
199
202
|
type: 'table',
|
|
200
203
|
id: tableId,
|
|
201
|
-
position:
|
|
204
|
+
position: {
|
|
205
|
+
x: element.position.x + existingColumns.get(columns[startColumn].id).x * ((_b = (_a = element === null || element === void 0 ? void 0 : element.scale) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 1),
|
|
206
|
+
y: element.position.y + existingRows.get(rows[startRow].id).y * ((_d = (_c = element === null || element === void 0 ? void 0 : element.scale) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : 1),
|
|
207
|
+
},
|
|
202
208
|
scale: Object.assign({}, element.scale),
|
|
203
209
|
size: {
|
|
204
210
|
width,
|
|
@@ -276,7 +282,8 @@ class TableCopyService {
|
|
|
276
282
|
var _a, _b, _c, _d, _e, _f;
|
|
277
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}`;
|
|
278
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`;
|
|
279
|
-
const size = table_service_1.TableService.getSize(cellElement.text, `width: ${cellElement.size.width -
|
|
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};`);
|
|
280
287
|
const documentElement = {
|
|
281
288
|
isTextTool: true,
|
|
282
289
|
text: cellElement.text,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DocumentElement } from '@contrail/documents';
|
|
2
|
+
interface MembershipEntry {
|
|
3
|
+
gridRow: number;
|
|
4
|
+
gridCol: number;
|
|
5
|
+
offsetX: number;
|
|
6
|
+
offsetY: number;
|
|
7
|
+
lineDx?: number;
|
|
8
|
+
lineDy?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class TableMemberPasteService {
|
|
11
|
+
static detectMemberships(tableEl: DocumentElement, structureEls: DocumentElement[], memberCandidates: DocumentElement[]): Map<string, MembershipEntry>;
|
|
12
|
+
static resolveMemberPositions(memberships: Map<string, MembershipEntry>, memberElements: DocumentElement[], targetTableEl: DocumentElement, targetChildEls: DocumentElement[], targetRow: number, targetCol: number): DocumentElement[];
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableMemberPasteService = void 0;
|
|
4
|
+
const table_merge_service_1 = require("./table-merge.service");
|
|
5
|
+
const table_state_service_1 = require("./table-state.service");
|
|
6
|
+
const util_1 = require("@contrail/util");
|
|
7
|
+
const nanoid_1 = require("nanoid");
|
|
8
|
+
class TableMemberPasteService {
|
|
9
|
+
static detectMemberships(tableEl, structureEls, memberCandidates) {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
11
|
+
const result = new Map();
|
|
12
|
+
if (!tableEl || !memberCandidates.length)
|
|
13
|
+
return result;
|
|
14
|
+
const childElementsMap = table_state_service_1.TableStateService.getTableElementsMap(tableEl, structureEls);
|
|
15
|
+
const nonTableEls = structureEls.filter((e) => e.type !== 'table');
|
|
16
|
+
const mergedRanges = table_merge_service_1.TableMergeService.getMergedRanges(tableEl, nonTableEls);
|
|
17
|
+
const { cells } = table_state_service_1.TableStateService.buildChildElementsState(tableEl, childElementsMap, mergedRanges);
|
|
18
|
+
const scale = (_b = (_a = tableEl.scale) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 1;
|
|
19
|
+
const tableX = (_d = (_c = tableEl.position) === null || _c === void 0 ? void 0 : _c.x) !== null && _d !== void 0 ? _d : 0;
|
|
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 : [];
|
|
23
|
+
for (const member of memberCandidates) {
|
|
24
|
+
const isLine = member.type === 'line';
|
|
25
|
+
let cx;
|
|
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 {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
for (const [cellId, cellState] of cells) {
|
|
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
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
static resolveMemberPositions(memberships, memberElements, targetTableEl, targetChildEls, targetRow, targetCol) {
|
|
78
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
79
|
+
const newElements = [];
|
|
80
|
+
if (!memberships.size)
|
|
81
|
+
return newElements;
|
|
82
|
+
const childElementsMap = table_state_service_1.TableStateService.getTableElementsMap(targetTableEl, targetChildEls);
|
|
83
|
+
const nonTableEls = targetChildEls.filter((e) => e.type !== 'table');
|
|
84
|
+
const mergedRanges = table_merge_service_1.TableMergeService.getMergedRanges(targetTableEl, nonTableEls);
|
|
85
|
+
const { cells } = table_state_service_1.TableStateService.buildChildElementsState(targetTableEl, childElementsMap, mergedRanges);
|
|
86
|
+
const scale = (_b = (_a = targetTableEl.scale) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 1;
|
|
87
|
+
const tableX = (_d = (_c = targetTableEl.position) === null || _c === void 0 ? void 0 : _c.x) !== null && _d !== void 0 ? _d : 0;
|
|
88
|
+
const tableY = (_f = (_e = targetTableEl.position) === null || _e === void 0 ? void 0 : _e.y) !== null && _f !== void 0 ? _f : 0;
|
|
89
|
+
const rowIds = (_g = targetTableEl.rowIds) !== null && _g !== void 0 ? _g : [];
|
|
90
|
+
const columnIds = (_h = targetTableEl.columnIds) !== null && _h !== void 0 ? _h : [];
|
|
91
|
+
const cellByRowCol = new Map();
|
|
92
|
+
for (const el of targetChildEls) {
|
|
93
|
+
if (el.type === 'cell' && el.rowId && el.columnId) {
|
|
94
|
+
cellByRowCol.set(`${el.rowId}-${el.columnId}`, el);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const member of memberElements) {
|
|
98
|
+
const entry = memberships.get(member.id);
|
|
99
|
+
if (!entry)
|
|
100
|
+
continue;
|
|
101
|
+
const { gridRow, gridCol, offsetX, offsetY } = entry;
|
|
102
|
+
const targetRowId = rowIds[targetRow + gridRow];
|
|
103
|
+
const targetColId = columnIds[targetCol + gridCol];
|
|
104
|
+
if (!targetRowId || !targetColId)
|
|
105
|
+
continue;
|
|
106
|
+
const targetCellEl = cellByRowCol.get(`${targetRowId}-${targetColId}`);
|
|
107
|
+
if (!targetCellEl)
|
|
108
|
+
continue;
|
|
109
|
+
const targetCellState = cells.get(targetCellEl.id);
|
|
110
|
+
if (!targetCellState)
|
|
111
|
+
continue;
|
|
112
|
+
const newEl = util_1.ObjectUtil.cloneDeep(member);
|
|
113
|
+
newEl.id = (0, nanoid_1.nanoid)(16);
|
|
114
|
+
const isLine = member.type === 'line';
|
|
115
|
+
if (isLine && member.lineDefinition) {
|
|
116
|
+
const newX1 = tableX + (targetCellState.x + offsetX) * scale;
|
|
117
|
+
const newY1 = tableY + (targetCellState.y + offsetY) * scale;
|
|
118
|
+
const newX2 = newX1 + ((_j = entry.lineDx) !== null && _j !== void 0 ? _j : 0);
|
|
119
|
+
const newY2 = newY1 + ((_k = entry.lineDy) !== null && _k !== void 0 ? _k : 0);
|
|
120
|
+
newEl.lineDefinition = Object.assign(Object.assign({}, newEl.lineDefinition), { x1: newX1, y1: newY1, x2: newX2, y2: newY2 });
|
|
121
|
+
if ((_l = newEl.points) === null || _l === void 0 ? void 0 : _l.length) {
|
|
122
|
+
const oldX1 = member.lineDefinition.x1;
|
|
123
|
+
const oldY1 = member.lineDefinition.y1;
|
|
124
|
+
const dx = newX1 - oldX1;
|
|
125
|
+
const dy = newY1 - oldY1;
|
|
126
|
+
newEl.points = newEl.points.map((p) => [p[0] + dx, p[1] + dy]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const newX = tableX + (targetCellState.x + offsetX) * scale;
|
|
131
|
+
const newY = tableY + (targetCellState.y + offsetY) * scale;
|
|
132
|
+
if (((_m = newEl.points) === null || _m === void 0 ? void 0 : _m.length) && member.position) {
|
|
133
|
+
const dx = newX - member.position.x;
|
|
134
|
+
const dy = newY - member.position.y;
|
|
135
|
+
newEl.points = newEl.points.map((p) => [p[0] + dx, p[1] + dy]);
|
|
136
|
+
}
|
|
137
|
+
newEl.position = { x: newX, y: newY };
|
|
138
|
+
}
|
|
139
|
+
newElements.push(newEl);
|
|
140
|
+
}
|
|
141
|
+
return newElements;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.TableMemberPasteService = TableMemberPasteService;
|
|
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TablePasteService = void 0;
|
|
4
4
|
const documents_1 = require("@contrail/documents");
|
|
5
5
|
const util_1 = require("@contrail/util");
|
|
6
|
+
const table_member_paste_service_1 = require("./table-member-paste.service");
|
|
6
7
|
const table_merge_service_1 = require("./table-merge.service");
|
|
7
8
|
const table_service_1 = require("./table.service");
|
|
8
9
|
const table_range_1 = require("./table-range");
|
|
10
|
+
const table_state_service_1 = require("./table-state.service");
|
|
11
|
+
const table_constants_1 = require("./table-constants");
|
|
9
12
|
class TablePasteService {
|
|
10
13
|
constructor() { }
|
|
11
14
|
static log(...message) {
|
|
@@ -13,15 +16,15 @@ class TablePasteService {
|
|
|
13
16
|
}
|
|
14
17
|
static pasteRowsAndColumns(tableElement, childElements, elementsToPaste, targetRow, targetColumn) {
|
|
15
18
|
var _a, _b, _c;
|
|
16
|
-
const tableToPaste = elementsToPaste.find(
|
|
17
|
-
const rowsToPaste = elementsToPaste.filter(
|
|
18
|
-
const columnsToPaste = elementsToPaste.filter(
|
|
19
|
-
const cellsToPaste = elementsToPaste.filter(
|
|
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');
|
|
20
23
|
const startRow = targetRow;
|
|
21
24
|
const endRow = startRow + tableToPaste.rowIds.length - 1;
|
|
22
25
|
const startColumn = targetColumn;
|
|
23
26
|
const endColumn = startColumn + tableToPaste.columnIds.length - 1;
|
|
24
|
-
const existingCells = childElements.filter(
|
|
27
|
+
const existingCells = childElements.filter(e => e.type === 'cell');
|
|
25
28
|
const elementsToCreate = [];
|
|
26
29
|
const elementsToUpdate = [];
|
|
27
30
|
const columnWidthsToUpdate = new Map();
|
|
@@ -30,8 +33,8 @@ class TablePasteService {
|
|
|
30
33
|
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
|
|
31
34
|
const rowToPaste = rowsToPaste[rowIndex - targetRow];
|
|
32
35
|
let existingRowId = tableElement.rowIds[rowIndex];
|
|
33
|
-
let existingRow = childElements.find(
|
|
34
|
-
elementsToCreate.find(
|
|
36
|
+
let existingRow = childElements.find(e => e.type === 'row' && e.id === existingRowId) ||
|
|
37
|
+
elementsToCreate.find(e => e.type === 'row' && e.id === existingRowId);
|
|
35
38
|
this.log('current row', rowIndex, existingRowId, existingRow);
|
|
36
39
|
if (!existingRowId) {
|
|
37
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;
|
|
@@ -47,8 +50,8 @@ class TablePasteService {
|
|
|
47
50
|
for (let columnIndex = startColumn; columnIndex <= endColumn; columnIndex++) {
|
|
48
51
|
const columnToPaste = columnsToPaste[columnIndex - targetColumn];
|
|
49
52
|
let existingColumnId = tableElement.columnIds[columnIndex];
|
|
50
|
-
let existingColumn = childElements.find(
|
|
51
|
-
elementsToCreate.find(
|
|
53
|
+
let existingColumn = childElements.find(e => e.type === 'column' && e.id === existingColumnId) ||
|
|
54
|
+
elementsToCreate.find(e => e.type === 'column' && e.id === existingColumnId);
|
|
52
55
|
this.log('current column', columnIndex, existingColumnId, existingColumn);
|
|
53
56
|
if (!tableElement.columnIds[columnIndex]) {
|
|
54
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;
|
|
@@ -62,14 +65,14 @@ class TablePasteService {
|
|
|
62
65
|
columnWidthsToUpdate.get(existingColumnId) < columnToPaste.size.width)) {
|
|
63
66
|
columnWidthsToUpdate.set(existingColumnId, columnToPaste.size.width);
|
|
64
67
|
}
|
|
65
|
-
const cellToPaste = cellsToPaste.find(
|
|
68
|
+
const cellToPaste = cellsToPaste.find(e => e.rowId === rowToPaste.id && e.columnId === columnToPaste.id);
|
|
66
69
|
if (!cellToPaste)
|
|
67
70
|
continue;
|
|
68
71
|
const cellRange = new table_range_1.TableRange(rowIndex, rowIndex, columnIndex, columnIndex);
|
|
69
|
-
const mergedRange = existingMergedRanges.find(
|
|
72
|
+
const mergedRange = existingMergedRanges.find(range => range.intersects(cellRange));
|
|
70
73
|
const mergedRangeOther = mergedRange && !cellRange.equals(mergedRange.start());
|
|
71
74
|
if (mergedRange) {
|
|
72
|
-
existingMergedRanges = existingMergedRanges.filter(
|
|
75
|
+
existingMergedRanges = existingMergedRanges.filter(r => !r.equals(mergedRange));
|
|
73
76
|
}
|
|
74
77
|
if (mergedRangeOther) {
|
|
75
78
|
const [updatedTable, ...unmergedCellAndRow] = (_c = table_merge_service_1.TableMergeService.unmerge(tableElement, childElements, mergedRange)) === null || _c === void 0 ? void 0 : _c.elementsToUpdate;
|
|
@@ -97,33 +100,34 @@ class TablePasteService {
|
|
|
97
100
|
return { elementsToCreate, elementsToUpdate };
|
|
98
101
|
}
|
|
99
102
|
static pasteTableCells(tableElement, childElements, elementsToPaste, targetRow, targetColumn) {
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
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');
|
|
105
109
|
const startRow = targetRow;
|
|
106
110
|
const endRow = startRow + tableToPaste.rowIds.length - 1;
|
|
107
111
|
const startColumn = targetColumn;
|
|
108
112
|
const endColumn = startColumn + tableToPaste.columnIds.length - 1;
|
|
109
|
-
const existingCells = childElements.filter(
|
|
113
|
+
const existingCells = childElements.filter(e => e.type === 'cell');
|
|
110
114
|
const tableUndo = util_1.ObjectUtil.cloneDeep(tableElement);
|
|
111
|
-
const { elementsToUpdate, elementsToCreate } = TablePasteService.pasteRowsAndColumns(tableElement, childElements,
|
|
115
|
+
const { elementsToUpdate, elementsToCreate } = TablePasteService.pasteRowsAndColumns(tableElement, childElements, structureElements, targetRow, targetColumn);
|
|
112
116
|
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
|
|
113
117
|
const rowToPaste = rowsToPaste[rowIndex - targetRow];
|
|
114
118
|
const existingRowId = tableElement.rowIds[rowIndex];
|
|
115
|
-
const existingRow = childElements.find(
|
|
116
|
-
elementsToCreate.find(
|
|
119
|
+
const existingRow = childElements.find(e => e.type === 'row' && e.id === existingRowId) ||
|
|
120
|
+
elementsToCreate.find(e => e.type === 'row' && e.id === existingRowId);
|
|
117
121
|
for (let columnIndex = startColumn; columnIndex <= endColumn; columnIndex++) {
|
|
118
122
|
const columnToPaste = columnsToPaste[columnIndex - targetColumn];
|
|
119
123
|
const existingColumnId = tableElement.columnIds[columnIndex];
|
|
120
|
-
const existingColumn = childElements.find(
|
|
121
|
-
elementsToCreate.find(
|
|
122
|
-
const cellToPaste = cellsToPaste.find(
|
|
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);
|
|
123
127
|
if (!cellToPaste)
|
|
124
128
|
continue;
|
|
125
|
-
const createdCell = elementsToCreate.find(
|
|
126
|
-
const existingCell = existingCells.find(
|
|
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);
|
|
127
131
|
const cell = createdCell !== null && createdCell !== void 0 ? createdCell : existingCell;
|
|
128
132
|
const cellUndo = util_1.ObjectUtil.cloneDeep(cell);
|
|
129
133
|
this.log('cell to paste', cellToPaste);
|
|
@@ -163,6 +167,17 @@ class TablePasteService {
|
|
|
163
167
|
change: tableElement,
|
|
164
168
|
undo: tableUndo,
|
|
165
169
|
});
|
|
170
|
+
if (memberCandidates.length > 0) {
|
|
171
|
+
const memberships = table_member_paste_service_1.TableMemberPasteService.detectMemberships(tableToPaste, structureElements, memberCandidates);
|
|
172
|
+
if (memberships.size > 0) {
|
|
173
|
+
const allTargetChildren = [
|
|
174
|
+
...childElements,
|
|
175
|
+
...elementsToCreate.filter(e => table_constants_1.TABLE_STRUCTURE_TYPES.includes(e.type)),
|
|
176
|
+
];
|
|
177
|
+
const newMembers = table_member_paste_service_1.TableMemberPasteService.resolveMemberPositions(memberships, memberCandidates, tableElement, allTargetChildren, targetRow, targetColumn);
|
|
178
|
+
elementsToCreate.push(...newMembers);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
166
181
|
return {
|
|
167
182
|
elementsToUpdate,
|
|
168
183
|
elementsToCreate,
|
|
@@ -47,7 +47,7 @@ class TableStateService {
|
|
|
47
47
|
}
|
|
48
48
|
if (cell && column && row) {
|
|
49
49
|
const cellRange = new document_table_1.TableRange(rowIndex, rowIndex, columnIndex, columnIndex);
|
|
50
|
-
const mergedRange = mergedRanges.find(range => cellRange.within(range));
|
|
50
|
+
const mergedRange = mergedRanges.find((range) => cellRange.within(range));
|
|
51
51
|
const mergedRangeStart = mergedRange && cellRange.equals(mergedRange.start());
|
|
52
52
|
const mergedRangeOther = mergedRange && !cellRange.equals(mergedRange.start());
|
|
53
53
|
const width = mergedRangeStart
|
|
@@ -92,9 +92,9 @@ class TableStateService {
|
|
|
92
92
|
}
|
|
93
93
|
static getMemberIdsForCellIds(table, cellIds) {
|
|
94
94
|
const memberIds = new Set();
|
|
95
|
-
cellIds.forEach(cellId => {
|
|
95
|
+
cellIds.forEach((cellId) => {
|
|
96
96
|
var _a, _b;
|
|
97
|
-
(_b = (_a = table.cellToMembers) === null || _a === void 0 ? void 0 : _a.get(cellId)) === null || _b === void 0 ? void 0 : _b.forEach(elementId => {
|
|
97
|
+
(_b = (_a = table.cellToMembers) === null || _a === void 0 ? void 0 : _a.get(cellId)) === null || _b === void 0 ? void 0 : _b.forEach((elementId) => {
|
|
98
98
|
memberIds.add(elementId);
|
|
99
99
|
});
|
|
100
100
|
});
|
|
@@ -117,7 +117,7 @@ class TableStateService {
|
|
|
117
117
|
const cellMembers = (_e = table.cellToMembers) === null || _e === void 0 ? void 0 : _e.get(cell.id);
|
|
118
118
|
if ((cellMembers === null || cellMembers === void 0 ? void 0 : cellMembers.size) > 0 &&
|
|
119
119
|
(includeAll || (rowIndexes === null || rowIndexes === void 0 ? void 0 : rowIndexes.includes(rowIndex)) || (columnIndexes === null || columnIndexes === void 0 ? void 0 : columnIndexes.includes(columnIndex)))) {
|
|
120
|
-
cellMembers.forEach(memberId => {
|
|
120
|
+
cellMembers.forEach((memberId) => {
|
|
121
121
|
tableMembers.set(memberId, {
|
|
122
122
|
memberId,
|
|
123
123
|
rowId,
|
|
@@ -207,20 +207,20 @@ class TableStateService {
|
|
|
207
207
|
}
|
|
208
208
|
static getTableElementsMap(tableElement, tableChildElements) {
|
|
209
209
|
var _a;
|
|
210
|
-
const childElementsMap = new Map(tableChildElements.map(el => [el.id, el]));
|
|
210
|
+
const childElementsMap = new Map(tableChildElements.map((el) => [el.id, el]));
|
|
211
211
|
const tableState = new Map();
|
|
212
|
-
(_a = tableElement.rowIds) === null || _a === void 0 ? void 0 : _a.forEach(rowId => {
|
|
212
|
+
(_a = tableElement.rowIds) === null || _a === void 0 ? void 0 : _a.forEach((rowId) => {
|
|
213
213
|
var _a;
|
|
214
214
|
const row = childElementsMap.get(rowId);
|
|
215
215
|
if (row) {
|
|
216
216
|
tableState.set(rowId, row);
|
|
217
217
|
}
|
|
218
|
-
(_a = tableElement.columnIds) === null || _a === void 0 ? void 0 : _a.forEach(columnId => {
|
|
218
|
+
(_a = tableElement.columnIds) === null || _a === void 0 ? void 0 : _a.forEach((columnId) => {
|
|
219
219
|
const column = childElementsMap.get(columnId);
|
|
220
220
|
if (column) {
|
|
221
221
|
tableState.set(columnId, column);
|
|
222
222
|
}
|
|
223
|
-
const cell = tableChildElements.find(el => el.rowId === rowId && el.columnId === columnId);
|
|
223
|
+
const cell = tableChildElements.find((el) => el.rowId === rowId && el.columnId === columnId);
|
|
224
224
|
if (cell) {
|
|
225
225
|
const compositeId = `${rowId}-${columnId}`;
|
|
226
226
|
tableState.set(cell.id, cell);
|