@atlaskit/editor-plugin-table 5.3.3 → 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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -9
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +1 -4
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +9 -9
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +30 -5
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +1 -4
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -10
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +30 -4
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +1 -4
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +9 -9
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +3 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +3 -1
- package/package.json +1 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +42 -6
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin-factory.ts +0 -3
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +19 -12
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/handlers.js +0 -24
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/handlers.js +0 -10
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/handlers.js +0 -18
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +0 -3
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +0 -3
- package/src/plugins/table/pm-plugins/drag-and-drop/handlers.ts +0 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 5.3.3
|
|
4
10
|
|
|
5
11
|
### 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
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
89
|
+
(0, _commands.moveSource)(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
90
90
|
}
|
|
91
91
|
})
|
|
92
92
|
};
|
|
@@ -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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
85
|
+
moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
85
86
|
}
|
|
86
87
|
})
|
|
87
88
|
};
|
|
@@ -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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
82
|
+
moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
83
83
|
}
|
|
84
84
|
})
|
|
85
85
|
};
|
|
@@ -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
|
|
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;
|
|
@@ -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
|
|
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;
|
package/package.json
CHANGED
|
@@ -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
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
moveSource(
|
|
106
|
+
sourceType,
|
|
107
|
+
sourceIndex,
|
|
108
|
+
targetAdjustedIndex,
|
|
109
|
+
)(editorView.state, editorView.dispatch);
|
|
103
110
|
},
|
|
104
111
|
}),
|
|
105
112
|
};
|
|
@@ -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);
|