@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
@@ -1,6 +1,8 @@
1
1
  import React, { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import classnames from 'classnames';
3
3
  import ReactDOM from 'react-dom';
4
+ import { injectIntl } from 'react-intl-next';
5
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
6
  import { browser } from '@atlaskit/editor-common/utils';
5
7
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
6
8
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
@@ -9,7 +11,7 @@ import { TableCssClassName as ClassName } from '../../types';
9
11
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
10
12
  import { DragPreview } from '../DragPreview';
11
13
  import { HandleIconComponent } from './HandleIconComponent';
12
- export const DragHandle = ({
14
+ const DragHandleComponent = ({
13
15
  isDragMenuTarget,
14
16
  tableLocalId,
15
17
  direction = 'row',
@@ -23,7 +25,10 @@ export const DragHandle = ({
23
25
  onMouseUp,
24
26
  onClick,
25
27
  editorView,
26
- canDrag = false
28
+ canDrag = false,
29
+ intl: {
30
+ formatMessage
31
+ }
27
32
  }) => {
28
33
  const dragHandleDivRef = useRef(null);
29
34
  const [previewContainer, setPreviewContainer] = useState(null);
@@ -110,6 +115,7 @@ export const DragHandle = ({
110
115
  transform: direction === 'column' ? 'none' : 'rotate(90deg)'
111
116
  },
112
117
  "data-testid": "table-drag-handle-button",
118
+ "aria-label": formatMessage(direction === 'row' ? messages.rowDragHandle : messages.columnDragHandle),
113
119
  onMouseOver: onMouseOver,
114
120
  onMouseOut: onMouseOut,
115
121
  onMouseUp: e => {
@@ -128,4 +134,5 @@ export const DragHandle = ({
128
134
  width: previewWidth,
129
135
  height: previewHeight
130
136
  }), previewContainer));
131
- };
137
+ };
138
+ export const DragHandle = injectIntl(DragHandleComponent);
@@ -143,7 +143,7 @@ export class ContextualMenu extends Component {
143
143
  isDragAndDropEnabled
144
144
  } = getPluginState(editorView.state);
145
145
  return {
146
- content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addColumn : messages.insertColumn),
146
+ content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addColumnRight : messages.insertColumn),
147
147
  value: {
148
148
  name: 'insert_column'
149
149
  },
@@ -164,7 +164,7 @@ export class ContextualMenu extends Component {
164
164
  isDragAndDropEnabled
165
165
  } = getPluginState(editorView.state);
166
166
  return {
167
- content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addRow : messages.insertRow),
167
+ content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addRowBelow : messages.insertRow),
168
168
  value: {
169
169
  name: 'insert_row'
170
170
  },
@@ -2,7 +2,9 @@
2
2
  /** @jsx jsx */
3
3
  import { useState } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
+ import { injectIntl } from 'react-intl-next';
5
6
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
8
  import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
7
9
  import { backgroundPaletteTooltipMessages, cellBackgroundColorPalette, ColorPalette } from '@atlaskit/editor-common/ui-color';
8
10
  import { ArrowKeyNavigationType, DropdownMenu } from '@atlaskit/editor-common/ui-menu';
@@ -24,18 +26,107 @@ import { checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColum
24
26
  import { getDragMenuConfig } from '../../utils/drag-menu';
25
27
  import { dragMenuDropdownWidth } from '../consts';
26
28
  import { cellColourPreviewStyles, dragMenuBackgroundColorStyles, toggleStyles } from './styles';
29
+ const MapDragMenuOptionIdToMessage = {
30
+ add_row_above: {
31
+ message: messages.addRowAbove,
32
+ plural: null
33
+ },
34
+ add_row_below: {
35
+ message: messages.addRowBelow,
36
+ plural: null
37
+ },
38
+ add_column_left: {
39
+ message: messages.addColumnLeft,
40
+ plural: null
41
+ },
42
+ add_column_right: {
43
+ message: messages.addColumnRight,
44
+ plural: null
45
+ },
46
+ distribute_columns: {
47
+ message: messages.distributeColumns,
48
+ plural: 'noOfCols'
49
+ },
50
+ clear_cells: {
51
+ message: messages.clearCells,
52
+ plural: 'noOfCells'
53
+ },
54
+ delete_row: {
55
+ message: messages.removeRows,
56
+ plural: 'noOfRows'
57
+ },
58
+ delete_column: {
59
+ message: messages.removeColumns,
60
+ plural: 'noOfCols'
61
+ },
62
+ move_column_left: {
63
+ message: messages.moveColumnLeft,
64
+ plural: 'noOfCols'
65
+ },
66
+ move_column_right: {
67
+ message: messages.moveColumnRight,
68
+ plural: 'noOfCols'
69
+ },
70
+ move_row_up: {
71
+ message: messages.moveRowUp,
72
+ plural: 'noOfRows'
73
+ },
74
+ move_row_down: {
75
+ message: messages.moveRowDown,
76
+ plural: 'noOfRows'
77
+ },
78
+ sort_column_asc: {
79
+ message: messages.sortColumnIncreasing,
80
+ plural: null
81
+ },
82
+ sort_column_desc: {
83
+ message: messages.sortColumnDecreasing,
84
+ plural: null
85
+ }
86
+ };
27
87
  const groupedDragMenuConfig = [['add_row_above', 'add_row_below', 'add_column_left', 'add_column_right', 'distribute_columns', 'clear_cells', 'delete_row', 'delete_column'], ['move_column_left', 'move_column_right', 'move_row_up', 'move_row_down'], ['sort_column_asc', 'sort_column_desc']];
28
- const convertToDropdownItems = dragMenuConfig => {
88
+ const convertToDropdownItems = (dragMenuConfig, formatMessage, selectionRect) => {
29
89
  let menuItemsArr = [...Array(groupedDragMenuConfig.length)].map(() => []);
30
90
  let menuCallback = {};
31
91
  dragMenuConfig.forEach(item => {
92
+ var _MapDragMenuOptionIdT;
32
93
  const menuGroupIndex = groupedDragMenuConfig.findIndex(group => group.includes(item.id));
33
94
  if (menuGroupIndex === -1) {
34
95
  return;
35
96
  }
97
+ const isPlural = Boolean((_MapDragMenuOptionIdT = MapDragMenuOptionIdToMessage[item.id]) === null || _MapDragMenuOptionIdT === void 0 ? void 0 : _MapDragMenuOptionIdT.plural);
98
+ let plural = 0;
99
+ if (isPlural && selectionRect) {
100
+ const {
101
+ top,
102
+ bottom,
103
+ right,
104
+ left
105
+ } = selectionRect;
106
+ switch (MapDragMenuOptionIdToMessage[item.id].plural) {
107
+ case 'noOfCols':
108
+ {
109
+ plural = right - left;
110
+ break;
111
+ }
112
+ case 'noOfRows':
113
+ {
114
+ plural = bottom - top;
115
+ break;
116
+ }
117
+ case 'noOfCells':
118
+ {
119
+ plural = Math.max(right - left, bottom - top);
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ const options = isPlural ? {
125
+ 0: plural
126
+ } : undefined;
36
127
  menuItemsArr[menuGroupIndex].push({
37
128
  key: item.id,
38
- content: item.title,
129
+ content: formatMessage(MapDragMenuOptionIdToMessage[item.id].message, options),
39
130
  value: {
40
131
  name: item.id
41
132
  },
@@ -45,7 +136,7 @@ const convertToDropdownItems = dragMenuConfig => {
45
136
  display: 'flex'
46
137
  }
47
138
  }, jsx(item.icon, {
48
- label: item.title
139
+ label: formatMessage(MapDragMenuOptionIdToMessage[item.id].message, options)
49
140
  })) : undefined,
50
141
  elemAfter: item.keymap ? jsx("div", {
51
142
  css: shortcutStyle
@@ -77,7 +168,10 @@ export const DragMenu = ({
77
168
  getEditorContainerWidth,
78
169
  canDrag,
79
170
  editorAnalyticsAPI,
80
- pluginConfig
171
+ pluginConfig,
172
+ intl: {
173
+ formatMessage
174
+ }
81
175
  }) => {
82
176
  var _pluginConfig$allowBa;
83
177
  const {
@@ -98,7 +192,7 @@ export const DragMenu = ({
98
192
  const {
99
193
  menuItems,
100
194
  menuCallback
101
- } = convertToDropdownItems(dragMenuConfig);
195
+ } = convertToDropdownItems(dragMenuConfig, formatMessage, selectionRect);
102
196
  const handleSubMenuRef = ref => {
103
197
  const parent = closestElement(editorView.dom, '.fabric-editor-popup-scroll-parent');
104
198
  if (!(parent && ref)) {
@@ -130,12 +224,12 @@ export const DragMenu = ({
130
224
  const node = targetCellPosition ? state.doc.nodeAt(targetCellPosition) : null;
131
225
  const background = hexToEditorBackgroundPaletteColor((node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.background) || '#ffffff');
132
226
  return {
133
- content: 'Background color',
227
+ content: formatMessage(messages.backgroundColor),
134
228
  value: {
135
229
  name: 'background'
136
230
  },
137
231
  elemBefore: jsx(EditorBackgroundColorIcon, {
138
- label: 'background color',
232
+ label: formatMessage(messages.backgroundColor),
139
233
  size: "medium"
140
234
  }),
141
235
  elemAfter: jsx("div", {
@@ -170,7 +264,7 @@ export const DragMenu = ({
170
264
  };
171
265
  const createhHeaderRowColumnMenuItem = direction => {
172
266
  return direction === 'column' ? {
173
- content: 'Header column',
267
+ content: formatMessage(messages.headerColumn),
174
268
  value: {
175
269
  name: 'header_column'
176
270
  },
@@ -182,7 +276,7 @@ export const DragMenu = ({
182
276
  isChecked: checkIfHeaderColumnEnabled(selection)
183
277
  }))
184
278
  } : {
185
- content: 'Header row',
279
+ content: formatMessage(messages.headerRow),
186
280
  value: {
187
281
  name: 'header_row'
188
282
  },
@@ -197,7 +291,7 @@ export const DragMenu = ({
197
291
  };
198
292
  const createRowNumbersMenuItem = () => {
199
293
  return {
200
- content: 'Row numbers',
294
+ content: formatMessage(messages.rowNumbers),
201
295
  value: {
202
296
  name: 'row_numbers'
203
297
  },
@@ -331,4 +425,5 @@ export const DragMenu = ({
331
425
  hasSeparator: true
332
426
  }
333
427
  });
334
- };
428
+ };
429
+ export default injectIntl(DragMenu);
@@ -3,7 +3,7 @@ import { Popup } from '@atlaskit/editor-common/ui';
3
3
  import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
5
  import { dragMenuDropdownWidth } from '../consts';
6
- import { DragMenu } from './DragMenu';
6
+ import DragMenu from './DragMenu';
7
7
  const FloatingDragMenu = ({
8
8
  mountPoint,
9
9
  boundariesElement,
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
3
  import _createClass from "@babel/runtime/helpers/createClass";
3
4
  import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
@@ -20,10 +21,9 @@ import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
20
21
  import { MAX_BROWSER_SCROLLBAR_HEIGHT, akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
21
22
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
22
23
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
23
- import { autoScrollForElements, autoScrollWindowForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
24
- import { unsafeOverflowAutoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/element';
25
24
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/util/combine';
26
25
  import { autoSizeTable, clearHoverSelection } from '../commands';
26
+ import { autoScrollerFactory } from '../pm-plugins/drag-and-drop/utils';
27
27
  import { getPluginState } from '../pm-plugins/plugin-factory';
28
28
  import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
29
29
  import { META_KEYS } from '../pm-plugins/table-analytics';
@@ -31,7 +31,7 @@ import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scal
31
31
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
32
32
  import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
33
33
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
34
- import { dropTargetExtendedWidth, tableOverflowShadowWidth, tableOverflowShadowWidthWide } from '../ui/consts';
34
+ import { tableOverflowShadowWidth, tableOverflowShadowWidthWide } from '../ui/consts';
35
35
  import TableFloatingColumnControls from '../ui/TableFloatingColumnControls';
36
36
  import TableFloatingControls from '../ui/TableFloatingControls';
37
37
  import { containsHeaderRow, isTableNested, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns } from '../utils';
@@ -320,55 +320,10 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
320
320
  }
321
321
  }
322
322
  if (isDragAndDropEnabled) {
323
- this.dragAndDropCleanupFn = combine(autoScrollForElements({
324
- element: this.wrapper,
325
- canScroll: function canScroll(_ref) {
326
- var source = _ref.source;
327
- var _ref2 = source.data,
328
- localId = _ref2.localId,
329
- type = _ref2.type;
330
- var node = getNode();
331
- return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
332
- }
333
- }), autoScrollWindowForElements({
334
- canScroll: function canScroll(_ref3) {
335
- var source = _ref3.source;
336
- var _ref4 = source.data,
337
- localId = _ref4.localId,
338
- type = _ref4.type;
339
- var node = getNode();
340
- return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-row';
341
- }
342
- }), unsafeOverflowAutoScrollForElements({
343
- element: this.wrapper,
344
- canScroll: function canScroll(_ref5) {
345
- var source = _ref5.source;
346
- var _ref6 = source.data,
347
- localId = _ref6.localId,
348
- type = _ref6.type;
349
- var node = getNode();
350
- return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
351
- },
352
- getOverflow: function getOverflow() {
353
- return {
354
- fromTopEdge: {
355
- top: dropTargetExtendedWidth,
356
- right: dropTargetExtendedWidth,
357
- left: dropTargetExtendedWidth
358
- },
359
- fromRightEdge: {
360
- right: dropTargetExtendedWidth,
361
- top: dropTargetExtendedWidth,
362
- bottom: dropTargetExtendedWidth
363
- },
364
- fromLeftEdge: {
365
- top: dropTargetExtendedWidth,
366
- left: dropTargetExtendedWidth,
367
- bottom: dropTargetExtendedWidth
368
- }
369
- };
370
- }
371
- }));
323
+ this.dragAndDropCleanupFn = combine.apply(void 0, _toConsumableArray(autoScrollerFactory({
324
+ tableWrapper: this.wrapper,
325
+ getNode: getNode
326
+ })));
372
327
  }
373
328
  }
374
329
  if (allowColumnResizing) {
@@ -1,5 +1,5 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  import { INPUT_METHOD, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
@@ -7,7 +7,9 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
8
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
9
9
  import { getCellsInRow } from '@atlaskit/editor-tables/utils';
10
+ import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
10
11
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
12
+ import { combine } from '@atlaskit/pragmatic-drag-and-drop/util/combine';
11
13
  import { findNearestCellIndexToPoint, hasMergedCellsInBetween } from '../../utils';
12
14
  import { getPluginState as getTablePluginState } from '../plugin-factory';
13
15
  import { pluginKey as tablePluginKey } from '../plugin-key';
@@ -19,6 +21,148 @@ import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT, DropTargetType } from './consts';
19
21
  import { createPluginState, getPluginState } from './plugin-factory';
20
22
  import { pluginKey } from './plugin-key';
21
23
  import { getDraggableDataFromEvent } from './utils/monitor';
24
+ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
25
+ var editorPageScrollContainer = document.querySelector('.fabric-editor-popup-scroll-parent');
26
+ var rowAutoScrollers = editorPageScrollContainer ? [monitorForElements({
27
+ canMonitor: function canMonitor(_ref) {
28
+ var source = _ref.source;
29
+ var _ref2 = source.data,
30
+ type = _ref2.type;
31
+ return type === 'table-row';
32
+ },
33
+ onDragStart: function onDragStart() {
34
+ // auto scroller doesn't work when scroll-behavior: smooth is set, this monitor temporarily removes it via inline styles
35
+ editorPageScrollContainer.style.setProperty('scroll-behavior', 'unset');
36
+ },
37
+ onDrop: function onDrop() {
38
+ // 'null' will remove the inline style
39
+ editorPageScrollContainer.style.setProperty('scroll-behavior', null);
40
+ }
41
+ }), autoScrollForElements({
42
+ element: editorPageScrollContainer,
43
+ canScroll: function canScroll(_ref3) {
44
+ var source = _ref3.source;
45
+ var _ref4 = source.data,
46
+ type = _ref4.type;
47
+ return type === 'table-row';
48
+ }
49
+ })] : [];
50
+ return combine.apply(void 0, rowAutoScrollers.concat([monitorForElements({
51
+ canMonitor: function canMonitor(_ref5) {
52
+ var source = _ref5.source;
53
+ var _ref6 = source.data,
54
+ type = _ref6.type,
55
+ localId = _ref6.localId,
56
+ indexes = _ref6.indexes;
57
+
58
+ // First; Perform any quick checks so we can abort early.
59
+ if (!indexes || !localId ||
60
+ // FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
61
+ // of more then 1 item.
62
+ indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
63
+ return false;
64
+ }
65
+ var _getTablePluginState = getTablePluginState(editorView.state),
66
+ tableNode = _getTablePluginState.tableNode;
67
+ // If the draggable localId is the same as the current selected table localId then we will allow the monitor
68
+ // watch for changes
69
+ return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
70
+ },
71
+ onDragStart: function onDragStart(_ref7) {
72
+ var location = _ref7.location;
73
+ toggleDragMenu(false)(editorView.state, editorView.dispatch);
74
+ },
75
+ onDrag: function onDrag(event) {
76
+ var data = getDraggableDataFromEvent(event);
77
+ // If no data can be found then it's most like we do not want to perform any drag actions
78
+ if (!data) {
79
+ clearDropTarget()(editorView.state, editorView.dispatch);
80
+ return;
81
+ }
82
+
83
+ // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
84
+ // insert location as to where the draggable will most likely be go. For example;
85
+ var sourceType = data.sourceType,
86
+ targetAdjustedIndex = data.targetAdjustedIndex;
87
+ var dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
88
+ var hasMergedCells = hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], dropTargetType)(editorView.state.selection);
89
+ setDropTarget(dropTargetType, targetAdjustedIndex, hasMergedCells)(editorView.state, editorView.dispatch);
90
+ },
91
+ onDrop: function onDrop(event) {
92
+ var _cell$row, _cell$col;
93
+ var data = getDraggableDataFromEvent(event);
94
+
95
+ // On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
96
+ // over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
97
+ // at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
98
+ // it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
99
+ // then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
100
+ // triggered by this on drop event.
101
+ var _getTablePluginState2 = getTablePluginState(editorView.state),
102
+ hoveredCell = _getTablePluginState2.hoveredCell;
103
+ var cell = findNearestCellIndexToPoint(event.location.current.input.clientX, event.location.current.input.clientY);
104
+ var tr = editorView.state.tr;
105
+ var action = {
106
+ type: 'HOVER_CELL',
107
+ data: {
108
+ hoveredCell: {
109
+ rowIndex: (_cell$row = cell === null || cell === void 0 ? void 0 : cell.row) !== null && _cell$row !== void 0 ? _cell$row : hoveredCell.rowIndex,
110
+ colIndex: (_cell$col = cell === null || cell === void 0 ? void 0 : cell.col) !== null && _cell$col !== void 0 ? _cell$col : hoveredCell.colIndex
111
+ }
112
+ }
113
+ };
114
+ tr.setMeta(tablePluginKey, action);
115
+
116
+ // If no data can be found then it's most like we do not want to perform any drop action
117
+ if (!data) {
118
+ var _event$source, _event$source2;
119
+ // If we're able to determine the source type of the dropped element then we should report to analytics that
120
+ // the drop event was cancelled. Otherwise we will cancel silently.
121
+ if ((event === null || event === void 0 || (_event$source = event.source) === null || _event$source === void 0 || (_event$source = _event$source.data) === null || _event$source === void 0 ? void 0 : _event$source.type) === 'table-row' || (event === null || event === void 0 || (_event$source2 = event.source) === null || _event$source2 === void 0 || (_event$source2 = _event$source2.data) === null || _event$source2 === void 0 ? void 0 : _event$source2.type) === 'table-column') {
122
+ return clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
123
+ }
124
+ return clearDropTarget(tr)(editorView.state, editorView.dispatch);
125
+ }
126
+ var sourceType = data.sourceType,
127
+ sourceIndexes = data.sourceIndexes,
128
+ targetIndex = data.targetIndex,
129
+ targetAdjustedIndex = data.targetAdjustedIndex,
130
+ direction = data.direction;
131
+
132
+ // When we drop on a target we will know the targets row/col index for certain,
133
+ if (sourceType === 'table-row') {
134
+ action.data.hoveredCell.rowIndex = targetIndex;
135
+ } else {
136
+ action.data.hoveredCell.colIndex = targetIndex;
137
+ }
138
+
139
+ // If the drop target index contains merged cells then we should not allow the drop to occur.
140
+ if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
141
+ clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
142
+ // This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
143
+ TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
144
+ return;
145
+ }
146
+ var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
147
+ sourceIndex = _sourceIndexes[0];
148
+ requestAnimationFrame(function () {
149
+ moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
150
+
151
+ // force a colgroup update here, otherwise dropped columns don't have
152
+ // the correct width immediately after the drop
153
+ if (sourceType === 'table-column') {
154
+ var _getTablePluginState3 = getTablePluginState(editorView.state),
155
+ tableRef = _getTablePluginState3.tableRef,
156
+ tableNode = _getTablePluginState3.tableNode;
157
+ if (tableRef && tableNode) {
158
+ insertColgroupFromNode(tableRef, tableNode);
159
+ }
160
+ }
161
+ editorView.focus();
162
+ });
163
+ }
164
+ })]));
165
+ };
22
166
  export var createPlugin = function createPlugin(dispatch, eventDispatcher, editorAnalyticsAPI) {
23
167
  return new SafePlugin({
24
168
  state: createPluginState(dispatch, function (state) {
@@ -34,12 +178,12 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher, edito
34
178
  }),
35
179
  key: pluginKey,
36
180
  appendTransaction: function appendTransaction(transactions, oldState, newState) {
37
- var _getTablePluginState = getTablePluginState(oldState),
38
- oldTargetCellPosition = _getTablePluginState.targetCellPosition,
39
- oldTableNode = _getTablePluginState.tableNode;
40
- var _getTablePluginState2 = getTablePluginState(newState),
41
- newTargetCellPosition = _getTablePluginState2.targetCellPosition,
42
- newTableNode = _getTablePluginState2.tableNode;
181
+ var _getTablePluginState4 = getTablePluginState(oldState),
182
+ oldTargetCellPosition = _getTablePluginState4.targetCellPosition,
183
+ oldTableNode = _getTablePluginState4.tableNode;
184
+ var _getTablePluginState5 = getTablePluginState(newState),
185
+ newTargetCellPosition = _getTablePluginState5.targetCellPosition,
186
+ newTableNode = _getTablePluginState5.tableNode;
43
187
  var _getPluginState = getPluginState(newState),
44
188
  isDragMenuOpen = _getPluginState.isDragMenuOpen,
45
189
  dragMenuIndex = _getPluginState.dragMenuIndex,
@@ -93,121 +237,7 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher, edito
93
237
  },
94
238
  view: function view(editorView) {
95
239
  return {
96
- destroy: monitorForElements({
97
- canMonitor: function canMonitor(_ref) {
98
- var source = _ref.source;
99
- var _ref2 = source.data,
100
- type = _ref2.type,
101
- localId = _ref2.localId,
102
- indexes = _ref2.indexes;
103
-
104
- // First; Perform any quick checks so we can abort early.
105
- if (!indexes || !localId ||
106
- // FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
107
- // of more then 1 item.
108
- indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
109
- return false;
110
- }
111
- var _getTablePluginState3 = getTablePluginState(editorView.state),
112
- tableNode = _getTablePluginState3.tableNode;
113
- // If the draggable localId is the same as the current selected table localId then we will allow the monitor
114
- // watch for changes
115
- return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
116
- },
117
- onDragStart: function onDragStart(_ref3) {
118
- var location = _ref3.location;
119
- toggleDragMenu(false)(editorView.state, editorView.dispatch);
120
- },
121
- onDrag: function onDrag(event) {
122
- var data = getDraggableDataFromEvent(event);
123
- // If no data can be found then it's most like we do not want to perform any drag actions
124
- if (!data) {
125
- clearDropTarget()(editorView.state, editorView.dispatch);
126
- return;
127
- }
128
-
129
- // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
130
- // insert location as to where the draggable will most likely be go. For example;
131
- var sourceType = data.sourceType,
132
- targetAdjustedIndex = data.targetAdjustedIndex;
133
- var dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
134
- var hasMergedCells = hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], dropTargetType)(editorView.state.selection);
135
- setDropTarget(dropTargetType, targetAdjustedIndex, hasMergedCells)(editorView.state, editorView.dispatch);
136
- },
137
- onDrop: function onDrop(event) {
138
- var _cell$row, _cell$col;
139
- var data = getDraggableDataFromEvent(event);
140
-
141
- // On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
142
- // over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
143
- // at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
144
- // it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
145
- // then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
146
- // triggered by this on drop event.
147
- var _getTablePluginState4 = getTablePluginState(editorView.state),
148
- hoveredCell = _getTablePluginState4.hoveredCell;
149
- var cell = findNearestCellIndexToPoint(event.location.current.input.clientX, event.location.current.input.clientY);
150
- var tr = editorView.state.tr;
151
- var action = {
152
- type: 'HOVER_CELL',
153
- data: {
154
- hoveredCell: {
155
- rowIndex: (_cell$row = cell === null || cell === void 0 ? void 0 : cell.row) !== null && _cell$row !== void 0 ? _cell$row : hoveredCell.rowIndex,
156
- colIndex: (_cell$col = cell === null || cell === void 0 ? void 0 : cell.col) !== null && _cell$col !== void 0 ? _cell$col : hoveredCell.colIndex
157
- }
158
- }
159
- };
160
- tr.setMeta(tablePluginKey, action);
161
-
162
- // If no data can be found then it's most like we do not want to perform any drop action
163
- if (!data) {
164
- var _event$source, _event$source2;
165
- // If we're able to determine the source type of the dropped element then we should report to analytics that
166
- // the drop event was cancelled. Otherwise we will cancel silently.
167
- if ((event === null || event === void 0 || (_event$source = event.source) === null || _event$source === void 0 || (_event$source = _event$source.data) === null || _event$source === void 0 ? void 0 : _event$source.type) === 'table-row' || (event === null || event === void 0 || (_event$source2 = event.source) === null || _event$source2 === void 0 || (_event$source2 = _event$source2.data) === null || _event$source2 === void 0 ? void 0 : _event$source2.type) === 'table-column') {
168
- return clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
169
- }
170
- return clearDropTarget(tr)(editorView.state, editorView.dispatch);
171
- }
172
- var sourceType = data.sourceType,
173
- sourceIndexes = data.sourceIndexes,
174
- targetIndex = data.targetIndex,
175
- targetAdjustedIndex = data.targetAdjustedIndex,
176
- direction = data.direction;
177
-
178
- // When we drop on a target we will know the targets row/col index for certain,
179
- if (sourceType === 'table-row') {
180
- action.data.hoveredCell.rowIndex = targetIndex;
181
- } else {
182
- action.data.hoveredCell.colIndex = targetIndex;
183
- }
184
-
185
- // If the drop target index contains merged cells then we should not allow the drop to occur.
186
- if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
187
- clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
188
- // This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
189
- TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
190
- return;
191
- }
192
- var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
193
- sourceIndex = _sourceIndexes[0];
194
- requestAnimationFrame(function () {
195
- moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
196
-
197
- // force a colgroup update here, otherwise dropped columns don't have
198
- // the correct width immediately after the drop
199
- if (sourceType === 'table-column') {
200
- var _getTablePluginState5 = getTablePluginState(editorView.state),
201
- tableRef = _getTablePluginState5.tableRef,
202
- tableNode = _getTablePluginState5.tableNode;
203
- if (tableRef && tableNode) {
204
- insertColgroupFromNode(tableRef, tableNode);
205
- }
206
- }
207
- editorView.focus();
208
- });
209
- }
210
- })
240
+ destroy: destroyFn(editorView, editorAnalyticsAPI)
211
241
  };
212
242
  },
213
243
  props: {