@atlaskit/editor-plugin-table 7.5.15 → 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 (49) hide show
  1. package/CHANGELOG.md +16 -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/toolbar.js +58 -12
  8. package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +31 -6
  9. package/dist/cjs/ui/TableFloatingControls/RowDropTarget/index.js +31 -6
  10. package/dist/cjs/ui/TableFullWidthLabel/index.js +25 -0
  11. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +34 -1
  12. package/dist/es2019/pm-plugins/drag-and-drop/commands.js +15 -1
  13. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +9 -3
  14. package/dist/es2019/pm-plugins/drag-and-drop/utils/getDragBehaviour.js +8 -0
  15. package/dist/es2019/pm-plugins/drag-and-drop/utils/monitor.js +9 -4
  16. package/dist/es2019/toolbar.js +49 -0
  17. package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +27 -3
  18. package/dist/es2019/ui/TableFloatingControls/RowDropTarget/index.js +27 -3
  19. package/dist/es2019/ui/TableFullWidthLabel/index.js +19 -0
  20. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +36 -1
  21. package/dist/esm/pm-plugins/drag-and-drop/commands.js +17 -1
  22. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +9 -3
  23. package/dist/esm/pm-plugins/drag-and-drop/utils/getDragBehaviour.js +7 -0
  24. package/dist/esm/pm-plugins/drag-and-drop/utils/monitor.js +10 -4
  25. package/dist/esm/toolbar.js +58 -12
  26. package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +31 -6
  27. package/dist/esm/ui/TableFloatingControls/RowDropTarget/index.js +31 -6
  28. package/dist/esm/ui/TableFullWidthLabel/index.js +18 -0
  29. package/dist/types/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +1 -0
  30. package/dist/types/pm-plugins/drag-and-drop/commands.d.ts +1 -0
  31. package/dist/types/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +3 -0
  32. package/dist/types/types.d.ts +12 -1
  33. package/dist/types/ui/TableFullWidthLabel/index.d.ts +2 -0
  34. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +1 -0
  35. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands.d.ts +1 -0
  36. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +3 -0
  37. package/dist/types-ts4.5/types.d.ts +12 -1
  38. package/dist/types-ts4.5/ui/TableFullWidthLabel/index.d.ts +2 -0
  39. package/package.json +3 -3
  40. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +56 -1
  41. package/src/pm-plugins/drag-and-drop/commands.ts +31 -2
  42. package/src/pm-plugins/drag-and-drop/plugin.ts +21 -7
  43. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +12 -0
  44. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +17 -3
  45. package/src/toolbar.tsx +50 -0
  46. package/src/types.ts +13 -1
  47. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +39 -5
  48. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +40 -5
  49. package/src/ui/TableFullWidthLabel/index.tsx +24 -0
