@atlaskit/editor-plugin-table 7.8.1 → 7.10.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 (57) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/commands/column-resize.js +18 -6
  3. package/dist/cjs/commands/misc.js +5 -1
  4. package/dist/cjs/commands-with-analytics.js +2 -2
  5. package/dist/cjs/nodeviews/TableComponent.js +11 -3
  6. package/dist/cjs/toolbar.js +4 -3
  7. package/dist/cjs/utils/index.js +12 -0
  8. package/dist/cjs/utils/nodes.js +6 -1
  9. package/dist/cjs/utils/table.js +34 -1
  10. package/dist/es2019/commands/column-resize.js +18 -6
  11. package/dist/es2019/commands/misc.js +5 -1
  12. package/dist/es2019/commands-with-analytics.js +2 -2
  13. package/dist/es2019/nodeviews/TableComponent.js +12 -4
  14. package/dist/es2019/toolbar.js +4 -3
  15. package/dist/es2019/utils/index.js +2 -2
  16. package/dist/es2019/utils/nodes.js +5 -0
  17. package/dist/es2019/utils/table.js +36 -1
  18. package/dist/esm/commands/column-resize.js +18 -6
  19. package/dist/esm/commands/misc.js +5 -1
  20. package/dist/esm/commands-with-analytics.js +2 -2
  21. package/dist/esm/nodeviews/TableComponent.js +12 -4
  22. package/dist/esm/toolbar.js +4 -3
  23. package/dist/esm/utils/index.js +2 -2
  24. package/dist/esm/utils/nodes.js +5 -0
  25. package/dist/esm/utils/table.js +33 -0
  26. package/dist/types/commands/column-resize.d.ts +5 -4
  27. package/dist/types/commands/misc.d.ts +1 -1
  28. package/dist/types/commands-with-analytics.d.ts +2 -1
  29. package/dist/types/nodeviews/TableComponent.d.ts +6 -54
  30. package/dist/types/plugin.d.ts +1 -1
  31. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +18 -22
  32. package/dist/types/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +36 -44
  33. package/dist/types/ui/TableFloatingControls/index.d.ts +18 -22
  34. package/dist/types/utils/index.d.ts +2 -2
  35. package/dist/types/utils/nodes.d.ts +1 -0
  36. package/dist/types/utils/table.d.ts +3 -0
  37. package/dist/types-ts4.5/commands/column-resize.d.ts +5 -4
  38. package/dist/types-ts4.5/commands/misc.d.ts +1 -1
  39. package/dist/types-ts4.5/commands-with-analytics.d.ts +2 -1
  40. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +6 -54
  41. package/dist/types-ts4.5/plugin.d.ts +1 -1
  42. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +18 -22
  43. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +36 -44
  44. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +18 -22
  45. package/dist/types-ts4.5/utils/index.d.ts +2 -2
  46. package/dist/types-ts4.5/utils/nodes.d.ts +1 -0
  47. package/dist/types-ts4.5/utils/table.d.ts +3 -0
  48. package/package.json +4 -4
  49. package/src/commands/column-resize.ts +31 -8
  50. package/src/commands/misc.ts +9 -1
  51. package/src/commands-with-analytics.ts +7 -1
  52. package/src/nodeviews/TableComponent.tsx +21 -6
  53. package/src/plugin.tsx +1 -1
  54. package/src/toolbar.tsx +10 -1
  55. package/src/utils/index.ts +2 -1
  56. package/src/utils/nodes.ts +10 -0
  57. package/src/utils/table.ts +36 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.8.1",
3
+ "version": "7.10.0",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/adf-schema": "^35.10.0",
32
32
  "@atlaskit/custom-steps": "^0.1.0",
33
- "@atlaskit/editor-common": "^78.31.0",
33
+ "@atlaskit/editor-common": "^78.33.0",
34
34
  "@atlaskit/editor-palette": "1.5.3",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.1.0",
@@ -40,7 +40,7 @@
40
40
  "@atlaskit/editor-plugin-selection": "^1.2.0",
41
41
  "@atlaskit/editor-plugin-width": "^1.1.0",
42
42
  "@atlaskit/editor-prosemirror": "4.0.0",
