@atlaskit/editor-plugin-table 7.5.16 → 7.6.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 (39) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +36 -1
  3. package/dist/cjs/pm-plugins/drag-and-drop/commands.js +17 -1
  4. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +8 -2
  5. package/dist/cjs/pm-plugins/drag-and-drop/utils/getDragBehaviour.js +13 -0
  6. package/dist/cjs/pm-plugins/drag-and-drop/utils/monitor.js +11 -4
  7. package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +31 -6
  8. package/dist/cjs/ui/TableFloatingControls/RowDropTarget/index.js +31 -6
  9. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +34 -1
  10. package/dist/es2019/pm-plugins/drag-and-drop/commands.js +15 -1
  11. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +9 -3
  12. package/dist/es2019/pm-plugins/drag-and-drop/utils/getDragBehaviour.js +8 -0
  13. package/dist/es2019/pm-plugins/drag-and-drop/utils/monitor.js +9 -4
  14. package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +27 -3
  15. package/dist/es2019/ui/TableFloatingControls/RowDropTarget/index.js +27 -3
  16. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +36 -1
  17. package/dist/esm/pm-plugins/drag-and-drop/commands.js +17 -1
  18. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +9 -3
  19. package/dist/esm/pm-plugins/drag-and-drop/utils/getDragBehaviour.js +7 -0
  20. package/dist/esm/pm-plugins/drag-and-drop/utils/monitor.js +10 -4
  21. package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +31 -6
  22. package/dist/esm/ui/TableFloatingControls/RowDropTarget/index.js +31 -6
  23. package/dist/types/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +1 -0
  24. package/dist/types/pm-plugins/drag-and-drop/commands.d.ts +1 -0
  25. package/dist/types/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +3 -0
  26. package/dist/types/types.d.ts +12 -1
  27. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +1 -0
  28. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands.d.ts +1 -0
  29. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +3 -0
  30. package/dist/types-ts4.5/types.d.ts +12 -1
  31. package/package.json +3 -3
  32. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +56 -1
  33. package/src/pm-plugins/drag-and-drop/commands.ts +31 -2
  34. package/src/pm-plugins/drag-and-drop/plugin.ts +21 -7
  35. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +12 -0
  36. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +17 -3
  37. package/src/types.ts +13 -1
  38. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +39 -5
  39. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +40 -5
package/src/types.ts CHANGED
@@ -477,6 +477,8 @@ export type TableDirection = 'row' | 'column';
477
477
  * Drag and Drop interfaces
478
478
  */
479
479
  export type DraggableType = 'table-row' | 'table-column';
