@atlaskit/editor-plugin-table 5.4.19 → 5.4.20

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 (96) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/plugins/table/index.js +1 -0
  3. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +5 -2
  4. package/dist/cjs/plugins/table/nodeviews/table.js +7 -2
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/consts.js +3 -2
  7. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +38 -14
  8. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  9. package/dist/cjs/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -2
  10. package/dist/cjs/plugins/table/ui/DragHandle/index.js +7 -4
  11. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  12. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +4 -2
  13. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -3
  14. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +4 -2
  15. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +5 -3
  16. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +7 -4
  17. package/dist/cjs/plugins/table/utils/drag-menu.js +10 -6
  18. package/dist/es2019/plugins/table/index.js +1 -0
  19. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -2
  20. package/dist/es2019/plugins/table/nodeviews/table.js +7 -2
  21. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
  22. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/consts.js +2 -1
  23. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +39 -15
  24. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +5 -0
  25. package/dist/es2019/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -1
  26. package/dist/es2019/plugins/table/ui/DragHandle/index.js +6 -4
  27. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  28. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +4 -2
  29. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -3
  30. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +4 -2
  31. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +5 -3
  32. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +7 -4
  33. package/dist/es2019/plugins/table/utils/drag-menu.js +6 -6
  34. package/dist/esm/plugins/table/index.js +1 -0
  35. package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -2
  36. package/dist/esm/plugins/table/nodeviews/table.js +7 -2
  37. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
  38. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/consts.js +2 -1
  39. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +39 -15
  40. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  41. package/dist/esm/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -2
  42. package/dist/esm/plugins/table/ui/DragHandle/index.js +7 -4
  43. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  44. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +4 -2
  45. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -3
  46. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +4 -2
  47. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +5 -3
  48. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +7 -4
  49. package/dist/esm/plugins/table/utils/drag-menu.js +10 -6
  50. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +1 -0
  51. package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +4 -1
  52. package/dist/types/plugins/table/pm-plugins/drag-and-drop/consts.d.ts +1 -0
  53. package/dist/types/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
  54. package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +1 -0
  55. package/dist/types/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +1 -0
  56. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +2 -1
  57. package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  58. package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +2 -1
  59. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  60. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  61. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  62. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  63. package/dist/types/plugins/table/utils/drag-menu.d.ts +1 -1
  64. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +1 -0
  65. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +4 -1
  66. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/consts.d.ts +1 -0
  67. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
  68. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +1 -0
  69. package/dist/types-ts4.5/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +1 -0
  70. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +2 -1
  71. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  72. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +2 -1
  73. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  74. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  75. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  76. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  77. package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +1 -1
  78. package/package.json +1 -1
  79. package/src/__tests__/unit/pm-plugins/drag-and-drop/plugin.ts +112 -0
  80. package/src/plugins/table/index.tsx +1 -0
  81. package/src/plugins/table/nodeviews/TableComponent.tsx +4 -0
  82. package/src/plugins/table/nodeviews/table.tsx +4 -0
  83. package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +9 -1
  84. package/src/plugins/table/pm-plugins/drag-and-drop/consts.ts +2 -0
  85. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +49 -17
  86. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +5 -0
  87. package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +1 -0
  88. package/src/plugins/table/ui/DragHandle/HandleIconComponent.tsx +5 -1
  89. package/src/plugins/table/ui/DragHandle/index.tsx +6 -2
  90. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +3 -1
  91. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +3 -0
  92. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +5 -1
  93. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +3 -0
  94. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +5 -2
  95. package/src/plugins/table/ui/TableFloatingControls/index.tsx +6 -1
  96. package/src/plugins/table/utils/drag-menu.ts +6 -6
