@atlaskit/editor-plugin-table 5.7.9 → 5.8.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 (105) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/dist/cjs/commands/column-resize.js +155 -0
  4. package/dist/cjs/commands/go-to-next-cell.js +15 -0
  5. package/dist/cjs/commands/selection.js +16 -3
  6. package/dist/cjs/nodeviews/ExternalDropTargets.js +2 -1
  7. package/dist/cjs/plugin.js +2 -1
  8. package/dist/cjs/pm-plugins/drag-and-drop/commands.js +3 -3
  9. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +2 -1
  10. package/dist/cjs/pm-plugins/keymap.js +9 -0
  11. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +18 -7
  12. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +6 -0
  13. package/dist/cjs/types.js +8 -1
  14. package/dist/cjs/ui/DragHandle/index.js +1 -1
  15. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +187 -17
  16. package/dist/cjs/ui/FloatingDragMenu/index.js +4 -2
  17. package/dist/cjs/ui/FloatingDragMenu/styles.js +19 -0
  18. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -2
  19. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +2 -2
  20. package/dist/cjs/ui/consts.js +2 -1
  21. package/dist/cjs/ui/ui-styles.js +6 -2
  22. package/dist/cjs/utils/decoration.js +14 -4
  23. package/dist/es2019/commands/column-resize.js +149 -0
  24. package/dist/es2019/commands/go-to-next-cell.js +13 -0
  25. package/dist/es2019/commands/selection.js +16 -3
  26. package/dist/es2019/nodeviews/ExternalDropTargets.js +2 -1
  27. package/dist/es2019/plugin.js +2 -1
  28. package/dist/es2019/pm-plugins/drag-and-drop/commands.js +3 -3
  29. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +2 -1
  30. package/dist/es2019/pm-plugins/keymap.js +10 -1
  31. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +19 -8
  32. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
  33. package/dist/es2019/types.js +8 -1
  34. package/dist/es2019/ui/DragHandle/index.js +1 -1
  35. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +177 -7
  36. package/dist/es2019/ui/FloatingDragMenu/index.js +4 -2
  37. package/dist/es2019/ui/FloatingDragMenu/styles.js +62 -0
  38. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -2
  39. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +2 -2
  40. package/dist/es2019/ui/consts.js +2 -1
  41. package/dist/es2019/ui/ui-styles.js +108 -65
  42. package/dist/es2019/utils/decoration.js +14 -4
  43. package/dist/esm/commands/column-resize.js +149 -0
  44. package/dist/esm/commands/go-to-next-cell.js +15 -0
  45. package/dist/esm/commands/selection.js +16 -3
  46. package/dist/esm/nodeviews/ExternalDropTargets.js +2 -1
  47. package/dist/esm/plugin.js +2 -1
  48. package/dist/esm/pm-plugins/drag-and-drop/commands.js +3 -3
  49. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +2 -1
  50. package/dist/esm/pm-plugins/keymap.js +10 -1
  51. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +19 -8
  52. package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
  53. package/dist/esm/types.js +8 -1
  54. package/dist/esm/ui/DragHandle/index.js +1 -1
  55. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +177 -7
  56. package/dist/esm/ui/FloatingDragMenu/index.js +4 -2
  57. package/dist/esm/ui/FloatingDragMenu/styles.js +12 -0
  58. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -2
  59. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +2 -2
  60. package/dist/esm/ui/consts.js +2 -1
  61. package/dist/esm/ui/ui-styles.js +7 -3
  62. package/dist/esm/utils/decoration.js +14 -4
  63. package/dist/types/commands/column-resize.d.ts +5 -0
  64. package/dist/types/pm-plugins/drag-and-drop/commands.d.ts +1 -1
  65. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  66. package/dist/types/types.d.ts +7 -0
  67. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +1 -2
  68. package/dist/types/ui/FloatingDragMenu/index.d.ts +3 -2
  69. package/dist/types/ui/FloatingDragMenu/styles.d.ts +3 -0
  70. package/dist/types/ui/consts.d.ts +1 -1
  71. package/dist/types/utils/decoration.d.ts +2 -2
  72. package/dist/types-ts4.5/commands/column-resize.d.ts +5 -0
  73. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands.d.ts +1 -1
  74. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  75. package/dist/types-ts4.5/types.d.ts +7 -0
  76. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +1 -2
  77. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +3 -2
  78. package/dist/types-ts4.5/ui/FloatingDragMenu/styles.d.ts +3 -0
  79. package/dist/types-ts4.5/ui/consts.d.ts +1 -1
  80. package/dist/types-ts4.5/utils/decoration.d.ts +2 -2
  81. package/package.json +8 -4
  82. package/src/__tests__/unit/analytics.ts +5 -1
  83. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +295 -0
  84. package/src/__tests__/unit/ui/RowDragControls.tsx +5 -4
  85. package/src/commands/column-resize.ts +257 -0
  86. package/src/commands/go-to-next-cell.ts +21 -0
  87. package/src/commands/selection.ts +19 -2
  88. package/src/nodeviews/ExternalDropTargets.tsx +1 -0
  89. package/src/plugin.tsx +1 -0
  90. package/src/pm-plugins/drag-and-drop/commands.ts +3 -2
  91. package/src/pm-plugins/drag-and-drop/plugin.ts +10 -4
  92. package/src/pm-plugins/keymap.ts +35 -0
  93. package/src/pm-plugins/table-resizing/event-handlers.ts +33 -21
  94. package/src/pm-plugins/table-resizing/utils/index.ts +1 -0
  95. package/src/types.ts +9 -0
  96. package/src/ui/DragHandle/index.tsx +1 -1
  97. package/src/ui/FloatingDragMenu/DragMenu.tsx +226 -7
  98. package/src/ui/FloatingDragMenu/index.tsx +4 -1
  99. package/src/ui/FloatingDragMenu/styles.ts +71 -0
  100. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +35 -37
  101. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +33 -33
  102. package/src/ui/consts.ts +6 -1
  103. package/src/ui/ui-styles.ts +115 -64
  104. package/src/utils/decoration.ts +27 -8
  105. package/tsconfig.app.json +3 -0
