@atlaskit/editor-plugin-table 5.2.2 → 5.3.1

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 (112) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +20 -2
  3. package/dist/cjs/plugins/table/nodeviews/table.js +1 -0
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/handlers.js +24 -0
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +29 -4
  7. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +83 -9
  8. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  9. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
  10. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
  11. package/dist/cjs/plugins/table/types.js +12 -1
  12. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +106 -0
  13. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +90 -0
  14. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  15. package/dist/cjs/plugins/table/ui/consts.js +2 -1
  16. package/dist/cjs/plugins/table/ui/ui-styles.js +15 -9
  17. package/dist/cjs/plugins/table/utils/decoration.js +67 -1
  18. package/dist/cjs/plugins/table/utils/index.js +26 -1
  19. package/dist/cjs/plugins/table/utils/merged-cells.js +66 -0
  20. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +20 -2
  21. package/dist/es2019/plugins/table/nodeviews/table.js +1 -0
  22. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -7
  23. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/handlers.js +10 -0
  24. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +28 -4
  25. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +82 -6
  26. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  27. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  28. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -0
  29. package/dist/es2019/plugins/table/types.js +12 -1
  30. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +101 -0
  31. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +60 -0
  32. package/dist/es2019/plugins/table/ui/common-styles.js +14 -1
  33. package/dist/es2019/plugins/table/ui/consts.js +1 -0
  34. package/dist/es2019/plugins/table/ui/ui-styles.js +127 -1
  35. package/dist/es2019/plugins/table/utils/decoration.js +62 -0
  36. package/dist/es2019/plugins/table/utils/index.js +3 -2
  37. package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
  38. package/dist/esm/plugins/table/nodeviews/TableComponent.js +20 -2
  39. package/dist/esm/plugins/table/nodeviews/table.js +1 -0
  40. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  41. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/handlers.js +18 -0
  42. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +28 -3
  43. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +82 -9
  44. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  45. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  46. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -0
  47. package/dist/esm/plugins/table/types.js +12 -1
  48. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +97 -0
  49. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +80 -0
  50. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  51. package/dist/esm/plugins/table/ui/consts.js +1 -0
  52. package/dist/esm/plugins/table/ui/ui-styles.js +15 -9
  53. package/dist/esm/plugins/table/utils/decoration.js +66 -0
  54. package/dist/esm/plugins/table/utils/index.js +3 -2
  55. package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
  56. package/dist/types/plugins/table/index.d.ts +1 -1
  57. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +1 -0
  58. package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  59. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  60. package/dist/types/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +3 -0
  61. package/dist/types/plugins/table/pm-plugins/drag-and-drop/plugin-factory.d.ts +1 -2
  62. package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +2 -0
  63. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  64. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  65. package/dist/types/plugins/table/types.d.ts +23 -1
  66. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +11 -0
  67. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +20 -0
  68. package/dist/types/plugins/table/ui/consts.d.ts +1 -0
  69. package/dist/types/plugins/table/ui/ui-styles.d.ts +2 -0
  70. package/dist/types/plugins/table/utils/decoration.d.ts +2 -0
  71. package/dist/types/plugins/table/utils/index.d.ts +2 -1
  72. package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
  73. package/dist/types-ts4.5/plugins/table/index.d.ts +1 -1
  74. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +1 -0
  75. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  76. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  77. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +3 -0
  78. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/plugin-factory.d.ts +1 -2
  79. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +2 -0
  80. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  81. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  82. package/dist/types-ts4.5/plugins/table/types.d.ts +23 -1
  83. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +11 -0
  84. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +20 -0
  85. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
  86. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +2 -0
  87. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -0
  88. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +2 -1
  89. package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
  90. package/package.json +4 -1
  91. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +139 -0
  92. package/src/plugins/table/index.tsx +1 -1
  93. package/src/plugins/table/nodeviews/TableComponent.tsx +25 -0
  94. package/src/plugins/table/nodeviews/table.tsx +1 -0
  95. package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +6 -1
  96. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
  97. package/src/plugins/table/pm-plugins/drag-and-drop/handlers.ts +35 -0
  98. package/src/plugins/table/pm-plugins/drag-and-drop/plugin-factory.ts +27 -2
  99. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +88 -6
  100. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
  101. package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +3 -0
  102. package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
  103. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -0
  104. package/src/plugins/table/types.ts +28 -1
  105. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +128 -0
  106. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +101 -0
  107. package/src/plugins/table/ui/common-styles.ts +15 -0
  108. package/src/plugins/table/ui/consts.ts +1 -0
  109. package/src/plugins/table/ui/ui-styles.ts +129 -0
  110. package/src/plugins/table/utils/decoration.ts +101 -0
  111. package/src/plugins/table/utils/index.ts +3 -0
  112. package/src/plugins/table/utils/merged-cells.ts +67 -0
