@atlaskit/editor-plugin-table 7.5.15 → 7.6.0

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 (49) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +36 -1
  3. package/dist/cjs/pm-plugins/drag-and-drop/commands.js +17 -1
  4. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +8 -2
  5. package/dist/cjs/pm-plugins/drag-and-drop/utils/getDragBehaviour.js +13 -0
  6. package/dist/cjs/pm-plugins/drag-and-drop/utils/monitor.js +11 -4
  7. package/dist/cjs/toolbar.js +58 -12
  8. package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +31 -6
  9. package/dist/cjs/ui/TableFloatingControls/RowDropTarget/index.js +31 -6
  10. package/dist/cjs/ui/TableFullWidthLabel/index.js +25 -0
  11. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +34 -1
  12. package/dist/es2019/pm-plugins/drag-and-drop/commands.js +15 -1
  13. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +9 -3
  14. package/dist/es2019/pm-plugins/drag-and-drop/utils/getDragBehaviour.js +8 -0
  15. package/dist/es2019/pm-plugins/drag-and-drop/utils/monitor.js +9 -4
  16. package/dist/es2019/toolbar.js +49 -0
  17. package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +27 -3
  18. package/dist/es2019/ui/TableFloatingControls/RowDropTarget/index.js +27 -3
  19. package/dist/es2019/ui/TableFullWidthLabel/index.js +19 -0
  20. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +36 -1
  21. package/dist/esm/pm-plugins/drag-and-drop/commands.js +17 -1
  22. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +9 -3
  23. package/dist/esm/pm-plugins/drag-and-drop/utils/getDragBehaviour.js +7 -0
  24. package/dist/esm/pm-plugins/drag-and-drop/utils/monitor.js +10 -4
  25. package/dist/esm/toolbar.js +58 -12
  26. package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +31 -6
  27. package/dist/esm/ui/TableFloatingControls/RowDropTarget/index.js +31 -6
  28. package/dist/esm/ui/TableFullWidthLabel/index.js +18 -0
  29. package/dist/types/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +1 -0
  30. package/dist/types/pm-plugins/drag-and-drop/commands.d.ts +1 -0
  31. package/dist/types/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +3 -0
  32. package/dist/types/types.d.ts +12 -1
  33. package/dist/types/ui/TableFullWidthLabel/index.d.ts +2 -0
  34. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +1 -0
  35. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands.d.ts +1 -0
  36. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +3 -0
  37. package/dist/types-ts4.5/types.d.ts +12 -1
  38. package/dist/types-ts4.5/ui/TableFullWidthLabel/index.d.ts +2 -0
  39. package/package.json +3 -3
  40. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +56 -1
  41. package/src/pm-plugins/drag-and-drop/commands.ts +31 -2
  42. package/src/pm-plugins/drag-and-drop/plugin.ts +21 -7
  43. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +12 -0
  44. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +17 -3
  45. package/src/toolbar.tsx +50 -0
  46. package/src/types.ts +13 -1
  47. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +39 -5
  48. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +40 -5
  49. package/src/ui/TableFullWidthLabel/index.tsx +24 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#83612](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83612) [`25b32cbfbb7e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/25b32cbfbb7e) - [ux] Added new clone row/column behaviour to tables drag N drop. When the user holds the alt modifier during the operation the row/column will be duplicated rather then moved.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
13
+ ## 7.5.16
14
+
15
+ ### Patch Changes
16
+
17
+ - [#83148](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83148) [`c7e46e32cf2d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c7e46e32cf2d) - [ux] add label in floating toolbar when table resize to widest guideline
18
+
3
19
  ## 7.5.15
4
20
 
5
21
  ### Patch Changes
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalytics = exports.clearDropTargetWithAnalytics = void 0;
7
+ exports.moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalytics = exports.cloneSourceWithAnalytics = exports.clearDropTargetWithAnalytics = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _analytics = require("@atlaskit/editor-common/analytics");
10
10
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
@@ -102,4 +102,39 @@ var moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalyticsViaShort
102
102
  return moveSourceWithAnalytics(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT, sourceType, selectedIndexes, targetIndex)(state, dispatch);
103
103
  };