@@ -1,6 +1,6 @@
1
1
  import { css } from '@emotion/react';
2
2
  import { tableCellBorderWidth, tableMarginTop, tableMarginTopWithControl } from '@atlaskit/editor-common/styles';
3
- import { akEditorShadowZIndex, akEditorTableNumberColumnWidth, akEditorUnitZIndex } from '@atlaskit/editor-shared-styles';
3
+ import { akEditorShadowZIndex, akEditorTableBorder, akEditorTableNumberColumnWidth, akEditorUnitZIndex } from '@atlaskit/editor-shared-styles';
4
4
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
5
  import { B300, N0, N300, N40A, N60A, Y200, Y50 } from '@atlaskit/theme/colors';
6
6
  import { TableCssClassName as ClassName } from '../types';
@@ -786,116 +786,159 @@ export const resizeHandle = () => css`
786
786
  `;
787
787
 
788
788
  // Drag and Drop: drop target insert line
789
+ const tableCellColumnInsertLineStyles = css`
790
+ content: ' ';
791
+ position: absolute;
792
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
793
+ width: ${insertLineWidth}px;
794
+ z-index: ${columnControlsZIndex * 2};
795
+ `;
796
+ const tableCellRowInsertLineStyles = css`
797
+ content: ' ';
798
+ position: absolute;
799
+ left: ${"var(--ds-space-negative-025, -2px)"};
800
+ height: ${insertLineWidth}px;
801
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
802
+ z-index: ${columnControlsZIndex * 2};
803
+ `;
804
+ const insertLineActiveColor = css`
805
+ background-color: ${tableBorderSelectedColor};
806
+ `;
807
+ const insertLineInactiveColor = css`
808
+ background-color: ${`var(--ds-background-accent-gray-subtler, ${akEditorTableBorder})`};
809
+ `;
789
810
  export const insertLine = () => css`
790
811
  .${ClassName.TABLE_CONTAINER} {
791
812
  td.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE}::before {
792
- content: ' ';
793
- position: absolute;
813
+ ${tableCellColumnInsertLineStyles}
794
814
  left: -1px;
795
815
  top: -1px;
796
- width: ${insertLineWidth}px;
797
- height: calc(100% + ${tableCellBorderWidth * 2}px);
798
- background-color: ${tableBorderSelectedColor};
799
- z-index: ${columnControlsZIndex * 2};
816
+ ${insertLineActiveColor}
817
+ }
818
+
819
+ td.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE_INACTIVE}::before {
820
+ ${tableCellColumnInsertLineStyles}
821
+ left: -1px;
822
+ top: -1px;
823
+ ${insertLineInactiveColor}
800
824
  }
801
825
 
802
826
  th.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE}::before {
803
- content: ' ';
827
+ ${tableCellColumnInsertLineStyles}
828
+ left: -1px;
829
+ top: -${tableCellBorderWidth}px;
830
+ ${insertLineActiveColor}
831
+ }
832
+
833
+ th.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE_INACTIVE}::before {
834
+ ${tableCellColumnInsertLineStyles}
804
835
  left: -1px;
805
- position: absolute;
806
- width: ${insertLineWidth}px;
807
- height: calc(100% + ${tableCellBorderWidth * 2}px);
808
- background-color: ${tableBorderSelectedColor};
809
- z-index: ${columnControlsZIndex * 2};
810
836
  top: -${tableCellBorderWidth}px;
837
+ ${insertLineInactiveColor}
811
838
  }
812
839
 
813
840
  td.${ClassName.WITH_COLUMN_INSERT_LINE}::before {
814
- content: ' ';
815
- position: absolute;
841
+ ${tableCellColumnInsertLineStyles}
816
842
  left: ${"var(--ds-space-negative-025, -2px)"};
817
843
  top: -1px;
818
- width: ${insertLineWidth}px;
819
- height: calc(100% + ${tableCellBorderWidth * 2}px);
820
- background-color: ${tableBorderSelectedColor};
821
- z-index: ${columnControlsZIndex * 2};
844
+ ${insertLineActiveColor}
845
+ }
846
+
847
+ td.${ClassName.WITH_COLUMN_INSERT_LINE_INACTIVE}::before {
848
+ ${tableCellColumnInsertLineStyles}
849
+ left: ${"var(--ds-space-negative-025, -2px)"};
850
+ top: -1px;
851
+ ${insertLineInactiveColor}
822
852
  }
823
853
 
824
854
  th.${ClassName.WITH_COLUMN_INSERT_LINE}::before {
825
- content: ' ';
855
+ ${tableCellColumnInsertLineStyles}
856
+ left: ${"var(--ds-space-negative-025, -2px)"};
857
+ top: -${tableCellBorderWidth}px;
858
+ ${insertLineActiveColor}
859
+ }
860
+
861
+ th.${ClassName.WITH_COLUMN_INSERT_LINE_INACTIVE}::before {
862
+ ${tableCellColumnInsertLineStyles}
826
863
  left: ${"var(--ds-space-negative-025, -2px)"};
827
- position: absolute;
828
- width: ${insertLineWidth}px;
829
- height: calc(100% + ${tableCellBorderWidth * 2}px);
830
- background-color: ${tableBorderSelectedColor};
831
- z-index: ${columnControlsZIndex * 2};
832
864
  top: -${tableCellBorderWidth}px;
865
+ ${insertLineInactiveColor}
833
866
  }
834
867
 
835
868
  td.${ClassName.WITH_LAST_COLUMN_INSERT_LINE}::before {
836
- content: ' ';
837
- position: absolute;
869
+ ${tableCellColumnInsertLineStyles}
838
870
  right: -1px;
839
871
  top: -1px;
840
- width: ${insertLineWidth}px;
841
- height: calc(100% + ${tableCellBorderWidth * 2}px);
842
- background-color: ${tableBorderSelectedColor};
843
- z-index: ${columnControlsZIndex * 2};
872
+ ${insertLineActiveColor}
873
+ }
874
+
875
+ td.${ClassName.WITH_LAST_COLUMN_INSERT_LINE_INACTIVE}::before {
876
+ ${tableCellColumnInsertLineStyles}
877
+ right: -1px;
878
+ top: -1px;
879
+ ${insertLineInactiveColor}
844
880
  }
845
881
 
846
882
  th.${ClassName.WITH_LAST_COLUMN_INSERT_LINE}::before {
847
- content: ' ';
883
+ ${tableCellColumnInsertLineStyles}
884
+ right: -1px;
885
+ top: -${tableCellBorderWidth}px;
886
+ ${insertLineActiveColor}
887
+ }
888
+
889
+ th.${ClassName.WITH_LAST_COLUMN_INSERT_LINE_INACTIVE}::before {
890
+ ${tableCellColumnInsertLineStyles}
848
891
  right: -1px;
849
- position: absolute;
850
- width: ${insertLineWidth}px;
851
- height: calc(100% + ${tableCellBorderWidth * 2}px);
852
- background-color: ${tableBorderSelectedColor};
853
- z-index: ${columnControlsZIndex * 2};
854
892
  top: -${tableCellBorderWidth}px;
893
+ ${insertLineInactiveColor}
855
894
  }
856
895
 
857
896
  td.${ClassName.WITH_ROW_INSERT_LINE}::before {
858
- content: ' ';
859
- position: absolute;
860
- left: ${"var(--ds-space-negative-025, -2px)"};
897
+ ${tableCellRowInsertLineStyles}
861
898
  top: -1px;
862
- height: ${insertLineWidth}px;
863
- width: calc(100% + ${tableCellBorderWidth * 2}px);
864
- background-color: ${tableBorderSelectedColor};
865
- z-index: ${columnControlsZIndex * 2};
899
+ ${insertLineActiveColor}
900
+ }
901
+
902
+ td.${ClassName.WITH_ROW_INSERT_LINE_INACTIVE}::before {
903
+ ${tableCellRowInsertLineStyles}
904
+ top: -1px;
905
+ ${insertLineInactiveColor}
866
906
  }
867
907
 
868
908
  th.${ClassName.WITH_ROW_INSERT_LINE}::before {
869
- content: ' ';
870
- left: ${"var(--ds-space-negative-025, -2px)"};
871
- position: absolute;
872
- height: ${insertLineWidth}px;
873
- width: calc(100% + ${tableCellBorderWidth * 2}px);
874
- background-color: ${tableBorderSelectedColor};
875
- z-index: ${columnControlsZIndex * 2};
909
+ ${tableCellRowInsertLineStyles}
910
+ top: -1px;
911
+ ${insertLineActiveColor}
912
+ }
913
+
914
+ th.${ClassName.WITH_ROW_INSERT_LINE_INACTIVE}::before {
915
+ ${tableCellRowInsertLineStyles}
876
916
  top: -1px;
917
+ ${insertLineInactiveColor}
877
918
  }
878
919
 
879
920
  td.${ClassName.WITH_LAST_ROW_INSERT_LINE}::before {
880
- content: ' ';
881
- position: absolute;
882
- left: ${"var(--ds-space-negative-025, -2px)"};
921
+ ${tableCellRowInsertLineStyles}
883
922
  bottom: 0;
884
- height: ${insertLineWidth}px;
885
- width: calc(100% + 2px);
886
- background-color: ${tableBorderSelectedColor};
887
- z-index: ${columnControlsZIndex * 2};
923
+ ${insertLineActiveColor}
924
+ }
925
+
926
+ td.${ClassName.WITH_LAST_ROW_INSERT_LINE_INACTIVE}::before {
927
+ ${tableCellRowInsertLineStyles}
928
+ bottom: 0;
929
+ ${insertLineInactiveColor}
888
930
  }
889
931
 
890
932
  th.${ClassName.WITH_LAST_ROW_INSERT_LINE}::before {
891
- content: ' ';
892
- left: ${"var(--ds-space-negative-025, -2px)"};
933
+ ${tableCellRowInsertLineStyles}
893
934
  bottom: 0;
894
- position: absolute;
895
- height: ${insertLineWidth}px;
896
- width: calc(100% + ${tableCellBorderWidth * 2}px);
897
- background-color: ${tableBorderSelectedColor};
898
- z-index: ${columnControlsZIndex * 2};
935
+ ${insertLineActiveColor}
936
+ }
937
+
938
+ th.${ClassName.WITH_LAST_ROW_INSERT_LINE_INACTIVE}::before {
939
+ ${tableCellRowInsertLineStyles}
940
+ bottom: 0;
941
+ ${insertLineInactiveColor}
899
942
  }
900
943
  }
901
944
  `;