@@ -67,7 +67,8 @@ export var DragMenu = function DragMenu(_ref) {
67
67
  boundariesElement = _ref.boundariesElement,
68
68
  scrollableElement = _ref.scrollableElement,
69
69
  targetCellPosition = _ref.targetCellPosition,
70
- getEditorContainerWidth = _ref.getEditorContainerWidth;
70
+ getEditorContainerWidth = _ref.getEditorContainerWidth,
71
+ canDrag = _ref.canDrag;
71
72
  var tableMap = tableNode ? TableMap.get(tableNode) : undefined;
72
73
  var state = editorView.state,
73
74
  dispatch = editorView.dispatch;
@@ -75,7 +76,7 @@ export var DragMenu = function DragMenu(_ref) {
75
76
  var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
76
77
  var hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
77
78
  var shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
78
- var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, shouldMoveDisabled, tableMap, index, targetCellPosition, selectionRect);
79
+ var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, tableMap, index, targetCellPosition, selectionRect);
79
80
  var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
80
81
  menuItems = _convertToDropdownIte.menuItems,
81
82
  menuCallback = _convertToDropdownIte.menuCallback;
@@ -16,7 +16,8 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
16
16
  direction = _ref.direction,
17
17
  index = _ref.index,
18
18
  targetCellPosition = _ref.targetCellPosition,
19
- getEditorContainerWidth = _ref.getEditorContainerWidth;
19
+ getEditorContainerWidth = _ref.getEditorContainerWidth,
20
+ canDrag = _ref.canDrag;
20
21
  if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
21
22
  return null;
22
23
  }
@@ -51,7 +52,8 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
51
52
  direction: direction,
52
53
  index: index,
53
54
  targetCellPosition: targetCellPosition,
54
- getEditorContainerWidth: getEditorContainerWidth
55
+ getEditorContainerWidth: getEditorContainerWidth,
56
+ canDrag: canDrag
55
57
  }));
56
58
  };
57
59
  FloatingDragMenu.displayName = 'FloatingDragMenu';
@@ -1,4 +1,5 @@
1
1
  import React, { useCallback, useMemo } from 'react';
2
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
3
  import { CellSelection } from '@atlaskit/editor-tables';
3
4
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
4
5
  import { clearHoverSelection, hoverCell, hoverColumns, selectColumn } from '../../../commands';
@@ -29,7 +30,8 @@ export var ColumnControls = function ColumnControls(_ref) {
29
30
  rowHeights = _ref.rowHeights,
30
31
  colWidths = _ref.colWidths,
31
32
  hasHeaderColumn = _ref.hasHeaderColumn,
32
- isTableHovered = _ref.isTableHovered;
33
+ isTableHovered = _ref.isTableHovered,
34
+ canDrag = _ref.canDrag;
33
35
  var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
34
36
  return width ? "".concat(width - 1, "px") : '0px';
35
37
  }).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
@@ -139,14 +141,15 @@ export var ColumnControls = function ColumnControls(_ref) {
139
141
  direction: "column",
140
142
  tableLocalId: localId || '',
141
143
  indexes: colIndexes,
142
- previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : 48,
144
+ previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
143
145
  previewHeight: previewHeight,
144
146
  appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
145
147
  onClick: handleClick,
146
148
  onMouseOver: handleMouseOver,
147
149
  onMouseOut: handleMouseOut,
148
150
  onMouseUp: handleMouseUp,
149
- editorView: editorView
151
+ editorView: editorView,
152
+ canDrag: canDrag
150
153
  }))));
151
154
  };
152
155
  export default ColumnControls;
@@ -19,7 +19,8 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
19
19
  stickyHeader = _ref.stickyHeader,
20
20
  selection = _ref.selection,
21
21
  isInDanger = _ref.isInDanger,
