@atlaskit/editor-plugin-table 5.3.0 → 5.3.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  3. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -7
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
  7. package/dist/cjs/plugins/table/types.js +8 -1
  8. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  9. package/dist/cjs/plugins/table/ui/consts.js +2 -1
  10. package/dist/cjs/plugins/table/ui/ui-styles.js +5 -2
  11. package/dist/cjs/plugins/table/utils/decoration.js +67 -1
  12. package/dist/cjs/plugins/table/utils/index.js +26 -1
  13. package/dist/cjs/plugins/table/utils/merged-cells.js +66 -0
  14. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -7
  15. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -4
  16. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  17. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  18. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -0
  19. package/dist/es2019/plugins/table/types.js +8 -1
  20. package/dist/es2019/plugins/table/ui/common-styles.js +2 -1
  21. package/dist/es2019/plugins/table/ui/consts.js +1 -0
  22. package/dist/es2019/plugins/table/ui/ui-styles.js +114 -1
  23. package/dist/es2019/plugins/table/utils/decoration.js +62 -0
  24. package/dist/es2019/plugins/table/utils/index.js +3 -2
  25. package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
  26. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  27. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +65 -4
  28. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  29. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  30. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -0
  31. package/dist/esm/plugins/table/types.js +8 -1
  32. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  33. package/dist/esm/plugins/table/ui/consts.js +1 -0
  34. package/dist/esm/plugins/table/ui/ui-styles.js +5 -2
  35. package/dist/esm/plugins/table/utils/decoration.js +66 -0
  36. package/dist/esm/plugins/table/utils/index.js +3 -2
  37. package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
  38. package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  39. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  40. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  41. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  42. package/dist/types/plugins/table/types.d.ts +19 -1
  43. package/dist/types/plugins/table/ui/consts.d.ts +1 -0
  44. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  45. package/dist/types/plugins/table/utils/decoration.d.ts +2 -0
  46. package/dist/types/plugins/table/utils/index.d.ts +2 -1
  47. package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
  48. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  49. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  50. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  51. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  52. package/dist/types-ts4.5/plugins/table/types.d.ts +19 -1
  53. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
  54. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  55. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -0
  56. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +2 -1
  57. package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
  58. package/package.json +4 -1
  59. package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +6 -1
  60. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
  61. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +77 -4
  62. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
  63. package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
  64. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -0
  65. package/src/plugins/table/types.ts +23 -1
  66. package/src/plugins/table/ui/common-styles.ts +2 -0
  67. package/src/plugins/table/ui/consts.ts +1 -0
  68. package/src/plugins/table/ui/ui-styles.ts +115 -0
  69. package/src/plugins/table/utils/decoration.ts +101 -0
  70. package/src/plugins/table/utils/index.ts +3 -0
  71. package/src/plugins/table/utils/merged-cells.ts +67 -0
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasMergedCellsInRow = exports.hasMergedCellsInColumn = void 0;
7
+ var _editorTables = require("@atlaskit/editor-tables");
8
+ var hasMergedCells = function hasMergedCells(indexes, normalizeRect) {
9
+ return function (selection) {
10
+ var table = (0, _editorTables.findTable)(selection);
11
+ if (!table) {
12
+ return false;
13
+ }
14
+ var map = _editorTables.TableMap.get(table.node);
15
+ var cellPositions = new Set();
16
+ var mergedCells = new Set();
17
+ map.map.forEach(function (value) {
18
+ if (cellPositions.has(value)) {
19
+ mergedCells.add(value);
20
+ } else {
21
+ cellPositions.add(value);
22
+ }
23
+ });
24
+ if (!mergedCells.size) {
25
+ return false;
26
+ }
27
+ return (Array.isArray(indexes) ? indexes : [indexes]).map(function (index) {
28
+ return normalizeRect(index, map);
29
+ }).filter(function (rect) {
30
+ return rect.left < rect.right && rect.top < rect.bottom;
31
+ }).some(function (rect) {
32
+ var n = (rect.right - rect.left) * (rect.bottom - rect.top);
33
+ var cells = map.cellsInRect(rect);
34
+ if (cells.length !== n) {
35
+ // We can quickly assume that if the amount of cells from the map is different to what the rect says
36
+ // then there is most likely merged cells across this area which is removing cells
37
+ return true;
38
+ }
39
+ return cells.some(function (nodePos) {
40
+ return mergedCells.has(nodePos);
41
+ });
42
+ });
43
+ };
44
+ };
45
+ var hasMergedCellsInColumn = exports.hasMergedCellsInColumn = function hasMergedCellsInColumn(columnIndexes) {
46
+ return hasMergedCells(columnIndexes, function (index, map) {
47
+ var x = Math.max(Math.min(index, map.width - 1), 0); // clamped index
48
+ return {
49
+ left: x,
50
+ right: x === index ? x + 1 : x,
51
+ top: 0,
52
+ bottom: map.height
53
+ };
54
+ });
55
+ };
56
+ var hasMergedCellsInRow = exports.hasMergedCellsInRow = function hasMergedCellsInRow(rowIndexes) {
57
+ return hasMergedCells(rowIndexes, function (index, map) {
58
+ var y = Math.max(Math.min(index, map.height - 1), 0); // clamped index
59
+ return {
60
+ left: 0,
61
+ right: map.width,
62
+ top: y,
63
+ bottom: y === index ? y + 1 : y
64
+ };
65
+ });
66
+ };
@@ -1,14 +1,42 @@
1
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+ import { TableDecorations } from '../../types';
3
+ import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
1
4
  import { DragAndDropActionType } from './actions';
