@atlaskit/editor-plugin-table 5.8.1 → 5.8.3

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 (27) hide show
  1. package/CHANGELOG.md +12 -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/FloatingInsertButton/InsertButton.js +1 -1
  7. package/dist/es2019/nodeviews/TableComponent.js +5 -55
  8. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +158 -124
  9. package/dist/es2019/pm-plugins/drag-and-drop/utils/autoscrollers.js +50 -0
  10. package/dist/es2019/pm-plugins/drag-and-drop/utils/index.js +2 -1
  11. package/dist/es2019/ui/FloatingInsertButton/InsertButton.js +1 -1
  12. package/dist/esm/nodeviews/TableComponent.js +7 -52
  13. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +152 -122
  14. package/dist/esm/pm-plugins/drag-and-drop/utils/autoscrollers.js +47 -0
  15. package/dist/esm/pm-plugins/drag-and-drop/utils/index.js +2 -1
  16. package/dist/esm/ui/FloatingInsertButton/InsertButton.js +1 -1
  17. package/dist/types/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +7 -0
  18. package/dist/types/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  19. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +7 -0
  20. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  21. package/package.json +1 -1
  22. package/src/__tests__/visual-regression/sticky-header.ts +1 -2
  23. package/src/nodeviews/TableComponent.tsx +5 -49
  24. package/src/pm-plugins/drag-and-drop/plugin.ts +202 -157
  25. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +52 -0
  26. package/src/pm-plugins/drag-and-drop/utils/index.ts +2 -0
  27. package/src/ui/FloatingInsertButton/InsertButton.tsx +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.8.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#66462](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66462) [`241abc835673`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/241abc835673) - Add autoscroll to editor page to fix table drag and drop
8
+
9
+ ## 5.8.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#66678](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66678) [`dcfaed76166a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/dcfaed76166a) - Update insert row / column plus icon for table
14
+
3
15
  ## 5.8.1
4
16
 
5
17
  ### Patch Changes
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
8
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
11
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
@@ -23,21 +24,20 @@ var _utils = require("@atlaskit/editor-common/utils");
23
24
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
24
25
  var _utils2 = require("@atlaskit/editor-tables/utils");
25
26
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
26
- var _element = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/element");
27
- var _element2 = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/element");
28
27
  var _combine = require("@atlaskit/pragmatic-drag-and-drop/util/combine");
29
28
  var _commands = require("../commands");
29
+ var _utils3 = require("../pm-plugins/drag-and-drop/utils");
30
30
  var _pluginFactory = require("../pm-plugins/plugin-factory");
31
31
  var _stickyHeaders = require("../pm-plugins/sticky-headers");
32
32
  var _tableAnalytics = require("../pm-plugins/table-analytics");
33
- var _utils3 = require("../pm-plugins/table-resizing/utils");
33
+ var _utils4 = require("../pm-plugins/table-resizing/utils");
34
34
  var _colgroup = require("../pm-plugins/table-resizing/utils/colgroup");
35
35
  var _dom = require("../pm-plugins/table-resizing/utils/dom");
36
36
  var _types = require("../types");
37
37
  var _consts = require("../ui/consts");
38
38
  var _TableFloatingColumnControls = _interopRequireDefault(require("../ui/TableFloatingColumnControls"));
39
39
  var _TableFloatingControls = _interopRequireDefault(require("../ui/TableFloatingControls"));
40
- var _utils4 = require("../utils");
40
+ var _utils5 = require("../utils");
41
41
  var _ExternalDropTargets = require("./ExternalDropTargets");
42
42
  var _OverflowShadowsObserver = require("./OverflowShadowsObserver");
43
43
  var _TableContainer = require("./TableContainer");
@@ -125,14 +125,14 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
125
125
  var prevNode = _this.node;
126
126
  var node = getNode();
127
127
  var prevAttrs = prevNode.attrs;
128
- var isNested = (0, _utils4.isTableNested)(_this.props.view.state, _this.props.getPos());
128
+ var isNested = (0, _utils5.isTableNested)(_this.props.view.state, _this.props.getPos());
129
129
  // We only consider a layout change valid if it's done outside of an autoSize.
130
130
  var layoutChanged = prevAttrs.layout !== node.attrs.layout && prevAttrs.__autoSize === node.attrs.__autoSize;