22
- isTableHovered = _ref.isTableHovered;
22
+ isTableHovered = _ref.isTableHovered,
23
+ canDrag = _ref.canDrag;
23
24
  var _useState = useState({
24
25
  width: 0,
25
26
  height: 0
@@ -110,7 +111,8 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
110
111
  isInDanger: isInDanger,
111
112
  rowHeights: rowHeights,
112
113
  colWidths: colWidths,
113
- hasHeaderColumn: hasHeaderColumn
114
+ hasHeaderColumn: hasHeaderColumn,
115
+ canDrag: canDrag
114
116
  }), hasDropTargets && /*#__PURE__*/React.createElement(ColumnDropTargets, {
115
117
  tableRef: tableRef,
116
118
  stickyTop: tableActive ? stickyTop : undefined,
@@ -33,6 +33,7 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
33
33
  isInDanger = _ref.isInDanger,
34
34
  isResizing = _ref.isResizing,
35
35
  isTableHovered = _ref.isTableHovered,
36
+ canDrag = _ref.canDrag,
36
37
  hoverRows = _ref.hoverRows,
37
38
  selectRow = _ref.selectRow,
38
39
  updateCellHoverLocation = _ref.updateCellHoverLocation;
@@ -132,11 +133,11 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
132
133
  "data-end-index": endIndex,
133
134
  className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER,
134
135
  contentEditable: false,
135
- key: index
136
+ key: "insert-dot-".concat(index)
136
137
  }, /*#__PURE__*/React.createElement("div", {
137
138
  className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT
138
139
  })), isDragging && /*#__PURE__*/React.createElement(RowDropTarget, {
139
- key: index,
140
+ key: "drop-target-".concat(index),
140
141
  index: index,
141
142
  localId: currentNodeLocalId,
142
143
  style: {
@@ -168,7 +169,8 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
168
169
  onMouseOver: handleMouseOver,
169
170
  onMouseOut: handleMouseOut,
170
171
  onMouseUp: onMouseUp,
171
- editorView: editorView
172
+ editorView: editorView,
173
+ canDrag: canDrag
172
174
  })));
173
175
  };
174
176
  export var DragControls = injectIntl(DragControlsComponent);
