@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.
Files changed (49) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/commands/column-resize.js +115 -45
  3. package/dist/cjs/commands/go-to-next-cell.js +7 -11
  4. package/dist/cjs/commands/misc.js +3 -2
  5. package/dist/cjs/commands/selection.js +3 -3
  6. package/dist/cjs/event-handlers.js +38 -25
  7. package/dist/cjs/pm-plugins/keymap.js +1 -0
  8. package/dist/cjs/pm-plugins/main.js +43 -9
  9. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
  10. package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
  11. package/dist/cjs/reducer.js +5 -2
  12. package/dist/es2019/commands/column-resize.js +100 -35
  13. package/dist/es2019/commands/go-to-next-cell.js +7 -9
  14. package/dist/es2019/commands/misc.js +3 -2
  15. package/dist/es2019/commands/selection.js +5 -5
  16. package/dist/es2019/event-handlers.js +17 -3
  17. package/dist/es2019/pm-plugins/keymap.js +3 -2
  18. package/dist/es2019/pm-plugins/main.js +41 -5
  19. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
  20. package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
  21. package/dist/es2019/reducer.js +5 -2
  22. package/dist/esm/commands/column-resize.js +105 -35
  23. package/dist/esm/commands/go-to-next-cell.js +7 -11
  24. package/dist/esm/commands/misc.js +3 -2
  25. package/dist/esm/commands/selection.js +5 -5
  26. package/dist/esm/event-handlers.js +38 -25
  27. package/dist/esm/pm-plugins/keymap.js +3 -2
  28. package/dist/esm/pm-plugins/main.js +38 -4
  29. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
  30. package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
  31. package/dist/esm/reducer.js +5 -2
  32. package/dist/types/commands/column-resize.d.ts +2 -0
  33. package/dist/types/commands/misc.d.ts +1 -1
  34. package/dist/types/types.d.ts +16 -0
  35. package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
  36. package/dist/types-ts4.5/commands/misc.d.ts +1 -1
  37. package/dist/types-ts4.5/types.d.ts +16 -0
  38. package/package.json +2 -2
  39. package/src/commands/column-resize.ts +155 -40
  40. package/src/commands/go-to-next-cell.ts +6 -15
  41. package/src/commands/misc.ts +2 -0
  42. package/src/commands/selection.ts +5 -5
  43. package/src/event-handlers.ts +21 -4
  44. package/src/pm-plugins/keymap.ts +3 -0
  45. package/src/pm-plugins/main.ts +47 -2
  46. package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
  47. package/src/pm-plugins/table-resizing/plugin.ts +18 -1
  48. package/src/reducer.ts +5 -2
  49. package/src/types.ts +16 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#63203](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/63203) [`2bf8f7ffabfd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2bf8f7ffabfd) - ECA11Y-194: Stop keyboard column resizing when table updated or lost focus
8
+
3
9
  ## 7.2.3
4
10
 
5
11
  ### Patch Changes
@@ -3,30 +3,66 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.initiateKeyboardColumnResizing = exports.changeColumnWidthByStep = exports.activateNextResizeArea = void 0;
6
+ exports.stopKeyboardColumnResizing = exports.initiateKeyboardColumnResizing = exports.changeColumnWidthByStep = exports.activateNextResizeArea = void 0;
7
7
  var _styles = require("@atlaskit/editor-common/styles");
8
8
  var _editorTables = require("@atlaskit/editor-tables");
9
9
  var _utils = require("@atlaskit/editor-tables/utils");
10
10
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
- var _pluginFactory = require("../pm-plugins/table-resizing/plugin-factory");
12
- var _utils2 = require("../pm-plugins/table-resizing/utils");
11
+ var _plugin = require("../pm-plugins/decorations/plugin");
12
+ var _utils2 = require("../pm-plugins/decorations/utils");
13
+ var _pluginFactory = require("../pm-plugins/plugin-factory");
14
+ var _pluginFactory2 = require("../pm-plugins/table-resizing/plugin-factory");
15
+ var _pluginKey = require("../pm-plugins/table-resizing/plugin-key");
16
+ var _utils3 = require("../pm-plugins/table-resizing/utils");
13
17
  var _transforms = require("../transforms");
