@atlaskit/editor-plugin-table 5.3.0 → 5.3.2

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 (186) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/table/commands/hover.js +17 -8
  3. package/dist/cjs/plugins/table/commands/index.js +6 -0
  4. package/dist/cjs/plugins/table/commands/misc.js +1 -7
  5. package/dist/cjs/plugins/table/event-handlers.js +29 -2
  6. package/dist/cjs/plugins/table/index.js +1 -1
  7. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +5 -3
  8. package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
  9. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +7 -3
  10. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  11. package/dist/cjs/plugins/table/pm-plugins/default-table-selection.js +14 -1
  12. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  13. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -7
  14. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  15. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
  16. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
  17. package/dist/cjs/plugins/table/pm-plugins/main.js +5 -5
  18. package/dist/cjs/plugins/table/reducer.js +2 -1
  19. package/dist/cjs/plugins/table/types.js +14 -1
  20. package/dist/cjs/plugins/table/ui/DragHandle/index.js +50 -0
  21. package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +53 -14
  22. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +114 -0
  23. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +53 -0
  24. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +11 -106
  25. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +16 -6
  26. package/dist/cjs/plugins/table/ui/common-styles.js +9 -6
  27. package/dist/cjs/plugins/table/ui/consts.js +3 -1
  28. package/dist/cjs/plugins/table/ui/ui-styles.js +21 -9
  29. package/dist/cjs/plugins/table/utils/decoration.js +111 -19
  30. package/dist/cjs/plugins/table/utils/dom.js +7 -1
  31. package/dist/cjs/plugins/table/utils/index.js +38 -1
  32. package/dist/cjs/plugins/table/utils/merged-cells.js +66 -0
  33. package/dist/es2019/plugins/table/commands/hover.js +12 -8
  34. package/dist/es2019/plugins/table/commands/index.js +1 -1
  35. package/dist/es2019/plugins/table/commands/misc.js +1 -7
  36. package/dist/es2019/plugins/table/event-handlers.js +28 -2
  37. package/dist/es2019/plugins/table/index.js +1 -1
  38. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -3
  39. package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
  40. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +8 -6
  41. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  42. package/dist/es2019/plugins/table/pm-plugins/default-table-selection.js +13 -0
  43. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -7
  44. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -4
  45. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  46. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  47. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -0
  48. package/dist/es2019/plugins/table/pm-plugins/main.js +6 -5
  49. package/dist/es2019/plugins/table/reducer.js +2 -1
  50. package/dist/es2019/plugins/table/types.js +14 -1
  51. package/dist/es2019/plugins/table/ui/DragHandle/index.js +41 -0
  52. package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -10
  53. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +86 -0
  54. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +43 -0
  55. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -88
  56. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +17 -7
  57. package/dist/es2019/plugins/table/ui/common-styles.js +49 -13
  58. package/dist/es2019/plugins/table/ui/consts.js +2 -0
  59. package/dist/es2019/plugins/table/ui/ui-styles.js +171 -15
  60. package/dist/es2019/plugins/table/utils/decoration.js +106 -18
  61. package/dist/es2019/plugins/table/utils/dom.js +2 -0
  62. package/dist/es2019/plugins/table/utils/index.js +4 -3
  63. package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
  64. package/dist/esm/plugins/table/commands/hover.js +16 -8
  65. package/dist/esm/plugins/table/commands/index.js +1 -1
  66. package/dist/esm/plugins/table/commands/misc.js +1 -7
  67. package/dist/esm/plugins/table/event-handlers.js +29 -2
  68. package/dist/esm/plugins/table/index.js +1 -1
  69. package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -3
  70. package/dist/esm/plugins/table/nodeviews/table.js +4 -2
  71. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +8 -6
  72. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  73. package/dist/esm/plugins/table/pm-plugins/default-table-selection.js +13 -0
  74. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  75. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +65 -4
  76. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  77. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  78. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -0
  79. package/dist/esm/plugins/table/pm-plugins/main.js +7 -7
  80. package/dist/esm/plugins/table/reducer.js +2 -1
  81. package/dist/esm/plugins/table/types.js +14 -1
  82. package/dist/esm/plugins/table/ui/DragHandle/index.js +41 -0
  83. package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -15
  84. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +104 -0
  85. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +46 -0
  86. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -104
  87. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +17 -7
  88. package/dist/esm/plugins/table/ui/common-styles.js +11 -8
  89. package/dist/esm/plugins/table/ui/consts.js +2 -0
  90. package/dist/esm/plugins/table/ui/ui-styles.js +21 -9
  91. package/dist/esm/plugins/table/utils/decoration.js +110 -18
  92. package/dist/esm/plugins/table/utils/dom.js +6 -0
  93. package/dist/esm/plugins/table/utils/index.js +4 -3
  94. package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
  95. package/dist/types/plugins/table/commands/hover.d.ts +2 -1
  96. package/dist/types/plugins/table/commands/index.d.ts +1 -1
  97. package/dist/types/plugins/table/event-handlers.d.ts +1 -0
  98. package/dist/types/plugins/table/nodeviews/types.d.ts +4 -3
  99. package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
  100. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
  101. package/dist/types/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
  102. package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  103. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  104. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  105. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  106. package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
  107. package/dist/types/plugins/table/types.d.ts +35 -2
  108. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +11 -0
  109. package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
  110. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
  111. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
  112. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
  113. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  114. package/dist/types/plugins/table/ui/consts.d.ts +2 -0
  115. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  116. package/dist/types/plugins/table/utils/decoration.d.ts +4 -2
  117. package/dist/types/plugins/table/utils/dom.d.ts +2 -0
  118. package/dist/types/plugins/table/utils/index.d.ts +3 -2
  119. package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
  120. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
  121. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
  122. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -0
  123. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +4 -3
  124. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
  125. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
  126. package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
  127. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  128. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  129. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  130. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  131. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
  132. package/dist/types-ts4.5/plugins/table/types.d.ts +35 -2
  133. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +11 -0
  134. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
  135. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
  136. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
  137. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
  138. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  139. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +2 -0
  140. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  141. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +4 -2
  142. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +2 -0
  143. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +3 -2
  144. package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
  145. package/package.json +6 -2
  146. package/src/__tests__/unit/event-handlers.ts +74 -1
  147. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +35 -15
  148. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +146 -42
  149. package/src/__tests__/unit/ui/NumberColumn.tsx +148 -0
  150. package/src/__tests__/unit/ui/RowControls.tsx +4 -4
  151. package/src/__tests__/unit/ui/RowDragControls.tsx +118 -0
  152. package/src/__tests__/unit/ui/TableFloatingControls.tsx +9 -5
  153. package/src/plugins/table/commands/hover.ts +16 -7
  154. package/src/plugins/table/commands/index.ts +1 -0
  155. package/src/plugins/table/commands/misc.ts +0 -5
  156. package/src/plugins/table/event-handlers.ts +49 -2
  157. package/src/plugins/table/index.tsx +1 -1
  158. package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
  159. package/src/plugins/table/nodeviews/table.tsx +2 -0
  160. package/src/plugins/table/nodeviews/types.ts +4 -3
  161. package/src/plugins/table/pm-plugins/decorations/plugin.ts +13 -4
  162. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +10 -5
  163. package/src/plugins/table/pm-plugins/default-table-selection.ts +10 -0
  164. package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +6 -1
  165. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
  166. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +77 -4
  167. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
  168. package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
  169. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -0
  170. package/src/plugins/table/pm-plugins/main.ts +9 -4
  171. package/src/plugins/table/reducer.ts +2 -1
  172. package/src/plugins/table/types.ts +37 -3
  173. package/src/plugins/table/ui/DragHandle/index.tsx +57 -0
  174. package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +68 -30
  175. package/src/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.tsx +129 -0
  176. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +75 -0
  177. package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +2 -135
  178. package/src/plugins/table/ui/TableFloatingControls/index.tsx +43 -24
  179. package/src/plugins/table/ui/common-styles.ts +54 -11
  180. package/src/plugins/table/ui/consts.ts +2 -0
  181. package/src/plugins/table/ui/ui-styles.ts +173 -14
  182. package/src/plugins/table/utils/decoration.ts +176 -27
  183. package/src/plugins/table/utils/dom.ts +8 -0
  184. package/src/plugins/table/utils/index.ts +5 -0
  185. package/src/plugins/table/utils/merged-cells.ts +67 -0
  186. package/tsconfig.app.json +3 -0