43
- "@atlaskit/editor-shared-styles": "^2.9.0",
43
+ "@atlaskit/editor-shared-styles": "^2.10.0",
44
44
  "@atlaskit/editor-tables": "^2.7.0",
45
45
  "@atlaskit/icon": "^22.1.0",
46
46
  "@atlaskit/menu": "^2.1.5",
@@ -48,7 +48,7 @@
48
48
  "@atlaskit/pragmatic-drag-and-drop": "^1.1.0",
49
49
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.0.0",
50
50
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
51
- "@atlaskit/primitives": "^5.5.0",
51
+ "@atlaskit/primitives": "^5.6.0",
52
52
  "@atlaskit/theme": "^12.7.0",
53
53
  "@atlaskit/toggle": "^13.0.0",
54
54
  "@atlaskit/tokens": "^1.43.0",
@@ -6,6 +6,7 @@ import type {
6
6
  Command,
7
7
  GetEditorContainerWidth,
8
8
  } from '@atlaskit/editor-common/types';
9
+ import type { AriaLiveElementAttributes } from '@atlaskit/editor-plugin-accessibility-utils';
9
10
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
10
11
  import { TableMap } from '@atlaskit/editor-tables';
11
12
  import type { CellAttributes, Direction } from '@atlaskit/editor-tables/types';
@@ -129,7 +130,10 @@ export const initiateKeyboardColumnResizing =
129
130
  ariaNotify,
130
131
  getIntl,
131
132
  }: {
132
- ariaNotify?: (message: string) => void;
133
+ ariaNotify?: (
134
+ message: string,
135
+ ariaLiveElementAttributes?: AriaLiveElementAttributes,
136
+ ) => void;
133
137
  getIntl?: () => IntlShape;
134
138
  }): Command =>
135
139
  (state, dispatch, view) => {
@@ -144,7 +148,9 @@ export const initiateKeyboardColumnResizing =
144
148
  const cell = findCellClosestToPos(selection.$from);
145
149
 
146
150
  if (ariaNotify && getIntl) {
147
- ariaNotify(getIntl().formatMessage(messages.startedColumnResize));
151
+ ariaNotify(getIntl().formatMessage(messages.startedColumnResize), {
152
+ priority: 'important',
153
+ });
148
154
  }
149
155
 
150
156
  if (selectionRect && cell && view) {
@@ -164,7 +170,10 @@ export const activateNextResizeArea =
164
170
  getIntl,
165
171
  }: {
166
172
  direction: Direction;
167
- ariaNotify?: (message: string) => void;
173
+ ariaNotify?: (
174
+ message: string,
175
+ ariaLiveElementAttributes?: AriaLiveElementAttributes,
176
+ ) => void;
168
177
  getIntl?: () => IntlShape;
169
178
  }): Command =>
170
179
  (state, dispatch, view) => {
@@ -210,6 +219,7 @@ export const activateNextResizeArea =
210
219
  getIntl().formatMessage(messages.focusedOtherResize, {
211
220
  direction: 'right',
212
221
  }),
222
+ { priority: 'important' },
213
223
  );
214
224
  }
215
225
 
@@ -218,6 +228,7 @@ export const activateNextResizeArea =
218
228
  getIntl().formatMessage(messages.focusedOtherResize, {
219
229
  direction: 'left',
220
230
  }),
231
+ { priority: 'important' },
221
232
  );
222
233
  }
223
234
  }
@@ -275,7 +286,10 @@ export const changeColumnWidthByStep =
275
286
  stepSize: number;
276
287
  getEditorContainerWidth: GetEditorContainerWidth;
277
288
  isTableScalingEnabled: boolean;
278
- ariaNotify?: (message: string) => void;
289
+ ariaNotify?: (
290
+ message: string,
291
+ ariaLiveElementAttributes?: AriaLiveElementAttributes,
292
+ ) => void;
279
293
  getIntl?: () => IntlShape;
280
294
  originalTr?: Transaction;
281
295
  }): Command =>
@@ -381,10 +395,14 @@ export const changeColumnWidthByStep =
381
395
 
