@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
@@ -13,12 +13,9 @@ import {
13
13
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
14
 
15
15
  import { insertRowWithAnalytics } from '../commands-with-analytics';
16
- import {
17
- getPluginState as getResizePluginState,
18
- createCommand as tableResizingPluginCreateCommand,
19
- } from '../pm-plugins/table-resizing/plugin-factory';
16
+ import { getPluginState } from '../pm-plugins/plugin-factory';
20
17
 
21
- import { hideResizeHandleLine } from './hover';
18
+ import { stopKeyboardColumnResizing } from './column-resize';
22
19
 
23
20
  const TAB_FORWARD_DIRECTION = 1;
24
21
  const TAB_BACKWARD_DIRECTION = -1;
@@ -26,23 +23,17 @@ const TAB_BACKWARD_DIRECTION = -1;
26
23
  export const goToNextCell =
27
24
  (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
28
25
  (direction: Direction): Command =>
29
- (state, dispatch) => {
26
+ (state, dispatch, view) => {
30
27
  const table = findTable(state.selection);
31
28
  if (!table) {
32
29
  return false;
33
30
  }
34
31
 
35
32
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
36
- const isColumnResizing = !!getResizePluginState(state)?.dragging;
33
+ const isColumnResizing = getPluginState(state)?.isKeyboardResize;
37
34
  if (isColumnResizing) {
38
- tableResizingPluginCreateCommand(
39
- {
40
- type: 'STOP_RESIZING',
41
- },
42
- (originalTr) =>
43
- (state.tr || originalTr).setMeta('scrollIntoView', false),
44
- )(state, dispatch);
45
- hideResizeHandleLine()(state, dispatch);
35
+ stopKeyboardColumnResizing()(state, dispatch, view);
36
+ return true;
46
37
  }
47
38
  }
48
39
 
@@ -616,6 +616,7 @@ export const addResizeHandleDecorations = (
616
616
  rowIndex: number,
617
617
  columnIndex: number,
618
618
  includeTooltip: boolean,
619
+ isKeyboardResize?: boolean,
619
620
  ) =>
620
621
  createCommand(
621
622
  (state) => {
@@ -644,6 +645,7 @@ export const addResizeHandleDecorations = (
644
645
  resizeHandleRowIndex: rowIndex,
645
646
  resizeHandleColumnIndex: columnIndex,
646
647
  resizeHandleIncludeTooltip: includeTooltip,
648
+ isKeyboardResize: isKeyboardResize || false,
647
649
  },
648
650
  };
649
651
  },
@@ -28,7 +28,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
28
28
 
29
29
  import { selectColumn, selectRow } from '../commands/misc';
30
30
  import type tablePlugin from '../plugin';
31
- import { getPluginState as getResizePluginState } from '../pm-plugins/table-resizing/plugin-factory';
31
+ import { getPluginState } from '../pm-plugins/plugin-factory';
32
32
  import { getClosestSelectionRect } from '../toolbar';
33
33
 
34
34
  export enum TableSelectionDirection {
@@ -294,8 +294,8 @@ const arrowLeftFromText =
294
294
  let isColumnResizing = false;
295
295
 
296
296
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
297
- const columResizePluginState = getResizePluginState(state) || {};
298
- isColumnResizing = Boolean(columResizePluginState?.dragging);
297
+ const columResizePluginState = getPluginState(state) || {};
298
+ isColumnResizing = Boolean(columResizePluginState?.isKeyboardResize);
299
299
  }
300
300
 
301
301
  if (
@@ -343,8 +343,8 @@ const arrowRightFromText =
343
343
  let isColumnResizing = false;
344
344
 
345
345
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
346
- const columResizePluginState = getResizePluginState(state) || {};
347
- isColumnResizing = Boolean(columResizePluginState?.dragging);
346
+ const columResizePluginState = getPluginState(state) || {};
347
+ isColumnResizing = Boolean(columResizePluginState?.isKeyboardResize);
348
348
  }
349
349
  if (
350
350
  isSelectionAtEndOfTable($to, selection) &&
@@ -27,6 +27,7 @@ import {
27
27
  getSelectionRect,
28
28
  removeTable,
29
29
  } from '@atlaskit/editor-tables/utils';
30
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
30
31
 
31
32
  import {
32
33
  addResizeHandleDecorations,
@@ -295,7 +296,16 @@ export const handleMouseOut = (
295
296
  !isResizeHandleDecoration(relatedTarget)
296
297
  ) {
297
298
  const { state, dispatch } = view;
298
- return hideResizeHandleLine()(state, dispatch);
299
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
300
+ const { isKeyboardResize } = getPluginState(state);
301
+ if (isKeyboardResize) {
302
+ // no need to hide decoration if column resizing started by keyboard
303
+ return false;
304
+ }
305
+ return hideResizeHandleLine()(state, dispatch);
306
+ } else {
307
+ return hideResizeHandleLine()(state, dispatch);
308
+ }
299
309
  }
300
310
 
301
311
  return false;
@@ -421,6 +431,12 @@ export const handleMouseMove = (
421
431
  const { state, dispatch } = view;
422
432
  const { resizeHandleColumnIndex, resizeHandleRowIndex } =
423
433
  getPluginState(state);
434
+
435
+ const isKeyboardResize = getBooleanFF(
436
+ 'platform.editor.a11y-column-resizing_emcvz',
437
+ )
438
+ ? getPluginState(state).isKeyboardResize
439
+ : false;
424
440
  const tableCell = closestElement(
425
441
  element,
426
442
  'td, th',
@@ -437,9 +453,10 @@ export const handleMouseMove = (
437
453
  const rowIndexTarget = rect.top;
438
454
 
439
455
  if (
440
- columnEndIndexTarget !== resizeHandleColumnIndex ||
441
- rowIndexTarget !== resizeHandleRowIndex ||
442
- !hasResizeHandler({ target: element, columnEndIndexTarget })
456
+ (columnEndIndexTarget !== resizeHandleColumnIndex ||
457
+ rowIndexTarget !== resizeHandleRowIndex ||
458
+ !hasResizeHandler({ target: element, columnEndIndexTarget })) &&
459
+ !isKeyboardResize // if initiated by keyboard don't need to react on hover for other resize sliders
443
460
  ) {
444
461
  return addResizeHandleDecorations(
445
462
  rowIndexTarget,
@@ -16,6 +16,7 @@ import {
16
16
  decreaseMediaSize,
17
17
  deleteColumn,
18
18
  deleteRow,
19
+ escape,
19
20
  increaseMediaSize,
20
21
  moveColumnLeft,
21
22
  moveColumnRight,
@@ -45,6 +46,7 @@ import {
45
46
  activateNextResizeArea,
46
47
  changeColumnWidthByStep,
47
48
  initiateKeyboardColumnResizing,
49
+ stopKeyboardColumnResizing,
48
50
  } from '../commands/column-resize';
49
51
  import {
50
52
  addColumnAfter as addColumnAfterCommand,
@@ -190,6 +192,7 @@ export function keymapPlugin(
190
192
  changeColumnWidthByStep(10, getEditorContainerWidth),
191
193
  list,
192
194
  );
195
+ bindKeymapWithCommand(escape.common!, stopKeyboardColumnResizing(), list);
193
196
  }
194
197
 
195
198
  return keymap(list) as SafePlugin;
@@ -38,12 +38,16 @@ import {
38
38
  findParentNodeOfType,
39
39
  } from '@atlaskit/editor-prosemirror/utils';
40
40
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
41
+ import { TableMap } from '@atlaskit/editor-tables';
42
+ import { findTable } from '@atlaskit/editor-tables/utils';
43
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
41
44
 
42
45
  import {
43
46
  addBoldInEmptyHeaderCells,
44
47
  clearHoverSelection,
45
48
  setTableRef,
46
49
  } from '../commands';
50
+ import { stopKeyboardColumnResizing } from '../commands/column-resize';
47
51
  import {
48
52
  removeResizeHandleDecorations,
49
53
  transformSliceRemoveCellBackgroundColor,
@@ -202,7 +206,7 @@ export const createPlugin = (
202
206
  editorViewRef = editorView;
203
207
 
204
208
  return {
205
- update: (view: EditorView) => {
209
+ update: (view: EditorView, prevState: EditorState) => {
206
210
  const { state, dispatch } = view;
207
211
  const { selection } = state;
208
212
  const pluginState = getPluginState(state);
@@ -218,6 +222,39 @@ export const createPlugin = (
218
222
  'table',
219
223
  ) || undefined;
220
224
  }
225
+ const tableNode = findTable(state.selection);
226
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
227
+ // when cursor leaves the table we need to stop column resizing
228
+ const pluginPrevState = getPluginState(prevState);
229
+ const isStopKeyboardColumResizing =
230
+ pluginPrevState.isResizeHandleWidgetAdded &&
231
+ pluginPrevState.isKeyboardResize;
232
+ if (isStopKeyboardColumResizing) {
233
+ const isTableNodesDifferent =
234
+ pluginPrevState?.tableNode !== tableNode?.node;
235
+ if (
236
+ pluginPrevState?.tableNode &&
237
+ tableNode &&
238
+ isTableNodesDifferent
239
+ ) {
240
+ const oldRowsNumber = TableMap.get(
241
+ pluginPrevState.tableNode,
242
+ ).height;
243
+ const newRowsNumber = TableMap.get(tableNode.node).height;
244
+ if (
245
+ oldRowsNumber !== newRowsNumber || // Add/delete row
246
+ tableNode.node.attrs.localId !==
247
+ pluginPrevState.tableNode.attrs.localId
248
+ ) {
249
+ // Jump to another table
250
+ stopKeyboardColumnResizing()(state, dispatch);
251
+ }
252
+ } else if (!tableNode) {
253
+ // selection outside of table
254
+ stopKeyboardColumnResizing()(state, dispatch);
255
+ }
256
+ }
257
+ }
221
258
  }
222
259
 
223
260
  if (pluginState.tableRef !== tableRef) {
@@ -333,7 +370,15 @@ export const createPlugin = (
333
370
  const maybeTr = closestElement(domRef as HTMLElement | undefined, 'tr');
334
371
  return maybeTr ? maybeTr.classList.contains('sticky') : false;
335
372
  },
336
- handleTextInput: ({ state, dispatch }, _from, _to, text) => {
373
+ handleTextInput: (view, _from, _to, text) => {
374
+ const { state, dispatch } = view;
375
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
376
+ const { isKeyboardResize } = getPluginState(state);
377
+ if (isKeyboardResize) {
378
+ stopKeyboardColumnResizing()(state, dispatch);
379
+ return false;
380
+ }
381
+ }
337
382
  const tr = replaceSelectedTable(
338
383
  state,
339
384
  text,
@@ -18,9 +18,11 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
18
18
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
19
19
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
20
20
 
21
+ import { stopKeyboardColumnResizing } from '../../commands/column-resize';
21
22
  import { updateResizeHandleDecorations } from '../../commands/misc';
22
23
  import { updateColumnWidths } from '../../transforms';
23
24
  import { getSelectedColumnIndexes } from '../../utils';
25
+ import { getPluginState as getTablePluginState } from '../plugin-factory';
24
26
  import { META_KEYS } from '../table-analytics';
25
27
 
26
28
  import { evenColumns, setDragging, stopResizing } from './commands';
@@ -54,6 +56,7 @@ export const handleMouseDown = (
54
56
  ) {
55
57
  return false;
56
58
  }
59
+ const { isKeyboardResize } = getTablePluginState(state);
57
60
  event.preventDefault();
58
61
 
59
62
  const tr = view.state.tr;
@@ -147,6 +150,7 @@ export const handleMouseDown = (
147
150
  const { clientX } = event;
148
151
  const { state, dispatch } = view;
149
152
  const { dragging, resizeHandlePos } = getPluginState(state);
153
+ const { isTableHovered } = getTablePluginState(state);
150
154
  if (resizeHandlePos === null) {
151
155
  return stopResizing()(state, dispatch);
152
156
  }
@@ -160,9 +164,20 @@ export const handleMouseDown = (
160
164
  const start = $cell.start(-1);
161
165
  const table = $cell.node(-1);
162
166
 
163
- // If we let go in the same place we started, dont need to do anything.
167
+ // If we let go in the same place we started, don't need to do anything.
164
168
  if (dragging && clientX === dragging.startX) {
165
- return stopResizing()(state, dispatch);
169
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
170
+ if (isKeyboardResize || !isTableHovered) {
171
+ /** if column resize had started via keyboard but continued by mouse
172
+ * or mouse pointer leaves the table but mouse button still pressed
173
+ */
174
+ return stopKeyboardColumnResizing()(state, dispatch, view);
175
+ } else {
176
+ return stopResizing()(state, dispatch);
177
+ }
178
+ } else {
179
+ return stopResizing()(state, dispatch);
180
+ }
166
181
  }
167
182
 
168
183
  let { tr } = state;
@@ -211,8 +226,18 @@ export const handleMouseDown = (
211
226
  })(tr);
212
227
  }
213
228
  }
214
-
215
- return stopResizing(tr)(state, dispatch);
229
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
230
+ if (isKeyboardResize || !isTableHovered) {
231
+ /** if column resize had started via keyboard but continued by mouse
232
+ * or mouse pointer leaves the table but mouse button still pressed
233
+ */
234
+ return stopKeyboardColumnResizing(tr)(state, dispatch, view);
235
+ } else {
236
+ return stopResizing(tr)(state, dispatch);
237
+ }
238
+ } else {
239
+ return stopResizing(tr)(state, dispatch);
240
+ }
216
241
  }
217
242
  }
218
243
 
@@ -220,11 +245,14 @@ export const handleMouseDown = (
220
245
  const { clientX, which } = event;
221
246
  const { state } = view;
222
247
  const { dragging, resizeHandlePos } = getPluginState(state);
248
+ const { isTableHovered } = getTablePluginState(state);
223
249
  if (
224
250
  !which ||
225
251
  !dragging ||
226
252
  resizeHandlePos === null ||
227
- !pointsAtCell(state.doc.resolve(resizeHandlePos))
253
+ !pointsAtCell(state.doc.resolve(resizeHandlePos)) ||
254
+ (!isTableHovered &&
255
+ getBooleanFF('platform.editor.a11y-column-resizing_emcvz'))
228
256
  ) {
229
257
  return finish(event);
230
258
  }
@@ -7,9 +7,11 @@ import type {
7
7
  GetEditorContainerWidth,
8
8
  GetEditorFeatureFlags,
9
9
  } from '@atlaskit/editor-common/types';
10
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
10
11
 
11
12
  import { TableCssClassName as ClassName } from '../../types';
12
13
  import type { ColumnResizingPluginState } from '../../types';
14
+ import { getPluginState as getTablePluginState } from '../plugin-factory';
13
15
 
14
16
  import { setResizeHandlePos } from './commands';
15
17
  import { handleMouseDown } from './event-handlers';
@@ -54,7 +56,22 @@ export function createPlugin(
54
56
  getResizeCellPos(view, event as MouseEvent);
55
57
 
56
58
  const { dragging } = getPluginState(state);
57
- if (resizeHandlePos !== null && !dragging) {
59
+ let isColumnKeyboardResizeStarted = false;
60
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
61
+ /*
62
+ We need to start listening mouse events if column resize started from keyboard.
63
+ This will allow continue resizing via mouse
64
+ */
65
+ const { isKeyboardResize } = getTablePluginState(state);
66
+ if (isKeyboardResize) {
67
+ isColumnKeyboardResizeStarted = isKeyboardResize;
68
+ }
69
+ }
70
+
71
+ if (
72
+ resizeHandlePos !== null &&
73
+ (!dragging || isColumnKeyboardResizeStarted)
74
+ ) {
58
75
  if (
59
76
  handleMouseDown(
60
77
  view,
package/src/reducer.ts CHANGED
@@ -82,14 +82,15 @@ export default (
82
82
  resizeHandleColumnIndex: undefined,
83
83
  resizeHandleRowIndex: undefined,
84
84
  };
85
-
85
+ case 'START_KEYBOARD_COLUMN_RESIZE':
86
86
  case 'ADD_RESIZE_HANDLE_DECORATIONS':
87
87
  if (
88
88
  action.data.resizeHandleColumnIndex ===
89
89
  pluginState.resizeHandleColumnIndex &&
90
90
  action.data.resizeHandleRowIndex === pluginState.resizeHandleRowIndex &&
91
91
  action.data.resizeHandleIncludeTooltip ===
92
- pluginState.resizeHandleIncludeTooltip
92
+ pluginState.resizeHandleIncludeTooltip &&
93
+ action.data.isKeyboardResize === pluginState.isKeyboardResize
93
94
  ) {
94
95
  return pluginState;
95
96
  }
@@ -128,6 +129,7 @@ export default (
128
129
  resizeHandleIncludeTooltip ?? pluginState.resizeHandleIncludeTooltip,
129
130
  };
130
131
 
132
+ case 'STOP_KEYBOARD_COLUMN_RESIZE':
131
133
  case 'REMOVE_RESIZE_HANDLE_DECORATIONS':
132
134
  if (!pluginState.isResizeHandleWidgetAdded) {
133
135
  return pluginState;
@@ -139,6 +141,7 @@ export default (
139
141
  resizeHandleColumnIndex: undefined,
140
142
  resizeHandleRowIndex: undefined,
141
143
  isResizeHandleWidgetAdded: false,
144
+ isKeyboardResize: undefined,
142
145
  };
143
146
 
144
147
  case 'SET_TABLE_REF':
package/src/types.ts CHANGED
@@ -119,6 +119,7 @@ export interface TablePluginState {
119
119
  resizeHandleRowIndex?: number;
120
120
  resizeHandleColumnIndex?: number;
121
121
  resizeHandleIncludeTooltip?: boolean;
122
+ isKeyboardResize?: boolean;
122
123
  // for table wrap/collapse
123
124
  isTableCollapsed?: boolean; // is the current table already in an expand?
124
125
  canCollapseTable?: boolean; // enabled/disabled state of collapse option
@@ -179,6 +180,16 @@ export type TablePluginAction =
179
180
  isInDanger?: boolean;
180
181
  };
181
182
  }
183
+ | {
184
+ type: 'START_KEYBOARD_COLUMN_RESIZE';
185
+ data: {
186
+ decorationSet: DecorationSet;
187
+ resizeHandleRowIndex: number;
188
+ resizeHandleColumnIndex: number;
189
+ resizeHandleIncludeTooltip: boolean;
190
+ isKeyboardResize?: boolean;
191
+ };
192
+ }
182
193
  | {
183
194
  type: 'ADD_RESIZE_HANDLE_DECORATIONS';
184
195
  data: {
@@ -186,6 +197,7 @@ export type TablePluginAction =
186
197
  resizeHandleRowIndex: number;
187
198
  resizeHandleColumnIndex: number;
188
199
  resizeHandleIncludeTooltip: boolean;
200
+ isKeyboardResize?: boolean;
189
201
  };
190
202
  }
191
203
  | {
@@ -201,6 +213,10 @@ export type TablePluginAction =
201
213
  type: 'REMOVE_RESIZE_HANDLE_DECORATIONS';
202
214
  data: { decorationSet: DecorationSet };
203
215
  }
216
+ | {
217
+ type: 'STOP_KEYBOARD_COLUMN_RESIZE';
218
+ data: { decorationSet: DecorationSet };
219
+ }
204
220
  | { type: 'CLEAR_HOVER_SELECTION'; data: { decorationSet: DecorationSet } }
205
221
  | { type: 'SHOW_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
206
222
  | { type: 'HIDE_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }