@atlaskit/editor-plugin-table 5.3.0 → 5.3.2
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 +13 -0
- package/dist/cjs/plugins/table/commands/hover.js +17 -8
- package/dist/cjs/plugins/table/commands/index.js +6 -0
- package/dist/cjs/plugins/table/commands/misc.js +1 -7
- package/dist/cjs/plugins/table/event-handlers.js +29 -2
- package/dist/cjs/plugins/table/index.js +1 -1
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +7 -3
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/cjs/plugins/table/pm-plugins/default-table-selection.js +14 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -7
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
- package/dist/cjs/plugins/table/pm-plugins/main.js +5 -5
- package/dist/cjs/plugins/table/reducer.js +2 -1
- package/dist/cjs/plugins/table/types.js +14 -1
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +50 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +53 -14
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +114 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +53 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +11 -106
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +16 -6
- package/dist/cjs/plugins/table/ui/common-styles.js +9 -6
- package/dist/cjs/plugins/table/ui/consts.js +3 -1
- package/dist/cjs/plugins/table/ui/ui-styles.js +21 -9
- package/dist/cjs/plugins/table/utils/decoration.js +111 -19
- package/dist/cjs/plugins/table/utils/dom.js +7 -1
- package/dist/cjs/plugins/table/utils/index.js +38 -1
- package/dist/cjs/plugins/table/utils/merged-cells.js +66 -0
- package/dist/es2019/plugins/table/commands/hover.js +12 -8
- package/dist/es2019/plugins/table/commands/index.js +1 -1
- package/dist/es2019/plugins/table/commands/misc.js +1 -7
- package/dist/es2019/plugins/table/event-handlers.js +28 -2
- package/dist/es2019/plugins/table/index.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +8 -6
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/es2019/plugins/table/pm-plugins/default-table-selection.js +13 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -7
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -4
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -0
- package/dist/es2019/plugins/table/pm-plugins/main.js +6 -5
- package/dist/es2019/plugins/table/reducer.js +2 -1
- package/dist/es2019/plugins/table/types.js +14 -1
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +41 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -10
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +86 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +43 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -88
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +17 -7
- package/dist/es2019/plugins/table/ui/common-styles.js +49 -13
- package/dist/es2019/plugins/table/ui/consts.js +2 -0
- package/dist/es2019/plugins/table/ui/ui-styles.js +171 -15
- package/dist/es2019/plugins/table/utils/decoration.js +106 -18
- package/dist/es2019/plugins/table/utils/dom.js +2 -0
- package/dist/es2019/plugins/table/utils/index.js +4 -3
- package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
- package/dist/esm/plugins/table/commands/hover.js +16 -8
- package/dist/esm/plugins/table/commands/index.js +1 -1
- package/dist/esm/plugins/table/commands/misc.js +1 -7
- package/dist/esm/plugins/table/event-handlers.js +29 -2
- package/dist/esm/plugins/table/index.js +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/esm/plugins/table/nodeviews/table.js +4 -2
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +8 -6
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/esm/plugins/table/pm-plugins/default-table-selection.js +13 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +65 -4
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -0
- package/dist/esm/plugins/table/pm-plugins/main.js +7 -7
- package/dist/esm/plugins/table/reducer.js +2 -1
- package/dist/esm/plugins/table/types.js +14 -1
- package/dist/esm/plugins/table/ui/DragHandle/index.js +41 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -15
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +104 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +46 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -104
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +17 -7
- package/dist/esm/plugins/table/ui/common-styles.js +11 -8
- package/dist/esm/plugins/table/ui/consts.js +2 -0
- package/dist/esm/plugins/table/ui/ui-styles.js +21 -9
- package/dist/esm/plugins/table/utils/decoration.js +110 -18
- package/dist/esm/plugins/table/utils/dom.js +6 -0
- package/dist/esm/plugins/table/utils/index.js +4 -3
- package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
- package/dist/types/plugins/table/commands/hover.d.ts +2 -1
- package/dist/types/plugins/table/commands/index.d.ts +1 -1
- package/dist/types/plugins/table/event-handlers.d.ts +1 -0
- package/dist/types/plugins/table/nodeviews/types.d.ts +4 -3
- package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
- package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
- package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +35 -2
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +11 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
- package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types/plugins/table/ui/consts.d.ts +2 -0
- package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
- package/dist/types/plugins/table/utils/decoration.d.ts +4 -2
- package/dist/types/plugins/table/utils/dom.d.ts +2 -0
- package/dist/types/plugins/table/utils/index.d.ts +3 -2
- package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +4 -3
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +35 -2
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +11 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +4 -2
- package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
- package/package.json +6 -2
- package/src/__tests__/unit/event-handlers.ts +74 -1
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +35 -15
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +146 -42
- package/src/__tests__/unit/ui/NumberColumn.tsx +148 -0
- package/src/__tests__/unit/ui/RowControls.tsx +4 -4
- package/src/__tests__/unit/ui/RowDragControls.tsx +118 -0
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +9 -5
- package/src/plugins/table/commands/hover.ts +16 -7
- package/src/plugins/table/commands/index.ts +1 -0
- package/src/plugins/table/commands/misc.ts +0 -5
- package/src/plugins/table/event-handlers.ts +49 -2
- package/src/plugins/table/index.tsx +1 -1
- package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
- package/src/plugins/table/nodeviews/table.tsx +2 -0
- package/src/plugins/table/nodeviews/types.ts +4 -3
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +13 -4
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +10 -5
- package/src/plugins/table/pm-plugins/default-table-selection.ts +10 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +6 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +77 -4
- package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -0
- package/src/plugins/table/pm-plugins/main.ts +9 -4
- package/src/plugins/table/reducer.ts +2 -1
- package/src/plugins/table/types.ts +37 -3
- package/src/plugins/table/ui/DragHandle/index.tsx +57 -0
- package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +68 -30
- package/src/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.tsx +129 -0
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +75 -0
- package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +2 -135
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +43 -24
- package/src/plugins/table/ui/common-styles.ts +54 -11
- package/src/plugins/table/ui/consts.ts +2 -0
- package/src/plugins/table/ui/ui-styles.ts +173 -14
- package/src/plugins/table/utils/decoration.ts +176 -27
- package/src/plugins/table/utils/dom.ts +8 -0
- package/src/plugins/table/utils/index.ts +5 -0
- package/src/plugins/table/utils/merged-cells.ts +67 -0
- package/tsconfig.app.json +3 -0
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { PluginKey
|
|
3
|
-
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
4
|
-
} from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
3
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
6
4
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
7
5
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
@@ -12,7 +10,7 @@ export var getDecorations = function getDecorations(state) {
|
|
|
12
10
|
return pluginKey.getState(state);
|
|
13
11
|
};
|
|
14
12
|
export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, decorationSet, oldState, newState) {
|
|
15
|
-
var _tableWidthPluginKey$, _tableWidthPluginKey$2;
|
|
13
|
+
var _tableWidthPluginKey$, _tableWidthPluginKey$2, _tr$getMeta;
|
|
16
14
|
var isResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
|
|
17
15
|
var wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
|
|
18
16
|
var changedResizing = isResizing !== wasResizing;
|
|
@@ -20,7 +18,7 @@ export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr
|
|
|
20
18
|
// Remove column controls when resizing
|
|
21
19
|
if (isResizing) {
|
|
22
20
|
return DecorationSet.empty;
|
|
23
|
-
} else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing) {
|
|
21
|
+
} else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing || ((_tr$getMeta = tr.getMeta(tablePluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type) === 'HOVER_CELL') {
|
|
24
22
|
return buildColumnControlsDecorations({
|
|
25
23
|
decorationSet: decorationSet,
|
|
26
24
|
tr: tr
|
|
@@ -43,12 +41,16 @@ export var createPlugin = function createPlugin() {
|
|
|
43
41
|
return DecorationSet.empty;
|
|
44
42
|
},
|
|
45
43
|
apply: function apply(tr, decorationSet, oldState, newState) {
|
|
44
|
+
var _tablePluginKey$getSt, _tablePluginKey$getSt2;
|
|
46
45
|
var pluginState = decorationSet;
|
|
47
46
|
var meta = tr.getMeta(tablePluginKey);
|
|
47
|
+
var previousHover = (_tablePluginKey$getSt = tablePluginKey.getState(oldState)) === null || _tablePluginKey$getSt === void 0 ? void 0 : _tablePluginKey$getSt.hoveredCell;
|
|
48
|
+
var newHover = (_tablePluginKey$getSt2 = tablePluginKey.getState(newState)) === null || _tablePluginKey$getSt2 === void 0 ? void 0 : _tablePluginKey$getSt2.hoveredCell;
|
|
49
|
+
var changedCellHover = (previousHover === null || previousHover === void 0 ? void 0 : previousHover.colIndex) !== (newHover === null || newHover === void 0 ? void 0 : newHover.colIndex) || (previousHover === null || previousHover === void 0 ? void 0 : previousHover.rowIndex) !== (newHover === null || newHover === void 0 ? void 0 : newHover.rowIndex);
|
|
48
50
|
if (meta && meta.data && meta.data.decorationSet) {
|
|
49
51
|
pluginState = meta.data.decorationSet;
|
|
50
52
|
}
|
|
51
|
-
if (tr.docChanged || tr.selectionSet || tr.getMeta(tableWidthPluginKey)) {
|
|
53
|
+
if (tr.docChanged || tr.selectionSet || tr.getMeta(tableWidthPluginKey) || changedCellHover) {
|
|
52
54
|
pluginState = pluginState.map(tr.mapping, tr.doc);
|
|
53
55
|
return handleDocOrSelectionChanged(tr, pluginState, oldState, newState);
|
|
54
56
|
}
|
|
@@ -4,6 +4,7 @@ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
|
4
4
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
5
5
|
import { TableDecorations } from '../../../types';
|
|
6
6
|
import { createColumnControlsDecoration, createColumnSelectedDecoration, findColumnControlSelectedDecoration, findControlsHoverDecoration, updateDecorations } from '../../../utils/decoration';
|
|
7
|
+
import { pluginKey as tablePluginKey } from '../../plugin-key';
|
|
7
8
|
import { composeDecorations } from './compose-decorations';
|
|
8
9
|
var isColumnSelected = function isColumnSelected(tr) {
|
|
9
10
|
return tr.selection instanceof CellSelection && tr.selection.isColSelection();
|
|
@@ -23,13 +24,17 @@ var maybeUpdateColumnSelectedDecoration = function maybeUpdateColumnSelectedDeco
|
|
|
23
24
|
return updateDecorations(tr.doc, decorationSet, createColumnSelectedDecoration(tr), TableDecorations.COLUMN_SELECTED);
|
|
24
25
|
};
|
|
25
26
|
var maybeUpdateColumnControlsDecoration = function maybeUpdateColumnControlsDecoration(_ref3) {
|
|
27
|
+
var _meta$data;
|
|
26
28
|
var decorationSet = _ref3.decorationSet,
|
|
27
29
|
tr = _ref3.tr;
|
|
28
30
|
var table = findTable(tr.selection);
|
|
29
|
-
|
|
31
|
+
var meta = tr.getMeta(tablePluginKey);
|
|
32
|
+
|
|
33
|
+
// avoid re-drawing state if dnd decorations don't need to be updated
|
|
34
|
+
if (!table && (meta === null || meta === void 0 ? void 0 : meta.type) !== 'HOVER_CELL') {
|
|
30
35
|
return decorationSet;
|
|
31
36
|
}
|
|
32
|
-
return updateDecorations(tr.doc, decorationSet, createColumnControlsDecoration(tr.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
|
|
37
|
+
return updateDecorations(tr.doc, decorationSet, createColumnControlsDecoration(tr.selection, meta === null || meta === void 0 || (_meta$data = meta.data) === null || _meta$data === void 0 ? void 0 : _meta$data.hoveredCell), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
// @see: https://product-fabric.atlassian.net/browse/ED-7304
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
export var defaultTableSelection = {
|
|
2
2
|
hoveredColumns: [],
|
|
3
3
|
hoveredRows: []
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creating a separate object for hoveredCell so it doesn't get defaulted when `handleDocOrSelectionChanged` runs.
|
|
8
|
+
*
|
|
9
|
+
* It is safe to persist this value as it gets removed when the mouse cursor leaves the table, so no need to remove it
|
|
10
|
+
* when doc changes.
|
|
11
|
+
*/
|
|
12
|
+
export var defaultHoveredCell = {
|
|
13
|
+
hoveredCell: {
|
|
14
|
+
rowIndex: undefined,
|
|
15
|
+
colIndex: undefined
|
|
16
|
+
}
|
|
4
17
|
};
|
|
@@ -1,21 +1,50 @@
|
|
|
1
|
+
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
+
import { TableDecorations } from '../../types';
|
|
3
|
+
import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
|
|
1
4
|
import { DragAndDropActionType } from './actions';
|
|
2
|
-
import { createCommand } from './plugin-factory';
|
|
5
|
+
import { createCommand, getPluginState } from './plugin-factory';
|
|
6
|
+
import { pluginKey } from './plugin-key';
|
|
3
7
|
|
|
4
8
|
// TODO: This command is a placeholder example. Please replace this if required.
|
|
9
|
+
export var getDecorations = function getDecorations(state) {
|
|
10
|
+
var _pluginKey$getState;
|
|
11
|
+
return ((_pluginKey$getState = pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.decorationSet) || DecorationSet.empty;
|
|
12
|
+
};
|
|
13
|
+
export var updatePluginStateDecorations = function updatePluginStateDecorations(state, decorations, key) {
|
|
14
|
+
return updateDecorations(state.doc, getDecorations(state), decorations, key);
|
|
15
|
+
};
|
|
5
16
|
export var setDropTarget = function setDropTarget(type, index, tr) {
|
|
6
|
-
return createCommand({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
return createCommand(function (state) {
|
|
18
|
+
var _getPluginState = getPluginState(state),
|
|
19
|
+
dropTargetType = _getPluginState.dropTargetType,
|
|
20
|
+
dropTargetIndex = _getPluginState.dropTargetIndex;
|
|
21
|
+
if (dropTargetType === type && dropTargetIndex === index) {
|
|
22
|
+
return false;
|
|
11
23
|
}
|
|
24
|
+
var decorationSet = DecorationSet.empty;
|
|
25
|
+
if (type === 'column') {
|
|
26
|
+
decorationSet = updatePluginStateDecorations(state, createColumnInsertLine(index, state.selection), TableDecorations.COLUMN_INSERT_LINE);
|
|
27
|
+
} else if (type === 'row') {
|
|
28
|
+
decorationSet = updatePluginStateDecorations(state, createRowInsertLine(index, state.selection), TableDecorations.ROW_INSERT_LINE);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
type: DragAndDropActionType.SET_DROP_TARGET,
|
|
32
|
+
data: {
|
|
33
|
+
decorationSet: decorationSet,
|
|
34
|
+
type: type,
|
|
35
|
+
index: index
|
|
36
|
+
}
|
|
37
|
+
};
|
|
12
38
|
}, function (originalTr) {
|
|
13
39
|
return (tr || originalTr).setMeta('addToHistory', false);
|
|
14
40
|
});
|
|
15
41
|
};
|
|
16
42
|
export var clearDropTarget = function clearDropTarget(tr) {
|
|
17
43
|
return createCommand({
|
|
18
|
-
type: DragAndDropActionType.CLEAR_DROP_TARGET
|
|
44
|
+
type: DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
45
|
+
data: {
|
|
46
|
+
decorationSet: DecorationSet.empty
|
|
47
|
+
}
|
|
19
48
|
}, function (originalTr) {
|
|
20
49
|
return (tr || originalTr).setMeta('addToHistory', false);
|
|
21
50
|
});
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
3
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
|
|
5
|
+
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
6
|
+
import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
|
|
7
|
+
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
3
8
|
import { DropTargetType } from './consts';
|
|
4
9
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
5
10
|
import { pluginKey } from './plugin-key';
|
|
11
|
+
import { getDraggableDataFromEvent } from './utils/monitor';
|
|
6
12
|
export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
7
13
|
return new SafePlugin({
|
|
8
14
|
state: createPluginState(dispatch, function (state) {
|
|
@@ -16,11 +22,66 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
16
22
|
}),
|
|
17
23
|
key: pluginKey,
|
|
18
24
|
view: function view(editorView) {
|
|
19
|
-
// TODO: Add Pragmatic DnD monitor when the view is constructed.
|
|
20
|
-
|
|
21
25
|
return {
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
destroy: monitorForElements({
|
|
27
|
+
canMonitor: function canMonitor(_ref) {
|
|
28
|
+
var source = _ref.source;
|
|
29
|
+
var _ref2 = source.data,
|
|
30
|
+
type = _ref2.type,
|
|
31
|
+
localId = _ref2.localId,
|
|
32
|
+
indexes = _ref2.indexes;
|
|
33
|
+
|
|
34
|
+
// First; Perform any quick checks so we can abort early.
|
|
35
|
+
if (!indexes || !localId ||
|
|
36
|
+
// FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
|
|
37
|
+
// of more then 1 item.
|
|
38
|
+
indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
var _getTablePluginState = getTablePluginState(editorView.state),
|
|
42
|
+
tableNode = _getTablePluginState.tableNode;
|
|
43
|
+
// If the draggable localId is the same as the current selected table localId then we will allow the monitor
|
|
44
|
+
// watch for changes
|
|
45
|
+
return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
|
|
46
|
+
},
|
|
47
|
+
onDrag: function onDrag(event) {
|
|
48
|
+
var data = getDraggableDataFromEvent(event);
|
|
49
|
+
|
|
50
|
+
// If no data can be found then it's most like we do not want to perform any drag actions
|
|
51
|
+
if (!data) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
|
|
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
|
+
// );
|
|
62
|
+
},
|
|
63
|
+
onDrop: function onDrop(event) {
|
|
64
|
+
var data = getDraggableDataFromEvent(event);
|
|
65
|
+
|
|
66
|
+
// If no data can be found then it's most like we do not want to perform any drop action
|
|
67
|
+
if (!data) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
var sourceType = data.sourceType,
|
|
71
|
+
sourceIndexes = data.sourceIndexes,
|
|
72
|
+
targetAdjustedIndex = data.targetAdjustedIndex;
|
|
73
|
+
|
|
74
|
+
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
75
|
+
var hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
76
|
+
if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var move = sourceType === 'table-row' ? moveRow : moveColumn;
|
|
80
|
+
var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
|
|
81
|
+
sourceIndex = _sourceIndexes[0];
|
|
82
|
+
return editorView.dispatch(move(sourceIndex, targetAdjustedIndex)(editorView.state.tr));
|
|
83
|
+
}
|
|
84
|
+
})
|
|
24
85
|
};
|
|
25
86
|
},
|
|
26
87
|
props: {
|
|
@@ -7,11 +7,13 @@ export default (function (pluginState, action) {
|
|
|
7
7
|
switch (action.type) {
|
|
8
8
|
case DragAndDropActionType.SET_DROP_TARGET:
|
|
9
9
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
10
|
+
decorationSet: action.data.decorationSet,
|
|
10
11
|
dropTargetType: action.data.type,
|
|
11
12
|
dropTargetIndex: action.data.index
|
|
12
13
|
});
|
|
13
14
|
case DragAndDropActionType.CLEAR_DROP_TARGET:
|
|
14
15
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
16
|
+
decorationSet: action.data.decorationSet,
|
|
15
17
|
dropTargetType: DropTargetType.NONE,
|
|
16
18
|
dropTargetIndex: 0
|
|
17
19
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getDraggableDataFromEvent } from './monitor';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { extractClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
|
|
2
|
+
export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref) {
|
|
3
|
+
var _extractClosestEdge;
|
|
4
|
+
var location = _ref.location,
|
|
5
|
+
source = _ref.source;
|
|
6
|
+
var destination = location.current.dropTargets.at(0);
|
|
7
|
+
// If no target exists at the current location, then the current draggable is not over a target or the target doesn't support
|
|
8
|
+
// the current draggable.
|
|
9
|
+
if (!destination) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// This is the draggable elements data
|
|
14
|
+
var _ref2 = source.data,
|
|
15
|
+
sourceIndexes = _ref2.indexes,
|
|
16
|
+
sourceType = _ref2.type,
|
|
17
|
+
sourceLocalId = _ref2.localId;
|
|
18
|
+
|
|
19
|
+
// This is the drop target's data
|
|
20
|
+
var _ref3 = destination.data,
|
|
21
|
+
targetIndex = _ref3.targetIndex,
|
|
22
|
+
targetType = _ref3.type,
|
|
23
|
+
targetLocalId = _ref3.localId;
|
|
24
|
+
|
|
25
|
+
// Some basic check to abort early with...
|
|
26
|
+
if (!sourceIndexes || targetIndex < 0 ||
|
|
27
|
+
// abort if the type of the draggable is different to the target, for eg. rows cannot be dropped onto column targets.
|
|
28
|
+
sourceType !== targetType ||
|
|
29
|
+
// abort if the draggable is coming from a different table that the target is on.
|
|
30
|
+
sourceLocalId !== targetLocalId) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// FIXME: currently we only support a single row/col index being moved, remove this clause when this is no longer the case.
|
|
35
|
+
if (sourceIndexes.length > 1) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
var targetClosestEdge = (_extractClosestEdge = extractClosestEdge(destination.data)) !== null && _extractClosestEdge !== void 0 ? _extractClosestEdge : targetType === 'table-row' ? 'top' : 'left';
|
|
39
|
+
// NOTE: By default we always insert row/cols at the target index to the top/left (retrospectively of row/cols).
|
|
40
|
+
// This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
|
|
41
|
+
// the new target index to be 1 index higher.
|
|
42
|
+
var targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
|
|
43
|
+
return {
|
|
44
|
+
sourceType: sourceType,
|
|
45
|
+
sourceLocalId: sourceLocalId,
|
|
46
|
+
sourceIndexes: sourceIndexes,
|
|
47
|
+
targetType: targetType,
|
|
48
|
+
targetLocalId: targetLocalId,
|
|
49
|
+
targetIndex: targetIndex,
|
|
50
|
+
targetAdjustedIndex: targetIndex + targetOffset,
|
|
51
|
+
targetClosestEdge: targetClosestEdge
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -11,7 +11,7 @@ import { findTable } from '@atlaskit/editor-tables/utils';
|
|
|
11
11
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
12
12
|
import { addBoldInEmptyHeaderCells, clearHoverSelection, setTableRef } from '../commands';
|
|
13
13
|
import { removeResizeHandleDecorations, transformSliceRemoveCellBackgroundColor, transformSliceToAddTableHeaders, transformSliceToRemoveColumnsWidths } from '../commands/misc';
|
|
14
|
-
import { handleBlur, handleClick, handleCut, handleFocus, handleMouseDown, handleMouseLeave, handleMouseMove, handleMouseOut, handleMouseOver, handleTripleClick, whenTableInFocus } from '../event-handlers';
|
|
14
|
+
import { handleBlur, handleClick, handleCut, handleFocus, handleMouseDown, handleMouseLeave, handleMouseMove, handleMouseOut, handleMouseOver, handleTripleClick, whenTableInFocus, withCellTracking } from '../event-handlers';
|
|
15
15
|
import { createTableView } from '../nodeviews/table';
|
|
16
16
|
import TableCell from '../nodeviews/TableCell';
|
|
17
17
|
import TableRow from '../nodeviews/TableRow';
|
|
@@ -20,12 +20,12 @@ import { fixTables, replaceSelectedTable } from '../transforms';
|
|
|
20
20
|
import { TableCssClassName as ClassName } from '../types';
|
|
21
21
|
import { findControlsHoverDecoration, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell, transformSliceToRemoveOpenTable, updateResizeHandles } from '../utils';
|
|
22
22
|
import { isHeaderRowRequired } from '../utils/paste';
|
|
23
|
-
import { defaultTableSelection } from './default-table-selection';
|
|
23
|
+
import { defaultHoveredCell, defaultTableSelection } from './default-table-selection';
|
|
24
24
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
25
25
|
import { pluginKey } from './plugin-key';
|
|
26
|
-
export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled,
|
|
26
|
+
export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, tableResizingEnabled, fullWidthModeEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi) {
|
|
27
27
|
var _window;
|
|
28
|
-
var state = createPluginState(dispatch, _objectSpread(_objectSpread({
|
|
28
|
+
var state = createPluginState(dispatch, _objectSpread(_objectSpread(_objectSpread({
|
|
29
29
|
pluginConfig: pluginConfig,
|
|
30
30
|
insertColumnButtonIndex: undefined,
|
|
31
31
|
insertRowButtonIndex: undefined,
|
|
@@ -36,7 +36,7 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
|
|
|
36
36
|
isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
|
|
37
37
|
isHeaderColumnEnabled: false,
|
|
38
38
|
isDragAndDropEnabled: dragAndDropEnabled
|
|
39
|
-
}, defaultTableSelection), {}, {
|
|
39
|
+
}, defaultHoveredCell), defaultTableSelection), {}, {
|
|
40
40
|
getIntl: getIntl
|
|
41
41
|
}));
|
|
42
42
|
var elementContentRects = {};
|
|
@@ -240,8 +240,8 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
|
|
|
240
240
|
handleDOMEvents: {
|
|
241
241
|
focus: handleFocus,
|
|
242
242
|
blur: handleBlur,
|
|
243
|
-
mousedown: handleMouseDown,
|
|
244
|
-
mouseover: whenTableInFocus(handleMouseOver),
|
|
243
|
+
mousedown: withCellTracking(handleMouseDown),
|
|
244
|
+
mouseover: whenTableInFocus(withCellTracking(handleMouseOver)),
|
|
245
245
|
mouseleave: whenTableInFocus(handleMouseLeave),
|
|
246
246
|
mouseout: whenTableInFocus(handleMouseOut),
|
|
247
247
|
mousemove: whenTableInFocus(handleMouseMove, elementContentRects),
|
|
@@ -90,7 +90,8 @@ export default (function (pluginState, action) {
|
|
|
90
90
|
case 'HOVER_ROWS':
|
|
91
91
|
case 'HOVER_COLUMNS':
|
|
92
92
|
case 'HOVER_TABLE':
|
|
93
|
-
case '
|
|
93
|
+
case 'HOVER_MERGED_CELLS':
|
|
94
|
+
case 'HOVER_CELL':
|
|
94
95
|
case 'SHOW_RESIZE_HANDLE_LINE':
|
|
95
96
|
case 'SET_EDITOR_FOCUS':
|
|
96
97
|
return _objectSpread(_objectSpread({}, pluginState), action.data);
|
|
@@ -42,10 +42,13 @@ export var TableDecorations = /*#__PURE__*/function (TableDecorations) {
|
|
|
42
42
|
TableDecorations["COLUMN_RESIZING_HANDLE"] = "COLUMN_RESIZING_HANDLE";
|
|
43
43
|
TableDecorations["COLUMN_RESIZING_HANDLE_WIDGET"] = "COLUMN_RESIZING_HANDLE_WIDGET";
|
|
44
44
|
TableDecorations["COLUMN_RESIZING_HANDLE_LINE"] = "COLUMN_RESIZING_HANDLE_LINE";
|
|
45
|
+
TableDecorations["COLUMN_INSERT_LINE"] = "COLUMN_INSERT_LINE";
|
|
46
|
+
TableDecorations["ROW_INSERT_LINE"] = "ROW_INSERT_LINE";
|
|
45
47
|
TableDecorations["LAST_CELL_ELEMENT"] = "LAST_CELL_ELEMENT";
|
|
46
48
|
return TableDecorations;
|
|
47
49
|
}({});
|
|
48
50
|
export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssClassName), {}, {
|
|
51
|
+
/** Classic controls */
|
|
49
52
|
COLUMN_CONTROLS: "".concat(tablePrefixSelector, "-column-controls"),
|
|
50
53
|
COLUMN_CONTROLS_DECORATIONS: "".concat(tablePrefixSelector, "-column-controls-decoration"),
|
|
51
54
|
COLUMN_SELECTED: "".concat(tablePrefixSelector, "-column__selected"),
|
|
@@ -76,8 +79,13 @@ export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssCla
|
|
|
76
79
|
CORNER_CONTROLS_INSERT_ROW_MARKER: "".concat(tablePrefixSelector, "-corner-controls__insert-row-marker"),
|
|
77
80
|
CORNER_CONTROLS_INSERT_COLUMN_MARKER: "".concat(tablePrefixSelector, "-corner-controls__insert-column-marker"),
|
|
78
81
|
CONTROLS_CORNER_BUTTON: "".concat(tablePrefixSelector, "-corner-button"),
|
|
82
|
+
/** Controls with drag handle */
|
|
83
|
+
COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: "".concat(tablePrefixSelector, "-column-controls-decoration-with-drag"),
|
|
84
|
+
ROW_CONTROLS_WITH_DRAG: "".concat(tablePrefixSelector, "-row-controls-with-drag"),
|
|
85
|
+
/** Other classes */
|
|
79
86
|
NUMBERED_COLUMN: "".concat(tablePrefixSelector, "-numbered-column"),
|
|
80
87
|
NUMBERED_COLUMN_BUTTON: "".concat(tablePrefixSelector, "-numbered-column__button"),
|
|
88
|
+
NUMBERED_COLUMN_BUTTON_DISABLED: "".concat(tablePrefixSelector, "-numbered-column__button-disabled"),
|
|
81
89
|
HOVERED_COLUMN: "".concat(tablePrefixSelector, "-hovered-column"),
|
|
82
90
|
HOVERED_ROW: "".concat(tablePrefixSelector, "-hovered-row"),
|
|
83
91
|
HOVERED_TABLE: "".concat(tablePrefixSelector, "-hovered-table"),
|
|
@@ -108,8 +116,13 @@ export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssCla
|
|
|
108
116
|
TABLE_STICKY: "".concat(tablePrefixSelector, "-sticky"),
|
|
109
117
|
TOP_LEFT_CELL: 'table > tbody > tr:nth-child(2) > td:nth-child(1)',
|
|
110
118
|
LAST_ITEM_IN_CELL: "".concat(tablePrefixSelector, "-last-item-in-cell"),
|
|
119
|
+
WITH_COLUMN_INSERT_LINE: "".concat(tablePrefixSelector, "-column-insert-line"),
|
|
120
|
+
WITH_FIRST_COLUMN_INSERT_LINE: "".concat(tablePrefixSelector, "-first-column-insert-line"),
|
|
121
|
+
WITH_LAST_COLUMN_INSERT_LINE: "".concat(tablePrefixSelector, "-last-column-insert-line"),
|
|
111
122
|
WITH_RESIZE_LINE: "".concat(tablePrefixSelector, "-column-resize-line"),
|
|
112
|
-
WITH_RESIZE_LINE_LAST_COLUMN: "".concat(tablePrefixSelector, "-column-resize-line-last-column")
|
|
123
|
+
WITH_RESIZE_LINE_LAST_COLUMN: "".concat(tablePrefixSelector, "-column-resize-line-last-column"),
|
|
124
|
+
WITH_ROW_INSERT_LINE: "".concat(tablePrefixSelector, "-row-insert-line"),
|
|
125
|
+
WITH_LAST_ROW_INSERT_LINE: "".concat(tablePrefixSelector, "-last-row-insert-line")
|
|
113
126
|
});
|
|
114
127
|
export var ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
|
|
115
128
|
ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { DragHandleButton } from '@atlaskit/pragmatic-drag-and-drop-react-accessibility/drag-handle-button';
|
|
3
|
+
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
4
|
+
// TODO: use for now, in future replace with custom @atlaskit/icon/glyph/drag-handler
|
|
5
|
+
// width is too large (24px), should be 16px
|
|
6
|
+
export var DragHandle = function DragHandle(_ref) {
|
|
7
|
+
var tableLocalId = _ref.tableLocalId,
|
|
8
|
+
_ref$direction = _ref.direction,
|
|
9
|
+
direction = _ref$direction === void 0 ? 'row' : _ref$direction,
|
|
10
|
+
indexes = _ref.indexes,
|
|
11
|
+
onClick = _ref.onClick,
|
|
12
|
+
onMouseOver = _ref.onMouseOver,
|
|
13
|
+
onMouseOut = _ref.onMouseOut;
|
|
14
|
+
var dragHandleDivRef = useRef(null);
|
|
15
|
+
useEffect(function () {
|
|
16
|
+
var dragHandleDivRefCurrent = dragHandleDivRef.current;
|
|
17
|
+
if (dragHandleDivRefCurrent) {
|
|
18
|
+
return draggable({
|
|
19
|
+
element: dragHandleDivRefCurrent,
|
|
20
|
+
getInitialData: function getInitialData() {
|
|
21
|
+
return {
|
|
22
|
+
localId: tableLocalId,
|
|
23
|
+
type: "table-".concat(direction),
|
|
24
|
+
indexes: indexes
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}, [tableLocalId, direction, indexes]);
|
|
30
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
31
|
+
ref: dragHandleDivRef,
|
|
32
|
+
style: {
|
|
33
|
+
backgroundColor: "var(--ds-surface, white)",
|
|
34
|
+
borderRadius: '4px',
|
|
35
|
+
border: "2px solid ".concat("var(--ds-surface, white)"),
|
|
36
|
+
transform: direction === 'column' ? 'rotate(90deg)' : 'none'
|
|
37
|
+
}
|
|
38
|
+
}, /*#__PURE__*/React.createElement(DragHandleButton, {
|
|
39
|
+
label: "blah"
|
|
40
|
+
}));
|
|
41
|
+
};
|
|
@@ -8,11 +8,14 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
8
8
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
9
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
10
|
import React, { Component } from 'react';
|
|
11
|
+
import classnames from 'classnames';
|
|
11
12
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
12
13
|
import { isRowSelected } from '@atlaskit/editor-tables/utils';
|
|
13
|
-
import { clearHoverSelection } from '../../../commands';
|
|
14
|
+
import { clearHoverSelection, hoverCell } from '../../../commands';
|
|
15
|
+
import { getPluginState } from '../../../pm-plugins/plugin-factory';
|
|
14
16
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
15
17
|
import { getRowHeights } from '../../../utils';
|
|
18
|
+
import { tableBorderColor } from '../../consts';
|
|
16
19
|
var NumberColumn = /*#__PURE__*/function (_Component) {
|
|
17
20
|
_inherits(NumberColumn, _Component);
|
|
18
21
|
var _super = _createSuper(NumberColumn);
|
|
@@ -59,14 +62,42 @@ var NumberColumn = /*#__PURE__*/function (_Component) {
|
|
|
59
62
|
clearHoverSelection()(state, dispatch);
|
|
60
63
|
}
|
|
61
64
|
});
|
|
62
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "updateDragHandleLocation", function (rowIndex) {
|
|
63
66
|
var _this$props3 = _this.props,
|
|
64
|
-
hoveredRows = _this$props3.hoveredRows,
|
|
65
67
|
editorView = _this$props3.editorView,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
tableActive = _this$props3.tableActive;
|
|
69
|
+
var state = editorView.state,
|
|
70
|
+
dispatch = editorView.dispatch;
|
|
71
|
+
var _getPluginState = getPluginState(state),
|
|
72
|
+
hoveredCell = _getPluginState.hoveredCell;
|
|
73
|
+
if (tableActive && hoveredCell.rowIndex !== rowIndex) {
|
|
74
|
+
hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
_defineProperty(_assertThisInitialized(_this), "getCellStyles", function (index, rowHeight) {
|
|
78
|
+
var _this$props4 = _this.props,
|
|
79
|
+
stickyTop = _this$props4.stickyTop,
|
|
80
|
+
hasHeaderRow = _this$props4.hasHeaderRow;
|
|
81
|
+
if (stickyTop && hasHeaderRow && index === 0) {
|
|
82
|
+
return {
|
|
83
|
+
height: rowHeight,
|
|
84
|
+
top: "".concat(stickyTop, "px")
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
height: rowHeight
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
_defineProperty(_assertThisInitialized(_this), "getClassNames", function (index) {
|
|
92
|
+
var _classnames;
|
|
93
|
+
var isButtonDisabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
94
|
+
var _this$props5 = _this.props,
|
|
95
|
+
hoveredRows = _this$props5.hoveredRows,
|
|
96
|
+
editorView = _this$props5.editorView,
|
|
97
|
+
isInDanger = _this$props5.isInDanger,
|
|
98
|
+
isResizing = _this$props5.isResizing;
|
|
68
99
|
var isActive = isRowSelected(index)(editorView.state.selection) || (hoveredRows || []).indexOf(index) !== -1 && !isResizing;
|
|
69
|
-
return
|
|
100
|
+
return classnames(ClassName.NUMBERED_COLUMN_BUTTON, (_classnames = {}, _defineProperty(_classnames, ClassName.NUMBERED_COLUMN_BUTTON_DISABLED, isButtonDisabled), _defineProperty(_classnames, ClassName.HOVERED_CELL_IN_DANGER, isActive && isInDanger), _defineProperty(_classnames, ClassName.HOVERED_CELL_ACTIVE, isActive), _classnames));
|
|
70
101
|
});
|
|
71
102
|
return _this;
|
|
72
103
|
}
|
|
@@ -74,25 +105,33 @@ var NumberColumn = /*#__PURE__*/function (_Component) {
|
|
|
74
105
|
key: "render",
|
|
75
106
|
value: function render() {
|
|
76
107
|
var _this2 = this;
|
|
77
|
-
var _this$
|
|
78
|
-
tableRef = _this$
|
|
79
|
-
hasHeaderRow = _this$
|
|
108
|
+
var _this$props6 = this.props,
|
|
109
|
+
tableRef = _this$props6.tableRef,
|
|
110
|
+
hasHeaderRow = _this$props6.hasHeaderRow,
|
|
111
|
+
isDragAndDropEnabled = _this$props6.isDragAndDropEnabled,
|
|
112
|
+
tableActive = _this$props6.tableActive;
|
|
80
113
|
var rowHeights = getRowHeights(tableRef);
|
|
81
114
|
return /*#__PURE__*/React.createElement("div", {
|
|
82
115
|
className: ClassName.NUMBERED_COLUMN,
|
|
83
116
|
style: {
|
|
84
|
-
marginTop: hasHeaderRow && this.props.stickyTop !== undefined ? rowHeights[0] : undefined
|
|
117
|
+
marginTop: hasHeaderRow && this.props.stickyTop !== undefined ? rowHeights[0] : undefined,
|
|
118
|
+
borderLeft: isDragAndDropEnabled && tableActive ? "1px solid ".concat(tableBorderColor()) : undefined
|
|
85
119
|
},
|
|
86
120
|
contentEditable: false
|
|
87
121
|
}, rowHeights.map(function (rowHeight, index) {
|
|
88
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
122
|
+
return isDragAndDropEnabled ? /*#__PURE__*/React.createElement("div", {
|
|
123
|
+
key: "wrapper-".concat(index),
|
|
124
|
+
className: _this2.getClassNames(index, true),
|
|
125
|
+
"data-index": index,
|
|
126
|
+
style: _this2.getCellStyles(index, rowHeight),
|
|
127
|
+
onMouseOver: function onMouseOver() {
|
|
128
|
+
return _this2.updateDragHandleLocation(index);
|
|
129
|
+
}
|
|
130
|
+
}, hasHeaderRow ? index > 0 ? index : null : index + 1) : /*#__PURE__*/React.createElement("div", {
|
|
89
131
|
key: "wrapper-".concat(index),
|
|
90
132
|
className: _this2.getClassNames(index),
|
|
91
133
|
"data-index": index,
|
|
92
|
-
style:
|
|
93
|
-
height: rowHeight,
|
|
94
|
-
top: _this2.props.stickyTop !== undefined && hasHeaderRow && index === 0 ? "".concat(_this2.props.stickyTop, "px") : undefined
|
|
95
|
-
},
|
|
134
|
+
style: _this2.getCellStyles(index, rowHeight),
|
|
96
135
|
onClick: function onClick(event) {
|
|
97
136
|
return _this2.selectRow(index, event);
|
|
98
137
|
},
|