382
396
  if (newResizeState.cols.length === colIndex + 1) {
383
397
  if (newResizeState.overflow === true) {
384
- ariaNotify(getIntl().formatMessage(messages.columnResizeLast));
398
+ ariaNotify(getIntl().formatMessage(messages.columnResizeLast), {
399
+ priority: 'important',
400
+ });
385
401
  }
386
402
  if (newResizeState.overflow === false) {
387
- ariaNotify(getIntl().formatMessage(messages.columnResizeOverflow));
403
+ ariaNotify(getIntl().formatMessage(messages.columnResizeOverflow), {
404
+ priority: 'important',
405
+ });
388
406
  }
389
407
  }
390
408
  }
@@ -398,7 +416,10 @@ export const stopKeyboardColumnResizing =
398
416
  getIntl,
399
417
  originalTr,
400
418
  }: {
401
- ariaNotify?: (message: string) => void;
419
+ ariaNotify?: (
420
+ message: string,
421
+ ariaLiveElementAttributes?: AriaLiveElementAttributes,
422
+ ) => void;
402
423
  getIntl?: () => IntlShape;
403
424
  originalTr?: Transaction;
404
425
  }): Command =>
@@ -439,7 +460,9 @@ export const stopKeyboardColumnResizing =
439
460
  () => customTr.setMeta('scrollIntoView', false),
440
461
  )(state, fakeDispatch);
441
462
  if (ariaNotify && getIntl) {
442
- ariaNotify(getIntl().formatMessage(messages.columnResizeStop));
463
+ ariaNotify(getIntl().formatMessage(messages.columnResizeStop), {
464
+ priority: 'important',
465
+ });
443
466
  }
444
467
 
