@atlaskit/editor-plugin-table 5.4.7 → 5.4.9
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 +12 -0
- package/dist/cjs/plugins/table/commands/misc.js +14 -12
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -4
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +9 -3
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
- package/dist/cjs/plugins/table/types.js +2 -1
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -1
- package/dist/cjs/plugins/table/ui/common-styles.js +6 -9
- package/dist/cjs/plugins/table/ui/ui-styles.js +12 -16
- package/dist/cjs/plugins/table/utils/decoration.js +20 -25
- package/dist/cjs/plugins/table/utils/drag-menu.js +2 -2
- package/dist/es2019/plugins/table/commands/misc.js +5 -4
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -4
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +9 -3
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
- package/dist/es2019/plugins/table/types.js +2 -1
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +4 -2
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +4 -1
- package/dist/es2019/plugins/table/ui/common-styles.js +20 -20
- package/dist/es2019/plugins/table/ui/ui-styles.js +18 -21
- package/dist/es2019/plugins/table/utils/decoration.js +20 -25
- package/dist/es2019/plugins/table/utils/drag-menu.js +2 -2
- package/dist/esm/plugins/table/commands/misc.js +13 -13
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -4
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +9 -3
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
- package/dist/esm/plugins/table/types.js +2 -1
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +4 -2
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +4 -1
- package/dist/esm/plugins/table/ui/common-styles.js +6 -9
- package/dist/esm/plugins/table/ui/ui-styles.js +12 -16
- package/dist/esm/plugins/table/utils/decoration.js +20 -25
- package/dist/esm/plugins/table/utils/drag-menu.js +2 -2
- package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
- package/dist/types/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
- package/dist/types/plugins/table/types.d.ts +2 -1
- package/dist/types/plugins/table/utils/drag-menu.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
- package/dist/types-ts4.5/plugins/table/types.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +1 -1
- package/package.json +1 -1
- package/src/__tests__/unit/event-handlers.ts +37 -38
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +46 -36
- package/src/plugins/table/commands/misc.ts +9 -7
- package/src/plugins/table/nodeviews/TableComponent.tsx +20 -22
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +7 -2
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +20 -11
- package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +2 -4
- package/src/plugins/table/pm-plugins/decorations/utils/types.ts +14 -7
- package/src/plugins/table/types.ts +2 -1
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +12 -1
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +73 -67
- package/src/plugins/table/ui/common-styles.ts +20 -23
- package/src/plugins/table/ui/ui-styles.ts +18 -21
- package/src/plugins/table/utils/decoration.ts +27 -32
- package/src/plugins/table/utils/drag-menu.ts +8 -2
|
@@ -13,7 +13,6 @@ var _utils = require("@atlaskit/editor-common/utils");
|
|
|
13
13
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
14
14
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
15
15
|
var _utils2 = require("@atlaskit/editor-tables/utils");
|
|
16
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
16
|
var _types = require("../types");
|
|
18
17
|
var _ColumnResizeWidget = require("../ui/ColumnResizeWidget");
|
|
19
18
|
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
@@ -163,32 +162,28 @@ var createColumnSelectedDecoration = exports.createColumnSelectedDecoration = fu
|
|
|
163
162
|
};
|
|
164
163
|
var createColumnControlsDecoration = exports.createColumnControlsDecoration = function createColumnControlsDecoration(selection) {
|
|
165
164
|
var cells = (0, _utils2.getCellsInRow)(0)(selection) || [];
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
// and we want to avoid value leak
|
|
174
|
-
var startIndex = index;
|
|
175
|
-
var endIndex = startIndex + colspan;
|
|
165
|
+
var index = 0;
|
|
166
|
+
return cells.map(function (cell) {
|
|
167
|
+
var colspan = cell.node.attrs.colspan || 1;
|
|
168
|
+
// It's important these values are scoped locally as the widget callback could be executed anytime in the future
|
|
169
|
+
// and we want to avoid value leak
|
|
170
|
+
var startIndex = index;
|
|
171
|
+
var endIndex = startIndex + colspan;
|
|
176
172
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
173
|
+
// The next cell start index will commence from the current cell end index.
|
|
174
|
+
index = endIndex;
|
|
175
|
+
return _view.Decoration.widget(cell.pos + 1, function () {
|
|
176
|
+
var element = document.createElement('div');
|
|
177
|
+
element.classList.add(_types.TableCssClassName.COLUMN_CONTROLS_DECORATIONS);
|
|
178
|
+
element.dataset.startIndex = "".concat(startIndex);
|
|
179
|
+
element.dataset.endIndex = "".concat(endIndex);
|
|
180
|
+
return element;
|
|
181
|
+
}, {
|
|
182
|
+
key: "".concat(_types.TableDecorations.COLUMN_CONTROLS_DECORATIONS, "_").concat(endIndex),
|
|
183
|
+
// this decoration should be the first one, even before gap cursor.
|
|
184
|
+
side: -100
|
|
190
185
|
});
|
|
191
|
-
}
|
|
186
|
+
});
|
|
192
187
|
};
|
|
193
188
|
var updateDecorations = exports.updateDecorations = function updateDecorations(node, decorationSet, decorations, key) {
|
|
194
189
|
var filteredDecorations = filterDecorationByKey(key, decorationSet);
|
|
@@ -30,7 +30,7 @@ var canIncrease = function canIncrease(index) {
|
|
|
30
30
|
var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
31
31
|
return index !== undefined && index < max;
|
|
32
32
|
};
|
|
33
|
-
var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect) {
|
|
33
|
+
var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, hasMergedCells, tableMap, index, targetCellPosition, selectionRect) {
|
|
34
34
|
var addOptions = direction === 'row' ? [{
|
|
35
35
|
label: 'above',
|
|
36
36
|
offset: 0,
|
|
@@ -144,7 +144,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
|
|
|
144
144
|
return {
|
|
145
145
|
id: "move_".concat(direction, "_").concat(label),
|
|
146
146
|
title: "Move ".concat(direction, " ").concat(label),
|
|
147
|
-
disabled: !canMove(index),
|
|
147
|
+
disabled: hasMergedCells || !canMove(index),
|
|
148
148
|
icon: icon,
|
|
149
149
|
onClick: function onClick(state, dispatch) {
|
|
150
150
|
if (canMove(index)) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// #region Imports
|
|
2
|
-
|
|
3
1
|
import { closestElement, isParagraph, isTextSelection, mapSlice } from '@atlaskit/editor-common/utils';
|
|
4
2
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
3
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
@@ -26,7 +24,9 @@ export const setTableRef = ref => createCommand(state => {
|
|
|
26
24
|
const tablePos = ref && foundTable ? foundTable.pos : undefined;
|
|
27
25
|
const tableWrapperTarget = closestElement(tableRef, `.${ClassName.TABLE_NODE_WRAPPER}`) || undefined;
|
|
28
26
|
const layout = tableNode ? tableNode.attrs.layout : undefined;
|
|
29
|
-
const
|
|
27
|
+
const {
|
|
28
|
+
isDragAndDropEnabled
|
|
29
|
+
} = getPluginState(state);
|
|
30
30
|
return {
|
|
31
31
|
type: 'SET_TABLE_REF',
|
|
32
32
|
data: {
|
|
@@ -38,7 +38,8 @@ export const setTableRef = ref => createCommand(state => {
|
|
|
38
38
|
isNumberColumnEnabled: checkIfNumberColumnEnabled(state.selection),
|
|
39
39
|
isHeaderRowEnabled: checkIfHeaderRowEnabled(state.selection),
|
|
40
40
|
isHeaderColumnEnabled: checkIfHeaderColumnEnabled(state.selection),
|
|
41
|
-
|
|
41
|
+
// decoration set is drawn by the decoration plugin, skip this for DnD as all controls are floating
|
|
42
|
+
decorationSet: !isDragAndDropEnabled ? updatePluginStateDecorations(state, createColumnControlsDecoration(state.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS) : undefined,
|
|
42
43
|
resizeHandleRowIndex: undefined,
|
|
43
44
|
resizeHandleColumnIndex: undefined
|
|
44
45
|
}
|
|
@@ -533,9 +533,7 @@ class TableComponent extends React.Component {
|
|
|
533
533
|
const tableRef = this.table || undefined;
|
|
534
534
|
const headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
|
|
535
535
|
const hasHeaderRow = containsHeaderRow(node);
|
|
536
|
-
const rowControls = /*#__PURE__*/React.createElement(
|
|
537
|
-
className: ClassName.ROW_CONTROLS_WRAPPER
|
|
538
|
-
}, /*#__PURE__*/React.createElement(TableFloatingControls, {
|
|
536
|
+
const rowControls = /*#__PURE__*/React.createElement(TableFloatingControls, {
|
|
539
537
|
editorView: view,
|
|
540
538
|
tableRef: tableRef,
|
|
541
539
|
tableNode: node,
|
|
@@ -555,7 +553,7 @@ class TableComponent extends React.Component {
|
|
|
555
553
|
selection: view.state.selection,
|
|
556
554
|
headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
|
|
557
555
|
stickyHeader: this.state.stickyHeader
|
|
558
|
-
})
|
|
556
|
+
});
|
|
559
557
|
const colControls = isDragAndDropEnabled ? /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
|
|
560
558
|
editorView: view,
|
|
561
559
|
tableRef: tableRef,
|
|
@@ -2,7 +2,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
4
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
5
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
5
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
7
6
|
import { pluginKey as tableWidthPluginKey } from '../table-width';
|
|
8
7
|
import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
|
|
@@ -12,15 +11,21 @@ export const handleDocOrSelectionChanged = (tr, decorationSet, oldState, newStat
|
|
|
12
11
|
var _tableWidthPluginKey$, _tableWidthPluginKey$2;
|
|
13
12
|
const isResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
|
|
14
13
|
const wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
|
|
14
|
+
const {
|
|
15
|
+
isDragAndDropEnabled = false
|
|
16
|
+
} = tablePluginKey.getState(newState) || {};
|
|
15
17
|
const changedResizing = isResizing !== wasResizing;
|
|
16
18
|
|
|
17
19
|
// Remove column controls when resizing and don't add column decoration controls when DnD enabled
|
|
18
|
-
if (isResizing
|
|
20
|
+
if (isResizing) {
|
|
19
21
|
return DecorationSet.empty;
|
|
20
22
|
} else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing) {
|
|
21
23
|
return buildColumnControlsDecorations({
|
|
22
24
|
decorationSet,
|
|
23
|
-
tr
|
|
25
|
+
tr,
|
|
26
|
+
options: {
|
|
27
|
+
isDragAndDropEnabled
|
|
28
|
+
}
|
|
24
29
|
});
|
|
25
30
|
} else if (tr.selectionSet) {
|
|
26
31
|
const isTransactionFromMouseClick = !tr.docChanged && tr.selectionSet && tr.getMeta('pointer');
|
|
@@ -39,6 +44,7 @@ export const createPlugin = () => {
|
|
|
39
44
|
init: () => DecorationSet.empty,
|
|
40
45
|
apply: (tr, decorationSet, oldState, newState) => {
|
|
41
46
|
let pluginState = decorationSet;
|
|
47
|
+
// main table plugin --->
|
|
42
48
|
const meta = tr.getMeta(tablePluginKey);
|
|
43
49
|
if (meta && meta.data && meta.data.decorationSet) {
|
|
44
50
|
pluginState = meta.data.decorationSet;
|
|
@@ -25,8 +25,6 @@ const maybeUpdateColumnControlsDecoration = ({
|
|
|
25
25
|
tr
|
|
26
26
|
}) => {
|
|
27
27
|
const table = findTable(tr.selection);
|
|
28
|
-
|
|
29
|
-
// avoid re-drawing state if dnd decorations don't need to be updated
|
|
30
28
|
if (!table) {
|
|
31
29
|
return decorationSet;
|
|
32
30
|
}
|
|
@@ -52,8 +50,15 @@ export const maybeUpdateColumnControlsSelectedDecoration = ({
|
|
|
52
50
|
};
|
|
53
51
|
export const buildColumnControlsDecorations = ({
|
|
54
52
|
decorationSet,
|
|
55
|
-
tr
|
|
53
|
+
tr,
|
|
54
|
+
options
|
|
56
55
|
}) => {
|
|
56
|
+
if (options.isDragAndDropEnabled) {
|
|
57
|
+
return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration])({
|
|
58
|
+
decorationSet,
|
|
59
|
+
tr
|
|
60
|
+
});
|
|
61
|
+
}
|
|
57
62
|
return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration, maybeUpdateColumnControlsDecoration])({
|
|
58
63
|
decorationSet,
|
|
59
64
|
tr
|
|
@@ -79,7 +79,8 @@ export const TableCssClassName = {
|
|
|
79
79
|
CORNER_CONTROLS_INSERT_ROW_MARKER: `${tablePrefixSelector}-corner-controls__insert-row-marker`,
|
|
80
80
|
CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
|
|
81
81
|
CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
|
|
82
|
-
/**
|
|
82
|
+
/** drag and drop controls */
|
|
83
|
+
DRAG_ROW_CONTROLS_WRAPPER: `${tablePrefixSelector}-drag-row-controls-wrapper`,
|
|
83
84
|
DRAG_ROW_CONTROLS: `${tablePrefixSelector}-drag-row-controls`,
|
|
84
85
|
DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-row-floating-insert-dot-wrapper`,
|
|
85
86
|
DRAG_ROW_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-row-floating-insert-dot`,
|
|
@@ -7,7 +7,7 @@ import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@at
|
|
|
7
7
|
import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
|
|
8
8
|
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
9
9
|
import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
10
|
-
import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
|
|
10
|
+
import { getSelectedColumnIndexes, getSelectedRowIndexes, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
11
11
|
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
12
12
|
import { dragMenuDropdownWidth } from '../consts';
|
|
13
13
|
const groupedDragMenuConfig = [['add_row_above', 'add_row_below', 'add_column_left', 'add_column_right', 'distribute_columns', 'clear_cells', 'delete_row', 'delete_column'], ['move_column_left', 'move_column_right', 'move_row_up', 'move_row_down'], ['sort_column_asc', 'sort_column_desc']];
|
|
@@ -72,7 +72,9 @@ export const DragMenu = ({
|
|
|
72
72
|
selection
|
|
73
73
|
} = state;
|
|
74
74
|
const selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
|
|
75
|
-
const
|
|
75
|
+
const hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
76
|
+
const mergedCells = index !== undefined && hasMergedCells(index)(selection);
|
|
77
|
+
const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, mergedCells, tableMap, index, targetCellPosition, selectionRect);
|
|
76
78
|
const {
|
|
77
79
|
menuItems,
|
|
78
80
|
menuCallback
|
|
@@ -128,7 +128,10 @@ export default class TableFloatingControls extends Component {
|
|
|
128
128
|
return null;
|
|
129
129
|
}
|
|
130
130
|
const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
|
|
131
|
+
const wrapperClassName = isDragAndDropEnabled ? ClassName.DRAG_ROW_CONTROLS_WRAPPER : ClassName.ROW_CONTROLS_WRAPPER;
|
|
131
132
|
return /*#__PURE__*/React.createElement("div", {
|
|
133
|
+
className: wrapperClassName
|
|
134
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
132
135
|
onMouseDown: e => !isDragAndDropEnabled && e.preventDefault()
|
|
133
136
|
}, isNumberColumnEnabled ? /*#__PURE__*/React.createElement(NumberColumn, {
|
|
134
137
|
editorView: editorView,
|
|
@@ -178,7 +181,7 @@ export default class TableFloatingControls extends Component {
|
|
|
178
181
|
isResizing: isResizing,
|
|
179
182
|
selectRow: this.selectRow,
|
|
180
183
|
stickyTop: tableActive ? stickyTop : undefined
|
|
181
|
-
}))));
|
|
184
|
+
})))));
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
187
|
_defineProperty(TableFloatingControls, "displayName", 'TableFloatingControls');
|
|
@@ -173,23 +173,6 @@ const tableStickyHeaderFirefoxFixStyle = props => {
|
|
|
173
173
|
`;
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
|
-
const tableRowControlStyles = () => {
|
|
177
|
-
return getBooleanFF('platform.editor.table.drag-and-drop') ? css`
|
|
178
|
-
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
179
|
-
position: absolute;
|
|
180
|
-
margin-top: ${tableMarginTop}px;
|
|
181
|
-
left: -${tableToolbarSize + 1}px;
|
|
182
|
-
z-index: ${rowControlsZIndex + 4};
|
|
183
|
-
}
|
|
184
|
-
` : css`
|
|
185
|
-
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
186
|
-
position: absolute;
|
|
187
|
-
/* top of corner control is table margin top - corner control height + 1 pixel of table border. */
|
|
188
|
-
top: ${tableMarginTop - cornerControlHeight + 1}px;
|
|
189
|
-
left: -${tableToolbarSize}px;
|
|
190
|
-
}
|
|
191
|
-
`;
|
|
192
|
-
};
|
|
193
176
|
const tableWrapperStyles = () => {
|
|
194
177
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
195
178
|
return css`
|
|
@@ -463,7 +446,8 @@ export const tableStyles = props => {
|
|
|
463
446
|
.less-padding {
|
|
464
447
|
padding: 0 ${tablePadding}px;
|
|
465
448
|
|
|
466
|
-
.${ClassName.
|
|
449
|
+
.${ClassName.DRAG_ROW_CONTROLS_WRAPPER},
|
|
450
|
+
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
467
451
|
padding: 0 ${tablePadding}px;
|
|
468
452
|
|
|
469
453
|
// https://product-fabric.atlassian.net/browse/ED-16386
|
|
@@ -935,8 +919,24 @@ export const tableStyles = props => {
|
|
|
935
919
|
}
|
|
936
920
|
}
|
|
937
921
|
}
|
|
938
|
-
|
|
939
|
-
|
|
922
|
+
|
|
923
|
+
// override for DnD controls
|
|
924
|
+
.${ClassName.DRAG_ROW_CONTROLS_WRAPPER} {
|
|
925
|
+
position: absolute;
|
|
926
|
+
margin-top: ${tableMarginTop}px;
|
|
927
|
+
left: -${tableToolbarSize + 1}px;
|
|
928
|
+
z-index: ${rowControlsZIndex + 4};
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
932
|
+
position: absolute;
|
|
933
|
+
/* top of corner control is table margin top - corner control height + 1 pixel of table border. */
|
|
934
|
+
top: ${tableMarginTop - cornerControlHeight + 1}px;
|
|
935
|
+
left: -${tableToolbarSize}px;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
.${ClassName.DRAG_ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW},
|
|
939
|
+
.${ClassName.ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW} {
|
|
940
940
|
z-index: ${akEditorUnitZIndex};
|
|
941
941
|
}
|
|
942
942
|
|
|
@@ -400,27 +400,24 @@ export const floatingColumnControls = props => {
|
|
|
400
400
|
`;
|
|
401
401
|
};
|
|
402
402
|
export const rowControlsWrapperDotStyle = props => {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
`;
|
|
423
|
-
}
|
|
403
|
+
return css`
|
|
404
|
+
// override for DnD controls
|
|
405
|
+
div.${ClassName.WITH_CONTROLS}>.${ClassName.DRAG_ROW_CONTROLS_WRAPPER}::after {
|
|
406
|
+
display: none;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
|
|
410
|
+
content: ' ';
|
|
411
|
+
background-color: ${tableBorderColor(props)};
|
|
412
|
+
position: absolute;
|
|
413
|
+
height: ${lineMarkerSize}px;
|
|
414
|
+
width: ${lineMarkerSize}px;
|
|
415
|
+
border-radius: 50%;
|
|
416
|
+
pointer-events: none;
|
|
417
|
+
top: -${tableToolbarSize + tableCellBorderWidth}px;
|
|
418
|
+
right: -1px;
|
|
419
|
+
}
|
|
420
|
+
`;
|
|
424
421
|
};
|
|
425
422
|
export const columnControlsDecoration = props => {
|
|
426
423
|
if (getBooleanFF('platform.editor.table.column-controls-styles-updated')) {
|
|
@@ -8,7 +8,6 @@ import { nonNullable } from '@atlaskit/editor-common/utils';
|
|
|
8
8
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
9
9
|
import { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
|
|
10
10
|
import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
11
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
12
11
|
import { TableCssClassName as ClassName, TableDecorations } from '../types';
|
|
13
12
|
import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
|
|
14
13
|
const filterDecorationByKey = (key, decorationSet) => decorationSet.find(undefined, undefined, spec => spec.key.indexOf(key) > -1);
|
|
@@ -138,32 +137,28 @@ export const createColumnSelectedDecoration = tr => {
|
|
|
138
137
|
};
|
|
139
138
|
export const createColumnControlsDecoration = selection => {
|
|
140
139
|
const cells = getCellsInRow(0)(selection) || [];
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// and we want to avoid value leak
|
|
149
|
-
const startIndex = index;
|
|
150
|
-
const endIndex = startIndex + colspan;
|
|
140
|
+
let index = 0;
|
|
141
|
+
return cells.map(cell => {
|
|
142
|
+
const colspan = cell.node.attrs.colspan || 1;
|
|
143
|
+
// It's important these values are scoped locally as the widget callback could be executed anytime in the future
|
|
144
|
+
// and we want to avoid value leak
|
|
145
|
+
const startIndex = index;
|
|
146
|
+
const endIndex = startIndex + colspan;
|
|
151
147
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
});
|
|
148
|
+
// The next cell start index will commence from the current cell end index.
|
|
149
|
+
index = endIndex;
|
|
150
|
+
return Decoration.widget(cell.pos + 1, () => {
|
|
151
|
+
const element = document.createElement('div');
|
|
152
|
+
element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
|
|
153
|
+
element.dataset.startIndex = `${startIndex}`;
|
|
154
|
+
element.dataset.endIndex = `${endIndex}`;
|
|
155
|
+
return element;
|
|
156
|
+
}, {
|
|
157
|
+
key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
|
|
158
|
+
// this decoration should be the first one, even before gap cursor.
|
|
159
|
+
side: -100
|
|
165
160
|
});
|
|
166
|
-
}
|
|
161
|
+
});
|
|
167
162
|
};
|
|
168
163
|
export const updateDecorations = (node, decorationSet, decorations, key) => {
|
|
169
164
|
const filteredDecorations = filterDecorationByKey(key, decorationSet);
|
|
@@ -16,7 +16,7 @@ import { deleteRows } from '../transforms';
|
|
|
16
16
|
import { AddColLeftIcon, AddColRightIcon, AddRowAboveIcon, AddRowBelowIcon } from '../ui/icons';
|
|
17
17
|
const canDecrease = (index, min = 0) => index !== undefined && index > min;
|
|
18
18
|
const canIncrease = (index, max = 0) => index !== undefined && index < max;
|
|
19
|
-
export const getDragMenuConfig = (direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect) => {
|
|
19
|
+
export const getDragMenuConfig = (direction, getEditorContainerWidth, hasMergedCells, tableMap, index, targetCellPosition, selectionRect) => {
|
|
20
20
|
const addOptions = direction === 'row' ? [{
|
|
21
21
|
label: 'above',
|
|
22
22
|
offset: 0,
|
|
@@ -129,7 +129,7 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, tableMap,
|
|
|
129
129
|
}) => ({
|
|
130
130
|
id: `move_${direction}_${label}`,
|
|
131
131
|
title: `Move ${direction} ${label}`,
|
|
132
|
-
disabled: !canMove(index),
|
|
132
|
+
disabled: hasMergedCells || !canMove(index),
|
|
133
133
|
icon,
|
|
134
134
|
onClick: (state, dispatch) => {
|
|
135
135
|
if (canMove(index)) {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
// #region Imports
|
|
5
|
-
|
|
6
4
|
import { closestElement, isParagraph, isTextSelection, mapSlice } from '@atlaskit/editor-common/utils';
|
|
7
5
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
6
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
@@ -32,7 +30,8 @@ export var setTableRef = function setTableRef(ref) {
|
|
|
32
30
|
var tablePos = ref && foundTable ? foundTable.pos : undefined;
|
|
33
31
|
var tableWrapperTarget = closestElement(tableRef, ".".concat(ClassName.TABLE_NODE_WRAPPER)) || undefined;
|
|
34
32
|
var layout = tableNode ? tableNode.attrs.layout : undefined;
|
|
35
|
-
var
|
|
33
|
+
var _getPluginState = getPluginState(state),
|
|
34
|
+
isDragAndDropEnabled = _getPluginState.isDragAndDropEnabled;
|
|
36
35
|
return {
|
|
37
36
|
type: 'SET_TABLE_REF',
|
|
38
37
|
data: {
|
|
@@ -44,7 +43,8 @@ export var setTableRef = function setTableRef(ref) {
|
|
|
44
43
|
isNumberColumnEnabled: checkIfNumberColumnEnabled(state.selection),
|
|
45
44
|
isHeaderRowEnabled: checkIfHeaderRowEnabled(state.selection),
|
|
46
45
|
isHeaderColumnEnabled: checkIfHeaderColumnEnabled(state.selection),
|
|
47
|
-
|
|
46
|
+
// decoration set is drawn by the decoration plugin, skip this for DnD as all controls are floating
|
|
47
|
+
decorationSet: !isDragAndDropEnabled ? updatePluginStateDecorations(state, createColumnControlsDecoration(state.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS) : undefined,
|
|
48
48
|
resizeHandleRowIndex: undefined,
|
|
49
49
|
resizeHandleColumnIndex: undefined
|
|
50
50
|
}
|
|
@@ -381,9 +381,9 @@ export var hideInsertColumnOrRowButton = function hideInsertColumnOrRowButton()
|
|
|
381
381
|
export var addResizeHandleDecorations = function addResizeHandleDecorations(rowIndex, columnIndex, includeTooltip) {
|
|
382
382
|
return createCommand(function (state) {
|
|
383
383
|
var tableNode = findTable(state.selection);
|
|
384
|
-
var
|
|
385
|
-
allowColumnResizing =
|
|
386
|
-
getIntl =
|
|
384
|
+
var _getPluginState2 = getPluginState(state),
|
|
385
|
+
allowColumnResizing = _getPluginState2.pluginConfig.allowColumnResizing,
|
|
386
|
+
getIntl = _getPluginState2.getIntl;
|
|
387
387
|
if (!tableNode || !allowColumnResizing) {
|
|
388
388
|
return false;
|
|
389
389
|
}
|
|
@@ -406,12 +406,12 @@ export var addResizeHandleDecorations = function addResizeHandleDecorations(rowI
|
|
|
406
406
|
export var updateResizeHandleDecorations = function updateResizeHandleDecorations(rowIndex, columnIndex, includeTooltip) {
|
|
407
407
|
return createCommand(function (state) {
|
|
408
408
|
var tableNode = findTable(state.selection);
|
|
409
|
-
var
|
|
410
|
-
resizeHandleRowIndex =
|
|
411
|
-
resizeHandleColumnIndex =
|
|
412
|
-
resizeHandleIncludeTooltip =
|
|
413
|
-
allowColumnResizing =
|
|
414
|
-
getIntl =
|
|
409
|
+
var _getPluginState3 = getPluginState(state),
|
|
410
|
+
resizeHandleRowIndex = _getPluginState3.resizeHandleRowIndex,
|
|
411
|
+
resizeHandleColumnIndex = _getPluginState3.resizeHandleColumnIndex,
|
|
412
|
+
resizeHandleIncludeTooltip = _getPluginState3.resizeHandleIncludeTooltip,
|
|
413
|
+
allowColumnResizing = _getPluginState3.pluginConfig.allowColumnResizing,
|
|
414
|
+
getIntl = _getPluginState3.getIntl;
|
|
415
415
|
if (!tableNode || !allowColumnResizing) {
|
|
416
416
|
return false;
|
|
417
417
|
}
|
|
@@ -524,9 +524,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
524
524
|
var tableRef = this.table || undefined;
|
|
525
525
|
var headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
|
|
526
526
|
var hasHeaderRow = containsHeaderRow(node);
|
|
527
|
-
var rowControls = /*#__PURE__*/React.createElement(
|
|
528
|
-
className: ClassName.ROW_CONTROLS_WRAPPER
|
|
529
|
-
}, /*#__PURE__*/React.createElement(TableFloatingControls, {
|
|
527
|
+
var rowControls = /*#__PURE__*/React.createElement(TableFloatingControls, {
|
|
530
528
|
editorView: view,
|
|
531
529
|
tableRef: tableRef,
|
|
532
530
|
tableNode: node,
|
|
@@ -546,7 +544,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
546
544
|
selection: view.state.selection,
|
|
547
545
|
headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
|
|
548
546
|
stickyHeader: this.state.stickyHeader
|
|
549
|
-
})
|
|
547
|
+
});
|
|
550
548
|
var colControls = isDragAndDropEnabled ? /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
|
|
551
549
|
editorView: view,
|
|
552
550
|
tableRef: tableRef,
|
|
@@ -2,7 +2,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
4
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
5
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
5
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
7
6
|
import { pluginKey as tableWidthPluginKey } from '../table-width';
|
|
8
7
|
import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
|
|
@@ -14,15 +13,21 @@ export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr
|
|
|
14
13
|
var _tableWidthPluginKey$, _tableWidthPluginKey$2;
|
|
15
14
|
var isResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
|
|
16
15
|
var wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
|
|
16
|
+
var _ref = tablePluginKey.getState(newState) || {},
|
|
17
|
+
_ref$isDragAndDropEna = _ref.isDragAndDropEnabled,
|
|
18
|
+
isDragAndDropEnabled = _ref$isDragAndDropEna === void 0 ? false : _ref$isDragAndDropEna;
|
|
17
19
|
var changedResizing = isResizing !== wasResizing;
|
|
18
20
|
|
|
19
21
|
// Remove column controls when resizing and don't add column decoration controls when DnD enabled
|
|
20
|
-
if (isResizing
|
|
22
|
+
if (isResizing) {
|
|
21
23
|
return DecorationSet.empty;
|
|
22
24
|
} else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing) {
|
|
23
25
|
return buildColumnControlsDecorations({
|
|
24
26
|
decorationSet: decorationSet,
|
|
25
|
-
tr: tr
|
|
27
|
+
tr: tr,
|
|
28
|
+
options: {
|
|
29
|
+
isDragAndDropEnabled: isDragAndDropEnabled
|
|
30
|
+
}
|
|
26
31
|
});
|
|
27
32
|
} else if (tr.selectionSet) {
|
|
28
33
|
var isTransactionFromMouseClick = !tr.docChanged && tr.selectionSet && tr.getMeta('pointer');
|
|
@@ -43,6 +48,7 @@ export var createPlugin = function createPlugin() {
|
|
|
43
48
|
},
|
|
44
49
|
apply: function apply(tr, decorationSet, oldState, newState) {
|
|
45
50
|
var pluginState = decorationSet;
|
|
51
|
+
// main table plugin --->
|
|
46
52
|
var meta = tr.getMeta(tablePluginKey);
|
|
47
53
|
if (meta && meta.data && meta.data.decorationSet) {
|
|
48
54
|
pluginState = meta.data.decorationSet;
|
|
@@ -26,8 +26,6 @@ var maybeUpdateColumnControlsDecoration = function maybeUpdateColumnControlsDeco
|
|
|
26
26
|
var decorationSet = _ref3.decorationSet,
|
|
27
27
|
tr = _ref3.tr;
|
|
28
28
|
var table = findTable(tr.selection);
|
|
29
|
-
|
|
30
|
-
// avoid re-drawing state if dnd decorations don't need to be updated
|
|
31
29
|
if (!table) {
|
|
32
30
|
return decorationSet;
|
|
33
31
|
}
|
|
@@ -55,7 +53,14 @@ export var maybeUpdateColumnControlsSelectedDecoration = function maybeUpdateCol
|
|
|
55
53
|
};
|
|
56
54
|
export var buildColumnControlsDecorations = function buildColumnControlsDecorations(_ref6) {
|
|
57
55
|
var decorationSet = _ref6.decorationSet,
|
|
58
|
-
tr = _ref6.tr
|
|
56
|
+
tr = _ref6.tr,
|
|
57
|
+
options = _ref6.options;
|
|
58
|
+
if (options.isDragAndDropEnabled) {
|
|
59
|
+
return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration])({
|
|
60
|
+
decorationSet: decorationSet,
|
|
61
|
+
tr: tr
|
|
62
|
+
});
|
|
63
|
+
}
|
|
59
64
|
return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration, maybeUpdateColumnControlsDecoration])({
|
|
60
65
|
decorationSet: decorationSet,
|
|
61
66
|
tr: tr
|
|
@@ -81,7 +81,8 @@ export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssCla
|
|
|
81
81
|
CORNER_CONTROLS_INSERT_ROW_MARKER: "".concat(tablePrefixSelector, "-corner-controls__insert-row-marker"),
|
|
82
82
|
CORNER_CONTROLS_INSERT_COLUMN_MARKER: "".concat(tablePrefixSelector, "-corner-controls__insert-column-marker"),
|
|
83
83
|
CONTROLS_CORNER_BUTTON: "".concat(tablePrefixSelector, "-corner-button"),
|
|
84
|
-
/**
|
|
84
|
+
/** drag and drop controls */
|
|
85
|
+
DRAG_ROW_CONTROLS_WRAPPER: "".concat(tablePrefixSelector, "-drag-row-controls-wrapper"),
|
|
85
86
|
DRAG_ROW_CONTROLS: "".concat(tablePrefixSelector, "-drag-row-controls"),
|
|
86
87
|
DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: "".concat(tablePrefixSelector, "-drag-row-floating-insert-dot-wrapper"),
|
|
87
88
|
DRAG_ROW_FLOATING_INSERT_DOT: "".concat(tablePrefixSelector, "-drag-row-floating-insert-dot"),
|
|
@@ -8,7 +8,7 @@ import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@at
|
|
|
8
8
|
import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
|
|
9
9
|
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
10
10
|
import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
11
|
-
import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
|
|
11
|
+
import { getSelectedColumnIndexes, getSelectedRowIndexes, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
12
12
|
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
13
13
|
import { dragMenuDropdownWidth } from '../consts';
|
|
14
14
|
var groupedDragMenuConfig = [['add_row_above', 'add_row_below', 'add_column_left', 'add_column_right', 'distribute_columns', 'clear_cells', 'delete_row', 'delete_column'], ['move_column_left', 'move_column_right', 'move_row_up', 'move_row_down'], ['sort_column_asc', 'sort_column_desc']];
|
|
@@ -73,7 +73,9 @@ export var DragMenu = function DragMenu(_ref) {
|
|
|
73
73
|
dispatch = editorView.dispatch;
|
|
74
74
|
var selection = state.selection;
|
|
75
75
|
var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
|
|
76
|
-
var
|
|
76
|
+
var hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
77
|
+
var mergedCells = index !== undefined && hasMergedCells(index)(selection);
|
|
78
|
+
var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, mergedCells, tableMap, index, targetCellPosition, selectionRect);
|
|
77
79
|
var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
|
|
78
80
|
menuItems = _convertToDropdownIte.menuItems,
|
|
79
81
|
menuCallback = _convertToDropdownIte.menuCallback;
|