@atlaskit/editor-plugin-table 5.3.2 → 5.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -9
  3. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +1 -4
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +9 -9
  5. package/dist/cjs/plugins/table/ui/DragPreview/index.js +39 -0
  6. package/dist/cjs/plugins/table/ui/Icons/DragInMotionIcon.js +55 -0
  7. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +30 -5
  8. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +1 -4
  9. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -10
  10. package/dist/es2019/plugins/table/ui/DragPreview/index.js +33 -0
  11. package/dist/es2019/plugins/table/ui/Icons/DragInMotionIcon.js +47 -0
  12. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +30 -4
  13. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +1 -4
  14. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +9 -9
  15. package/dist/esm/plugins/table/ui/DragPreview/index.js +32 -0
  16. package/dist/esm/plugins/table/ui/Icons/DragInMotionIcon.js +48 -0
  17. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +3 -1
  18. package/dist/types/plugins/table/ui/DragPreview/index.d.ts +6 -0
  19. package/dist/types/plugins/table/ui/Icons/DragInMotionIcon.d.ts +6 -0
  20. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +3 -1
  21. package/dist/types-ts4.5/plugins/table/ui/DragPreview/index.d.ts +6 -0
  22. package/dist/types-ts4.5/plugins/table/ui/Icons/DragInMotionIcon.d.ts +6 -0
  23. package/package.json +4 -3
  24. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +42 -6
  25. package/src/plugins/table/pm-plugins/drag-and-drop/plugin-factory.ts +0 -3
  26. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +19 -12
  27. package/src/plugins/table/ui/DragPreview/index.tsx +45 -0
  28. package/src/plugins/table/ui/Icons/DragInMotionIcon.tsx +60 -0
  29. package/tsconfig.app.json +3 -0
  30. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/handlers.js +0 -24
  31. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/handlers.js +0 -10
  32. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/handlers.js +0 -18
  33. package/dist/types/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +0 -3
  34. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +0 -3
  35. package/src/plugins/table/pm-plugins/drag-and-drop/handlers.ts +0 -35
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.3.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#41793](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41793) [`7e48d39f900`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7e48d39f900) - Connected the Pragmatic DnD monitor to the new drop target insert line decorations
8
+
9
+ ## 5.3.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [#41701](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41701) [`168e0da8a1c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/168e0da8a1c) - [ux] ED-20425: Added DragPreview and DragInMotionIcon
14
+
3
15
  ## 5.3.2
4
16
 
5
17
  ### Patch Changes
@@ -3,11 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.updatePluginStateDecorations = exports.setDropTarget = exports.getDecorations = exports.clearDropTarget = void 0;
6
+ exports.updatePluginStateDecorations = exports.setDropTarget = exports.moveSource = exports.getDecorations = exports.clearDropTarget = void 0;
7
7
  var _view = require("@atlaskit/editor-prosemirror/view");
8
+ var _utils = require("@atlaskit/editor-tables/utils");
8
9
  var _types = require("../../types");
9
- var _utils = require("../../utils");
10
+ var _utils2 = require("../../utils");
10
11
  var _actions = require("./actions");
12
+ var _consts = require("./consts");
11
13
  var _pluginFactory = require("./plugin-factory");
12
14
  var _pluginKey = require("./plugin-key");
13
15
  // TODO: This command is a placeholder example. Please replace this if required.
@@ -16,7 +18,7 @@ var getDecorations = exports.getDecorations = function getDecorations(state) {
16
18
  return ((_pluginKey$getState = _pluginKey.pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.decorationSet) || _view.DecorationSet.empty;
17
19
  };
18
20
  var updatePluginStateDecorations = exports.updatePluginStateDecorations = function updatePluginStateDecorations(state, decorations, key) {
19
- return (0, _utils.updateDecorations)(state.doc, getDecorations(state), decorations, key);
21
+ return (0, _utils2.updateDecorations)(state.doc, getDecorations(state), decorations, key);
20
22
  };
21
23
  var setDropTarget = exports.setDropTarget = function setDropTarget(type, index, tr) {
22
24
  return (0, _pluginFactory.createCommand)(function (state) {
@@ -28,9 +30,9 @@ var setDropTarget = exports.setDropTarget = function setDropTarget(type, index,
28
30
  }
29
31
  var decorationSet = _view.DecorationSet.empty;
30
32
  if (type === 'column') {
31
- decorationSet = updatePluginStateDecorations(state, (0, _utils.createColumnInsertLine)(index, state.selection), _types.TableDecorations.COLUMN_INSERT_LINE);
33
+ decorationSet = updatePluginStateDecorations(state, (0, _utils2.createColumnInsertLine)(index, state.selection), _types.TableDecorations.COLUMN_INSERT_LINE);
32
34
  } else if (type === 'row') {
33
- decorationSet = updatePluginStateDecorations(state, (0, _utils.createRowInsertLine)(index, state.selection), _types.TableDecorations.ROW_INSERT_LINE);
35
+ decorationSet = updatePluginStateDecorations(state, (0, _utils2.createRowInsertLine)(index, state.selection), _types.TableDecorations.ROW_INSERT_LINE);
34
36
  }
35
37
  return {
36
38
  type: _actions.DragAndDropActionType.SET_DROP_TARGET,
@@ -45,12 +47,36 @@ var setDropTarget = exports.setDropTarget = function setDropTarget(type, index,
45
47
  });
46
48
  };
47
49
  var clearDropTarget = exports.clearDropTarget = function clearDropTarget(tr) {
48
- return (0, _pluginFactory.createCommand)({
49
- type: _actions.DragAndDropActionType.CLEAR_DROP_TARGET,
50
- data: {
51
- decorationSet: _view.DecorationSet.empty
50
+ return (0, _pluginFactory.createCommand)(function (state) {
51
+ var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
52
+ dropTargetType = _getPluginState2.dropTargetType,
53
+ dropTargetIndex = _getPluginState2.dropTargetIndex;
54
+ if (dropTargetType === _consts.DropTargetType.NONE && dropTargetIndex === 0) {
55
+ return false;
52
56
  }
57
+ return {
58
+ type: _actions.DragAndDropActionType.CLEAR_DROP_TARGET,
59
+ data: {
60
+ decorationSet: _view.DecorationSet.empty
61
+ }
62
+ };
53
63
  }, function (originalTr) {
54
64
  return (tr || originalTr).setMeta('addToHistory', false);
55
65
  });
66
+ };
67
+ var moveSource = exports.moveSource = function moveSource(sourceType, sourceIndex, targetIndex) {
68
+ return (0, _pluginFactory.createCommand)(function (state) {
69
+ return {
70
+ type: _actions.DragAndDropActionType.CLEAR_DROP_TARGET,
71
+ data: {
72
+ decorationSet: _view.DecorationSet.empty
73
+ }
74
+ };
75
+ }, function (tr) {
76
+ if (sourceIndex === targetIndex) {
77
+ return tr.setMeta('addToHistory', false);
78
+ }
79
+ var move = sourceType === 'table-row' ? _utils.moveRow : _utils.moveColumn;
80
+ return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
81
+ });
56
82
  };
@@ -8,7 +8,6 @@ exports.getPluginState = exports.createPluginState = exports.createCommand = voi
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _utils = require("@atlaskit/editor-common/utils");
10
10
  var _pluginKey = require("../plugin-key");
11
- var _handlers = require("./handlers");
12
11
  var _pluginKey2 = require("./plugin-key");
13
12
  var _reducer = _interopRequireDefault(require("./reducer"));
14
13
  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; }
@@ -29,9 +28,7 @@ var _pluginFactory = (0, _utils.pluginFactory)(_pluginKey2.pluginKey, _reducer.d
29
28
  });
30
29
  }
31
30
  return pluginState;
32
- },
33
- onDocChanged: _handlers.handleDocOrSelectionChanged,
34
- onSelectionChanged: _handlers.handleDocOrSelectionChanged
31
+ }
35
32
  }),