131
131
  var parentWidth = _this.getParentNodeWidth();
132
132
  var parentWidthChanged = parentWidth && parentWidth !== _this.state.parentWidth;
133
133
  var layoutSize = _this.tableNodeLayoutSize(node, containerWidth.width, options);
134
134
  var hasNumberedColumnChanged = prevAttrs.isNumberColumnEnabled !== node.attrs.isNumberColumnEnabled;
135
- var noOfColumnsChanged = (0, _utils4.tablesHaveDifferentNoOfColumns)(node, prevNode);
135
+ var noOfColumnsChanged = (0, _utils5.tablesHaveDifferentNoOfColumns)(node, prevNode);
136
136
  if (
137
137
  // Breakout mode/layout changed
138
138
  layoutChanged ||
@@ -186,7 +186,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
186
186
  var domAtPos = view.domAtPos.bind(view);
187
187
  var width = containerWidth.width;
188
188
  _this.scaleTableDebounced.cancel();
189
- var tr = (0, _utils3.scaleTable)(_this.table, _objectSpread(_objectSpread({}, scaleOptions), {}, {
189
+ var tr = (0, _utils4.scaleTable)(_this.table, _objectSpread(_objectSpread({}, scaleOptions), {}, {
190
190
  node: node,
191
191
  prevNode: _this.node || node,
192
192
  start: pos + 1,
@@ -274,7 +274,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
274
274
  });
275
275
  });
276
276
  (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "tableNodeLayoutSize", function (node, containerWidth, options) {
277
- return (0, _utils3.getLayoutSize)(node.attrs.layout, containerWidth || _this.props.containerWidth.width, options || _this.props.options || {});
277
+ return (0, _utils4.getLayoutSize)(node.attrs.layout, containerWidth || _this.props.containerWidth.width, options || _this.props.options || {});
278
278
  });
279
279
  (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "scaleTableDebounced", (0, _rafSchd.default)(_this.scaleTable));
280
280
  (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "handleTableResizingDebounced", (0, _rafSchd.default)(_this.handleTableResizing));
@@ -327,55 +327,10 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
327
327
  }
328
328
  }
329
329
  if (isDragAndDropEnabled) {
330
- this.dragAndDropCleanupFn = (0, _combine.combine)((0, _element.autoScrollForElements)({
331
- element: this.wrapper,
332
- canScroll: function canScroll(_ref) {
333
- var source = _ref.source;
334
- var _ref2 = source.data,
335
- localId = _ref2.localId,
336
- type = _ref2.type;
337
- var node = getNode();
338
- return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
339
- }
340
- }), (0, _element.autoScrollWindowForElements)({
341
- canScroll: function canScroll(_ref3) {
342
- var source = _ref3.source;
343
- var _ref4 = source.data,
344
- localId = _ref4.localId,
345
- type = _ref4.type;
346
- var node = getNode();
347
- return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-row';
348
- }
349
- }), (0, _element2.unsafeOverflowAutoScrollForElements)({
350
- element: this.wrapper,
351
- canScroll: function canScroll(_ref5) {
352
- var source = _ref5.source;
353
- var _ref6 = source.data,
354
- localId = _ref6.localId,
355
- type = _ref6.type;
356
- var node = getNode();
357
- return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
358
- },
359
- getOverflow: function getOverflow() {
360
- return {
361
- fromTopEdge: {
362
- top: _consts.dropTargetExtendedWidth,
363
- right: _consts.dropTargetExtendedWidth,
364
- left: _consts.dropTargetExtendedWidth
365
- },
366
- fromRightEdge: {
367
- right: _consts.dropTargetExtendedWidth,
368
- top: _consts.dropTargetExtendedWidth,
369
- bottom: _consts.dropTargetExtendedWidth
370
- },
371
- fromLeftEdge: {
372
- top: _consts.dropTargetExtendedWidth,
373
- left: _consts.dropTargetExtendedWidth,
374
- bottom: _consts.dropTargetExtendedWidth
375
- }
376
- };
377
- }
378
- }));
330
+ this.dragAndDropCleanupFn = _combine.combine.apply(void 0, (0, _toConsumableArray2.default)((0, _utils3.autoScrollerFactory)({
331
+ tableWrapper: this.wrapper,
332
+ getNode: getNode
333
+ })));
379
334
  }
380
335
  }
