@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
@@ -23,6 +23,7 @@ import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizin
23
23
  import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
24
24
  import { canMergeCells } from './transforms';
25
25
  import { TableCssClassName } from './types';
26
+ import { FullWidthDisplay } from './ui/TableFullWidthLabel';
26
27
  import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes } from './utils';
27
28
  export const getToolbarMenuConfig = (config, state, {
28
29
  formatMessage
@@ -293,6 +294,54 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
293
294
 
294
295
  // We don't want to show floating toolbar while resizing the table
295
296
  const isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
297
+ const {
298
+ isTableScalingEnabled,
299
+ widthToWidest
300
+ } = pluginState;
301
+ if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
302
+ const {
303
+ stickyScrollbar
304
+ } = getEditorFeatureFlags();
305
+ const nodeType = state.schema.nodes.table;
306
+ const getDomRef = editorView => {
307
+ let element;
308
+ const domAtPos = editorView.domAtPos.bind(editorView);
309
+ const parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
310
+ if (parent) {
311
+ const tableRef = parent.querySelector('table') || undefined;
312
+ if (tableRef) {
313
+ element = closestElement(tableRef, `.${TableCssClassName.TABLE_NODE_WRAPPER}`) || undefined;
314
+ }
315
+ }
316
+ return element;
317
+ };
318
+ const fullWidthLabel = {
319
+ id: 'editor.table.fullWidthLabel',
320
+ type: 'custom',
321
+ fallback: [],
322
+ render: () => {
323
+ return jsx(FullWidthDisplay, {
324
+ key: 'full-width-label'
325
+ });
326
+ }
327
+ };
328
+ return {
329
+ title: 'Table floating label',
330
+ getDomRef,
331
+ nodeType,
332
+ key: 'full-width-label',
333
+ offset: [0, 18],
334
+ absoluteOffset: stickyScrollbar ? {
335
+ top: -6
336
+ } : {
337
+ top: 0
338
+ },
339
+ zIndex: akEditorFloatingPanelZIndex + 1,
340
+ // Place the context menu slightly above the others
341
+ items: [fullWidthLabel],
342
+ scrollable: true
343
+ };
344
+ }
296
345
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
297
346
  const nodeType = state.schema.nodes.table;
298
347
  const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
@@ -1,6 +1,7 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
  import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
3
3
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
4
+ import { getDragBehaviour } from '../../../pm-plugins/drag-and-drop/utils/getDragBehaviour';
4
5
  export const ColumnDropTarget = ({
5
6
  index,
6
7
  localId,
@@ -16,33 +17,56 @@ export const ColumnDropTarget = ({
16
17
  return dropTargetForElements({
17
18
  element: dropTargetRef.current,
18
19
  canDrop({
19
- source
20
+ source,
21
+ input
20
22
  }) {
21
23
  var _data$indexes, _data$indexes2;
22
24
  const data = source.data;
25
+ const behaviour = getDragBehaviour(input);
26
+
27
+ // A move drop is limited too where it can go, however a clone can drop can go anywhere.
28
+ const isDropValid = behaviour === 'move' ? ((_data$indexes = data.indexes) === null || _data$indexes === void 0 ? void 0 : _data$indexes.indexOf(index)) === -1 : behaviour === 'clone';
23
29
  return (
24
30
  // Only draggables of row type can be dropped on this target
25
31
  data.type === 'table-column' &&
26
32
  // Only draggables which came from the same table can be dropped on this target
27
33
  data.localId === localId &&
28
34
  // Only draggables which DO NOT include this drop targets index can be dropped
29
- !!((_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
35
+ !!((_data$indexes2 = data.indexes) !== null && _data$indexes2 !== void 0 && _data$indexes2.length) && isDropValid
30
36
  );
31
37
  },
38
+ getDropEffect: ({
39
+ input
40
+ }) => getDragBehaviour(input) === 'clone' ? 'copy' : 'move',
32
41
  getIsSticky: () => true,
33
42
  getData({
43
+ source,
34
44
  input,
35
45
  element
36
46
  }) {
47
+ var _srcData$indexes;
37
48
  const data = {
38
49
  localId,
39
50
  type: 'table-column',
40
51
  targetIndex: index
41
52
  };
53
+ const srcData = source.data;
54
+ const behaviour = getDragBehaviour(input);
55
+
56
+ // During a move op there's no point in allowing edges to be dropped on which result in no change/move to occur.
57
+ const allowedEdges = behaviour === 'move' ? (_srcData$indexes = srcData.indexes) === null || _srcData$indexes === void 0 ? void 0 : _srcData$indexes.reduce((acc, v) => {
58
+ if (v - index === -1) {
59
+ acc.shift();
60
+ }
61
+ if (v - index === 1) {
62
+ acc.pop();
63
+ }
64
+ return acc;
65
+ }, ['left', 'right']) : ['left', 'right'];
42
66
  return attachClosestEdge(data, {
43
67
  input,
44
68
  element,
45
- allowedEdges: ['left', 'right']
69
+ allowedEdges
46
70
  });
47
71
  }
48
72
  });
@@ -1,6 +1,7 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
  import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
3
3
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
4
+ import { getDragBehaviour } from '../../../pm-plugins/drag-and-drop/utils/getDragBehaviour';
4
5
  const RowDropTarget = ({
5
6
  index,
6
7
  localId,
@@ -14,33 +15,56 @@ const RowDropTarget = ({
14
15
  return dropTargetForElements({
15
16
  element: dropTargetRef.current,
16
17
  canDrop({
17
- source
18
+ source,
19
+ input
18
20
  }) {
19
21
  var _data$indexes, _data$indexes2;
20
22
  const data = source.data;
23
+ const behaviour = getDragBehaviour(input);
24
+
25
+ // A move drop is limited too where it can go, however a clone can drop can go anywhere.
26
+ const isDropValid = behaviour === 'move' ? ((_data$indexes = data.indexes) === null || _data$indexes === void 0 ? void 0 : _data$indexes.indexOf(index)) === -1 : behaviour === 'clone';
21
27
  return (
22
28
  // Only draggables of row type can be dropped on this target
23
29
  data.type === 'table-row' &&
24
30
  // Only draggables which came from the same table can be dropped on this target
25
31
  data.localId === localId &&
26
32
  // Only draggables which DO NOT include this drop targets index can be dropped
27
- !!((_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
33
+ !!((_data$indexes2 = data.indexes) !== null && _data$indexes2 !== void 0 && _data$indexes2.length) && isDropValid
28
34
  );
29
35
  },
36
+ getDropEffect: ({
37
+ input
38
+ }) => getDragBehaviour(input) === 'clone' ? 'copy' : 'move',
30
39
  getIsSticky: () => true,
31
40
  getData({
41
+ source,
32
42
  input,
33
43
  element
34
44
  }) {
45
+ var _srcData$indexes;
35
46
  const data = {
36
47
  localId,
37
48
  type: 'table-row',
38
49
  targetIndex: index
39
50
  };
51
+ const srcData = source.data;
52
+ const behaviour = getDragBehaviour(input);
53
+
54
+ // During a move op there's no point in allowing edges to be dropped on which result in no change/move to occur.
55
+ const allowedEdges = behaviour === 'move' ? (_srcData$indexes = srcData.indexes) === null || _srcData$indexes === void 0 ? void 0 : _srcData$indexes.reduce((acc, v) => {
56
+ if (v - index === -1) {
57
+ acc.shift();
58
+ }
59
+ if (v - index === 1) {
60
+ acc.pop();
61
+ }
62
+ return acc;
63
+ }, ['top', 'bottom']) : ['top', 'bottom'];
40
64
  return attachClosestEdge(data, {
41
65
  input,
42
66
  element,
43
- allowedEdges: ['top', 'bottom']
67
+ allowedEdges
44
68
  });
45
69
  }
46
70
  });
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
+ import { Box, Inline, xcss } from '@atlaskit/primitives';
5
+ const tableFullWidthLabelStyles = xcss({
6
+ minWidth: '120px',
7
+ height: "var(--ds-space-300, 24px)",
8
+ display: 'flex',
9
+ justifyContent: 'center',
10
+ alignItems: 'center'
11
+ });
12
+ export const FullWidthDisplay = () => {
13
+ const {
14
+ formatMessage
15
+ } = useIntl();
16
+ return /*#__PURE__*/React.createElement(Box, {
17
+ xcss: tableFullWidthLabelStyles
18
+ }, /*#__PURE__*/React.createElement(Inline, null, formatMessage(messages.fullWidthLabel)));
19
+ };
@@ -5,7 +5,7 @@ import { findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tab
5
5
  import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo } from '../../utils';
6
6
  import { withEditorAnalyticsAPI } from '../../utils/analytics';
7
7
  import { canMove, getTargetIndex } from '../../utils/drag-menu';
8
- import { clearDropTarget, moveSource } from './commands';
8
+ import { clearDropTarget, cloneSource, moveSource } from './commands';
9
9
  export var clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(editorAnalyticsAPI) {
10
10
  return function (inputMethod, sourceType, sourceIndexes, status, tr) {
11
11
  return withEditorAnalyticsAPI(function (_ref) {
@@ -95,4 +95,39 @@ export var moveSourceWithAnalyticsViaShortcut = function moveSourceWithAnalytics
95
95
  return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, selectedIndexes, targetIndex)(state, dispatch);
96
96
  };
97
97
  };
98
+ };
99
+ export var cloneSourceWithAnalytics = function cloneSourceWithAnalytics(editorAnalyticsAPI) {
100
+ return function (inputMethod, sourceType, sourceIndexes, targetIndex, targetDirection, tr) {
101
+ return withEditorAnalyticsAPI(function (_ref3) {
102
+ var selection = _ref3.selection;
103
+ var direction = sourceIndexes[0] > targetIndex ? -1 : 1;
104
+ var _getSelectedTableInfo4 = getSelectedTableInfo(selection),
105
+ totalRowCount = _getSelectedTableInfo4.totalRowCount,
106
+ totalColumnCount = _getSelectedTableInfo4.totalColumnCount;
107
+ return {
108
+ action: sourceType === 'table-row' ? TABLE_ACTION.CLONED_ROW : TABLE_ACTION.CLONED_COLUMN,
109
+ actionSubject: ACTION_SUBJECT.TABLE,
110
+ actionSubjectId: null,
111
+ attributes: {
112
+ inputMethod: inputMethod,
113
+ count: sourceIndexes.length,
114
+ // This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
115
+ // of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
116
+ distance: Math.min.apply(Math, _toConsumableArray(sourceIndexes.map(function (v) {
117
+ return Math.abs(targetIndex - v);
118
+ }))) * direction,
119
+ // If a drop doesn't actually change anything then we're going to mark the event as cancelled.
120
+ status: sourceIndexes.includes(targetIndex) ? TABLE_STATUS.CANCELLED : TABLE_STATUS.SUCCESS,
121
+ totalRowCount: totalRowCount,
122
+ totalColumnCount: totalColumnCount
123
+ },
124
+ eventType: EVENT_TYPE.TRACK
125
+ };
126
+ })(editorAnalyticsAPI)(function (state, dispatch) {
127
+ if (dispatch) {
128
+ cloneSource(sourceType, sourceIndexes, targetIndex, targetDirection, tr)(state, dispatch);
129
+ }
130
+ return true;
131
+ });
132
+ };
98
133
  };
@@ -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';
@@ -112,4 +112,20 @@ export var toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, i
112
112
  }, function (tr) {
113
113
  return tr.setMeta('addToHistory', false);
114
114
  });
115
+ };
116
+ export var cloneSource = function cloneSource(sourceType, sourceIndexes, targetIndex, targetDirection, tr) {
117
+ return createCommand(function (state) {
118
+ return {
119
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
120
+ data: {
121
+ decorationSet: DecorationSet.empty
122
+ }
123
+ };
124
+ }, function (originalTr, state) {
125
+ var nextTr = tr || originalTr;
126
+ var clone = sourceType === 'table-row' ? cloneRow : cloneColumn;
127
+ return clone(state, sourceIndexes, targetIndex, targetDirection, {
128
+ selectAfterClone: true
129
+ })(nextTr);
130
+ });
115
131
  };
@@ -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';
@@ -121,7 +121,9 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
121
121
  sourceIndexes = data.sourceIndexes,
122
122
  targetIndex = data.targetIndex,
123
123
  targetAdjustedIndex = data.targetAdjustedIndex,
124
- direction = data.direction;
124
+ targetDirection = data.targetDirection,
125
+ direction = data.direction,
126
+ behaviour = data.behaviour;
125
127
 
126
128
  // When we drop on a target we will know the targets row/col index for certain,
127
129
  if (sourceType === 'table-row') {
@@ -138,7 +140,11 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
138
140
  return;
139
141
  }
140
142
  requestAnimationFrame(function () {
141
- moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
143
+ if (behaviour === 'clone') {
144
+ cloneSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetIndex, targetDirection, tr)(editorView.state, editorView.dispatch);
145
+ } else {
146
+ moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetAdjustedIndex + (direction === 1 ? -1 : 0), tr)(editorView.state, editorView.dispatch);
147
+ }
142
148
 
143
149
  // force a colgroup update here, otherwise dropped columns don't have
144
150
  // the correct width immediately after the drop
@@ -0,0 +1,7 @@
1
+ import { browser } from '@atlaskit/editor-common/utils';
2
+ export var getDragBehaviour = function getDragBehaviour(_ref) {
3
+ var altKey = _ref.altKey,
4
+ ctrlKey = _ref.ctrlKey;
5
+ var isCloneModifierKeyPressed = browser.mac ? altKey : ctrlKey;
6
+ return isCloneModifierKeyPressed ? 'clone' : 'move';
7
+ };
@@ -1,4 +1,6 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import { extractClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
3
+ import { getDragBehaviour } from './getDragBehaviour';
2
4
  export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref) {
3
5
  var _extractClosestEdge;
4
6
  var location = _ref.location,
@@ -36,9 +38,11 @@ export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref)
36
38
  // the new target index to be 1 index higher.
37
39
  var targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
38
40
 
39
- // since only consecutive rows/cols can be moved we can assume that if the first index is greater then
40
- // the target index, the then the direction of the DnD is decreasing
41
- var direction = sourceIndexes[0] > targetIndex ? -1 : 1;
41
+ // if the min index is greater then the target index, the then the direction of the DnD is decreasing
42
+ // if the target is within the min/max index then we can assume that no direction exists so it will be 0.
43
+ var srcMin = Math.min.apply(Math, _toConsumableArray(sourceIndexes));
44
+ var srcMax = Math.max.apply(Math, _toConsumableArray(sourceIndexes));
45
+ var direction = targetIndex >= srcMin && targetIndex <= srcMax ? 0 : srcMin >= targetIndex ? -1 : 1;
42
46
  return {
43
47
  sourceType: sourceType,
44
48
  sourceLocalId: sourceLocalId,
@@ -48,6 +52,8 @@ export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref)
48
52
  targetIndex: targetIndex,
49
53
  targetAdjustedIndex: targetIndex + targetOffset,
50
54
  targetClosestEdge: targetClosestEdge,
51
- direction: direction
55
+ targetDirection: targetClosestEdge === 'top' || targetClosestEdge === 'left' ? 'start' : 'end',
56
+ direction: direction,
57
+ behaviour: getDragBehaviour(location.current.input)
52
58
  };
53
59
  };
@@ -24,6 +24,7 @@ import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizin
24
24
  import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
25
25
  import { canMergeCells } from './transforms';
26
26
  import { TableCssClassName } from './types';
27
+ import { FullWidthDisplay } from './ui/TableFullWidthLabel';
27
28
  import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes } from './utils';
28
29
  export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
29
30
  var formatMessage = _ref.formatMessage;
@@ -296,16 +297,61 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
296
297
 
297
298
  // We don't want to show floating toolbar while resizing the table
298
299
  var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
299
- if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
300
+ var isTableScalingEnabled = pluginState.isTableScalingEnabled,
301
+ widthToWidest = pluginState.widthToWidest;
302
+ if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
303
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
304
+ stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
300
305
  var nodeType = state.schema.nodes.table;
306
+ var getDomRef = function getDomRef(editorView) {
307
+ var element;
308
+ var domAtPos = editorView.domAtPos.bind(editorView);
309
+ var parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
310
+ if (parent) {
311
+ var tableRef = parent.querySelector('table') || undefined;
312
+ if (tableRef) {
313
+ element = closestElement(tableRef, ".".concat(TableCssClassName.TABLE_NODE_WRAPPER)) || undefined;
314
+ }
315
+ }
316
+ return element;
317
+ };
318
+ var fullWidthLabel = {
319
+ id: 'editor.table.fullWidthLabel',
320
+ type: 'custom',
321
+ fallback: [],
322
+ render: function render() {
323
+ return jsx(FullWidthDisplay, {
324
+ key: 'full-width-label'
325
+ });
326
+ }
327
+ };
328
+ return {
329
+ title: 'Table floating label',
330
+ getDomRef: getDomRef,
331
+ nodeType: nodeType,
332
+ key: 'full-width-label',
333
+ offset: [0, 18],
334
+ absoluteOffset: stickyScrollbar ? {
335
+ top: -6
336
+ } : {
337
+ top: 0
338
+ },
339
+ zIndex: akEditorFloatingPanelZIndex + 1,
340
+ // Place the context menu slightly above the others
341
+ items: [fullWidthLabel],
342
+ scrollable: true
343
+ };
344
+ }
345
+ if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
346
+ var _nodeType = state.schema.nodes.table;
301
347
  var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
302
348
  var _getPluginState2 = getPluginState(state),
303
349
  _getPluginState2$isTa = _getPluginState2.isTableScalingEnabled,
304
- isTableScalingEnabled = _getPluginState2$isTa === void 0 ? false : _getPluginState2$isTa;
350
+ _isTableScalingEnabled = _getPluginState2$isTa === void 0 ? false : _getPluginState2$isTa;
305
351
  var cellItems;
306
- cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled);
352
+ cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, _isTableScalingEnabled);
307
353
  var columnSettingsItems;
308
- columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled) : [];
354
+ columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, _isTableScalingEnabled) : [];
309
355
  var colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
310
356
 
311
357
  // Check if we need to show confirm dialog for delete button
@@ -332,10 +378,10 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
332
378
  };
333
379
  };