@@ -126,8 +126,9 @@ var TableFloatingControls = /*#__PURE__*/function (_Component) {
126
126
  headerRowHeight = _this$props2.headerRowHeight,
127
127
  stickyHeader = _this$props2.stickyHeader,
128
128
  hoveredCell = _this$props2.hoveredCell,
129
- isTableHovered = _this$props2.isTableHovered;
130
- return this.state.tableWrapperWidth !== nextState.tableWrapperWidth || this.state.tableWrapperHeight !== nextState.tableWrapperHeight || ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || isSelectionUpdated(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell || isTableHovered !== nextProps.isTableHovered;
129
+ isTableHovered = _this$props2.isTableHovered,
130
+ canDrag = _this$props2.canDrag;
131
+ return this.state.tableWrapperWidth !== nextState.tableWrapperWidth || this.state.tableWrapperHeight !== nextState.tableWrapperHeight || ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || isSelectionUpdated(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell || isTableHovered !== nextProps.isTableHovered || canDrag !== nextProps.canDrag;
131
132
  }
132
133
  }, {
133
134
  key: "componentWillUnmount",
@@ -154,7 +155,8 @@ var TableFloatingControls = /*#__PURE__*/function (_Component) {
154
155
  stickyHeader = _this$props3.stickyHeader,
155
156
  isDragAndDropEnabled = _this$props3.isDragAndDropEnabled,
156
157
  hoveredCell = _this$props3.hoveredCell,
157
- isTableHovered = _this$props3.isTableHovered;
158
+ isTableHovered = _this$props3.isTableHovered,
159
+ canDrag = _this$props3.canDrag;
158
160
  if (!tableRef) {
159
161
  return null;
160
162
  }
@@ -196,7 +198,8 @@ var TableFloatingControls = /*#__PURE__*/function (_Component) {
196
198
  tableWidth: this.state.tableWrapperWidth,
197
199
  hoverRows: this.hoverRows,
198
200
  selectRow: this.selectRow,
199
- updateCellHoverLocation: this.updateCellHoverLocation
201
+ updateCellHoverLocation: this.updateCellHoverLocation,
202
+ canDrag: canDrag
200
203
  })) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
201
204
  editorView: editorView,
202
205
  tableRef: tableRef,
@@ -23,7 +23,7 @@ var canIncrease = function canIncrease(index) {
23
23
  var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
24
24
  return index !== undefined && index < max;
25
25
  };
26
- export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, hasMergedCells, tableMap, index, targetCellPosition, selectionRect) {
26
+ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, tableMap, index, targetCellPosition, selectionRect) {
27
27
  var addOptions = direction === 'row' ? [{
28
28
  label: 'above',
29
29
  offset: 0,
@@ -48,27 +48,31 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
48
48
  var moveOptions = direction === 'row' ? [{
49
49
  label: 'up',
50
50
  offset: -1,
51
- canMove: canDecrease,
51
+ canMove: function canMove(index) {
52
+ return canDrag && canDecrease(index);
53
+ },
52
54
  icon: ArrowUpIcon
53
55
  }, {
54
56
  label: 'down',
55
57
  offset: 1,
56
58
  canMove: function canMove(index) {
57
59
  var _tableMap$height;
58
- return canIncrease(index, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
60
+ return canDrag && canIncrease(index, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
59
61
  },
60
62
  icon: ArrowDownIcon
61
63
  }] : [{
62
64
  label: 'left',
63
65
  offset: -1,
64
- canMove: canDecrease,
66
+ canMove: function canMove(index) {
67
+ return canDrag && canDecrease(index);
68
+ },
65
69
  icon: ArrowLeftIcon
66
70
  }, {
67
71
  label: 'right',
68
72
  offset: 1,
69
73
  canMove: function canMove(index) {
70
74
  var _tableMap$width;
71
- return canIncrease(index, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
75
+ return canDrag && canIncrease(index, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
72
76
  },
73
77
  icon: ArrowRightIcon
74
78
  }];
@@ -137,7 +141,7 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
137
141
  return {
138
142
  id: "move_".concat(direction, "_").concat(label),
139
143
  title: "Move ".concat(direction, " ").concat(label),
140
- disabled: hasMergedCells || !canMove(index),
144
+ disabled: !canMove(index),
141
145
  icon: icon,
142
146
  onClick: function onClick(state, dispatch) {
143
147
  if (canMove(index)) {
@@ -23,6 +23,7 @@ export interface ComponentProps {
23
23
  isHeaderColumnEnabled: boolean;
24
24
  isMediaFullscreen?: boolean;
25
25
  isDragAndDropEnabled?: boolean;
26
+ canDrag?: boolean;
26
27
  tableActive: boolean;
27
28
  ordering: TableColumnOrdering;
28
29
  isResizing?: boolean;
@@ -1,6 +1,7 @@
1
1
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
2
  import type { TableDirection } from '../../types';
3
3
  import type { DropTargetType } from './consts';
4
+ import type { DragAndDropPluginState } from './types';
4
5
  export interface DragAndDropAction<T, D> {
5
6
  type: T;
6
7
  data: D;
@@ -9,6 +10,7 @@ export declare const DragAndDropActionType: {
9
10
  readonly SET_DROP_TARGET: "SET_DROP_TARGET";
10
11
  readonly CLEAR_DROP_TARGET: "CLEAR_DROP_TARGET";
11
12
  readonly TOGGLE_DRAG_MENU: "TOGGLE_DRAG_MENU";
13
+ readonly UPDATE: "UPDATE";
12
14
  };
13
15
  export type DragAndDropSetDropTargetAction = DragAndDropAction<typeof DragAndDropActionType.SET_DROP_TARGET, {
14
16
  type: DropTargetType;
@@ -23,4 +25,5 @@ export type DragAndDropToggleDragMenuAction = DragAndDropAction<typeof DragAndDr
23
25
  direction: TableDirection;
24
26
  index: number;
25
27
  }>;
26
- export type DragAndDropPluginAction = DragAndDropSetDropTargetAction | DragAndDropClearDropTargetAction | DragAndDropToggleDragMenuAction;
28
+ export type DragAndDropUpdateAction = DragAndDropAction<typeof DragAndDropActionType.UPDATE, Partial<DragAndDropPluginState>>;
29
+ export type DragAndDropPluginAction = DragAndDropSetDropTargetAction | DragAndDropClearDropTargetAction | DragAndDropToggleDragMenuAction | DragAndDropUpdateAction;
@@ -4,3 +4,4 @@ export declare const DropTargetType: {
4
4
  readonly COLUMN: "column";
5
5
  };
6
6
  export type DropTargetType = (typeof DropTargetType)[keyof typeof DropTargetType];
7
+ export declare const DRAGGABLE_TABLE_NODE_SIZE_LIMIT = 20000;
@@ -1,3 +1,4 @@
1
1
  import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher) => SafePlugin<import("./types").DragAndDropPluginState>;
3
+ import type { DragAndDropPluginState } from './types';
4
+ export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher) => SafePlugin<DragAndDropPluginState>;
@@ -9,4 +9,5 @@ export interface DragAndDropPluginState {
9
9
  dragMenuDirection?: TableDirection;
10
10
  dragMenuIndex: number;
11
11
  isDragging: boolean;
12
+ canDrag: boolean;
12
13
  }
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  type HandleIconProps = {
3
+ canDrag: boolean;
3
4
  hasMergedCells: boolean;
4
5
  direction: 'row' | 'column';
5
6
  isDragMenuOpen: boolean | undefined;
@@ -14,6 +14,7 @@ type DragHandleProps = {
14
14
  onMouseOut?: MouseEventHandler;
15
15
  onMouseUp?: MouseEventHandler;
16
16
  editorView: EditorView;
17
+ canDrag?: boolean;
17
18
  };
18
- export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, }: DragHandleProps) => JSX.Element;
19
+ export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, canDrag, }: DragHandleProps) => JSX.Element;
19
20
  export {};
@@ -17,6 +17,7 @@ type DragMenuProps = {
17
17
  scrollableElement?: HTMLElement;
18
18
  pluginConfig?: PluginConfig;
19
19
  getEditorContainerWidth: GetEditorContainerWidth;
20
+ canDrag?: boolean;
20
21
  };
21
- export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, }: DragMenuProps) => jsx.JSX.Element | null;
22
+ export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, canDrag, }: DragMenuProps) => jsx.JSX.Element | null;
22
23
  export {};
@@ -15,9 +15,10 @@ export interface Props {
15
15
  index?: number;
16
16
  targetCellPosition?: number;
17
17
  getEditorContainerWidth: GetEditorContainerWidth;
18
+ canDrag?: boolean;
18
19
  }
19
20
  declare const FloatingDragMenu: {
20
- ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableRef, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, }: Props): JSX.Element | null;
21
+ ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableRef, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, canDrag, }: Props): JSX.Element | null;
21
22
  displayName: string;
