@atlaskit/editor-plugin-table 5.8.2 → 5.8.4

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 (46) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +17 -62
  3. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +153 -123
  4. package/dist/cjs/pm-plugins/drag-and-drop/utils/autoscrollers.js +53 -0
  5. package/dist/cjs/pm-plugins/drag-and-drop/utils/index.js +8 -1
  6. package/dist/cjs/ui/DragHandle/index.js +8 -3
  7. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
  8. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +103 -12
  9. package/dist/cjs/ui/FloatingDragMenu/index.js +2 -2
  10. package/dist/es2019/nodeviews/TableComponent.js +5 -55
  11. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +158 -124
  12. package/dist/es2019/pm-plugins/drag-and-drop/utils/autoscrollers.js +50 -0
  13. package/dist/es2019/pm-plugins/drag-and-drop/utils/index.js +2 -1
  14. package/dist/es2019/ui/DragHandle/index.js +10 -3
  15. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
  16. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +106 -11
  17. package/dist/es2019/ui/FloatingDragMenu/index.js +1 -1
  18. package/dist/esm/nodeviews/TableComponent.js +7 -52
  19. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +152 -122
  20. package/dist/esm/pm-plugins/drag-and-drop/utils/autoscrollers.js +47 -0
  21. package/dist/esm/pm-plugins/drag-and-drop/utils/index.js +2 -1
  22. package/dist/esm/ui/DragHandle/index.js +8 -3
  23. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
  24. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +102 -11
  25. package/dist/esm/ui/FloatingDragMenu/index.js +1 -1
  26. package/dist/types/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +7 -0
  27. package/dist/types/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  28. package/dist/types/ui/DragHandle/index.d.ts +5 -1
  29. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +7 -2
  30. package/dist/types/utils/drag-menu.d.ts +2 -1
  31. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +7 -0
  32. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  33. package/dist/types-ts4.5/ui/DragHandle/index.d.ts +5 -1
  34. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +7 -2
  35. package/dist/types-ts4.5/utils/drag-menu.d.ts +2 -1
  36. package/package.json +2 -2
  37. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +129 -105
  38. package/src/nodeviews/TableComponent.tsx +5 -49
  39. package/src/pm-plugins/drag-and-drop/plugin.ts +202 -157
  40. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +52 -0
  41. package/src/pm-plugins/drag-and-drop/utils/index.ts +2 -0
  42. package/src/ui/DragHandle/index.tsx +13 -2
  43. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +2 -2
  44. package/src/ui/FloatingDragMenu/DragMenu.tsx +137 -12
  45. package/src/ui/FloatingDragMenu/index.tsx +1 -1
  46. package/src/utils/drag-menu.ts +17 -1
@@ -4,12 +4,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.DragMenu = void 0;
7
+ exports.default = exports.DragMenu = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
10
  var _react = require("react");
11
11
  var _react2 = require("@emotion/react");
12
+ var _reactIntlNext = require("react-intl-next");
12
13
  var _analytics = require("@atlaskit/editor-common/analytics");
14
+ var _messages = require("@atlaskit/editor-common/messages");
13
15
  var _styles = require("@atlaskit/editor-common/styles");
14
16
  var _uiColor = require("@atlaskit/editor-common/ui-color");
15
17
  var _uiMenu = require("@atlaskit/editor-common/ui-menu");
@@ -34,22 +36,109 @@ var _styles2 = require("./styles");
34
36
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
35
37
  /** @jsx jsx */
36
38
 
