@atlaskit/editor-plugin-table 5.3.8 → 5.3.10

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 (77) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/commands/hover.js +4 -2
  3. package/dist/cjs/plugins/table/event-handlers.js +7 -4
  4. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -1
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  7. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  8. package/dist/cjs/plugins/table/ui/DragHandle/index.js +6 -4
  9. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +16 -25
  10. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +70 -0
  11. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +12 -77
  12. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +45 -20
  13. package/dist/cjs/plugins/table/ui/icons/index.js +19 -0
  14. package/dist/cjs/plugins/table/ui/ui-styles.js +1 -1
  15. package/dist/es2019/plugins/table/commands/hover.js +4 -2
  16. package/dist/es2019/plugins/table/event-handlers.js +7 -4
  17. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
  18. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  19. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  20. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  21. package/dist/es2019/plugins/table/ui/DragHandle/index.js +5 -3
  22. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +14 -21
  23. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +62 -0
  24. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +8 -74
  25. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +45 -19
  26. package/dist/es2019/plugins/table/ui/icons/index.js +2 -0
  27. package/dist/es2019/plugins/table/ui/ui-styles.js +0 -1
  28. package/dist/esm/plugins/table/commands/hover.js +4 -2
  29. package/dist/esm/plugins/table/event-handlers.js +7 -4
  30. package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
  31. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  32. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  33. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  34. package/dist/esm/plugins/table/ui/DragHandle/index.js +5 -3
  35. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +15 -22
  36. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +61 -0
  37. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +9 -72
  38. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +45 -20
  39. package/dist/esm/plugins/table/ui/icons/index.js +2 -0
  40. package/dist/esm/plugins/table/ui/ui-styles.js +1 -1
  41. package/dist/types/plugins/table/commands/hover.d.ts +1 -1
  42. package/dist/types/plugins/table/types.d.ts +9 -4
  43. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +4 -3
  44. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
  45. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
  46. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +4 -2
  47. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -2
  48. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +2 -2
  49. package/dist/types/plugins/table/ui/icons/index.d.ts +2 -0
  50. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +1 -1
  51. package/dist/types-ts4.5/plugins/table/types.d.ts +9 -4
  52. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +4 -3
  53. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
  54. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
  55. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +4 -2
  56. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -2
  57. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +2 -2
  58. package/dist/types-ts4.5/plugins/table/ui/icons/index.d.ts +2 -0
  59. package/package.json +2 -1
  60. package/src/__tests__/unit/event-handlers.ts +4 -1
  61. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +58 -12
  62. package/src/plugins/table/commands/hover.ts +7 -2
  63. package/src/plugins/table/event-handlers.ts +18 -4
  64. package/src/plugins/table/nodeviews/TableComponent.tsx +2 -1
  65. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +1 -4
  66. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +7 -2
  67. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +5 -0
  68. package/src/plugins/table/types.ts +14 -4
  69. package/src/plugins/table/ui/DragHandle/index.tsx +3 -1
  70. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +36 -39
  71. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +74 -0
  72. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -80
  73. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +62 -32
  74. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +2 -2
  75. package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -2
  76. package/src/plugins/table/ui/icons/index.ts +2 -0
  77. package/src/plugins/table/ui/ui-styles.ts +0 -1
@@ -1,37 +1,26 @@
1
- import React, { useEffect, useMemo, useRef } from 'react';
1
+ import React from 'react';
2
2
 
3
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
- import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
5
- import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
6
-
7
- import type { DraggableSourceData } from '../../../types';
8
3
  import { TableCssClassName as ClassName } from '../../../types';
9
- import { getColumnsWidths, getRowHeights } from '../../../utils';
4
+
5
+ import { ColumnDropTarget } from './ColumnDropTarget';
10
6
 
11
7
  export interface Props {
12
- editorView: EditorView;
13
8
  tableRef: HTMLTableElement;
14
9
  stickyTop?: number;
15
10
  tableHeight?: number;
16
11
  localId?: string;
12
+ rowHeights?: number[];
13
+ colWidths?: (number | undefined)[];
17
14
  }