2
- import { createCommand } from './plugin-factory';
5
+ import { createCommand, getPluginState } from './plugin-factory';
6
+ import { pluginKey } from './plugin-key';
3
7
 
4
8
  // TODO: This command is a placeholder example. Please replace this if required.
5
- export const setDropTarget = (type, index, tr) => createCommand({
6
- type: DragAndDropActionType.SET_DROP_TARGET,
7
- data: {
8
- type,
9
- index
9
+ export const getDecorations = state => {
10
+ var _pluginKey$getState;
11
+ return ((_pluginKey$getState = pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.decorationSet) || DecorationSet.empty;
12
+ };
13
+ export const updatePluginStateDecorations = (state, decorations, key) => updateDecorations(state.doc, getDecorations(state), decorations, key);
14
+ export const setDropTarget = (type, index, tr) => createCommand(state => {
15
+ const {
16
+ dropTargetType,
17
+ dropTargetIndex
18
+ } = getPluginState(state);
19
+ if (dropTargetType === type && dropTargetIndex === index) {
20
+ return false;
21
+ }
22
+ let decorationSet = DecorationSet.empty;
23
+ if (type === 'column') {
24
+ decorationSet = updatePluginStateDecorations(state, createColumnInsertLine(index, state.selection), TableDecorations.COLUMN_INSERT_LINE);
25
+ } else if (type === 'row') {
26
+ decorationSet = updatePluginStateDecorations(state, createRowInsertLine(index, state.selection), TableDecorations.ROW_INSERT_LINE);
10
27
  }
28
+ return {
29
+ type: DragAndDropActionType.SET_DROP_TARGET,
30
+ data: {
31
+ decorationSet,
32
+ type,
33
+ index
34
+ }
35
+ };
11
36
  }, originalTr => (tr || originalTr).setMeta('addToHistory', false));
12
37
  export const clearDropTarget = tr => createCommand({
13
- type: DragAndDropActionType.CLEAR_DROP_TARGET
38
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
39
+ data: {
40
+ decorationSet: DecorationSet.empty
41
+ }
14
42
  }, originalTr => (tr || originalTr).setMeta('addToHistory', false));
@@ -1,8 +1,13 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
+ import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
4
+ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
5
+ import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
6
+ import { getPluginState as getTablePluginState } from '../plugin-factory';
3
7
  import { DropTargetType } from './consts';
4
8
  import { createPluginState, getPluginState } from './plugin-factory';
5
9
  import { pluginKey } from './plugin-key';
10
+ import { getDraggableDataFromEvent } from './utils/monitor';
6
11
  export const createPlugin = (dispatch, eventDispatcher) => {
7
12
  return new SafePlugin({
8
13
  state: createPluginState(dispatch, state => ({
@@ -14,11 +19,71 @@ export const createPlugin = (dispatch, eventDispatcher) => {
14
19
  })),
15
20
  key: pluginKey,
16
21
  view: editorView => {
17
- // TODO: Add Pragmatic DnD monitor when the view is constructed.
18
-
19
22
  return {
20
- // TODO: Cleanup monitor instance
21
- // destroy: cleanup,
23
+ destroy: monitorForElements({
24
+ canMonitor({
25
+ source
26
+ }) {
27
+ const {
28
+ type,
29
+ localId,
30
+ indexes
31
+ } = source.data;
32
+
33
+ // First; Perform any quick checks so we can abort early.
34
+ if (!indexes || !localId ||
35
+ // FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
36
+ // of more then 1 item.
37
+ indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
38
+ return false;
39
+ }
40
+ const {
41
+ tableNode
42
+ } = getTablePluginState(editorView.state);
43
+ // If the draggable localId is the same as the current selected table localId then we will allow the monitor
44
+ // watch for changes
45
+ return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
46
+ },
47
+ onDrag(event) {
48
+ const data = getDraggableDataFromEvent(event);
49
+
50
+ // If no data can be found then it's most like we do not want to perform any drag actions
51
+ if (!data) {
52
+ return;
53
+ }
54
+
55
+ // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
56
+ // insert location as to where the draggable will most likely be go. For example;
57
+ // const { sourceType, targetAdjustedIndex } = data;
58
+ // const highlight = sourceType === 'table-row' ? highlightRow : highlightColumn;
59
+ // return editorView.dispatch(
60
+ // highlight(targetAdjustedIndex)(editorView.state.tr),
61
+ // );
62
+ },
63
+
64
+ onDrop(event) {
65
+ const data = getDraggableDataFromEvent(event);
66
+
67
+ // If no data can be found then it's most like we do not want to perform any drop action
68
+ if (!data) {
69
+ return;
70
+ }
71
+ const {
72
+ sourceType,
73
+ sourceIndexes,
74
+ targetAdjustedIndex
75
+ } = data;
76
+
77
+ // If the drop target index contains merged cells then we should not allow the drop to occur.
78
+ const hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
79
+ if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
80
+ return;
81
+ }
82
+ const move = sourceType === 'table-row' ? moveRow : moveColumn;
83
+ const [sourceIndex] = sourceIndexes;
84
+ return editorView.dispatch(move(sourceIndex, targetAdjustedIndex)(editorView.state.tr));
85
+ }
86
+ })
22
87
  };
23
88
  },
24
89
  props: {
@@ -5,12 +5,14 @@ export default ((pluginState, action) => {
5
5
  case DragAndDropActionType.SET_DROP_TARGET:
6
6
  return {
7
7
  ...pluginState,
8
+ decorationSet: action.data.decorationSet,
8
9
  dropTargetType: action.data.type,
9
10
  dropTargetIndex: action.data.index
10
11
  };
11
12
  case DragAndDropActionType.CLEAR_DROP_TARGET:
12
13
  return {
13
14
  ...pluginState,
15
+ decorationSet: action.data.decorationSet,
14
16
  dropTargetType: DropTargetType.NONE,
15
17
  dropTargetIndex: 0
16
18
  };
@@ -0,0 +1 @@
1
+ export { getDraggableDataFromEvent } from './monitor';
@@ -0,0 +1,56 @@
1
+ import { extractClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
2
+ export const getDraggableDataFromEvent = ({
3
+ location,
4
+ source
5
+ }) => {
6
+ var _extractClosestEdge;
7
+ const destination = location.current.dropTargets.at(0);
8
+ // If no target exists at the current location, then the current draggable is not over a target or the target doesn't support
9
+ // the current draggable.
10
+ if (!destination) {
11
+ return undefined;
12
+ }
13
+
14
+ // This is the draggable elements data
15
+ const {
16
+ indexes: sourceIndexes,
17
+ type: sourceType,
18
+ localId: sourceLocalId
19
+ } = source.data;
20
+
21
+ // This is the drop target's data
22
+ const {
23
+ targetIndex,
24
+ type: targetType,
25
+ localId: targetLocalId
26
+ } = destination.data;
27
+
28
+ // Some basic check to abort early with...
29
+ if (!sourceIndexes || targetIndex < 0 ||
30
+ // abort if the type of the draggable is different to the target, for eg. rows cannot be dropped onto column targets.
31
+ sourceType !== targetType ||
32
+ // abort if the draggable is coming from a different table that the target is on.
33
+ sourceLocalId !== targetLocalId) {
34
+ return undefined;
35
+ }
36
+
37
+ // FIXME: currently we only support a single row/col index being moved, remove this clause when this is no longer the case.
38
+ if (sourceIndexes.length > 1) {
39
+ return undefined;
40
+ }
41
+ const targetClosestEdge = (_extractClosestEdge = extractClosestEdge(destination.data)) !== null && _extractClosestEdge !== void 0 ? _extractClosestEdge : targetType === 'table-row' ? 'top' : 'left';
42
+ // NOTE: By default we always insert row/cols at the target index to the top/left (retrospectively of row/cols).
43
+ // This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
44
+ // the new target index to be 1 index higher.
45
+ const targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
46
+ return {
47
+ sourceType,
48
+ sourceLocalId,
49
+ sourceIndexes,
50
+ targetType,
51
+ targetLocalId,
52
+ targetIndex,
53
+ targetAdjustedIndex: targetIndex + targetOffset,
54
+ targetClosestEdge
55
+ };
56
+ };
@@ -39,6 +39,8 @@ export let TableDecorations = /*#__PURE__*/function (TableDecorations) {
39
39
  TableDecorations["COLUMN_RESIZING_HANDLE"] = "COLUMN_RESIZING_HANDLE";
40
40
  TableDecorations["COLUMN_RESIZING_HANDLE_WIDGET"] = "COLUMN_RESIZING_HANDLE_WIDGET";
41
41
  TableDecorations["COLUMN_RESIZING_HANDLE_LINE"] = "COLUMN_RESIZING_HANDLE_LINE";
42
+ TableDecorations["COLUMN_INSERT_LINE"] = "COLUMN_INSERT_LINE";
43
+ TableDecorations["ROW_INSERT_LINE"] = "ROW_INSERT_LINE";
42
44
  TableDecorations["LAST_CELL_ELEMENT"] = "LAST_CELL_ELEMENT";
43
45
  return TableDecorations;
44
46
  }({});
@@ -106,8 +108,13 @@ export const TableCssClassName = {
106
108
  TABLE_STICKY: `${tablePrefixSelector}-sticky`,
107
109
  TOP_LEFT_CELL: 'table > tbody > tr:nth-child(2) > td:nth-child(1)',
108
110
  LAST_ITEM_IN_CELL: `${tablePrefixSelector}-last-item-in-cell`,
111
+ WITH_COLUMN_INSERT_LINE: `${tablePrefixSelector}-column-insert-line`,
112
+ WITH_FIRST_COLUMN_INSERT_LINE: `${tablePrefixSelector}-first-column-insert-line`,
113
+ WITH_LAST_COLUMN_INSERT_LINE: `${tablePrefixSelector}-last-column-insert-line`,
109
114
  WITH_RESIZE_LINE: `${tablePrefixSelector}-column-resize-line`,
110
- WITH_RESIZE_LINE_LAST_COLUMN: `${tablePrefixSelector}-column-resize-line-last-column`
115
+ WITH_RESIZE_LINE_LAST_COLUMN: `${tablePrefixSelector}-column-resize-line-last-column`,
116
+ WITH_ROW_INSERT_LINE: `${tablePrefixSelector}-row-insert-line`,
117
+ WITH_LAST_ROW_INSERT_LINE: `${tablePrefixSelector}-last-row-insert-line`
111
118
  };
112
119
  export let ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
113
120
  ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
@@ -7,7 +7,7 @@ import { B300, N0, N20A, N300, N40A, R500 } from '@atlaskit/theme/colors';
7
7
  import { fontSize } from '@atlaskit/theme/constants';
8
8
  import { TableCssClassName as ClassName } from '../types';
9
9
  import { columnControlsDecorationHeight, resizeHandlerAreaWidth, resizeLineWidth, stickyHeaderBorderBottomWidth, stickyRowOffsetTop, tableBorderColor, tableBorderDeleteColor, tableBorderRadiusSize, tableBorderSelectedColor, tableCellBackgroundColor, tableCellDeleteColor, tableCellSelectedColor, tableControlsSpacing, tableHeaderCellBackgroundColor, tableInsertColumnButtonSize, tableOverflowShadowWidth, tablePadding, tableScrollbarOffset, tableTextColor, tableToolbarDeleteColor, tableToolbarSelectedColor, tableToolbarSize } from './consts';
10
- import { columnControlsDecoration, columnControlsLineMarker, DeleteButton, floatingColumnControls, HeaderButton, HeaderButtonDanger, HeaderButtonHover, hoveredCell, hoveredDeleteButton, hoveredWarningCell, insertColumnButtonWrapper, InsertMarker, insertRowButtonWrapper, OverflowShadow, resizeHandle } from './ui-styles';
10
+ import { columnControlsDecoration, columnControlsLineMarker, DeleteButton, floatingColumnControls, HeaderButton, HeaderButtonDanger, HeaderButtonHover, hoveredCell, hoveredDeleteButton, hoveredWarningCell, insertColumnButtonWrapper, insertLine, InsertMarker, insertRowButtonWrapper, OverflowShadow, resizeHandle } from './ui-styles';
11
11
  const cornerControlHeight = tableToolbarSize + 1;
12
12
 
13
13
  /*
@@ -210,6 +210,7 @@ export const tableStyles = props => {
210
210
  ${hoveredDeleteButton(props)};
211
211
  ${hoveredCell(props)};
212
212
  ${hoveredWarningCell};
213
+ ${getBooleanFF('platform.editor.table.drag-and-drop') && insertLine(props)};
213
214
  ${resizeHandle(props)};
214
215
  ${rangeSelectionStyles};
215
216
 
@@ -89,6 +89,7 @@ export const columnControlsDecorationHeight = 25;
89
89
  export const columnControlsZIndex = akEditorUnitZIndex * 10;
90
90
  export const columnControlsSelectedZIndex = columnControlsZIndex + 1;
91
91
  export const columnResizeHandleZIndex = columnControlsSelectedZIndex + 1;
92
+ export const insertLineWidth = 3;
92
93
  export const resizeHandlerAreaWidth = RESIZE_HANDLE_AREA_DECORATION_GAP / 3;
93
94
  export const resizeLineWidth = 2;
94
95
  export const resizeHandlerZIndex = columnControlsZIndex + akRichMediaResizeZIndex;
@@ -5,7 +5,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
5
  import { B300, N0, N300, N40A, N60A, Y200, Y50 } from '@atlaskit/theme/colors';
6
6
  import { borderRadius } from '@atlaskit/theme/constants';
7
7
  import { TableCssClassName as ClassName } from '../types';
8
- import { columnControlsDecorationHeight, columnControlsSelectedZIndex, columnControlsZIndex, lineMarkerSize, resizeHandlerAreaWidth, resizeHandlerZIndex, resizeLineWidth, tableBorderColor, tableBorderDeleteColor, tableBorderSelectedColor, tableCellDeleteColor, tableCellHoverDeleteIconBackground, tableCellHoverDeleteIconColor, tableCellSelectedDeleteIconBackground, tableCellSelectedDeleteIconColor, tableDeleteButtonSize, tableHeaderCellBackgroundColor, tableInsertColumnButtonSize, tableOverflowShadowWidth, tableOverflowShadowWidthWide, tableToolbarDeleteColor, tableToolbarSelectedColor, tableToolbarSize } from './consts';
8
+ import { columnControlsDecorationHeight, columnControlsSelectedZIndex, columnControlsZIndex, insertLineWidth, lineMarkerSize, resizeHandlerAreaWidth, resizeHandlerZIndex, resizeLineWidth, tableBorderColor, tableBorderDeleteColor, tableBorderSelectedColor, tableCellDeleteColor, tableCellHoverDeleteIconBackground, tableCellHoverDeleteIconColor, tableCellSelectedDeleteIconBackground, tableCellSelectedDeleteIconColor, tableDeleteButtonSize, tableHeaderCellBackgroundColor, tableInsertColumnButtonSize, tableOverflowShadowWidth, tableOverflowShadowWidthWide, tableToolbarDeleteColor, tableToolbarSelectedColor, tableToolbarSize } from './consts';
9
9
  const InsertLine = (props, cssString) => css`
10
10
  .${ClassName.CONTROLS_INSERT_LINE} {
11
11
  background: ${tableBorderSelectedColor(props)};
@@ -635,4 +635,117 @@ export const resizeHandle = props => css`
635
635
  height: calc(100% + ${tableToolbarSize + tableCellBorderWidth}px);
636
636
  }
637
637
  }
638
+ `;
639
+ export const insertLine = props => css`
640
+ .${ClassName.TABLE_CONTAINER} {
641
+ td.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE}::before {
642
+ content: ' ';
643
+ position: absolute;
644
+ left: -1px;
645
+ top: -1px;
646
+ width: ${insertLineWidth}px;
647
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
648
+ background-color: ${tableBorderSelectedColor(props)};
649
+ z-index: ${columnControlsZIndex * 2};
650
+ }
651
+
652
+ th.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE}::before {
653
+ content: ' ';
654
+ left: -1px;
655
+ position: absolute;
656
+ width: ${insertLineWidth}px;
657
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
658
+ background-color: ${tableBorderSelectedColor(props)};
659
+ z-index: ${columnControlsZIndex * 2};
660
+ top: -${tableCellBorderWidth}px;
661
+ }
662
+
663
+ td.${ClassName.WITH_COLUMN_INSERT_LINE}::before {
664
+ content: ' ';
665
+ position: absolute;
666
+ left: ${"var(--ds-space-negative-025, -2px)"};
667
+ top: -1px;
668
+ width: ${insertLineWidth}px;
669
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
670
+ background-color: ${tableBorderSelectedColor(props)};
671
+ z-index: ${columnControlsZIndex * 2};
672
+ }
673
+
674
+ th.${ClassName.WITH_COLUMN_INSERT_LINE}::before {
675
+ content: ' ';
676
+ left: ${"var(--ds-space-negative-025, -2px)"};
677
+ position: absolute;
678
+ width: ${insertLineWidth}px;
679
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
680
+ background-color: ${tableBorderSelectedColor(props)};
681
+ z-index: ${columnControlsZIndex * 2};
682
+ top: -${tableCellBorderWidth}px;
683
+ }
684
+
685
+ td.${ClassName.WITH_LAST_COLUMN_INSERT_LINE}::before {
686
+ content: ' ';
687
+ position: absolute;
688
+ right: -1px;
689
+ top: -1px;
690
+ width: ${insertLineWidth}px;
691
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
692
+ background-color: ${tableBorderSelectedColor(props)};
693
+ z-index: ${columnControlsZIndex * 2};
694
+ }
695
+
696
+ th.${ClassName.WITH_LAST_COLUMN_INSERT_LINE}::before {
697
+ content: ' ';
698
+ right: -1px;
699
+ position: absolute;
700
+ width: ${insertLineWidth}px;
701
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
702
+ background-color: ${tableBorderSelectedColor(props)};
703
+ z-index: ${columnControlsZIndex * 2};
704
+ top: -${tableCellBorderWidth}px;
705
+ }
706
+
707
+ td.${ClassName.WITH_ROW_INSERT_LINE}::before {
708
+ content: ' ';
709
+ position: absolute;
710
+ left: ${"var(--ds-space-negative-025, -2px)"};
711
+ top: -1px;
712
+ height: ${insertLineWidth}px;
713
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
714
+ background-color: ${tableBorderSelectedColor(props)};
715
+ z-index: ${columnControlsZIndex * 2};
716
+ }
717
+
718
+ th.${ClassName.WITH_ROW_INSERT_LINE}::before {
719
+ content: ' ';
720
+ left: ${"var(--ds-space-negative-025, -2px)"};
721
+ position: absolute;
722
+ height: ${insertLineWidth}px;
723
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
724
+ background-color: ${tableBorderSelectedColor(props)};
725
+ z-index: ${columnControlsZIndex * 2};
726
+ top: -1px;
727
+ }
728
+
729
+ td.${ClassName.WITH_LAST_ROW_INSERT_LINE}::before {
730
+ content: ' ';
731
+ position: absolute;
732
+ left: ${"var(--ds-space-negative-025, -2px)"};
733
+ bottom: 0;
734
+ height: ${insertLineWidth}px;
735
+ width: calc(100% + 2px);
736
+ background-color: ${tableBorderSelectedColor(props)};
737
+ z-index: ${columnControlsZIndex * 2};
738
+ }
739
+
740
+ th.${ClassName.WITH_LAST_ROW_INSERT_LINE}::before {
741
+ content: ' ';
742
+ left: ${"var(--ds-space-negative-025, -2px)"};
743
+ bottom: 0;
744
+ position: absolute;
745
+ height: ${insertLineWidth}px;
746
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
747
+ background-color: ${tableBorderSelectedColor(props)};
748
+ z-index: ${columnControlsZIndex * 2};
749
+ }
750
+ }
638
751
  `;
@@ -404,4 +404,66 @@ export const createColumnLineResize = (selection, cellColumnPositioning) => {
404
404
  key: `${TableDecorations.COLUMN_RESIZING_HANDLE_LINE}_${cellColumnPositioning.right}_${index}`
405
405
  });
406
406
  }).filter(nonNullable);
407
+ };
408
+ export const createColumnInsertLine = (columnIndex, selection) => {
409
+ const table = findTable(selection);
410
+ if (!table) {
411
+ return [];
412
+ }
413
+ const map = TableMap.get(table.node);
414
+ const isFirstColumn = columnIndex === 0;
415
+ const isLastColumn = columnIndex === map.width;
416
+ if (isLastColumn) {
417
+ columnIndex -= 1;
418
+ }
419
+ const decorationClassName = isFirstColumn ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE : isLastColumn ? ClassName.WITH_LAST_COLUMN_INSERT_LINE : ClassName.WITH_COLUMN_INSERT_LINE;
420
+ const cellPositions = makeArray(map.height).map(rowIndex => map.map[map.width * rowIndex + columnIndex]).filter((cellPosition, rowIndex) => {
421
+ if (isLastColumn) {
422
+ return true; // If is the last column no filter applied
423
+ }
424
+
425
+ const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
426
+ return cellPosition !== nextPosition; // Removed it if next position is merged
427
+ });
428
+
429
+ const cells = cellPositions.map(pos => ({
430
+ pos: pos + table.start,
431
+ node: table.node.nodeAt(pos)
432
+ }));
433
+ return cells.map((cell, index) => {
434
+ if (!cell || !cell.node) {
435
+ return;
436
+ }
437
+ return Decoration.node(cell.pos, cell.pos + cell.node.nodeSize, {
438
+ class: decorationClassName
439
+ }, {
440
+ key: `${TableDecorations.COLUMN_INSERT_LINE}_${index}`
441
+ });
442
+ }).filter(nonNullable);
443
+ };
444
+ export const createRowInsertLine = (rowIndex, selection) => {
445
+ const table = findTable(selection);
446
+ if (!table) {
447
+ return [];
448
+ }
449
+ const map = TableMap.get(table.node);
450
+ const isLastRow = rowIndex === map.height;
451
+ if (isLastRow) {
452
+ rowIndex -= 1;
453
+ }
454
+ const cells = getCellsInRow(rowIndex)(selection);
455
+ if (!cells) {
456
+ return [];
457
+ }
458
+ const decorationClassName = isLastRow ? ClassName.WITH_LAST_ROW_INSERT_LINE : ClassName.WITH_ROW_INSERT_LINE;
459
+ return cells.map((cell, index) => {
460
+ if (!cell || !cell.node) {
461
+ return;
462
+ }
463
+ return Decoration.node(cell.pos, cell.pos + cell.node.nodeSize, {
464
+ class: decorationClassName
465
+ }, {
466
+ key: `${TableDecorations.ROW_INSERT_LINE}_${index}`
467
+ });
468
+ }).filter(nonNullable);
407
469
  };
@@ -1,5 +1,5 @@
1
1
  export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, isSelectionUpdated } from './selection';
2
- export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnLineResize } from './decoration';
2
+ export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnInsertLine, createColumnLineResize, createRowInsertLine } from './decoration';
3
3
  export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow } from './nodes';
4
4
  export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell } from './paste';
5
5
  export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler } from './dom';
@@ -7,4 +7,5 @@ export { getColumnsWidths, isColumnDeleteButtonVisible, getColumnDeleteButtonPar
7
7
  export { getRowHeights, isRowDeleteButtonVisible, getRowDeleteButtonParams, getRowsParams, getRowClassNames, copyPreviousRow } from './row-controls';
8
8
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
9
9
  export { getMergedCellsPositions } from './table';
10
- export { updatePluginStateDecorations } from './update-plugin-state-decorations';
10
+ export { updatePluginStateDecorations } from './update-plugin-state-decorations';
11
+ export { hasMergedCellsInColumn, hasMergedCellsInRow } from './merged-cells';
@@ -0,0 +1,48 @@
1
+ import { findTable, TableMap } from '@atlaskit/editor-tables';
2
+ const hasMergedCells = (indexes, normalizeRect) => selection => {
3
+ const table = findTable(selection);
4
+ if (!table) {
5
+ return false;
6
+ }
7
+ const map = TableMap.get(table.node);
8
+ const cellPositions = new Set();
9
+ const mergedCells = new Set();
10
+ map.map.forEach(value => {
11
+ if (cellPositions.has(value)) {
12
+ mergedCells.add(value);
13
+ } else {
14
+ cellPositions.add(value);
15
+ }
16
+ });
17
+ if (!mergedCells.size) {
18
+ return false;
19
+ }
20
+ return (Array.isArray(indexes) ? indexes : [indexes]).map(index => normalizeRect(index, map)).filter(rect => rect.left < rect.right && rect.top < rect.bottom).some(rect => {
21
+ const n = (rect.right - rect.left) * (rect.bottom - rect.top);
22
+ const cells = map.cellsInRect(rect);
23
+ if (cells.length !== n) {
24
+ // We can quickly assume that if the amount of cells from the map is different to what the rect says
25
+ // then there is most likely merged cells across this area which is removing cells
26
+ return true;
27
+ }
28
+ return cells.some(nodePos => mergedCells.has(nodePos));
29
+ });
30
+ };
31
+ export const hasMergedCellsInColumn = columnIndexes => hasMergedCells(columnIndexes, (index, map) => {
32
+ const x = Math.max(Math.min(index, map.width - 1), 0); // clamped index
33
+ return {
34
+ left: x,
35
+ right: x === index ? x + 1 : x,
36
+ top: 0,
37
+ bottom: map.height
38
+ };
39
+ });
40
+ export const hasMergedCellsInRow = rowIndexes => hasMergedCells(rowIndexes, (index, map) => {
41
+ const y = Math.max(Math.min(index, map.height - 1), 0); // clamped index
42
+ return {
43
+ left: 0,
44
+ right: map.width,
45
+ top: y,
46
+ bottom: y === index ? y + 1 : y
47
+ };
48
+ });
@@ -1,21 +1,50 @@
1
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+ import { TableDecorations } from '../../types';
3
+ import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
1
4
  import { DragAndDropActionType } from './actions';
2
- import { createCommand } from './plugin-factory';
5
+ import { createCommand, getPluginState } from './plugin-factory';
6
+ import { pluginKey } from './plugin-key';
3
7
 
4
8
  // TODO: This command is a placeholder example. Please replace this if required.
9
+ export var getDecorations = function getDecorations(state) {
10
+ var _pluginKey$getState;
11
+ return ((_pluginKey$getState = pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.decorationSet) || DecorationSet.empty;
12
+ };
13
+ export var updatePluginStateDecorations = function updatePluginStateDecorations(state, decorations, key) {
14
+ return updateDecorations(state.doc, getDecorations(state), decorations, key);
15
+ };
5
16
  export var setDropTarget = function setDropTarget(type, index, tr) {
6
- return createCommand({
7
- type: DragAndDropActionType.SET_DROP_TARGET,
8
- data: {
9
- type: type,
10
- index: index
17
+ return createCommand(function (state) {
18
+ var _getPluginState = getPluginState(state),
19
+ dropTargetType = _getPluginState.dropTargetType,
20
+ dropTargetIndex = _getPluginState.dropTargetIndex;
21
+ if (dropTargetType === type && dropTargetIndex === index) {
22
+ return false;
11
23
  }
24
+ var decorationSet = DecorationSet.empty;
25
+ if (type === 'column') {
26
+ decorationSet = updatePluginStateDecorations(state, createColumnInsertLine(index, state.selection), TableDecorations.COLUMN_INSERT_LINE);
27
+ } else if (type === 'row') {
28
+ decorationSet = updatePluginStateDecorations(state, createRowInsertLine(index, state.selection), TableDecorations.ROW_INSERT_LINE);
29
+ }
30
+ return {
31
+ type: DragAndDropActionType.SET_DROP_TARGET,
32
+ data: {
33
+ decorationSet: decorationSet,
34
+ type: type,
35
+ index: index
36
+ }
37
+ };
12
38
  }, function (originalTr) {
13
39
  return (tr || originalTr).setMeta('addToHistory', false);
14
40
  });
15
41
  };
16
42
  export var clearDropTarget = function clearDropTarget(tr) {
17
43
  return createCommand({
18
- type: DragAndDropActionType.CLEAR_DROP_TARGET
44
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
45
+ data: {
46
+ decorationSet: DecorationSet.empty
47
+ }
19
48
  }, function (originalTr) {
20
49
  return (tr || originalTr).setMeta('addToHistory', false);
21
50
  });