@atlaskit/editor-plugin-table 5.3.24 → 5.3.26
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 +13 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +19 -6
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +6 -1
- package/dist/cjs/plugins/table/transforms/column-width.js +10 -43
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +26 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +19 -6
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +6 -1
- package/dist/es2019/plugins/table/transforms/column-width.js +10 -43
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +27 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +19 -6
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +6 -1
- package/dist/esm/plugins/table/transforms/column-width.js +10 -43
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +26 -1
- package/package.json +2 -5
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +31 -7
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +7 -1
- package/src/plugins/table/transforms/column-width.ts +14 -60
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +33 -1
- package/src/__tests__/integration/__snapshots__/auto-size.ts.snap +0 -612
- package/src/__tests__/integration/__snapshots__/delete-columns.ts.snap +0 -820
- package/src/__tests__/integration/__snapshots__/delete-last-column-in-full-width.ts.snap +0 -120
- package/src/__tests__/integration/__snapshots__/delete-last-column-with-empty-action.ts.snap +0 -120
- package/src/__tests__/integration/__snapshots__/delete-last-row-with-empty-action.ts.snap +0 -229
- package/src/__tests__/integration/__snapshots__/insert-row-inside-layout.ts.snap +0 -239
- package/src/__tests__/integration/__snapshots__/resize.ts.snap +0 -2685
- package/src/__tests__/integration/__snapshots__/scale.ts.snap +0 -1085
- package/src/__tests__/integration/arrow-down-into-table.ts +0 -50
- package/src/__tests__/integration/auto-size.ts +0 -92
- package/src/__tests__/integration/cell-selection.ts +0 -105
- package/src/__tests__/integration/delete-columns.ts +0 -99
- package/src/__tests__/integration/delete-last-column-in-full-width.ts +0 -73
- package/src/__tests__/integration/delete-last-column-with-empty-action.ts +0 -60
- package/src/__tests__/integration/delete-last-row-with-empty-action.ts +0 -99
- package/src/__tests__/integration/insert-row-inside-layout.ts +0 -52
- package/src/__tests__/integration/resize.ts +0 -333
- package/src/__tests__/integration/scale.ts +0 -70
|
@@ -78,71 +78,25 @@ export const updateColumnWidths =
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// updating all cells with new attributes
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
for (let
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
updatedCellsAttrs[pos].colwidth,
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
seen[pos] = true;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
const rows: PMNode[] = [];
|
|
104
|
-
const seen: { [key: number]: boolean } = {};
|
|
105
|
-
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
106
|
-
const row = table.child(rowIndex);
|
|
107
|
-
const cells: PMNode[] = [];
|
|
108
|
-
|
|
109
|
-
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
110
|
-
const mapIndex = rowIndex * map.width + columnIndex;
|
|
111
|
-
const pos = map.map[mapIndex];
|
|
112
|
-
const cell = table.nodeAt(pos);
|
|
113
|
-
if (!seen[pos] && cell) {
|
|
114
|
-
cells.push(
|
|
115
|
-
cell.type.createChecked(
|
|
116
|
-
updatedCellsAttrs[pos] || cell.attrs,
|
|
117
|
-
cell.content,
|
|
118
|
-
cell.marks,
|
|
81
|
+
const seen: { [key: number]: boolean } = {};
|
|
82
|
+
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
83
|
+
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
84
|
+
const mapIndex = rowIndex * map.width + columnIndex;
|
|
85
|
+
const pos = map.map[mapIndex];
|
|
86
|
+
const cell = table.nodeAt(pos);
|
|
87
|
+
if (!seen[pos] && cell) {
|
|
88
|
+
if (updatedCellsAttrs[pos]) {
|
|
89
|
+
tr.step(
|
|
90
|
+
new AttrStep(
|
|
91
|
+
pos + start,
|
|
92
|
+
'colwidth',
|
|
93
|
+
updatedCellsAttrs[pos].colwidth,
|
|
119
94
|
),
|
|
120
95
|
);
|
|
121
|
-
seen[pos] = true;
|
|
122
96
|
}
|
|
97
|
+
seen[pos] = true;
|
|
123
98
|
}
|
|
124
|
-
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
125
99
|
}
|
|
126
|
-
|
|
127
|
-
const tablePos = start - 1;
|
|
128
|
-
const selectionBookmark = tr.selection.getBookmark();
|
|
129
|
-
|
|
130
|
-
tr.replaceWith(
|
|
131
|
-
tablePos,
|
|
132
|
-
tablePos + table.nodeSize,
|
|
133
|
-
table.type.createChecked(table.attrs, rows, table.marks),
|
|
134
|
-
);
|
|
135
|
-
/**
|
|
136
|
-
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
137
|
-
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
138
|
-
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
139
|
-
* e.g. if we change the content before a selection. This is because mapping
|
|
140
|
-
* means moving it if the content in front of it changed. Instead we can get
|
|
141
|
-
* bookmark of selection.
|
|
142
|
-
*
|
|
143
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
144
|
-
*/
|
|
145
|
-
tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
146
100
|
}
|
|
147
101
|
|
|
148
102
|
return tr;
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from '@atlaskit/editor-common/ui-menu';
|
|
12
12
|
import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
13
13
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
14
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
14
15
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
15
16
|
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
16
17
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
@@ -23,6 +24,7 @@ import { token } from '@atlaskit/tokens';
|
|
|
23
24
|
|
|
24
25
|
import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
|
|
25
26
|
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
27
|
+
import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
26
28
|
import type { PluginConfig, TableDirection } from '../../types';
|
|
27
29
|
import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
|
|
28
30
|
import type { DragMenuConfig } from '../../utils/drag-menu';
|
|
@@ -132,9 +134,39 @@ export const DragMenu = ({
|
|
|
132
134
|
|
|
133
135
|
const { menuItems, menuCallback } = convertToDropdownItems(dragMenuConfig);
|
|
134
136
|
|
|
137
|
+
/**
|
|
138
|
+
* This function is to check if the menu should be closed or not.
|
|
139
|
+
* As when continously clicking on drag handle on different rows/columns,
|
|
140
|
+
* should open the menu corresponding to the position of the drag handle.
|
|
141
|
+
* @returns true when the menu should be closed, false otherwise
|
|
142
|
+
*/
|
|
143
|
+
const shouldCloseMenu = (state: EditorState) => {
|
|
144
|
+
let {
|
|
145
|
+
isDragMenuOpen: previousOpenState,
|
|
146
|
+
dragMenuDirection: previousDragMenuDirection,
|
|
147
|
+
dragMenuIndex: previousDragMenuIndex,
|
|
148
|
+
} = getPluginState(state);
|
|
149
|
+
|
|
150
|
+
// menu open but menu direction changed, means user clicked on drag handle of different row/column
|
|
151
|
+
// menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
|
|
152
|
+
// 2 scenarios above , menu should not be closed.
|
|
153
|
+
if (
|
|
154
|
+
(previousOpenState === true && previousDragMenuDirection !== direction) ||
|
|
155
|
+
(previousOpenState === true &&
|
|
156
|
+
previousDragMenuDirection === direction &&
|
|
157
|
+
previousDragMenuIndex !== index)
|
|
158
|
+
) {
|
|
159
|
+
return false;
|
|
160
|
+
} else {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
135
165
|
const closeMenu = () => {
|
|
136
166
|
const { state, dispatch } = editorView;
|
|
137
|
-
|
|
167
|
+
if (shouldCloseMenu(state)) {
|
|
168
|
+
toggleDragMenu(false, direction, index)(state, dispatch);
|
|
169
|
+
}
|
|
138
170
|
};
|
|
139
171
|
|
|
140
172
|
const handleMenuItemActivated = ({ item }: { item: MenuItem }) => {
|