@atlaskit/editor-plugin-table 5.3.13 → 5.3.14

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 (95) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/plugins/table/event-handlers.js +6 -3
  3. package/dist/cjs/plugins/table/index.js +4 -3
  4. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +3 -7
  5. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -0
  7. package/dist/cjs/plugins/table/types.js +9 -2
  8. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +5 -3
  9. package/dist/cjs/plugins/table/ui/FloatingInsertButton/InsertButton.js +57 -9
  10. package/dist/cjs/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
  11. package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +13 -4
  12. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +44 -5
  13. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +6 -4
  14. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +35 -13
  15. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +2 -0
  16. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  17. package/dist/cjs/plugins/table/ui/ui-styles.js +27 -24
  18. package/dist/cjs/plugins/table/utils/dom.js +12 -4
  19. package/dist/cjs/plugins/table/utils/index.js +12 -0
  20. package/dist/es2019/plugins/table/event-handlers.js +5 -4
  21. package/dist/es2019/plugins/table/index.js +4 -3
  22. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +3 -7
  23. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  24. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +12 -0
  25. package/dist/es2019/plugins/table/types.js +9 -2
  26. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +5 -3
  27. package/dist/es2019/plugins/table/ui/FloatingInsertButton/InsertButton.js +58 -7
  28. package/dist/es2019/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
  29. package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +10 -4
  30. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +46 -6
  31. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
  32. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +35 -14
  33. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -0
  34. package/dist/es2019/plugins/table/ui/common-styles.js +51 -3
  35. package/dist/es2019/plugins/table/ui/ui-styles.js +23 -1
  36. package/dist/es2019/plugins/table/utils/dom.js +5 -1
  37. package/dist/es2019/plugins/table/utils/index.js +1 -1
  38. package/dist/esm/plugins/table/event-handlers.js +7 -4
  39. package/dist/esm/plugins/table/index.js +4 -3
  40. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +3 -7
  41. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  42. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -0
  43. package/dist/esm/plugins/table/types.js +9 -2
  44. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +5 -3
  45. package/dist/esm/plugins/table/ui/FloatingInsertButton/InsertButton.js +56 -8
  46. package/dist/esm/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
  47. package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +10 -4
  48. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +45 -6
  49. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
  50. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +36 -14
  51. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -0
  52. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  53. package/dist/esm/plugins/table/ui/ui-styles.js +26 -23
  54. package/dist/esm/plugins/table/utils/dom.js +11 -3
  55. package/dist/esm/plugins/table/utils/index.js +1 -1
  56. package/dist/types/plugins/table/types.d.ts +9 -2
  57. package/dist/types/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +5 -1
  58. package/dist/types/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +1 -1
  59. package/dist/types/plugins/table/ui/FloatingInsertButton/index.d.ts +1 -0
  60. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  61. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
  62. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  63. package/dist/types/plugins/table/utils/dom.d.ts +4 -1
  64. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  65. package/dist/types-ts4.5/plugins/table/types.d.ts +9 -2
  66. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +5 -1
  67. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +1 -1
  68. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +1 -0
  69. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  70. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
  71. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  72. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +4 -1
  73. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  74. package/package.json +2 -1
  75. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +40 -194
  76. package/src/__tests__/unit/ui/RowDragControls.tsx +9 -11
  77. package/src/plugins/table/event-handlers.ts +15 -3
  78. package/src/plugins/table/index.tsx +3 -2
  79. package/src/plugins/table/pm-plugins/decorations/plugin.ts +2 -9
  80. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +1 -3
  81. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +9 -0
  82. package/src/plugins/table/types.ts +12 -2
  83. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +10 -3
  84. package/src/plugins/table/ui/FloatingInsertButton/InsertButton.tsx +82 -8
  85. package/src/plugins/table/ui/FloatingInsertButton/getPopupOptions.ts +28 -5
  86. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +19 -7
  87. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +47 -3
  88. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +11 -4
  89. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +49 -18
  90. package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -0
  91. package/src/plugins/table/ui/common-styles.ts +57 -2
  92. package/src/plugins/table/ui/ui-styles.ts +27 -1
  93. package/src/plugins/table/utils/dom.ts +11 -4
  94. package/src/plugins/table/utils/index.ts +2 -0
  95. package/tsconfig.app.json +3 -0
@@ -9,12 +9,17 @@ import type { Selection } from '@atlaskit/editor-prosemirror/state';
9
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
10
10
  import { CellSelection } from '@atlaskit/editor-tables';