36
33
  createPluginState = exports.createPluginState = _pluginFactory.createPluginState,
37
34
  createCommand = exports.createCommand = _pluginFactory.createCommand,
@@ -8,10 +8,10 @@ exports.createPlugin = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
10
  var _view = require("@atlaskit/editor-prosemirror/view");
11
- var _utils = require("@atlaskit/editor-tables/utils");
12
11
  var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
13
12
  var _mergedCells = require("../../utils/merged-cells");
14
13
  var _pluginFactory = require("../plugin-factory");
14
+ var _commands = require("./commands");
15
15
  var _consts = require("./consts");
16
16
  var _pluginFactory2 = require("./plugin-factory");
17
17
  var _pluginKey = require("./plugin-key");
@@ -53,25 +53,25 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
53
53
  },
54
54
  onDrag: function onDrag(event) {
55
55
  var data = (0, _monitor.getDraggableDataFromEvent)(event);
56
-
57
56
  // If no data can be found then it's most like we do not want to perform any drag actions
58
57
  if (!data) {
58
+ (0, _commands.clearDropTarget)()(editorView.state, editorView.dispatch);
59
59
  return;
60
60
  }
61
61
 
62
62
  // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
63
63
  // insert location as to where the draggable will most likely be go. For example;
64
- // const { sourceType, targetAdjustedIndex } = data;
65
- // const highlight = sourceType === 'table-row' ? highlightRow : highlightColumn;
66
- // return editorView.dispatch(
67
- // highlight(targetAdjustedIndex)(editorView.state.tr),
68
- // );
64
+ var sourceType = data.sourceType,
65
+ targetAdjustedIndex = data.targetAdjustedIndex;
66
+ var dropTargetType = sourceType === 'table-row' ? _consts.DropTargetType.ROW : _consts.DropTargetType.COLUMN;
67
+ (0, _commands.setDropTarget)(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
69
68
  },
70
69
  onDrop: function onDrop(event) {
71
70
  var data = (0, _monitor.getDraggableDataFromEvent)(event);
72
71
 
73
72
  // If no data can be found then it's most like we do not want to perform any drop action
74
73
  if (!data) {
74
+ (0, _commands.clearDropTarget)()(editorView.state, editorView.dispatch);
75
75
  return;
76
76
  }
77
77
  var sourceType = data.sourceType,
@@ -81,12 +81,12 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
81
81
  // If the drop target index contains merged cells then we should not allow the drop to occur.
82
82
  var hasMergedCells = sourceType === 'table-row' ? _mergedCells.hasMergedCellsInRow : _mergedCells.hasMergedCellsInColumn;
83
83
  if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
84
+ (0, _commands.clearDropTarget)()(editorView.state, editorView.dispatch);
84
85
  return;
85
86
  }
86
- var move = sourceType === 'table-row' ? _utils.moveRow : _utils.moveColumn;
87
87
  var _sourceIndexes = (0, _slicedToArray2.default)(sourceIndexes, 1),
88
88
  sourceIndex = _sourceIndexes[0];
89
- return editorView.dispatch(move(sourceIndex, targetAdjustedIndex)(editorView.state.tr));
89
+ (0, _commands.moveSource)(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
90
90
  }
91
91
  })
92
92
  };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DragPreview = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _primitives = require("@atlaskit/primitives");