@@ -426,7 +426,7 @@ export const createColumnLineResize = (selection, cellColumnPositioning) => {
426
426
  });
427
427
  }).filter(nonNullable);
428
428
  };
429
- export const createColumnInsertLine = (columnIndex, selection) => {
429
+ export const createColumnInsertLine = (columnIndex, selection, hasMergedCells) => {
430
430
  const table = findTable(selection);
431
431
  if (!table) {
432
432
  return [];
@@ -437,7 +437,12 @@ export const createColumnInsertLine = (columnIndex, selection) => {
437
437
  if (isLastColumn) {
438
438
  columnIndex -= 1;
439
439
  }
440
- const decorationClassName = isFirstColumn ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE : isLastColumn ? ClassName.WITH_LAST_COLUMN_INSERT_LINE : ClassName.WITH_COLUMN_INSERT_LINE;
440
+ let decorationClassName;
441
+ if (hasMergedCells) {
442
+ decorationClassName = isFirstColumn ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE_INACTIVE : isLastColumn ? ClassName.WITH_LAST_COLUMN_INSERT_LINE_INACTIVE : ClassName.WITH_COLUMN_INSERT_LINE_INACTIVE;
443
+ } else {
444
+ decorationClassName = isFirstColumn ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE : isLastColumn ? ClassName.WITH_LAST_COLUMN_INSERT_LINE : ClassName.WITH_COLUMN_INSERT_LINE;
445
+ }
441
446
  const cellPositions = makeArray(map.height).map(rowIndex => map.map[map.width * rowIndex + columnIndex]).filter((cellPosition, rowIndex) => {
442
447
  if (isLastColumn) {
443
448
  return true; // If is the last column no filter applied
@@ -462,7 +467,7 @@ export const createColumnInsertLine = (columnIndex, selection) => {
462
467
  });
463
468
  }).filter(nonNullable);
464
469
  };
465
- export const createRowInsertLine = (rowIndex, selection) => {
470
+ export const createRowInsertLine = (rowIndex, selection, hasMergedCells) => {
466
471
  const table = findTable(selection);
467
472
  if (!table) {
468
473
  return [];
@@ -476,7 +481,12 @@ export const createRowInsertLine = (rowIndex, selection) => {
476
481
  if (!cells) {
477
482
  return [];
478
483
  }
479
- const decorationClassName = isLastRow ? ClassName.WITH_LAST_ROW_INSERT_LINE : ClassName.WITH_ROW_INSERT_LINE;
484
+ let decorationClassName;
485
+ if (hasMergedCells) {
486
+ decorationClassName = isLastRow ? ClassName.WITH_LAST_ROW_INSERT_LINE_INACTIVE : ClassName.WITH_ROW_INSERT_LINE_INACTIVE;
487
+ } else {
488
+ decorationClassName = isLastRow ? ClassName.WITH_LAST_ROW_INSERT_LINE : ClassName.WITH_ROW_INSERT_LINE;
489
+ }
480
490
  return cells.map((cell, index) => {
481
491
  if (!cell || !cell.node) {
482
492
  return;
@@ -0,0 +1,149 @@
1
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
+ import { TableMap } from '@atlaskit/editor-tables';
3
+ import { findCellClosestToPos, findCellRectClosestToPos, findTableClosestToPos, getSelectionRect, isSelectionType, nextCell } from '@atlaskit/editor-tables/src/utils';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
+ import { getPluginState as getTableResizingPluginState, createCommand as tableResizingPluginCreateCommand } from '../pm-plugins/table-resizing/plugin-factory';
6
+ import { currentColWidth, getResizeState, getTableMaxWidth, resizeColumn, updateControls } from '../pm-plugins/table-resizing/utils';
7
+ import { updateColumnWidths } from '../transforms';
8
+ import { getSelectedColumnIndexes } from '../utils';
9
+ import { addResizeHandleDecorations, showResizeHandleLine } from './index';
10
+ var updateResizeHandleAndStatePosition = function updateResizeHandleAndStatePosition(rowIndex, columnIndex, nextResizeHandlePos) {
11
+ return function (state, dispatch) {
12
+ addResizeHandleDecorations(rowIndex, columnIndex, true)(state, dispatch);
13
+ // Currently only 'right' position is used in showResizeHandleLine
14
+ showResizeHandleLine({
15
+ left: 0,
16
+ right: columnIndex
17
+ })(state, dispatch);
18
+ tableResizingPluginCreateCommand({
19
+ type: 'SET_RESIZE_HANDLE_POSITION',
20
+ data: {
21
+ resizeHandlePos: nextResizeHandlePos
22
+ }
23
+ })(state, dispatch);
24
+ return false;
25
+ };
26
+ };
27
+ export var initiateKeyboardColumnResizing = function initiateKeyboardColumnResizing(state, dispatch, view) {
28
+ if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
29
+ return false;
30
+ }
31
+ var selection = state.selection;
32
+ var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
33
+ var cell = findCellClosestToPos(selection.$from);
34
+ if (selectionRect && cell && view) {
35
+ var cellAttrs = cell.node.attrs;
36
+ var width = currentColWidth(view, cell.pos, cellAttrs);
37
+ updateResizeHandleAndStatePosition(selectionRect.top, selectionRect.right, cell.pos)(state, dispatch);
38
+ tableResizingPluginCreateCommand({
39
+ type: 'SET_DRAGGING',
40
+ data: {
41
+ dragging: {
42
+ startX: 0,
43
+ startWidth: width
44
+ }
45
+ }
46
+ })(state, dispatch);
47
+ return true;
48
+ }
49
+ return false;
50
+ };
51
+ export var activateNextResizeArea = function activateNextResizeArea(direction) {
52
+ return function (state, dispatch) {
53
+ if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
54
+ return false;
55
+ }
56
+ var _ref = getTableResizingPluginState(state) || {},
57
+ resizeHandlePos = _ref.resizeHandlePos,
58
+ dragging = _ref.dragging;
59
+ // If No resizing has initiated, skip to regular handler
60
+ if (!resizeHandlePos || !dragging) {
61
+ return false;
62
+ }
63
+ var selection = state.selection;
64
+ var cell = findCellClosestToPos(selection.$from);
65
+ if (!cell) {
66
+ // cursor position may be changed by mouse to be outside of table;
67
+ return false;
68
+ }
69
+ var $currentCell = state.doc.resolve(resizeHandlePos);
70
+ if (!$currentCell) {
71
+ return false;
72
+ }
73
+ var tableNode = $currentCell.node(-1);
74
+ var closestTable = findTableClosestToPos($currentCell);
75
+ var tableMap = TableMap.get(tableNode);
76
+ if (!tableNode || !closestTable || !tableMap) {
77
+ return false;
78
+ }
79
+ var currentCellRect = tableMap.findCell($currentCell.pos - $currentCell.start(-1));
80
+ var $nextCell = nextCell($currentCell, 'horiz', direction);
81
+ if ($nextCell) {
82
+ // we are somewhere in between the side columns of the table
83
+ var offset = $nextCell.pos - $nextCell.start(-1);
84
+ var rectForNextCell = tableMap.findCell(offset);
85
+ updateResizeHandleAndStatePosition(rectForNextCell.top, rectForNextCell.right, $nextCell.pos)(state, dispatch);
86
+ } else {
87
+ // current position is in the one of the side columns of the table(left or right)
88
+ if (currentCellRect.left === 0) {
89
+ var lastCellInCurrentRow = tableMap.positionAt(currentCellRect.top, tableMap.width - 1, tableNode) + closestTable.start;
90
+ var $lastCell = state.doc.resolve(lastCellInCurrentRow);
91
+ updateResizeHandleAndStatePosition(currentCellRect.top, tableMap.width, $lastCell.pos)(state, dispatch);
92
+ } else if (tableMap.width === currentCellRect.right) {
93
+ var firsCellInCurrentRow = tableMap.positionAt(currentCellRect.top, 0, tableNode) + closestTable.start;
94
+ var _$nextCell = state.doc.resolve(firsCellInCurrentRow);
95
+ updateResizeHandleAndStatePosition(currentCellRect.top, 1, _$nextCell.pos)(state, dispatch);
96
+ }
97
+ }
98
+ return true;
99
+ };
100
+ };
101
+ export var changeColumnWidthByStep = function changeColumnWidthByStep(stepSize, getEditorContainerWidth) {
102
+ return function (state, dispatch, view) {
103
+ if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
104
+ return false;
105
+ }
106
+ var _getTableResizingPlug = getTableResizingPluginState(state),
107
+ resizeHandlePos = _getTableResizingPlug.resizeHandlePos,
108
+ dragging = _getTableResizingPlug.dragging;
109
+ if (!view || !resizeHandlePos || !dragging) {
110
+ return false;
111
+ }
112
+ var $cell = state.doc.resolve(resizeHandlePos);
113
+ var tableStartPosition = $cell.start(-1);
114
+ var originalTable = $cell.node(-1);
115
+ var map = TableMap.get(originalTable);
116
+ var domAtPos = view.domAtPos.bind(view);
117
+ var colIndex = map.colCount($cell.pos - tableStartPosition) + ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) - 1;
118
+ var dom = domAtPos(tableStartPosition).node;
119
+ if (dom && dom.nodeName !== 'TABLE') {
120
+ dom = dom.closest('table');
121
+ }
122
+ var maxSize = getTableMaxWidth({
123
+ table: originalTable,
124
+ tableStart: tableStartPosition,
125
+ state: state,
126
+ layout: originalTable.attrs.layout,
127
+ getEditorContainerWidth: getEditorContainerWidth
128
+ });
129
+ var initialResizeState = getResizeState({
130
+ minWidth: tableCellMinWidth,
131
+ maxSize: maxSize,
132
+ table: originalTable,
133
+ tableRef: dom,
134
+ start: tableStartPosition,
135
+ domAtPos: domAtPos
136
+ });
137
+ updateControls()(state);
138
+ var selectionRect = getSelectionRect(state.selection);
139
+ var selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
140
+ // only selected (or selected - 1) columns should be distributed
141
+ var resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
142
+ var newResizeState = resizeColumn(initialResizeState, colIndex, stepSize, dom, resizingSelectedColumns ? selectedColumns : undefined);
143
+ var tr = updateColumnWidths(newResizeState, originalTable, tableStartPosition)(state.tr);
144
+ if (dispatch) {
145
+ dispatch(tr);
146
+ }
147
+ return true;
148
+ };
149
+ };
@@ -4,7 +4,10 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
6
  import { goToNextCell as baseGotoNextCell, findTable } from '@atlaskit/editor-tables/utils';
7
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
8
  import { insertRowWithAnalytics } from '../commands-with-analytics';
9
+ import { getPluginState as getResizePluginState, createCommand as tableResizingPluginCreateCommand } from '../pm-plugins/table-resizing/plugin-factory';
10
+ import { hideResizeHandleLine } from './hover';
8
11
  var TAB_FORWARD_DIRECTION = 1;
9
12
  var TAB_BACKWARD_DIRECTION = -1;
10
13
  export var goToNextCell = function goToNextCell(editorAnalyticsAPI) {
@@ -14,6 +17,18 @@ export var goToNextCell = function goToNextCell(editorAnalyticsAPI) {
14
17
  if (!table) {
15
18
  return false;
16
19
  }
20
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
21
+ var _getResizePluginState;
22
+ var isColumnResizing = !!((_getResizePluginState = getResizePluginState(state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging);
23
+ if (isColumnResizing) {
24
+ tableResizingPluginCreateCommand({
25
+ type: 'STOP_RESIZING'
26
+ }, function (originalTr) {
27
+ return (state.tr || originalTr).setMeta('scrollIntoView', false);
28
+ })(state, dispatch);
29
+ hideResizeHandleLine()(state, dispatch);
30
+ }
31
+ }
17
32
  var map = TableMap.get(table.node);
18
33
  var _state$schema$nodes = state.schema.nodes,
19
34
  tableCell = _state$schema$nodes.tableCell,
@@ -3,7 +3,9 @@ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
5
  import { findTable, isColumnSelected, isRowSelected, isTableSelected, selectedRect } from '@atlaskit/editor-tables/utils';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
7
  import { selectColumn, selectRow } from '../commands/misc';
8
+ import { getPluginState as getResizePluginState } from '../pm-plugins/table-resizing/plugin-factory';
7
9
  import { getClosestSelectionRect } from '../toolbar';
8
10
  export var TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
9
11
  TableSelectionDirection["TopToBottom"] = "TopToBottom";
@@ -192,9 +194,14 @@ var arrowLeftFromText = function arrowLeftFromText(editorSelectionAPI) {
192
194
  var table = findTable(selection);
193
195
  if (table) {
194
196
  var $from = selection.$from;
197
+ var isColumnResizing = false;
198
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
199
+ var columResizePluginState = getResizePluginState(state) || {};
200
+ isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.dragging);
201
+ }
195
202
  if (isSelectionAtStartOfTable($from, selection) && $from.parent.type.name === 'paragraph' && $from.depth === table.depth + 3 &&
196
203
  // + 3 for: row, cell & paragraph nodes
197
- editorSelectionAPI) {
204
+ editorSelectionAPI && !isColumnResizing) {
198
205
  var selectionState = editorSelectionAPI.sharedState.currentState() || {};
199
206
  if ((selectionState === null || selectionState === void 0 ? void 0 : selectionState.selectionRelativeToNode) === RelativeSelectionPos.Before) {
200
207
  // we have a text selection at start of first table cell, directly inside a top level paragraph,
@@ -221,8 +228,14 @@ var arrowRightFromText = function arrowRightFromText(editorSelectionAPI) {
221
228
  var table = findTable(selection);
222
229
  if (table) {
223
230
  var $to = selection.$to;
224
- if (isSelectionAtEndOfTable($to, selection) && $to.parent.type.name === 'paragraph' && $to.depth === table.depth + 3 // + 3 for: row, cell & paragraph nodes
225
- ) {
231
+ var isColumnResizing = false;
232
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
233
+ var columResizePluginState = getResizePluginState(state) || {};
234
+ isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.dragging);
235
+ }
236
+ if (isSelectionAtEndOfTable($to, selection) && $to.parent.type.name === 'paragraph' && $to.depth === table.depth + 3 &&
237
+ // + 3 for: row, cell & paragraph nodes
238
+ !isColumnResizing) {
226
239
  // we have a text selection at end of last table cell, directly inside a top level paragraph,
227
240
  // and want to set a full table cell selection
228
241
  return selectFullTable(editorSelectionAPI)({
@@ -45,7 +45,8 @@ export var ExternalDropTargets = function ExternalDropTargets(_ref) {
45
45
  top: "-".concat(dropTargetExtendedWidth - tableMarginTop, "px"),
46
46
  pointerEvents: 'auto',
47
47
  zIndex: "".concat(dropTargetsZIndex)
48
- }
48
+ },
49
+ "data-testid": "table-floating-column-extended-drop-targets"
49
50
  }, /*#__PURE__*/React.createElement("div", {
50
51
  style: {
51
52
  display: 'flex',
@@ -355,7 +355,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
355
355
  canDrag: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.canDrag,
356
356
  getEditorContainerWidth: defaultGetEditorContainerWidth,
357
357
  editorAnalyticsAPI: editorAnalyticsAPI,
358
- stickyHeaders: stickyHeader
358
+ stickyHeaders: stickyHeader,
359
+ pluginConfig: pluginConfig
359
360
  }), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
360
361
  editorView: editorView,
361
362
  selection: editorView.state.selection,
@@ -17,7 +17,7 @@ export var getDecorations = function getDecorations(state) {
17
17
  export var updatePluginStateDecorations = function updatePluginStateDecorations(state, decorations, key) {
18
18
  return updateDecorations(state.doc, getDecorations(state), decorations, key);
19
19
  };
20
- export var setDropTarget = function setDropTarget(type, index, tr) {
20
+ export var setDropTarget = function setDropTarget(type, index, hasMergedCells, tr) {
21
21
  return createCommand(function (state) {
22
22
  var _getPluginState = getPluginState(state),
23
23
  dropTargetType = _getPluginState.dropTargetType,
@@ -27,9 +27,9 @@ export var setDropTarget = function setDropTarget(type, index, tr) {
27
27
  }
28
28
  var decorationSet = DecorationSet.empty;
29
29
  if (type === 'column') {
30
- decorationSet = updatePluginStateDecorations(state, createColumnInsertLine(index, state.selection), TableDecorations.COLUMN_INSERT_LINE);
30
+ decorationSet = updatePluginStateDecorations(state, createColumnInsertLine(index, state.selection, hasMergedCells), TableDecorations.COLUMN_INSERT_LINE);
31
31
  } else if (type === 'row') {
32
- decorationSet = updatePluginStateDecorations(state, createRowInsertLine(index, state.selection), TableDecorations.ROW_INSERT_LINE);
32
+ decorationSet = updatePluginStateDecorations(state, createRowInsertLine(index, state.selection, hasMergedCells), TableDecorations.ROW_INSERT_LINE);
33
33
  }
34
34
  return {
35
35
  type: DragAndDropActionType.SET_DROP_TARGET,
@@ -131,7 +131,8 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher, edito
131
131
  var sourceType = data.sourceType,
132
132
  targetAdjustedIndex = data.targetAdjustedIndex;
133
133
  var dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
134
- setDropTarget(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
134
+ var hasMergedCells = hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], dropTargetType)(editorView.state.selection);
135
+ setDropTarget(dropTargetType, targetAdjustedIndex, hasMergedCells)(editorView.state, editorView.dispatch);
135
136
  },
136
137
  onDrop: function onDrop(event) {
137
138
  var _cell$row, _cell$col;
@@ -1,9 +1,11 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, backspace, bindKeymapWithCommand, deleteColumn, deleteRow, moveColumnLeft, moveColumnRight, moveRowDown, moveRowUp, nextCell, previousCell, toggleTable } from '@atlaskit/editor-common/keymaps';
2
+ import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, backspace, bindKeymapWithCommand, decreaseMediaSize, deleteColumn, deleteRow, increaseMediaSize, moveColumnLeft, moveColumnRight, moveLeft, moveRight, moveRowDown, moveRowUp, nextCell, previousCell, startColumnResizing, toggleTable } from '@atlaskit/editor-common/keymaps';
3
3
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
4
4
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
6
  import { createTable, goToNextCell, moveCursorBackward, triggerUnlessTableHeader } from '../commands';
6
7
  import { addRowAroundSelection, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut, deleteTableIfSelectedWithAnalytics, emptyMultipleCellsWithAnalytics } from '../commands-with-analytics';
8
+ import { activateNextResizeArea, changeColumnWidthByStep, initiateKeyboardColumnResizing } from '../commands/column-resize';
7
9
  import { addColumnAfter as addColumnAfterCommand, addColumnBefore as addColumnBeforeCommand } from '../commands/insert';
8
10
  import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/commands-with-analytics';
9
11
  import { withEditorAnalyticsAPI } from '../utils/analytics';
@@ -42,6 +44,13 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAn
42
44
  bindKeymapWithCommand(deleteColumn.common, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI), list);
43
45
  bindKeymapWithCommand(deleteRow.common, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI), list);
44
46
  }
47
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
48
+ bindKeymapWithCommand(startColumnResizing.common, initiateKeyboardColumnResizing, list);
49
+ bindKeymapWithCommand(moveRight.common, activateNextResizeArea(1), list);
50
+ bindKeymapWithCommand(moveLeft.common, activateNextResizeArea(-1), list);
51
+ bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStep(-10, getEditorContainerWidth), list);
52
+ bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStep(10, getEditorContainerWidth), list);
53
+ }
45
54
  return keymap(list);
46
55
  }
47
56
  export default keymapPlugin;
@@ -11,7 +11,7 @@ import { getSelectedColumnIndexes } from '../../utils';
11
11
  import { META_KEYS } from '../table-analytics';
12
12
  import { evenColumns, setDragging, stopResizing } from './commands';
13
13
  import { getPluginState } from './plugin-factory';
14
- import { currentColWidth, getLayoutSize, getResizeState, pointsAtCell, resizeColumn, updateControls } from './utils';
14
+ import { currentColWidth, getLayoutSize, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, updateControls } from './utils';
15
15
  export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI) {
16
16
  var state = view.state,
17
17
  dispatch = view.dispatch;
@@ -35,13 +35,24 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
35
35
  if (dom && dom.nodeName !== 'TABLE') {
36
36
  dom = dom.closest('table');
37
37
  }
38
- var containerWidth = getEditorContainerWidth();
39
- var parentWidth = getParentNodeWidth(start, state, containerWidth);
40
- var maxSize = getBooleanFF('platform.editor.custom-table-width') ? parentWidth ||
41
- // its safe to reference table width from node as this will not have changed
42
- originalTable.attrs.width || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {}) : parentWidth || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {});
43
- if (originalTable.attrs.isNumberColumnEnabled) {
44
- maxSize -= akEditorTableNumberColumnWidth;
38
+ var maxSize;
39
+ if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
40
+ var containerWidth = getEditorContainerWidth();
41
+ var parentWidth = getParentNodeWidth(start, state, containerWidth);
42
+ maxSize = getBooleanFF('platform.editor.custom-table-width') ? parentWidth ||
43
+ // its safe to reference table width from node as this will not have changed
44
+ originalTable.attrs.width || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {}) : parentWidth || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {});
45
+ if (originalTable.attrs.isNumberColumnEnabled) {
46
+ maxSize -= akEditorTableNumberColumnWidth;
47
+ }
48
+ } else {
49
+ maxSize = getTableMaxWidth({
50
+ table: originalTable,
51
+ tableStart: start,
52
+ state: state,
53
+ layout: originalTable.attrs.layout,
54
+ getEditorContainerWidth: getEditorContainerWidth
55
+ });
45
56
  }
46
57
  var resizeState = getResizeState({
47
58
  minWidth: tableCellMinWidth,
@@ -3,7 +3,7 @@ export { contentWidth } from './content-width';
3
3
  export { getColumnStateFromDOM, getFreeSpace, getCellsRefsInColumn, calculateColumnWidth, addContainerLeftRightPadding } from './column-state';
4
4
  export { growColumn, shrinkColumn, reduceSpace } from './resize-logic';
5
5
  export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bulkColumnsResize, areColumnsEven, adjustColumnsWidths } from './resize-state';
6
- export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround } from './misc';
6
+ export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth } from './misc';
7
7
  export { updateControls, isClickNear, getResizeCellPos } from './dom';
8
8
  export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
9
9
  export { resizeColumn } from './resize-column';