334
380
  }
335
- var getDomRef = function getDomRef(editorView) {
381
+ var _getDomRef = function _getDomRef(editorView) {
336
382
  var element;
337
383
  var domAtPos = editorView.domAtPos.bind(editorView);
338
- var parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
384
+ var parent = findParentDomRefOfType(_nodeType, domAtPos)(state.selection);
339
385
  if (parent) {
340
386
  var tableRef = parent.querySelector('table') || undefined;
341
387
  if (tableRef) {
@@ -344,14 +390,14 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
344
390
  }
345
391
  return element;
346
392
  };
347
- var _getEditorFeatureFlag = getEditorFeatureFlags(),
348
- stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
393
+ var _getEditorFeatureFlag2 = getEditorFeatureFlags(),
394
+ _stickyScrollbar = _getEditorFeatureFlag2.stickyScrollbar;
349
395
  return {
350
396
  title: 'Table floating controls',
351
- getDomRef: getDomRef,
352
- nodeType: nodeType,
397
+ getDomRef: _getDomRef,
398
+ nodeType: _nodeType,
353
399
  offset: [0, 18],
354
- absoluteOffset: stickyScrollbar ? {
400
+ absoluteOffset: _stickyScrollbar ? {
355
401
  top: -6
356
402
  } : {
357
403
  top: 0
@@ -366,7 +412,7 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
366
412
  items: [{
367
413
  state: state,
368
414
  formatMessage: intl.formatMessage,
369
- nodeType: nodeType,
415
+ nodeType: _nodeType,
370
416
  onMouseEnter: hoverTable(false, true),
371
417
  onMouseLeave: clearHoverSelection(),
372
418
  onFocus: hoverTable(false, true),
@@ -1,6 +1,7 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
  import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
3
3
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
4
+ import { getDragBehaviour } from '../../../pm-plugins/drag-and-drop/utils/getDragBehaviour';
4
5
  export var ColumnDropTarget = function ColumnDropTarget(_ref) {
5
6
  var index = _ref.index,
6
7
  localId = _ref.localId,
@@ -16,32 +17,56 @@ export var ColumnDropTarget = function ColumnDropTarget(_ref) {
16
17
  element: dropTargetRef.current,
17
18
  canDrop: function canDrop(_ref2) {
18
19
  var _data$indexes, _data$indexes2;
19
- var source = _ref2.source;
20
+ var source = _ref2.source,
21
+ input = _ref2.input;
20
22
  var data = source.data;
23
+ var behaviour = getDragBehaviour(input);
24
+
25
+ // A move drop is limited too where it can go, however a clone can drop can go anywhere.
26
+ var isDropValid = behaviour === 'move' ? ((_data$indexes = data.indexes) === null || _data$indexes === void 0 ? void 0 : _data$indexes.indexOf(index)) === -1 : behaviour === 'clone';
21
27
  return (
22
28
  // Only draggables of row type can be dropped on this target
23
29
  data.type === 'table-column' &&
24
30
  // Only draggables which came from the same table can be dropped on this target
25
31
  data.localId === localId &&
26
32
  // Only draggables which DO NOT include this drop targets index can be dropped
27
- !!((_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
33
+ !!((_data$indexes2 = data.indexes) !== null && _data$indexes2 !== void 0 && _data$indexes2.length) && isDropValid
28
34
  );
29
35
  },
36
+ getDropEffect: function getDropEffect(_ref3) {
37
+ var input = _ref3.input;
38
+ return getDragBehaviour(input) === 'clone' ? 'copy' : 'move';
39
+ },
30
40
  getIsSticky: function getIsSticky() {
31
41
  return true;
32
42
  },
33
- getData: function getData(_ref3) {
34
- var input = _ref3.input,
35
- element = _ref3.element;
43
+ getData: function getData(_ref4) {
44
+ var _srcData$indexes;
45
+ var source = _ref4.source,
46
+ input = _ref4.input,
47
+ element = _ref4.element;
36
48
  var data = {
37
49
  localId: localId,
38
50
  type: 'table-column',
39
51
  targetIndex: index
40
52
  };
53
+ var srcData = source.data;
54
+ var behaviour = getDragBehaviour(input);
55
+
56
+ // During a move op there's no point in allowing edges to be dropped on which result in no change/move to occur.
57
+ var allowedEdges = behaviour === 'move' ? (_srcData$indexes = srcData.indexes) === null || _srcData$indexes === void 0 ? void 0 : _srcData$indexes.reduce(function (acc, v) {
58
+ if (v - index === -1) {
59
+ acc.shift();
60
+ }
61
+ if (v - index === 1) {
62
+ acc.pop();
63
+ }
64
+ return acc;
65
+ }, ['left', 'right']) : ['left', 'right'];
41
66
  return attachClosestEdge(data, {
42
67
  input: input,
43
68
  element: element,
44
- allowedEdges: ['left', 'right']
69
+ allowedEdges: allowedEdges
45
70
  });
46
71
  }
47
72
  });
@@ -1,6 +1,7 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
  import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
3
3
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
4
+ import { getDragBehaviour } from '../../../pm-plugins/drag-and-drop/utils/getDragBehaviour';
4
5
  var RowDropTarget = function RowDropTarget(_ref) {
5
6
  var index = _ref.index,
6
7
  localId = _ref.localId,
@@ -14,32 +15,56 @@ var RowDropTarget = function RowDropTarget(_ref) {
14
15
  element: dropTargetRef.current,
15
16
  canDrop: function canDrop(_ref2) {
16
17
  var _data$indexes, _data$indexes2;
17
- var source = _ref2.source;
18
+ var source = _ref2.source,
19
+ input = _ref2.input;
18
20
  var data = source.data;
21
+ var behaviour = getDragBehaviour(input);
22
+
23
+ // A move drop is limited too where it can go, however a clone can drop can go anywhere.
24
+ var isDropValid = behaviour === 'move' ? ((_data$indexes = data.indexes) === null || _data$indexes === void 0 ? void 0 : _data$indexes.indexOf(index)) === -1 : behaviour === 'clone';
19
25
  return (
20
26
  // Only draggables of row type can be dropped on this target
21
27
  data.type === 'table-row' &&
22
28
  // Only draggables which came from the same table can be dropped on this target
23
29
  data.localId === localId &&
24
30
  // Only draggables which DO NOT include this drop targets index can be dropped
25
- !!((_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
31
+ !!((_data$indexes2 = data.indexes) !== null && _data$indexes2 !== void 0 && _data$indexes2.length) && isDropValid
26
32
  );
27
33
  },
34
+ getDropEffect: function getDropEffect(_ref3) {
35
+ var input = _ref3.input;
36
+ return getDragBehaviour(input) === 'clone' ? 'copy' : 'move';
37
+ },
28
38
  getIsSticky: function getIsSticky() {
29
39
  return true;
30
40
  },
31
- getData: function getData(_ref3) {
32
- var input = _ref3.input,
33
- element = _ref3.element;
41
+ getData: function getData(_ref4) {
42
+ var _srcData$indexes;
43
+ var source = _ref4.source,
44
+ input = _ref4.input,
45
+ element = _ref4.element;
34
46
  var data = {
35
47
  localId: localId,
36
48
  type: 'table-row',
37
49
  targetIndex: index
38
50
  };
51
+ var srcData = source.data;
52
+ var behaviour = getDragBehaviour(input);
53
+
54
+ // During a move op there's no point in allowing edges to be dropped on which result in no change/move to occur.
55
+ var allowedEdges = behaviour === 'move' ? (_srcData$indexes = srcData.indexes) === null || _srcData$indexes === void 0 ? void 0 : _srcData$indexes.reduce(function (acc, v) {
56
+ if (v - index === -1) {
57
+ acc.shift();
58
+ }
59
+ if (v - index === 1) {
60
+ acc.pop();
61
+ }
62
+ return acc;
63
+ }, ['top', 'bottom']) : ['top', 'bottom'];
39
64
  return attachClosestEdge(data, {
40
65
  input: input,
41
66
  element: element,
42
- allowedEdges: ['top', 'bottom']
67
+ allowedEdges: allowedEdges
43
68
  });
44
69
  }
45
70
  });
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
+ import { Box, Inline, xcss } from '@atlaskit/primitives';
5
+ var tableFullWidthLabelStyles = xcss({
6
+ minWidth: '120px',
7
+ height: "var(--ds-space-300, 24px)",
8
+ display: 'flex',
9
+ justifyContent: 'center',
10
+ alignItems: 'center'
11
+ });
12
+ export var FullWidthDisplay = function FullWidthDisplay() {
13
+ var _useIntl = useIntl(),
14
+ formatMessage = _useIntl.formatMessage;
15
+ return /*#__PURE__*/React.createElement(Box, {
16
+ xcss: tableFullWidthLabelStyles
17
+ }, /*#__PURE__*/React.createElement(Inline, null, formatMessage(messages.fullWidthLabel)));
18
+ };
@@ -6,3 +6,4 @@ import type { DraggableData, DraggableType } from '../../types';
6
6
  export declare const clearDropTargetWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, sourceIndexes: number[] | undefined, status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID, tr?: Transaction) => Command;
7
7
  export declare const moveSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT, sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, tr?: Transaction) => Command;
8
8
  export declare const moveSourceWithAnalyticsViaShortcut: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (sourceType: DraggableType, direction: DraggableData['direction']) => Command;
9
+ export declare const cloneSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT, sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, targetDirection: 'start' | 'end', tr?: Transaction) => Command;