@@ -11,3 +11,4 @@ export declare const setDropTarget: (type: DropTargetType, index: number, hasMer
11
11
  export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
12
12
  export declare const moveSource: (sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
13
13
  export declare const toggleDragMenu: (isDragMenuOpen: boolean | undefined, direction?: TableDirection, index?: number, trigger?: TriggerType) => import("@atlaskit/editor-common/types").Command;
14
+ export declare const cloneSource: (sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, targetDirection: 'start' | 'end', tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
@@ -0,0 +1,3 @@
1
+ import type { Input } from '@atlaskit/pragmatic-drag-and-drop/types';
2
+ import type { DraggableBehaviour } from '../../../types';
3
+ export declare const getDragBehaviour: ({ altKey, ctrlKey, }: Input) => DraggableBehaviour;
@@ -435,6 +435,7 @@ export type TableDirection = 'row' | 'column';
435
435
  * Drag and Drop interfaces
436
436
  */
437
437
  export type DraggableType = 'table-row' | 'table-column';
438
+ export type DraggableBehaviour = 'move' | 'clone';
438
439
  export interface DraggableSourceData extends Record<string, unknown> {
439
440
  type: DraggableType;
440
441
  localId: string;
@@ -454,7 +455,17 @@ export interface DraggableData {
454
455
  targetIndex: number;
455
456
  targetAdjustedIndex: number;
456
457
  targetClosestEdge: Edge;
457
- direction: 1 | -1;
458
+ /**
459
+ * The target direction identifies where relative to the target index is the item being dropped. A value of 'start' would
460
+ * mean that the item is being inserted before the index, and 'end would be after.
461
+ */
462
+ targetDirection: 'start' | 'end';
463
+ /**
464
+ * This represents a hollistic movement direction; a value of 1 means the source->target index would shift in a positive direction.
465
+ * A value of 0 indicates that the target index is inside the the source indexes.
466
+ */
467
+ direction: 1 | -1 | 0;
468
+ behaviour: DraggableBehaviour;
458
469
  }
459
470
  export type HandleTypes = 'hover' | 'selected';
460
471
  export interface MessageDescriptor {
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const FullWidthDisplay: () => JSX.Element;
@@ -6,3 +6,4 @@ import type { DraggableData, DraggableType } from '../../types';
6
6
  export declare const clearDropTargetWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, sourceIndexes: number[] | undefined, status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID, tr?: Transaction) => Command;
7
7
  export declare const moveSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT, sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, tr?: Transaction) => Command;
8
8
  export declare const moveSourceWithAnalyticsViaShortcut: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (sourceType: DraggableType, direction: DraggableData['direction']) => Command;
9
+ export declare const cloneSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT, sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, targetDirection: 'start' | 'end', tr?: Transaction) => Command;
@@ -11,3 +11,4 @@ export declare const setDropTarget: (type: DropTargetType, index: number, hasMer
11
11
  export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
12
12
  export declare const moveSource: (sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
13
13
  export declare const toggleDragMenu: (isDragMenuOpen: boolean | undefined, direction?: TableDirection, index?: number, trigger?: TriggerType) => import("@atlaskit/editor-common/types").Command;
14
+ export declare const cloneSource: (sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, targetDirection: 'start' | 'end', tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
@@ -0,0 +1,3 @@
1
+ import type { Input } from '@atlaskit/pragmatic-drag-and-drop/types';
2
+ import type { DraggableBehaviour } from '../../../types';
3
+ export declare const getDragBehaviour: ({ altKey, ctrlKey, }: Input) => DraggableBehaviour;
@@ -435,6 +435,7 @@ export type TableDirection = 'row' | 'column';
435
435
  * Drag and Drop interfaces
436
436
  */
437
437
  export type DraggableType = 'table-row' | 'table-column';
438
+ export type DraggableBehaviour = 'move' | 'clone';
438
439
  export interface DraggableSourceData extends Record<string, unknown> {
439
440
  type: DraggableType;
440
441
  localId: string;
@@ -454,7 +455,17 @@ export interface DraggableData {
454
455
  targetIndex: number;
455
456
  targetAdjustedIndex: number;
456
457
  targetClosestEdge: Edge;
457
- direction: 1 | -1;
458
+ /**
459
+ * The target direction identifies where relative to the target index is the item being dropped. A value of 'start' would
460
+ * mean that the item is being inserted before the index, and 'end would be after.
461
+ */
462
+ targetDirection: 'start' | 'end';
463
+ /**
464
+ * This represents a hollistic movement direction; a value of 1 means the source->target index would shift in a positive direction.
465
+ * A value of 0 indicates that the target index is inside the the source indexes.
466
+ */
467
+ direction: 1 | -1 | 0;
468
+ behaviour: DraggableBehaviour;
458
469
  }
459
470
  export type HandleTypes = 'hover' | 'selected';
460
471
  export interface MessageDescriptor {
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const FullWidthDisplay: () => JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.5.15",
3
+ "version": "7.6.0",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/adf-schema": "^35.7.0",
32
32
  "@atlaskit/custom-steps": "^0.0.16",
33
- "@atlaskit/editor-common": "^78.18.0",
33
+ "@atlaskit/editor-common": "^78.20.0",
34
34
  "@atlaskit/editor-palette": "1.5.3",
35
35
  "@atlaskit/editor-plugin-analytics": "^1.0.0",
36
36
  "@atlaskit/editor-plugin-content-insertion": "^1.0.0",
@@ -39,7 +39,7 @@
39
39
  "@atlaskit/editor-plugin-width": "^1.0.0",
40
40
  "@atlaskit/editor-prosemirror": "3.0.0",
41
41
  "@atlaskit/editor-shared-styles": "^2.9.0",
42
- "@atlaskit/editor-tables": "^2.5.0",
42
+ "@atlaskit/editor-tables": "^2.6.0",
43
43
  "@atlaskit/icon": "^22.1.0",
44
44
  "@atlaskit/menu": "^2.1.5",
45
45
  "@atlaskit/platform-feature-flags": "^0.2.1",
@@ -26,7 +26,7 @@ import {
26
26
  import { withEditorAnalyticsAPI } from '../../utils/analytics';
27
27
  import { canMove, getTargetIndex } from '../../utils/drag-menu';
28
28
 
29
- import { clearDropTarget, moveSource } from './commands';
29
+ import { clearDropTarget, cloneSource, moveSource } from './commands';
30
30
 
31
31
  export const clearDropTargetWithAnalytics =
32
32
  (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
@@ -157,3 +157,58 @@ export const moveSourceWithAnalyticsViaShortcut =
157
157
  targetIndex,
158
158
  )(state, dispatch);
159
159
  };
160
+
161
+ export const cloneSourceWithAnalytics =
162
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
163
+ (
164
+ inputMethod:
165
+ | INPUT_METHOD.TABLE_CONTEXT_MENU
166
+ | INPUT_METHOD.DRAG_AND_DROP
167
+ | INPUT_METHOD.SHORTCUT,
168
+ sourceType: DraggableType,
169
+ sourceIndexes: number[],
170
+ targetIndex: number,
171
+ targetDirection: 'start' | 'end',
172
+ tr?: Transaction,
173
+ ) => {
174
+ return withEditorAnalyticsAPI(({ selection }: EditorState) => {
175
+ const direction = sourceIndexes[0] > targetIndex ? -1 : 1;
176
+ const { totalRowCount, totalColumnCount } =
177
+ getSelectedTableInfo(selection);
178
+ return {
179
+ action:
180
+ sourceType === 'table-row'
181
+ ? TABLE_ACTION.CLONED_ROW
182
+ : TABLE_ACTION.CLONED_COLUMN,
183
+ actionSubject: ACTION_SUBJECT.TABLE,
184
+ actionSubjectId: null,
185
+ attributes: {
186
+ inputMethod,
187
+ count: sourceIndexes.length,
188
+ // This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
189
+ // of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
190
+ distance:
191
+ Math.min(...sourceIndexes.map((v) => Math.abs(targetIndex - v))) *
192
+ direction,
193
+ // If a drop doesn't actually change anything then we're going to mark the event as cancelled.
194
+ status: sourceIndexes.includes(targetIndex)
195
+ ? TABLE_STATUS.CANCELLED
196
+ : TABLE_STATUS.SUCCESS,
197
+ totalRowCount,
198
+ totalColumnCount,
199
+ },
200
+ eventType: EVENT_TYPE.TRACK,
201
+ };
202
+ })(editorAnalyticsAPI)((state, dispatch) => {
203
+ if (dispatch) {
204
+ cloneSource(
205
+ sourceType,
206
+ sourceIndexes,
207
+ targetIndex,
208
+ targetDirection,
209
+ tr,
210
+ )(state, dispatch);
211
+ }
212
+ return true;
213
+ });
214
+ };
@@ -4,7 +4,12 @@ import type {
4
4
  } from '@atlaskit/editor-prosemirror/state';
5
5
  import type { Decoration } from '@atlaskit/editor-prosemirror/view';
6
6
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
- import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
7
+ import {
8
+ cloneColumn,
9
+ cloneRow,
10
+ moveColumn,
11
+ moveRow,
12
+ } from '@atlaskit/editor-tables/utils';
8
13
 
9
14
  import type { DraggableType, TableDirection } from '../../types';
10
15
  import { TableDecorations } from '../../types';
@@ -59,7 +64,6 @@ export const setDropTarget = (
59
64
  TableDecorations.ROW_INSERT_LINE,
60
65
  );
61
66
  }
62
-
63
67
  return {
64
68
  type: DragAndDropActionType.SET_DROP_TARGET,
65
69
  data: {
@@ -175,3 +179,28 @@ export const toggleDragMenu = (
175
179
  return tr.setMeta('addToHistory', false);
176
180
  },
177
181
  );
182
+
183
+ export const cloneSource = (
184
+ sourceType: DraggableType,
185
+ sourceIndexes: number[],
186
+ targetIndex: number,
187
+ targetDirection: 'start' | 'end',
188
+ tr?: Transaction,
189
+ ) =>
190
+ createCommand(
191
+ (state) => {
192
+ return {
193
+ type: DragAndDropActionType.CLEAR_DROP_TARGET,
194
+ data: {
195
+ decorationSet: DecorationSet.empty,
196
+ },
197
+ };
198
+ },
199
+ (originalTr: Transaction, state) => {
200
+ const nextTr = tr || originalTr;
201
+ const clone = sourceType === 'table-row' ? cloneRow : cloneColumn;
202
+ return clone(state, sourceIndexes, targetIndex, targetDirection, {
203
+ selectAfterClone: true,
204
+ })(nextTr);
205
+ },
206
+ );
@@ -26,6 +26,7 @@ import { DragAndDropActionType } from './actions';
26
26
  import { clearDropTarget, setDropTarget, toggleDragMenu } from './commands';
27
27
  import {
28
28
  clearDropTargetWithAnalytics,
29
+ cloneSourceWithAnalytics,
29
30
  moveSourceWithAnalytics,
30
31
  } from './commands-with-analytics';
31
32
  import { DropTargetType } from './consts';
@@ -172,7 +173,9 @@ const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
172
173
  sourceIndexes,
173
174
  targetIndex,
174
175
  targetAdjustedIndex,
176
+ targetDirection,
175
177
  direction,
178
+ behaviour,
176
179
  } = data;
177
180
 
178
181
  // When we drop on a target we will know the targets row/col index for certain,
@@ -203,13 +206,24 @@ const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
203
206
  }
204
207
 
205
208
  requestAnimationFrame(() => {
206
- moveSourceWithAnalytics(editorAnalyticsAPI)(
207
- INPUT_METHOD.DRAG_AND_DROP,
208
- sourceType,
209
- sourceIndexes,
210
- targetAdjustedIndex + (direction === -1 ? 0 : -1),
211
- tr,
212
- )(editorView.state, editorView.dispatch);
209
+ if (behaviour === 'clone') {
210
+ cloneSourceWithAnalytics(editorAnalyticsAPI)(
211
+ INPUT_METHOD.DRAG_AND_DROP,
212
+ sourceType,
213
+ sourceIndexes,
214
+ targetIndex,
215
+ targetDirection,
216
+ tr,
217
+ )(editorView.state, editorView.dispatch);
218
+ } else {
219
+ moveSourceWithAnalytics(editorAnalyticsAPI)(
220
+ INPUT_METHOD.DRAG_AND_DROP,
221
+ sourceType,
222
+ sourceIndexes,
223
+ targetAdjustedIndex + (direction === 1 ? -1 : 0),
224
+ tr,
225
+ )(editorView.state, editorView.dispatch);
226
+ }
213
227
 
214
228
  // force a colgroup update here, otherwise dropped columns don't have
215
229
  // the correct width immediately after the drop
@@ -0,0 +1,12 @@
1
+ import { browser } from '@atlaskit/editor-common/utils';
2
+ import type { Input } from '@atlaskit/pragmatic-drag-and-drop/types';
3
+
4
+ import type { DraggableBehaviour } from '../../../types';
5
+
6
+ export const getDragBehaviour = ({
7
+ altKey,
8
+ ctrlKey,
9
+ }: Input): DraggableBehaviour => {
10
+ const isCloneModifierKeyPressed = browser.mac ? altKey : ctrlKey;
11
+ return isCloneModifierKeyPressed ? 'clone' : 'move';
12
+ };
@@ -8,6 +8,8 @@ import type {
8
8
  DraggableTargetData,
9
9
  } from '../../../types';
10
10
 
11
+ import { getDragBehaviour } from './getDragBehaviour';
12
+
11
13
  export const getDraggableDataFromEvent = ({
12
14
  location,
13
15
  source,
@@ -54,9 +56,16 @@ export const getDraggableDataFromEvent = ({
54
56
  const targetOffset =
55
57
  targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
56
58
 
57
- // since only consecutive rows/cols can be moved we can assume that if the first index is greater then
58
- // the target index, the then the direction of the DnD is decreasing
59
- const direction = sourceIndexes[0] > targetIndex ? -1 : 1;
59
+ // if the min index is greater then the target index, the then the direction of the DnD is decreasing
60
+ // if the target is within the min/max index then we can assume that no direction exists so it will be 0.
61
+ const srcMin = Math.min(...sourceIndexes);
62
+ const srcMax = Math.max(...sourceIndexes);
63
+ const direction =
64
+ targetIndex >= srcMin && targetIndex <= srcMax
65
+ ? 0
66
+ : srcMin >= targetIndex
67
+ ? -1
68
+ : 1;
60
69
 
61
70
  return {
62
71
  sourceType,
@@ -67,6 +76,11 @@ export const getDraggableDataFromEvent = ({
67
76
  targetIndex,
68
77
  targetAdjustedIndex: targetIndex + targetOffset,
69
78
  targetClosestEdge,
79
+ targetDirection:
80
+ targetClosestEdge === 'top' || targetClosestEdge === 'left'
81
+ ? 'start'
82
+ : 'end',
70
83
  direction,
84
+ behaviour: getDragBehaviour(location.current.input),
71
85
  };
72
86
  };
package/src/toolbar.tsx CHANGED
@@ -90,6 +90,7 @@ import type {
90
90
  ToolbarMenuState,
91
91
  } from './types';
92
92
  import { TableCssClassName } from './types';
93
+ import { FullWidthDisplay } from './ui/TableFullWidthLabel';
93
94
  import {
94
95
  getMergedCellsPositions,
95
96
  getSelectedColumnIndexes,
@@ -452,6 +453,55 @@ export const getToolbarConfig =
452
453
  // We don't want to show floating toolbar while resizing the table
453
454
  const isWidthResizing = tableWidthState?.resizing;
454
455
 
456
+ const { isTableScalingEnabled, widthToWidest } = pluginState;
457
+
458
+ if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
459
+ const { stickyScrollbar } = getEditorFeatureFlags();
460
+
461
+ const nodeType = state.schema.nodes.table;
462
+ const getDomRef = (editorView: EditorView) => {
463
+ let element: HTMLElement | undefined;
464
+ const domAtPos = editorView.domAtPos.bind(editorView);
465
+ const parent = findParentDomRefOfType(
466
+ nodeType,
467
+ domAtPos,
468
+ )(state.selection);
469
+ if (parent) {
470
+ const tableRef =
471
+ (parent as HTMLElement).querySelector<HTMLTableElement>('table') ||
472
+ undefined;
473
+ if (tableRef) {
474
+ element =
475
+ closestElement(
476
+ tableRef,
477
+ `.${TableCssClassName.TABLE_NODE_WRAPPER}`,
478
+ ) || undefined;
479
+ }
480
+ }
481
+ return element;
482
+ };
483
+ const fullWidthLabel = {
484
+ id: 'editor.table.fullWidthLabel',
485
+ type: 'custom',
486
+ fallback: [],
487
+ render: () => {
488
+ return <FullWidthDisplay key={'full-width-label'} />;
489
+ },
490
+ } as FloatingToolbarItem<Command>;
491
+
492
+ return {
493
+ title: 'Table floating label',
494
+ getDomRef,
495
+ nodeType,
496
+ key: 'full-width-label',
497
+ offset: [0, 18],
498
+ absoluteOffset: stickyScrollbar ? { top: -6 } : { top: 0 },
499
+ zIndex: akEditorFloatingPanelZIndex + 1, // Place the context menu slightly above the others
500
+ items: [fullWidthLabel],
501
+ scrollable: true,
502
+ };
503
+ }
504
+
455
505
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
456
506
  const nodeType = state.schema.nodes.table;
457
507
  const menu = getToolbarMenuConfig(
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
  });
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+
3
+ import { useIntl } from 'react-intl-next';
4
+
5
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { Box, Inline, xcss } from '@atlaskit/primitives';
7
+ import { token } from '@atlaskit/tokens';
8
+
9
+ const tableFullWidthLabelStyles = xcss({
10
+ minWidth: '120px',
11
+ height: token('space.300', '24px'),
12
+ display: 'flex',
13
+ justifyContent: 'center',
14
+ alignItems: 'center',
15
+ });
16
+
17
+ export const FullWidthDisplay = () => {
18
+ const { formatMessage } = useIntl();
19
+ return (
20
+ <Box xcss={tableFullWidthLabelStyles}>
21
+ <Inline>{formatMessage(messages.fullWidthLabel)}</Inline>
22
+ </Box>
23
+ );
24
+ };