10
+ var _DragInMotionIcon = require("../Icons/DragInMotionIcon");
11
+ var boxStyles = (0, _primitives.xcss)({
12
+ borderColor: 'color.border.focused',
13
+ borderStyle: 'solid',
14
+ borderRadius: 'border.radius.100',
15
+ borderWidth: 'border.width.outline',
16
+ backgroundColor: 'color.blanket.selected'
17
+ });
18
+ var DragPreview = exports.DragPreview = function DragPreview(_ref) {
19
+ var direction = _ref.direction,
20
+ width = _ref.width,
21
+ height = _ref.height;
22
+ var marginLeft = direction === 'row' ? -14 : width / 2 - 14;
23
+ var marginTop = direction === 'row' ? height / 2 - 14 : -10;
24
+ var transform = direction === 'row' ? 'rotate(90deg)' : 'none';
25
+ return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
26
+ xcss: boxStyles,
27
+ style: {
28
+ width: "".concat(width, "px"),
29
+ height: "".concat(height, "px")
30
+ }
31
+ }, /*#__PURE__*/_react.default.createElement(_DragInMotionIcon.DragInMotionIcon, {
32
+ style: {
33
+ position: 'absolute',
34
+ marginLeft: "".concat(marginLeft, "px"),
35
+ marginTop: "".concat(marginTop, "px"),
36
+ transform: transform
37
+ }
38
+ }));
39
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DragInMotionIcon = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var DragInMotionIcon = exports.DragInMotionIcon = function DragInMotionIcon(_ref) {
10
+ var style = _ref.style;
11
+ return /*#__PURE__*/_react.default.createElement("svg", {
12
+ width: "28",
13
+ height: "20",
14
+ viewBox: "0 0 28 20",
15
+ fill: "none",
16
+ xmlns: "http://www.w3.org/2000/svg",
17
+ style: style
18
+ }, /*#__PURE__*/_react.default.createElement("rect", {
19
+ x: "1",
20
+ y: "1",
21
+ width: "26",
22
+ height: "18",
23
+ rx: "5",
24
+ fill: "var(--ds-background-accent-blue-subtle, #579DFF)"
25
+ }), /*#__PURE__*/_react.default.createElement("rect", {
26
+ x: "9",
27
+ y: "6",
28
+ width: "2",
29
+ height: "8",
30
+ rx: "1",
31
+ fill: "var(--ds-border-inverse, #FFFFFF)"
32
+ }), /*#__PURE__*/_react.default.createElement("rect", {
33
+ x: "13",
34
+ y: "6",
35
+ width: "2",
36
+ height: "8",
37
+ rx: "1",
38
+ fill: "var(--ds-border-inverse, #FFFFFF)"
39
+ }), /*#__PURE__*/_react.default.createElement("rect", {
40
+ x: "17",
41
+ y: "6",
42
+ width: "2",
43
+ height: "8",
44
+ rx: "1",
45
+ fill: "var(--ds-border-inverse, #FFFFFF)"
46
+ }), /*#__PURE__*/_react.default.createElement("rect", {
47
+ x: "1",
48
+ y: "1",
49
+ width: "26",
50
+ height: "18",
51
+ rx: "5",
52
+ stroke: "var(--ds-border-inverse, #FFFFFF)",
53
+ strokeWidth: "2"
54
+ }));
55
+ };
@@ -1,7 +1,9 @@
1
1
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+ import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
2
3
  import { TableDecorations } from '../../types';
3
4
  import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
4
5
  import { DragAndDropActionType } from './actions';
6
+ import { DropTargetType } from './consts';
5
7
  import { createCommand, getPluginState } from './plugin-factory';
6
8
  import { pluginKey } from './plugin-key';
7
9
 
@@ -34,9 +36,32 @@ export const setDropTarget = (type, index, tr) => createCommand(state => {
34
36
  }
35
37
  };
36
38
  }, originalTr => (tr || originalTr).setMeta('addToHistory', false));
37
- export const clearDropTarget = tr => createCommand({
38
- type: DragAndDropActionType.CLEAR_DROP_TARGET,
39
- data: {
40
- decorationSet: DecorationSet.empty
39
+ export const clearDropTarget = tr => createCommand(state => {
40
+ const {
41
+ dropTargetType,
42
+ dropTargetIndex
43
+ } = getPluginState(state);
44
+ if (dropTargetType === DropTargetType.NONE && dropTargetIndex === 0) {
45
+ return false;
46
+ }
47
+ return {
48
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
49
+ data: {
50
+ decorationSet: DecorationSet.empty
51
+ }
52
+ };
53
+ }, originalTr => (tr || originalTr).setMeta('addToHistory', false));
54
+ export const moveSource = (sourceType, sourceIndex, targetIndex) => createCommand(state => {
55
+ return {
56
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
57
+ data: {
58
+ decorationSet: DecorationSet.empty
59
+ }
60
+ };
61
+ }, tr => {
62
+ if (sourceIndex === targetIndex) {
63
+ return tr.setMeta('addToHistory', false);
41
64
  }
42
- }, originalTr => (tr || originalTr).setMeta('addToHistory', false));
65
+ const move = sourceType === 'table-row' ? moveRow : moveColumn;
66
+ return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
67
+ });
@@ -1,6 +1,5 @@
1
1
  import { pluginFactory } from '@atlaskit/editor-common/utils';
2
2
  import { pluginKey as tablePluginKey } from '../plugin-key';
3
- import { handleDocOrSelectionChanged } from './handlers';
4
3
  import { pluginKey } from './plugin-key';
5
4
  import reducer from './reducer';
6
5
  export const {
@@ -26,7 +25,5 @@ export const {
26
25
  };
27
26
  }
28
27
  return pluginState;
29
- },
30
- onDocChanged: handleDocOrSelectionChanged,
31
- onSelectionChanged: handleDocOrSelectionChanged
28
+ }
32
29
  });
@@ -1,9 +1,9 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
- import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
4
3
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
5
4
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
6
5
  import { getPluginState as getTablePluginState } from '../plugin-factory';
6
+ import { clearDropTarget, moveSource, setDropTarget } from './commands';
7
7
  import { DropTargetType } from './consts';
8
8
  import { createPluginState, getPluginState } from './plugin-factory';
9
9
  import { pluginKey } from './plugin-key';
@@ -46,26 +46,27 @@ export const createPlugin = (dispatch, eventDispatcher) => {
46
46
  },