22
23
  };
23
24
  export default FloatingDragMenu;
@@ -14,6 +14,7 @@ export interface ColumnControlsProps {
14
14
  colWidths?: (number | undefined)[];
15
15
  hasHeaderColumn?: boolean;
16
16
  isTableHovered?: boolean;
17
+ canDrag?: boolean;
17
18
  }
18
- export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, }: ColumnControlsProps) => JSX.Element;
19
+ export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, canDrag, }: ColumnControlsProps) => JSX.Element;
19
20
  export default ColumnControls;
@@ -22,6 +22,7 @@ export interface Props {
22
22
  ordering?: TableColumnOrdering;
23
23
  stickyHeader?: RowStickyState;
24
24
  isTableHovered?: boolean;
25
+ canDrag?: boolean;
25
26
  }
26
27
  export declare const TableFloatingColumnControls: React.FC<Props>;
27
28
  export default TableFloatingColumnControls;
@@ -13,6 +13,7 @@ type DragControlsProps = {
13
13
  isInDanger?: boolean;
14
14
  isResizing?: boolean;
15
15
  isTableHovered?: boolean;
16
+ canDrag?: boolean;
16
17
  hoverRows: (rows: number[], danger?: boolean) => void;
17
18
  selectRow: (row: number, expand: boolean) => void;
18
19
  updateCellHoverLocation: (rowIndex: number) => void;
@@ -18,6 +18,7 @@ export interface Props {
18
18
  isHeaderColumnEnabled?: boolean;
19
19
  isNumberColumnEnabled?: boolean;
20
20
  isDragAndDropEnabled?: boolean;
21
+ canDrag?: boolean;
21
22
  hasHeaderRow?: boolean;
22
23
  headerRowHeight?: number;
23
24
  hoveredRows?: number[];
@@ -7,4 +7,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
7
7
  icon?: React.ComponentType<IconProps>;
8
8
  keymap?: string;
9
9
  }
10
- export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, hasMergedCells: boolean, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
10
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
@@ -23,6 +23,7 @@ export interface ComponentProps {
23
23
  isHeaderColumnEnabled: boolean;
24
24
  isMediaFullscreen?: boolean;
25
25
  isDragAndDropEnabled?: boolean;
26
+ canDrag?: boolean;
26
27
  tableActive: boolean;
27
28
  ordering: TableColumnOrdering;
28
29
  isResizing?: boolean;
@@ -1,6 +1,7 @@
1
1
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
2
  import type { TableDirection } from '../../types';
3
3
  import type { DropTargetType } from './consts';
4
+ import type { DragAndDropPluginState } from './types';
4
5
  export interface DragAndDropAction<T, D> {
5
6
  type: T;
6
7
  data: D;
@@ -9,6 +10,7 @@ export declare const DragAndDropActionType: {
9
10
  readonly SET_DROP_TARGET: "SET_DROP_TARGET";
10
11
  readonly CLEAR_DROP_TARGET: "CLEAR_DROP_TARGET";
11
12
  readonly TOGGLE_DRAG_MENU: "TOGGLE_DRAG_MENU";
13
+ readonly UPDATE: "UPDATE";
12
14
  };
13
15
  export type DragAndDropSetDropTargetAction = DragAndDropAction<typeof DragAndDropActionType.SET_DROP_TARGET, {
14
16
  type: DropTargetType;
@@ -23,4 +25,5 @@ export type DragAndDropToggleDragMenuAction = DragAndDropAction<typeof DragAndDr
23
25
  direction: TableDirection;
24
26
  index: number;
25
27
  }>;
26
- export type DragAndDropPluginAction = DragAndDropSetDropTargetAction | DragAndDropClearDropTargetAction | DragAndDropToggleDragMenuAction;
28
+ export type DragAndDropUpdateAction = DragAndDropAction<typeof DragAndDropActionType.UPDATE, Partial<DragAndDropPluginState>>;
29
+ export type DragAndDropPluginAction = DragAndDropSetDropTargetAction | DragAndDropClearDropTargetAction | DragAndDropToggleDragMenuAction | DragAndDropUpdateAction;
@@ -4,3 +4,4 @@ export declare const DropTargetType: {
4
4
  readonly COLUMN: "column";
5
5
  };
6
6
  export type DropTargetType = (typeof DropTargetType)[keyof typeof DropTargetType];
7
+ export declare const DRAGGABLE_TABLE_NODE_SIZE_LIMIT = 20000;
@@ -1,3 +1,4 @@
1
1
  import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher) => SafePlugin<import("./types").DragAndDropPluginState>;
3
+ import type { DragAndDropPluginState } from './types';
4
+ export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher) => SafePlugin<DragAndDropPluginState>;
@@ -9,4 +9,5 @@ export interface DragAndDropPluginState {
9
9
  dragMenuDirection?: TableDirection;
10
10
  dragMenuIndex: number;
11
11
  isDragging: boolean;
12
+ canDrag: boolean;
12
13
  }
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  type HandleIconProps = {
3
+ canDrag: boolean;
3
4
  hasMergedCells: boolean;
4
5
  direction: 'row' | 'column';
5
6
  isDragMenuOpen: boolean | undefined;
@@ -14,6 +14,7 @@ type DragHandleProps = {
14
14
  onMouseOut?: MouseEventHandler;
15
15
  onMouseUp?: MouseEventHandler;
16
16
  editorView: EditorView;
17
+ canDrag?: boolean;
17
18
  };
18
- export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, }: DragHandleProps) => JSX.Element;
19
+ export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, canDrag, }: DragHandleProps) => JSX.Element;
19
20
  export {};