104
104
  };
105
+ };
106
+ var cloneSourceWithAnalytics = exports.cloneSourceWithAnalytics = function cloneSourceWithAnalytics(editorAnalyticsAPI) {
107
+ return function (inputMethod, sourceType, sourceIndexes, targetIndex, targetDirection, tr) {
108
+ return (0, _analytics2.withEditorAnalyticsAPI)(function (_ref3) {
109
+ var selection = _ref3.selection;
110
+ var direction = sourceIndexes[0] > targetIndex ? -1 : 1;
111
+ var _getSelectedTableInfo4 = (0, _utils2.getSelectedTableInfo)(selection),
112
+ totalRowCount = _getSelectedTableInfo4.totalRowCount,
113
+ totalColumnCount = _getSelectedTableInfo4.totalColumnCount;
114
+ return {
115
+ action: sourceType === 'table-row' ? _analytics.TABLE_ACTION.CLONED_ROW : _analytics.TABLE_ACTION.CLONED_COLUMN,
116
+ actionSubject: _analytics.ACTION_SUBJECT.TABLE,
117
+ actionSubjectId: null,
118
+ attributes: {
119
+ inputMethod: inputMethod,
120
+ count: sourceIndexes.length,
121
+ // This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
122
+ // of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
123
+ distance: Math.min.apply(Math, (0, _toConsumableArray2.default)(sourceIndexes.map(function (v) {
124
+ return Math.abs(targetIndex - v);
125
+ }))) * direction,
126
+ // If a drop doesn't actually change anything then we're going to mark the event as cancelled.
127
+ status: sourceIndexes.includes(targetIndex) ? _analytics.TABLE_STATUS.CANCELLED : _analytics.TABLE_STATUS.SUCCESS,
128
+ totalRowCount: totalRowCount,
129
+ totalColumnCount: totalColumnCount
130
+ },
131
+ eventType: _analytics.EVENT_TYPE.TRACK
132
+ };
133
+ })(editorAnalyticsAPI)(function (state, dispatch) {
134
+ if (dispatch) {
135
+ (0, _commands.cloneSource)(sourceType, sourceIndexes, targetIndex, targetDirection, tr)(state, dispatch);
136
+ }
137
+ return true;
138
+ });
139
+ };
105
140
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.updatePluginStateDecorations = exports.toggleDragMenu = exports.setDropTarget = exports.moveSource = exports.getDecorations = exports.clearDropTarget = void 0;
6
+ exports.updatePluginStateDecorations = exports.toggleDragMenu = exports.setDropTarget = exports.moveSource = exports.getDecorations = exports.cloneSource = exports.clearDropTarget = void 0;
7
7
  var _view = require("@atlaskit/editor-prosemirror/view");
8
8
  var _utils = require("@atlaskit/editor-tables/utils");
9
9
  var _types = require("../../types");
@@ -118,4 +118,20 @@ var toggleDragMenu = exports.toggleDragMenu = function toggleDragMenu(isDragMenu
118
118
  }, function (tr) {
119
119
  return tr.setMeta('addToHistory', false);
120
120
  });
121
+ };
122
+ var cloneSource = exports.cloneSource = function cloneSource(sourceType, sourceIndexes, targetIndex, targetDirection, tr) {
123
+ return (0, _pluginFactory.createCommand)(function (state) {
124
+ return {
125
+ type: _actions.DragAndDropActionType.CLEAR_DROP_TARGET,
126
+ data: {
127
+ decorationSet: _view.DecorationSet.empty
128
+ }
129
+ };
130
+ }, function (originalTr, state) {
131
+ var nextTr = tr || originalTr;
132
+ var clone = sourceType === 'table-row' ? _utils.cloneRow : _utils.cloneColumn;
133
+ return clone(state, sourceIndexes, targetIndex, targetDirection, {
134
+ selectAfterClone: true
135
+ })(nextTr);
136
+ });
121
137
  };