@@ -7,6 +7,7 @@ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
7
7
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
8
8
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
9
9
  import type { Rect } from '@atlaskit/editor-tables/table-map';
10
+ import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
10
11
  import type tablePlugin from './index';
11
12
  export declare const RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
12
13
  export type RowInsertPosition = 'TOP' | 'BOTTOM';
@@ -225,16 +226,22 @@ export declare enum TableDecorations {
225
226
  TABLE_CONTROLS_HOVER = "TABLE_CONTROLS_HOVER",
226
227
  CELL_CONTROLS_HOVER = "CELL_CONTROLS_HOVER",
227
228
  COLUMN_CONTROLS_DECORATIONS = "COLUMN_CONTROLS_DECORATIONS",
229
+ COLUMN_DROP_TARGET_DECORATIONS = "COLUMN_DROP_TARGET_DECORATIONS",
228
230
  COLUMN_SELECTED = "COLUMN_SELECTED",
229
231
  COLUMN_RESIZING_HANDLE = "COLUMN_RESIZING_HANDLE",
230
232
  COLUMN_RESIZING_HANDLE_WIDGET = "COLUMN_RESIZING_HANDLE_WIDGET",
231
233
  COLUMN_RESIZING_HANDLE_LINE = "COLUMN_RESIZING_HANDLE_LINE",
234
+ COLUMN_INSERT_LINE = "COLUMN_INSERT_LINE",
235
+ ROW_INSERT_LINE = "ROW_INSERT_LINE",
232
236
  LAST_CELL_ELEMENT = "LAST_CELL_ELEMENT"
233
237
  }