47
47
  onDrag(event) {
48
48
  const data = getDraggableDataFromEvent(event);
49
-
50
49
  // If no data can be found then it's most like we do not want to perform any drag actions
51
50
  if (!data) {
51
+ clearDropTarget()(editorView.state, editorView.dispatch);
52
52
  return;
53
53
  }
54
54
 
55
55
  // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
56
56
  // insert location as to where the draggable will most likely be go. For example;
57
- // const { sourceType, targetAdjustedIndex } = data;
58
- // const highlight = sourceType === 'table-row' ? highlightRow : highlightColumn;
59
- // return editorView.dispatch(
60
- // highlight(targetAdjustedIndex)(editorView.state.tr),
61
- // );
57
+ const {
58
+ sourceType,
59
+ targetAdjustedIndex
60
+ } = data;
61
+ const dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
62
+ setDropTarget(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
62
63
  },
63
-
64
64
  onDrop(event) {
65
65
  const data = getDraggableDataFromEvent(event);
66
66
 
67
67
  // If no data can be found then it's most like we do not want to perform any drop action
68
68
  if (!data) {
69
+ clearDropTarget()(editorView.state, editorView.dispatch);
69
70
  return;
70
71
  }
71
72
  const {
@@ -77,11 +78,11 @@ export const createPlugin = (dispatch, eventDispatcher) => {
77
78
  // If the drop target index contains merged cells then we should not allow the drop to occur.
78
79
  const hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
79
80
  if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
81
+ clearDropTarget()(editorView.state, editorView.dispatch);
80
82
  return;
81
83
  }
82
- const move = sourceType === 'table-row' ? moveRow : moveColumn;
83
84
  const [sourceIndex] = sourceIndexes;
84
- return editorView.dispatch(move(sourceIndex, targetAdjustedIndex)(editorView.state.tr));
85
+ moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
85
86
  }
86
87
  })
87
88
  };
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { Box, xcss } from '@atlaskit/primitives';
3
+ import { DragInMotionIcon } from '../Icons/DragInMotionIcon';
4
+ const boxStyles = xcss({
5
+ borderColor: 'color.border.focused',
6
+ borderStyle: 'solid',
7
+ borderRadius: 'border.radius.100',
8
+ borderWidth: 'border.width.outline',
9
+ backgroundColor: 'color.blanket.selected'
10
+ });
11
+ export const DragPreview = ({
12
+ direction,
13
+ width,
14
+ height
15
+ }) => {
16
+ let marginLeft = direction === 'row' ? -14 : width / 2 - 14;
17
+ let marginTop = direction === 'row' ? height / 2 - 14 : -10;
18
+ let transform = direction === 'row' ? 'rotate(90deg)' : 'none';
19
+ return /*#__PURE__*/React.createElement(Box, {
20
+ xcss: boxStyles,
21
+ style: {
22
+ width: `${width}px`,
23
+ height: `${height}px`
24
+ }
25
+ }, /*#__PURE__*/React.createElement(DragInMotionIcon, {
26
+ style: {
27
+ position: 'absolute',
28
+ marginLeft: `${marginLeft}px`,
29
+ marginTop: `${marginTop}px`,
30
+ transform: transform
31
+ }
32
+ }));
33
+ };
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ export const DragInMotionIcon = ({
3
+ style
4
+ }) => /*#__PURE__*/React.createElement("svg", {
5
+ width: "28",
6
+ height: "20",
7
+ viewBox: "0 0 28 20",
8
+ fill: "none",
9
+ xmlns: "http://www.w3.org/2000/svg",
10
+ style: style
11
+ }, /*#__PURE__*/React.createElement("rect", {
12
+ x: "1",
13
+ y: "1",
14
+ width: "26",
15
+ height: "18",
16
+ rx: "5",
17
+ fill: "var(--ds-background-accent-blue-subtle, #579DFF)"
18
+ }), /*#__PURE__*/React.createElement("rect", {
19
+ x: "9",
20
+ y: "6",
21
+ width: "2",
22
+ height: "8",
23
+ rx: "1",
24
+ fill: "var(--ds-border-inverse, #FFFFFF)"
25
+ }), /*#__PURE__*/React.createElement("rect", {
26
+ x: "13",
27
+ y: "6",
28
+ width: "2",
29
+ height: "8",
30
+ rx: "1",
31
+ fill: "var(--ds-border-inverse, #FFFFFF)"
32
+ }), /*#__PURE__*/React.createElement("rect", {
33
+ x: "17",
34
+ y: "6",
35
+ width: "2",
36
+ height: "8",
37
+ rx: "1",
38
+ fill: "var(--ds-border-inverse, #FFFFFF)"
39
+ }), /*#__PURE__*/React.createElement("rect", {
40
+ x: "1",
41
+ y: "1",
42
+ width: "26",
43
+ height: "18",
44
+ rx: "5",
45
+ stroke: "var(--ds-border-inverse, #FFFFFF)",
46
+ strokeWidth: "2"
47
+ }));
@@ -1,7 +1,9 @@
1
1
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+ import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
2
3
  import { TableDecorations } from '../../types';
3
4
  import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
4
5
  import { DragAndDropActionType } from './actions';
6
+ import { DropTargetType } from './consts';
5
7
  import { createCommand, getPluginState } from './plugin-factory';
6
8
  import { pluginKey } from './plugin-key';
7
9
 
@@ -40,12 +42,36 @@ export var setDropTarget = function setDropTarget(type, index, tr) {
40
42
  });
41
43
  };