@@ -127,7 +127,9 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
127
127
  sourceIndexes = data.sourceIndexes,
128
128
  targetIndex = data.targetIndex,
129
129
  targetAdjustedIndex = data.targetAdjustedIndex,
130
- direction = data.direction;
130
+ targetDirection = data.targetDirection,
131
+ direction = data.direction,
132
+ behaviour = data.behaviour;
131
133
 
132
134
  // When we drop on a target we will know the targets row/col index for certain,
133
135
  if (sourceType === 'table-row') {
@@ -144,7 +146,11 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
144
146
  return;
145
147
  }
146
148
  requestAnimationFrame(function () {
147
- (0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
149
+ if (behaviour === 'clone') {
150
+ (0, _commandsWithAnalytics.cloneSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetIndex, targetDirection, tr)(editorView.state, editorView.dispatch);
151
+ } else {
152
+ (0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetAdjustedIndex + (direction === 1 ? -1 : 0), tr)(editorView.state, editorView.dispatch);
153
+ }
148
154
 
149
155
  // force a colgroup update here, otherwise dropped columns don't have
150
156
  // the correct width immediately after the drop
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDragBehaviour = void 0;
7
+ var _utils = require("@atlaskit/editor-common/utils");
8
+ var getDragBehaviour = exports.getDragBehaviour = function getDragBehaviour(_ref) {
9
+ var altKey = _ref.altKey,
10
+ ctrlKey = _ref.ctrlKey;
11
+ var isCloneModifierKeyPressed = _utils.browser.mac ? altKey : ctrlKey;
12
+ return isCloneModifierKeyPressed ? 'clone' : 'move';
13
+ };
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.getDraggableDataFromEvent = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
7
9
  var _closestEdge = require("@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge");
10
+ var _getDragBehaviour = require("./getDragBehaviour");
8
11
  var getDraggableDataFromEvent = exports.getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref) {
9
12
  var _extractClosestEdge;
10
13
  var location = _ref.location,
@@ -42,9 +45,11 @@ var getDraggableDataFromEvent = exports.getDraggableDataFromEvent = function get
42
45
  // the new target index to be 1 index higher.
43
46
  var targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
44
47
 
45
- // since only consecutive rows/cols can be moved we can assume that if the first index is greater then
46
- // the target index, the then the direction of the DnD is decreasing
47
- var direction = sourceIndexes[0] > targetIndex ? -1 : 1;
48
+ // if the min index is greater then the target index, the then the direction of the DnD is decreasing
49
+ // if the target is within the min/max index then we can assume that no direction exists so it will be 0.
50
+ var srcMin = Math.min.apply(Math, (0, _toConsumableArray2.default)(sourceIndexes));
51
+ var srcMax = Math.max.apply(Math, (0, _toConsumableArray2.default)(sourceIndexes));
52
+ var direction = targetIndex >= srcMin && targetIndex <= srcMax ? 0 : srcMin >= targetIndex ? -1 : 1;
48
53
  return {
49
54
  sourceType: sourceType,
50
55
  sourceLocalId: sourceLocalId,
@@ -54,6 +59,8 @@ var getDraggableDataFromEvent = exports.getDraggableDataFromEvent = function get
54
59
  targetIndex: targetIndex,
55
60
  targetAdjustedIndex: targetIndex + targetOffset,
56
61
  targetClosestEdge: targetClosestEdge,
57
- direction: direction
62
+ targetDirection: targetClosestEdge === 'top' || targetClosestEdge === 'left' ? 'start' : 'end',
63
+ direction: direction,
64
+ behaviour: (0, _getDragBehaviour.getDragBehaviour)(location.current.input)
58
65
  };
59
66
  };
@@ -31,6 +31,7 @@ var _resizeState = require("./pm-plugins/table-resizing/utils/resize-state");
31
31
  var _tableWidth = require("./pm-plugins/table-width");
32
32
  var _transforms = require("./transforms");
33
33
  var _types = require("./types");
34
+ var _TableFullWidthLabel = require("./ui/TableFullWidthLabel");
34
35
  var _utils4 = require("./utils");
35
36
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
36
37
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -307,16 +308,61 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
307
308
 
308
309
  // We don't want to show floating toolbar while resizing the table
309
310
  var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
310
- if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
311
+ var isTableScalingEnabled = pluginState.isTableScalingEnabled,
312
+ widthToWidest = pluginState.widthToWidest;
313
+ if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
314
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
315
+ stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
311
316
  var nodeType = state.schema.nodes.table;
317
+ var getDomRef = function getDomRef(editorView) {
318
+ var element;
319
+ var domAtPos = editorView.domAtPos.bind(editorView);
320
+ var parent = (0, _utils2.findParentDomRefOfType)(nodeType, domAtPos)(state.selection);
321
+ if (parent) {
322
+ var tableRef = parent.querySelector('table') || undefined;
323
+ if (tableRef) {
324
+ element = (0, _utils.closestElement)(tableRef, ".".concat(_types.TableCssClassName.TABLE_NODE_WRAPPER)) || undefined;
325
+ }
326
+ }
327
+ return element;
328
+ };
329
+ var fullWidthLabel = {
330
+ id: 'editor.table.fullWidthLabel',
331
+ type: 'custom',
332
+ fallback: [],
333
+ render: function render() {
334
+ return (0, _react.jsx)(_TableFullWidthLabel.FullWidthDisplay, {
335
+ key: 'full-width-label'
336
+ });
337
+ }
338
+ };
339
+ return {
340
+ title: 'Table floating label',
341
+ getDomRef: getDomRef,
342
+ nodeType: nodeType,
343
+ key: 'full-width-label',
344
+ offset: [0, 18],
345
+ absoluteOffset: stickyScrollbar ? {
346
+ top: -6
347
+ } : {
348
+ top: 0
349
+ },
350
+ zIndex: _editorSharedStyles.akEditorFloatingPanelZIndex + 1,
351
+ // Place the context menu slightly above the others
352
+ items: [fullWidthLabel],
353
+ scrollable: true
354
+ };
355
+ }
356
+ if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
357
+ var _nodeType = state.schema.nodes.table;
312
358
  var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
313
359
  var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
314
360
  _getPluginState2$isTa = _getPluginState2.isTableScalingEnabled,
315
- isTableScalingEnabled = _getPluginState2$isTa === void 0 ? false : _getPluginState2$isTa;
361
+ _isTableScalingEnabled = _getPluginState2$isTa === void 0 ? false : _getPluginState2$isTa;
316
362
  var cellItems;
317
- cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled);
363
+ cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, _isTableScalingEnabled);
318
364
  var columnSettingsItems;