234
238
  export declare const TableCssClassName: {
235
239
  COLUMN_CONTROLS: string;
236
240
  COLUMN_CONTROLS_DECORATIONS: string;
237
241
  COLUMN_SELECTED: string;
242
+ COLUMN_CONTROLS_WRAPPER: string;
243
+ COLUMN_DROP_TARGET_CONTROLS: string;
244
+ COLUMN_CONTROLS_INNER: string;
238
245
  ROW_CONTROLS_WRAPPER: string;
239
246
  ROW_CONTROLS: string;
240
247
  ROW_CONTROLS_INNER: string;
@@ -288,8 +295,13 @@ export declare const TableCssClassName: {
288
295
  TABLE_STICKY: string;
289
296
  TOP_LEFT_CELL: string;
290
297
  LAST_ITEM_IN_CELL: string;
298
+ WITH_COLUMN_INSERT_LINE: string;
299
+ WITH_FIRST_COLUMN_INSERT_LINE: string;
300
+ WITH_LAST_COLUMN_INSERT_LINE: string;
291
301
  WITH_RESIZE_LINE: string;
292
302
  WITH_RESIZE_LINE_LAST_COLUMN: string;
303
+ WITH_ROW_INSERT_LINE: string;
304
+ WITH_LAST_ROW_INSERT_LINE: string;
293
305
  TABLE_CONTAINER: string;
294
306
  TABLE_NODE_WRAPPER: string;
295
307
  TABLE_LEFT_SHADOW: string;
@@ -350,8 +362,18 @@ export interface DraggableSourceData extends Record<string, unknown> {
350
362
  localId: string;
351
363
  indexes: number[];
352
364
  }
353
- export interface DraggableTargetData extends Record<string, unknown> {
365
+ export interface DraggableTargetData extends Record<string | symbol, unknown> {
354
366
  type: DraggableType;
355
367
  localId: string;
356
368
  targetIndex: number;
357
369
  }
370
+ export interface DraggableData {
371
+ sourceType: DraggableType;
372
+ sourceLocalId: string;
373
+ sourceIndexes: number[];
374
+ targetType: DraggableType;
375
+ targetLocalId: string;
376
+ targetIndex: number;
377
+ targetAdjustedIndex: number;
378
+ targetClosestEdge: Edge;
379
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ export interface Props {
4
+ editorView: EditorView;
5
+ tableRef: HTMLTableElement;
6
+ stickyTop?: number;
7
+ tableHeight?: number;
8
+ localId?: string;
9
+ }
10
+ export declare const ColumnDropTargets: React.FC<Props>;
11
+ export default ColumnDropTargets;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import type { TableColumnOrdering } from '@atlaskit/custom-steps';
3
+ import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
4
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
5
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import type { RowStickyState } from '../../pm-plugins/sticky-headers';
7
+ export interface Props {
8
+ editorView: EditorView;
9
+ getEditorFeatureFlags: GetEditorFeatureFlags;
10
+ selection?: Selection;
11
+ tableRef?: HTMLTableElement;
12
+ tableActive?: boolean;
13
+ hasHeaderRow?: boolean;
14
+ headerRowHeight?: number;
15
+ hoveredRows?: number[];
16
+ ordering?: TableColumnOrdering;
17
+ stickyHeader?: RowStickyState;
18
+ }
19
+ export declare const TableFloatingColumnControls: React.FC<Props>;
20
+ export default TableFloatingColumnControls;
@@ -34,6 +34,7 @@ export declare const columnControlsDecorationHeight = 25;
34
34
  export declare const columnControlsZIndex: number;
35
35
  export declare const columnControlsSelectedZIndex: number;
36
36
  export declare const columnResizeHandleZIndex: number;
37
+ export declare const insertLineWidth = 3;
37
38
  export declare const resizeHandlerAreaWidth: number;
38
39
  export declare const resizeLineWidth = 2;
39
40
  export declare const resizeHandlerZIndex: number;
@@ -8,8 +8,10 @@ export declare const insertRowButtonWrapper: (props: ThemeProps) => import("@emo
8
8
  export declare const columnControlsLineMarker: () => import("@emotion/react").SerializedStyles;
9
9
  export declare const DeleteButton: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
10
10
  export declare const OverflowShadow: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
11
+ export declare const floatingColumnControls: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
11
12
  export declare const columnControlsDecoration: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
12
13
  export declare const hoveredDeleteButton: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
13
14
  export declare const hoveredCell: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
14
15
  export declare const hoveredWarningCell: import("@emotion/react").SerializedStyles;
15
16
  export declare const resizeHandle: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
17
+ export declare const insertLine: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
@@ -14,3 +14,5 @@ export declare const createColumnControlsDecoration: (selection: Selection) => D
14
14
  export declare const updateDecorations: (node: PmNode, decorationSet: DecorationSet, decorations: Decoration[], key: TableDecorations) => DecorationSet;
15
15
  export declare const createResizeHandleDecoration: (tr: Transaction | ReadonlyTransaction, rowIndexTarget: number, columnEndIndexTarget: Omit<CellColumnPositioning, 'left'>, includeTooltip: boolean | undefined, getIntl: () => IntlShape) => [Decoration[], Decoration[]];
16
16
  export declare const createColumnLineResize: (selection: Selection, cellColumnPositioning: Omit<CellColumnPositioning, 'left'>) => Decoration[];
17
+ export declare const createColumnInsertLine: (columnIndex: number, selection: Selection) => Decoration[];
18
+ export declare const createRowInsertLine: (rowIndex: number, selection: Selection) => Decoration[];
@@ -1,5 +1,5 @@
1
1
  export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, isSelectionUpdated, } from './selection';
2
- export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnLineResize, } from './decoration';
2
+ export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnInsertLine, createColumnLineResize, createRowInsertLine, } from './decoration';
3
3
  export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow, } from './nodes';
4
4
  export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell, } from './paste';
5
5
  export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler, } from './dom';
@@ -9,3 +9,4 @@ export type { RowParams } from './row-controls';
9
9
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
10
10
  export { getMergedCellsPositions } from './table';
11
11
  export { updatePluginStateDecorations } from './update-plugin-state-decorations';
12
+ export { hasMergedCellsInColumn, hasMergedCellsInRow } from './merged-cells';
@@ -0,0 +1,3 @@
1
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const hasMergedCellsInColumn: (columnIndexes: number | number[]) => (selection: Selection) => boolean;
3
+ export declare const hasMergedCellsInRow: (rowIndexes: number | number[]) => (selection: Selection) => boolean;
@@ -6,7 +6,7 @@ import type { GuidelinePlugin } from '@atlaskit/editor-plugin-guideline';
6
6
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
7
7
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
8
8
  import type { PluginConfig } from './types';