381
336
  if (allowColumnResizing) {
@@ -471,11 +426,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
471
426
  // If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
472
427
  // re-draw colgroup.
473
428
  var previousTable = this.node;
474
- if ((0, _utils4.tablesHaveDifferentColumnWidths)(currentTable, previousTable) || (0, _utils4.tablesHaveDifferentNoOfColumns)(currentTable, previousTable)) {
429
+ if ((0, _utils5.tablesHaveDifferentColumnWidths)(currentTable, previousTable) || (0, _utils5.tablesHaveDifferentNoOfColumns)(currentTable, previousTable)) {
475
430
  var _view = this.props.view;
476
- var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || (0, _utils4.tablesHaveDifferentNoOfColumns)(currentTable, previousTable) && isResizing;
431
+ var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || (0, _utils5.tablesHaveDifferentNoOfColumns)(currentTable, previousTable) && isResizing;
477
432
  if (shouldRecreateResizeCols) {
478
- (0, _utils3.insertColgroupFromNode)(this.table, currentTable);
433
+ (0, _utils4.insertColgroupFromNode)(this.table, currentTable);
479
434
  }
480
435
  (0, _dom.updateControls)()(_view.state);
481
436
  }
@@ -537,7 +492,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
537
492
  isTableHovered = _getPluginState2.isTableHovered;
538
493
  var tableRef = this.table || undefined;
539
494
  var headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
540
- var hasHeaderRow = (0, _utils4.containsHeaderRow)(node);
495
+ var hasHeaderRow = (0, _utils5.containsHeaderRow)(node);
541
496
  var rowControls = /*#__PURE__*/_react.default.createElement(_TableFloatingControls.default, {
542
497
  editorView: view,
543
498
  tableRef: tableRef,
@@ -602,7 +557,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
602
557
  } catch (e) {
603
558
  tablePos = undefined;
604
559
  }
605
- var isNested = (0, _utils4.isTableNested)(view.state, tablePos);
560
+ var isNested = (0, _utils5.isTableNested)(view.state, tablePos);
606
561
  var topStickyShadowPosition = isDragAndDropEnabled ? this.state.stickyHeader && this.state.stickyHeader.top + this.state.stickyHeader.padding + 2 : this.state.stickyHeader && this.state.stickyHeader.top + this.state.stickyHeader.padding + shadowPadding + 2;
607
562
  var _getEditorFeatureFlag3 = getEditorFeatureFlags(),
608
563
  stickyScrollbar = _getEditorFeatureFlag3.stickyScrollbar,
@@ -5,14 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createPlugin = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
11
11
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
12
  var _view = require("@atlaskit/editor-prosemirror/view");
13
13
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
14
14
  var _utils = require("@atlaskit/editor-tables/utils");
15
- var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
15
+ var _element = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/element");
16
+ var _element2 = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
17
+ var _combine = require("@atlaskit/pragmatic-drag-and-drop/util/combine");
16
18
  var _utils2 = require("../../utils");
17
19
  var _pluginFactory = require("../plugin-factory");
18
20
  var _pluginKey = require("../plugin-key");
@@ -26,6 +28,148 @@ var _pluginKey2 = require("./plugin-key");
26
28
  var _monitor = require("./utils/monitor");
27
29
  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; }
28
30
  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) { (0, _defineProperty2.default)(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; }
31
+ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
32
+ var editorPageScrollContainer = document.querySelector('.fabric-editor-popup-scroll-parent');
33
+ var rowAutoScrollers = editorPageScrollContainer ? [(0, _element2.monitorForElements)({
34
+ canMonitor: function canMonitor(_ref) {
35
+ var source = _ref.source;
36
+ var _ref2 = source.data,
37
+ type = _ref2.type;
38
+ return type === 'table-row';
39
+ },
40
+ onDragStart: function onDragStart() {
41
+ // auto scroller doesn't work when scroll-behavior: smooth is set, this monitor temporarily removes it via inline styles
42
+ editorPageScrollContainer.style.setProperty('scroll-behavior', 'unset');
43
+ },
44
+ onDrop: function onDrop() {
45
+ // 'null' will remove the inline style
46
+ editorPageScrollContainer.style.setProperty('scroll-behavior', null);
47
+ }
48
+ }), (0, _element.autoScrollForElements)({
49
+ element: editorPageScrollContainer,
50
+ canScroll: function canScroll(_ref3) {
51
+ var source = _ref3.source;
52
+ var _ref4 = source.data,
53
+ type = _ref4.type;
54
+ return type === 'table-row';
55
+ }
56
+ })] : [];
57
+ return _combine.combine.apply(void 0, rowAutoScrollers.concat([(0, _element2.monitorForElements)({
58
+ canMonitor: function canMonitor(_ref5) {
59
+ var source = _ref5.source;
60
+ var _ref6 = source.data,
61
+ type = _ref6.type,
62
+ localId = _ref6.localId,
63
+ indexes = _ref6.indexes;
64
+
65
+ // First; Perform any quick checks so we can abort early.
66
+ if (!indexes || !localId ||
67
+ // FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
68
+ // of more then 1 item.
69
+ indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
70
+ return false;
71
+ }
72
+ var _getTablePluginState = (0, _pluginFactory.getPluginState)(editorView.state),
73
+ tableNode = _getTablePluginState.tableNode;
74
+ // If the draggable localId is the same as the current selected table localId then we will allow the monitor
75
+ // watch for changes
76
+ return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
77
+ },
78
+ onDragStart: function onDragStart(_ref7) {
79
+ var location = _ref7.location;
80
+ (0, _commands.toggleDragMenu)(false)(editorView.state, editorView.dispatch);
81
+ },
82
+ onDrag: function onDrag(event) {
83
+ var data = (0, _monitor.getDraggableDataFromEvent)(event);
84
+ // If no data can be found then it's most like we do not want to perform any drag actions
85
+ if (!data) {
86
+ (0, _commands.clearDropTarget)()(editorView.state, editorView.dispatch);
87
+ return;
88
+ }
89
+
90
+ // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
91
+ // insert location as to where the draggable will most likely be go. For example;
92
+ var sourceType = data.sourceType,
93
+ targetAdjustedIndex = data.targetAdjustedIndex;
94
+ var dropTargetType = sourceType === 'table-row' ? _consts.DropTargetType.ROW : _consts.DropTargetType.COLUMN;
95
+ var hasMergedCells = (0, _utils2.hasMergedCellsInBetween)([targetAdjustedIndex - 1, targetAdjustedIndex], dropTargetType)(editorView.state.selection);
96
+ (0, _commands.setDropTarget)(dropTargetType, targetAdjustedIndex, hasMergedCells)(editorView.state, editorView.dispatch);
97
+ },
98
+ onDrop: function onDrop(event) {
99
+ var _cell$row, _cell$col;
100
+ var data = (0, _monitor.getDraggableDataFromEvent)(event);
101
+
102
+ // On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
103
+ // over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
104
+ // at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
105
+ // it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
106
+ // then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
107
+ // triggered by this on drop event.
108
+ var _getTablePluginState2 = (0, _pluginFactory.getPluginState)(editorView.state),
109
+ hoveredCell = _getTablePluginState2.hoveredCell;
110
+ var cell = (0, _utils2.findNearestCellIndexToPoint)(event.location.current.input.clientX, event.location.current.input.clientY);
111
+ var tr = editorView.state.tr;
112
+ var 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(_pluginKey.pluginKey, 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$source2;
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 || (_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') {
129
+ return (0, _commandsWithAnalytics.clearDropTargetWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, _analytics.TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
130
+ }
131
+ return (0, _commands.clearDropTarget)(tr)(editorView.state, editorView.dispatch);
132
+ }
133
+ var sourceType = data.sourceType,
134
+ sourceIndexes = data.sourceIndexes,
135
+ targetIndex = data.targetIndex,
136
+ targetAdjustedIndex = data.targetAdjustedIndex,
137
+ direction = data.direction;
138
+
139
+ // When we drop on a target we will know the targets row/col index for certain,
140
+ if (sourceType === 'table-row') {
141
+ action.data.hoveredCell.rowIndex = targetIndex;
142
+ } else {
143
+ action.data.hoveredCell.colIndex = targetIndex;
144
+ }
145
+
146
+ // If the drop target index contains merged cells then we should not allow the drop to occur.
147
+ if ((0, _utils2.hasMergedCellsInBetween)([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? _consts.DropTargetType.ROW : _consts.DropTargetType.COLUMN)(editorView.state.selection)) {
148
+ (0, _commandsWithAnalytics.clearDropTargetWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType,
149
+ // This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
150
+ _analytics.TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
151
+ return;
152
+ }
153
+ var _sourceIndexes = (0, _slicedToArray2.default)(sourceIndexes, 1),
154
+ sourceIndex = _sourceIndexes[0];
155
+ requestAnimationFrame(function () {
156
+ (0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
157
+
158
+ // force a colgroup update here, otherwise dropped columns don't have
159
+ // the correct width immediately after the drop
160
+ if (sourceType === 'table-column') {
161
+ var _getTablePluginState3 = (0, _pluginFactory.getPluginState)(editorView.state),
162
+ tableRef = _getTablePluginState3.tableRef,
163
+ tableNode = _getTablePluginState3.tableNode;
164
+ if (tableRef && tableNode) {
165
+ (0, _utils3.insertColgroupFromNode)(tableRef, tableNode);
166
+ }
167
+ }
168
+ editorView.focus();
169
+ });
170
+ }
171
+ })]));
172
+ };
29
173
  var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventDispatcher, editorAnalyticsAPI) {
30
174
  return new _safePlugin.SafePlugin({
31
175
  state: (0, _pluginFactory2.createPluginState)(dispatch, function (state) {
@@ -41,12 +185,12 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
41
185
  }),
42
186
  key: _pluginKey2.pluginKey,
43
187
  appendTransaction: function appendTransaction(transactions, oldState, newState) {
44
- var _getTablePluginState = (0, _pluginFactory.getPluginState)(oldState),
45
- oldTargetCellPosition = _getTablePluginState.targetCellPosition,
46
- oldTableNode = _getTablePluginState.tableNode;
47
- var _getTablePluginState2 = (0, _pluginFactory.getPluginState)(newState),
48
- newTargetCellPosition = _getTablePluginState2.targetCellPosition,
49
- newTableNode = _getTablePluginState2.tableNode;
188
+ var _getTablePluginState4 = (0, _pluginFactory.getPluginState)(oldState),
189
+ oldTargetCellPosition = _getTablePluginState4.targetCellPosition,
190
+ oldTableNode = _getTablePluginState4.tableNode;
191
+ var _getTablePluginState5 = (0, _pluginFactory.getPluginState)(newState),
192
+ newTargetCellPosition = _getTablePluginState5.targetCellPosition,
193
+ newTableNode = _getTablePluginState5.tableNode;
50
194
  var _getPluginState = (0, _pluginFactory2.getPluginState)(newState),
51
195
  isDragMenuOpen = _getPluginState.isDragMenuOpen,
52
196
  dragMenuIndex = _getPluginState.dragMenuIndex,
@@ -100,121 +244,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
100
244
  },
101
245
  view: function view(editorView) {
102
246
  return {
103
- destroy: (0, _element.monitorForElements)({
104
- canMonitor: function canMonitor(_ref) {
105
- var source = _ref.source;
106
- var _ref2 = source.data,
107
- type = _ref2.type,
108
- localId = _ref2.localId,
109
- indexes = _ref2.indexes;
110
-
111
- // First; Perform any quick checks so we can abort early.
112
- if (!indexes || !localId ||
113
- // FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
114
- // of more then 1 item.
115
- indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
116
- return false;
117
- }
118
- var _getTablePluginState3 = (0, _pluginFactory.getPluginState)(editorView.state),
119
- tableNode = _getTablePluginState3.tableNode;
120
- // If the draggable localId is the same as the current selected table localId then we will allow the monitor
121
- // watch for changes
122
- return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
123
- },
124
- onDragStart: function onDragStart(_ref3) {
125
- var location = _ref3.location;
126
- (0, _commands.toggleDragMenu)(false)(editorView.state, editorView.dispatch);
127
- },
128
- onDrag: function onDrag(event) {
129
- var data = (0, _monitor.getDraggableDataFromEvent)(event);
130
- // If no data can be found then it's most like we do not want to perform any drag actions
131
- if (!data) {
132
- (0, _commands.clearDropTarget)()(editorView.state, editorView.dispatch);
133
- return;
134
- }
135
-
136
- // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
137
- // insert location as to where the draggable will most likely be go. For example;
138
- var sourceType = data.sourceType,
139
- targetAdjustedIndex = data.targetAdjustedIndex;
140
- var dropTargetType = sourceType === 'table-row' ? _consts.DropTargetType.ROW : _consts.DropTargetType.COLUMN;
141
- var hasMergedCells = (0, _utils2.hasMergedCellsInBetween)([targetAdjustedIndex - 1, targetAdjustedIndex], dropTargetType)(editorView.state.selection);
142
- (0, _commands.setDropTarget)(dropTargetType, targetAdjustedIndex, hasMergedCells)(editorView.state, editorView.dispatch);
143
- },
144
- onDrop: function onDrop(event) {
145
- var _cell$row, _cell$col;
146
- var data = (0, _monitor.getDraggableDataFromEvent)(event);
147
-
148
- // On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
149
- // over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
150
- // at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
151
- // it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
152
- // then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
153
- // triggered by this on drop event.
154
- var _getTablePluginState4 = (0, _pluginFactory.getPluginState)(editorView.state),
155
- hoveredCell = _getTablePluginState4.hoveredCell;
156
- var cell = (0, _utils2.findNearestCellIndexToPoint)(event.location.current.input.clientX, event.location.current.input.clientY);
157
- var tr = editorView.state.tr;
158
- var 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(_pluginKey.pluginKey, 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$source2;
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 || (_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') {
175
- return (0, _commandsWithAnalytics.clearDropTargetWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, _analytics.TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
176
- }
177
- return (0, _commands.clearDropTarget)(tr)(editorView.state, editorView.dispatch);
178
- }
179
- var sourceType = data.sourceType,
180
- sourceIndexes = data.sourceIndexes,
181
- targetIndex = data.targetIndex,
182
- targetAdjustedIndex = data.targetAdjustedIndex,
183
- direction = data.direction;
184
-
185
- // When we drop on a target we will know the targets row/col index for certain,
186
- if (sourceType === 'table-row') {
187
- action.data.hoveredCell.rowIndex = targetIndex;
188
- } else {
189
- action.data.hoveredCell.colIndex = targetIndex;
190
- }
191
-
192
- // If the drop target index contains merged cells then we should not allow the drop to occur.
193
- if ((0, _utils2.hasMergedCellsInBetween)([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? _consts.DropTargetType.ROW : _consts.DropTargetType.COLUMN)(editorView.state.selection)) {
194
- (0, _commandsWithAnalytics.clearDropTargetWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType,
195
- // This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
196
- _analytics.TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
197
- return;
198
- }
199
- var _sourceIndexes = (0, _slicedToArray2.default)(sourceIndexes, 1),
200
- sourceIndex = _sourceIndexes[0];
201
- requestAnimationFrame(function () {
202
- (0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
203
-
204
- // force a colgroup update here, otherwise dropped columns don't have
205
- // the correct width immediately after the drop
206
- if (sourceType === 'table-column') {
207
- var _getTablePluginState5 = (0, _pluginFactory.getPluginState)(editorView.state),
208
- tableRef = _getTablePluginState5.tableRef,
209
- tableNode = _getTablePluginState5.tableNode;
210
- if (tableRef && tableNode) {
211
- (0, _utils3.insertColgroupFromNode)(tableRef, tableNode);
212
- }
213
- }
214
- editorView.focus();
215
- });
216
- }
217
- })
247
+ destroy: destroyFn(editorView, editorAnalyticsAPI)
218
248
  };
219
249
  },
220
250
  props: {
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.autoScrollerFactory = void 0;
7
+ var _element = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/element");
8
+ var _element2 = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/element");
9
+ var _consts = require("../../../ui/consts");
10
+ var autoScrollerFactory = exports.autoScrollerFactory = function autoScrollerFactory(_ref) {
11
+ var tableWrapper = _ref.tableWrapper,
12
+ getNode = _ref.getNode;
13
+ return [(0, _element.autoScrollForElements)({
14
+ element: tableWrapper,
15
+ canScroll: function canScroll(_ref2) {
16
+ var source = _ref2.source;
17
+ var _ref3 = source.data,
18
+ localId = _ref3.localId,
19
+ type = _ref3.type;
20
+ var node = getNode();
21
+ return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
22
+ }
23
+ }), (0, _element2.unsafeOverflowAutoScrollForElements)({
24
+ element: tableWrapper,
25
+ canScroll: function canScroll(_ref4) {
26
+ var source = _ref4.source;
27
+ var _ref5 = source.data,
28
+ localId = _ref5.localId,
29
+ type = _ref5.type;
30
+ var node = getNode();
31
+ return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
32
+ },
33
+ getOverflow: function getOverflow() {
34
+ return {
35
+ fromTopEdge: {
36
+ top: _consts.dropTargetExtendedWidth,
37
+ right: _consts.dropTargetExtendedWidth,
38
+ left: _consts.dropTargetExtendedWidth
39
+ },
40
+ fromRightEdge: {
41
+ right: _consts.dropTargetExtendedWidth,
42
+ top: _consts.dropTargetExtendedWidth,
43
+ bottom: _consts.dropTargetExtendedWidth
44
+ },
45
+ fromLeftEdge: {
46
+ top: _consts.dropTargetExtendedWidth,
47
+ left: _consts.dropTargetExtendedWidth,
48
+ bottom: _consts.dropTargetExtendedWidth
49
+ }
50
+ };
51
+ }
52
+ })];
53
+ };
@@ -3,10 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "autoScrollerFactory", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _autoscrollers.autoScrollerFactory;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "getDraggableDataFromEvent", {
7
13
  enumerable: true,
8
14
  get: function get() {
9
15
  return _monitor.getDraggableDataFromEvent;
10
16
  }
11
17
  });
12
- var _monitor = require("./monitor");
18
+ var _monitor = require("./monitor");
19
+ var _autoscrollers = require("./autoscrollers");
@@ -81,7 +81,7 @@ var InsertButtonForDragAndDrop = exports.InsertButtonForDragAndDrop = function I
81
81
  fill: "none",
82
82
  xmlns: "http://www.w3.org/2000/svg"
83
83
  }, /*#__PURE__*/_react.default.createElement("path", {
84
- d: "M8.66667 7.33333V4.66667C8.66667 4.48986 8.59643 4.32029 8.47141 4.19526C8.34638 4.07024 8.17682 4 8 4C7.82318 4 7.65362 4.07024 7.52859 4.19526C7.40357 4.32029 7.33333 4.48986 7.33333 4.66667V7.33333H4.66667C4.48986 7.33333 4.32029 7.40357 4.19526 7.52859C4.07024 7.65362 4 7.82318 4 8C4 8.17682 4.07024 8.34638 4.19526 8.47141C4.32029 8.59643 4.48986 8.66667 4.66667 8.66667H7.33333V11.3333C7.33333 11.5101 7.40357 11.6797 7.52859 11.8047C7.65362 11.9298 7.82318 12 8 12C8.17682 12 8.34638 11.9298 8.47141 11.8047C8.59643 11.6797 8.66667 11.5101 8.66667 11.3333V8.66667H11.3333C11.5101 8.66667 11.6797 8.59643 11.8047 8.47141C11.9298 8.34638 12 8.17682 12 8C12 7.82318 11.9298 7.65362 11.8047 7.52859C11.6797 7.40357 11.5101 7.33333 11.3333 7.33333H8.66667Z",
84
+ d: "M8 4C7.44771 4 7 4.44771 7 5V7H5C4.44771 7 4 7.44771 4 8C4 8.55229 4.44771 9 5 9H7V11C7 11.5523 7.44771 12 8 12C8.55229 12 9 11.5523 9 11V9H11C11.5523 9 12 8.55229 12 8C12 7.44771 11.5523 7 11 7H9V5C9 4.44771 8.55229 4 8 4Z",
85
85
  fill: "currentColor"
86
86
  })))), /*#__PURE__*/_react.default.createElement("div", {
87
87
  className: _types.TableCssClassName.CONTROLS_INSERT_LINE,