39
+ var MapDragMenuOptionIdToMessage = {
40
+ add_row_above: {
41
+ message: _messages.tableMessages.addRowAbove,
42
+ plural: null
43
+ },
44
+ add_row_below: {
45
+ message: _messages.tableMessages.addRowBelow,
46
+ plural: null
47
+ },
48
+ add_column_left: {
49
+ message: _messages.tableMessages.addColumnLeft,
50
+ plural: null
51
+ },
52
+ add_column_right: {
53
+ message: _messages.tableMessages.addColumnRight,
54
+ plural: null
55
+ },
56
+ distribute_columns: {
57
+ message: _messages.tableMessages.distributeColumns,
58
+ plural: 'noOfCols'
59
+ },
60
+ clear_cells: {
61
+ message: _messages.tableMessages.clearCells,
62
+ plural: 'noOfCells'
63
+ },
64
+ delete_row: {
65
+ message: _messages.tableMessages.removeRows,
66
+ plural: 'noOfRows'
67
+ },
68
+ delete_column: {
69
+ message: _messages.tableMessages.removeColumns,
70
+ plural: 'noOfCols'
71
+ },
72
+ move_column_left: {
73
+ message: _messages.tableMessages.moveColumnLeft,
74
+ plural: 'noOfCols'
75
+ },
76
+ move_column_right: {
77
+ message: _messages.tableMessages.moveColumnRight,
78
+ plural: 'noOfCols'
79
+ },
80
+ move_row_up: {
81
+ message: _messages.tableMessages.moveRowUp,
82
+ plural: 'noOfRows'
83
+ },
84
+ move_row_down: {
85
+ message: _messages.tableMessages.moveRowDown,
86
+ plural: 'noOfRows'
87
+ },
88
+ sort_column_asc: {
89
+ message: _messages.tableMessages.sortColumnIncreasing,
90
+ plural: null
91
+ },
92
+ sort_column_desc: {
93
+ message: _messages.tableMessages.sortColumnDecreasing,
94
+ plural: null
95
+ }
96
+ };
37
97
  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']];