18
15
 
19
16
  export const ColumnDropTargets: React.FC<Props> = ({
20
- editorView,
21
17
  tableRef,
22
18
  tableHeight,
23
19
  stickyTop,
24
20
  localId,
21
+ rowHeights,
22
+ colWidths,
25
23
  }) => {
26
- const colWidths = getColumnsWidths(editorView);
27
- const rowHeights = useMemo(() => {
28
- // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
29
- if (tableRef && !!tableHeight) {
30
- return getRowHeights(tableRef);
31
- }
32
- return [0];
33
- }, [tableRef, tableHeight]);
34
-
35
24
  if (!tableRef) {
36
25
  return null;
37
26
  }
@@ -45,12 +34,15 @@ export const ColumnDropTargets: React.FC<Props> = ({
45
34
  hasHeaderRow && stickyTop !== undefined ? rowHeights?.[0] ?? 0 : 0;
46
35
 
47
36
  return (
48
- <div className={ClassName.COLUMN_DROP_TARGET_CONTROLS}>
37
+ <div
38
+ className={ClassName.COLUMN_DROP_TARGET_CONTROLS}
39
+ contentEditable={false}
40
+ >
49
41
  <div
50
42
  className={ClassName.COLUMN_CONTROLS_INNER}
51
43
  data-testid="table-floating-column-controls-drop-targets"
52
44
  >
53
- {colWidths.map((width, index) => {
45
+ {colWidths?.map((width, index) => {
54
46
  return (
55
47
  <ColumnDropTarget
56
48
  key={index}
@@ -66,63 +58,3 @@ export const ColumnDropTargets: React.FC<Props> = ({
66
58
  </div>
67
59
  );
68
60
  };
69
-
70
- export default ColumnDropTargets;
71
-
72
- const ColumnDropTarget: React.FC<{
73
- index: number;
74
- localId?: string;
75
- width?: number;
76
- height?: number;
77
- marginTop?: number;
78
- }> = ({ index, localId, width, height, marginTop }) => {
79
- const dropTargetRef = useRef<HTMLDivElement | null>(null);
80
-
81
- useEffect(() => {
82
- if (!dropTargetRef.current) {
83
- return;
84
- }
85
-
86
- return dropTargetForElements({
87
- element: dropTargetRef.current,
88
- canDrop({ source }) {
89
- const data = source.data as DraggableSourceData;
90
- return (
91
- // Only draggables of row type can be dropped on this target
92
- data.type === 'table-column' &&
93
- // Only draggables which came from the same table can be dropped on this target
94
- data.localId === localId &&
95
- // Only draggables which DO NOT include this drop targets index can be dropped
96
- !!data.indexes?.length &&
97
- data.indexes?.indexOf(index) === -1
98
- );
99
- },
100
- getData({ input, element }) {
101
- const data = {
102
- localId,
103
- type: 'table-column',
104
- targetIndex: index,
105
- };
106
- return attachClosestEdge(data, {
107
- input,
108
- element,
109
- allowedEdges: ['left', 'right'],
110
- });
111
- },
112
- });
113
- }, [index, localId]);
114
-
115
- return (
116
- <div
117
- ref={dropTargetRef}
118
- style={{
119
- width: width && `${width - 1}px`,
120
- height: height && `${height}px`,
121
- marginTop: marginTop && `${marginTop}px`,
122
- }}
123
- data-drop-target-index={index}
124
- data-drop-target-localid={localId}
125
- data-testid="table-floating-column-controls-drop-target"
126
- ></div>
127
- );
128
- };
@@ -4,13 +4,15 @@ import ReactDOM from 'react-dom';
4
4
 
5
5
  import type { TableColumnOrdering } from '@atlaskit/custom-steps';
6
6
  import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
7
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
7
8
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
8
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
- import { findTable } from '@atlaskit/editor-tables';
10
+ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
10
11
 
11
12
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
12
- import type { CellHoverCoordinates } from '../../types';
13
+ import type { CellHoverMeta, DraggableSourceData } from '../../types';
13
14
  import { TableCssClassName as ClassName } from '../../types';
15
+ import { getColumnsWidths, getRowHeights } from '../../utils';
14
16
 
15
17
  import { ColumnControls } from './ColumnControls';
16
18
  import { ColumnDropTargets } from './ColumnDropTargets';
@@ -20,11 +22,12 @@ export interface Props {
20
22
  getEditorFeatureFlags: GetEditorFeatureFlags;
21
23
  selection?: Selection;
22
24
  tableRef?: HTMLTableElement;
25
+ getNode: () => PmNode;
23
26
  tableActive?: boolean;
24
27
  hasHeaderRow?: boolean;
25
28
  headerRowHeight?: number;
26
29
  hoveredRows?: number[];
27
- hoveredCell?: CellHoverCoordinates;
30
+ hoveredCell?: CellHoverMeta;
28
31
  isResizing?: boolean;
29
32
  ordering?: TableColumnOrdering;
30
33
  stickyHeader?: RowStickyState;
@@ -33,6 +36,7 @@ export interface Props {
33
36
  export const TableFloatingColumnControls: React.FC<Props> = ({
34
37
  editorView,
35
38
  tableRef,
39
+ getNode,
36
40
  tableActive,
37
41
  hasHeaderRow,
38
42
  hoveredCell,
@@ -44,6 +48,10 @@ export const TableFloatingColumnControls: React.FC<Props> = ({
44
48
  { width: 0, height: 0 },
45
49
  );
46
50
 
51
+ const [hasDropTargets, setHasDropTargets] = useState(false);
52
+ const node = getNode();
53
+ const currentNodeLocalId = node?.attrs.localId;
54
+
47
55
  useEffect(() => {
48
56
  if (tableRef && window?.ResizeObserver) {
49
57
  const resizeObserver = new ResizeObserver((entries) => {
@@ -67,23 +75,40 @@ export const TableFloatingColumnControls: React.FC<Props> = ({
67
75
  }
68
76
  }, [tableRef]);
69
77
 
70
- const selectedLocalId = useMemo(() => {
71
- if (!selection) {
72
- return undefined;
73
- }
74
-
75
- const tableNode = findTable(selection);
76
- if (!tableNode) {
77
- return undefined;
78
+ useEffect(() => {
79
+ return monitorForElements({
80
+ canMonitor({ source }) {
81
+ const { type, localId, indexes } =
82
+ source.data as Partial<DraggableSourceData>;
83
+ return (
84
+ type === 'table-column' &&
85
+ !!indexes?.length &&
86
+ localId === currentNodeLocalId
87
+ );
88
+ },
89
+ onDragStart() {
90
+ setHasDropTargets(true);
91
+ },
92
+ onDrop() {
93
+ setHasDropTargets(false);
94
+ },
95
+ });
96
+ }, [editorView, currentNodeLocalId]);
97
+
98
+ const rowHeights = useMemo(() => {
99
+ // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
100
+ if (tableRef && !!tableRect.height) {
101
+ return getRowHeights(tableRef);
78
102
  }
79
-
80
- return tableNode.node.attrs.localId;
81
- }, [selection]);
103
+ return [0];
104
+ }, [tableRef, tableRect.height]);
82
105
 
83
106
  if (!tableRef) {
84
107
  return null;
85
108
  }
86
109
 
110
+ const colWidths = getColumnsWidths(editorView);
111
+
87
112
  const stickyTop =
88
113
  stickyHeader && stickyHeader.sticky && hasHeaderRow
89
114
  ? stickyHeader.top
@@ -92,29 +117,34 @@ export const TableFloatingColumnControls: React.FC<Props> = ({
92
117
  const mountTo = (tableRef && tableRef?.parentElement) || document.body;
93
118
 
94
119
  return ReactDOM.createPortal(
95
- <div className={ClassName.COLUMN_CONTROLS_WRAPPER}>
96
- <div
97
- onMouseDown={(e) => e.preventDefault()}
98
- data-testid="table-floating-column-controls-wrapper"
99
- >
100
- <ColumnControls
101
- editorView={editorView}
102
- hoveredCell={hoveredCell}
103
- tableRef={tableRef}
104
- isResizing={isResizing}
105
- tableActive={tableActive}
106
- stickyTop={tableActive ? stickyTop : undefined}
107
- tableHeight={tableRect.height}
108
- localId={selectedLocalId}
109
- />
120
+ <div
121
+ className={ClassName.COLUMN_CONTROLS_WRAPPER}
122
+ style={{
123
+ pointerEvents: 'none',
124
+ }}
125
+ data-testid="table-floating-column-controls-wrapper"
126
+ >
127
+ <ColumnControls
128
+ editorView={editorView}
129
+ hoveredCell={hoveredCell}
130
+ tableRef={tableRef}
131
+ isResizing={isResizing}
132
+ tableActive={tableActive}
133
+ stickyTop={tableActive ? stickyTop : undefined}
134
+ localId={currentNodeLocalId}
135
+ rowHeights={rowHeights}
136
+ colWidths={colWidths}
137
+ />
138
+ {hasDropTargets && (
110
139
  <ColumnDropTargets
111
- editorView={editorView}
112
140
  tableRef={tableRef}
113
141
  stickyTop={tableActive ? stickyTop : undefined}
114
142
  tableHeight={tableRect.height}
115
- localId={selectedLocalId}
143
+ localId={currentNodeLocalId}
144
+ rowHeights={rowHeights}
145
+ colWidths={colWidths}
116
146
  />
117
- </div>
147
+ )}
118
148
  </div>,
119
149
  mountTo,
120
150
  );
@@ -6,7 +6,7 @@ import type { WrappedComponentProps } from 'react-intl-next';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import { findTable } from '@atlaskit/editor-tables/utils';
8
8
 
9
- import type { CellHoverCoordinates } from '../../../types';
9
+ import type { CellHoverMeta } from '../../../types';
10
10
  import { TableCssClassName as ClassName } from '../../../types';
11
11
  import { getRowHeights } from '../../../utils';
12
12
  import { DragHandle } from '../../DragHandle';
@@ -15,7 +15,7 @@ type DragControlsProps = {
15
15
  editorView: EditorView;
16
16
  tableRef: HTMLTableElement;
17
17
  tableActive?: boolean;
18
- hoveredCell?: CellHoverCoordinates;
18
+ hoveredCell?: CellHoverMeta;
19
19
  hoverRows?: (rows: number[], danger?: boolean) => void;
20
20
  selectRow?: (row: number, expand: boolean) => void;
21
21
  };
@@ -7,7 +7,7 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
 
8
8
  import { hoverRows, selectRow } from '../../commands';
9
9
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
10
- import type { CellHoverCoordinates } from '../../types';
10
+ import type { CellHoverMeta } from '../../types';
11
11
  import { isSelectionUpdated } from '../../utils';
12
12
 
13
13
  import { CornerControls } from './CornerControls';
@@ -28,7 +28,7 @@ export interface Props {
28
28
  hasHeaderRow?: boolean;
29
29
  headerRowHeight?: number;
30
30
  hoveredRows?: number[];
31
- hoveredCell?: CellHoverCoordinates;
31
+ hoveredCell?: CellHoverMeta;
32
32
  ordering?: TableColumnOrdering;
33
33
  stickyHeader?: RowStickyState;
34
34
  }
@@ -0,0 +1,2 @@
1
+ export { DragHandleIcon } from './DragHandleIcon';
2
+ export { DragInMotionIcon } from './DragInMotionIcon';
@@ -381,7 +381,6 @@ export const floatingColumnControls = (props: ThemeProps) => {
381
381
  box-sizing: border-box;
382
382
  position: absolute;
383
383
  top: 0;
384
- z-index: -1;
385
384
 
386
385
  .${ClassName.COLUMN_CONTROLS_INNER} {
387
386
  display: flex;