@atlaskit/editor-plugin-table 12.2.6 → 12.2.7
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/CHANGELOG.md +8 -0
- package/package.json +4 -4
- package/afm-cc/tsconfig.json +0 -123
- package/afm-dev-agents/tsconfig.json +0 -123
- package/afm-jira/tsconfig.json +0 -123
- package/afm-passionfruit/tsconfig.json +0 -123
- package/afm-post-office/tsconfig.json +0 -123
- package/afm-rovo-extension/tsconfig.json +0 -123
- package/afm-townsquare/tsconfig.json +0 -123
- package/afm-volt/tsconfig.json +0 -114
- package/build/tsconfig.json +0 -23
- package/docs/0-intro.tsx +0 -57
- package/src/index.ts +0 -21
- package/src/nodeviews/ExternalDropTargets.tsx +0 -91
- package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
- package/src/nodeviews/TableCell.ts +0 -134
- package/src/nodeviews/TableComponent.tsx +0 -1590
- package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
- package/src/nodeviews/TableContainer.tsx +0 -926
- package/src/nodeviews/TableNodeViewBase.ts +0 -29
- package/src/nodeviews/TableResizer.tsx +0 -884
- package/src/nodeviews/TableRow.ts +0 -830
- package/src/nodeviews/TableStickyScrollbar.ts +0 -211
- package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
- package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
- package/src/nodeviews/table-container-styles.ts +0 -9
- package/src/nodeviews/table-node-views.ts +0 -76
- package/src/nodeviews/table.tsx +0 -530
- package/src/nodeviews/toDOM.ts +0 -244
- package/src/nodeviews/types.ts +0 -36
- package/src/nodeviews/update-overflow-shadows.ts +0 -11
- package/src/pm-plugins/analytics/actions.ts +0 -21
- package/src/pm-plugins/analytics/commands.ts +0 -47
- package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
- package/src/pm-plugins/analytics/plugin-key.ts +0 -5
- package/src/pm-plugins/analytics/plugin.ts +0 -80
- package/src/pm-plugins/analytics/reducer.ts +0 -27
- package/src/pm-plugins/analytics/types.ts +0 -20
- package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
- package/src/pm-plugins/commands/clear.ts +0 -43
- package/src/pm-plugins/commands/collapse.ts +0 -17
- package/src/pm-plugins/commands/column-resize.ts +0 -478
- package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
- package/src/pm-plugins/commands/delete.ts +0 -42
- package/src/pm-plugins/commands/display-mode.ts +0 -18
- package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
- package/src/pm-plugins/commands/hover.ts +0 -242
- package/src/pm-plugins/commands/index.ts +0 -51
- package/src/pm-plugins/commands/insert.ts +0 -438
- package/src/pm-plugins/commands/misc.ts +0 -811
- package/src/pm-plugins/commands/referentiality.ts +0 -15
- package/src/pm-plugins/commands/selection.ts +0 -537
- package/src/pm-plugins/commands/sort.ts +0 -102
- package/src/pm-plugins/commands/split-cell.ts +0 -28
- package/src/pm-plugins/commands/toggle.ts +0 -109
- package/src/pm-plugins/create-plugin-config.ts +0 -17
- package/src/pm-plugins/decorations/plugin.ts +0 -107
- package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
- package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
- package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
- package/src/pm-plugins/decorations/utils/types.ts +0 -16
- package/src/pm-plugins/default-table-selection.ts +0 -14
- package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
- package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
- package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
- package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
- package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
- package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
- package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
- package/src/pm-plugins/drag-and-drop/types.ts +0 -18
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
- package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
- package/src/pm-plugins/handlers.ts +0 -161
- package/src/pm-plugins/keymap.ts +0 -436
- package/src/pm-plugins/main.ts +0 -433
- package/src/pm-plugins/plugin-factory.ts +0 -42
- package/src/pm-plugins/plugin-key.ts +0 -8
- package/src/pm-plugins/reducer.ts +0 -145
- package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
- package/src/pm-plugins/sticky-headers/commands.ts +0 -8
- package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
- package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
- package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
- package/src/pm-plugins/sticky-headers/types.ts +0 -20
- package/src/pm-plugins/sticky-headers/util.ts +0 -18
- package/src/pm-plugins/table-analytics.ts +0 -100
- package/src/pm-plugins/table-local-id.ts +0 -213
- package/src/pm-plugins/table-resizing/commands.ts +0 -116
- package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
- package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
- package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
- package/src/pm-plugins/table-resizing/plugin.ts +0 -94
- package/src/pm-plugins/table-resizing/reducer.ts +0 -37
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
- package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
- package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
- package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
- package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
- package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
- package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
- package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
- package/src/pm-plugins/table-selection-keymap.ts +0 -64
- package/src/pm-plugins/table-size-selector.ts +0 -39
- package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
- package/src/pm-plugins/table-width.ts +0 -153
- package/src/pm-plugins/transforms/column-width.ts +0 -249
- package/src/pm-plugins/transforms/delete-columns.ts +0 -281
- package/src/pm-plugins/transforms/delete-rows.ts +0 -154
- package/src/pm-plugins/transforms/fix-tables.ts +0 -249
- package/src/pm-plugins/transforms/merge.ts +0 -301
- package/src/pm-plugins/transforms/replace-table.ts +0 -38
- package/src/pm-plugins/transforms/split.ts +0 -90
- package/src/pm-plugins/utils/alignment.ts +0 -33
- package/src/pm-plugins/utils/analytics.ts +0 -238
- package/src/pm-plugins/utils/collapse.ts +0 -93
- package/src/pm-plugins/utils/column-controls.ts +0 -250
- package/src/pm-plugins/utils/create.ts +0 -64
- package/src/pm-plugins/utils/decoration.ts +0 -672
- package/src/pm-plugins/utils/dom.ts +0 -251
- package/src/pm-plugins/utils/drag-menu.tsx +0 -491
- package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
- package/src/pm-plugins/utils/guidelines.ts +0 -30
- package/src/pm-plugins/utils/merged-cells.ts +0 -239
- package/src/pm-plugins/utils/nodes.ts +0 -162
- package/src/pm-plugins/utils/paste.ts +0 -386
- package/src/pm-plugins/utils/row-controls.ts +0 -211
- package/src/pm-plugins/utils/selection.ts +0 -17
- package/src/pm-plugins/utils/snapping.ts +0 -136
- package/src/pm-plugins/utils/table.ts +0 -60
- package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
- package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
- package/src/pm-plugins/view-mode-sort/index.ts +0 -291
- package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
- package/src/pm-plugins/view-mode-sort/types.ts +0 -23
- package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
- package/src/tablePlugin.tsx +0 -971
- package/src/tablePluginType.ts +0 -102
- package/src/types/index.ts +0 -592
- package/src/ui/ColumnResizeWidget/index.tsx +0 -61
- package/src/ui/ContentComponent.tsx +0 -311
- package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
- package/src/ui/DragHandle/index.tsx +0 -391
- package/src/ui/DragPreview/index.tsx +0 -51
- package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
- package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
- package/src/ui/FloatingContextualButton/index.tsx +0 -168
- package/src/ui/FloatingContextualButton/styles.ts +0 -69
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
- package/src/ui/FloatingContextualMenu/index.tsx +0 -141
- package/src/ui/FloatingContextualMenu/styles.ts +0 -77
- package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
- package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
- package/src/ui/FloatingDeleteButton/index.tsx +0 -383
- package/src/ui/FloatingDeleteButton/types.ts +0 -3
- package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
- package/src/ui/FloatingDragMenu/index.tsx +0 -136
- package/src/ui/FloatingDragMenu/styles.ts +0 -83
- package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
- package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
- package/src/ui/FloatingInsertButton/index.tsx +0 -314
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
- package/src/ui/SizeSelector/index.tsx +0 -74
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
- package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
- package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
- package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -175
- package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
- package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
- package/src/ui/TableFloatingControls/index.tsx +0 -275
- package/src/ui/TableFullWidthLabel/index.tsx +0 -38
- package/src/ui/common-styles.ts +0 -1218
- package/src/ui/consts.ts +0 -109
- package/src/ui/event-handlers.ts +0 -662
- package/src/ui/global-styles.tsx +0 -55
- package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
- package/src/ui/icons/AddColLeftIcon.tsx +0 -37
- package/src/ui/icons/AddColRightIcon.tsx +0 -37
- package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
- package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
- package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
- package/src/ui/icons/DragHandleIcon.tsx +0 -16
- package/src/ui/icons/DragInMotionIcon.tsx +0 -54
- package/src/ui/icons/MergeCellsIcon.tsx +0 -26
- package/src/ui/icons/MinimisedHandle.tsx +0 -15
- package/src/ui/icons/SortingIconWrapper.tsx +0 -43
- package/src/ui/icons/SplitCellIcon.tsx +0 -34
- package/src/ui/toolbar.tsx +0 -1153
- package/src/ui/ui-styles.ts +0 -960
- package/tsconfig.app.json +0 -135
- package/tsconfig.dev.json +0 -54
- package/tsconfig.json +0 -18
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { findTable, TableMap } from '@atlaskit/editor-tables';
|
|
3
|
-
|
|
4
|
-
type MergeType = 'row' | 'column';
|
|
5
|
-
|
|
6
|
-
const getRect = (index: number, type: MergeType, map: TableMap) => {
|
|
7
|
-
if (type === 'column') {
|
|
8
|
-
const x = Math.max(Math.min(index, map.width - 1), 0); // clamped index
|
|
9
|
-
return {
|
|
10
|
-
left: x,
|
|
11
|
-
right: x === index ? x + 1 : x,
|
|
12
|
-
top: 0,
|
|
13
|
-
bottom: map.height,
|
|
14
|
-
};
|
|
15
|
-
} else {
|
|
16
|
-
const y = Math.max(Math.min(index, map.height - 1), 0); // clamped index
|
|
17
|
-
return {
|
|
18
|
-
left: 0,
|
|
19
|
-
right: map.width,
|
|
20
|
-
top: y,
|
|
21
|
-
bottom: y === index ? y + 1 : y,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const hasMergedCellsInBetween =
|
|
27
|
-
(indexes: number[], type: MergeType) =>
|
|
28
|
-
(selection: Selection): boolean => {
|
|
29
|
-
const table = findTable(selection);
|
|
30
|
-
if (!table) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const map = TableMap.get(table.node);
|
|
35
|
-
const cellPositions = new Set<number>();
|
|
36
|
-
const mergedCells = new Set<number>();
|
|
37
|
-
|
|
38
|
-
map.map.forEach((value) => {
|
|
39
|
-
if (cellPositions.has(value)) {
|
|
40
|
-
mergedCells.add(value);
|
|
41
|
-
} else {
|
|
42
|
-
cellPositions.add(value);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
if (!mergedCells.size) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const getMergedCellsInRect = (index: number, type: MergeType) => {
|
|
51
|
-
const rect = getRect(index, type, map);
|
|
52
|
-
const isValidRectangle = rect.left < rect.right && rect.top < rect.bottom;
|
|
53
|
-
if (!isValidRectangle) {
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const cells = map.cellsInRect(rect);
|
|
58
|
-
|
|
59
|
-
let allCellsInRect = [];
|
|
60
|
-
if (type === 'column') {
|
|
61
|
-
allCellsInRect = map.map.filter((_, key) => key % map.width === index);
|
|
62
|
-
} else {
|
|
63
|
-
allCellsInRect = map.map.filter((_, key) => Math.floor(key / map.width) === index);
|
|
64
|
-
}
|
|
65
|
-
const mergedCell = allCellsInRect.filter((nodePos) => {
|
|
66
|
-
return !cells.includes(nodePos) // cell exists in Rect but not show in the map.cellsInRect list => merged cell
|
|
67
|
-
? true
|
|
68
|
-
: mergedCells.has(nodePos); // cell includes in mergedCells => merged cell
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return [...new Set(mergedCell)];
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const mergedCellsInRectArr = indexes.map((index) => getMergedCellsInRect(index, type));
|
|
75
|
-
|
|
76
|
-
// Currently only support 2 indexes, but we can extend this to support more indexes in the future.
|
|
77
|
-
return mergedCellsInRectArr[0].some((cell) => mergedCellsInRectArr[1].includes(cell));
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// Checks if any cell in the column with colIndex is merged with a cell in a column to the left or to the right of it.
|
|
81
|
-
// colIndex is a logical index of the column. It starts at 0 and goes up to tableMap.width - 1.
|
|
82
|
-
export const hasMergedCellsWithColumnNextToColumnIndex = (
|
|
83
|
-
colIndex: number,
|
|
84
|
-
selection: Selection,
|
|
85
|
-
) => {
|
|
86
|
-
const table = findTable(selection);
|
|
87
|
-
if (!table) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const tableMap = TableMap.get(table.node);
|
|
92
|
-
const { width } = tableMap;
|
|
93
|
-
if (width <= 1) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (colIndex < 0 || colIndex > width - 1) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const { map } = tableMap;
|
|
102
|
-
// j is an index in the tableMap.map array. tableMap.map is a flat array.
|
|
103
|
-
// Each item of this array contains a number.
|
|
104
|
-
// The number represents the position of the corresponding cell in the tableMap. It exists for each cell.
|
|
105
|
-
// If there are merged cells, their positions will be represented by the same number.
|
|
106
|
-
const isFirstColumn = colIndex === 0;
|
|
107
|
-
const isLastColumn = colIndex === width - 1;
|
|
108
|
-
for (let j = colIndex; j < map.length; j += width) {
|
|
109
|
-
if (
|
|
110
|
-
(!isFirstColumn && map[j] === map[j - 1]) || // compare with a cell in the column on the left
|
|
111
|
-
(!isLastColumn && map[j] === map[j + 1]) // compare with a cell in the column on the right
|
|
112
|
-
) {
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return false;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// Checks if any cell in the row with rowIndex is merged with a cell in a row above or below it.
|
|
121
|
-
export const hasMergedCellsWithRowNextToRowIndex = (
|
|
122
|
-
rowIndex: number, // logical row index in the table. It starts at 0 and goes up to tableMap.height - 1.
|
|
123
|
-
selection: Selection,
|
|
124
|
-
) => {
|
|
125
|
-
const table = findTable(selection);
|
|
126
|
-
if (!table) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const tableMap = TableMap.get(table.node);
|
|
131
|
-
const { height } = tableMap;
|
|
132
|
-
if (height <= 1) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (rowIndex < 0 || rowIndex > height - 1) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const { map, width } = tableMap; // map is a flat array representing position of each cell in the table.
|
|
141
|
-
const indexOfFirstCellInTheRow = rowIndex * width;
|
|
142
|
-
const indexOfLastCellInTheRow = indexOfFirstCellInTheRow + width - 1;
|
|
143
|
-
const isFirstRow = rowIndex === 0;
|
|
144
|
-
const isLastRow = rowIndex === height - 1;
|
|
145
|
-
// j is an index of a cell in a row
|
|
146
|
-
for (let j = indexOfFirstCellInTheRow; j <= indexOfLastCellInTheRow; j++) {
|
|
147
|
-
if (
|
|
148
|
-
(!isFirstRow && map[j] === map[j - width]) || // compare with a cell in the row above
|
|
149
|
-
(!isLastRow && map[j] === map[j + width]) // compare with a cell in the row below
|
|
150
|
-
) {
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return false;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
export const hasMergedCellsInSelection =
|
|
159
|
-
(indexes: number[], type: MergeType) =>
|
|
160
|
-
(selection: Selection): boolean => {
|
|
161
|
-
const table = findTable(selection);
|
|
162
|
-
if (!table) {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const map = TableMap.get(table.node);
|
|
167
|
-
|
|
168
|
-
if (!map.hasMergedCells()) {
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return checkEdgeHasMergedCells(indexes, map, type);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* this check the selection has merged cells with previous/next col or row.
|
|
177
|
-
*
|
|
178
|
-
* @param indexes - this get the indexes of the selection,e.g. [0,1] for selecting first two rows or columns.
|
|
179
|
-
* @param tableMap - this return a TableMap object.
|
|
180
|
-
* @param direction - check selection is selected by row or column
|
|
181
|
-
* @returns boolean
|
|
182
|
-
*/
|
|
183
|
-
export const checkEdgeHasMergedCells = (
|
|
184
|
-
indexes: number[],
|
|
185
|
-
tableMap: TableMap,
|
|
186
|
-
direction: 'row' | 'column',
|
|
187
|
-
): boolean => {
|
|
188
|
-
const { mapByRow, mapByColumn } = tableMap;
|
|
189
|
-
const map = 'row' === direction ? mapByRow : mapByColumn;
|
|
190
|
-
const lengthLimiter = direction === 'row' ? tableMap.width : tableMap.height;
|
|
191
|
-
const minIndex = Math.min(...indexes);
|
|
192
|
-
const maxIndex = Math.max(...indexes);
|
|
193
|
-
let isTopSideHaveMergedCells = false;
|
|
194
|
-
let isBottomSideHaveMergedCells = false;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* this is to check if the cell position from last focused table is overflow. since if you selection from a cell in 6th row and 7th column cell in a 7x8 table to 3x3 table, the cell position will be overflow because new table dont have this cell at all.
|
|
198
|
-
TODO: ED-22335 this should better called only when hover over the drag handle.
|
|
199
|
-
*/
|
|
200
|
-
const isOldMinIndex = !map[minIndex - 1] || !map[minIndex];
|
|
201
|
-
const isOldMaxIndex = !map[maxIndex + 1] || !map[maxIndex];
|
|
202
|
-
|
|
203
|
-
if (minIndex > 0 && !isOldMinIndex) {
|
|
204
|
-
const prevSelectionSet = map[minIndex - 1];
|
|
205
|
-
const minSelectionSet = map[minIndex];
|
|
206
|
-
for (let i = 0; i < lengthLimiter; i++) {
|
|
207
|
-
if (prevSelectionSet[i] === minSelectionSet[i]) {
|
|
208
|
-
isTopSideHaveMergedCells = true;
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (maxIndex < map.length - 1 && !isOldMaxIndex) {
|
|
215
|
-
const afterSelectionSet = map[maxIndex + 1];
|
|
216
|
-
const maxSelectionSet = map[maxIndex];
|
|
217
|
-
|
|
218
|
-
for (let i = 0; i < lengthLimiter; i++) {
|
|
219
|
-
if (afterSelectionSet[i] === maxSelectionSet[i]) {
|
|
220
|
-
isBottomSideHaveMergedCells = true;
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return isTopSideHaveMergedCells || isBottomSideHaveMergedCells;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* this function will find the duplicate position in the array(table map position array).
|
|
230
|
-
*
|
|
231
|
-
* @param array this usually be the array including positions of the table map.
|
|
232
|
-
* @returns []
|
|
233
|
-
*/
|
|
234
|
-
export const findDuplicatePosition = (array: number[]): number[] => {
|
|
235
|
-
if (!array) {
|
|
236
|
-
return [];
|
|
237
|
-
}
|
|
238
|
-
return array.filter((item, index) => array.indexOf(item) !== index);
|
|
239
|
-
};
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { mapChildren } from '@atlaskit/editor-common/utils';
|
|
2
|
-
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
|
-
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
6
|
-
|
|
7
|
-
export const isIsolating = (node: PmNode): boolean => {
|
|
8
|
-
return !!node.type.spec.isolating;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const containsHeaderColumn = (table: PmNode): boolean => {
|
|
12
|
-
const map = TableMap.get(table);
|
|
13
|
-
// Get cell positions for first column.
|
|
14
|
-
const cellPositions = map.cellsInRect({
|
|
15
|
-
left: 0,
|
|
16
|
-
top: 0,
|
|
17
|
-
right: 1,
|
|
18
|
-
bottom: map.height,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < cellPositions.length; i++) {
|
|
22
|
-
try {
|
|
23
|
-
const cell = table.nodeAt(cellPositions[i]);
|
|
24
|
-
if (cell && cell.type !== table.type.schema.nodes.tableHeader) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return true;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const containsHeaderRow = (table: PmNode): boolean => {
|
|
36
|
-
const map = TableMap.get(table);
|
|
37
|
-
for (let i = 0; i < map.width; i++) {
|
|
38
|
-
const cell = table.nodeAt(map.map[i]);
|
|
39
|
-
if (cell && cell.type !== table.type.schema.nodes.tableHeader) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return true;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const checkIfHeaderColumnEnabled = (selection: Selection): boolean =>
|
|
47
|
-
filterNearSelection(selection, findTable, containsHeaderColumn, false);
|
|
48
|
-
|
|
49
|
-
export const checkIfHeaderRowEnabled = (selection: Selection): boolean =>
|
|
50
|
-
filterNearSelection(selection, findTable, containsHeaderRow, false);
|
|
51
|
-
|
|
52
|
-
export const checkIfNumberColumnEnabled = (selection: Selection): boolean =>
|
|
53
|
-
filterNearSelection(selection, findTable, (table) => !!table.attrs.isNumberColumnEnabled, false);
|
|
54
|
-
|
|
55
|
-
export const getTableWidth = (node: PmNode) => {
|
|
56
|
-
return getTableWidths(node).reduce((acc, current) => acc + current, 0);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const tablesHaveDifferentColumnWidths = (
|
|
60
|
-
currentTable: PmNode,
|
|
61
|
-
previousTable: PmNode,
|
|
62
|
-
): boolean => {
|
|
63
|
-
const currentTableWidths = getTableWidths(currentTable);
|
|
64
|
-
const previousTableWidths = getTableWidths(previousTable);
|
|
65
|
-
|
|
66
|
-
if (currentTableWidths.length !== previousTableWidths.length) {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const sameWidths = currentTableWidths.every((value: number, index: number) => {
|
|
71
|
-
return value === previousTableWidths[index];
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return sameWidths === false;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const tablesHaveDifferentNoOfColumns = (
|
|
78
|
-
currentTable: PmNode,
|
|
79
|
-
previousTable: PmNode,
|
|
80
|
-
): boolean => {
|
|
81
|
-
const prevMap = TableMap.get(previousTable);
|
|
82
|
-
const currentMap = TableMap.get(currentTable);
|
|
83
|
-
|
|
84
|
-
return prevMap.width !== currentMap.width;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export const tablesHaveDifferentNoOfRows = (
|
|
88
|
-
currentTable: PmNode,
|
|
89
|
-
previousTable: PmNode,
|
|
90
|
-
): boolean => {
|
|
91
|
-
const prevMap = TableMap.get(previousTable);
|
|
92
|
-
const currentMap = TableMap.get(currentTable);
|
|
93
|
-
|
|
94
|
-
return prevMap.height !== currentMap.height;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
function filterNearSelection<T, U>(
|
|
98
|
-
selection: Selection,
|
|
99
|
-
findNode: (selection: Selection) => { pos: number; node: PmNode } | undefined,
|
|
100
|
-
predicate: (node: PmNode, pos?: number) => T,
|
|
101
|
-
defaultValue: U,
|
|
102
|
-
): T | U {
|
|
103
|
-
const found = findNode(selection);
|
|
104
|
-
if (!found) {
|
|
105
|
-
return defaultValue;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return predicate(found.node, found.pos);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function getTableWidths(node: PmNode): number[] {
|
|
112
|
-
if (!node.content.firstChild) {
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const tableWidths: Array<number> = [];
|
|
117
|
-
node.content.firstChild.content.forEach((cell) => {
|
|
118
|
-
if (Array.isArray(cell.attrs.colwidth)) {
|
|
119
|
-
const colspan = cell.attrs.colspan || 1;
|
|
120
|
-
tableWidths.push(...cell.attrs.colwidth.slice(0, colspan));
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
return tableWidths;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export const isTableNested = (state: EditorState, tablePos = 0): boolean => {
|
|
128
|
-
const parent = state.doc.resolve(tablePos).parent;
|
|
129
|
-
const nodeTypes = state.schema.nodes;
|
|
130
|
-
|
|
131
|
-
return (
|
|
132
|
-
parent.type === nodeTypes.layoutColumn ||
|
|
133
|
-
parent.type === nodeTypes.expand ||
|
|
134
|
-
parent.type === nodeTypes.bodiedExtension ||
|
|
135
|
-
parent.type === nodeTypes.extensionFrame ||
|
|
136
|
-
parent.type === nodeTypes.tableHeader ||
|
|
137
|
-
parent.type === nodeTypes.tableCell
|
|
138
|
-
);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export const isTableNestedInMoreThanOneNode = (state: EditorState, tablePos = 0) => {
|
|
142
|
-
return state.doc.resolve(tablePos).depth > 2;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const anyChildCellMergedAcrossRow = (node: PmNode): boolean =>
|
|
146
|
-
mapChildren(node, (child) => child.attrs.rowspan || 0).some((rowspan) => rowspan > 1);
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Check if a given node is a header row with this definition:
|
|
150
|
-
* - all children are tableHeader cells
|
|
151
|
-
* - no table cells have been have merged with other table row cells
|
|
152
|
-
*
|
|
153
|
-
* @param node ProseMirror node
|
|
154
|
-
* @return boolean if it meets definition
|
|
155
|
-
*/
|
|
156
|
-
export const supportedHeaderRow = (node: PmNode): boolean => {
|
|
157
|
-
const allHeaders = mapChildren(node, (child) => child.type.name === 'tableHeader').every(Boolean);
|
|
158
|
-
|
|
159
|
-
const someMerged = anyChildCellMergedAcrossRow(node);
|
|
160
|
-
|
|
161
|
-
return allHeaders && !someMerged;
|
|
162
|
-
};
|