42
44
  export var clearDropTarget = function clearDropTarget(tr) {
43
- return createCommand({
44
- type: DragAndDropActionType.CLEAR_DROP_TARGET,
45
- data: {
46
- decorationSet: DecorationSet.empty
45
+ return createCommand(function (state) {
46
+ var _getPluginState2 = getPluginState(state),
47
+ dropTargetType = _getPluginState2.dropTargetType,
48
+ dropTargetIndex = _getPluginState2.dropTargetIndex;
49
+ if (dropTargetType === DropTargetType.NONE && dropTargetIndex === 0) {
50
+ return false;
47
51
  }
52
+ return {
53
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
54
+ data: {
55
+ decorationSet: DecorationSet.empty
56
+ }
57
+ };
48
58
  }, function (originalTr) {
49
59
  return (tr || originalTr).setMeta('addToHistory', false);
50
60
  });
61
+ };
62
+ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex) {
63
+ return createCommand(function (state) {
64
+ return {
65
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
66
+ data: {
67
+ decorationSet: DecorationSet.empty
68
+ }
69
+ };
70
+ }, function (tr) {
71
+ if (sourceIndex === targetIndex) {
72
+ return tr.setMeta('addToHistory', false);
73
+ }
74
+ var move = sourceType === 'table-row' ? moveRow : moveColumn;
75
+ return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
76
+ });
51
77
  };
@@ -3,7 +3,6 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  import { pluginFactory } from '@atlaskit/editor-common/utils';
5
5
  import { pluginKey as tablePluginKey } from '../plugin-key';
6
- import { handleDocOrSelectionChanged } from './handlers';
7
6
  import { pluginKey } from './plugin-key';
8
7
  import reducer from './reducer';
9
8
  var _pluginFactory = pluginFactory(pluginKey, reducer, {
@@ -22,9 +21,7 @@ var _pluginFactory = pluginFactory(pluginKey, reducer, {
22
21
  });
23
22
  }
24
23
  return pluginState;
25
- },
26
- onDocChanged: handleDocOrSelectionChanged,
27
- onSelectionChanged: handleDocOrSelectionChanged
24
+ }
28
25
  }),
29
26
  createPluginState = _pluginFactory.createPluginState,
30
27
  createCommand = _pluginFactory.createCommand,
@@ -1,10 +1,10 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
5
4
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
6
5
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
7
6
  import { getPluginState as getTablePluginState } from '../plugin-factory';
7
+ import { clearDropTarget, moveSource, setDropTarget } from './commands';
8
8
  import { DropTargetType } from './consts';
9
9
  import { createPluginState, getPluginState } from './plugin-factory';
10
10
  import { pluginKey } from './plugin-key';
@@ -46,25 +46,25 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
46
46
  },
47
47
  onDrag: function onDrag(event) {
48
48
  var data = getDraggableDataFromEvent(event);
49
-
50
49
  // If no data can be found then it's most like we do not want to perform any drag actions
51
50
  if (!data) {
51
+ clearDropTarget()(editorView.state, editorView.dispatch);
52
52
  return;
53
53
  }
54
54
 
55
55
  // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
56
56
  // insert location as to where the draggable will most likely be go. For example;
57
- // const { sourceType, targetAdjustedIndex } = data;
58
- // const highlight = sourceType === 'table-row' ? highlightRow : highlightColumn;
59
- // return editorView.dispatch(
60
- // highlight(targetAdjustedIndex)(editorView.state.tr),
61
- // );
57
+ var sourceType = data.sourceType,
58
+ targetAdjustedIndex = data.targetAdjustedIndex;
59
+ var dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
60
+ setDropTarget(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
62
61
  },
63
62
  onDrop: function onDrop(event) {
64
63
  var data = getDraggableDataFromEvent(event);
65
64
 
66
65
  // If no data can be found then it's most like we do not want to perform any drop action
67
66
  if (!data) {
67
+ clearDropTarget()(editorView.state, editorView.dispatch);
68
68
  return;
69
69
  }
70
70
  var sourceType = data.sourceType,
@@ -74,12 +74,12 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
74
74
  // If the drop target index contains merged cells then we should not allow the drop to occur.
75
75
  var hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
76
76
  if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
77
+ clearDropTarget()(editorView.state, editorView.dispatch);
77
78
  return;
78
79
  }
79
- var move = sourceType === 'table-row' ? moveRow : moveColumn;
80
80
  var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
81
81
  sourceIndex = _sourceIndexes[0];
82
- return editorView.dispatch(move(sourceIndex, targetAdjustedIndex)(editorView.state.tr));
82
+ moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
83
83
  }
84
84
  })
85
85
  };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { Box, xcss } from '@atlaskit/primitives';
3
+ import { DragInMotionIcon } from '../Icons/DragInMotionIcon';
4
+ var boxStyles = xcss({
5
+ borderColor: 'color.border.focused',
6
+ borderStyle: 'solid',
7
+ borderRadius: 'border.radius.100',
8
+ borderWidth: 'border.width.outline',
9
+ backgroundColor: 'color.blanket.selected'
10
+ });
11
+ export var DragPreview = function DragPreview(_ref) {
12
+ var direction = _ref.direction,
13
+ width = _ref.width,
14
+ height = _ref.height;
15
+ var marginLeft = direction === 'row' ? -14 : width / 2 - 14;
16
+ var marginTop = direction === 'row' ? height / 2 - 14 : -10;
17
+ var transform = direction === 'row' ? 'rotate(90deg)' : 'none';
18
+ return /*#__PURE__*/React.createElement(Box, {
19
+ xcss: boxStyles,
20
+ style: {
21
+ width: "".concat(width, "px"),
22
+ height: "".concat(height, "px")
23
+ }
24
+ }, /*#__PURE__*/React.createElement(DragInMotionIcon, {
25
+ style: {
26
+ position: 'absolute',
27
+ marginLeft: "".concat(marginLeft, "px"),
28
+ marginTop: "".concat(marginTop, "px"),
29
+ transform: transform
30
+ }
31
+ }));
32
+ };
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ export var DragInMotionIcon = function DragInMotionIcon(_ref) {
3
+ var style = _ref.style;
4
+ return /*#__PURE__*/React.createElement("svg", {
5
+ width: "28",
6
+ height: "20",
7
+ viewBox: "0 0 28 20",
8
+ fill: "none",
9
+ xmlns: "http://www.w3.org/2000/svg",
10
+ style: style
11
+ }, /*#__PURE__*/React.createElement("rect", {
12
+ x: "1",
13
+ y: "1",
14
+ width: "26",
15
+ height: "18",
16
+ rx: "5",
17
+ fill: "var(--ds-background-accent-blue-subtle, #579DFF)"
18
+ }), /*#__PURE__*/React.createElement("rect", {
19
+ x: "9",
20
+ y: "6",
21
+ width: "2",
22
+ height: "8",
23
+ rx: "1",
24
+ fill: "var(--ds-border-inverse, #FFFFFF)"
25
+ }), /*#__PURE__*/React.createElement("rect", {
26
+ x: "13",
27
+ y: "6",
28
+ width: "2",
29
+ height: "8",
30
+ rx: "1",
31
+ fill: "var(--ds-border-inverse, #FFFFFF)"
32
+ }), /*#__PURE__*/React.createElement("rect", {
33
+ x: "17",
34
+ y: "6",
35
+ width: "2",
36
+ height: "8",
37
+ rx: "1",
38
+ fill: "var(--ds-border-inverse, #FFFFFF)"
39
+ }), /*#__PURE__*/React.createElement("rect", {
40
+ x: "1",
41
+ y: "1",
42
+ width: "26",
43
+ height: "18",
44
+ rx: "5",
45
+ stroke: "var(--ds-border-inverse, #FFFFFF)",
46
+ strokeWidth: "2"
47
+ }));
48
+ };
@@ -1,9 +1,11 @@
1
1
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  import type { Decoration } from '@atlaskit/editor-prosemirror/view';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import type { DraggableType } from '../../types';
4
5
  import { TableDecorations } from '../../types';