9
- interface TablePluginOptions {
9
+ export interface TablePluginOptions {
10
10
  tableOptions: PluginConfig;
11
11
  tableResizingEnabled?: boolean;
12
12
  dragAndDropEnabled?: boolean;
@@ -21,6 +21,7 @@ export interface ComponentProps {
21
21
  isHeaderRowEnabled: boolean;
22
22
  isHeaderColumnEnabled: boolean;
23
23
  isMediaFullscreen?: boolean;
24
+ isDragAndDropEnabled?: boolean;
24
25
  tableActive: boolean;
25
26
  ordering: TableColumnOrdering;
26
27
  isResizing?: boolean;
@@ -1,3 +1,4 @@
1
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
1
2
  import type { DropTargetType } from './consts';
2
3
  export interface DragAndDropAction<T, D> {
3
4
  type: T;
@@ -10,6 +11,9 @@ export declare const DragAndDropActionType: {
10
11
  export type DragAndDropSetDropTargetAction = DragAndDropAction<typeof DragAndDropActionType.SET_DROP_TARGET, {
11
12
  type: DropTargetType;
12
13
  index: number;
14
+ decorationSet: DecorationSet;
15
+ }>;
16
+ export type DragAndDropClearDropTargetAction = DragAndDropAction<typeof DragAndDropActionType.CLEAR_DROP_TARGET, {
17
+ decorationSet: DecorationSet;
13
18
  }>;
14
- export type DragAndDropClearDropTargetAction = DragAndDropAction<typeof DragAndDropActionType.CLEAR_DROP_TARGET, undefined>;
15
19
  export type DragAndDropPluginAction = DragAndDropSetDropTargetAction | DragAndDropClearDropTargetAction;
@@ -1,4 +1,9 @@
1
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { Decoration } from '@atlaskit/editor-prosemirror/view';
3
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { TableDecorations } from '../../types';
2
5
  import type { DropTargetType } from './consts';
6
+ export declare const getDecorations: (state: EditorState) => DecorationSet;
7
+ export declare const updatePluginStateDecorations: (state: EditorState, decorations: Decoration[], key: TableDecorations) => DecorationSet;
3
8
  export declare const setDropTarget: (type: DropTargetType, index: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
4
9
  export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
@@ -0,0 +1,3 @@
1
+ import type { ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { DragAndDropPluginState } from './types';
3
+ export declare const handleDocOrSelectionChanged: (tr: Transaction | ReadonlyTransaction, pluginState: DragAndDropPluginState) => DragAndDropPluginState;
@@ -1,2 +1 @@
1
- declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: import("./types").DragAndDropPluginState | ((state: import("prosemirror-state").EditorState) => import("./types").DragAndDropPluginState)) => import("prosemirror-state").SafeStateField<import("./types").DragAndDropPluginState>, createCommand: <A = import("./actions").DragAndDropPluginAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
2
- export { createPluginState, createCommand };
1
+ export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: import("./types").DragAndDropPluginState | ((state: import("prosemirror-state").EditorState) => import("./types").DragAndDropPluginState)) => import("prosemirror-state").SafeStateField<import("./types").DragAndDropPluginState>, createCommand: <A = import("./actions").DragAndDropPluginAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command, getPluginState: (state: import("prosemirror-state").EditorState) => import("./types").DragAndDropPluginState;
@@ -1,5 +1,7 @@
1
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
1
2
  import type { DropTargetType } from './consts';
2
3
  export interface DragAndDropPluginState {
4
+ decorationSet: DecorationSet;
3
5
  dropTargetType: DropTargetType;
4
6
  dropTargetIndex: number;
5
7
  }
@@ -0,0 +1 @@
1
+ export { getDraggableDataFromEvent } from './monitor';
@@ -0,0 +1,3 @@
1
+ import type { ElementEventBasePayload } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
2
+ import type { DraggableData } from '../../../types';
3
+ export declare const getDraggableDataFromEvent: ({ location, source, }: ElementEventBasePayload) => DraggableData | undefined;
@@ -7,6 +7,7 @@ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
7
7
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
8
8
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
9
9
  import type { Rect } from '@atlaskit/editor-tables/table-map';
10
+ import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
10
11
  import type tablePlugin from './index';
11
12
  export declare const RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
12
13
  export type RowInsertPosition = 'TOP' | 'BOTTOM';
@@ -225,16 +226,22 @@ export declare enum TableDecorations {
225
226
  TABLE_CONTROLS_HOVER = "TABLE_CONTROLS_HOVER",
226
227
  CELL_CONTROLS_HOVER = "CELL_CONTROLS_HOVER",
227
228
  COLUMN_CONTROLS_DECORATIONS = "COLUMN_CONTROLS_DECORATIONS",
229
+ COLUMN_DROP_TARGET_DECORATIONS = "COLUMN_DROP_TARGET_DECORATIONS",
228
230
  COLUMN_SELECTED = "COLUMN_SELECTED",
229
231
  COLUMN_RESIZING_HANDLE = "COLUMN_RESIZING_HANDLE",
230
232
  COLUMN_RESIZING_HANDLE_WIDGET = "COLUMN_RESIZING_HANDLE_WIDGET",
231
233
  COLUMN_RESIZING_HANDLE_LINE = "COLUMN_RESIZING_HANDLE_LINE",
234
+ COLUMN_INSERT_LINE = "COLUMN_INSERT_LINE",
235
+ ROW_INSERT_LINE = "ROW_INSERT_LINE",
232
236
  LAST_CELL_ELEMENT = "LAST_CELL_ELEMENT"
233
237
  }
234
238
  export declare const TableCssClassName: {
235
239
  COLUMN_CONTROLS: string;
236
240
  COLUMN_CONTROLS_DECORATIONS: string;
237
241
  COLUMN_SELECTED: string;
242
+ COLUMN_CONTROLS_WRAPPER: string;
243
+ COLUMN_DROP_TARGET_CONTROLS: string;
244
+ COLUMN_CONTROLS_INNER: string;
238
245
  ROW_CONTROLS_WRAPPER: string;
239
246
  ROW_CONTROLS: string;
240
247
  ROW_CONTROLS_INNER: string;
@@ -288,8 +295,13 @@ export declare const TableCssClassName: {
288
295
  TABLE_STICKY: string;
289
296
  TOP_LEFT_CELL: string;
290
297
  LAST_ITEM_IN_CELL: string;
298
+ WITH_COLUMN_INSERT_LINE: string;
299
+ WITH_FIRST_COLUMN_INSERT_LINE: string;
300
+ WITH_LAST_COLUMN_INSERT_LINE: string;
291
301
  WITH_RESIZE_LINE: string;
292
302
  WITH_RESIZE_LINE_LAST_COLUMN: string;
303
+ WITH_ROW_INSERT_LINE: string;
304
+ WITH_LAST_ROW_INSERT_LINE: string;
293
305
  TABLE_CONTAINER: string;
294
306
  TABLE_NODE_WRAPPER: string;
295
307
  TABLE_LEFT_SHADOW: string;
@@ -350,8 +362,18 @@ export interface DraggableSourceData extends Record<string, unknown> {
350
362
  localId: string;
351
363
  indexes: number[];
352
364
  }
353
- export interface DraggableTargetData extends Record<string, unknown> {
365
+ export interface DraggableTargetData extends Record<string | symbol, unknown> {
354
366
  type: DraggableType;
355
367
  localId: string;
356
368
  targetIndex: number;
357
369
  }
370
+ export interface DraggableData {
371
+ sourceType: DraggableType;
372
+ sourceLocalId: string;
373
+ sourceIndexes: number[];
374
+ targetType: DraggableType;
375
+ targetLocalId: string;
376
+ targetIndex: number;
377
+ targetAdjustedIndex: number;
378
+ targetClosestEdge: Edge;
379
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ export interface Props {
4
+ editorView: EditorView;
5
+ tableRef: HTMLTableElement;
6
+ stickyTop?: number;
7
+ tableHeight?: number;
8
+ localId?: string;
9
+ }
10
+ export declare const ColumnDropTargets: React.FC<Props>;
11
+ export default ColumnDropTargets;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import type { TableColumnOrdering } from '@atlaskit/custom-steps';
3
+ import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
4
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
5
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import type { RowStickyState } from '../../pm-plugins/sticky-headers';
7
+ export interface Props {
8
+ editorView: EditorView;
9
+ getEditorFeatureFlags: GetEditorFeatureFlags;
10
+ selection?: Selection;
11
+ tableRef?: HTMLTableElement;
12
+ tableActive?: boolean;
13
+ hasHeaderRow?: boolean;
14
+ headerRowHeight?: number;
15
+ hoveredRows?: number[];
16
+ ordering?: TableColumnOrdering;
17
+ stickyHeader?: RowStickyState;
18
+ }
19
+ export declare const TableFloatingColumnControls: React.FC<Props>;
20
+ export default TableFloatingColumnControls;
@@ -34,6 +34,7 @@ export declare const columnControlsDecorationHeight = 25;
34
34
  export declare const columnControlsZIndex: number;
35
35
  export declare const columnControlsSelectedZIndex: number;
36
36
  export declare const columnResizeHandleZIndex: number;
37
+ export declare const insertLineWidth = 3;
37
38
  export declare const resizeHandlerAreaWidth: number;
38
39
  export declare const resizeLineWidth = 2;
39
40
  export declare const resizeHandlerZIndex: number;
@@ -8,8 +8,10 @@ export declare const insertRowButtonWrapper: (props: ThemeProps) => import("@emo
8
8
  export declare const columnControlsLineMarker: () => import("@emotion/react").SerializedStyles;
9
9
  export declare const DeleteButton: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
10
10
  export declare const OverflowShadow: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
11
+ export declare const floatingColumnControls: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
11
12
  export declare const columnControlsDecoration: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
12
13
  export declare const hoveredDeleteButton: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
13
14
  export declare const hoveredCell: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
14
15
  export declare const hoveredWarningCell: import("@emotion/react").SerializedStyles;
15
16
  export declare const resizeHandle: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
17
+ export declare const insertLine: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
@@ -17,3 +17,5 @@ export declare const createResizeHandleDecoration: (tr: Transaction | ReadonlyTr
17
17
  Decoration[]
18
18
  ];
19
19
  export declare const createColumnLineResize: (selection: Selection, cellColumnPositioning: Omit<CellColumnPositioning, 'left'>) => Decoration[];
20
+ export declare const createColumnInsertLine: (columnIndex: number, selection: Selection) => Decoration[];
21
+ export declare const createRowInsertLine: (rowIndex: number, selection: Selection) => Decoration[];
@@ -1,5 +1,5 @@
1
1
  export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, isSelectionUpdated, } from './selection';
2
- export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnLineResize, } from './decoration';
2
+ export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnInsertLine, createColumnLineResize, createRowInsertLine, } from './decoration';
3
3
  export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow, } from './nodes';
4
4
  export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell, } from './paste';
5
5
  export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler, } from './dom';
@@ -9,3 +9,4 @@ export type { RowParams } from './row-controls';
9
9
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
10
10
  export { getMergedCellsPositions } from './table';
11
11
  export { updatePluginStateDecorations } from './update-plugin-state-decorations';
12
+ export { hasMergedCellsInColumn, hasMergedCellsInRow } from './merged-cells';
@@ -0,0 +1,3 @@
1
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const hasMergedCellsInColumn: (columnIndexes: number | number[]) => (selection: Selection) => boolean;
3
+ export declare const hasMergedCellsInRow: (rowIndexes: number | number[]) => (selection: Selection) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.2.2",
3
+ "version": "5.3.1",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -106,6 +106,9 @@
106
106
  "platform.editor.custom-table-width": {
107
107
  "type": "boolean"
108
108
  },
109
+ "platform.editor.table.drag-and-drop": {
110
+ "type": "boolean"
111
+ },
109
112
  "platform.editor.table-sticky-scrollbar": {
110
113
  "type": "boolean"
111
114
  },
@@ -0,0 +1,139 @@
1
+ import React from 'react';
2
+
3
+ import { render, screen } from '@testing-library/react';
4
+ import { IntlProvider } from 'react-intl-next';
5
+
6
+ import type { DocBuilder } from '@atlaskit/editor-common/types';
7
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
8
+ import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
9
+ import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
10
+ import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
11
+ import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
12
+ import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
13
+ import { widthPlugin } from '@atlaskit/editor-plugin-width';
14
+ import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
15
+ import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
16
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
17
+ import {
18
+ createProsemirrorEditorFactory,
19
+ Preset,
20
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
21
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
22
+ import {
23
+ doc,
24
+ p,
25
+ table,
26
+ tdEmpty,
27
+ tr,
28
+ } from '@atlaskit/editor-test-helpers/doc-builder';
29
+
30
+ import tablePlugin from '../../../plugins/table-plugin';
31
+ import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
32
+ import type { TablePluginState } from '../../../plugins/table/types';
33
+ import TableFloatingColumnControls from '../../../plugins/table/ui/TableFloatingColumnControls';
34
+
35
+ describe('TableFloatingColumnControls', () => {
36
+ const createEditor = createProsemirrorEditorFactory();
37
+ const fakeGetEditorFeatureFlags = () => ({});
38
+ const editor = (
39
+ doc: DocBuilder,
40
+ options?: {
41
+ dragAndDropEnabled?: boolean;
42
+ },
43
+ ) => {
44
+ const preset = new Preset<LightEditorPlugin>()
45
+ .add([featureFlagsPlugin, {}])
46
+ .add([analyticsPlugin, {}])
47
+ .add(contentInsertionPlugin)
48
+ .add(widthPlugin)
49
+ .add(guidelinePlugin)
50
+ .add(selectionPlugin)
51
+ .add([tablePlugin, { ...options, tableOptions: {} }]);
52
+ return createEditor<TablePluginState, PluginKey, typeof preset>({
53
+ doc,
54
+ preset,
55
+ pluginKey: pluginKey,
56
+ });
57
+ };
58
+
59
+ it('should not render floating column controls when tableRef undefined and drag and drop is not enabled', () => {
60
+ const { editorView } = editor(
61
+ doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
62
+ );
63
+ const { container } = render(
64
+ <TableFloatingColumnControls
65
+ editorView={editorView}
66
+ getEditorFeatureFlags={fakeGetEditorFeatureFlags}
67
+ />,
68
+ );
69
+ expect(container.innerHTML).toEqual('');
70
+ });
71
+
72
+ it('should not render floating column controls when tableRef undefined and drag and drop is enabled', () => {
73
+ const { editorView } = editor(
74
+ doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
75
+ {
76
+ dragAndDropEnabled: true,
77
+ },
78
+ );
79
+ const { container } = render(
80
+ <TableFloatingColumnControls
81
+ editorView={editorView}
82
+ getEditorFeatureFlags={fakeGetEditorFeatureFlags}
83
+ />,
84
+ );
85
+ expect(container.innerHTML).toEqual('');
86
+ });
87
+
88
+ it('should render a drop target per column', () => {
89
+ const { editorView } = editor(
90
+ doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty, tdEmpty))),
91
+ {
92
+ dragAndDropEnabled: true,
93
+ },
94
+ );
95
+ const ref = editorView.dom.querySelector('table') || undefined;
96
+
97
+ render(
98
+ <IntlProvider locale="en">
99
+ <TableFloatingColumnControls
100
+ tableRef={ref}
101
+ tableActive={true}
102
+ editorView={editorView}
103
+ getEditorFeatureFlags={fakeGetEditorFeatureFlags}
104
+ />
105
+ </IntlProvider>,
106
+ );
107
+
108
+ const dropTargets = screen.getAllByTestId(
109
+ 'table-floating-column-controls-drop-target',
110
+ );
111
+ expect(dropTargets).toHaveLength(5);
112
+ });
113
+
114
+ it('should render a drop target per column regardless of row count', () => {
115
+ const { editorView } = editor(
116
+ doc(p('text'), table()(tr(tdEmpty), tr(tdEmpty), tr(tdEmpty))),
117
+ {
118
+ dragAndDropEnabled: true,
119
+ },
120
+ );
121
+ const ref = editorView.dom.querySelector('table') || undefined;
122
+
123
+ render(
124
+ <IntlProvider locale="en">
125
+ <TableFloatingColumnControls
126
+ tableRef={ref}
127
+ tableActive={true}
128
+ editorView={editorView}
129
+ getEditorFeatureFlags={fakeGetEditorFeatureFlags}
130
+ />
131
+ </IntlProvider>,
132
+ );
133
+
134
+ const dropTargets = screen.getAllByTestId(
135
+ 'table-floating-column-controls-drop-target',
136
+ );
137
+ expect(dropTargets).toHaveLength(1);
138
+ });
139
+ });
@@ -78,7 +78,7 @@ import FloatingDeleteButton from './ui/FloatingDeleteButton';
78
78
  import FloatingInsertButton from './ui/FloatingInsertButton';
79
79
  import LayoutButton from './ui/LayoutButton';
80
80
  import { isLayoutSupported } from './utils';
81
- interface TablePluginOptions {
81
+ export interface TablePluginOptions {
82
82
  tableOptions: PluginConfig;
83
83
  // experimental custom table resizing experience, set inside editor-core behind a feature flag
84
84
  // will eventually replace breakoutEnabled
@@ -58,6 +58,7 @@ import {
58
58
  tableOverflowShadowWidth,
59
59
  tableOverflowShadowWidthWide,
60
60
  } from '../ui/consts';
61
+ import TableFloatingColumnControls from '../ui/TableFloatingColumnControls';
61
62
  import TableFloatingControls from '../ui/TableFloatingControls';
62
63
  import {
63
64
  containsHeaderRow,
@@ -91,6 +92,7 @@ export interface ComponentProps {
91
92
  isHeaderRowEnabled: boolean;
92
93
  isHeaderColumnEnabled: boolean;
93
94
  isMediaFullscreen?: boolean;
95
+ isDragAndDropEnabled?: boolean;
94
96
  tableActive: boolean;
95
97
  ordering: TableColumnOrdering;
96
98
  isResizing?: boolean;
@@ -396,6 +398,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
396
398
  options,
397
399
  getPos,
398
400
  pluginInjectionApi,
401
+ isDragAndDropEnabled,
399
402
  } = this.props;
400
403
  const { showBeforeShadow, showAfterShadow } = this.state;
401
404
  const node = getNode();
@@ -431,6 +434,24 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
431
434
  </div>
432
435
  );
433
436
 
437
+ const colControls = (
438
+ <div className={ClassName.COLUMN_CONTROLS_WRAPPER}>
439
+ <TableFloatingColumnControls
440
+ editorView={view}
441
+ tableRef={tableRef}
442
+ tableActive={tableActive}
443
+ hoveredRows={hoveredRows}
444
+ ordering={ordering}
445
+ hasHeaderRow={hasHeaderRow}
446
+ // pass `selection` and `tableHeight` to control re-render
447
+ selection={view.state.selection}
448
+ headerRowHeight={headerRow ? headerRow.offsetHeight : undefined}
449
+ stickyHeader={this.state.stickyHeader}
450
+ getEditorFeatureFlags={this.props.getEditorFeatureFlags}
451
+ />
452
+ </div>
453
+ );
454
+
434
455
  const shadowPadding =
435
456
  allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
436
457
 
@@ -482,7 +503,11 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
482
503
  data-testid="sticky-scrollbar-sentinel-top"
483
504
  />
484
505
  )}
506
+
485
507
  {allowControls && rowControls}
508
+
509
+ {isDragAndDropEnabled && allowControls && colControls}
510
+
486
511
  <div
487
512
  style={shadowStyle(showBeforeShadow)}
488
513
  className={ClassName.TABLE_LEFT_SHADOW}
@@ -248,6 +248,7 @@ export default class TableView extends ReactNodeView<Props> {
248
248
  allowControls={pluginState!.pluginConfig.allowControls!}
249
249
  isHeaderRowEnabled={pluginState!.isHeaderRowEnabled}
250
250
  isHeaderColumnEnabled={pluginState!.isHeaderColumnEnabled}
251
+ isDragAndDropEnabled={pluginState!.isDragAndDropEnabled}
251
252
  tableActive={tableActive}
252
253
  ordering={pluginState!.ordering as TableColumnOrdering}
253
254
  isResizing={isResizing}
@@ -1,3 +1,5 @@
1
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+
1
3
  import type { DropTargetType } from './consts';
2
4
 
3
5
  export interface DragAndDropAction<T, D> {
@@ -15,12 +17,15 @@ export type DragAndDropSetDropTargetAction = DragAndDropAction<
15
17
  {
16
18
  type: DropTargetType;
17
19
  index: number;
20
+ decorationSet: DecorationSet;
18
21
  }
19
22
  >;
20
23
 
21
24
  export type DragAndDropClearDropTargetAction = DragAndDropAction<
22
25
  typeof DragAndDropActionType.CLEAR_DROP_TARGET,
23
- undefined
26
+ {
27
+ decorationSet: DecorationSet;
28
+ }
24
29
  >;
25
30
 
26
31
  // NOTE: This should be a Union of all possible actions