11
11
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
12
+ import { token } from '@atlaskit/tokens';
12
13
 
13
14
  import { clearHoverSelection } from '../../../commands';
14
15
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
15
16
  import type { CellHoverMeta } from '../../../types';
16
17
  import { TableCssClassName as ClassName } from '../../../types';
17
- import { getRowHeights, getSelectedRowIndexes } from '../../../utils';
18
+ import {
19
+ getRowHeights,
20
+ getRowsParams,
21
+ getSelectedRowIndexes,
22
+ } from '../../../utils';
18
23
  import { DragHandle } from '../../DragHandle';
19
24
 
20
25
  type DragControlsProps = {
@@ -24,6 +29,8 @@ type DragControlsProps = {
24
29
  tableActive?: boolean;
25
30
  hoveredCell?: CellHoverMeta;
26
31
  isInDanger?: boolean;
32
+ isResizing?: boolean;
33
+ hasHeaderRow?: boolean;
27
34
  hoverRows: (rows: number[], danger?: boolean) => void;
28
35
  selectRow: (row: number, expand: boolean) => void;
29
36
  updateCellHoverLocation: (rowIndex: number) => void;
@@ -47,11 +54,14 @@ const DragControlsComponent = ({
47
54
  tableActive,
48
55
  editorView,
49
56
  isInDanger,
57
+ isResizing,
58
+ hasHeaderRow,
50
59
  hoverRows,
51
60
  selectRow,
52
61
  updateCellHoverLocation,
53
62
  }: DragControlsProps & WrappedComponentProps) => {
54
63
  const rowHeights = getRowHeights(tableRef);
64
+ const rowsParams = getRowsParams(rowHeights);
55
65
  const heights = rowHeights.map((height) => `${height - 1}px`).join(' ');
56
66
  const selectedRowIndexes = getSelectedRows(editorView.state.selection);
57
67
  const rowWidth = tableRef.offsetWidth;
@@ -83,25 +93,21 @@ const DragControlsComponent = ({
83
93
 
84
94
  const handleMouseMove = useCallback(
85
95
  (e: MouseEvent) => {
86
- // avoid updating if event target is drag handle
87
- if (
88
- !(e.nativeEvent.target as Element).classList.contains(
89
- ClassName.ROW_CONTROLS_WITH_DRAG,
90
- )
91
- ) {
96
+ const isParentDragControls = (e.nativeEvent.target as Element).closest(
97
+ `.${ClassName.DRAG_ROW_CONTROLS}`,
98
+ );
99
+ const rowIndex = (e.nativeEvent.target as Element).getAttribute(
100
+ 'data-start-index',
101
+ );
102
+
103
+ // avoid updating if event target is not related
104
+ if (!isParentDragControls || !rowIndex) {
92
105
  return;
93
106
  }
94
107
 
95
- const hoverHeight = e.nativeEvent.offsetY;
96
- let totalHeight = 0;
97
- const rowIndex = rowHeights.findIndex((row) => {
98
- totalHeight += row;
99
- return hoverHeight <= totalHeight;
100
- });
101
-
102
- updateCellHoverLocation(rowIndex);
108
+ updateCellHoverLocation(Number(rowIndex));
103
109
  },
104
- [updateCellHoverLocation, rowHeights],
110
+ [updateCellHoverLocation],
105
111
  );
106
112
 
107
113
  const handleMouseOver = useCallback(() => {
@@ -117,13 +123,37 @@ const DragControlsComponent = ({
117
123
 
118
124
  return (
119
125
  <div
120
- className={ClassName.ROW_CONTROLS_WITH_DRAG}
126
+ className={ClassName.DRAG_ROW_CONTROLS}
121
127
  style={{
122
128
  gridTemplateRows: heights,
123
129
  }}
124
130
  onMouseMove={handleMouseMove}
125
131
  >
126
- {Number.isFinite(rowIndex) && (
132
+ {!isResizing &&
133
+ rowsParams.map(({ startIndex, endIndex }, index) => (
134
+ <div
135
+ style={{
136
+ gridRow: `${index + 1} / span 1`,
137
+ }}
138
+ data-start-index={startIndex}
139
+ data-end-index={endIndex}
140
+ className={ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER}
141
+ contentEditable={false}
142
+ key={index}
143
+ >
144
+ {!hasHeaderRow && index === 0 && (
145
+ <div
146
+ style={{
147
+ top: '0px',
148
+ left: token('space.075', '6px'),
149
+ }}
150
+ className={ClassName.DRAG_ROW_FLOATING_INSERT_DOT}
151
+ />
152
+ )}
153
+ <div className={ClassName.DRAG_ROW_FLOATING_INSERT_DOT} />
154
+ </div>
155
+ ))}
156
+ {!isResizing && Number.isFinite(rowIndex) && (
127
157
  <div
128
158
  style={{
129
159
  gridRow: gridRowPosition,
@@ -132,6 +162,7 @@ const DragControlsComponent = ({
132
162
  alignItems: 'center',
133
163
  justifyContent: 'center',
134
164
  }}
165
+ data-testid="table-floating-row-drag-handle"
135
166
  >
136
167
  <DragHandle
137
168
  tableLocalId={tableNode?.attrs?.localId ?? ''}
@@ -166,6 +166,8 @@ export default class TableFloatingControls extends Component<Props, State> {
166
166
  editorView={editorView}
167
167
  tableActive={tableActive}
168
168
  isInDanger={isInDanger}
169
+ isResizing={isResizing}
170
+ hasHeaderRow={hasHeaderRow}
169
171
  hoverRows={this.hoverRows}
170
172
  selectRow={this.selectRow}
171
173
  updateCellHoverLocation={this.updateCellHoverLocation}
@@ -56,6 +56,7 @@ import {
56
56
  columnControlsDecoration,
57
57
  columnControlsLineMarker,
58
58
  DeleteButton,
59
+ dragInsertButtonWrapper,
59
60
  floatingColumnControls,
60
61
  HeaderButton,
61
62
  HeaderButtonDanger,
@@ -357,6 +358,8 @@ export const tableStyles = (
357
358
  ${insertRowButtonWrapper(props)}
358
359
  }
359
360
 
361
+ ${dragInsertButtonWrapper(props)}
362
+
360
363
  /* Delete button */
361
364
  ${DeleteButton(props)}
362
365
  /* Ends Delete button */
@@ -700,12 +703,64 @@ export const tableStyles = (
700
703
  )}
701
704
  }
702
705
 
703
- .${ClassName.ROW_CONTROLS_WITH_DRAG} {
706
+ .${ClassName.DRAG_ROW_CONTROLS} {
704
707
  display: grid;
705
708
  align-items: center;
706
709
  position: absolute;
707
710
  left: -4px;
708
711
  z-index: ${akEditorUnitZIndex};
712
+
713
+ .${ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER} {
714
+ align-self: end;
715
+ position: absolute;
716
+ height: 100%;
717
+ width: 24px;
718
+ }
719
+
720
+ .${ClassName.DRAG_ROW_FLOATING_INSERT_DOT} {
721
+ position: absolute;
722
+ bottom: -3px;
723
+ left: 6px;
724
+ background-color: ${token(
725
+ 'color.background.accent.gray.subtler',
726
+ '#C1C7D0',
727
+ )};
728
+ height: 4px;
729
+ width: 4px;
730
+ border-radius: 50%;
731
+ }
732
+ }
733
+
734
+ .${ClassName.DRAG_COLUMN_CONTROLS} {
735
+ .${ClassName.COLUMN_CONTROLS_INNER} {
736
+ height: 24px;
737
+ position: absolute;
738
+ top: ${token('space.negative.150', '-12px')};
739
+ z-index: ${akEditorUnitZIndex};
740
+ }
741
+
742
+ .${ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER} {
743
+ position: absolute;
744
+ height: 24px;
745
+ width: 100%;
746
+ }
747
+
748
+ .${ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT} {
749
+ background-color: ${token(
750
+ 'color.background.accent.gray.subtler',
751
+ '#C1C7D0',
752
+ )};
753
+ height: 4px;
754
+ width: 4px;
755
+ border-radius: 50%;
756
+ position: absolute;
757
+ right: -2px;
758
+ }
759
+ }
760
+
761
+ .${ClassName.CONTROLS_FLOATING_BUTTON_ROW}
762
+ .${ClassName.DRAG_CONTROLS_INSERT_BUTTON_INNER} {
763
+ bottom: -1px;
709
764
  }
710
765
 
711
766
  .${ClassName.DRAG_HANDLE_BUTTON_CONTAINER} {
@@ -719,10 +774,10 @@ export const tableStyles = (
719
774
  display: flex;
720
775
  justify-content: center;
721
776
  align-items: center;
777
+ outline: none !important;
722
778
 
723
779
  svg {
724
780
  rect {
725
- //
726
781
  fill: ${token('color.background.accent.gray.subtlest', '#F1F2F4')};
727
782
  }
728
783
  g {
@@ -180,6 +180,32 @@ const InsertButtonHover = () => css`
180
180
  }
181
181
  `;
182
182
 
183
+ export const dragInsertButtonWrapper = (props: ThemeProps) => css`
184
+ .${ClassName.DRAG_CONTROLS_INSERT_BUTTON_INNER} {
185
+ position: absolute;
186
+ z-index: ${akEditorUnitZIndex + 10};
187
+ bottom: -5px;
188
+ left: 3px;
189
+ }
190
+ .${ClassName.DRAG_CONTROLS_INSERT_BUTTON} {
191
+ ${Button(`
192
+ background: ${token('elevation.surface.overlay', 'white')};
193
+ color: ${token('color.icon', N300)};
194
+ border: 1px solid ${token(
195
+ 'color.background.accent.gray.subtler',
196
+ '#C1C7D0',
197
+ )};
198
+ border-radius: 50%;
199
+ `)}
200
+ }
201
+ .${ClassName.DRAG_CONTROLS_INSERT_BUTTON}:hover {
202
+ background: ${token('color.background.brand.bold', B300)};
203
+ border: 1px solid ${token('color.background.brand.bold', B300)};
204
+ color: ${token('color.icon.inverse', 'white')};
205
+ cursor: pointer;
206
+ }
207
+ `;
208
+
183
209
  export const insertColumnButtonWrapper = (props: ThemeProps) => css`
184
210
  ${InsertButton()}
185
211
  ${InsertButtonHover()}
@@ -388,7 +414,7 @@ export const floatingColumnControls = (props: ThemeProps) => {
388
414
  }
389
415
  }
390
416
 
391
- .${ClassName.COLUMN_CONTROLS_WITH_DRAG} {
417
+ .${ClassName.DRAG_COLUMN_CONTROLS} {
392
418
  box-sizing: border-box;
393
419
 
394
420
  .${ClassName.COLUMN_CONTROLS_INNER} {
@@ -40,10 +40,6 @@ export const isRowControlsButton = (node: HTMLElement | null): boolean =>
40
40
  containsClassName(node, ClassName.ROW_CONTROLS_BUTTON) ||
41
41
  containsClassName(node, ClassName.NUMBERED_COLUMN_BUTTON);
42
42
 
43
- export const isRowDragControlsButton = (node: HTMLElement | null) =>
44
- containsClassName(node, ClassName.ROW_CONTROLS_WITH_DRAG) ||
45
- closestElement(node, `.${ClassName.ROW_CONTROLS_WITH_DRAG}`);
46
-
47
43
  export const isResizeHandleDecoration = (node: HTMLElement | null): boolean =>
48
44
  containsClassName(node, ClassName.RESIZE_HANDLE_DECORATION);
49
45
 
@@ -55,6 +51,17 @@ export const isTableContainerOrWrapper = (node: HTMLElement | null): boolean =>
55
51
  containsClassName(node, ClassName.TABLE_CONTAINER) ||
56
52
  containsClassName(node, ClassName.TABLE_NODE_WRAPPER);
57
53
 
54
+ /** drag-and-drop classes */
55
+ export const isRowDragControlsButton = (node: HTMLElement | null) =>
56
+ containsClassName(node, ClassName.DRAG_ROW_CONTROLS) ||
57
+ closestElement(node, `.${ClassName.DRAG_ROW_CONTROLS}`);
58
+
59
+ export const isDragRowFloatingInsertDot = (node: HTMLElement | null) =>
60
+ containsClassName(node, ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER);
61
+
62
+ export const isDragColumnFloatingInsertDot = (node: HTMLElement | null) =>
63
+ containsClassName(node, ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER);
64
+
58
65
  /*
59
66
  * This function returns which side of a given element the mouse cursor is,
60
67
  * using as a base the half of the width by default, for example:
@@ -48,6 +48,8 @@ export {
48
48
  isTableContainerOrWrapper,
49
49
  isRowDragControlsButton,
50
50
  isRowControlsButton,
51
+ isDragColumnFloatingInsertDot,
52
+ isDragRowFloatingInsertDot,
51
53
  getColumnOrRowIndex,
52
54
  getMousePositionHorizontalRelativeByElement,
53
55
  getMousePositionVerticalRelativeByElement,
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-beautiful-dnd-autoscroll/tsconfig.app.json"
80
+ },
78
81
  {
79
82
  "path": "../../design-system/primitives/tsconfig.app.json"
80
83
  },