445
468
  if (dispatch) {
@@ -435,7 +435,11 @@ export const moveCursorBackward: Command = (state, dispatch) => {
435
435
  };
436
436
 
437
437
  export const setMultipleCellAttrs =
438
- (attrs: Object, targetCellPosition?: number): Command =>
438
+ (
439
+ attrs: Object,
440
+ targetCellPosition?: number,
441
+ editorView?: EditorView | null,
442
+ ): Command =>
439
443
  (state, dispatch) => {
440
444
  let cursorPos: number | undefined;
441
445
  let { tr } = state;
@@ -457,6 +461,10 @@ export const setMultipleCellAttrs =
457
461
 
458
462
  if (tr.docChanged && cursorPos !== undefined) {
459
463
  if (dispatch) {
464
+ if (cursorPos !== undefined) {
465
+ editorView?.focus();
466
+ tr.setSelection(new TextSelection(tr.doc.resolve(cursorPos)));
467
+ }
460
468
  dispatch(tr);
461
469
  }
462
470
  return true;
@@ -17,6 +17,7 @@ import type {
17
17
  Command,
18
18
  GetEditorContainerWidth,
19
19
  } from '@atlaskit/editor-common/types';
20
+ import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
20
21
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
21
22
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
22
23
  import type { Rect } from '@atlaskit/editor-tables/table-map';
@@ -173,6 +174,7 @@ export const setColorWithAnalytics =
173
174
  | INPUT_METHOD.TABLE_CONTEXT_MENU,
174
175
  cellColor: string,
175
176
  targetCellPosition?: number,
177
+ editorView?: EditorView | null,
176
178
  ) =>
177
179
  withEditorAnalyticsAPI(({ selection }) => {
178
180
  const {
@@ -202,7 +204,11 @@ export const setColorWithAnalytics =
202
204
  eventType: EVENT_TYPE.TRACK,
203
205
  };
204
206
  })(editorAnalyticsAPI)(
205
- setMultipleCellAttrs({ background: cellColor }, targetCellPosition),
207
+ setMultipleCellAttrs(
208
+ { background: cellColor },
209
+ targetCellPosition,
210
+ editorView,
211
+ ),
206
212
  );
207
213
 
208
214
  export const addRowAroundSelection =
@@ -4,6 +4,8 @@ import React from 'react';
4
4
  import classnames from 'classnames';
5
5
  import memoizeOne from 'memoize-one';
6
6
  import rafSchedule from 'raf-schd';
7
+ import type { IntlShape } from 'react-intl-next';
8
+ import { injectIntl } from 'react-intl-next';
7
9
 
8
10
  import type { TableColumnOrdering } from '@atlaskit/custom-steps';
9
11
  import {
@@ -61,9 +63,11 @@ import TableFloatingColumnControls from '../ui/TableFloatingColumnControls';
61
63
  import TableFloatingControls from '../ui/TableFloatingControls';
62
64
  import {
63
65
  containsHeaderRow,
66
+ getAssistiveMessage,
64
67
  isTableNested,
65
68
  tablesHaveDifferentColumnWidths,
66
69
  tablesHaveDifferentNoOfColumns,
70
+ tablesHaveDifferentNoOfRows,
67
71
  } from '../utils';
68
72
 
69
73
  import { ExternalDropTargets } from './ExternalDropTargets';
@@ -106,6 +110,7 @@ export interface ComponentProps {
106
110
  getEditorFeatureFlags: GetEditorFeatureFlags;
107
111
  dispatchAnalyticsEvent: DispatchAnalyticsEvent;
108
112
  pluginInjectionApi?: PluginInjectionAPI;
113
+ intl: IntlShape;
109
114
 
110
115
  // marking props as option to ensure backward compatibility when platform.editor.table.use-shared-state-hook disabled
111
116
  isInDanger?: boolean;
@@ -442,6 +447,21 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
442
447
  }
443
448
 
444
449
  const currentTable = getNode();
450
+ const previousTable = this.node;
451
+ const isNoOfColumnsChanged = tablesHaveDifferentNoOfColumns(
452
+ currentTable,
453
+ previousTable,
454
+ );
455
+ const isNoOfRowsChanged = tablesHaveDifferentNoOfRows(
456
+ currentTable,
457
+ previousTable,
458
+ );
459
+ if (isNoOfColumnsChanged || isNoOfRowsChanged) {
460
+ this.props.pluginInjectionApi?.accessibilityUtils?.actions.ariaNotify(
461
+ getAssistiveMessage(previousTable, currentTable, this.props.intl),
462
+ { priority: 'important' },
463
+ );
464
+ }
445
465
  if (currentTable.attrs.__autoSize) {
446
466
  // Wait for next tick to handle auto sizing, gives the browser time to do layout calc etc.
447
467
  this.handleAutoSizeDebounced();
@@ -451,11 +471,6 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
451
471
  else if (allowColumnResizing && this.table && !isMediaFullscreen) {
452
472
  // If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
453
473
  // re-draw colgroup.
454
- const previousTable = this.node;
455
- const isNoOfColumnsChanged = tablesHaveDifferentNoOfColumns(
456
- currentTable,
457
- previousTable,
458
- );
459
474
  if (
460
475
  tablesHaveDifferentColumnWidths(currentTable, previousTable) ||
461
476
  isNoOfColumnsChanged
@@ -1044,4 +1059,4 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
1044
1059
  private handleWindowResizeDebounced = rafSchedule(this.handleWindowResize);
1045
1060
  }
1046
1061
 
1047
- export default TableComponent;
1062
+ export default injectIntl(TableComponent);
package/src/plugin.tsx CHANGED
@@ -131,12 +131,12 @@ export type TablePlugin = NextEditorPlugin<
131
131
  ) => EditorCommand;
132
132
  };
133
133
  dependencies: [
134
- OptionalPlugin<AccessibilityUtilsPlugin>,
135
134
  AnalyticsPlugin,
136
135
  ContentInsertionPlugin,
137
136
  WidthPlugin,
138
137
  GuidelinePlugin,
139
138
  SelectionPlugin,
139
+ OptionalPlugin<AccessibilityUtilsPlugin>,
140
140
  OptionalPlugin<MediaPlugin>,
141
141
  OptionalPlugin<EditorViewModePlugin>,
142
142
  ];
package/src/toolbar.tsx CHANGED
@@ -557,7 +557,13 @@ export const getToolbarConfig =
557
557
  isTableScalingEnabled,
558
558
  )
559
559
  : [];
560
- const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
560
+ const colorPicker = getColorPicker(
561
+ state,
562
+ menu,
563
+ intl,
564
+ editorAnalyticsAPI,
565
+ getEditorView,
566
+ );
561
567
 
562
568
  // Check if we need to show confirm dialog for delete button
563
569
  let confirmDialog;
@@ -812,6 +818,7 @@ const getColorPicker = (
812
818
  menu: FloatingToolbarItem<Command>,
813
819
  { formatMessage }: ToolbarMenuContext,
814
820
  editorAnalyticsAPI: EditorAnalyticsAPI | null | undefined,
821
+ getEditorView: () => EditorView | null,
815
822
  ): Array<FloatingToolbarItem<Command>> => {
816
823
  const { targetCellPosition, pluginConfig } = getPluginState(state);
817
824
  if (!pluginConfig.allowBackgroundColor) {
@@ -838,11 +845,13 @@ const getColorPicker = (
838
845
  selectType: 'color',
839
846
  defaultValue: defaultPalette,
840
847
  options: cellBackgroundColorPalette,
848
+ returnEscToButton: true,
841
849
  onChange: (option: any) =>
842
850
  setColorWithAnalytics(editorAnalyticsAPI)(
843
851
  INPUT_METHOD.FLOATING_TB,
844
852
  option.value,
845
853
  targetCellPosition,
854
+ getEditorView(),
846
855
  ),
847
856
  },
848
857
  separator(menu.hidden),
@@ -26,6 +26,7 @@ export {
26
26
  getTableWidth,
27
27
  tablesHaveDifferentColumnWidths,
28
28
  tablesHaveDifferentNoOfColumns,
29
+ tablesHaveDifferentNoOfRows,
29
30
  isTableNested,
30
31
  anyChildCellMergedAcrossRow,
31
32
  supportedHeaderRow,
@@ -75,7 +76,7 @@ export {
75
76
  } from './row-controls';
76
77
  export type { RowParams } from './row-controls';
77
78
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
78
- export { getMergedCellsPositions } from './table';
79
+ export { getMergedCellsPositions, getAssistiveMessage } from './table';
79
80
  export { updatePluginStateDecorations } from './update-plugin-state-decorations';
80
81
  export {
81
82
  hasMergedCellsInColumn,
@@ -94,6 +94,16 @@ export const tablesHaveDifferentNoOfColumns = (
94
94
  return prevMap.width !== currentMap.width;
95
95
  };
96
96
 
97
+ export const tablesHaveDifferentNoOfRows = (
98
+ currentTable: PmNode,
99
+ previousTable: PmNode,
100
+ ): boolean => {
101
+ const prevMap = TableMap.get(previousTable);
102
+ const currentMap = TableMap.get(currentTable);
103
+
104
+ return prevMap.height !== currentMap.height;
105
+ };
106
+
97
107
  function filterNearSelection<T, U>(
98
108
  selection: Selection,
99
109
  findNode: (selection: Selection) => { pos: number; node: PmNode } | undefined,
@@ -1,3 +1,7 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+
3
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
1
5
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
6
  import type { Rect } from '@atlaskit/editor-tables/table-map';
3
7
  import { TableMap } from '@atlaskit/editor-tables/table-map';
@@ -30,3 +34,35 @@ export const colsToRect = (cols: Array<number>, noOfRows: number): Rect => ({
30
34
  top: 0,
31
35
  bottom: noOfRows,
32
36
  });
37
+
38
+ export const getAssistiveMessage = (
39
+ prevTableNode: PmNode,
40
+ currentTableNode: PmNode,
41
+ intl: IntlShape,
42
+ ) => {
43
+ const { formatMessage } = intl;
44
+ const prevTableMap = TableMap.get(prevTableNode);
45
+ const currentTableMap = TableMap.get(currentTableNode);
46
+
47
+ if (currentTableMap.width !== prevTableMap.width) {
48
+ const diff = Math.abs(currentTableMap.width - prevTableMap.width);
49
+ if (currentTableMap.width > prevTableMap.width) {
50
+ return formatMessage(messages.columnsAreInserted, { count: diff });
51
+ }
52
+ if (currentTableMap.width < prevTableMap.width) {
53
+ return formatMessage(messages.columnsAreRemoved, { count: diff });
54
+ }
55
+ }
56
+
57
+ if (currentTableMap.height !== prevTableMap.height) {
58
+ const diff = Math.abs(currentTableMap.height - prevTableMap.height);
59
+ if (currentTableMap.height > prevTableMap.height) {
60
+ return formatMessage(messages.rowsAreInserted, { count: diff });
61
+ }
62
+ if (currentTableMap.height < prevTableMap.height) {
63
+ return formatMessage(messages.rowsAreRemoved, { count: diff });
64
+ }
65
+ }
66
+
67
+ return '';
68
+ };