@contrail/document-table 1.0.16 → 1.0.17
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-state.service.d.ts +92 -0
- package/lib/table-state.service.js +331 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -22,3 +22,4 @@ __exportStar(require("./table-paste.service"), exports);
|
|
|
22
22
|
__exportStar(require("./table-rotate.service"), exports);
|
|
23
23
|
__exportStar(require("./table.service"), exports);
|
|
24
24
|
__exportStar(require("./table-range"), exports);
|
|
25
|
+
__exportStar(require("./table-state.service"), exports);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { CoordinateBox, DocumentElement, PositionDefinition, ViewBox } from '@contrail/documents';
|
|
2
|
+
import { TableRange } from '@contrail/document-table';
|
|
3
|
+
export interface TableMemberToUpdate {
|
|
4
|
+
element: DocumentElement;
|
|
5
|
+
startingElement: DocumentElement;
|
|
6
|
+
dimensions: ViewBox;
|
|
7
|
+
rowId: string;
|
|
8
|
+
columnId: string;
|
|
9
|
+
cellId: string;
|
|
10
|
+
rowIndex: number;
|
|
11
|
+
columnIndex: number;
|
|
12
|
+
columnX: number;
|
|
13
|
+
rowY: number;
|
|
14
|
+
}
|
|
15
|
+
export interface TableCellState {
|
|
16
|
+
id: string;
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
mergedRange?: TableRange;
|
|
22
|
+
isMerged?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface TableRowState {
|
|
25
|
+
id: string;
|
|
26
|
+
y: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}
|
|
29
|
+
export interface TableColumnState {
|
|
30
|
+
id: string;
|
|
31
|
+
x: number;
|
|
32
|
+
width: number;
|
|
33
|
+
}
|
|
34
|
+
export interface TableState {
|
|
35
|
+
id: string;
|
|
36
|
+
index?: number;
|
|
37
|
+
box: CoordinateBox;
|
|
38
|
+
element: DocumentElement;
|
|
39
|
+
childElements: DocumentElement[];
|
|
40
|
+
childElementsMap: Map<string, DocumentElement>;
|
|
41
|
+
mergedRanges: TableRange[];
|
|
42
|
+
columns: Map<string, TableColumnState>;
|
|
43
|
+
rows: Map<string, TableRowState>;
|
|
44
|
+
cells: Map<string, TableCellState>;
|
|
45
|
+
cellToMembers?: Map<string, Set<string>>;
|
|
46
|
+
memberToCell?: Map<string, string>;
|
|
47
|
+
}
|
|
48
|
+
export interface TableMemberState {
|
|
49
|
+
memberId: string;
|
|
50
|
+
rowId: string;
|
|
51
|
+
columnId: string;
|
|
52
|
+
cellId: string;
|
|
53
|
+
columnX: number;
|
|
54
|
+
rowY: number;
|
|
55
|
+
columnIndex: number;
|
|
56
|
+
rowIndex: number;
|
|
57
|
+
}
|
|
58
|
+
export declare class TableStateService {
|
|
59
|
+
constructor();
|
|
60
|
+
static createTableState(element: DocumentElement, childElements: DocumentElement[], index: number): TableState;
|
|
61
|
+
static updateTableState(tableState: TableState, element: DocumentElement, childElements: DocumentElement[]): void;
|
|
62
|
+
private static buildTableStateProperties;
|
|
63
|
+
static buildChildElementsState(tableElement: DocumentElement, childElementsMap: Map<string, DocumentElement>, mergedRanges: TableRange[]): {
|
|
64
|
+
cells: Map<string, TableCellState>;
|
|
65
|
+
columns: Map<string, TableColumnState>;
|
|
66
|
+
rows: Map<string, TableRowState>;
|
|
67
|
+
};
|
|
68
|
+
static addMemberToCell(table: TableState, cellId: string, elementId: string): void;
|
|
69
|
+
static removeMember(table: TableState, elementId: string): void;
|
|
70
|
+
static getMemberIdsForCellIds(table: TableState, cellIds: string[]): Set<string>;
|
|
71
|
+
static getMembers(table: TableState, { rowIndexes, columnIndexes }?: {
|
|
72
|
+
rowIndexes?: number[];
|
|
73
|
+
columnIndexes?: number[];
|
|
74
|
+
}): Map<string, TableMemberState>;
|
|
75
|
+
static getTableMembersToDelete(tableElement: DocumentElement, childElements: DocumentElement[], tableMembersToUpdate: Map<string, TableMemberToUpdate>): Map<string, TableMemberToUpdate>;
|
|
76
|
+
static adjustTableMemberPositions(tableElement: DocumentElement, childElements: DocumentElement[], tableMembersToUpdate: Map<string, TableMemberToUpdate>): Map<string, TableMemberToUpdate>;
|
|
77
|
+
static updatePositionWithDelta(element: DocumentElement, position: PositionDefinition, deltaX: number, deltaY: number): void;
|
|
78
|
+
static getElementPositionChange(element: DocumentElement, startingElement: DocumentElement): {
|
|
79
|
+
change: DocumentElement;
|
|
80
|
+
undo: DocumentElement;
|
|
81
|
+
};
|
|
82
|
+
static getTableElementsMap(tableElement: DocumentElement, tableChildElements: DocumentElement[]): Map<string, DocumentElement>;
|
|
83
|
+
static getOverlappedTable(elementBox: CoordinateBox, index: number, tables: Map<string, TableState>): TableState;
|
|
84
|
+
static isOnTable(table: TableState, index: number, elementBox: CoordinateBox): boolean;
|
|
85
|
+
static isOnCell(table: TableState, cellId: string, elementBox: CoordinateBox): boolean;
|
|
86
|
+
static isValidTableMember(documentElement: DocumentElement): boolean;
|
|
87
|
+
static getTableViewBox(element: DocumentElement): ViewBox;
|
|
88
|
+
static getTableCoordinateBox({ x, y, width, height }: ViewBox): CoordinateBox;
|
|
89
|
+
static getTableMemberCoordinateBox({ x, y, width, height }: ViewBox): CoordinateBox;
|
|
90
|
+
static getOverlappedCell(table: TableState, elementBox: CoordinateBox): DocumentElement;
|
|
91
|
+
private static isInBox;
|
|
92
|
+
}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableStateService = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const document_table_1 = require("@contrail/document-table");
|
|
6
|
+
const util_1 = require("@contrail/util");
|
|
7
|
+
class TableStateService {
|
|
8
|
+
constructor() { }
|
|
9
|
+
static createTableState(element, childElements, index) {
|
|
10
|
+
return Object.assign({ id: element.id, index, cellToMembers: new Map(), memberToCell: new Map() }, TableStateService.buildTableStateProperties(element, childElements));
|
|
11
|
+
}
|
|
12
|
+
static updateTableState(tableState, element, childElements) {
|
|
13
|
+
Object.assign(tableState, TableStateService.buildTableStateProperties(element, childElements));
|
|
14
|
+
}
|
|
15
|
+
static buildTableStateProperties(element, childElements) {
|
|
16
|
+
const childElementsMap = this.getTableElementsMap(element, childElements);
|
|
17
|
+
const mergedRanges = document_table_1.TableMergeService.getMergedRanges(element, childElements);
|
|
18
|
+
return Object.assign({ id: element.id, box: this.getTableCoordinateBox(this.getTableViewBox(element)), element,
|
|
19
|
+
childElements,
|
|
20
|
+
childElementsMap,
|
|
21
|
+
mergedRanges }, TableStateService.buildChildElementsState(element, childElementsMap, mergedRanges));
|
|
22
|
+
}
|
|
23
|
+
static buildChildElementsState(tableElement, childElementsMap, mergedRanges) {
|
|
24
|
+
const columns = new Map();
|
|
25
|
+
const rows = new Map();
|
|
26
|
+
const cells = new Map();
|
|
27
|
+
let offsetX = 0;
|
|
28
|
+
let offsetY = 0;
|
|
29
|
+
for (const [rowIndex, rowId] of tableElement.rowIds.entries()) {
|
|
30
|
+
const row = childElementsMap.get(rowId);
|
|
31
|
+
if (row) {
|
|
32
|
+
rows.set(rowId, {
|
|
33
|
+
id: rowId,
|
|
34
|
+
y: offsetY,
|
|
35
|
+
height: row.size.height,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
for (const [columnIndex, columnId] of tableElement.columnIds.entries()) {
|
|
39
|
+
const column = childElementsMap.get(columnId);
|
|
40
|
+
const compositeCellId = `${rowId}-${columnId}`;
|
|
41
|
+
const cell = childElementsMap.get(compositeCellId);
|
|
42
|
+
if (column) {
|
|
43
|
+
columns.set(columnId, {
|
|
44
|
+
id: columnId,
|
|
45
|
+
x: offsetX,
|
|
46
|
+
width: column.size.width,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (cell && column && row) {
|
|
50
|
+
const cellRange = new document_table_1.TableRange(rowIndex, rowIndex, columnIndex, columnIndex);
|
|
51
|
+
const mergedRange = mergedRanges.find(range => cellRange.within(range));
|
|
52
|
+
const mergedRangeStart = mergedRange && cellRange.equals(mergedRange.start());
|
|
53
|
+
const mergedRangeOther = mergedRange && !cellRange.equals(mergedRange.start());
|
|
54
|
+
const width = mergedRangeStart
|
|
55
|
+
? Array.from({ length: mergedRange.endColumn - mergedRange.startColumn + 1 }, (_, i) => mergedRange.startColumn + i).reduce((acc, i) => { var _a, _b; return acc + ((_b = (_a = childElementsMap.get(tableElement.columnIds[i])) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.width) || 0; }, 0)
|
|
56
|
+
: column.size.width;
|
|
57
|
+
const height = mergedRangeStart
|
|
58
|
+
? Array.from({ length: mergedRange.endRow - mergedRange.startRow + 1 }, (_, i) => mergedRange.startRow + i).reduce((acc, i) => { var _a, _b; return acc + ((_b = (_a = childElementsMap.get(tableElement.rowIds[i])) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.height) || 0; }, 0)
|
|
59
|
+
: row.size.height;
|
|
60
|
+
cells.set(cell.id, {
|
|
61
|
+
id: cell.id,
|
|
62
|
+
x: offsetX,
|
|
63
|
+
y: offsetY,
|
|
64
|
+
width,
|
|
65
|
+
height,
|
|
66
|
+
mergedRange,
|
|
67
|
+
isMerged: !!mergedRangeOther,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
offsetX += column ? column.size.width : 0;
|
|
71
|
+
}
|
|
72
|
+
offsetX = 0;
|
|
73
|
+
offsetY += row ? row.size.height : 0;
|
|
74
|
+
}
|
|
75
|
+
return { cells, columns, rows };
|
|
76
|
+
}
|
|
77
|
+
static addMemberToCell(table, cellId, elementId) {
|
|
78
|
+
let cellMembers = table.cellToMembers.get(cellId);
|
|
79
|
+
if (!cellMembers) {
|
|
80
|
+
cellMembers = new Set();
|
|
81
|
+
table.cellToMembers.set(cellId, cellMembers);
|
|
82
|
+
}
|
|
83
|
+
table.cellToMembers.get(cellId).add(elementId);
|
|
84
|
+
table.memberToCell.set(elementId, cellId);
|
|
85
|
+
}
|
|
86
|
+
static removeMember(table, elementId) {
|
|
87
|
+
const cellId = table.memberToCell.get(elementId);
|
|
88
|
+
if (cellId) {
|
|
89
|
+
const cellMembers = table.cellToMembers.get(cellId);
|
|
90
|
+
cellMembers === null || cellMembers === void 0 ? void 0 : cellMembers.delete(elementId);
|
|
91
|
+
table.memberToCell.delete(elementId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
static getMemberIdsForCellIds(table, cellIds) {
|
|
95
|
+
const memberIds = new Set();
|
|
96
|
+
cellIds.forEach(cellId => {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
(_b = (_a = table.cellToMembers) === null || _a === void 0 ? void 0 : _a.get(cellId)) === null || _b === void 0 ? void 0 : _b.forEach(elementId => {
|
|
99
|
+
memberIds.add(elementId);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
return memberIds;
|
|
103
|
+
}
|
|
104
|
+
static getMembers(table, { rowIndexes, columnIndexes } = {}) {
|
|
105
|
+
var _a, _b, _c, _d, _e;
|
|
106
|
+
const { columns, rows } = table;
|
|
107
|
+
const tableMembers = new Map();
|
|
108
|
+
const includeAll = !(rowIndexes === null || rowIndexes === void 0 ? void 0 : rowIndexes.length) && !(columnIndexes === null || columnIndexes === void 0 ? void 0 : columnIndexes.length);
|
|
109
|
+
for (let rowIndex = 0; rowIndex < ((_a = table.element.rowIds) === null || _a === void 0 ? void 0 : _a.length); rowIndex++) {
|
|
110
|
+
const rowId = table.element.rowIds[rowIndex];
|
|
111
|
+
for (let columnIndex = 0; columnIndex < ((_b = table.element.columnIds) === null || _b === void 0 ? void 0 : _b.length); columnIndex++) {
|
|
112
|
+
const columnId = table.element.columnIds[columnIndex];
|
|
113
|
+
const compositeCellId = `${rowId}-${columnId}`;
|
|
114
|
+
const cell = table.childElementsMap.get(compositeCellId);
|
|
115
|
+
const x = ((_c = columns.get(columnId)) === null || _c === void 0 ? void 0 : _c.x) || 0;
|
|
116
|
+
const y = ((_d = rows.get(rowId)) === null || _d === void 0 ? void 0 : _d.y) || 0;
|
|
117
|
+
if (cell) {
|
|
118
|
+
const cellMembers = (_e = table.cellToMembers) === null || _e === void 0 ? void 0 : _e.get(cell.id);
|
|
119
|
+
if ((cellMembers === null || cellMembers === void 0 ? void 0 : cellMembers.size) > 0 &&
|
|
120
|
+
(includeAll || (rowIndexes === null || rowIndexes === void 0 ? void 0 : rowIndexes.includes(rowIndex)) || (columnIndexes === null || columnIndexes === void 0 ? void 0 : columnIndexes.includes(columnIndex)))) {
|
|
121
|
+
cellMembers.forEach(memberId => {
|
|
122
|
+
tableMembers.set(memberId, {
|
|
123
|
+
memberId,
|
|
124
|
+
rowId,
|
|
125
|
+
columnId,
|
|
126
|
+
cellId: cell.id,
|
|
127
|
+
columnX: x,
|
|
128
|
+
rowY: y,
|
|
129
|
+
columnIndex,
|
|
130
|
+
rowIndex,
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return tableMembers;
|
|
138
|
+
}
|
|
139
|
+
static getTableMembersToDelete(tableElement, childElements, tableMembersToUpdate) {
|
|
140
|
+
const affectedTableMembers = new Map();
|
|
141
|
+
if (tableMembersToUpdate.size > 0) {
|
|
142
|
+
tableMembersToUpdate.forEach((tableMemberToUpdate) => {
|
|
143
|
+
if (tableElement.rowIds.indexOf(tableMemberToUpdate.rowId) === -1 ||
|
|
144
|
+
tableElement.columnIds.indexOf(tableMemberToUpdate.columnId) === -1) {
|
|
145
|
+
affectedTableMembers.set(tableMemberToUpdate.element.id, tableMemberToUpdate);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return affectedTableMembers;
|
|
150
|
+
}
|
|
151
|
+
static adjustTableMemberPositions(tableElement, childElements, tableMembersToUpdate) {
|
|
152
|
+
var _a;
|
|
153
|
+
const childElementsMap = TableStateService.getTableElementsMap(tableElement, childElements);
|
|
154
|
+
const mergedRanges = document_table_1.TableMergeService.getMergedRanges(tableElement, childElements);
|
|
155
|
+
const { columns, rows } = TableStateService.buildChildElementsState(tableElement, childElementsMap, mergedRanges);
|
|
156
|
+
const tableScale = ((_a = tableElement.scale) === null || _a === void 0 ? void 0 : _a.x) || 1;
|
|
157
|
+
const affectedTableMembers = new Map();
|
|
158
|
+
if (tableMembersToUpdate.size > 0) {
|
|
159
|
+
tableMembersToUpdate.forEach((tableMemberToUpdate) => {
|
|
160
|
+
var _a, _b;
|
|
161
|
+
const dx = ((_a = columns.get(tableMemberToUpdate.columnId)) === null || _a === void 0 ? void 0 : _a.x) - tableMemberToUpdate.columnX || 0;
|
|
162
|
+
const dy = ((_b = rows.get(tableMemberToUpdate.rowId)) === null || _b === void 0 ? void 0 : _b.y) - tableMemberToUpdate.rowY || 0;
|
|
163
|
+
if (dx !== 0 || dy !== 0) {
|
|
164
|
+
TableStateService.updatePositionWithDelta(tableMemberToUpdate.element, tableMemberToUpdate.dimensions, dx * tableScale, dy * tableScale);
|
|
165
|
+
affectedTableMembers.set(tableMemberToUpdate.element.id, tableMemberToUpdate);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return affectedTableMembers;
|
|
170
|
+
}
|
|
171
|
+
static updatePositionWithDelta(element, position, deltaX, deltaY) {
|
|
172
|
+
var _a, _b, _c;
|
|
173
|
+
if (element.type === 'line') {
|
|
174
|
+
if (element.lineDefinition) {
|
|
175
|
+
element.lineDefinition = Object.assign(Object.assign({}, util_1.ObjectUtil.cloneDeep(element.lineDefinition)), { x1: element.lineDefinition.x1 + deltaX, y1: element.lineDefinition.y1 + deltaY, x2: element.lineDefinition.x2 + deltaX, y2: element.lineDefinition.y2 + deltaY });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const isThumbnailOnlyComponent = documents_1.ItemComponentService.isThumbnailOnlyComponent(element);
|
|
180
|
+
let pr = 0;
|
|
181
|
+
let pt = 0;
|
|
182
|
+
if (documents_1.ItemComponentService.isItemComponent(element) && !isThumbnailOnlyComponent) {
|
|
183
|
+
pr = 8;
|
|
184
|
+
pt = 18;
|
|
185
|
+
}
|
|
186
|
+
element.position = Object.assign(Object.assign({}, element.position), { x: ((isThumbnailOnlyComponent ? (_a = element.position) === null || _a === void 0 ? void 0 : _a.x : position === null || position === void 0 ? void 0 : position.x) || 0) + deltaX + pr, y: ((isThumbnailOnlyComponent ? (_b = element.position) === null || _b === void 0 ? void 0 : _b.y : position === null || position === void 0 ? void 0 : position.y) || 0) + deltaY + pt });
|
|
187
|
+
}
|
|
188
|
+
if (['callout', 'line'].indexOf(element.type) !== -1 && ((_c = element.points) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
189
|
+
const points = element.points.map(([x, y]) => [x + deltaX, y + deltaY]);
|
|
190
|
+
element.points = points;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
static getElementPositionChange(element, startingElement) {
|
|
194
|
+
var _a;
|
|
195
|
+
let change, undo;
|
|
196
|
+
if (element.type === 'line') {
|
|
197
|
+
change = {
|
|
198
|
+
id: element.id,
|
|
199
|
+
lineDefinition: Object.assign({}, element.lineDefinition),
|
|
200
|
+
};
|
|
201
|
+
undo = { id: element.id, lineDefinition: Object.assign({}, startingElement.lineDefinition) };
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
change = {
|
|
205
|
+
id: element.id,
|
|
206
|
+
position: Object.assign({}, element.position),
|
|
207
|
+
};
|
|
208
|
+
undo = { id: element.id, position: Object.assign({}, startingElement.position) };
|
|
209
|
+
}
|
|
210
|
+
if (((_a = element.points) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
211
|
+
change.points = [...element.points];
|
|
212
|
+
undo.points = [...startingElement.points];
|
|
213
|
+
}
|
|
214
|
+
return { change, undo };
|
|
215
|
+
}
|
|
216
|
+
static getTableElementsMap(tableElement, tableChildElements) {
|
|
217
|
+
var _a;
|
|
218
|
+
const childElementsMap = new Map(tableChildElements.map(el => [el.id, el]));
|
|
219
|
+
const tableState = new Map();
|
|
220
|
+
(_a = tableElement.rowIds) === null || _a === void 0 ? void 0 : _a.forEach(rowId => {
|
|
221
|
+
var _a;
|
|
222
|
+
const row = childElementsMap.get(rowId);
|
|
223
|
+
if (row) {
|
|
224
|
+
tableState.set(rowId, row);
|
|
225
|
+
}
|
|
226
|
+
(_a = tableElement.columnIds) === null || _a === void 0 ? void 0 : _a.forEach(columnId => {
|
|
227
|
+
const column = childElementsMap.get(columnId);
|
|
228
|
+
if (column) {
|
|
229
|
+
tableState.set(columnId, column);
|
|
230
|
+
}
|
|
231
|
+
const cell = tableChildElements.find(el => el.rowId === rowId && el.columnId === columnId);
|
|
232
|
+
if (cell) {
|
|
233
|
+
const compositeId = `${rowId}-${columnId}`;
|
|
234
|
+
tableState.set(cell.id, cell);
|
|
235
|
+
tableState.set(compositeId, cell);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
return tableState;
|
|
240
|
+
}
|
|
241
|
+
static getOverlappedTable(elementBox, index, tables) {
|
|
242
|
+
let result = null;
|
|
243
|
+
for (const table of tables.values()) {
|
|
244
|
+
if (this.isOnTable(table, index, elementBox)) {
|
|
245
|
+
if (!result || table.index > result.index) {
|
|
246
|
+
result = table;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
static isOnTable(table, index, elementBox) {
|
|
253
|
+
return index > table.index && TableStateService.isInBox(table.box, elementBox);
|
|
254
|
+
}
|
|
255
|
+
static isOnCell(table, cellId, elementBox) {
|
|
256
|
+
var _a, _b;
|
|
257
|
+
const cellState = table.cells.get(cellId);
|
|
258
|
+
if (cellState && !cellState.isMerged) {
|
|
259
|
+
const scale = ((_b = (_a = table.element) === null || _a === void 0 ? void 0 : _a.scale) === null || _b === void 0 ? void 0 : _b.x) || 1;
|
|
260
|
+
const cellBox = this.getTableCoordinateBox({
|
|
261
|
+
x: table.element.position.x + cellState.x * scale,
|
|
262
|
+
y: table.element.position.y + cellState.y * scale,
|
|
263
|
+
width: cellState.width * scale,
|
|
264
|
+
height: cellState.height * scale,
|
|
265
|
+
});
|
|
266
|
+
return TableStateService.isInBox(cellBox, elementBox);
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
static isValidTableMember(documentElement) {
|
|
271
|
+
return !['frame', 'table', 'cell', 'column', 'row', 'group'].includes(documentElement.type);
|
|
272
|
+
}
|
|
273
|
+
static getTableViewBox(element) {
|
|
274
|
+
var _a;
|
|
275
|
+
const scale = ((_a = element === null || element === void 0 ? void 0 : element.scale) === null || _a === void 0 ? void 0 : _a.x) || 1;
|
|
276
|
+
return {
|
|
277
|
+
x: element.position.x,
|
|
278
|
+
y: element.position.y,
|
|
279
|
+
width: element.size.width * scale,
|
|
280
|
+
height: element.size.height * scale,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
static getTableCoordinateBox({ x, y, width, height }) {
|
|
284
|
+
return {
|
|
285
|
+
x,
|
|
286
|
+
y,
|
|
287
|
+
width,
|
|
288
|
+
height,
|
|
289
|
+
left: x,
|
|
290
|
+
right: x + width,
|
|
291
|
+
top: y,
|
|
292
|
+
bottom: y + height,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
static getTableMemberCoordinateBox({ x, y, width, height }) {
|
|
296
|
+
return {
|
|
297
|
+
x,
|
|
298
|
+
y,
|
|
299
|
+
width,
|
|
300
|
+
height,
|
|
301
|
+
left: x + width * 0.5,
|
|
302
|
+
right: x + width * 0.5,
|
|
303
|
+
top: y + height * 0.5,
|
|
304
|
+
bottom: y + height * 0.5,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
static getOverlappedCell(table, elementBox) {
|
|
308
|
+
var _a, _b;
|
|
309
|
+
let overlappedCell = null;
|
|
310
|
+
outer: for (let rowIndex = 0; rowIndex < ((_a = table.element.rowIds) === null || _a === void 0 ? void 0 : _a.length); rowIndex++) {
|
|
311
|
+
const rowId = table.element.rowIds[rowIndex];
|
|
312
|
+
for (let columnIndex = 0; columnIndex < ((_b = table.element.columnIds) === null || _b === void 0 ? void 0 : _b.length); columnIndex++) {
|
|
313
|
+
const columnId = table.element.columnIds[columnIndex];
|
|
314
|
+
const compositeCellId = `${rowId}-${columnId}`;
|
|
315
|
+
const cell = table.childElementsMap.get(compositeCellId);
|
|
316
|
+
if (cell && TableStateService.isOnCell(table, cell.id, elementBox)) {
|
|
317
|
+
overlappedCell = cell;
|
|
318
|
+
break outer;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return overlappedCell;
|
|
323
|
+
}
|
|
324
|
+
static isInBox(box, elementBox) {
|
|
325
|
+
return (box.bottom > elementBox.bottom &&
|
|
326
|
+
box.top < elementBox.top &&
|
|
327
|
+
box.right > elementBox.right &&
|
|
328
|
+
box.left < elementBox.left);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
exports.TableStateService = TableStateService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/document-table",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "Library for document tables",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@contrail/actions": "^1.0.17",
|
|
42
42
|
"@contrail/documents": "^1.3.2",
|
|
43
43
|
"@contrail/types": "^3.1.3",
|
|
44
|
-
"@contrail/util": "^1.1.
|
|
44
|
+
"@contrail/util": "^1.1.19",
|
|
45
45
|
"reflect-metadata": "^0.1.13"
|
|
46
46
|
}
|
|
47
47
|
}
|