@@ -17,6 +17,7 @@ type DragMenuProps = {
17
17
  scrollableElement?: HTMLElement;
18
18
  pluginConfig?: PluginConfig;
19
19
  getEditorContainerWidth: GetEditorContainerWidth;
20
+ canDrag?: boolean;
20
21
  };
21
- export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, }: DragMenuProps) => jsx.JSX.Element | null;
22
+ export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, canDrag, }: DragMenuProps) => jsx.JSX.Element | null;
22
23
  export {};
@@ -15,9 +15,10 @@ export interface Props {
15
15
  index?: number;
16
16
  targetCellPosition?: number;
17
17
  getEditorContainerWidth: GetEditorContainerWidth;
18
+ canDrag?: boolean;
18
19
  }
19
20
  declare const FloatingDragMenu: {
20
- ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableRef, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, }: Props): JSX.Element | null;
21
+ ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableRef, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, canDrag, }: Props): JSX.Element | null;
21
22
  displayName: string;
22
23
  };
23
24
  export default FloatingDragMenu;
@@ -14,6 +14,7 @@ export interface ColumnControlsProps {
14
14
  colWidths?: (number | undefined)[];
15
15
  hasHeaderColumn?: boolean;
16
16
  isTableHovered?: boolean;
17
+ canDrag?: boolean;
17
18
  }