319
- columnSettingsItems = pluginState.isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled) : [];
365
+ columnSettingsItems = pluginState.isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, _isTableScalingEnabled) : [];
320
366
  var colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
321
367
 
322
368
  // Check if we need to show confirm dialog for delete button
@@ -343,10 +389,10 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
343
389
  };
344
390
  };
345
391
  }
346
- var getDomRef = function getDomRef(editorView) {
392
+ var _getDomRef = function _getDomRef(editorView) {
347
393
  var element;
348
394
  var domAtPos = editorView.domAtPos.bind(editorView);
349
- var parent = (0, _utils2.findParentDomRefOfType)(nodeType, domAtPos)(state.selection);
395
+ var parent = (0, _utils2.findParentDomRefOfType)(_nodeType, domAtPos)(state.selection);
350
396
  if (parent) {
351
397
  var tableRef = parent.querySelector('table') || undefined;
352
398
  if (tableRef) {
@@ -355,14 +401,14 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
355
401
  }
356
402
  return element;
357
403
  };
358
- var _getEditorFeatureFlag = getEditorFeatureFlags(),
359
- stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
404
+ var _getEditorFeatureFlag2 = getEditorFeatureFlags(),
405
+ _stickyScrollbar = _getEditorFeatureFlag2.stickyScrollbar;
360
406
  return {
361
407
  title: 'Table floating controls',
362
- getDomRef: getDomRef,
363
- nodeType: nodeType,
408
+ getDomRef: _getDomRef,
409
+ nodeType: _nodeType,
364
410
  offset: [0, 18],
365
- absoluteOffset: stickyScrollbar ? {
411
+ absoluteOffset: _stickyScrollbar ? {
366
412
  top: -6
367
413
  } : {
368
414
  top: 0
@@ -377,7 +423,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
377
423
  items: [{
378
424
  state: state,
379
425
  formatMessage: intl.formatMessage,
380
- nodeType: nodeType,
426
+ nodeType: _nodeType,
381
427
  onMouseEnter: (0, _commands.hoverTable)(false, true),
382
428
  onMouseLeave: (0, _commands.clearHoverSelection)(),
383
429
  onFocus: (0, _commands.hoverTable)(false, true),
@@ -8,6 +8,7 @@ exports.ColumnDropTarget = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _closestEdge = require("@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge");
10
10
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
11
+ var _getDragBehaviour = require("../../../pm-plugins/drag-and-drop/utils/getDragBehaviour");
11
12
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
12
13
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
14
  var ColumnDropTarget = exports.ColumnDropTarget = function ColumnDropTarget(_ref) {
@@ -25,32 +26,56 @@ var ColumnDropTarget = exports.ColumnDropTarget = function ColumnDropTarget(_ref
25
26
  element: dropTargetRef.current,
26
27
  canDrop: function canDrop(_ref2) {
27
28
  var _data$indexes, _data$indexes2;
28
- var source = _ref2.source;
29
+ var source = _ref2.source,
30
+ input = _ref2.input;
29
31
  var data = source.data;
32
+ var behaviour = (0, _getDragBehaviour.getDragBehaviour)(input);
33
+
34
+ // A move drop is limited too where it can go, however a clone can drop can go anywhere.
35
+ var isDropValid = behaviour === 'move' ? ((_data$indexes = data.indexes) === null || _data$indexes === void 0 ? void 0 : _data$indexes.indexOf(index)) === -1 : behaviour === 'clone';
30
36
  return (
31
37
  // Only draggables of row type can be dropped on this target
32
38
  data.type === 'table-column' &&
33
39
  // Only draggables which came from the same table can be dropped on this target
34
40
  data.localId === localId &&
35
41
  // Only draggables which DO NOT include this drop targets index can be dropped
36
- !!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
42
+ !!((_data$indexes2 = data.indexes) !== null && _data$indexes2 !== void 0 && _data$indexes2.length) && isDropValid
37
43
  );
38
44
  },
45
+ getDropEffect: function getDropEffect(_ref3) {
46
+ var input = _ref3.input;
47
+ return (0, _getDragBehaviour.getDragBehaviour)(input) === 'clone' ? 'copy' : 'move';
48
+ },
39
49
  getIsSticky: function getIsSticky() {
40
50
  return true;
41
51
  },
42
- getData: function getData(_ref3) {
43
- var input = _ref3.input,
44
- element = _ref3.element;
52
+ getData: function getData(_ref4) {
53
+ var _srcData$indexes;
54
+ var source = _ref4.source,
55
+ input = _ref4.input,
56
+ element = _ref4.element;
45
57
  var data = {
46
58
  localId: localId,
47
59
  type: 'table-column',
48
60
  targetIndex: index
49
61
  };
62
+ var srcData = source.data;
63
+ var behaviour = (0, _getDragBehaviour.getDragBehaviour)(input);
64
+
65
+ // During a move op there's no point in allowing edges to be dropped on which result in no change/move to occur.
66
+ var allowedEdges = behaviour === 'move' ? (_srcData$indexes = srcData.indexes) === null || _srcData$indexes === void 0 ? void 0 : _srcData$indexes.reduce(function (acc, v) {
67
+ if (v - index === -1) {
68
+ acc.shift();
69
+ }
70
+ if (v - index === 1) {
71
+ acc.pop();
72
+ }
73
+ return acc;
74
+ }, ['left', 'right']) : ['left', 'right'];
50
75
  return (0, _closestEdge.attachClosestEdge)(data, {
51
76
  input: input,
52
77
  element: element,
53
- allowedEdges: ['left', 'right']
78
+ allowedEdges: allowedEdges
54
79
  });
55
80
  }
56
81
  });
@@ -8,6 +8,7 @@ exports.default = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _closestEdge = require("@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge");
10
10
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
11
+ var _getDragBehaviour = require("../../../pm-plugins/drag-and-drop/utils/getDragBehaviour");
11
12
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
12
13
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
14
  var RowDropTarget = function RowDropTarget(_ref) {
@@ -23,32 +24,56 @@ var RowDropTarget = function RowDropTarget(_ref) {
23
24
  element: dropTargetRef.current,
24
25
  canDrop: function canDrop(_ref2) {
25
26
  var _data$indexes, _data$indexes2;
26
- var source = _ref2.source;
27
+ var source = _ref2.source,
28
+ input = _ref2.input;
27
29
  var data = source.data;
30
+ var behaviour = (0, _getDragBehaviour.getDragBehaviour)(input);
31
+
32
+ // A move drop is limited too where it can go, however a clone can drop can go anywhere.
33
+ var isDropValid = behaviour === 'move' ? ((_data$indexes = data.indexes) === null || _data$indexes === void 0 ? void 0 : _data$indexes.indexOf(index)) === -1 : behaviour === 'clone';
28
34
  return (
29
35
  // Only draggables of row type can be dropped on this target
30
36
  data.type === 'table-row' &&
31
37
  // Only draggables which came from the same table can be dropped on this target
32
38
  data.localId === localId &&
33
39
  // Only draggables which DO NOT include this drop targets index can be dropped
34
- !!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
40
+ !!((_data$indexes2 = data.indexes) !== null && _data$indexes2 !== void 0 && _data$indexes2.length) && isDropValid
35
41
  );
36
42
  },
43
+ getDropEffect: function getDropEffect(_ref3) {
44
+ var input = _ref3.input;
45
+ return (0, _getDragBehaviour.getDragBehaviour)(input) === 'clone' ? 'copy' : 'move';
46
+ },
37
47
  getIsSticky: function getIsSticky() {
38
48
  return true;
39
49
  },
40
- getData: function getData(_ref3) {
41
- var input = _ref3.input,
42
- element = _ref3.element;
50
+ getData: function getData(_ref4) {
51
+ var _srcData$indexes;
52
+ var source = _ref4.source,
53
+ input = _ref4.input,
54
+ element = _ref4.element;
43
55
  var data = {
44
56
  localId: localId,
45
57
  type: 'table-row',
46
58
  targetIndex: index
47
59
  };
60
+ var srcData = source.data;
61
+ var behaviour = (0, _getDragBehaviour.getDragBehaviour)(input);
62
+
63
+ // During a move op there's no point in allowing edges to be dropped on which result in no change/move to occur.
64
+ var allowedEdges = behaviour === 'move' ? (_srcData$indexes = srcData.indexes) === null || _srcData$indexes === void 0 ? void 0 : _srcData$indexes.reduce(function (acc, v) {
65
+ if (v - index === -1) {
66
+ acc.shift();
67
+ }
68
+ if (v - index === 1) {
69
+ acc.pop();
70
+ }
71
+ return acc;
72
+ }, ['top', 'bottom']) : ['top', 'bottom'];
48
73
  return (0, _closestEdge.attachClosestEdge)(data, {
49
74
  input: input,
50
75
  element: element,
51
- allowedEdges: ['top', 'bottom']
76
+ allowedEdges: allowedEdges
52
77
  });
53
78
  }
54
79
  });
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.FullWidthDisplay = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _messages = require("@atlaskit/editor-common/messages");
11
+ var _primitives = require("@atlaskit/primitives");
12
+ var tableFullWidthLabelStyles = (0, _primitives.xcss)({
13
+ minWidth: '120px',
14
+ height: "var(--ds-space-300, 24px)",
15
+ display: 'flex',
16
+ justifyContent: 'center',
17
+ alignItems: 'center'
18
+ });
19
+ var FullWidthDisplay = exports.FullWidthDisplay = function FullWidthDisplay() {
20
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
21
+ formatMessage = _useIntl.formatMessage;
22
+ return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
23
+ xcss: tableFullWidthLabelStyles
24
+ }, /*#__PURE__*/_react.default.createElement(_primitives.Inline, null, formatMessage(_messages.tableMessages.fullWidthLabel)));
25
+ };
@@ -4,7 +4,7 @@ import { findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tab
4
4
  import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo } from '../../utils';
5
5
  import { withEditorAnalyticsAPI } from '../../utils/analytics';
6
6
  import { canMove, getTargetIndex } from '../../utils/drag-menu';
7
- import { clearDropTarget, moveSource } from './commands';
7
+ import { clearDropTarget, cloneSource, moveSource } from './commands';
8
8
  export const clearDropTargetWithAnalytics = editorAnalyticsAPI => (inputMethod, sourceType, sourceIndexes, status, tr) => {
9
9
  return withEditorAnalyticsAPI(({
10
10
  selection
@@ -91,4 +91,37 @@ export const moveSourceWithAnalyticsViaShortcut = editorAnalyticsAPI => (sourceT
91
91
  }
92
92
  const targetIndex = getTargetIndex(selectedIndexes, direction);
93
93
  return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, selectedIndexes, targetIndex)(state, dispatch);
94
+ };
95
+ export const cloneSourceWithAnalytics = editorAnalyticsAPI => (inputMethod, sourceType, sourceIndexes, targetIndex, targetDirection, tr) => {
96
+ return withEditorAnalyticsAPI(({
97
+ selection
98
+ }) => {
99
+ const direction = sourceIndexes[0] > targetIndex ? -1 : 1;
100
+ const {
101
+ totalRowCount,
102
+ totalColumnCount
103
+ } = getSelectedTableInfo(selection);
104
+ return {
105
+ action: sourceType === 'table-row' ? TABLE_ACTION.CLONED_ROW : TABLE_ACTION.CLONED_COLUMN,
106
+ actionSubject: ACTION_SUBJECT.TABLE,
107
+ actionSubjectId: null,
108
+ attributes: {
109
+ inputMethod,
110
+ count: sourceIndexes.length,
111
+ // This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
112
+ // of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
113
+ distance: Math.min(...sourceIndexes.map(v => Math.abs(targetIndex - v))) * direction,
114
+ // If a drop doesn't actually change anything then we're going to mark the event as cancelled.
115
+ status: sourceIndexes.includes(targetIndex) ? TABLE_STATUS.CANCELLED : TABLE_STATUS.SUCCESS,
116
+ totalRowCount,
117
+ totalColumnCount
118
+ },
119
+ eventType: EVENT_TYPE.TRACK
120
+ };
121
+ })(editorAnalyticsAPI)((state, dispatch) => {
122
+ if (dispatch) {
123
+ cloneSource(sourceType, sourceIndexes, targetIndex, targetDirection, tr)(state, dispatch);
124
+ }
125
+ return true;
126
+ });
94
127
  };
@@ -1,5 +1,5 @@
1
1
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
- import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
2
+ import { cloneColumn, cloneRow, moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
3
3
  import { TableDecorations } from '../../types';
4
4
  import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
5
5
  import { DragAndDropActionType } from './actions';
@@ -100,4 +100,18 @@ export const toggleDragMenu = (isDragMenuOpen, direction, index, trigger = 'mous
100
100
  };
101
101
  }, tr => {
102
102
  return tr.setMeta('addToHistory', false);
103
+ });
104
+ export const cloneSource = (sourceType, sourceIndexes, targetIndex, targetDirection, tr) => createCommand(state => {
105
+ return {
106
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
107
+ data: {
108
+ decorationSet: DecorationSet.empty
109
+ }
110
+ };
111
+ }, (originalTr, state) => {
112
+ const nextTr = tr || originalTr;
113
+ const clone = sourceType === 'table-row' ? cloneRow : cloneColumn;
114
+ return clone(state, sourceIndexes, targetIndex, targetDirection, {
115
+ selectAfterClone: true
116
+ })(nextTr);
103
117
  });
@@ -12,7 +12,7 @@ import { pluginKey as tablePluginKey } from '../plugin-key';
12
12
  import { insertColgroupFromNode } from '../table-resizing/utils';
13
13
  import { DragAndDropActionType } from './actions';
14
14
  import { clearDropTarget, setDropTarget, toggleDragMenu } from './commands';
15
- import { clearDropTargetWithAnalytics, moveSourceWithAnalytics } from './commands-with-analytics';
15
+ import { clearDropTargetWithAnalytics, cloneSourceWithAnalytics, moveSourceWithAnalytics } from './commands-with-analytics';
16
16
  import { DropTargetType } from './consts';
17
17
  import { createPluginState, getPluginState } from './plugin-factory';
18
18
  import { pluginKey } from './plugin-key';
@@ -133,7 +133,9 @@ const destroyFn = (editorView, editorAnalyticsAPI) => {
133
133
  sourceIndexes,
134
134
  targetIndex,
135
135
  targetAdjustedIndex,
136
- direction
136
+ targetDirection,
137
+ direction,
138
+ behaviour
137
139
  } = data;
138
140
 
139
141
  // When we drop on a target we will know the targets row/col index for certain,
@@ -151,7 +153,11 @@ const destroyFn = (editorView, editorAnalyticsAPI) => {
151
153
  return;
152
154
  }
153
155
  requestAnimationFrame(() => {
154
- moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
156
+ if (behaviour === 'clone') {
157
+ cloneSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetIndex, targetDirection, tr)(editorView.state, editorView.dispatch);
158
+ } else {
159
+ moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetAdjustedIndex + (direction === 1 ? -1 : 0), tr)(editorView.state, editorView.dispatch);
160
+ }
155
161
 
156
162
  // force a colgroup update here, otherwise dropped columns don't have
157
163
  // the correct width immediately after the drop
@@ -0,0 +1,8 @@
1
+ import { browser } from '@atlaskit/editor-common/utils';
2
+ export const getDragBehaviour = ({
3
+ altKey,
4
+ ctrlKey
5
+ }) => {
6
+ const isCloneModifierKeyPressed = browser.mac ? altKey : ctrlKey;
7
+ return isCloneModifierKeyPressed ? 'clone' : 'move';
8
+ };
@@ -1,4 +1,5 @@
1
1
  import { extractClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
2
+ import { getDragBehaviour } from './getDragBehaviour';
2
3
  export const getDraggableDataFromEvent = ({
3
4
  location,
4
5
  source
@@ -39,9 +40,11 @@ export const getDraggableDataFromEvent = ({
39
40
  // the new target index to be 1 index higher.
40
41
  const targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
41
42
 
42
- // since only consecutive rows/cols can be moved we can assume that if the first index is greater then
43
- // the target index, the then the direction of the DnD is decreasing
44
- const direction = sourceIndexes[0] > targetIndex ? -1 : 1;
43
+ // if the min index is greater then the target index, the then the direction of the DnD is decreasing
44
+ // if the target is within the min/max index then we can assume that no direction exists so it will be 0.
45
+ const srcMin = Math.min(...sourceIndexes);
46
+ const srcMax = Math.max(...sourceIndexes);
47
+ const direction = targetIndex >= srcMin && targetIndex <= srcMax ? 0 : srcMin >= targetIndex ? -1 : 1;
45
48
  return {
46
49
  sourceType,
47
50
  sourceLocalId,
@@ -51,6 +54,8 @@ export const getDraggableDataFromEvent = ({
51
54
  targetIndex,
52
55
  targetAdjustedIndex: targetIndex + targetOffset,
53
56
  targetClosestEdge,
54
- direction
57
+ targetDirection: targetClosestEdge === 'top' || targetClosestEdge === 'left' ? 'start' : 'end',
58
+ direction,
59
+ behaviour: getDragBehaviour(location.current.input)
55
60
  };
56
61
  };