38
- var convertToDropdownItems = function convertToDropdownItems(dragMenuConfig) {
98
+ var convertToDropdownItems = function convertToDropdownItems(dragMenuConfig, formatMessage, selectionRect) {
39
99
  var menuItemsArr = (0, _toConsumableArray2.default)(Array(groupedDragMenuConfig.length)).map(function () {
40
100
  return [];
41
101
  });
42
102
  var menuCallback = {};
43
103
  dragMenuConfig.forEach(function (item) {
104
+ var _MapDragMenuOptionIdT;
44
105
  var menuGroupIndex = groupedDragMenuConfig.findIndex(function (group) {
45
106
  return group.includes(item.id);
46
107
  });
47
108
  if (menuGroupIndex === -1) {
48
109
  return;
49
110
  }
111
+ var isPlural = Boolean((_MapDragMenuOptionIdT = MapDragMenuOptionIdToMessage[item.id]) === null || _MapDragMenuOptionIdT === void 0 ? void 0 : _MapDragMenuOptionIdT.plural);
112
+ var plural = 0;
113
+ if (isPlural && selectionRect) {
114
+ var top = selectionRect.top,
115
+ bottom = selectionRect.bottom,
116
+ right = selectionRect.right,
117
+ left = selectionRect.left;
118
+ switch (MapDragMenuOptionIdToMessage[item.id].plural) {
119
+ case 'noOfCols':
120
+ {
121
+ plural = right - left;
122
+ break;
123
+ }
124
+ case 'noOfRows':
125
+ {
126
+ plural = bottom - top;
127
+ break;
128
+ }
129
+ case 'noOfCells':
130
+ {
131
+ plural = Math.max(right - left, bottom - top);
132
+ break;
133
+ }
134
+ }
135
+ }
136
+ var options = isPlural ? {
137
+ 0: plural
138
+ } : undefined;
50
139
  menuItemsArr[menuGroupIndex].push({
51
140
  key: item.id,
52
- content: item.title,
141
+ content: formatMessage(MapDragMenuOptionIdToMessage[item.id].message, options),
53
142
  value: {
54
143
  name: item.id
55
144
  },
@@ -59,7 +148,7 @@ var convertToDropdownItems = function convertToDropdownItems(dragMenuConfig) {
59
148
  display: 'flex'
60
149
  }
61
150
  }, (0, _react2.jsx)(item.icon, {
62
- label: item.title
151
+ label: formatMessage(MapDragMenuOptionIdToMessage[item.id].message, options)
63
152
  })) : undefined,
64
153
  elemAfter: item.keymap ? (0, _react2.jsx)("div", {
65
154
  css: _shortcut.shortcutStyle
@@ -93,7 +182,8 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
93
182
  getEditorContainerWidth = _ref.getEditorContainerWidth,
94
183
  canDrag = _ref.canDrag,
95
184
  editorAnalyticsAPI = _ref.editorAnalyticsAPI,
96
- pluginConfig = _ref.pluginConfig;
185
+ pluginConfig = _ref.pluginConfig,
186
+ formatMessage = _ref.intl.formatMessage;
97
187
  var state = editorView.state,
98
188
  dispatch = editorView.dispatch;
99
189
  var selection = state.selection;
@@ -108,7 +198,7 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
108
198
  var hasMergedCellsInTable = (0, _utils3.getMergedCellsPositions)(state.tr).length > 0;
109
199
  var allowBackgroundColor = (_pluginConfig$allowBa = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.allowBackgroundColor) !== null && _pluginConfig$allowBa !== void 0 ? _pluginConfig$allowBa : false;
110
200
  var dragMenuConfig = (0, _dragMenu.getDragMenuConfig)(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI);
111
- var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
201
+ var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig, formatMessage, selectionRect),
112
202
  menuItems = _convertToDropdownIte.menuItems,
113
203
  menuCallback = _convertToDropdownIte.menuCallback;
114
204
  var handleSubMenuRef = function handleSubMenuRef(ref) {
@@ -138,12 +228,12 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
138
228
  var node = targetCellPosition ? state.doc.nodeAt(targetCellPosition) : null;
139
229
  var background = (0, _editorPalette.hexToEditorBackgroundPaletteColor)((node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.background) || '#ffffff');
140
230
  return {
141
- content: 'Background color',
231
+ content: formatMessage(_messages.tableMessages.backgroundColor),
142
232
  value: {
143
233
  name: 'background'
144
234
  },
145
235
  elemBefore: (0, _react2.jsx)(_backgroundColor.default, {
146
- label: 'background color',
236
+ label: formatMessage(_messages.tableMessages.backgroundColor),
147
237
  size: "medium"
148
238
  }),
149
239
  elemAfter: (0, _react2.jsx)("div", {
@@ -178,7 +268,7 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
178
268
  };
179
269
  var createhHeaderRowColumnMenuItem = function createhHeaderRowColumnMenuItem(direction) {
180
270
  return direction === 'column' ? {
181
- content: 'Header column',
271
+ content: formatMessage(_messages.tableMessages.headerColumn),
182
272
  value: {
183
273
  name: 'header_column'
184
274
  },
@@ -190,7 +280,7 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
190
280
  isChecked: (0, _utils3.checkIfHeaderColumnEnabled)(selection)
191
281
  }))
192
282
  } : {
193
- content: 'Header row',
283
+ content: formatMessage(_messages.tableMessages.headerRow),
194
284
  value: {
195
285
  name: 'header_row'
196
286
  },
@@ -205,7 +295,7 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
205
295
  };
206
296
  var createRowNumbersMenuItem = function createRowNumbersMenuItem() {
207
297
  return {
208
- content: 'Row numbers',
298
+ content: formatMessage(_messages.tableMessages.rowNumbers),
209
299
  value: {
210
300
  name: 'row_numbers'
211
301
  },
@@ -333,4 +423,5 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
333
423
  hasSeparator: true
334
424
  }
335
425
  });
336
- };
426
+ };
427
+ var _default = exports.default = (0, _reactIntlNext.injectIntl)(DragMenu);
@@ -10,7 +10,7 @@ var _ui = require("@atlaskit/editor-common/ui");
10
10
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
11
11
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
12
12
  var _consts = require("../consts");
13
- var _DragMenu = require("./DragMenu");
13
+ var _DragMenu = _interopRequireDefault(require("./DragMenu"));
14
14
  var FloatingDragMenu = function FloatingDragMenu(_ref) {
15
15
  var mountPoint = _ref.mountPoint,
16
16
  boundariesElement = _ref.boundariesElement,
@@ -53,7 +53,7 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
53
53
  forcePlacement: true,
54
54
  offset: offset,
55
55
  stick: true
56
- }, /*#__PURE__*/_react.default.createElement(_DragMenu.DragMenu, {
56
+ }, /*#__PURE__*/_react.default.createElement(_DragMenu.default, {
57
57
  editorView: editorView,
58
58
  isOpen: isOpen,
59
59
  boundariesElement: boundariesElement,
@@ -10,10 +10,9 @@ import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
10
10
  import { MAX_BROWSER_SCROLLBAR_HEIGHT, akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
11
11
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
12
12
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
13
- import { autoScrollForElements, autoScrollWindowForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
14
- import { unsafeOverflowAutoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/element';
15
13
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/util/combine';
16
14
  import { autoSizeTable, clearHoverSelection } from '../commands';
15
+ import { autoScrollerFactory } from '../pm-plugins/drag-and-drop/utils';
17
16
  import { getPluginState } from '../pm-plugins/plugin-factory';
18
17
  import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
19
18
  import { META_KEYS } from '../pm-plugins/table-analytics';
@@ -21,7 +20,7 @@ import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scal
21
20
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
22
21
  import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
23
22
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
24
- import { dropTargetExtendedWidth, tableOverflowShadowWidth, tableOverflowShadowWidthWide } from '../ui/consts';
23
+ import { tableOverflowShadowWidth, tableOverflowShadowWidthWide } from '../ui/consts';
25
24
  import TableFloatingColumnControls from '../ui/TableFloatingColumnControls';
26
25
  import TableFloatingControls from '../ui/TableFloatingControls';
27
26
  import { containsHeaderRow, isTableNested, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns } from '../utils';
@@ -325,58 +324,9 @@ class TableComponent extends React.Component {
325
324
  }
326
325
  }
327
326
  if (isDragAndDropEnabled) {
328
- this.dragAndDropCleanupFn = combine(autoScrollForElements({
329
- element: this.wrapper,
330
- canScroll: ({
331
- source
332
- }) => {
333
- const {
334
- localId,
335
- type
336
- } = source.data;
337
- const node = getNode();
338
- return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
339
- }
340
- }), autoScrollWindowForElements({
341
- canScroll: ({
342
- source
343
- }) => {
344
- const {
345
- localId,
346
- type
347
- } = source.data;
348
- const node = getNode();
349
- return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-row';
350
- }
351
- }), unsafeOverflowAutoScrollForElements({
352
- element: this.wrapper,
353
- canScroll: ({
354
- source
355
- }) => {
356
- const {
357
- localId,
358
- type
359
- } = source.data;
360
- const node = getNode();
361
- return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
362
- },
363
- getOverflow: () => ({
364
- fromTopEdge: {
365
- top: dropTargetExtendedWidth,
366
- right: dropTargetExtendedWidth,
367
- left: dropTargetExtendedWidth
368
- },
369
- fromRightEdge: {
370
- right: dropTargetExtendedWidth,
371
- top: dropTargetExtendedWidth,
372
- bottom: dropTargetExtendedWidth
373
- },
374
- fromLeftEdge: {
375
- top: dropTargetExtendedWidth,
376
- left: dropTargetExtendedWidth,
377
- bottom: dropTargetExtendedWidth
378
- }
379
- })
327
+ this.dragAndDropCleanupFn = combine(...autoScrollerFactory({
328
+ tableWrapper: this.wrapper,
329
+ getNode
380
330
  }));
381
331
  }
382
332
  }
@@ -3,7 +3,9 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
5
  import { getCellsInRow } from '@atlaskit/editor-tables/utils';
6
+ import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
6
7
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
8
+ import { combine } from '@atlaskit/pragmatic-drag-and-drop/util/combine';
7
9
  import { findNearestCellIndexToPoint, hasMergedCellsInBetween } from '../../utils';
8
10
  import { getPluginState as getTablePluginState } from '../plugin-factory';
9
11
  import { pluginKey as tablePluginKey } from '../plugin-key';
@@ -15,6 +17,161 @@ import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT, DropTargetType } from './consts';
15
17
  import { createPluginState, getPluginState } from './plugin-factory';
16
18
  import { pluginKey } from './plugin-key';
17
19
  import { getDraggableDataFromEvent } from './utils/monitor';
20
+ const destroyFn = (editorView, editorAnalyticsAPI) => {
21
+ const editorPageScrollContainer = document.querySelector('.fabric-editor-popup-scroll-parent');
22
+ const rowAutoScrollers = editorPageScrollContainer ? [monitorForElements({
23
+ canMonitor({
24
+ source
25
+ }) {
26
+ const {
27
+ type
28
+ } = source.data;
29
+ return type === 'table-row';
30
+ },
31
+ onDragStart() {
32
+ // auto scroller doesn't work when scroll-behavior: smooth is set, this monitor temporarily removes it via inline styles
33
+ editorPageScrollContainer.style.setProperty('scroll-behavior', 'unset');
34
+ },
35
+ onDrop() {
36
+ // 'null' will remove the inline style
37
+ editorPageScrollContainer.style.setProperty('scroll-behavior', null);
38
+ }
39
+ }), autoScrollForElements({
40
+ element: editorPageScrollContainer,
41
+ canScroll: ({
42
+ source
43
+ }) => {
44
+ const {
45
+ type
46
+ } = source.data;
47
+ return type === 'table-row';
48
+ }
49
+ })] : [];
50
+ return combine(...rowAutoScrollers, monitorForElements({
51
+ canMonitor({
52
+ source
53
+ }) {
54
+ const {
55
+ type,
56
+ localId,
57
+ indexes
58
+ } = source.data;
59
+
60
+ // First; Perform any quick checks so we can abort early.
61
+ if (!indexes || !localId ||
62
+ // FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
63
+ // of more then 1 item.
64
+ indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
65
+ return false;
66
+ }
67
+ const {
68
+ tableNode
69
+ } = getTablePluginState(editorView.state);
70
+ // If the draggable localId is the same as the current selected table localId then we will allow the monitor
71
+ // watch for changes
72
+ return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
73
+ },
74
+ onDragStart: ({
75
+ location
76
+ }) => {
77
+ toggleDragMenu(false)(editorView.state, editorView.dispatch);
78
+ },
79
+ onDrag(event) {
80
+ const data = getDraggableDataFromEvent(event);
81
+ // If no data can be found then it's most like we do not want to perform any drag actions
82
+ if (!data) {
83
+ clearDropTarget()(editorView.state, editorView.dispatch);
84
+ return;
85
+ }
86
+
87
+ // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
88
+ // insert location as to where the draggable will most likely be go. For example;
89
+ const {
90
+ sourceType,
91
+ targetAdjustedIndex
92
+ } = data;
93
+ const dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
94
+ const hasMergedCells = hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], dropTargetType)(editorView.state.selection);
95
+ setDropTarget(dropTargetType, targetAdjustedIndex, hasMergedCells)(editorView.state, editorView.dispatch);
96
+ },
97
+ onDrop(event) {
98
+ var _cell$row, _cell$col;
99
+ const data = getDraggableDataFromEvent(event);
100
+
101
+ // On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
102
+ // over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
103
+ // at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
104
+ // it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
105
+ // then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
106
+ // triggered by this on drop event.
107
+ const {
108
+ hoveredCell
109
+ } = getTablePluginState(editorView.state);
110
+ const cell = findNearestCellIndexToPoint(event.location.current.input.clientX, event.location.current.input.clientY);
111
+ const tr = editorView.state.tr;
112
+ const action = {
113
+ type: 'HOVER_CELL',
114
+ data: {
115
+ hoveredCell: {
116
+ rowIndex: (_cell$row = cell === null || cell === void 0 ? void 0 : cell.row) !== null && _cell$row !== void 0 ? _cell$row : hoveredCell.rowIndex,
117
+ colIndex: (_cell$col = cell === null || cell === void 0 ? void 0 : cell.col) !== null && _cell$col !== void 0 ? _cell$col : hoveredCell.colIndex
118
+ }
119
+ }
120
+ };
121
+ tr.setMeta(tablePluginKey, action);
122
+
123
+ // If no data can be found then it's most like we do not want to perform any drop action
124
+ if (!data) {
125
+ var _event$source, _event$source$data, _event$source2, _event$source2$data;
126
+ // If we're able to determine the source type of the dropped element then we should report to analytics that
127
+ // the drop event was cancelled. Otherwise we will cancel silently.
128
+ if ((event === null || event === void 0 ? void 0 : (_event$source = event.source) === null || _event$source === void 0 ? void 0 : (_event$source$data = _event$source.data) === null || _event$source$data === void 0 ? void 0 : _event$source$data.type) === 'table-row' || (event === null || event === void 0 ? void 0 : (_event$source2 = event.source) === null || _event$source2 === void 0 ? void 0 : (_event$source2$data = _event$source2.data) === null || _event$source2$data === void 0 ? void 0 : _event$source2$data.type) === 'table-column') {
129
+ return clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
130
+ }
131
+ return clearDropTarget(tr)(editorView.state, editorView.dispatch);
132
+ }
133
+ const {
134
+ sourceType,
135
+ sourceIndexes,
136
+ targetIndex,
137
+ targetAdjustedIndex,
138
+ direction
139
+ } = data;
140
+
141
+ // When we drop on a target we will know the targets row/col index for certain,
142
+ if (sourceType === 'table-row') {
143
+ action.data.hoveredCell.rowIndex = targetIndex;
144
+ } else {
145
+ action.data.hoveredCell.colIndex = targetIndex;
146
+ }
147
+
148
+ // If the drop target index contains merged cells then we should not allow the drop to occur.
149
+ if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
150
+ clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
151
+ // This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
152
+ TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
153
+ return;
154
+ }
155
+ const [sourceIndex] = sourceIndexes;
156
+ requestAnimationFrame(() => {
157
+ moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
158
+
159
+ // force a colgroup update here, otherwise dropped columns don't have
160
+ // the correct width immediately after the drop
161
+ if (sourceType === 'table-column') {
162
+ const {
163
+ tableRef,
164
+ tableNode
165
+ } = getTablePluginState(editorView.state);
166
+ if (tableRef && tableNode) {
167
+ insertColgroupFromNode(tableRef, tableNode);
168
+ }
169
+ }
170
+ editorView.focus();
171
+ });
172
+ }
173
+ }));
174
+ };
18
175
  export const createPlugin = (dispatch, eventDispatcher, editorAnalyticsAPI) => {
19
176
  return new SafePlugin({
20
177
  state: createPluginState(dispatch, state => ({
@@ -93,130 +250,7 @@ export const createPlugin = (dispatch, eventDispatcher, editorAnalyticsAPI) => {
93
250
  },
94
251
  view: editorView => {
95
252
  return {
96
- destroy: monitorForElements({
97
- canMonitor({
98
- source
99
- }) {
100
- const {
101
- type,
102
- localId,
103
- indexes
104
- } = source.data;
105
-
106
- // First; Perform any quick checks so we can abort early.
107
- if (!indexes || !localId ||
108
- // FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
109
- // of more then 1 item.
110
- indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
111
- return false;
112
- }
113
- const {
114
- tableNode
115
- } = getTablePluginState(editorView.state);
116
- // If the draggable localId is the same as the current selected table localId then we will allow the monitor
117
- // watch for changes
118
- return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
119
- },
120
- onDragStart: ({
121
- location
122
- }) => {
123
- toggleDragMenu(false)(editorView.state, editorView.dispatch);
124
- },
125
- onDrag(event) {
126
- const data = getDraggableDataFromEvent(event);
127
- // If no data can be found then it's most like we do not want to perform any drag actions
128
- if (!data) {
129
- clearDropTarget()(editorView.state, editorView.dispatch);
130
- return;
131
- }
132
-
133
- // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
134
- // insert location as to where the draggable will most likely be go. For example;
135
- const {
136
- sourceType,
137
- targetAdjustedIndex
138
- } = data;
139
- const dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
140
- const hasMergedCells = hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], dropTargetType)(editorView.state.selection);
141
- setDropTarget(dropTargetType, targetAdjustedIndex, hasMergedCells)(editorView.state, editorView.dispatch);
142
- },
143
- onDrop(event) {
144
- var _cell$row, _cell$col;
145
- const data = getDraggableDataFromEvent(event);
146
-
147
- // On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
148
- // over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
149
- // at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
150
- // it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
151
- // then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
152
- // triggered by this on drop event.
153
- const {
154
- hoveredCell
155
- } = getTablePluginState(editorView.state);
156
- const cell = findNearestCellIndexToPoint(event.location.current.input.clientX, event.location.current.input.clientY);
157
- const tr = editorView.state.tr;
158
- const action = {
159
- type: 'HOVER_CELL',
160
- data: {
161
- hoveredCell: {
162
- rowIndex: (_cell$row = cell === null || cell === void 0 ? void 0 : cell.row) !== null && _cell$row !== void 0 ? _cell$row : hoveredCell.rowIndex,
163
- colIndex: (_cell$col = cell === null || cell === void 0 ? void 0 : cell.col) !== null && _cell$col !== void 0 ? _cell$col : hoveredCell.colIndex
164
- }
165
- }
166
- };
167
- tr.setMeta(tablePluginKey, action);
168
-
169
- // If no data can be found then it's most like we do not want to perform any drop action
170
- if (!data) {
171
- var _event$source, _event$source$data, _event$source2, _event$source2$data;
172
- // If we're able to determine the source type of the dropped element then we should report to analytics that
173
- // the drop event was cancelled. Otherwise we will cancel silently.
174
- if ((event === null || event === void 0 ? void 0 : (_event$source = event.source) === null || _event$source === void 0 ? void 0 : (_event$source$data = _event$source.data) === null || _event$source$data === void 0 ? void 0 : _event$source$data.type) === 'table-row' || (event === null || event === void 0 ? void 0 : (_event$source2 = event.source) === null || _event$source2 === void 0 ? void 0 : (_event$source2$data = _event$source2.data) === null || _event$source2$data === void 0 ? void 0 : _event$source2$data.type) === 'table-column') {
175
- return clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
176
- }
177
- return clearDropTarget(tr)(editorView.state, editorView.dispatch);
178
- }
179
- const {
180
- sourceType,
181
- sourceIndexes,
182
- targetIndex,
183
- targetAdjustedIndex,
184
- direction
185
- } = data;
186
-
187
- // When we drop on a target we will know the targets row/col index for certain,
188
- if (sourceType === 'table-row') {
189
- action.data.hoveredCell.rowIndex = targetIndex;
190
- } else {
191
- action.data.hoveredCell.colIndex = targetIndex;
192
- }
193
-
194
- // If the drop target index contains merged cells then we should not allow the drop to occur.
195
- if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
196
- clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
197
- // This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
198
- TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
199
- return;
200
- }
201
- const [sourceIndex] = sourceIndexes;
202
- requestAnimationFrame(() => {
203
- moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
204
-
205
- // force a colgroup update here, otherwise dropped columns don't have
206
- // the correct width immediately after the drop
207
- if (sourceType === 'table-column') {
208
- const {
209
- tableRef,
210
- tableNode
211
- } = getTablePluginState(editorView.state);
212
- if (tableRef && tableNode) {
213
- insertColgroupFromNode(tableRef, tableNode);
214
- }
215
- }
216
- editorView.focus();
217
- });
218
- }
219
- })
253
+ destroy: destroyFn(editorView, editorAnalyticsAPI)
220
254
  };
221
255
  },
222
256
  props: {
@@ -0,0 +1,50 @@
1
+ import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
2
+ import { unsafeOverflowAutoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/element';
3
+ import { dropTargetExtendedWidth } from '../../../ui/consts';
4
+ export const autoScrollerFactory = ({
5
+ tableWrapper,
6
+ getNode
7
+ }) => {
8
+ return [autoScrollForElements({
9
+ element: tableWrapper,
10
+ canScroll: ({
11
+ source
12
+ }) => {
13
+ const {
14
+ localId,
15
+ type
16
+ } = source.data;
17
+ const node = getNode();
18
+ return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
19
+ }
20
+ }), unsafeOverflowAutoScrollForElements({
21
+ element: tableWrapper,
22
+ canScroll: ({
23
+ source
24
+ }) => {
25
+ const {
26
+ localId,
27
+ type
28
+ } = source.data;
29
+ const node = getNode();
30
+ return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
31
+ },
32
+ getOverflow: () => ({
33
+ fromTopEdge: {
34
+ top: dropTargetExtendedWidth,
35
+ right: dropTargetExtendedWidth,
36
+ left: dropTargetExtendedWidth
37
+ },
38
+ fromRightEdge: {
39
+ right: dropTargetExtendedWidth,
40
+ top: dropTargetExtendedWidth,
41
+ bottom: dropTargetExtendedWidth
42
+ },
43
+ fromLeftEdge: {
44
+ top: dropTargetExtendedWidth,
45
+ left: dropTargetExtendedWidth,
46
+ bottom: dropTargetExtendedWidth
47
+ }
48
+ })
49
+ })];
50
+ };
@@ -1 +1,2 @@
1
- export { getDraggableDataFromEvent } from './monitor';
1
+ export { getDraggableDataFromEvent } from './monitor';
2
+ export { autoScrollerFactory } from './autoscrollers';