18
- export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, }: ColumnControlsProps) => JSX.Element;
19
+ export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, canDrag, }: ColumnControlsProps) => JSX.Element;
19
20
  export default ColumnControls;
@@ -22,6 +22,7 @@ export interface Props {
22
22
  ordering?: TableColumnOrdering;
23
23
  stickyHeader?: RowStickyState;
24
24
  isTableHovered?: boolean;
25
+ canDrag?: boolean;
25
26
  }
26
27
  export declare const TableFloatingColumnControls: React.FC<Props>;
27
28
  export default TableFloatingColumnControls;
@@ -13,6 +13,7 @@ type DragControlsProps = {
13
13
  isInDanger?: boolean;
14
14
  isResizing?: boolean;
15
15
  isTableHovered?: boolean;
16
+ canDrag?: boolean;
16
17
  hoverRows: (rows: number[], danger?: boolean) => void;
17
18
  selectRow: (row: number, expand: boolean) => void;
18
19
  updateCellHoverLocation: (rowIndex: number) => void;
@@ -18,6 +18,7 @@ export interface Props {
18
18
  isHeaderColumnEnabled?: boolean;
19
19
  isNumberColumnEnabled?: boolean;
20
20
  isDragAndDropEnabled?: boolean;
21
+ canDrag?: boolean;
21
22
  hasHeaderRow?: boolean;
22
23
  headerRowHeight?: number;
23
24
  hoveredRows?: number[];
@@ -7,4 +7,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
7
7
  icon?: React.ComponentType<IconProps>;
8
8
  keymap?: string;
9
9
  }
10
- export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, hasMergedCells: boolean, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
10
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.4.19",
3
+ "version": "5.4.20",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -0,0 +1,112 @@
1
+ import type { DocBuilder } from '@atlaskit/editor-common/types';
2
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
3
+ import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
+ import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
5
+ import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
6
+ import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
7
+ import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
8
+ import { widthPlugin } from '@atlaskit/editor-plugin-width';
9
+ // eslint-disable-next-line import/no-extraneous-dependencies
10
+ import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
11
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
12
+ import {
13
+ createProsemirrorEditorFactory,
14
+ Preset,
15
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
16
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
17
+ import {
18
+ doc,
19
+ p,
20
+ table,
21
+ td,
22
+ tdCursor,
23
+ tdEmpty,
24
+ tr,
25
+ } from '@atlaskit/editor-test-helpers/doc-builder';
26
+
27
+ import tablePlugin from '../../../../plugins/table';
28
+ import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT } from '../../../../plugins/table/pm-plugins/drag-and-drop/consts';
29
+ import { getPluginState } from '../../../../plugins/table/pm-plugins/drag-and-drop/plugin-factory';
30
+ import { pluginKey } from '../../../../plugins/table/pm-plugins/plugin-key';
31
+ import type { PluginConfig } from '../../../../plugins/table/types';
32
+
33
+ const tableOptions = {
34
+ allowNumberColumn: true,
35
+ allowHeaderRow: true,
36
+ allowHeaderColumn: true,
37
+ permittedLayouts: 'all',
38
+ allowColumnResizing: true,
39
+ stickyHeaders: true,
40
+ } as PluginConfig;
41
+
42
+ describe('drag and drop plugin', () => {
43
+ const createEditor = createProsemirrorEditorFactory();
44
+ const editor = (doc: DocBuilder) =>
45
+ createEditor({
46
+ doc,
47
+ attachTo: document.body,
48
+ preset: new Preset<LightEditorPlugin>()
49
+ .add([featureFlagsPlugin, {}])
50
+ .add([analyticsPlugin, {}])
51
+ .add(contentInsertionPlugin)
52
+ .add(widthPlugin)
53
+ .add(guidelinePlugin)
54
+ .add(selectionPlugin)
55
+ .add([
56
+ tablePlugin,
57
+ {
58
+ tableOptions,
59
+ dragAndDropEnabled: true,
60
+ },
61
+ ]),
62
+ pluginKey,
63
+ });
64
+
65
+ describe('when table is not selected', () => {
66
+ it('should reset table canDrag so by default tables are draggable', () => {
67
+ const { editorView } = editor(
68
+ doc(
69
+ p('{<>}Hello World'),
70
+ table()(tr(tdEmpty, tdEmpty), tr(tdEmpty, tdEmpty)),
71
+ ),
72
+ );
73
+
74
+ const { canDrag } = getPluginState(editorView.state);
75
+ expect(canDrag).toBe(true);
76
+ });
77
+ });
78
+
79
+ describe('when table is selected', () => {
80
+ it('should allow items to be draggable if table is within nodeSize limit', () => {
81
+ const { editorView } = editor(
82
+ // The nodeSize of an empty 2x2 is 22 so if i adjust the limit to be 1 under the max (ie. 23), then canDrag should be enabled.
83
+ doc(
84
+ table()(
85
+ tr(tdCursor, tdEmpty),
86
+ tr(
87
+ tdEmpty,
88
+ td()(p('-'.repeat(DRAGGABLE_TABLE_NODE_SIZE_LIMIT - 23))),
89
+ ),
90
+ ),
91
+ ),
92
+ );
93
+
94
+ const { canDrag } = getPluginState(editorView.state);
95
+ expect(canDrag).toBe(true);
96
+ });
97
+
98
+ it('should not allow items to be draggable if table is above nodeSize limit', () => {
99
+ const { editorView } = editor(
100
+ doc(
101
+ table()(
102
+ tr(tdCursor, tdEmpty),
103
+ tr(tdEmpty, td()(p('-'.repeat(DRAGGABLE_TABLE_NODE_SIZE_LIMIT)))),
104
+ ),
105
+ ),
106
+ );
107
+
108
+ const { canDrag } = getPluginState(editorView.state);
109
+ expect(canDrag).toBe(false);
110
+ });
111
+ });
112
+ });
@@ -494,6 +494,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
494
494
  direction={dragAndDropState?.dragMenuDirection}
495
495
  index={dragAndDropState?.dragMenuIndex}
496
496
  isOpen={!!dragAndDropState?.isDragMenuOpen && !isResizing}
497
+ canDrag={dragAndDropState?.canDrag}
497
498
  getEditorContainerWidth={defaultGetEditorContainerWidth}
498
499
  />
499
500
  )}