14
- var _utils3 = require("../utils");
15
- var _index = require("./index");
18
+ var _types = require("../types");
19
+ var _utils4 = require("../utils");
20
+ var getTablePluginCommand = function getTablePluginCommand(actionPayload, originalTr) {
21
+ return (0, _pluginFactory.createCommand)(function () {
22
+ return actionPayload;
23
+ }, function (tr) {
24
+ return (originalTr || tr).setMeta('addToHistory', false);
25
+ });
26
+ };
16
27
  var updateResizeHandleAndStatePosition = function updateResizeHandleAndStatePosition(rowIndex, columnIndex, nextResizeHandlePos) {
17
28
  return function (state, dispatch) {
18
- (0, _index.addResizeHandleDecorations)(rowIndex, columnIndex, true)(state, dispatch);
19
- // Currently only 'right' position is used in showResizeHandleLine
20
- (0, _index.showResizeHandleLine)({
21
- left: 0,
29
+ var customTr = state.tr;
30
+ var _getPluginState = (0, _pluginFactory.getPluginState)(state),
31
+ allowColumnResizing = _getPluginState.pluginConfig.allowColumnResizing,
32
+ getIntl = _getPluginState.getIntl;
33
+ var fakeDispatch = function fakeDispatch(tr) {
34
+ customTr = tr;
35
+ };
36
+ if (!allowColumnResizing) {
37
+ return false;
38
+ }
39
+ var decorationsWithWidget = (0, _utils2.buildColumnResizingDecorations)(rowIndex, columnIndex, true, getIntl)({
40
+ tr: customTr,
41
+ decorationSet: (0, _plugin.getDecorations)(state)
42
+ });
43
+ var decorationsWithWidgetAndHandle = (0, _utils4.updateDecorations)(customTr.doc, decorationsWithWidget, (0, _utils4.createColumnLineResize)(state.selection, {
22
44
  right: columnIndex
23
- })(state, dispatch);
24
- (0, _pluginFactory.createCommand)({
45
+ }), _types.TableDecorations.COLUMN_RESIZING_HANDLE_LINE);
46
+ getTablePluginCommand({
47
+ type: 'START_KEYBOARD_COLUMN_RESIZE',
48
+ data: {
49
+ resizeHandleRowIndex: rowIndex,
50
+ resizeHandleColumnIndex: columnIndex,
51
+ resizeHandleIncludeTooltip: true,
52
+ isKeyboardResize: true,
53
+ decorationSet: decorationsWithWidgetAndHandle
54
+ }
55
+ }, customTr)(state, fakeDispatch);
56
+ customTr.setMeta(_pluginKey.pluginKey, {
25
57
  type: 'SET_RESIZE_HANDLE_POSITION',
26
58
  data: {
27
59
  resizeHandlePos: nextResizeHandlePos
28
60
  }
29
- })(state, dispatch);
61
+ });
62
+ if (dispatch) {
63
+ dispatch(customTr);
64
+ return true;
65
+ }
30
66
  return false;
31
67
  };
32
68
  };
@@ -38,32 +74,19 @@ var initiateKeyboardColumnResizing = exports.initiateKeyboardColumnResizing = fu
38
74
  var selectionRect = (0, _utils.isSelectionType)(selection, 'cell') ? (0, _utils.getSelectionRect)(selection) : (0, _utils.findCellRectClosestToPos)(selection.$from);
39
75
  var cell = (0, _utils.findCellClosestToPos)(selection.$from);
40
76
  if (selectionRect && cell && view) {
41
- var cellAttrs = cell.node.attrs;
42
- var width = (0, _utils2.currentColWidth)(view, cell.pos, cellAttrs);
43
- updateResizeHandleAndStatePosition(selectionRect.top, selectionRect.right, cell.pos)(state, dispatch);
44
- (0, _pluginFactory.createCommand)({
45
- type: 'SET_DRAGGING',
46
- data: {
47
- dragging: {
48
- startX: 0,
49
- startWidth: width
50
- }
51
- }
52
- })(state, dispatch);
53
- return true;
77
+ return updateResizeHandleAndStatePosition(selectionRect.top, selectionRect.right, cell.pos)(state, dispatch);
54
78
  }
55
79
  return false;
56
80
  };
57
81
  var activateNextResizeArea = exports.activateNextResizeArea = function activateNextResizeArea(direction) {
58
- return function (state, dispatch) {
82
+ return function (state, dispatch, view) {
59
83
  if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
60
84
  return false;
61
85
  }
62
- var _ref = (0, _pluginFactory.getPluginState)(state) || {},
63
- resizeHandlePos = _ref.resizeHandlePos,
64
- dragging = _ref.dragging;
86
+ var _ref = (0, _pluginFactory2.getPluginState)(state) || {},
87
+ resizeHandlePos = _ref.resizeHandlePos;
65
88
  // If No resizing has initiated, skip to regular handler
66
- if (!resizeHandlePos || !dragging) {
89
+ if (!resizeHandlePos) {
67
90
  return false;
68
91
  }
69
92
  var selection = state.selection;
@@ -88,31 +111,35 @@ var activateNextResizeArea = exports.activateNextResizeArea = function activateN
88
111
  // we are somewhere in between the side columns of the table
89
112
  var offset = $nextCell.pos - $nextCell.start(-1);
90
113
  var rectForNextCell = tableMap.findCell(offset);
91
- updateResizeHandleAndStatePosition(rectForNextCell.top, rectForNextCell.right, $nextCell.pos)(state, dispatch);
114
+ return updateResizeHandleAndStatePosition(rectForNextCell.top, rectForNextCell.right, $nextCell.pos)(state, dispatch, view);
92
115
  } else {
93
116
  // current position is in the one of the side columns of the table(left or right)
94
117
  if (currentCellRect.left === 0) {
95
118
  var lastCellInCurrentRow = tableMap.positionAt(currentCellRect.top, tableMap.width - 1, tableNode) + closestTable.start;
96
119
  var $lastCell = state.doc.resolve(lastCellInCurrentRow);
97
- updateResizeHandleAndStatePosition(currentCellRect.top, tableMap.width, $lastCell.pos)(state, dispatch);
120
+ return updateResizeHandleAndStatePosition(currentCellRect.top, tableMap.width, $lastCell.pos)(state, dispatch, view);
98
121
  } else if (tableMap.width === currentCellRect.right) {
99
122
  var firsCellInCurrentRow = tableMap.positionAt(currentCellRect.top, 0, tableNode) + closestTable.start;
100
123
  var _$nextCell = state.doc.resolve(firsCellInCurrentRow);
101
- updateResizeHandleAndStatePosition(currentCellRect.top, 1, _$nextCell.pos)(state, dispatch);
124
+ return updateResizeHandleAndStatePosition(currentCellRect.top, 1, _$nextCell.pos)(state, dispatch);
102
125
  }
103
126
  }
104
- return true;
127
+ return false;
105
128
  };
106
129
  };