5
- import type { DropTargetType } from './consts';
6
+ import { DropTargetType } from './consts';
6
7
  export declare const getDecorations: (state: EditorState) => DecorationSet;
7
8
  export declare const updatePluginStateDecorations: (state: EditorState, decorations: Decoration[], key: TableDecorations) => DecorationSet;
8
9
  export declare const setDropTarget: (type: DropTargetType, index: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
9
10
  export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
11
+ export declare const moveSource: (sourceType: DraggableType, sourceIndex: number, targetIndex: number) => import("@atlaskit/editor-common/types").Command;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export declare const DragPreview: ({ direction, width, height, }: {
3
+ direction: 'column' | 'row';
4
+ width: number;
5
+ height: number;
6
+ }) => JSX.Element;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface DragInMotionIconProps {
3
+ style?: React.CSSProperties;
4
+ }
5
+ export declare const DragInMotionIcon: ({ style }: DragInMotionIconProps) => JSX.Element;
6
+ export {};
@@ -1,9 +1,11 @@
1
1
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  import type { Decoration } from '@atlaskit/editor-prosemirror/view';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import type { DraggableType } from '../../types';
4
5
  import { TableDecorations } from '../../types';
5
- import type { DropTargetType } from './consts';
6
+ import { DropTargetType } from './consts';
6
7
  export declare const getDecorations: (state: EditorState) => DecorationSet;
7
8
  export declare const updatePluginStateDecorations: (state: EditorState, decorations: Decoration[], key: TableDecorations) => DecorationSet;
8
9
  export declare const setDropTarget: (type: DropTargetType, index: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
9
10
  export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
11
+ export declare const moveSource: (sourceType: DraggableType, sourceIndex: number, targetIndex: number) => import("@atlaskit/editor-common/types").Command;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export declare const DragPreview: ({ direction, width, height, }: {
3
+ direction: 'column' | 'row';
4
+ width: number;
5
+ height: number;
6
+ }) => JSX.Element;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface DragInMotionIconProps {
3
+ style?: React.CSSProperties;
4
+ }
5
+ export declare const DragInMotionIcon: ({ style }: DragInMotionIconProps) => JSX.Element;
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.3.2",
3
+ "version": "5.3.4",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^32.0.0",
31
31
  "@atlaskit/custom-steps": "^0.0.2",
32
- "@atlaskit/editor-common": "^76.11.0",
32
+ "@atlaskit/editor-common": "^76.12.0",
33
33
  "@atlaskit/editor-palette": "1.5.1",
34
34
  "@atlaskit/editor-plugin-analytics": "^0.2.0",
35
35
  "@atlaskit/editor-plugin-content-insertion": "^0.1.0",
@@ -41,8 +41,9 @@
41
41
  "@atlaskit/pragmatic-drag-and-drop": "^0.23.0",
42
42
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.11.8",
43
43
  "@atlaskit/pragmatic-drag-and-drop-react-accessibility": "^0.4.0",
44
+ "@atlaskit/primitives": "^1.6.7",
44
45
  "@atlaskit/theme": "^12.6.0",
45
- "@atlaskit/tokens": "^1.27.0",
46
+ "@atlaskit/tokens": "^1.28.0",
46
47
  "@atlaskit/tooltip": "^17.8.0",
47
48
  "@babel/runtime": "^7.0.0",
48
49
  "@emotion/react": "^11.7.1",
@@ -4,7 +4,9 @@ import type {
4
4
  } from '@atlaskit/editor-prosemirror/state';
5
5
  import type { Decoration } from '@atlaskit/editor-prosemirror/view';
6
6
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
+ import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
7
8
 
9
+ import type { DraggableType } from '../../types';
8
10
  import { TableDecorations } from '../../types';
9
11
  import {
10
12
  createColumnInsertLine,
@@ -13,7 +15,7 @@ import {
13
15
  } from '../../utils';
14
16
 
15
17
  import { DragAndDropActionType } from './actions';
16
- import type { DropTargetType } from './consts';
18
+ import { DropTargetType } from './consts';
17
19
  import { createCommand, getPluginState } from './plugin-factory';
18
20
  import { pluginKey } from './plugin-key';
19
21
 
@@ -71,12 +73,46 @@ export const setDropTarget = (
71
73
 
72
74
  export const clearDropTarget = (tr?: Transaction) =>
73
75
  createCommand(
74
- {
75
- type: DragAndDropActionType.CLEAR_DROP_TARGET,
76
- data: {
77
- decorationSet: DecorationSet.empty,
78
- },
76
+ (state) => {
77
+ const { dropTargetType, dropTargetIndex } = getPluginState(state);
78
+ if (dropTargetType === DropTargetType.NONE && dropTargetIndex === 0) {
79
+ return false;
80
+ }
81
+
82
+ return {
83
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
84
+ data: {
85
+ decorationSet: DecorationSet.empty,
86
+ },
87
+ };
79
88
  },
80
89
  (originalTr: Transaction) =>
81
90
  (tr || originalTr).setMeta('addToHistory', false),
82
91
  );
92
+
93
+ export const moveSource = (
94
+ sourceType: DraggableType,
95
+ sourceIndex: number,
96
+ targetIndex: number,
97
+ ) =>
98
+ createCommand(
99
+ (state) => {
100
+ return {
101
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
102
+ data: {
103
+ decorationSet: DecorationSet.empty,
104
+ },
105
+ };
106
+ },
107
+ (tr: Transaction) => {
108
+ if (sourceIndex === targetIndex) {
109
+ return tr.setMeta('addToHistory', false);
110
+ }
111
+
112
+ const move = sourceType === 'table-row' ? moveRow : moveColumn;
113
+ return move(
114
+ sourceIndex,
115
+ targetIndex + (sourceIndex > targetIndex ? 0 : -1),
116
+ )(tr);
117
+ },
118
+ );
@@ -2,7 +2,6 @@ import { pluginFactory } from '@atlaskit/editor-common/utils';
2
2
 
3
3
  import { pluginKey as tablePluginKey } from '../plugin-key';
4
4
 
5
- import { handleDocOrSelectionChanged } from './handlers';
6
5
  import { pluginKey } from './plugin-key';
7
6
  import reducer from './reducer';
8
7
 
@@ -28,6 +27,4 @@ export const { createPluginState, createCommand, getPluginState } =
28
27
  }
29
28
  return pluginState;
30
29
  },
31
- onDocChanged: handleDocOrSelectionChanged,
32
- onSelectionChanged: handleDocOrSelectionChanged,
33
30
  });
@@ -5,7 +5,6 @@ import type {
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
- import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
9
8
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
10
9
 
11
10
  import type { DraggableSourceData } from '../../types';
@@ -15,6 +14,7 @@ import {
15
14
  } from '../../utils/merged-cells';
16
15
  import { getPluginState as getTablePluginState } from '../plugin-factory';
17
16
 
17
+ import { clearDropTarget, moveSource, setDropTarget } from './commands';
18
18
  import { DropTargetType } from './consts';
19
19
  import { createPluginState, getPluginState } from './plugin-factory';
20
20
  import { pluginKey } from './plugin-key';
@@ -59,25 +59,31 @@ export const createPlugin = (
59
59
  },
60
60
  onDrag(event) {
61
61
  const data = getDraggableDataFromEvent(event);
62
-
63
62
  // If no data can be found then it's most like we do not want to perform any drag actions
64
63
  if (!data) {
64
+ clearDropTarget()(editorView.state, editorView.dispatch);
65
65
  return;
66
66
  }
67
67
 
68
68
  // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
69
69
  // insert location as to where the draggable will most likely be go. For example;
70
- // const { sourceType, targetAdjustedIndex } = data;
71
- // const highlight = sourceType === 'table-row' ? highlightRow : highlightColumn;
72
- // return editorView.dispatch(
73
- // highlight(targetAdjustedIndex)(editorView.state.tr),
74
- // );
70
+ const { sourceType, targetAdjustedIndex } = data;
71
+ const dropTargetType =
72
+ sourceType === 'table-row'
73
+ ? DropTargetType.ROW
74
+ : DropTargetType.COLUMN;
75
+
76
+ setDropTarget(dropTargetType, targetAdjustedIndex)(
77
+ editorView.state,
78
+ editorView.dispatch,
79
+ );
75
80
  },
76
81
  onDrop(event) {
77
82
  const data = getDraggableDataFromEvent(event);
78
83
 
79
84
  // If no data can be found then it's most like we do not want to perform any drop action
80
85
  if (!data) {
86
+ clearDropTarget()(editorView.state, editorView.dispatch);
81
87
  return;
82
88
  }
83
89
 
@@ -91,15 +97,16 @@ export const createPlugin = (
91
97
  if (
92
98
  hasMergedCells(targetAdjustedIndex)(editorView.state.selection)
93
99
  ) {
100
+ clearDropTarget()(editorView.state, editorView.dispatch);
94
101
  return;
95
102
  }
96
103
 
97
- const move = sourceType === 'table-row' ? moveRow : moveColumn;
98
-
99
104
  const [sourceIndex] = sourceIndexes;
100
- return editorView.dispatch(
101
- move(sourceIndex, targetAdjustedIndex)(editorView.state.tr),
102
- );
105
+ moveSource(
106
+ sourceType,
107
+ sourceIndex,
108
+ targetAdjustedIndex,
109
+ )(editorView.state, editorView.dispatch);
103
110
  },
104
111
  }),
105
112
  };
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+
3
+ import { Box, xcss } from '@atlaskit/primitives';
4
+
5
+ import { DragInMotionIcon } from '../Icons/DragInMotionIcon';
6
+
7
+ const boxStyles = xcss({
8
+ borderColor: 'color.border.focused',
9
+ borderStyle: 'solid',
10
+ borderRadius: 'border.radius.100',
11
+ borderWidth: 'border.width.outline',
12
+ backgroundColor: 'color.blanket.selected',
13
+ });
14
+
15
+ export const DragPreview = ({
16
+ direction,
17
+ width,
18
+ height,
19
+ }: {
20
+ direction: 'column' | 'row';
21
+ width: number;
22
+ height: number;
23
+ }) => {
24
+ let marginLeft = direction === 'row' ? -14 : width / 2 - 14;
25
+ let marginTop = direction === 'row' ? height / 2 - 14 : -10;
26
+ let transform = direction === 'row' ? 'rotate(90deg)' : 'none';
27
+ return (
28
+ <Box
29
+ xcss={boxStyles}
30
+ style={{
31
+ width: `${width}px`,
32
+ height: `${height}px`,
33
+ }}
34
+ >
35
+ <DragInMotionIcon
36
+ style={{
37
+ position: 'absolute',
38
+ marginLeft: `${marginLeft}px`,
39
+ marginTop: `${marginTop}px`,
40
+ transform: transform,
41
+ }}
42
+ />
43
+ </Box>
44
+ );
45
+ };
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+
3
+ import { token } from '@atlaskit/tokens';
4
+
5
+ interface DragInMotionIconProps {
6
+ style?: React.CSSProperties;
7
+ }
8
+
9
+ export const DragInMotionIcon = ({ style }: DragInMotionIconProps) => (
10
+ <svg
11
+ width="28"
12
+ height="20"
13
+ viewBox="0 0 28 20"
14
+ fill="none"
15
+ xmlns="http://www.w3.org/2000/svg"
16
+ style={style}
17
+ >
18
+ <rect
19
+ x="1"
20
+ y="1"
21
+ width="26"
22
+ height="18"
23
+ rx="5"
24
+ fill={token('color.background.accent.blue.subtle', '#579DFF')}
25
+ />
26
+ <rect
27
+ x="9"
28
+ y="6"
29
+ width="2"
30
+ height="8"
31
+ rx="1"
32
+ fill={token('color.border.inverse', '#FFFFFF')}
33
+ />
34
+ <rect
35
+ x="13"
36
+ y="6"
37
+ width="2"
38
+ height="8"
39
+ rx="1"
40
+ fill={token('color.border.inverse', '#FFFFFF')}
41
+ />
42
+ <rect
43
+ x="17"
44
+ y="6"
45
+ width="2"
46
+ height="8"
47
+ rx="1"
48
+ fill={token('color.border.inverse', '#FFFFFF')}
49
+ />
50
+ <rect
51
+ x="1"
52
+ y="1"
53
+ width="26"
54
+ height="18"
55
+ rx="5"
56
+ stroke={token('color.border.inverse', '#FFFFFF')}
57
+ strokeWidth="2"
58
+ />
59
+ </svg>
60
+ );
package/tsconfig.app.json CHANGED
@@ -78,6 +78,9 @@
78
78
  {
79
79
  "path": "../../pragmatic-drag-and-drop/react-accessibility/tsconfig.app.json"
80
80
  },
