@atlaskit/editor-plugin-table 7.2.3 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/commands/column-resize.js +115 -45
- package/dist/cjs/commands/go-to-next-cell.js +7 -11
- package/dist/cjs/commands/misc.js +3 -2
- package/dist/cjs/commands/selection.js +3 -3
- package/dist/cjs/event-handlers.js +38 -25
- package/dist/cjs/pm-plugins/keymap.js +1 -0
- package/dist/cjs/pm-plugins/main.js +43 -9
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
- package/dist/cjs/reducer.js +5 -2
- package/dist/es2019/commands/column-resize.js +100 -35
- package/dist/es2019/commands/go-to-next-cell.js +7 -9
- package/dist/es2019/commands/misc.js +3 -2
- package/dist/es2019/commands/selection.js +5 -5
- package/dist/es2019/event-handlers.js +17 -3
- package/dist/es2019/pm-plugins/keymap.js +3 -2
- package/dist/es2019/pm-plugins/main.js +41 -5
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
- package/dist/es2019/reducer.js +5 -2
- package/dist/esm/commands/column-resize.js +105 -35
- package/dist/esm/commands/go-to-next-cell.js +7 -11
- package/dist/esm/commands/misc.js +3 -2
- package/dist/esm/commands/selection.js +5 -5
- package/dist/esm/event-handlers.js +38 -25
- package/dist/esm/pm-plugins/keymap.js +3 -2
- package/dist/esm/pm-plugins/main.js +38 -4
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
- package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
- package/dist/esm/reducer.js +5 -2
- package/dist/types/commands/column-resize.d.ts +2 -0
- package/dist/types/commands/misc.d.ts +1 -1
- package/dist/types/types.d.ts +16 -0
- package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
- package/dist/types-ts4.5/commands/misc.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +16 -0
- package/package.json +2 -2
- package/src/commands/column-resize.ts +155 -40
- package/src/commands/go-to-next-cell.ts +6 -15
- package/src/commands/misc.ts +2 -0
- package/src/commands/selection.ts +5 -5
- package/src/event-handlers.ts +21 -4
- package/src/pm-plugins/keymap.ts +3 -0
- package/src/pm-plugins/main.ts +47 -2
- package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
- package/src/pm-plugins/table-resizing/plugin.ts +18 -1
- package/src/reducer.ts +5 -2
- package/src/types.ts +16 -0
|
@@ -7,7 +7,11 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
7
7
|
import { transformSliceToRemoveOpenBodiedExtension, transformSliceToRemoveOpenExpand, transformSliceToRemoveOpenLayoutNodes, transformSliceToRemoveOpenMultiBodiedExtension } from '@atlaskit/editor-common/transforms';
|
|
8
8
|
import { browser, closestElement } from '@atlaskit/editor-common/utils';
|
|
9
9
|
import { findParentDomRefOfType, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
10
|
+
import { TableMap } from '@atlaskit/editor-tables';
|
|
11
|
+
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
12
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
10
13
|
import { addBoldInEmptyHeaderCells, clearHoverSelection, setTableRef } from '../commands';
|
|
14
|
+
import { stopKeyboardColumnResizing } from '../commands/column-resize';
|
|
11
15
|
import { removeResizeHandleDecorations, transformSliceRemoveCellBackgroundColor, transformSliceToAddTableHeaders, transformSliceToRemoveColumnsWidths } from '../commands/misc';
|
|
12
16
|
import { handleBlur, handleClick, handleCut, handleFocus, handleMouseDown, handleMouseEnter, handleMouseLeave, handleMouseMove, handleMouseOut, handleMouseOver, handleTripleClick, whenTableInFocus, withCellTracking } from '../event-handlers';
|
|
13
17
|
import { createTableView } from '../nodeviews/table';
|
|
@@ -99,7 +103,7 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
|
|
|
99
103
|
var domAtPos = editorView.domAtPos.bind(editorView);
|
|
100
104
|
editorViewRef = editorView;
|
|
101
105
|
return {
|
|
102
|
-
update: function update(view) {
|
|
106
|
+
update: function update(view, prevState) {
|
|
103
107
|
var state = view.state,
|
|
104
108
|
dispatch = view.dispatch;
|
|
105
109
|
var selection = state.selection;
|
|
@@ -110,6 +114,28 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
|
|
|
110
114
|
if (parent) {
|
|
111
115
|
tableRef = parent.querySelector('table') || undefined;
|
|
112
116
|
}
|
|
117
|
+
var tableNode = findTable(state.selection);
|
|
118
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
119
|
+
// when cursor leaves the table we need to stop column resizing
|
|
120
|
+
var pluginPrevState = getPluginState(prevState);
|
|
121
|
+
var isStopKeyboardColumResizing = pluginPrevState.isResizeHandleWidgetAdded && pluginPrevState.isKeyboardResize;
|
|
122
|
+
if (isStopKeyboardColumResizing) {
|
|
123
|
+
var isTableNodesDifferent = (pluginPrevState === null || pluginPrevState === void 0 ? void 0 : pluginPrevState.tableNode) !== (tableNode === null || tableNode === void 0 ? void 0 : tableNode.node);
|
|
124
|
+
if (pluginPrevState !== null && pluginPrevState !== void 0 && pluginPrevState.tableNode && tableNode && isTableNodesDifferent) {
|
|
125
|
+
var oldRowsNumber = TableMap.get(pluginPrevState.tableNode).height;
|
|
126
|
+
var newRowsNumber = TableMap.get(tableNode.node).height;
|
|
127
|
+
if (oldRowsNumber !== newRowsNumber ||
|
|
128
|
+
// Add/delete row
|
|
129
|
+
tableNode.node.attrs.localId !== pluginPrevState.tableNode.attrs.localId) {
|
|
130
|
+
// Jump to another table
|
|
131
|
+
stopKeyboardColumnResizing()(state, dispatch);
|
|
132
|
+
}
|
|
133
|
+
} else if (!tableNode) {
|
|
134
|
+
// selection outside of table
|
|
135
|
+
stopKeyboardColumnResizing()(state, dispatch);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
113
139
|
}
|
|
114
140
|
if (pluginState.tableRef !== tableRef) {
|
|
115
141
|
setTableRef(tableRef)(state, dispatch);
|
|
@@ -206,9 +232,17 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
|
|
|
206
232
|
var maybeTr = closestElement(domRef, 'tr');
|
|
207
233
|
return maybeTr ? maybeTr.classList.contains('sticky') : false;
|
|
208
234
|
},
|
|
209
|
-
handleTextInput: function handleTextInput(
|
|
210
|
-
var state =
|
|
211
|
-
dispatch =
|
|
235
|
+
handleTextInput: function handleTextInput(view, _from, _to, text) {
|
|
236
|
+
var state = view.state,
|
|
237
|
+
dispatch = view.dispatch;
|
|
238
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
239
|
+
var _getPluginState = getPluginState(state),
|
|
240
|
+
isKeyboardResize = _getPluginState.isKeyboardResize;
|
|
241
|
+
if (isKeyboardResize) {
|
|
242
|
+
stopKeyboardColumnResizing()(state, dispatch);
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
212
246
|
var tr = replaceSelectedTable(state, text, INPUT_METHOD.KEYBOARD, editorAnalyticsAPI);
|
|
213
247
|
if (tr.selectionSet) {
|
|
214
248
|
dispatch(tr);
|
|
@@ -5,9 +5,11 @@ import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
|
5
5
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
6
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
7
7
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
8
|
+
import { stopKeyboardColumnResizing } from '../../commands/column-resize';
|
|
8
9
|
import { updateResizeHandleDecorations } from '../../commands/misc';
|
|
9
10
|
import { updateColumnWidths } from '../../transforms';
|
|
10
11
|
import { getSelectedColumnIndexes } from '../../utils';
|
|
12
|
+
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
11
13
|
import { META_KEYS } from '../table-analytics';
|
|
12
14
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
13
15
|
import { getPluginState } from './plugin-factory';
|
|
@@ -20,6 +22,8 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
20
22
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
21
23
|
return false;
|
|
22
24
|
}
|
|
25
|
+
var _getTablePluginState = getTablePluginState(state),
|
|
26
|
+
isKeyboardResize = _getTablePluginState.isKeyboardResize;
|
|
23
27
|
event.preventDefault();
|
|
24
28
|
var tr = view.state.tr;
|
|
25
29
|
tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
@@ -89,6 +93,8 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
89
93
|
var _getPluginState = getPluginState(state),
|
|
90
94
|
dragging = _getPluginState.dragging,
|
|
91
95
|
resizeHandlePos = _getPluginState.resizeHandlePos;
|
|
96
|
+
var _getTablePluginState2 = getTablePluginState(state),
|
|
97
|
+
isTableHovered = _getTablePluginState2.isTableHovered;
|
|
92
98
|
if (resizeHandlePos === null) {
|
|
93
99
|
return stopResizing()(state, dispatch);
|
|
94
100
|
}
|
|
@@ -101,9 +107,20 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
101
107
|
var start = $cell.start(-1);
|
|
102
108
|
var table = $cell.node(-1);
|
|
103
109
|
|
|
104
|
-
// If we let go in the same place we started,
|
|
110
|
+
// If we let go in the same place we started, don't need to do anything.
|
|
105
111
|
if (dragging && clientX === dragging.startX) {
|
|
106
|
-
|
|
112
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
113
|
+
if (isKeyboardResize || !isTableHovered) {
|
|
114
|
+
/** if column resize had started via keyboard but continued by mouse
|
|
115
|
+
* or mouse pointer leaves the table but mouse button still pressed
|
|
116
|
+
*/
|
|
117
|
+
return stopKeyboardColumnResizing()(state, dispatch, view);
|
|
118
|
+
} else {
|
|
119
|
+
return stopResizing()(state, dispatch);
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
return stopResizing()(state, dispatch);
|
|
123
|
+
}
|
|
107
124
|
}
|
|
108
125
|
var tr = state.tr;
|
|
109
126
|
if (dragging) {
|
|
@@ -137,7 +154,18 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
137
154
|
})(tr);
|
|
138
155
|
}
|
|
139
156
|
}
|
|
140
|
-
|
|
157
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
158
|
+
if (isKeyboardResize || !isTableHovered) {
|
|
159
|
+
/** if column resize had started via keyboard but continued by mouse
|
|
160
|
+
* or mouse pointer leaves the table but mouse button still pressed
|
|
161
|
+
*/
|
|
162
|
+
return stopKeyboardColumnResizing(tr)(state, dispatch, view);
|
|
163
|
+
} else {
|
|
164
|
+
return stopResizing(tr)(state, dispatch);
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
return stopResizing(tr)(state, dispatch);
|
|
168
|
+
}
|
|
141
169
|
}
|
|
142
170
|
}
|
|
143
171
|
function move(event) {
|
|
@@ -147,7 +175,9 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
147
175
|
var _getPluginState2 = getPluginState(state),
|
|
148
176
|
dragging = _getPluginState2.dragging,
|
|
149
177
|
resizeHandlePos = _getPluginState2.resizeHandlePos;
|
|
150
|
-
|
|
178
|
+
var _getTablePluginState3 = getTablePluginState(state),
|
|
179
|
+
isTableHovered = _getTablePluginState3.isTableHovered;
|
|
180
|
+
if (!which || !dragging || resizeHandlePos === null || !pointsAtCell(state.doc.resolve(resizeHandlePos)) || !isTableHovered && getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
151
181
|
return finish(event);
|
|
152
182
|
}
|
|
153
183
|
var $cell = state.doc.resolve(resizeHandlePos);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import classnames from 'classnames';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { TableCssClassName as ClassName } from '../../types';
|
|
6
|
+
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
5
7
|
import { setResizeHandlePos } from './commands';
|
|
6
8
|
import { handleMouseDown } from './event-handlers';
|
|
7
9
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
@@ -34,7 +36,19 @@ export function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorF
|
|
|
34
36
|
getPluginState(state).resizeHandlePos || getResizeCellPos(view, event);
|
|
35
37
|
var _getPluginState = getPluginState(state),
|
|
36
38
|
dragging = _getPluginState.dragging;
|
|
37
|
-
|
|
39
|
+
var isColumnKeyboardResizeStarted = false;
|
|
40
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
41
|
+
/*
|
|
42
|
+
We need to start listening mouse events if column resize started from keyboard.
|
|
43
|
+
This will allow continue resizing via mouse
|
|
44
|
+
*/
|
|
45
|
+
var _getTablePluginState = getTablePluginState(state),
|
|
46
|
+
isKeyboardResize = _getTablePluginState.isKeyboardResize;
|
|
47
|
+
if (isKeyboardResize) {
|
|
48
|
+
isColumnKeyboardResizeStarted = isKeyboardResize;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (resizeHandlePos !== null && (!dragging || isColumnKeyboardResizeStarted)) {
|
|
38
52
|
if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI)) {
|
|
39
53
|
var _state = view.state,
|
|
40
54
|
_dispatch = view.dispatch;
|
package/dist/esm/reducer.js
CHANGED
|
@@ -57,8 +57,9 @@ export default (function (pluginState, action) {
|
|
|
57
57
|
resizeHandleColumnIndex: undefined,
|
|
58
58
|
resizeHandleRowIndex: undefined
|
|
59
59
|
});
|
|
60
|
+
case 'START_KEYBOARD_COLUMN_RESIZE':
|
|
60
61
|
case 'ADD_RESIZE_HANDLE_DECORATIONS':
|
|
61
|
-
if (action.data.resizeHandleColumnIndex === pluginState.resizeHandleColumnIndex && action.data.resizeHandleRowIndex === pluginState.resizeHandleRowIndex && action.data.resizeHandleIncludeTooltip === pluginState.resizeHandleIncludeTooltip) {
|
|
62
|
+
if (action.data.resizeHandleColumnIndex === pluginState.resizeHandleColumnIndex && action.data.resizeHandleRowIndex === pluginState.resizeHandleRowIndex && action.data.resizeHandleIncludeTooltip === pluginState.resizeHandleIncludeTooltip && action.data.isKeyboardResize === pluginState.isKeyboardResize) {
|
|
62
63
|
return pluginState;
|
|
63
64
|
}
|
|
64
65
|
return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), {}, {
|
|
@@ -77,6 +78,7 @@ export default (function (pluginState, action) {
|
|
|
77
78
|
resizeHandleRowIndex: resizeHandleRowIndex !== null && resizeHandleRowIndex !== void 0 ? resizeHandleRowIndex : pluginState.resizeHandleRowIndex,
|
|
78
79
|
resizeHandleIncludeTooltip: resizeHandleIncludeTooltip !== null && resizeHandleIncludeTooltip !== void 0 ? resizeHandleIncludeTooltip : pluginState.resizeHandleIncludeTooltip
|
|
79
80
|
});
|
|
81
|
+
case 'STOP_KEYBOARD_COLUMN_RESIZE':
|
|
80
82
|
case 'REMOVE_RESIZE_HANDLE_DECORATIONS':
|
|
81
83
|
if (!pluginState.isResizeHandleWidgetAdded) {
|
|
82
84
|
return pluginState;
|
|
@@ -84,7 +86,8 @@ export default (function (pluginState, action) {
|
|
|
84
86
|
return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), {}, {
|
|
85
87
|
resizeHandleColumnIndex: undefined,
|
|
86
88
|
resizeHandleRowIndex: undefined,
|
|
87
|
-
isResizeHandleWidgetAdded: false
|
|
89
|
+
isResizeHandleWidgetAdded: false,
|
|
90
|
+
isKeyboardResize: undefined
|
|
88
91
|
});
|
|
89
92
|
case 'SET_TABLE_REF':
|
|
90
93
|
case 'HOVER_ROWS':
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Command, GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
3
|
import type { Direction } from '@atlaskit/editor-tables/types';
|
|
3
4
|
export declare const initiateKeyboardColumnResizing: Command;
|
|
4
5
|
export declare const activateNextResizeArea: (direction: Direction) => Command;
|
|
5
6
|
export declare const changeColumnWidthByStep: (stepSize: number, getEditorContainerWidth: GetEditorContainerWidth) => Command;
|
|
7
|
+
export declare const stopKeyboardColumnResizing: (originalTr?: Transaction) => Command;
|
|
@@ -26,7 +26,7 @@ export declare const selectRows: (rowIndexes: number[]) => Command;
|
|
|
26
26
|
export declare const showInsertColumnButton: (columnIndex: number) => Command;
|
|
27
27
|
export declare const showInsertRowButton: (rowIndex: number) => Command;
|
|
28
28
|
export declare const hideInsertColumnOrRowButton: () => Command;
|
|
29
|
-
export declare const addResizeHandleDecorations: (rowIndex: number, columnIndex: number, includeTooltip: boolean) => Command;
|
|
29
|
+
export declare const addResizeHandleDecorations: (rowIndex: number, columnIndex: number, includeTooltip: boolean, isKeyboardResize?: boolean) => Command;
|
|
30
30
|
export declare const updateResizeHandleDecorations: (rowIndex?: number, columnIndex?: number, includeTooltip?: boolean) => Command;
|
|
31
31
|
export declare const removeResizeHandleDecorations: () => Command;
|
|
32
32
|
export declare const autoSizeTable: (view: EditorView, node: PMNode, table: HTMLTableElement, basePos: number | undefined, opts: {
|
package/dist/types/types.d.ts
CHANGED
|
@@ -74,6 +74,7 @@ export interface TablePluginState {
|
|
|
74
74
|
resizeHandleRowIndex?: number;
|
|
75
75
|
resizeHandleColumnIndex?: number;
|
|
76
76
|
resizeHandleIncludeTooltip?: boolean;
|
|
77
|
+
isKeyboardResize?: boolean;
|
|
77
78
|
isTableCollapsed?: boolean;
|
|
78
79
|
canCollapseTable?: boolean;
|
|
79
80
|
getIntl: () => IntlShape;
|
|
@@ -134,6 +135,15 @@ export type TablePluginAction = {
|
|
|
134
135
|
hoveredColumns: number[];
|
|
135
136
|
isInDanger?: boolean;
|
|
136
137
|
};
|
|
138
|
+
} | {
|
|
139
|
+
type: 'START_KEYBOARD_COLUMN_RESIZE';
|
|
140
|
+
data: {
|
|
141
|
+
decorationSet: DecorationSet;
|
|
142
|
+
resizeHandleRowIndex: number;
|
|
143
|
+
resizeHandleColumnIndex: number;
|
|
144
|
+
resizeHandleIncludeTooltip: boolean;
|
|
145
|
+
isKeyboardResize?: boolean;
|
|
146
|
+
};
|
|
137
147
|
} | {
|
|
138
148
|
type: 'ADD_RESIZE_HANDLE_DECORATIONS';
|
|
139
149
|
data: {
|
|
@@ -141,6 +151,7 @@ export type TablePluginAction = {
|
|
|
141
151
|
resizeHandleRowIndex: number;
|
|
142
152
|
resizeHandleColumnIndex: number;
|
|
143
153
|
resizeHandleIncludeTooltip: boolean;
|
|
154
|
+
isKeyboardResize?: boolean;
|
|
144
155
|
};
|
|
145
156
|
} | {
|
|
146
157
|
type: 'UPDATE_RESIZE_HANDLE_DECORATIONS';
|
|
@@ -155,6 +166,11 @@ export type TablePluginAction = {
|
|
|
155
166
|
data: {
|
|
156
167
|
decorationSet: DecorationSet;
|
|
157
168
|
};
|
|
169
|
+
} | {
|
|
170
|
+
type: 'STOP_KEYBOARD_COLUMN_RESIZE';
|
|
171
|
+
data: {
|
|
172
|
+
decorationSet: DecorationSet;
|
|
173
|
+
};
|
|
158
174
|
} | {
|
|
159
175
|
type: 'CLEAR_HOVER_SELECTION';
|
|
160
176
|
data: {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Command, GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
3
|
import type { Direction } from '@atlaskit/editor-tables/types';
|
|
3
4
|
export declare const initiateKeyboardColumnResizing: Command;
|
|
4
5
|
export declare const activateNextResizeArea: (direction: Direction) => Command;
|
|
5
6
|
export declare const changeColumnWidthByStep: (stepSize: number, getEditorContainerWidth: GetEditorContainerWidth) => Command;
|
|
7
|
+
export declare const stopKeyboardColumnResizing: (originalTr?: Transaction) => Command;
|
|
@@ -26,7 +26,7 @@ export declare const selectRows: (rowIndexes: number[]) => Command;
|
|
|
26
26
|
export declare const showInsertColumnButton: (columnIndex: number) => Command;
|
|
27
27
|
export declare const showInsertRowButton: (rowIndex: number) => Command;
|
|
28
28
|
export declare const hideInsertColumnOrRowButton: () => Command;
|
|
29
|
-
export declare const addResizeHandleDecorations: (rowIndex: number, columnIndex: number, includeTooltip: boolean) => Command;
|
|
29
|
+
export declare const addResizeHandleDecorations: (rowIndex: number, columnIndex: number, includeTooltip: boolean, isKeyboardResize?: boolean) => Command;
|
|
30
30
|
export declare const updateResizeHandleDecorations: (rowIndex?: number, columnIndex?: number, includeTooltip?: boolean) => Command;
|
|
31
31
|
export declare const removeResizeHandleDecorations: () => Command;
|
|
32
32
|
export declare const autoSizeTable: (view: EditorView, node: PMNode, table: HTMLTableElement, basePos: number | undefined, opts: {
|
|
@@ -74,6 +74,7 @@ export interface TablePluginState {
|
|
|
74
74
|
resizeHandleRowIndex?: number;
|
|
75
75
|
resizeHandleColumnIndex?: number;
|
|
76
76
|
resizeHandleIncludeTooltip?: boolean;
|
|
77
|
+
isKeyboardResize?: boolean;
|
|
77
78
|
isTableCollapsed?: boolean;
|
|
78
79
|
canCollapseTable?: boolean;
|
|
79
80
|
getIntl: () => IntlShape;
|
|
@@ -134,6 +135,15 @@ export type TablePluginAction = {
|
|
|
134
135
|
hoveredColumns: number[];
|
|
135
136
|
isInDanger?: boolean;
|
|
136
137
|
};
|
|
138
|
+
} | {
|
|
139
|
+
type: 'START_KEYBOARD_COLUMN_RESIZE';
|
|
140
|
+
data: {
|
|
141
|
+
decorationSet: DecorationSet;
|
|
142
|
+
resizeHandleRowIndex: number;
|
|
143
|
+
resizeHandleColumnIndex: number;
|
|
144
|
+
resizeHandleIncludeTooltip: boolean;
|
|
145
|
+
isKeyboardResize?: boolean;
|
|
146
|
+
};
|
|
137
147
|
} | {
|
|
138
148
|
type: 'ADD_RESIZE_HANDLE_DECORATIONS';
|
|
139
149
|
data: {
|
|
@@ -141,6 +151,7 @@ export type TablePluginAction = {
|
|
|
141
151
|
resizeHandleRowIndex: number;
|
|
142
152
|
resizeHandleColumnIndex: number;
|
|
143
153
|
resizeHandleIncludeTooltip: boolean;
|
|
154
|
+
isKeyboardResize?: boolean;
|
|
144
155
|
};
|
|
145
156
|
} | {
|
|
146
157
|
type: 'UPDATE_RESIZE_HANDLE_DECORATIONS';
|
|
@@ -155,6 +166,11 @@ export type TablePluginAction = {
|
|
|
155
166
|
data: {
|
|
156
167
|
decorationSet: DecorationSet;
|
|
157
168
|
};
|
|
169
|
+
} | {
|
|
170
|
+
type: 'STOP_KEYBOARD_COLUMN_RESIZE';
|
|
171
|
+
data: {
|
|
172
|
+
decorationSet: DecorationSet;
|
|
173
|
+
};
|
|
158
174
|
} | {
|
|
159
175
|
type: 'CLEAR_HOVER_SELECTION';
|
|
160
176
|
data: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@atlaskit/primitives": "^2.0.0",
|
|
49
49
|
"@atlaskit/theme": "^12.6.0",
|
|
50
50
|
"@atlaskit/toggle": "^13.0.0",
|
|
51
|
-
"@atlaskit/tokens": "^1.
|
|
51
|
+
"@atlaskit/tokens": "^1.36.0",
|
|
52
52
|
"@atlaskit/tooltip": "^18.1.0",
|
|
53
53
|
"@babel/runtime": "^7.0.0",
|
|
54
54
|
"@emotion/react": "^11.7.1",
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
Command,
|
|
4
4
|
GetEditorContainerWidth,
|
|
5
5
|
} from '@atlaskit/editor-common/types';
|
|
6
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
6
7
|
import { TableMap } from '@atlaskit/editor-tables';
|
|
7
8
|
import type { CellAttributes, Direction } from '@atlaskit/editor-tables/types';
|
|
8
9
|
import {
|
|
@@ -15,10 +16,17 @@ import {
|
|
|
15
16
|
} from '@atlaskit/editor-tables/utils';
|
|
16
17
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
17
18
|
|
|
19
|
+
import { getDecorations } from '../pm-plugins/decorations/plugin';
|
|
20
|
+
import {
|
|
21
|
+
buildColumnResizingDecorations,
|
|
22
|
+
clearColumnResizingDecorations,
|
|
23
|
+
} from '../pm-plugins/decorations/utils';
|
|
24
|
+
import { createCommand, getPluginState } from '../pm-plugins/plugin-factory';
|
|
18
25
|
import {
|
|
19
26
|
getPluginState as getTableResizingPluginState,
|
|
20
27
|
createCommand as tableResizingPluginCreateCommand,
|
|
21
28
|
} from '../pm-plugins/table-resizing/plugin-factory';
|
|
29
|
+
import { pluginKey as tableResizingPK } from '../pm-plugins/table-resizing/plugin-key';
|
|
22
30
|
import {
|
|
23
31
|
currentColWidth,
|
|
24
32
|
getResizeState,
|
|
@@ -27,9 +35,23 @@ import {
|
|
|
27
35
|
updateControls,
|
|
28
36
|
} from '../pm-plugins/table-resizing/utils';
|
|
29
37
|
import { updateColumnWidths } from '../transforms';
|
|
30
|
-
import {
|
|
38
|
+
import { TableDecorations } from '../types';
|
|
39
|
+
import type { TablePluginAction } from '../types';
|
|
40
|
+
import {
|
|
41
|
+
createColumnLineResize,
|
|
42
|
+
getSelectedColumnIndexes,
|
|
43
|
+
updateDecorations,
|
|
44
|
+
} from '../utils';
|
|
31
45
|
|
|
32
|
-
|
|
46
|
+
const getTablePluginCommand = (
|
|
47
|
+
actionPayload: TablePluginAction,
|
|
48
|
+
originalTr?: Transaction,
|
|
49
|
+
): Command => {
|
|
50
|
+
return createCommand(
|
|
51
|
+
() => actionPayload,
|
|
52
|
+
(tr) => (originalTr || tr).setMeta('addToHistory', false),
|
|
53
|
+
);
|
|
54
|
+
};
|
|
33
55
|
|
|
34
56
|
const updateResizeHandleAndStatePosition =
|
|
35
57
|
(
|
|
@@ -38,19 +60,64 @@ const updateResizeHandleAndStatePosition =
|
|
|
38
60
|
nextResizeHandlePos: number,
|
|
39
61
|
): Command =>
|
|
40
62
|
(state, dispatch) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})(state, dispatch);
|
|
63
|
+
let customTr = state.tr;
|
|
64
|
+
const {
|
|
65
|
+
pluginConfig: { allowColumnResizing },
|
|
66
|
+
getIntl,
|
|
67
|
+
} = getPluginState(state);
|
|
47
68
|
|
|
48
|
-
|
|
69
|
+
const fakeDispatch = (tr: Transaction) => {
|
|
70
|
+
customTr = tr;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (!allowColumnResizing) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const decorationsWithWidget = buildColumnResizingDecorations(
|
|
78
|
+
rowIndex,
|
|
79
|
+
columnIndex,
|
|
80
|
+
true,
|
|
81
|
+
getIntl,
|
|
82
|
+
)({
|
|
83
|
+
tr: customTr,
|
|
84
|
+
decorationSet: getDecorations(state),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const decorationsWithWidgetAndHandle = updateDecorations(
|
|
88
|
+
customTr.doc,
|
|
89
|
+
decorationsWithWidget,
|
|
90
|
+
createColumnLineResize(state.selection, {
|
|
91
|
+
right: columnIndex,
|
|
92
|
+
}),
|
|
93
|
+
TableDecorations.COLUMN_RESIZING_HANDLE_LINE,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
getTablePluginCommand(
|
|
97
|
+
{
|
|
98
|
+
type: 'START_KEYBOARD_COLUMN_RESIZE',
|
|
99
|
+
data: {
|
|
100
|
+
resizeHandleRowIndex: rowIndex,
|
|
101
|
+
resizeHandleColumnIndex: columnIndex,
|
|
102
|
+
resizeHandleIncludeTooltip: true,
|
|
103
|
+
isKeyboardResize: true,
|
|
104
|
+
decorationSet: decorationsWithWidgetAndHandle,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
customTr,
|
|
108
|
+
)(state, fakeDispatch);
|
|
109
|
+
|
|
110
|
+
customTr.setMeta(tableResizingPK, {
|
|
49
111
|
type: 'SET_RESIZE_HANDLE_POSITION',
|
|
50
112
|
data: {
|
|
51
113
|
resizeHandlePos: nextResizeHandlePos,
|
|
52
114
|
},
|
|
53
|
-
})
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (dispatch) {
|
|
118
|
+
dispatch(customTr);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
54
121
|
return false;
|
|
55
122
|
};
|
|
56
123
|
|
|
@@ -69,39 +136,24 @@ export const initiateKeyboardColumnResizing: Command = (
|
|
|
69
136
|
const cell = findCellClosestToPos(selection.$from);
|
|
70
137
|
|
|
71
138
|
if (selectionRect && cell && view) {
|
|
72
|
-
|
|
73
|
-
const width = currentColWidth(view, cell.pos, cellAttrs as CellAttributes);
|
|
74
|
-
|
|
75
|
-
updateResizeHandleAndStatePosition(
|
|
139
|
+
return updateResizeHandleAndStatePosition(
|
|
76
140
|
selectionRect.top,
|
|
77
141
|
selectionRect.right,
|
|
78
142
|
cell.pos,
|
|
79
143
|
)(state, dispatch);
|
|
80
|
-
|
|
81
|
-
tableResizingPluginCreateCommand({
|
|
82
|
-
type: 'SET_DRAGGING',
|
|
83
|
-
data: {
|
|
84
|
-
dragging: {
|
|
85
|
-
startX: 0,
|
|
86
|
-
startWidth: width,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
})(state, dispatch);
|
|
90
|
-
return true;
|
|
91
144
|
}
|
|
92
145
|
return false;
|
|
93
146
|
};
|
|
94
147
|
|
|
95
148
|
export const activateNextResizeArea =
|
|
96
149
|
(direction: Direction): Command =>
|
|
97
|
-
(state, dispatch) => {
|
|
150
|
+
(state, dispatch, view) => {
|
|
98
151
|
if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
99
152
|
return false;
|
|
100
153
|
}
|
|
101
|
-
const { resizeHandlePos
|
|
102
|
-
getTableResizingPluginState(state) || {};
|
|
154
|
+
const { resizeHandlePos } = getTableResizingPluginState(state) || {};
|
|
103
155
|
// If No resizing has initiated, skip to regular handler
|
|
104
|
-
if (!resizeHandlePos
|
|
156
|
+
if (!resizeHandlePos) {
|
|
105
157
|
return false;
|
|
106
158
|
}
|
|
107
159
|
|
|
@@ -135,11 +187,11 @@ export const activateNextResizeArea =
|
|
|
135
187
|
// we are somewhere in between the side columns of the table
|
|
136
188
|
const offset = $nextCell.pos - $nextCell.start(-1);
|
|
137
189
|
const rectForNextCell = tableMap.findCell(offset);
|
|
138
|
-
updateResizeHandleAndStatePosition(
|
|
190
|
+
return updateResizeHandleAndStatePosition(
|
|
139
191
|
rectForNextCell.top,
|
|
140
192
|
rectForNextCell.right,
|
|
141
193
|
$nextCell.pos,
|
|
142
|
-
)(state, dispatch);
|
|
194
|
+
)(state, dispatch, view);
|
|
143
195
|
} else {
|
|
144
196
|
// current position is in the one of the side columns of the table(left or right)
|
|
145
197
|
if (currentCellRect.left === 0) {
|
|
@@ -151,25 +203,25 @@ export const activateNextResizeArea =
|
|
|
151
203
|
) + closestTable.start;
|
|
152
204
|
const $lastCell = state.doc.resolve(lastCellInCurrentRow);
|
|
153
205
|
|
|
154
|
-
updateResizeHandleAndStatePosition(
|
|
206
|
+
return updateResizeHandleAndStatePosition(
|
|
155
207
|
currentCellRect.top,
|
|
156
208
|
tableMap.width,
|
|
157
209
|
$lastCell.pos,
|
|
158
|
-
)(state, dispatch);
|
|
210
|
+
)(state, dispatch, view);
|
|
159
211
|
} else if (tableMap.width === currentCellRect.right) {
|
|
160
212
|
const firsCellInCurrentRow =
|
|
161
213
|
tableMap.positionAt(currentCellRect.top, 0, tableNode) +
|
|
162
214
|
closestTable.start;
|
|
163
215
|
const $nextCell = state.doc.resolve(firsCellInCurrentRow);
|
|
164
216
|
|
|
165
|
-
updateResizeHandleAndStatePosition(
|
|
217
|
+
return updateResizeHandleAndStatePosition(
|
|
166
218
|
currentCellRect.top,
|
|
167
219
|
1,
|
|
168
220
|
$nextCell.pos,
|
|
169
221
|
)(state, dispatch);
|
|
170
222
|
}
|
|
171
223
|
}
|
|
172
|
-
return
|
|
224
|
+
return false;
|
|
173
225
|
};
|
|
174
226
|
|
|
175
227
|
export const changeColumnWidthByStep =
|
|
@@ -178,11 +230,16 @@ export const changeColumnWidthByStep =
|
|
|
178
230
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
179
231
|
): Command =>
|
|
180
232
|
(state, dispatch, view) => {
|
|
233
|
+
let customTr = state.tr;
|
|
234
|
+
const fakeDispatch = (tr: Transaction) => {
|
|
235
|
+
customTr = tr;
|
|
236
|
+
};
|
|
181
237
|
if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
182
238
|
return false;
|
|
183
239
|
}
|
|
184
|
-
const { resizeHandlePos
|
|
185
|
-
|
|
240
|
+
const { resizeHandlePos } = getTableResizingPluginState(state);
|
|
241
|
+
const cell = findCellClosestToPos(state.selection.$from);
|
|
242
|
+
if (!view || !resizeHandlePos || !cell) {
|
|
186
243
|
return false;
|
|
187
244
|
}
|
|
188
245
|
|
|
@@ -205,6 +262,18 @@ export const changeColumnWidthByStep =
|
|
|
205
262
|
dom = dom.closest('table') as HTMLTableElement;
|
|
206
263
|
}
|
|
207
264
|
|
|
265
|
+
const cellAttrs = cell?.node.attrs;
|
|
266
|
+
const width = currentColWidth(view, cell?.pos, cellAttrs as CellAttributes);
|
|
267
|
+
tableResizingPluginCreateCommand({
|
|
268
|
+
type: 'SET_DRAGGING',
|
|
269
|
+
data: {
|
|
270
|
+
dragging: {
|
|
271
|
+
startX: 0,
|
|
272
|
+
startWidth: width,
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
})(state, fakeDispatch);
|
|
276
|
+
|
|
208
277
|
const maxSize = getTableMaxWidth({
|
|
209
278
|
table: originalTable,
|
|
210
279
|
tableStart: tableStartPosition,
|
|
@@ -240,15 +309,61 @@ export const changeColumnWidthByStep =
|
|
|
240
309
|
resizingSelectedColumns ? selectedColumns : undefined,
|
|
241
310
|
);
|
|
242
311
|
|
|
243
|
-
|
|
312
|
+
customTr = updateColumnWidths(
|
|
244
313
|
newResizeState,
|
|
245
314
|
originalTable,
|
|
246
315
|
tableStartPosition,
|
|
247
|
-
)(
|
|
316
|
+
)(customTr);
|
|
248
317
|
|
|
249
318
|
if (dispatch) {
|
|
250
|
-
dispatch(
|
|
319
|
+
dispatch(customTr);
|
|
251
320
|
}
|
|
252
321
|
|
|
253
322
|
return true;
|
|
254
323
|
};
|
|
324
|
+
|
|
325
|
+
export const stopKeyboardColumnResizing =
|
|
326
|
+
(originalTr?: Transaction): Command =>
|
|
327
|
+
(state, dispatch) => {
|
|
328
|
+
if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
let customTr = originalTr || state.tr;
|
|
332
|
+
const fakeDispatch = (tr: Transaction) => {
|
|
333
|
+
customTr = tr;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const decorationWithoutWidget = clearColumnResizingDecorations()({
|
|
337
|
+
tr: customTr,
|
|
338
|
+
decorationSet: getDecorations(state),
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const decorationWithoutWidgetAndHandle = updateDecorations(
|
|
342
|
+
customTr.doc,
|
|
343
|
+
decorationWithoutWidget,
|
|
344
|
+
[],
|
|
345
|
+
TableDecorations.COLUMN_RESIZING_HANDLE_LINE,
|
|
346
|
+
);
|
|
347
|
+
getTablePluginCommand(
|
|
348
|
+
{
|
|
349
|
+
type: 'STOP_KEYBOARD_COLUMN_RESIZE',
|
|
350
|
+
data: {
|
|
351
|
+
decorationSet: decorationWithoutWidgetAndHandle,
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
customTr,
|
|
355
|
+
)(state, fakeDispatch);
|
|
356
|
+
|
|
357
|
+
tableResizingPluginCreateCommand(
|
|
358
|
+
{
|
|
359
|
+
type: 'STOP_RESIZING',
|
|
360
|
+
},
|
|
361
|
+
() => customTr.setMeta('scrollIntoView', false),
|
|
362
|
+
)(state, fakeDispatch);
|
|
363
|
+
|
|
364
|
+
if (dispatch) {
|
|
365
|
+
dispatch(customTr);
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
return false;
|
|
369
|
+
};
|