107
130
  var changeColumnWidthByStep = exports.changeColumnWidthByStep = function changeColumnWidthByStep(stepSize, getEditorContainerWidth) {
108
131
  return function (state, dispatch, view) {
132
+ var customTr = state.tr;
133
+ var fakeDispatch = function fakeDispatch(tr) {
134
+ customTr = tr;
135
+ };
109
136
  if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
110
137
  return false;
111
138
  }
112
- var _getTableResizingPlug = (0, _pluginFactory.getPluginState)(state),
113
- resizeHandlePos = _getTableResizingPlug.resizeHandlePos,
114
- dragging = _getTableResizingPlug.dragging;
115
- if (!view || !resizeHandlePos || !dragging) {
139
+ var _getTableResizingPlug = (0, _pluginFactory2.getPluginState)(state),
140
+ resizeHandlePos = _getTableResizingPlug.resizeHandlePos;
141
+ var cell = (0, _utils.findCellClosestToPos)(state.selection.$from);
142
+ if (!view || !resizeHandlePos || !cell) {
116
143
  return false;
117
144
  }
118
145
  var $cell = state.doc.resolve(resizeHandlePos);
@@ -125,14 +152,25 @@ var changeColumnWidthByStep = exports.changeColumnWidthByStep = function changeC
125
152
  if (dom && dom.nodeName !== 'TABLE') {
126
153
  dom = dom.closest('table');
127
154
  }
128
- var maxSize = (0, _utils2.getTableMaxWidth)({
155
+ var cellAttrs = cell === null || cell === void 0 ? void 0 : cell.node.attrs;
156
+ var width = (0, _utils3.currentColWidth)(view, cell === null || cell === void 0 ? void 0 : cell.pos, cellAttrs);
157
+ (0, _pluginFactory2.createCommand)({
158
+ type: 'SET_DRAGGING',
159
+ data: {
160
+ dragging: {
161
+ startX: 0,
162
+ startWidth: width
163
+ }
164
+ }
165
+ })(state, fakeDispatch);
166
+ var maxSize = (0, _utils3.getTableMaxWidth)({
129
167
  table: originalTable,
130
168
  tableStart: tableStartPosition,
131
169
  state: state,
132
170
  layout: originalTable.attrs.layout,
133
171
  getEditorContainerWidth: getEditorContainerWidth
134
172
  });
135
- var initialResizeState = (0, _utils2.getResizeState)({
173
+ var initialResizeState = (0, _utils3.getResizeState)({
136
174
  minWidth: _styles.tableCellMinWidth,
137
175
  maxSize: maxSize,
138
176
  table: originalTable,
@@ -140,16 +178,48 @@ var changeColumnWidthByStep = exports.changeColumnWidthByStep = function changeC
140
178
  start: tableStartPosition,
141
179
  domAtPos: domAtPos
142
180
  });
143
- (0, _utils2.updateControls)()(state);
181
+ (0, _utils3.updateControls)()(state);
144
182
  var selectionRect = (0, _utils.getSelectionRect)(state.selection);
145
- var selectedColumns = selectionRect ? (0, _utils3.getSelectedColumnIndexes)(selectionRect) : [];
183
+ var selectedColumns = selectionRect ? (0, _utils4.getSelectedColumnIndexes)(selectionRect) : [];
146
184
  // only selected (or selected - 1) columns should be distributed
147
185
  var resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
148
- var newResizeState = (0, _utils2.resizeColumn)(initialResizeState, colIndex, stepSize, dom, resizingSelectedColumns ? selectedColumns : undefined);
149
- var tr = (0, _transforms.updateColumnWidths)(newResizeState, originalTable, tableStartPosition)(state.tr);
186
+ var newResizeState = (0, _utils3.resizeColumn)(initialResizeState, colIndex, stepSize, dom, resizingSelectedColumns ? selectedColumns : undefined);
187
+ customTr = (0, _transforms.updateColumnWidths)(newResizeState, originalTable, tableStartPosition)(customTr);
150
188
  if (dispatch) {
151
- dispatch(tr);
189
+ dispatch(customTr);
152
190
  }
153
191
  return true;
154
192
  };
193
+ };
194
+ var stopKeyboardColumnResizing = exports.stopKeyboardColumnResizing = function stopKeyboardColumnResizing(originalTr) {
195
+ return function (state, dispatch) {
196
+ if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
197
+ return false;
198
+ }
199
+ var customTr = originalTr || state.tr;
200
+ var fakeDispatch = function fakeDispatch(tr) {
201
+ customTr = tr;
202
+ };
203
+ var decorationWithoutWidget = (0, _utils2.clearColumnResizingDecorations)()({
204
+ tr: customTr,
205
+ decorationSet: (0, _plugin.getDecorations)(state)
206
+ });
207
+ var decorationWithoutWidgetAndHandle = (0, _utils4.updateDecorations)(customTr.doc, decorationWithoutWidget, [], _types.TableDecorations.COLUMN_RESIZING_HANDLE_LINE);
208
+ getTablePluginCommand({
209
+ type: 'STOP_KEYBOARD_COLUMN_RESIZE',
210
+ data: {
211
+ decorationSet: decorationWithoutWidgetAndHandle
212
+ }
213
+ }, customTr)(state, fakeDispatch);
214
+ (0, _pluginFactory2.createCommand)({
215
+ type: 'STOP_RESIZING'
216
+ }, function () {
217
+ return customTr.setMeta('scrollIntoView', false);
218
+ })(state, fakeDispatch);
219
+ if (dispatch) {
220
+ dispatch(customTr);
221
+ return true;
222
+ }
223
+ return false;
224
+ };
155
225
  };
@@ -10,29 +10,25 @@ var _tableMap = require("@atlaskit/editor-tables/table-map");
10
10
  var _utils2 = require("@atlaskit/editor-tables/utils");
11
11
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
12
  var _commandsWithAnalytics = require("../commands-with-analytics");
13
- var _pluginFactory = require("../pm-plugins/table-resizing/plugin-factory");
14
- var _hover = require("./hover");
13
+ var _pluginFactory = require("../pm-plugins/plugin-factory");
14
+ var _columnResize = require("./column-resize");
15
15
  // #region Constants
16
16
 
17
17
  var TAB_FORWARD_DIRECTION = 1;
18
18
  var TAB_BACKWARD_DIRECTION = -1;
19
19
  var goToNextCell = exports.goToNextCell = function goToNextCell(editorAnalyticsAPI) {
20
20
  return function (direction) {
21
- return function (state, dispatch) {
21
+ return function (state, dispatch, view) {
22
22
  var table = (0, _utils2.findTable)(state.selection);
23
23
  if (!table) {
24
24
  return false;
25
25
  }
26
26
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
27
- var _getResizePluginState;
28
- var isColumnResizing = !!((_getResizePluginState = (0, _pluginFactory.getPluginState)(state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging);
27
+ var _getPluginState;
28
+ var isColumnResizing = (_getPluginState = (0, _pluginFactory.getPluginState)(state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.isKeyboardResize;
29
29
  if (isColumnResizing) {
30
- (0, _pluginFactory.createCommand)({
31
- type: 'STOP_RESIZING'
32
- }, function (originalTr) {
33
- return (state.tr || originalTr).setMeta('scrollIntoView', false);
34
- })(state, dispatch);
35
- (0, _hover.hideResizeHandleLine)()(state, dispatch);
30
+ (0, _columnResize.stopKeyboardColumnResizing)()(state, dispatch, view);
31
+ return true;
36
32
  }
37
33
  }
38
34
  var map = _tableMap.TableMap.get(table.node);
@@ -454,7 +454,7 @@ var hideInsertColumnOrRowButton = exports.hideInsertColumnOrRowButton = function
454
454
  return tr.setMeta('addToHistory', false);
455
455
  });
456
456
  };
457
- var addResizeHandleDecorations = exports.addResizeHandleDecorations = function addResizeHandleDecorations(rowIndex, columnIndex, includeTooltip) {
457
+ var addResizeHandleDecorations = exports.addResizeHandleDecorations = function addResizeHandleDecorations(rowIndex, columnIndex, includeTooltip, isKeyboardResize) {
458
458
  return (0, _pluginFactory.createCommand)(function (state) {
459
459
  var tableNode = (0, _utils2.findTable)(state.selection);
460
460
  var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
@@ -472,7 +472,8 @@ var addResizeHandleDecorations = exports.addResizeHandleDecorations = function a
472
472
  }),
473
473
  resizeHandleRowIndex: rowIndex,
474
474
  resizeHandleColumnIndex: columnIndex,
475
- resizeHandleIncludeTooltip: includeTooltip
475
+ resizeHandleIncludeTooltip: includeTooltip,
476
+ isKeyboardResize: isKeyboardResize || false
476
477
  }
477
478
  };
478
479
  }, function (tr) {
@@ -11,7 +11,7 @@ var _tableMap = require("@atlaskit/editor-tables/table-map");
11
11
  var _utils = require("@atlaskit/editor-tables/utils");
12
12
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
13
  var _misc = require("../commands/misc");
14
- var _pluginFactory = require("../pm-plugins/table-resizing/plugin-factory");
14
+ var _pluginFactory = require("../pm-plugins/plugin-factory");
15
15
  var _toolbar = require("../toolbar");
16
16
  var TableSelectionDirection = exports.TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
17
17
  TableSelectionDirection["TopToBottom"] = "TopToBottom";
@@ -203,7 +203,7 @@ var arrowLeftFromText = function arrowLeftFromText(editorSelectionAPI) {
203
203
  var isColumnResizing = false;
204
204
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
205
205
  var columResizePluginState = (0, _pluginFactory.getPluginState)(state) || {};
206
- isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.dragging);
206
+ isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.isKeyboardResize);
207
207
  }
208
208
  if (isSelectionAtStartOfTable($from, selection) && $from.parent.type.name === 'paragraph' && $from.depth === table.depth + 3 &&
209
209
  // + 3 for: row, cell & paragraph nodes
@@ -237,7 +237,7 @@ var arrowRightFromText = function arrowRightFromText(editorSelectionAPI) {
237
237
  var isColumnResizing = false;
238
238
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
239
239
  var columResizePluginState = (0, _pluginFactory.getPluginState)(state) || {};
240
- isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.dragging);
240
+ isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.isKeyboardResize);
241
241
  }
242
242
  if (isSelectionAtEndOfTable($to, selection) && $to.parent.type.name === 'paragraph' && $to.depth === table.depth + 3 &&
243
243
  // + 3 for: row, cell & paragraph nodes
@@ -14,6 +14,7 @@ var _state5 = require("@atlaskit/editor-prosemirror/state");
14
14
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
15
15
  var _tableMap = require("@atlaskit/editor-tables/table-map");
16
16
  var _utils2 = require("@atlaskit/editor-tables/utils");
17
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
18
  var _commands = require("./commands");
18
19
  var _pluginFactory = require("./pm-plugins/drag-and-drop/plugin-factory");
19
20
  var _pluginFactory2 = require("./pm-plugins/plugin-factory");
@@ -172,15 +173,25 @@ var handleMouseOut = exports.handleMouseOut = function handleMouseOut(view, mous
172
173
  if ((0, _utils3.isResizeHandleDecoration)(target) && !(0, _utils3.isResizeHandleDecoration)(relatedTarget)) {
173
174
  var _state2 = view.state,
174
175
  _dispatch3 = view.dispatch;
175
- return (0, _commands.hideResizeHandleLine)()(_state2, _dispatch3);
176
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
177
+ var _getPluginState2 = (0, _pluginFactory2.getPluginState)(_state2),
178
+ isKeyboardResize = _getPluginState2.isKeyboardResize;
179
+ if (isKeyboardResize) {
180
+ // no need to hide decoration if column resizing started by keyboard
181
+ return false;
182
+ }
183
+ return (0, _commands.hideResizeHandleLine)()(_state2, _dispatch3);
184
+ } else {
185
+ return (0, _commands.hideResizeHandleLine)()(_state2, _dispatch3);
186
+ }
176
187
  }
177
188
  return false;
178
189
  };
179
190
  var handleMouseEnter = exports.handleMouseEnter = function handleMouseEnter(view, mouseEvent) {
180
191
  var state = view.state,
181
192
  dispatch = view.dispatch;
182
- var _getPluginState2 = (0, _pluginFactory2.getPluginState)(state),
183
- isTableHovered = _getPluginState2.isTableHovered;
193
+ var _getPluginState3 = (0, _pluginFactory2.getPluginState)(state),
194
+ isTableHovered = _getPluginState3.isTableHovered;
184
195
  if (!isTableHovered) {
185
196
  return (0, _commands.setTableHovered)(true)(state, dispatch);
186
197
  }
@@ -192,11 +203,11 @@ var handleMouseLeave = exports.handleMouseLeave = function handleMouseLeave(view
192
203
  }
193
204
  var state = view.state,
194
205
  dispatch = view.dispatch;
195
- var _getPluginState3 = (0, _pluginFactory2.getPluginState)(state),
196
- insertColumnButtonIndex = _getPluginState3.insertColumnButtonIndex,
197
- insertRowButtonIndex = _getPluginState3.insertRowButtonIndex,
198
- isDragAndDropEnabled = _getPluginState3.isDragAndDropEnabled,
199
- isTableHovered = _getPluginState3.isTableHovered;
206
+ var _getPluginState4 = (0, _pluginFactory2.getPluginState)(state),
207
+ insertColumnButtonIndex = _getPluginState4.insertColumnButtonIndex,
208
+ insertRowButtonIndex = _getPluginState4.insertRowButtonIndex,
209
+ isDragAndDropEnabled = _getPluginState4.isDragAndDropEnabled,
210
+ isTableHovered = _getPluginState4.isTableHovered;
200
211
  if (isTableHovered) {
201
212
  if (isDragAndDropEnabled) {
202
213
  var _getDragDropPluginSta = (0, _pluginFactory.getPluginState)(state),
@@ -229,9 +240,9 @@ var handleMouseMove = exports.handleMouseMove = function handleMouseMove(view, e
229
240
  if ((0, _utils3.isColumnControlsDecorations)(element) || (0, _utils3.isDragColumnFloatingInsertDot)(element)) {
230
241
  var state = view.state,
231
242
  dispatch = view.dispatch;
232
- var _getPluginState4 = (0, _pluginFactory2.getPluginState)(state),
233
- insertColumnButtonIndex = _getPluginState4.insertColumnButtonIndex,
234
- isDragAndDropEnabled = _getPluginState4.isDragAndDropEnabled;
243
+ var _getPluginState5 = (0, _pluginFactory2.getPluginState)(state),
244
+ insertColumnButtonIndex = _getPluginState5.insertColumnButtonIndex,
245
+ isDragAndDropEnabled = _getPluginState5.isDragAndDropEnabled;
235
246
  var _getColumnOrRowIndex9 = (0, _utils3.getColumnOrRowIndex)(element),
236
247
  _getColumnOrRowIndex10 = (0, _slicedToArray2.default)(_getColumnOrRowIndex9, 2),
237
248
  startIndex = _getColumnOrRowIndex10[0],
@@ -244,8 +255,8 @@ var handleMouseMove = exports.handleMouseMove = function handleMouseMove(view, e
244
255
  if ((0, _utils3.isRowControlsButton)(element) || (0, _utils3.isDragRowFloatingInsertDot)(element)) {
245
256
  var _state3 = view.state,
246
257
  _dispatch4 = view.dispatch;
247
- var _getPluginState5 = (0, _pluginFactory2.getPluginState)(_state3),
248
- insertRowButtonIndex = _getPluginState5.insertRowButtonIndex;
258
+ var _getPluginState6 = (0, _pluginFactory2.getPluginState)(_state3),
259
+ insertRowButtonIndex = _getPluginState6.insertRowButtonIndex;
249
260
  var _getColumnOrRowIndex11 = (0, _utils3.getColumnOrRowIndex)(element),
250
261
  _getColumnOrRowIndex12 = (0, _slicedToArray2.default)(_getColumnOrRowIndex11, 2),
251
262
  _startIndex3 = _getColumnOrRowIndex12[0],
@@ -260,19 +271,21 @@ var handleMouseMove = exports.handleMouseMove = function handleMouseMove(view, e
260
271
  if (_positionColumn !== null) {
261
272
  var _state4 = view.state,
262
273
  _dispatch5 = view.dispatch;
263
- var _getPluginState6 = (0, _pluginFactory2.getPluginState)(_state4),
264
- resizeHandleColumnIndex = _getPluginState6.resizeHandleColumnIndex,
265
- resizeHandleRowIndex = _getPluginState6.resizeHandleRowIndex;
274
+ var _getPluginState7 = (0, _pluginFactory2.getPluginState)(_state4),
275
+ resizeHandleColumnIndex = _getPluginState7.resizeHandleColumnIndex,
276
+ resizeHandleRowIndex = _getPluginState7.resizeHandleRowIndex;
277
+ var isKeyboardResize = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz') ? (0, _pluginFactory2.getPluginState)(_state4).isKeyboardResize : false;
266
278
  var tableCell = (0, _utils.closestElement)(element, 'td, th');
267
279
  var cellStartPosition = view.posAtDOM(tableCell, 0);
268
280
  var rect = (0, _utils2.findCellRectClosestToPos)(_state4.doc.resolve(cellStartPosition));
269
281
  if (rect) {
270
282
  var columnEndIndexTarget = _positionColumn === 'left' ? rect.left : rect.right;
271
283
  var rowIndexTarget = rect.top;
272
- if (columnEndIndexTarget !== resizeHandleColumnIndex || rowIndexTarget !== resizeHandleRowIndex || !(0, _utils3.hasResizeHandler)({
284
+ if ((columnEndIndexTarget !== resizeHandleColumnIndex || rowIndexTarget !== resizeHandleRowIndex || !(0, _utils3.hasResizeHandler)({
273
285
  target: element,
274
286
  columnEndIndexTarget: columnEndIndexTarget
275
- })) {
287
+ })) && !isKeyboardResize // if initiated by keyboard don't need to react on hover for other resize sliders
288
+ ) {
276
289
  return (0, _commands.addResizeHandleDecorations)(rowIndexTarget, columnEndIndexTarget, true)(_state4, _dispatch5);
277
290
  }
278
291
  }
@@ -337,8 +350,8 @@ var handleCut = exports.handleCut = function handleCut(oldTr, oldState, newState
337
350
  if (isTableSelected) {
338
351
  tr = (0, _utils2.removeTable)(tr);
339
352
  } else if (tr.selection.isRowSelection()) {
340
- var _getPluginState7 = (0, _pluginFactory2.getPluginState)(newState),
341
- isHeaderRowRequired = _getPluginState7.pluginConfig.isHeaderRowRequired;
353
+ var _getPluginState8 = (0, _pluginFactory2.getPluginState)(newState),
354
+ isHeaderRowRequired = _getPluginState8.pluginConfig.isHeaderRowRequired;
342
355
  tr = (0, _transforms.deleteRows)(rect, isHeaderRowRequired)(tr);
343
356
  } else if (tr.selection.isColSelection()) {
344
357
  tr = (0, _transforms.deleteColumns)(rect, (0, _getAllowAddColumnCustomStep.getAllowAddColumnCustomStep)(oldState), editorView)(tr);
@@ -350,8 +363,8 @@ var handleCut = exports.handleCut = function handleCut(oldTr, oldState, newState
350
363
  return tr;
351
364
  };
352
365
  var isTableInFocus = exports.isTableInFocus = function isTableInFocus(view) {
353
- var _getPluginState8, _getResizePluginState;
354
- return !!((_getPluginState8 = (0, _pluginFactory2.getPluginState)(view.state)) !== null && _getPluginState8 !== void 0 && _getPluginState8.tableNode) && !((_getResizePluginState = (0, _pluginFactory3.getPluginState)(view.state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging);
366
+ var _getPluginState9, _getResizePluginState;
367
+ return !!((_getPluginState9 = (0, _pluginFactory2.getPluginState)(view.state)) !== null && _getPluginState9 !== void 0 && _getPluginState9.tableNode) && !((_getResizePluginState = (0, _pluginFactory3.getPluginState)(view.state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging);
355
368
  };
356
369
  var whenTableInFocus = exports.whenTableInFocus = function whenTableInFocus(eventHandler, elementContentRects) {
357
370
  return function (view, mouseEvent) {
@@ -365,9 +378,9 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
365
378
  var _tableElement$dataset;
366
379
  var target = mouseEvent.target;
367
380
  var maybeTableCell = (0, _utils.isElementInTableCell)(target);
368
- var _getPluginState9 = (0, _pluginFactory2.getPluginState)(view.state),
369
- tableNode = _getPluginState9.tableNode,
370
- tableRef = _getPluginState9.tableRef;
381
+ var _getPluginState10 = (0, _pluginFactory2.getPluginState)(view.state),
382
+ tableNode = _getPluginState10.tableNode,
383
+ tableRef = _getPluginState10.tableRef;
371
384
  var tableElement = (0, _utils.closestElement)(target, 'table');
372
385
 
373
386
  // hover will only trigger if target localId is the same with selected localId
@@ -57,6 +57,7 @@ function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEn
57
57
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveLeft.common, (0, _columnResize.activateNextResizeArea)(-1), list);
58
58
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.decreaseMediaSize.common, (0, _columnResize.changeColumnWidthByStep)(-10, getEditorContainerWidth), list);
59
59
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.increaseMediaSize.common, (0, _columnResize.changeColumnWidthByStep)(10, getEditorContainerWidth), list);
60
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.escape.common, (0, _columnResize.stopKeyboardColumnResizing)(), list);
60
61
  }
61
62
  return (0, _keymap.keymap)(list);
62
63
  }
@@ -12,7 +12,11 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
12
  var _transforms = require("@atlaskit/editor-common/transforms");
13
13
  var _utils = require("@atlaskit/editor-common/utils");
14
14
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
15
+ var _editorTables = require("@atlaskit/editor-tables");
16
+ var _utils3 = require("@atlaskit/editor-tables/utils");
17
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
18
  var _commands = require("../commands");
19
+ var _columnResize = require("../commands/column-resize");
16
20
  var _misc = require("../commands/misc");
17
21
  var _eventHandlers = require("../event-handlers");
18
22
  var _table = require("../nodeviews/table");
@@ -21,7 +25,7 @@ var _TableRow = _interopRequireDefault(require("../nodeviews/TableRow"));
21
25
  var _plugin = require("../pm-plugins/decorations/plugin");
22
26
  var _transforms2 = require("../transforms");
23
27
  var _types = require("../types");
24
- var _utils3 = require("../utils");
28
+ var _utils4 = require("../utils");
25
29
  var _paste = require("../utils/paste");
26
30
  var _defaultTableSelection = require("./default-table-selection");
27
31
  var _pluginFactory = require("./plugin-factory");
@@ -106,7 +110,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
106
110
  var domAtPos = editorView.domAtPos.bind(editorView);
107
111
  editorViewRef = editorView;
108
112
  return {
109
- update: function update(view) {
113
+ update: function update(view, prevState) {
110
114
  var state = view.state,
111
115
  dispatch = view.dispatch;
112
116
  var selection = state.selection;
@@ -117,6 +121,28 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
117
121
  if (parent) {
118
122
  tableRef = parent.querySelector('table') || undefined;
119
123
  }
124
+ var tableNode = (0, _utils3.findTable)(state.selection);
125
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
126
+ // when cursor leaves the table we need to stop column resizing
127
+ var pluginPrevState = (0, _pluginFactory.getPluginState)(prevState);
128
+ var isStopKeyboardColumResizing = pluginPrevState.isResizeHandleWidgetAdded && pluginPrevState.isKeyboardResize;
129
+ if (isStopKeyboardColumResizing) {
130
+ var isTableNodesDifferent = (pluginPrevState === null || pluginPrevState === void 0 ? void 0 : pluginPrevState.tableNode) !== (tableNode === null || tableNode === void 0 ? void 0 : tableNode.node);
131
+ if (pluginPrevState !== null && pluginPrevState !== void 0 && pluginPrevState.tableNode && tableNode && isTableNodesDifferent) {
132
+ var oldRowsNumber = _editorTables.TableMap.get(pluginPrevState.tableNode).height;
133
+ var newRowsNumber = _editorTables.TableMap.get(tableNode.node).height;
134
+ if (oldRowsNumber !== newRowsNumber ||
135
+ // Add/delete row
136
+ tableNode.node.attrs.localId !== pluginPrevState.tableNode.attrs.localId) {
137
+ // Jump to another table
138
+ (0, _columnResize.stopKeyboardColumnResizing)()(state, dispatch);
139
+ }
140
+ } else if (!tableNode) {
141
+ // selection outside of table
142
+ (0, _columnResize.stopKeyboardColumnResizing)()(state, dispatch);
143
+ }
144
+ }
145
+ }
120
146
  }
121
147
  if (pluginState.tableRef !== tableRef) {
122
148
  (0, _commands.setTableRef)(tableRef)(state, dispatch);
@@ -156,7 +182,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
156
182
  if (!(0, _coreUtils.insideTable)(editorState) && (0, _paste.isHeaderRowRequired)(editorState)) {
157
183
  slice = (0, _misc.transformSliceToAddTableHeaders)(slice, schema);
158
184
  }
159
- slice = (0, _utils3.transformSliceToFixHardBreakProblemOnCopyFromCell)(slice, schema);
185
+ slice = (0, _utils4.transformSliceToFixHardBreakProblemOnCopyFromCell)(slice, schema);
160
186
 
161
187
  // We do this separately, so it also applies to drag/drop events
162
188
  // This needs to go before `transformSliceToRemoveOpenExpand`
@@ -167,14 +193,14 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
167
193
  slice = (0, _transforms.transformSliceToRemoveOpenExpand)(slice, schema);
168
194
 
169
195
  /** If a partial paste of table, paste only table's content */
170
- slice = (0, _utils3.transformSliceToRemoveOpenTable)(slice, schema);
196
+ slice = (0, _utils4.transformSliceToRemoveOpenTable)(slice, schema);
171
197
 
172
198
  /** If a partial paste of bodied extension, paste only text */
173
199
  slice = (0, _transforms.transformSliceToRemoveOpenBodiedExtension)(slice, schema);
174
200
 
175
201
  /** If a partial paste of multi bodied extension, paste only children */
176
202
  slice = (0, _transforms.transformSliceToRemoveOpenMultiBodiedExtension)(slice, schema);
177
- slice = (0, _utils3.transformSliceToCorrectEmptyTableCells)(slice, schema);
203
+ slice = (0, _utils4.transformSliceToCorrectEmptyTableCells)(slice, schema);
178
204
  if (!pluginConfig.allowColumnResizing) {
179
205
  slice = (0, _misc.transformSliceToRemoveColumnsWidths)(slice, schema);
180
206
  }
@@ -190,7 +216,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
190
216
  var state = _ref2.state,
191
217
  dispatch = _ref2.dispatch;
192
218
  var decorationSet = _plugin.pluginKey.getState(state);
193
- if ((0, _utils3.findControlsHoverDecoration)(decorationSet).length) {
219
+ if ((0, _utils4.findControlsHoverDecoration)(decorationSet).length) {
194
220
  (0, _commands.clearHoverSelection)()(state, dispatch);
195
221
  }
196
222
 
@@ -213,9 +239,17 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
213
239
  var maybeTr = (0, _utils.closestElement)(domRef, 'tr');
214
240
  return maybeTr ? maybeTr.classList.contains('sticky') : false;
215
241
  },
216
- handleTextInput: function handleTextInput(_ref3, _from, _to, text) {
217
- var state = _ref3.state,
218
- dispatch = _ref3.dispatch;
242
+ handleTextInput: function handleTextInput(view, _from, _to, text) {
243
+ var state = view.state,
244
+ dispatch = view.dispatch;
245
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
246
+ var _getPluginState = (0, _pluginFactory.getPluginState)(state),
247
+ isKeyboardResize = _getPluginState.isKeyboardResize;
248
+ if (isKeyboardResize) {
249
+ (0, _columnResize.stopKeyboardColumnResizing)()(state, dispatch);
250
+ return false;
251
+ }
252
+ }
219
253
  var tr = (0, _transforms2.replaceSelectedTable)(state, text, _analytics.INPUT_METHOD.KEYBOARD, editorAnalyticsAPI);
220
254
  if (tr.selectionSet) {
221
255
  dispatch(tr);