81
+ {
82
+ "path": "../../design-system/primitives/tsconfig.app.json"
83
+ },
81
84
  {
82
85
  "path": "../../design-system/theme/tsconfig.app.json"
83
86
  },
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.handleDocOrSelectionChanged = void 0;
7
- var _utils = require("@atlaskit/editor-tables/utils");
8
- // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
9
-
10
- var buildPluginState = function buildPluginState(builders) {
11
- return function (props) {
12
- return function (pluginState) {
13
- return builders.reduce(function (_pluginState, transform) {
14
- return transform(props)(_pluginState);
15
- }, pluginState);
16
- };
17
- };
18
- };
19
- var handleDocOrSelectionChanged = exports.handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, pluginState) {
20
- return buildPluginState([])({
21
- tr: tr,
22
- table: (0, _utils.findTable)(tr.selection)
23
- })(pluginState);
24
- };
@@ -1,10 +0,0 @@
1
- // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
2
-
3
- import { findTable } from '@atlaskit/editor-tables/utils';
4
- const buildPluginState = builders => props => pluginState => {
5
- return builders.reduce((_pluginState, transform) => transform(props)(_pluginState), pluginState);
6
- };
7
- export const handleDocOrSelectionChanged = (tr, pluginState) => buildPluginState([])({
8
- tr,
9
- table: findTable(tr.selection)
10
- })(pluginState);
@@ -1,18 +0,0 @@
1
- // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
2
-
3
- import { findTable } from '@atlaskit/editor-tables/utils';
4
- var buildPluginState = function buildPluginState(builders) {
5
- return function (props) {
6
- return function (pluginState) {
7
- return builders.reduce(function (_pluginState, transform) {
8
- return transform(props)(_pluginState);
9
- }, pluginState);
10
- };
11
- };
12
- };
13
- export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, pluginState) {
14
- return buildPluginState([])({
15
- tr: tr,
16
- table: findTable(tr.selection)
17
- })(pluginState);
18
- };
@@ -1,3 +0,0 @@
1
- import type { ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
2
- import type { DragAndDropPluginState } from './types';
3
- export declare const handleDocOrSelectionChanged: (tr: Transaction | ReadonlyTransaction, pluginState: DragAndDropPluginState) => DragAndDropPluginState;
@@ -1,3 +0,0 @@
1
- import type { ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
2
- import type { DragAndDropPluginState } from './types';
3
- export declare const handleDocOrSelectionChanged: (tr: Transaction | ReadonlyTransaction, pluginState: DragAndDropPluginState) => DragAndDropPluginState;
@@ -1,35 +0,0 @@
1
- // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
2
- import type {
3
- ReadonlyTransaction,
4
- Transaction,
5
- } from '@atlaskit/editor-prosemirror/state';
6
- import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
7
- import { findTable } from '@atlaskit/editor-tables/utils';
8
-
9
- import type { DragAndDropPluginState } from './types';
10
-
11
- type BuilderDragAndDropPluginState = (props: {
12
- tr: Transaction | ReadonlyTransaction;
13
- table?: ContentNodeWithPos;
14
- }) => (pluginState: DragAndDropPluginState) => DragAndDropPluginState;
15
-
16
- const buildPluginState =
17
- (
18
- builders: Array<BuilderDragAndDropPluginState>,
19
- ): BuilderDragAndDropPluginState =>
20
- (props) =>
21
- (pluginState) => {
22
- return builders.reduce(
23
- (_pluginState, transform) => transform(props)(_pluginState),
24
- pluginState,
25
- );
26
- };
27
-
28
- export const handleDocOrSelectionChanged = (
29
- tr: Transaction | ReadonlyTransaction,
30
- pluginState: DragAndDropPluginState,
31
- ): DragAndDropPluginState =>
32
- buildPluginState([])({
33
- tr,
34
- table: findTable(tr.selection),
35
- })(pluginState);