@atlaskit/editor-plugin-table 0.1.0 → 0.1.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/CHANGELOG.md +8 -0
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/esm/version.json +1 -1
- package/examples/99-testing.tsx +35 -30
- package/package.json +2 -11
- package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
- package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
- package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
- package/src/__tests__/integration/resize.ts +1 -2
- package/src/__tests__/unit/analytics.ts +33 -32
- package/src/__tests__/unit/collab.ts +12 -9
- package/src/__tests__/unit/commands/sort.ts +28 -28
- package/src/__tests__/unit/copy-paste.ts +6 -8
- package/src/__tests__/unit/event-handlers.ts +7 -10
- package/src/__tests__/unit/fix-tables.ts +17 -23
- package/src/__tests__/unit/get-toolbar-config.ts +0 -5
- package/src/__tests__/unit/hover-selection.ts +1 -66
- package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
- package/src/__tests__/unit/index.ts +5 -5
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
- package/src/__tests__/unit/nodeviews/cell.ts +12 -10
- package/src/__tests__/unit/nodeviews/table.ts +25 -26
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
- package/src/__tests__/unit/toolbar.ts +18 -5
- package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
- package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
- package/src/__tests__/unit/ui/RowControls.tsx +112 -141
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
- package/src/__tests__/unit/undo-redo.ts +10 -9
- package/src/__tests__/unit/utils/nodes.ts +8 -4
- package/src/__tests__/unit/utils/row-controls.ts +8 -4
- package/src/plugins/table/commands/clear.ts +30 -29
- package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
- package/src/plugins/table/commands/insert.ts +91 -91
- package/src/plugins/table/commands/misc.ts +123 -125
- package/src/plugins/table/commands/selection.ts +329 -319
- package/src/plugins/table/commands-with-analytics.ts +299 -294
- package/src/plugins/table/event-handlers.ts +111 -111
- package/src/plugins/table/handlers.ts +95 -94
- package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
- package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
- package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
- package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
- package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
- package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
- package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
- package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
- package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
- package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
- package/src/plugins/table/toolbar.tsx +116 -113
- package/src/plugins/table/transforms/column-width.ts +143 -146
- package/src/plugins/table/transforms/delete-columns.ts +144 -142
- package/src/plugins/table/transforms/delete-rows.ts +110 -111
- package/src/plugins/table/transforms/metadata.ts +9 -9
- package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
- package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
- package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
- package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
- package/src/plugins/table/ui/common-styles.ts +1 -3
- package/src/plugins/table/utils/analytics.ts +24 -25
- package/src/plugins/table/utils/dom.ts +3 -3
- package/src/plugins/table/utils/row-controls.ts +92 -93
- package/dist/types-ts4.0/index.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
- package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
- package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
- package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
- package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
- package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
- package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
- package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
- package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
- package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
- package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
- package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
- package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
- package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
- package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
- package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
- package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
- package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +0 -50
|
@@ -9,173 +9,175 @@ import { AddColumnStep } from '@atlaskit/adf-schema/steps';
|
|
|
9
9
|
import { setMeta } from './metadata';
|
|
10
10
|
import { splitCellsInColumns } from './split';
|
|
11
11
|
|
|
12
|
-
const deleteColumnsCustomStep =
|
|
13
|
-
|
|
14
|
-
): Transaction => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// Need to split all the merge in the ranges (this is the current behaviour)
|
|
21
|
-
// Maybe is better to split only the last column?
|
|
22
|
-
// TODO: After talking with Roto about this behaviour, he likes when we dont split the columns, I am keeping this for consistency of the current implementation.
|
|
23
|
-
splitCellsInColumns(tr, table.pos, rect.left, rect.right);
|
|
24
|
-
|
|
25
|
-
// Delete the columns
|
|
26
|
-
let mapStart = tr.mapping.maps.length;
|
|
27
|
-
const originalDoc = tr.doc;
|
|
28
|
-
const deletedColumns = [];
|
|
29
|
-
for (let i = rect.left; i < rect.right; i++) {
|
|
30
|
-
const step = AddColumnStep.create(originalDoc, table.pos, i, true);
|
|
31
|
-
deletedColumns.push(i);
|
|
32
|
-
tr.step(step.map(tr.mapping.slice(mapStart))!);
|
|
33
|
-
}
|
|
12
|
+
const deleteColumnsCustomStep =
|
|
13
|
+
(rect: Rect) =>
|
|
14
|
+
(tr: Transaction): Transaction => {
|
|
15
|
+
const table = findTable(tr.selection);
|
|
16
|
+
if (!table) {
|
|
17
|
+
return tr;
|
|
18
|
+
}
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
tr.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
20
|
+
// Need to split all the merge in the ranges (this is the current behaviour)
|
|
21
|
+
// Maybe is better to split only the last column?
|
|
22
|
+
// TODO: After talking with Roto about this behaviour, he likes when we dont split the columns, I am keeping this for consistency of the current implementation.
|
|
23
|
+
splitCellsInColumns(tr, table.pos, rect.left, rect.right);
|
|
24
|
+
|
|
25
|
+
// Delete the columns
|
|
26
|
+
let mapStart = tr.mapping.maps.length;
|
|
27
|
+
const originalDoc = tr.doc;
|
|
28
|
+
const deletedColumns = [];
|
|
29
|
+
for (let i = rect.left; i < rect.right; i++) {
|
|
30
|
+
const step = AddColumnStep.create(originalDoc, table.pos, i, true);
|
|
31
|
+
deletedColumns.push(i);
|
|
32
|
+
tr.step(step.map(tr.mapping.slice(mapStart))!);
|
|
44
33
|
}
|
|
45
|
-
}
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
const tablePosResult = tr.mapping.mapResult(table.pos);
|
|
36
|
+
if (tablePosResult.deleted) {
|
|
37
|
+
const pos = Math.min(tablePosResult.pos, tr.doc.nodeSize - 1);
|
|
38
|
+
tr.setSelection(Selection.near(tr.doc.resolve(pos)));
|
|
39
|
+
} else {
|
|
40
|
+
const newTable = tr.doc.nodeAt(tablePosResult.pos);
|
|
41
|
+
if (newTable) {
|
|
42
|
+
const cursorPos = getNextCursorPos(newTable, deletedColumns);
|
|
43
|
+
tr.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos)));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
49
46
|
|
|
50
|
-
const deleteColumnsLegacy = (rect: Rect) => (tr: Transaction): Transaction => {
|
|
51
|
-
const table = findTable(tr.selection);
|
|
52
|
-
if (!table) {
|
|
53
47
|
return tr;
|
|
54
|
-
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const deleteColumnsLegacy =
|
|
51
|
+
(rect: Rect) =>
|
|
52
|
+
(tr: Transaction): Transaction => {
|
|
53
|
+
const table = findTable(tr.selection);
|
|
54
|
+
if (!table) {
|
|
55
|
+
return tr;
|
|
56
|
+
}
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const columnsToDelete: number[] = [];
|
|
59
|
+
for (let i = rect.left; i < rect.right; i++) {
|
|
60
|
+
columnsToDelete.push(i);
|
|
61
|
+
}
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
if (!columnsToDelete.length) {
|
|
64
|
+
return tr;
|
|
65
|
+
}
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const map = TableMap.get(table.node);
|
|
68
|
+
const rows: PMNode[] = [];
|
|
69
|
+
const seen: { [key: string]: boolean } = {};
|
|
70
|
+
const deletedCells: { [key: string]: boolean } = {};
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
72
|
+
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
73
|
+
const rowCells: PMNode[] = [];
|
|
74
|
+
const row = table.node.child(rowIndex);
|
|
75
|
+
|
|
76
|
+
for (let colIndex = 0; colIndex < map.width; colIndex++) {
|
|
77
|
+
const cellPos = map.map[rowIndex * map.width + colIndex];
|
|
78
|
+
const cell = table.node.nodeAt(cellPos);
|
|
79
|
+
if (!cell) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const cellsInColumn = map.cellsInRect({
|
|
83
|
+
left: colIndex,
|
|
84
|
+
top: 0,
|
|
85
|
+
right: colIndex + 1,
|
|
86
|
+
bottom: map.height,
|
|
87
|
+
});
|
|
88
|
+
if (columnsToDelete.indexOf(colIndex) === -1) {
|
|
89
|
+
// decrement colspans for col-spanning cells that overlap deleted columns
|
|
90
|
+
if (cellsInColumn.indexOf(cellPos) > -1 && !seen[cellPos]) {
|
|
91
|
+
let overlappingCols = 0;
|
|
92
|
+
columnsToDelete.forEach((colIndexToDelete) => {
|
|
93
|
+
if (
|
|
94
|
+
colIndex < colIndexToDelete &&
|
|
95
|
+
cell.attrs.colspan + colIndex - 1 >= colIndexToDelete
|
|
96
|
+
) {
|
|
97
|
+
overlappingCols += 1;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (overlappingCols > 0) {
|
|
101
|
+
const attrs: CellAttributes = {
|
|
102
|
+
...cell.attrs,
|
|
103
|
+
colspan: cell.attrs.colspan - overlappingCols,
|
|
104
|
+
};
|
|
105
|
+
if (cell.attrs.colwidth) {
|
|
106
|
+
const minColIndex = Math.min(...columnsToDelete);
|
|
107
|
+
const pos =
|
|
108
|
+
minColIndex > 0 ? minColIndex - map.colCount(cellPos) : 0;
|
|
109
|
+
const colwidth = cell.attrs.colwidth.slice() || [];
|
|
110
|
+
colwidth.splice(pos, overlappingCols);
|
|
111
|
+
attrs.colwidth = colwidth;
|
|
112
|
+
}
|
|
113
|
+
const newCell = cell.type.createChecked(
|
|
114
|
+
attrs,
|
|
115
|
+
cell.content,
|
|
116
|
+
cell.marks,
|
|
117
|
+
);
|
|
118
|
+
rowCells.push(newCell);
|
|
119
|
+
seen[cellPos] = true;
|
|
120
|
+
continue;
|
|
96
121
|
}
|
|
97
|
-
})
|
|
98
|
-
|
|
122
|
+
} else if (deletedCells[cellPos]) {
|
|
123
|
+
// if we're removing a col-spanning cell, we need to add missing cells to columns to the right
|
|
99
124
|
const attrs: CellAttributes = {
|
|
100
125
|
...cell.attrs,
|
|
101
|
-
colspan:
|
|
126
|
+
colspan: 1,
|
|
127
|
+
rowspan: 1,
|
|
102
128
|
};
|
|
103
129
|
if (cell.attrs.colwidth) {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
minColIndex > 0 ? minColIndex - map.colCount(cellPos) : 0;
|
|
107
|
-
const colwidth = cell.attrs.colwidth.slice() || [];
|
|
108
|
-
colwidth.splice(pos, overlappingCols);
|
|
109
|
-
attrs.colwidth = colwidth;
|
|
130
|
+
const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
|
|
131
|
+
attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
|
|
110
132
|
}
|
|
111
133
|
const newCell = cell.type.createChecked(
|
|
112
134
|
attrs,
|
|
113
|
-
cell.
|
|
135
|
+
cell.type.schema.nodes.paragraph.createChecked(),
|
|
114
136
|
cell.marks,
|
|
115
137
|
);
|
|
116
138
|
rowCells.push(newCell);
|
|
117
|
-
seen[cellPos] = true;
|
|
118
139
|
continue;
|
|
119
140
|
}
|
|
120
|
-
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
rowspan: 1,
|
|
126
|
-
};
|
|
127
|
-
if (cell.attrs.colwidth) {
|
|
128
|
-
const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
|
|
129
|
-
attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
|
|
141
|
+
|
|
142
|
+
// normal cells that we want to keep
|
|
143
|
+
if (!seen[cellPos]) {
|
|
144
|
+
seen[cellPos] = true;
|
|
145
|
+
rowCells.push(cell);
|
|
130
146
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
cell.type.schema.nodes.paragraph.createChecked(),
|
|
134
|
-
cell.marks,
|
|
135
|
-
);
|
|
136
|
-
rowCells.push(newCell);
|
|
137
|
-
continue;
|
|
147
|
+
} else if (cellsInColumn.indexOf(cellPos) > -1) {
|
|
148
|
+
deletedCells[cellPos] = true;
|
|
138
149
|
}
|
|
150
|
+
}
|
|
139
151
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
seen[cellPos] = true;
|
|
143
|
-
rowCells.push(cell);
|
|
144
|
-
}
|
|
145
|
-
} else if (cellsInColumn.indexOf(cellPos) > -1) {
|
|
146
|
-
deletedCells[cellPos] = true;
|
|
152
|
+
if (rowCells.length) {
|
|
153
|
+
rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
|
|
147
154
|
}
|
|
148
155
|
}
|
|
149
156
|
|
|
150
|
-
if (
|
|
151
|
-
|
|
157
|
+
if (!rows.length) {
|
|
158
|
+
return setMeta({ type: 'DELETE_COLUMNS', problem: 'EMPTY_TABLE' })(tr);
|
|
152
159
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (!rows.length) {
|
|
156
|
-
return setMeta({ type: 'DELETE_COLUMNS', problem: 'EMPTY_TABLE' })(tr);
|
|
157
|
-
}
|
|
158
160
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
const newTable = table.node.type.createChecked(
|
|
162
|
+
table.node.attrs,
|
|
163
|
+
rows,
|
|
164
|
+
table.node.marks,
|
|
165
|
+
);
|
|
164
166
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
const fixedTable = fixRowSpans(newTable);
|
|
168
|
+
if (fixedTable === null) {
|
|
169
|
+
return setMeta({ type: 'DELETE_COLUMNS', problem: 'FIX_ROWSPANS' })(tr);
|
|
170
|
+
}
|
|
169
171
|
|
|
170
|
-
|
|
172
|
+
const cursorPos = getNextCursorPos(newTable, columnsToDelete);
|
|
171
173
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
};
|
|
174
|
+
return setMeta({ type: 'DELETE_COLUMNS' })(
|
|
175
|
+
tr
|
|
176
|
+
.replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
|
|
177
|
+
// move cursor to the left of the deleted columns if possible, otherwise - to the first column
|
|
178
|
+
.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos))),
|
|
179
|
+
);
|
|
180
|
+
};
|
|
179
181
|
|
|
180
182
|
function getNextCursorPos(table: PMNode, deletedColumns: number[]): number {
|
|
181
183
|
const minColumn = Math.min(...deletedColumns);
|
|
@@ -241,11 +243,11 @@ function fixRowSpans(table: PMNode): PMNode | null {
|
|
|
241
243
|
return table.type.createChecked(table.attrs, rows, table.marks);
|
|
242
244
|
}
|
|
243
245
|
|
|
244
|
-
export const deleteColumns =
|
|
245
|
-
|
|
246
|
-
): Transaction => {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
};
|
|
246
|
+
export const deleteColumns =
|
|
247
|
+
(rect: Rect, allowAddColumnCustomStep = false) =>
|
|
248
|
+
(tr: Transaction): Transaction => {
|
|
249
|
+
if (allowAddColumnCustomStep) {
|
|
250
|
+
return deleteColumnsCustomStep(rect)(tr);
|
|
251
|
+
}
|
|
252
|
+
return deleteColumnsLegacy(rect)(tr);
|
|
253
|
+
};
|
|
@@ -8,139 +8,138 @@ import { CellAttributes } from '@atlaskit/adf-schema';
|
|
|
8
8
|
import { removeEmptyColumns } from './merge';
|
|
9
9
|
import { setMeta } from './metadata';
|
|
10
10
|
|
|
11
|
-
export const deleteRows =
|
|
12
|
-
rect: Rect,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
11
|
+
export const deleteRows =
|
|
12
|
+
(rect: Rect, isHeaderRowRequired: boolean = false) =>
|
|
13
|
+
(tr: Transaction): Transaction => {
|
|
14
|
+
const table = findTable(tr.selection);
|
|
15
|
+
if (!table) {
|
|
16
|
+
return tr;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const rowsToDelete: number[] = [];
|
|
20
|
+
|
|
21
|
+
const map = TableMap.get(table.node);
|
|
22
|
+
|
|
23
|
+
for (let i = rect.top; i < rect.bottom; i++) {
|
|
24
|
+
// skip header row if its required
|
|
25
|
+
if (isHeaderRowRequired) {
|
|
26
|
+
const cell = table.node.nodeAt(map.map[i * map.width]);
|
|
27
|
+
if (cell && cell.type !== cell.type.schema.nodes.tableHeader) {
|
|
28
|
+
rowsToDelete.push(i);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
29
31
|
rowsToDelete.push(i);
|
|
30
32
|
}
|
|
31
|
-
} else {
|
|
32
|
-
rowsToDelete.push(i);
|
|
33
33
|
}
|
|
34
|
-
}
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
if (!rowsToDelete.length) {
|
|
36
|
+
return tr;
|
|
37
|
+
}
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const rows: PMNode[] = [];
|
|
40
|
+
const seen: { [key: string]: boolean } = {};
|
|
41
|
+
const deletedCells: { [key: string]: boolean } = {};
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
44
|
+
const rowCells: PMNode[] = [];
|
|
45
|
+
const row = table.node.child(rowIndex);
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
for (let colIndex = 0; colIndex < map.width; colIndex++) {
|
|
48
|
+
const cellPos = map.map[rowIndex * map.width + colIndex];
|
|
49
|
+
const cell = table.node.nodeAt(cellPos);
|
|
50
|
+
if (!cell) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const cellsInRow = map.cellsInRect({
|
|
54
|
+
left: 0,
|
|
55
|
+
top: rowIndex,
|
|
56
|
+
right: map.width,
|
|
57
|
+
bottom: rowIndex + 1,
|
|
58
|
+
});
|
|
59
|
+
if (rowsToDelete.indexOf(rowIndex) === -1 && !seen[cellPos]) {
|
|
60
|
+
// decrement rowspans for row-spanning cells that overlap deleted rows
|
|
61
|
+
if (cellsInRow.indexOf(cellPos) > -1) {
|
|
62
|
+
let overlappingRows = 0;
|
|
63
|
+
rowsToDelete.forEach((rowIndexToDelete) => {
|
|
64
|
+
if (
|
|
65
|
+
rowIndex < rowIndexToDelete &&
|
|
66
|
+
cell.attrs.rowspan + rowIndex - 1 >= rowIndexToDelete
|
|
67
|
+
) {
|
|
68
|
+
overlappingRows += 1;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
if (overlappingRows > 0) {
|
|
72
|
+
const newCell = cell.type.createChecked(
|
|
73
|
+
{
|
|
74
|
+
...cell.attrs,
|
|
75
|
+
rowspan: cell.attrs.rowspan - overlappingRows,
|
|
76
|
+
},
|
|
77
|
+
cell.content,
|
|
78
|
+
cell.marks,
|
|
79
|
+
);
|
|
80
|
+
rowCells.push(newCell);
|
|
81
|
+
seen[cellPos] = true;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
} else if (deletedCells[cellPos]) {
|
|
85
|
+
// if we're removing a row-spanning cell, we need to add missing cells to rows below
|
|
86
|
+
const attrs: CellAttributes = {
|
|
87
|
+
...cell.attrs,
|
|
88
|
+
colspan: 1,
|
|
89
|
+
rowspan: 1,
|
|
90
|
+
};
|
|
91
|
+
if (cell.attrs.colwidth) {
|
|
92
|
+
const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
|
|
93
|
+
attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
|
|
70
94
|
}
|
|
71
|
-
});
|
|
72
|
-
if (overlappingRows > 0) {
|
|
73
95
|
const newCell = cell.type.createChecked(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
rowspan: cell.attrs.rowspan - overlappingRows,
|
|
77
|
-
},
|
|
78
|
-
cell.content,
|
|
96
|
+
attrs,
|
|
97
|
+
cell.type.schema.nodes.paragraph.createChecked(),
|
|
79
98
|
cell.marks,
|
|
80
99
|
);
|
|
81
100
|
rowCells.push(newCell);
|
|
82
|
-
seen[cellPos] = true;
|
|
83
101
|
continue;
|
|
84
102
|
}
|
|
85
|
-
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
rowspan: 1,
|
|
91
|
-
};
|
|
92
|
-
if (cell.attrs.colwidth) {
|
|
93
|
-
const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
|
|
94
|
-
attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
|
|
103
|
+
|
|
104
|
+
// normal cells that we want to keep
|
|
105
|
+
if (!seen[cellPos]) {
|
|
106
|
+
seen[cellPos] = true;
|
|
107
|
+
rowCells.push(cell);
|
|
95
108
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
cell.type.schema.nodes.paragraph.createChecked(),
|
|
99
|
-
cell.marks,
|
|
100
|
-
);
|
|
101
|
-
rowCells.push(newCell);
|
|
102
|
-
continue;
|
|
109
|
+
} else if (cellsInRow.indexOf(cellPos) > -1) {
|
|
110
|
+
deletedCells[cellPos] = true;
|
|
103
111
|
}
|
|
112
|
+
}
|
|
104
113
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
seen[cellPos] = true;
|
|
108
|
-
rowCells.push(cell);
|
|
109
|
-
}
|
|
110
|
-
} else if (cellsInRow.indexOf(cellPos) > -1) {
|
|
111
|
-
deletedCells[cellPos] = true;
|
|
114
|
+
if (rowCells.length) {
|
|
115
|
+
rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
118
|
|
|
115
|
-
if (
|
|
116
|
-
|
|
119
|
+
if (!rows.length) {
|
|
120
|
+
return setMeta({ type: 'DELETE_ROWS', problem: 'EMPTY_TABLE' })(tr);
|
|
117
121
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
122
|
+
|
|
123
|
+
const newTable = table.node.type.createChecked(
|
|
124
|
+
table.node.attrs,
|
|
125
|
+
rows,
|
|
126
|
+
table.node.marks,
|
|
127
|
+
);
|
|
128
|
+
const fixedTable = removeEmptyColumns(newTable);
|
|
129
|
+
if (fixedTable === null) {
|
|
130
|
+
return setMeta({ type: 'DELETE_ROWS', problem: 'REMOVE_EMPTY_COLUMNS' })(
|
|
131
|
+
tr,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const cursorPos = getNextCursorPos(newTable, rowsToDelete);
|
|
135
|
+
|
|
136
|
+
return setMeta({ type: 'DELETE_ROWS' })(
|
|
137
|
+
tr
|
|
138
|
+
.replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
|
|
139
|
+
// move cursor before the deleted rows if possible, otherwise - to the first row
|
|
140
|
+
.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos))),
|
|
133
141
|
);
|
|
134
|
-
}
|
|
135
|
-
const cursorPos = getNextCursorPos(newTable, rowsToDelete);
|
|
136
|
-
|
|
137
|
-
return setMeta({ type: 'DELETE_ROWS' })(
|
|
138
|
-
tr
|
|
139
|
-
.replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
|
|
140
|
-
// move cursor before the deleted rows if possible, otherwise - to the first row
|
|
141
|
-
.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos))),
|
|
142
|
-
);
|
|
143
|
-
};
|
|
142
|
+
};
|
|
144
143
|
|
|
145
144
|
function getNextCursorPos(table: PMNode, deletedRows: number[]): number {
|
|
146
145
|
const minRow = Math.min(...deletedRows);
|
|
@@ -24,12 +24,12 @@ export type TableMetaData =
|
|
|
24
24
|
problem?: TableProblems;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export const setMeta =
|
|
28
|
-
|
|
29
|
-
): Transaction => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
27
|
+
export const setMeta =
|
|
28
|
+
(meta: TableMetaData) =>
|
|
29
|
+
(tr: Transaction): Transaction => {
|
|
30
|
+
if ('problem' in meta) {
|
|
31
|
+
// Send analytics event whenever we encounter with a problem
|
|
32
|
+
fireAnalytics(meta);
|
|
33
|
+
}
|
|
34
|
+
return tr.setMeta(pluginKey, meta);
|
|
35
|
+
};
|
|
@@ -377,12 +377,13 @@ export class ContextualMenu extends Component<
|
|
|
377
377
|
this.toggleOpen();
|
|
378
378
|
break;
|
|
379
379
|
case 'distribute_columns':
|
|
380
|
-
const newResizeStateWithAnalytics =
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
380
|
+
const newResizeStateWithAnalytics =
|
|
381
|
+
getNewResizeStateFromSelectedColumns(
|
|
382
|
+
selectionRect,
|
|
383
|
+
state,
|
|
384
|
+
editorView.domAtPos.bind(editorView),
|
|
385
|
+
getEditorContainerWidth,
|
|
386
|
+
);
|
|
386
387
|
|
|
387
388
|
if (newResizeStateWithAnalytics) {
|
|
388
389
|
distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
1
|
+
import React, { Component, SyntheticEvent } from 'react';
|
|
2
2
|
|
|
3
3
|
import { Selection } from 'prosemirror-state';
|
|
4
4
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
@@ -263,7 +263,8 @@ class FloatingDeleteButton extends Component<Props, State> {
|
|
|
263
263
|
* @private
|
|
264
264
|
* @memberof FloatingDeleteButton
|
|
265
265
|
*/
|
|
266
|
-
private handleClick = () => {
|
|
266
|
+
private handleClick = (event: SyntheticEvent) => {
|
|
267
|
+
event.preventDefault();
|
|
267
268
|
const { editorAnalyticsAPI } = this.props;
|
|
268
269
|
let { state, dispatch } = this.props.editorView;
|
|
269
270
|
const {
|
|
@@ -202,11 +202,8 @@ export class FloatingInsertButton extends React.Component<
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
private getCellPosition(type: 'column' | 'row'): number | null {
|
|
205
|
-
const {
|
|
206
|
-
|
|
207
|
-
insertColumnButtonIndex,
|
|
208
|
-
insertRowButtonIndex,
|
|
209
|
-
} = this.props;
|
|
205
|
+
const { tableNode, insertColumnButtonIndex, insertRowButtonIndex } =
|
|
206
|
+
this.props;
|
|
210
207
|
const tableMap = TableMap.get(tableNode!);
|
|
211
208
|
|
|
212
209
|
if (type === 'column') {
|