@@ -22,6 +22,7 @@ import {
22
22
  columnControlsDecorationHeight,
23
23
  columnControlsSelectedZIndex,
24
24
  columnControlsZIndex,
25
+ insertLineWidth,
25
26
  lineMarkerSize,
26
27
  resizeHandlerAreaWidth,
27
28
  resizeHandlerZIndex,
@@ -389,6 +390,17 @@ export const floatingColumnControls = (props: ThemeProps) => {
389
390
  };
390
391
 
391
392
  export const columnControlsDecoration = (props: ThemeProps) => {
393
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
394
+ return css`
395
+ .${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} {
396
+ position: absolute;
397
+ // kinda a hacky way to center an element with absolute positioning inside a relative element
398
+ top: 25%;
399
+ left: 50%;
400
+ transform: translate(-50%, -100%);
401
+ }
402
+ `;
403
+ }
392
404
  if (getBooleanFF('platform.editor.table.column-controls-styles-updated')) {
393
405
  return css`
394
406
  .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
@@ -674,21 +686,35 @@ const getLastColumnResizerOverrides = () => {
674
686
  : '';
675
687
  };
676
688
 
677
- export const resizeHandle = (props: ThemeProps) => css`
678
- .${ClassName.TABLE_CONTAINER} {
679
- .${ClassName.RESIZE_HANDLE_DECORATION} {
680
- background-color: transparent;
681
- position: absolute;
682
- width: ${resizeHandlerAreaWidth}px;
683
- height: 100%;
684
- top: 0;
685
- right: -${resizeHandlerAreaWidth / 2}px;
686
- cursor: col-resize;
687
- z-index: ${resizeHandlerZIndex};
688
- }
689
-
690
- ${getLastColumnResizerOverrides()}
689
+ const resizeHandleOverrides = (props: ThemeProps) => {
690
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
691
+ return css`
692
+ th.${ClassName.WITH_RESIZE_LINE}::before,
693
+ td.${ClassName.WITH_RESIZE_LINE}::before {
694
+ content: ' ';
695
+ position: absolute;
696
+ left: ${token('space.negative.025', '-2px')};
697
+ top: -1px;
698
+ width: ${resizeLineWidth}px;
699
+ height: calc(100% + 2px);
700
+ background-color: ${tableBorderSelectedColor(props)};
701
+ z-index: ${columnControlsZIndex * 2};
702
+ }
691
703
 
704
+ th.${ClassName.WITH_RESIZE_LINE_LAST_COLUMN}::before,
705
+ td.${ClassName.WITH_RESIZE_LINE_LAST_COLUMN}::before {
706
+ content: ' ';
707
+ position: absolute;
708
+ right: -1px;
709
+ top: -1px;
710
+ width: ${resizeLineWidth}px;
711
+ height: calc(100% + 2px);
712
+ background-color: ${tableBorderSelectedColor(props)};
713
+ z-index: ${columnControlsZIndex * 2};
714
+ }
715
+ `;
716
+ }
717
+ return css`
692
718
  td.${ClassName.WITH_RESIZE_LINE}::before {
693
719
  content: ' ';
694
720
  position: absolute;
@@ -732,6 +758,25 @@ export const resizeHandle = (props: ThemeProps) => css`
732
758
  z-index: ${columnControlsZIndex * 2};
733
759
  top: -${tableToolbarSize + tableCellBorderWidth}px;
734
760
  }
761
+ `;
762
+ };
763
+
764
+ export const resizeHandle = (props: ThemeProps) => css`
765
+ .${ClassName.TABLE_CONTAINER} {
766
+ .${ClassName.RESIZE_HANDLE_DECORATION} {
767
+ background-color: transparent;
768
+ position: absolute;
769
+ width: ${resizeHandlerAreaWidth}px;
770
+ height: 100%;
771
+ top: 0;
772
+ right: -${resizeHandlerAreaWidth / 2}px;
773
+ cursor: col-resize;
774
+ z-index: ${resizeHandlerZIndex};
775
+ }
776
+
777
+ ${getLastColumnResizerOverrides()}
778
+
779
+ ${resizeHandleOverrides(props)}
735
780
 
736
781
  table
737
782
  tr:first-of-type
@@ -746,3 +791,117 @@ export const resizeHandle = (props: ThemeProps) => css`
746
791
  }
747
792
  }
748
793
  `;
794
+
795
+ export const insertLine = (props: ThemeProps) => css`
796
+ .${ClassName.TABLE_CONTAINER} {
797
+ td.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE}::before {
798
+ content: ' ';
799
+ position: absolute;
800
+ left: -1px;
801
+ top: -1px;
802
+ width: ${insertLineWidth}px;
803
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
804
+ background-color: ${tableBorderSelectedColor(props)};
805
+ z-index: ${columnControlsZIndex * 2};
806
+ }
807
+
808
+ th.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE}::before {
809
+ content: ' ';
810
+ left: -1px;
811
+ position: absolute;
812
+ width: ${insertLineWidth}px;
813
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
814
+ background-color: ${tableBorderSelectedColor(props)};
815
+ z-index: ${columnControlsZIndex * 2};
816
+ top: -${tableCellBorderWidth}px;
817
+ }
818
+
819
+ td.${ClassName.WITH_COLUMN_INSERT_LINE}::before {
820
+ content: ' ';
821
+ position: absolute;
822
+ left: ${token('space.negative.025', '-2px')};
823
+ top: -1px;
824
+ width: ${insertLineWidth}px;
825
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
826
+ background-color: ${tableBorderSelectedColor(props)};
827
+ z-index: ${columnControlsZIndex * 2};
828
+ }
829
+
830
+ th.${ClassName.WITH_COLUMN_INSERT_LINE}::before {
831
+ content: ' ';
832
+ left: ${token('space.negative.025', '-2px')};
833
+ position: absolute;
834
+ width: ${insertLineWidth}px;
835
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
836
+ background-color: ${tableBorderSelectedColor(props)};
837
+ z-index: ${columnControlsZIndex * 2};
838
+ top: -${tableCellBorderWidth}px;
839
+ }
840
+
841
+ td.${ClassName.WITH_LAST_COLUMN_INSERT_LINE}::before {
842
+ content: ' ';
843
+ position: absolute;
844
+ right: -1px;
845
+ top: -1px;
846
+ width: ${insertLineWidth}px;
847
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
848
+ background-color: ${tableBorderSelectedColor(props)};
849
+ z-index: ${columnControlsZIndex * 2};
850
+ }
851
+
852
+ th.${ClassName.WITH_LAST_COLUMN_INSERT_LINE}::before {
853
+ content: ' ';
854
+ right: -1px;
855
+ position: absolute;
856
+ width: ${insertLineWidth}px;
857
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
858
+ background-color: ${tableBorderSelectedColor(props)};
859
+ z-index: ${columnControlsZIndex * 2};
860
+ top: -${tableCellBorderWidth}px;
861
+ }
862
+
863
+ td.${ClassName.WITH_ROW_INSERT_LINE}::before {
864
+ content: ' ';
865
+ position: absolute;
866
+ left: ${token('space.negative.025', '-2px')};
867
+ top: -1px;
868
+ height: ${insertLineWidth}px;
869
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
870
+ background-color: ${tableBorderSelectedColor(props)};
871
+ z-index: ${columnControlsZIndex * 2};
872
+ }
873
+
874
+ th.${ClassName.WITH_ROW_INSERT_LINE}::before {
875
+ content: ' ';
876
+ left: ${token('space.negative.025', '-2px')};
877
+ position: absolute;
878
+ height: ${insertLineWidth}px;
879
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
880
+ background-color: ${tableBorderSelectedColor(props)};
881
+ z-index: ${columnControlsZIndex * 2};
882
+ top: -1px;
883
+ }
884
+
885
+ td.${ClassName.WITH_LAST_ROW_INSERT_LINE}::before {
886
+ content: ' ';
887
+ position: absolute;
888
+ left: ${token('space.negative.025', '-2px')};
889
+ bottom: 0;
890
+ height: ${insertLineWidth}px;
891
+ width: calc(100% + 2px);
892
+ background-color: ${tableBorderSelectedColor(props)};
893
+ z-index: ${columnControlsZIndex * 2};
894
+ }
895
+
896
+ th.${ClassName.WITH_LAST_ROW_INSERT_LINE}::before {
897
+ content: ' ';
898
+ left: ${token('space.negative.025', '-2px')};
899
+ bottom: 0;
900
+ position: absolute;
901
+ height: ${insertLineWidth}px;
902
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
903
+ background-color: ${tableBorderSelectedColor(props)};
904
+ z-index: ${columnControlsZIndex * 2};
905
+ }
906
+ }
907
+ `;
@@ -22,10 +22,16 @@ import {
22
22
  getCellsInRow,
23
23
  getSelectionRect,
24
24
  } from '@atlaskit/editor-tables/utils';
25
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
25
26
 
26
- import type { Cell, CellColumnPositioning } from '../types';
27
+ import type {
28
+ Cell,
29
+ CellColumnPositioning,
30
+ CellHoverCoordinates,
31
+ } from '../types';
27
32
  import { TableCssClassName as ClassName, TableDecorations } from '../types';
28
33
  import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
34
+ import { DragHandle } from '../ui/DragHandle';
29
35
 
30
36
  const filterDecorationByKey = (
31
37
  key: TableDecorations,
@@ -206,35 +212,77 @@ export const createColumnSelectedDecoration = (
206
212
 
207
213
  export const createColumnControlsDecoration = (
208
214
  selection: Selection,
215
+ hoverLocation?: CellHoverCoordinates,
209
216
  ): Decoration[] => {
217
+ // todo: issue here where table may not be selected yet
210
218
  const cells: ContentNodeWithPos[] = getCellsInRow(0)(selection) || [];
211
- let index = 0;
212
- return cells.map((cell) => {
213
- const colspan = (cell.node.attrs as CellAttributes).colspan || 1;
214
- // It's important these values are scoped locally as the widget callback could be executed anytime in the future
215
- // and we want to avoid value leak
216
- const startIndex = index;
217
- const endIndex = startIndex + colspan;
218
-
219
- // The next cell start index will commence from the current cell end index.
220
- index = endIndex;
219
+ const table = findTable(selection);
221
220
 
222
- return Decoration.widget(
223
- cell.pos + 1,
224
- () => {
225
- const element = document.createElement('div');
226
- element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
227
- element.dataset.startIndex = `${startIndex}`;
228
- element.dataset.endIndex = `${endIndex}`;
229
- return element;
230
- },
231
- {
232
- key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
233
- // this decoration should be the first one, even before gap cursor.
234
- side: -100,
235
- },
236
- );
237
- });
221
+ if (
222
+ getBooleanFF('platform.editor.table.drag-and-drop') &&
223
+ hoverLocation &&
224
+ !Number.isNaN(hoverLocation?.colIndex) &&
225
+ table
226
+ ) {
227
+ const colIndex = hoverLocation.colIndex as number;
228
+ const cell = cells[colIndex];
229
+ return [
230
+ Decoration.widget(
231
+ cell.pos + 1,
232
+ () => {
233
+ const element = document.createElement('div');
234
+ element.classList.add(
235
+ ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG,
236
+ );
237
+ ReactDOM.render(
238
+ createElement(DragHandle, {
239
+ tableLocalId: table.node.attrs.localId,
240
+ direction: 'column',
241
+ indexes: [colIndex],
242
+ }),
243
+ element,
244
+ );
245
+ return element;
246
+ },
247
+ {
248
+ key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${colIndex}`,
249
+ // this decoration should be the first one, even before gap cursor.
250
+ side: -100,
251
+ destroy: (node) => {
252
+ ReactDOM.unmountComponentAtNode(node as HTMLDivElement);
253
+ },
254
+ },
255
+ ),
256
+ ];
257
+ } else {
258
+ let index = 0;
259
+ return cells.map((cell) => {
260
+ const colspan = (cell.node.attrs as CellAttributes).colspan || 1;
261
+ // It's important these values are scoped locally as the widget callback could be executed anytime in the future
262
+ // and we want to avoid value leak
263
+ const startIndex = index;
264
+ const endIndex = startIndex + colspan;
265
+
266
+ // The next cell start index will commence from the current cell end index.
267
+ index = endIndex;
268
+
269
+ return Decoration.widget(
270
+ cell.pos + 1,
271
+ () => {
272
+ const element = document.createElement('div');
273
+ element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
274
+ element.dataset.startIndex = `${startIndex}`;
275
+ element.dataset.endIndex = `${endIndex}`;
276
+ return element;
277
+ },
278
+ {
279
+ key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
280
+ // this decoration should be the first one, even before gap cursor.
281
+ side: -100,
282
+ },
283
+ );
284
+ });
285
+ }
238
286
  };
239
287
 
240
288
  export const updateDecorations = (
@@ -566,3 +614,104 @@ export const createColumnLineResize = (
566
614
  })
567
615
  .filter(nonNullable);
568
616
  };
617
+
618
+ export const createColumnInsertLine = (
619
+ columnIndex: number,
620
+ selection: Selection,
621
+ ): Decoration[] => {
622
+ const table = findTable(selection);
623
+ if (!table) {
624
+ return [];
625
+ }
626
+
627
+ const map = TableMap.get(table.node);
628
+
629
+ const isFirstColumn = columnIndex === 0;
630
+ const isLastColumn = columnIndex === map.width;
631
+ if (isLastColumn) {
632
+ columnIndex -= 1;
633
+ }
634
+ const decorationClassName = isFirstColumn
635
+ ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE
636
+ : isLastColumn
637
+ ? ClassName.WITH_LAST_COLUMN_INSERT_LINE
638
+ : ClassName.WITH_COLUMN_INSERT_LINE;
639
+
640
+ const cellPositions = makeArray(map.height)
641
+ .map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
642
+ .filter((cellPosition, rowIndex) => {
643
+ if (isLastColumn) {
644
+ return true; // If is the last column no filter applied
645
+ }
646
+ const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
647
+ return cellPosition !== nextPosition; // Removed it if next position is merged
648
+ });
649
+
650
+ const cells = cellPositions.map((pos) => ({
651
+ pos: pos + table.start,
652
+ node: table.node.nodeAt(pos),
653
+ }));
654
+
655
+ return cells
656
+ .map((cell, index) => {
657
+ if (!cell || !cell.node) {
658
+ return;
659
+ }
660
+
661
+ return Decoration.node(
662
+ cell.pos,
663
+ cell.pos + cell.node.nodeSize,
664
+ {
665
+ class: decorationClassName,
666
+ },
667
+ {
668
+ key: `${TableDecorations.COLUMN_INSERT_LINE}_${index}`,
669
+ },
670
+ );
671
+ })
672
+ .filter(nonNullable);
673
+ };
674
+
675
+ export const createRowInsertLine = (
676
+ rowIndex: number,
677
+ selection: Selection,
678
+ ): Decoration[] => {
679
+ const table = findTable(selection);
680
+ if (!table) {
681
+ return [];
682
+ }
683
+
684
+ const map = TableMap.get(table.node);
685
+ const isLastRow = rowIndex === map.height;
686
+ if (isLastRow) {
687
+ rowIndex -= 1;
688
+ }
689
+
690
+ const cells = getCellsInRow(rowIndex)(selection);
691
+ if (!cells) {
692
+ return [];
693
+ }
694
+
695
+ const decorationClassName = isLastRow
696
+ ? ClassName.WITH_LAST_ROW_INSERT_LINE
697
+ : ClassName.WITH_ROW_INSERT_LINE;
698
+
699
+ return cells
700
+ .map((cell, index) => {
701
+ if (!cell || !cell.node) {
702
+ return;
703
+ }
704
+
705
+ return Decoration.node(
706
+ cell.pos,
707
+ cell.pos + cell.node.nodeSize,
708
+ {
709
+ class: decorationClassName,
710
+ },
711
+ {
712
+ key: `${TableDecorations.ROW_INSERT_LINE}_${index}`,
713
+ },
714
+ );
715
+ })
716
+ .filter(nonNullable);
717
+ };
@@ -36,10 +36,18 @@ export const isColumnControlsDecorations = (
36
36
  node: HTMLElement | null,
37
37
  ): boolean => containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS);
38
38
 
39
+ export const isColumnDragControlsDecorations = (node: HTMLElement | null) =>
40
+ containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG) ||
41
+ closestElement(node, `.${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG}`);
42
+
39
43
  export const isRowControlsButton = (node: HTMLElement | null): boolean =>
40
44
  containsClassName(node, ClassName.ROW_CONTROLS_BUTTON) ||
41
45
  containsClassName(node, ClassName.NUMBERED_COLUMN_BUTTON);
42
46
 
47
+ export const isRowDragControlsButton = (node: HTMLElement | null) =>
48
+ containsClassName(node, ClassName.ROW_CONTROLS_WITH_DRAG) ||
49
+ closestElement(node, `.${ClassName.ROW_CONTROLS_WITH_DRAG}`);
50
+
43
51
  export const isResizeHandleDecoration = (node: HTMLElement | null): boolean =>
44
52
  containsClassName(node, ClassName.RESIZE_HANDLE_DECORATION);
45
53
 
@@ -12,7 +12,9 @@ export {
12
12
  createCellHoverDecoration,
13
13
  updateDecorations,
14
14
  createResizeHandleDecoration,
15
+ createColumnInsertLine,
15
16
  createColumnLineResize,
17
+ createRowInsertLine,
16
18
  } from './decoration';
17
19
  export {
18
20
  isIsolating,
@@ -44,6 +46,8 @@ export {
44
46
  isColumnControlsDecorations,
45
47
  isTableControlsButton,
46
48
  isTableContainerOrWrapper,
49
+ isColumnDragControlsDecorations,
50
+ isRowDragControlsButton,
47
51
  isRowControlsButton,
48
52
  getColumnOrRowIndex,
49
53
  getMousePositionHorizontalRelativeByElement,
@@ -70,3 +74,4 @@ export type { RowParams } from './row-controls';
70
74
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
71
75
  export { getMergedCellsPositions } from './table';
72
76
  export { updatePluginStateDecorations } from './update-plugin-state-decorations';
77
+ export { hasMergedCellsInColumn, hasMergedCellsInRow } from './merged-cells';
@@ -0,0 +1,67 @@
1
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
+ import type { Rect } from '@atlaskit/editor-tables';
3
+ import { findTable, TableMap } from '@atlaskit/editor-tables';
4
+
5
+ const hasMergedCells =
6
+ (
7
+ indexes: number | number[],
8
+ normalizeRect: (index: number, map: TableMap) => Rect,
9
+ ) =>
10
+ (selection: Selection): boolean => {
11
+ const table = findTable(selection);
12
+ if (!table) {
13
+ return false;
14
+ }
15
+
16
+ const map = TableMap.get(table.node);
17
+ const cellPositions = new Set<number>();
18
+ const mergedCells = new Set<number>();
19
+
20
+ map.map.forEach((value) => {
21
+ if (cellPositions.has(value)) {
22
+ mergedCells.add(value);
23
+ } else {
24
+ cellPositions.add(value);
25
+ }
26
+ });
27
+
28
+ if (!mergedCells.size) {
29
+ return false;
30
+ }
31
+
32
+ return (Array.isArray(indexes) ? indexes : [indexes])
33
+ .map((index) => normalizeRect(index, map))
34
+ .filter((rect) => rect.left < rect.right && rect.top < rect.bottom)
35
+ .some((rect) => {
36
+ const n = (rect.right - rect.left) * (rect.bottom - rect.top);
37
+ const cells = map.cellsInRect(rect);
38
+ if (cells.length !== n) {
39
+ // We can quickly assume that if the amount of cells from the map is different to what the rect says
40
+ // then there is most likely merged cells across this area which is removing cells
41
+ return true;
42
+ }
43
+ return cells.some((nodePos) => mergedCells.has(nodePos));
44
+ });
45
+ };
46
+
47
+ export const hasMergedCellsInColumn = (columnIndexes: number | number[]) =>
48
+ hasMergedCells(columnIndexes, (index: number, map: TableMap) => {
49
+ const x = Math.max(Math.min(index, map.width - 1), 0); // clamped index
50
+ return {
51
+ left: x,
52
+ right: x === index ? x + 1 : x,
53
+ top: 0,
54
+ bottom: map.height,
55
+ };
56
+ });
57
+
58
+ export const hasMergedCellsInRow = (rowIndexes: number | number[]) =>
59
+ hasMergedCells(rowIndexes, (index: number, map: TableMap) => {
60
+ const y = Math.max(Math.min(index, map.height - 1), 0); // clamped index
61
+ return {
62
+ left: 0,
63
+ right: map.width,
64
+ top: y,
65
+ bottom: y === index ? y + 1 : y,
66
+ };
67
+ });
package/tsconfig.app.json CHANGED
@@ -75,6 +75,9 @@
75
75
  {
76
76
  "path": "../../pragmatic-drag-and-drop/hitbox/tsconfig.app.json"
77
77
  },
78
+ {
79
+ "path": "../../pragmatic-drag-and-drop/react-accessibility/tsconfig.app.json"
80
+ },
78
81
  {
79
82
  "path": "../../design-system/theme/tsconfig.app.json"
80
83
  },