480
+ export type DraggableBehaviour = 'move' | 'clone';
481
+
480
482
  export interface DraggableSourceData extends Record<string, unknown> {
481
483
  type: DraggableType;
482
484
  localId: string;
@@ -498,7 +500,17 @@ export interface DraggableData {
498
500
  targetIndex: number;
499
501
  targetAdjustedIndex: number;
500
502
  targetClosestEdge: Edge;
501
- direction: 1 | -1;
503
+ /**
504
+ * The target direction identifies where relative to the target index is the item being dropped. A value of 'start' would
505
+ * mean that the item is being inserted before the index, and 'end would be after.
506
+ */
507
+ targetDirection: 'start' | 'end';
508
+ /**
509
+ * This represents a hollistic movement direction; a value of 1 means the source->target index would shift in a positive direction.
510
+ * A value of 0 indicates that the target index is inside the the source indexes.
511
+ */
512
+ direction: 1 | -1 | 0;
513
+ behaviour: DraggableBehaviour;
502
514
  }
503
515
 
504
516
  export type HandleTypes = 'hover' | 'selected';
@@ -1,8 +1,12 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
 
3
- import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
3
+ import {
4
+ attachClosestEdge,
5
+ type Edge,
6
+ } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
4
7
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
5
8
 
9
+ import { getDragBehaviour } from '../../../pm-plugins/drag-and-drop/utils/getDragBehaviour';
6
10
  import type { DraggableSourceData } from '../../../types';
7
11
 
8
12
  export interface Props {
@@ -29,8 +33,16 @@ export const ColumnDropTarget = ({
29
33
 
30
34
  return dropTargetForElements({
31
35
  element: dropTargetRef.current,
32
- canDrop({ source }) {
36
+ canDrop({ source, input }) {
33
37
  const data = source.data as DraggableSourceData;
38
+ const behaviour = getDragBehaviour(input);
39
+
40
+ // A move drop is limited too where it can go, however a clone can drop can go anywhere.
41
+ const isDropValid =
42
+ behaviour === 'move'
43
+ ? data.indexes?.indexOf(index) === -1
44
+ : behaviour === 'clone';
45
+
34
46
  return (
35
47
  // Only draggables of row type can be dropped on this target
36
48
  data.type === 'table-column' &&
@@ -38,20 +50,42 @@ export const ColumnDropTarget = ({
38
50
  data.localId === localId &&
39
51
  // Only draggables which DO NOT include this drop targets index can be dropped
40
52
  !!data.indexes?.length &&
41
- data.indexes?.indexOf(index) === -1
53
+ isDropValid
42
54
  );
43
55
  },
56
+ getDropEffect: ({ input }) =>
57
+ getDragBehaviour(input) === 'clone' ? 'copy' : 'move',
44
58
  getIsSticky: () => true,
45
- getData({ input, element }) {
59
+ getData({ source, input, element }) {
46
60
  const data = {
47
61
  localId,
48
62
  type: 'table-column',
49
63
  targetIndex: index,
50
64
  };
65
+ const srcData = source.data as DraggableSourceData;
66
+ const behaviour = getDragBehaviour(input);
67
+
68
+ // During a move op there's no point in allowing edges to be dropped on which result in no change/move to occur.
69
+ const allowedEdges: Edge[] =
70
+ behaviour === 'move'
71
+ ? srcData.indexes?.reduce(
72
+ (acc, v) => {
73
+ if (v - index === -1) {
74
+ acc.shift();
75
+ }
76
+ if (v - index === 1) {
77
+ acc.pop();
78
+ }
79
+ return acc;
80
+ },
81
+ ['left', 'right'],
82
+ )
83
+ : ['left', 'right'];
84
+
51
85
  return attachClosestEdge(data, {
52
86
  input,
53
87
  element,
54
- allowedEdges: ['left', 'right'],
88
+ allowedEdges,
55
89
  });
56
90
  },
57
91
  });
@@ -1,8 +1,12 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
 
3
- import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
3
+ import {
4
+ attachClosestEdge,
5
+ type Edge,
6
+ } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
4
7
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
5
8
 
9
+ import { getDragBehaviour } from '../../../pm-plugins/drag-and-drop/utils/getDragBehaviour';
6
10
  import type { DraggableSourceData } from '../../../types';
7
11
 
8
12
  export type RowDropTargetProps = {
@@ -21,8 +25,16 @@ const RowDropTarget = ({ index, localId, style }: RowDropTargetProps) => {
21
25
 
22
26
  return dropTargetForElements({
23
27
  element: dropTargetRef.current,
24
- canDrop({ source }) {
28
+ canDrop({ source, input }) {
25
29
  const data = source.data as DraggableSourceData;
30
+ const behaviour = getDragBehaviour(input);
31
+
32
+ // A move drop is limited too where it can go, however a clone can drop can go anywhere.
33
+ const isDropValid =
34
+ behaviour === 'move'
35
+ ? data.indexes?.indexOf(index) === -1
36
+ : behaviour === 'clone';
37
+
26
38
  return (
27
39
  // Only draggables of row type can be dropped on this target
28
40
  data.type === 'table-row' &&
@@ -30,20 +42,43 @@ const RowDropTarget = ({ index, localId, style }: RowDropTargetProps) => {
30
42
  data.localId === localId &&
31
43
  // Only draggables which DO NOT include this drop targets index can be dropped
32
44
  !!data.indexes?.length &&
33
- data.indexes?.indexOf(index) === -1
45
+ isDropValid
34
46
  );
35
47
  },
48
+ getDropEffect: ({ input }) =>
49
+ getDragBehaviour(input) === 'clone' ? 'copy' : 'move',
36
50
  getIsSticky: () => true,
37
- getData({ input, element }) {
51
+ getData({ source, input, element }) {
38
52
  const data = {
39
53
  localId,
40
54
  type: 'table-row',
41
55
  targetIndex: index,
42
56
  };
57
+
58
+ const srcData = source.data as DraggableSourceData;
59
+ const behaviour = getDragBehaviour(input);
60
+
61
+ // During a move op there's no point in allowing edges to be dropped on which result in no change/move to occur.
62
+ const allowedEdges: Edge[] =
63
+ behaviour === 'move'
64
+ ? srcData.indexes?.reduce(
65
+ (acc, v) => {
66
+ if (v - index === -1) {
67
+ acc.shift();
68
+ }
69
+ if (v - index === 1) {
70
+ acc.pop();
71
+ }
72
+ return acc;
73
+ },
74
+ ['top', 'bottom'],
75
+ )
76
+ : ['top', 'bottom'];
77
+
43
78
  return attachClosestEdge(data, {
44
79
  input,
45
80
  element,
46
- allowedEdges: ['top', 'bottom'],
81
+ allowedEdges,
47
82
  });
48
83
  },
49
84
  });