@atlaskit/editor-plugin-table 7.16.11 → 7.16.13
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.
- package/.eslintrc.js +3 -3
- package/CHANGELOG.md +16 -0
- package/dist/cjs/commands/misc.js +3 -3
- package/dist/cjs/nodeviews/TableCell.js +10 -10
- package/dist/cjs/nodeviews/TableContainer.js +83 -27
- package/dist/cjs/nodeviews/TableResizer.js +40 -19
- package/dist/cjs/nodeviews/TableRow.js +23 -23
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/cjs/ui/FloatingContextualMenu/styles.js +1 -1
- package/dist/cjs/ui/FloatingDragMenu/styles.js +1 -1
- package/dist/cjs/ui/common-styles.js +13 -13
- package/dist/cjs/ui/ui-styles.js +25 -25
- package/dist/cjs/utils/guidelines.js +7 -4
- package/dist/cjs/utils/merged-cells.js +3 -3
- package/dist/cjs/utils/snapping.js +7 -8
- package/dist/es2019/commands/misc.js +3 -3
- package/dist/es2019/nodeviews/TableContainer.js +70 -9
- package/dist/es2019/nodeviews/TableResizer.js +42 -21
- package/dist/es2019/nodeviews/TableRow.js +21 -21
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/es2019/ui/FloatingContextualMenu/styles.js +47 -47
- package/dist/es2019/ui/FloatingDragMenu/styles.js +30 -30
- package/dist/es2019/ui/common-styles.js +802 -816
- package/dist/es2019/ui/ui-styles.js +665 -678
- package/dist/es2019/utils/guidelines.js +5 -2
- package/dist/es2019/utils/merged-cells.js +3 -3
- package/dist/es2019/utils/snapping.js +5 -6
- package/dist/esm/commands/misc.js +3 -3
- package/dist/esm/nodeviews/TableCell.js +10 -10
- package/dist/esm/nodeviews/TableContainer.js +85 -29
- package/dist/esm/nodeviews/TableResizer.js +42 -21
- package/dist/esm/nodeviews/TableRow.js +23 -23
- package/dist/esm/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/esm/ui/FloatingContextualMenu/styles.js +1 -1
- package/dist/esm/ui/FloatingDragMenu/styles.js +1 -1
- package/dist/esm/ui/common-styles.js +13 -13
- package/dist/esm/ui/ui-styles.js +25 -25
- package/dist/esm/utils/guidelines.js +6 -3
- package/dist/esm/utils/merged-cells.js +3 -3
- package/dist/esm/utils/snapping.js +6 -7
- package/dist/types/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
- package/dist/types/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types/ui/ColumnResizeWidget/index.d.ts +1 -1
- package/dist/types/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
- package/dist/types/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
- package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
- package/dist/types/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
- package/dist/types/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
- package/dist/types/utils/guidelines.d.ts +2 -1
- package/dist/types/utils/snapping.d.ts +3 -2
- package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/ColumnResizeWidget/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
- package/dist/types-ts4.5/utils/guidelines.d.ts +2 -1
- package/dist/types-ts4.5/utils/snapping.d.ts +3 -2
- package/docs/0-intro.tsx +9 -7
- package/package.json +3 -3
- package/report.api.md +67 -66
- package/src/commands/clear.ts +36 -44
- package/src/commands/collapse.ts +8 -8
- package/src/commands/column-resize.ts +412 -452
- package/src/commands/delete.ts +14 -14
- package/src/commands/display-mode.ts +10 -11
- package/src/commands/go-to-next-cell.ts +48 -54
- package/src/commands/hover.ts +210 -227
- package/src/commands/index.ts +35 -35
- package/src/commands/insert.ts +208 -235
- package/src/commands/misc.ts +655 -748
- package/src/commands/referentiality.ts +9 -9
- package/src/commands/selection.ts +433 -563
- package/src/commands/sort.ts +68 -86
- package/src/commands/split-cell.ts +14 -14
- package/src/commands/toggle.ts +69 -67
- package/src/commands-with-analytics.ts +570 -639
- package/src/create-plugin-config.ts +13 -13
- package/src/event-handlers.ts +513 -612
- package/src/handlers.ts +120 -133
- package/src/nodeviews/ExternalDropTargets.tsx +68 -73
- package/src/nodeviews/OverflowShadowsObserver.ts +148 -157
- package/src/nodeviews/TableCell.ts +47 -54
- package/src/nodeviews/TableComponent.tsx +1018 -1112
- package/src/nodeviews/TableComponentWithSharedState.tsx +91 -94
- package/src/nodeviews/TableContainer.tsx +384 -340
- package/src/nodeviews/TableNodeViewBase.ts +19 -24
- package/src/nodeviews/TableResizer.tsx +642 -653
- package/src/nodeviews/TableRow.ts +580 -629
- package/src/nodeviews/TableStickyScrollbar.ts +173 -190
- package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +8 -8
- package/src/nodeviews/__mocks__/OverridableMock.ts +14 -15
- package/src/nodeviews/table.tsx +345 -375
- package/src/nodeviews/types.ts +21 -24
- package/src/nodeviews/update-overflow-shadows.ts +8 -14
- package/src/plugin.tsx +578 -603
- package/src/pm-plugins/analytics/actions.ts +10 -12
- package/src/pm-plugins/analytics/commands.ts +31 -37
- package/src/pm-plugins/analytics/plugin-factory.ts +4 -2
- package/src/pm-plugins/analytics/plugin-key.ts +1 -3
- package/src/pm-plugins/analytics/plugin.ts +60 -70
- package/src/pm-plugins/analytics/reducer.ts +19 -19
- package/src/pm-plugins/analytics/types.ts +10 -10
- package/src/pm-plugins/analytics/utils/moved-event.ts +38 -38
- package/src/pm-plugins/decorations/plugin.ts +58 -77
- package/src/pm-plugins/decorations/utils/column-controls.ts +59 -71
- package/src/pm-plugins/decorations/utils/column-resizing.ts +50 -57
- package/src/pm-plugins/decorations/utils/compose-decorations.ts +6 -6
- package/src/pm-plugins/decorations/utils/index.ts +3 -6
- package/src/pm-plugins/decorations/utils/types.ts +7 -12
- package/src/pm-plugins/default-table-selection.ts +3 -3
- package/src/pm-plugins/drag-and-drop/actions.ts +25 -25
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +158 -190
- package/src/pm-plugins/drag-and-drop/commands.ts +154 -170
- package/src/pm-plugins/drag-and-drop/consts.ts +4 -5
- package/src/pm-plugins/drag-and-drop/plugin-factory.ts +23 -20
- package/src/pm-plugins/drag-and-drop/plugin-key.ts +1 -3
- package/src/pm-plugins/drag-and-drop/plugin.ts +329 -383
- package/src/pm-plugins/drag-and-drop/reducer.ts +30 -30
- package/src/pm-plugins/drag-and-drop/types.ts +8 -8
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +38 -41
- package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +3 -6
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +57 -70
- package/src/pm-plugins/keymap.ts +208 -220
- package/src/pm-plugins/main.ts +348 -400
- package/src/pm-plugins/plugin-factory.ts +32 -34
- package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +83 -97
- package/src/pm-plugins/sticky-headers/commands.ts +2 -6
- package/src/pm-plugins/sticky-headers/plugin-key.ts +1 -3
- package/src/pm-plugins/sticky-headers/plugin-state.ts +41 -44
- package/src/pm-plugins/sticky-headers/plugin.ts +4 -4
- package/src/pm-plugins/sticky-headers/types.ts +8 -8
- package/src/pm-plugins/sticky-headers/util.ts +10 -10
- package/src/pm-plugins/table-analytics.ts +70 -72
- package/src/pm-plugins/table-local-id.ts +180 -184
- package/src/pm-plugins/table-resizing/commands.ts +72 -85
- package/src/pm-plugins/table-resizing/event-handlers.ts +298 -317
- package/src/pm-plugins/table-resizing/plugin-factory.ts +10 -10
- package/src/pm-plugins/table-resizing/plugin-key.ts +1 -3
- package/src/pm-plugins/table-resizing/plugin.ts +61 -68
- package/src/pm-plugins/table-resizing/reducer.ts +30 -33
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +84 -84
- package/src/pm-plugins/table-resizing/utils/column-state.ts +78 -81
- package/src/pm-plugins/table-resizing/utils/content-width.ts +94 -114
- package/src/pm-plugins/table-resizing/utils/dom.ts +93 -110
- package/src/pm-plugins/table-resizing/utils/index.ts +29 -34
- package/src/pm-plugins/table-resizing/utils/misc.ts +94 -119
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +93 -106
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +240 -257
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +343 -372
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +202 -207
- package/src/pm-plugins/table-resizing/utils/types.ts +17 -17
- package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +1 -2
- package/src/pm-plugins/table-selection-keymap.ts +25 -51
- package/src/pm-plugins/table-width.ts +191 -204
- package/src/pm-plugins/view-mode-sort/index.ts +223 -227
- package/src/pm-plugins/view-mode-sort/plugin-key.ts +3 -2
- package/src/pm-plugins/view-mode-sort/types.ts +12 -12
- package/src/pm-plugins/view-mode-sort/utils.ts +108 -117
- package/src/reducer.ts +139 -155
- package/src/toolbar.tsx +815 -905
- package/src/transforms/column-width.ts +186 -213
- package/src/transforms/delete-columns.ts +208 -222
- package/src/transforms/delete-rows.ts +117 -121
- package/src/transforms/fix-tables.ts +190 -215
- package/src/transforms/merge.ts +263 -269
- package/src/transforms/replace-table.ts +27 -43
- package/src/transforms/split.ts +65 -75
- package/src/types.ts +421 -427
- package/src/ui/ColumnResizeWidget/index.tsx +40 -47
- package/src/ui/DragHandle/HandleIconComponent.tsx +9 -13
- package/src/ui/DragHandle/index.tsx +221 -250
- package/src/ui/DragPreview/index.tsx +35 -35
- package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +33 -41
- package/src/ui/FloatingContextualButton/FixedButton.tsx +154 -157
- package/src/ui/FloatingContextualButton/index.tsx +109 -115
- package/src/ui/FloatingContextualButton/styles.ts +43 -46
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +634 -694
- package/src/ui/FloatingContextualMenu/index.tsx +83 -101
- package/src/ui/FloatingContextualMenu/styles.ts +57 -65
- package/src/ui/FloatingDeleteButton/DeleteButton.tsx +37 -37
- package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +47 -57
- package/src/ui/FloatingDeleteButton/index.tsx +319 -350
- package/src/ui/FloatingDragMenu/DragMenu.tsx +555 -596
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +152 -162
- package/src/ui/FloatingDragMenu/index.tsx +88 -102
- package/src/ui/FloatingDragMenu/styles.ts +51 -54
- package/src/ui/FloatingInsertButton/InsertButton.tsx +204 -217
- package/src/ui/FloatingInsertButton/getPopupOptions.ts +100 -115
- package/src/ui/FloatingInsertButton/index.tsx +248 -292
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +24 -29
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +308 -329
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +85 -94
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +46 -46
- package/src/ui/TableFloatingColumnControls/index.tsx +116 -136
- package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +79 -91
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +95 -102
- package/src/ui/TableFloatingControls/CornerControls/index.tsx +1 -4
- package/src/ui/TableFloatingControls/CornerControls/types.ts +8 -8
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +50 -50
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +111 -124
- package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +86 -105
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +305 -341
- package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +72 -75
- package/src/ui/TableFloatingControls/index.tsx +191 -193
- package/src/ui/TableFullWidthLabel/index.tsx +20 -20
- package/src/ui/common-styles.ts +880 -912
- package/src/ui/consts.ts +29 -74
- package/src/ui/icons/AddColLeftIcon.tsx +33 -39
- package/src/ui/icons/AddColRightIcon.tsx +33 -39
- package/src/ui/icons/AddRowAboveIcon.tsx +16 -22
- package/src/ui/icons/AddRowBelowIcon.tsx +33 -39
- package/src/ui/icons/DisplayModeIcon.tsx +31 -31
- package/src/ui/icons/DragHandleDisabledIcon.tsx +19 -21
- package/src/ui/icons/DragHandleIcon.tsx +12 -12
- package/src/ui/icons/DragInMotionIcon.tsx +45 -52
- package/src/ui/icons/MergeCellsIcon.tsx +22 -28
- package/src/ui/icons/MinimisedHandle.tsx +9 -9
- package/src/ui/icons/SplitCellIcon.tsx +30 -36
- package/src/ui/ui-styles.ts +769 -798
- package/src/utils/alignment.ts +1 -1
- package/src/utils/analytics.ts +192 -208
- package/src/utils/collapse.ts +55 -64
- package/src/utils/column-controls.ts +237 -254
- package/src/utils/create.ts +30 -30
- package/src/utils/decoration.ts +482 -502
- package/src/utils/dom.ts +127 -134
- package/src/utils/drag-menu.ts +322 -373
- package/src/utils/get-allow-add-column-custom-step.ts +4 -5
- package/src/utils/guidelines.ts +16 -21
- package/src/utils/index.ts +68 -68
- package/src/utils/merged-cells.ts +245 -254
- package/src/utils/nodes.ts +91 -106
- package/src/utils/paste.ts +119 -135
- package/src/utils/row-controls.ts +199 -213
- package/src/utils/selection.ts +77 -87
- package/src/utils/snapping.ts +87 -100
- package/src/utils/table.ts +44 -44
- package/src/utils/transforms.ts +5 -5
- package/src/utils/update-plugin-state-decorations.ts +5 -9
|
@@ -7,36 +7,25 @@ import type { WrappedComponentProps } from 'react-intl-next';
|
|
|
7
7
|
import { injectIntl } from 'react-intl-next';
|
|
8
8
|
|
|
9
9
|
type DropdownItem = MenuItem & {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
value: {
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
16
16
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
17
17
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
18
|
-
import {
|
|
19
|
-
addColumnAfter,
|
|
20
|
-
addRowAfter,
|
|
21
|
-
backspace,
|
|
22
|
-
tooltip,
|
|
23
|
-
} from '@atlaskit/editor-common/keymaps';
|
|
18
|
+
import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
24
19
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
25
20
|
import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
|
|
26
|
-
import type {
|
|
27
|
-
GetEditorContainerWidth,
|
|
28
|
-
GetEditorFeatureFlags,
|
|
29
|
-
} from '@atlaskit/editor-common/types';
|
|
21
|
+
import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
30
22
|
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
backgroundPaletteTooltipMessages,
|
|
24
|
+
cellBackgroundColorPalette,
|
|
25
|
+
ColorPalette,
|
|
34
26
|
} from '@atlaskit/editor-common/ui-color';
|
|
35
27
|
import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
36
|
-
import {
|
|
37
|
-
ArrowKeyNavigationType,
|
|
38
|
-
DropdownMenu,
|
|
39
|
-
} from '@atlaskit/editor-common/ui-menu';
|
|
28
|
+
import { ArrowKeyNavigationType, DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
40
29
|
import { closestElement } from '@atlaskit/editor-common/utils';
|
|
41
30
|
import { hexToEditorBackgroundPaletteColor } from '@atlaskit/editor-palette';
|
|
42
31
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
@@ -48,698 +37,649 @@ import EditorBackgroundColorIcon from '@atlaskit/icon/glyph/editor/background-co
|
|
|
48
37
|
import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
49
38
|
|
|
50
39
|
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
clearHoverSelection,
|
|
41
|
+
hoverColumns,
|
|
42
|
+
hoverMergedCells,
|
|
43
|
+
hoverRows,
|
|
44
|
+
toggleContextualMenu,
|
|
56
45
|
} from '../../commands';
|
|
57
46
|
import {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
47
|
+
deleteColumnsWithAnalytics,
|
|
48
|
+
deleteRowsWithAnalytics,
|
|
49
|
+
distributeColumnsWidthsWithAnalytics,
|
|
50
|
+
emptyMultipleCellsWithAnalytics,
|
|
51
|
+
insertColumnWithAnalytics,
|
|
52
|
+
insertRowWithAnalytics,
|
|
53
|
+
mergeCellsWithAnalytics,
|
|
54
|
+
setColorWithAnalytics,
|
|
55
|
+
sortColumnWithAnalytics,
|
|
56
|
+
splitCellWithAnalytics,
|
|
68
57
|
} from '../../commands-with-analytics';
|
|
69
58
|
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
70
59
|
import { getNewResizeStateFromSelectedColumns } from '../../pm-plugins/table-resizing/utils/resize-state';
|
|
71
60
|
import { canMergeCells } from '../../transforms';
|
|
72
61
|
import { TableCssClassName as ClassName } from '../../types';
|
|
73
62
|
import {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
getMergedCellsPositions,
|
|
64
|
+
getSelectedColumnIndexes,
|
|
65
|
+
getSelectedRowIndexes,
|
|
77
66
|
} from '../../utils';
|
|
78
|
-
import {
|
|
79
|
-
|
|
80
|
-
contextualMenuDropdownWidthDnD,
|
|
81
|
-
} from '../consts';
|
|
82
|
-
import {
|
|
83
|
-
AddColRightIcon,
|
|
84
|
-
AddRowBelowIcon,
|
|
85
|
-
MergeCellsIcon,
|
|
86
|
-
SplitCellIcon,
|
|
87
|
-
} from '../icons';
|
|
67
|
+
import { contextualMenuDropdownWidth, contextualMenuDropdownWidthDnD } from '../consts';
|
|
68
|
+
import { AddColRightIcon, AddRowBelowIcon, MergeCellsIcon, SplitCellIcon } from '../icons';
|
|
88
69
|
|
|
89
70
|
import { cellColourPreviewStyles, elementBeforeIconStyles } from './styles';
|
|
90
71
|
|
|
91
72
|
export interface Props {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
73
|
+
editorView: EditorView;
|
|
74
|
+
isOpen: boolean;
|
|
75
|
+
selectionRect: Rect;
|
|
76
|
+
targetCellPosition?: number; // We keep this because we need to know when to rerender
|
|
77
|
+
mountPoint?: HTMLElement;
|
|
78
|
+
allowMergeCells?: boolean;
|
|
79
|
+
allowColumnSorting?: boolean;
|
|
80
|
+
allowBackgroundColor?: boolean;
|
|
81
|
+
boundariesElement?: HTMLElement;
|
|
82
|
+
offset?: Array<number>;
|
|
83
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
84
|
+
getEditorContainerWidth: GetEditorContainerWidth;
|
|
85
|
+
getEditorFeatureFlags?: GetEditorFeatureFlags;
|
|
105
86
|
}
|
|
106
87
|
|
|
107
88
|
export interface State {
|
|
108
|
-
|
|
89
|
+
isSubmenuOpen: boolean;
|
|
109
90
|
}
|
|
110
91
|
|
|
111
|
-
export class ContextualMenu extends Component<
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
getMergedCellsPositions(state.tr).length !== 0
|
|
703
|
-
) {
|
|
704
|
-
hoverMergedCells()(state, dispatch);
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
|
|
708
|
-
private handleItemMouseLeave = ({ item }: { item: any }) => {
|
|
709
|
-
const { state, dispatch } = this.props.editorView;
|
|
710
|
-
if (item.value.name === 'background') {
|
|
711
|
-
this.closeSubmenu();
|
|
712
|
-
}
|
|
713
|
-
if (
|
|
714
|
-
[
|
|
715
|
-
'sort_column_asc',
|
|
716
|
-
'sort_column_desc',
|
|
717
|
-
'delete_column',
|
|
718
|
-
'delete_row',
|
|
719
|
-
].indexOf(item.value.name) > -1
|
|
720
|
-
) {
|
|
721
|
-
clearHoverSelection()(state, dispatch);
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
|
|
725
|
-
private closeSubmenu = () => {
|
|
726
|
-
if (this.state.isSubmenuOpen) {
|
|
727
|
-
this.setState({ isSubmenuOpen: false });
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
|
|
731
|
-
private setColor = (color: string) => {
|
|
732
|
-
const { editorView, editorAnalyticsAPI } = this.props;
|
|
733
|
-
// TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
|
|
734
|
-
const { targetCellPosition } = getPluginState(editorView.state);
|
|
735
|
-
const { state, dispatch } = editorView;
|
|
736
|
-
setColorWithAnalytics(editorAnalyticsAPI)(
|
|
737
|
-
INPUT_METHOD.CONTEXT_MENU,
|
|
738
|
-
color,
|
|
739
|
-
targetCellPosition,
|
|
740
|
-
)(state, dispatch);
|
|
741
|
-
this.toggleOpen();
|
|
742
|
-
};
|
|
92
|
+
export class ContextualMenu extends Component<Props & WrappedComponentProps, State> {
|
|
93
|
+
state: State = {
|
|
94
|
+
isSubmenuOpen: false,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
static defaultProps = {
|
|
98
|
+
boundariesElement: typeof document !== 'undefined' ? document.body : undefined,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
render() {
|
|
102
|
+
const { isOpen, mountPoint, offset, boundariesElement, editorView } = this.props;
|
|
103
|
+
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
104
|
+
const items = isDragAndDropEnabled
|
|
105
|
+
? this.createNewContextMenuItems()
|
|
106
|
+
: this.createOriginalContextMenuItems();
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div data-testid="table-cell-contextual-menu" onMouseLeave={this.closeSubmenu}>
|
|
110
|
+
<DropdownMenu
|
|
111
|
+
mountTo={mountPoint}
|
|
112
|
+
//This needs be removed when the a11y is completely handled
|
|
113
|
+
//Disabling key navigation now as it works only partially
|
|
114
|
+
arrowKeyNavigationProviderOptions={{
|
|
115
|
+
type: ArrowKeyNavigationType.MENU,
|
|
116
|
+
disableArrowKeyNavigation: true,
|
|
117
|
+
}}
|
|
118
|
+
items={items}
|
|
119
|
+
isOpen={isOpen}
|
|
120
|
+
onOpenChange={this.handleOpenChange}
|
|
121
|
+
onItemActivated={this.onMenuItemActivated}
|
|
122
|
+
onMouseEnter={this.handleItemMouseEnter}
|
|
123
|
+
onMouseLeave={this.handleItemMouseLeave}
|
|
124
|
+
fitHeight={188}
|
|
125
|
+
fitWidth={
|
|
126
|
+
isDragAndDropEnabled ? contextualMenuDropdownWidthDnD : contextualMenuDropdownWidth
|
|
127
|
+
}
|
|
128
|
+
boundariesElement={boundariesElement}
|
|
129
|
+
offset={offset}
|
|
130
|
+
section={isDragAndDropEnabled ? { hasSeparator: true } : undefined}
|
|
131
|
+
/>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private handleSubMenuRef = (ref: HTMLDivElement | null) => {
|
|
137
|
+
const parent = closestElement(
|
|
138
|
+
this.props.editorView.dom as HTMLElement,
|
|
139
|
+
'.fabric-editor-popup-scroll-parent',
|
|
140
|
+
);
|
|
141
|
+
if (!(parent && ref)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const boundariesRect = parent.getBoundingClientRect();
|
|
145
|
+
const rect = ref.getBoundingClientRect();
|
|
146
|
+
if (rect.left + rect.width > boundariesRect.width) {
|
|
147
|
+
ref.style.left = `-${rect.width}px`;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
private createBackgroundColorItem = () => {
|
|
152
|
+
const {
|
|
153
|
+
allowBackgroundColor,
|
|
154
|
+
editorView: { state },
|
|
155
|
+
isOpen,
|
|
156
|
+
intl: { formatMessage },
|
|
157
|
+
editorView,
|
|
158
|
+
} = this.props;
|
|
159
|
+
const { isSubmenuOpen } = this.state;
|
|
160
|
+
const { targetCellPosition, isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
161
|
+
|
|
162
|
+
if (allowBackgroundColor) {
|
|
163
|
+
const node = isOpen && targetCellPosition ? state.doc.nodeAt(targetCellPosition) : null;
|
|
164
|
+
const background = hexToEditorBackgroundPaletteColor(node?.attrs?.background || '#ffffff');
|
|
165
|
+
return {
|
|
166
|
+
content: isDragAndDropEnabled
|
|
167
|
+
? formatMessage(messages.backgroundColor)
|
|
168
|
+
: formatMessage(messages.cellBackground),
|
|
169
|
+
value: { name: 'background' },
|
|
170
|
+
elemBefore: isDragAndDropEnabled ? (
|
|
171
|
+
<span css={elementBeforeIconStyles}>
|
|
172
|
+
<EditorBackgroundColorIcon
|
|
173
|
+
label={formatMessage(messages.backgroundColor)}
|
|
174
|
+
size="medium"
|
|
175
|
+
/>
|
|
176
|
+
</span>
|
|
177
|
+
) : undefined,
|
|
178
|
+
elemAfter: (
|
|
179
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
180
|
+
<div className={DropdownMenuSharedCssClassName.SUBMENU}>
|
|
181
|
+
<div
|
|
182
|
+
css={cellColourPreviewStyles(background)}
|
|
183
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
184
|
+
className={
|
|
185
|
+
isDragAndDropEnabled
|
|
186
|
+
? ClassName.CONTEXTUAL_MENU_ICON_SMALL
|
|
187
|
+
: ClassName.CONTEXTUAL_MENU_ICON
|
|
188
|
+
}
|
|
189
|
+
/>
|
|
190
|
+
{isSubmenuOpen && (
|
|
191
|
+
<div
|
|
192
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
193
|
+
className={ClassName.CONTEXTUAL_SUBMENU}
|
|
194
|
+
ref={this.handleSubMenuRef}
|
|
195
|
+
>
|
|
196
|
+
<ColorPalette
|
|
197
|
+
cols={7}
|
|
198
|
+
onClick={this.setColor}
|
|
199
|
+
selectedColor={node?.attrs?.background || '#ffffff'}
|
|
200
|
+
paletteOptions={{
|
|
201
|
+
palette: cellBackgroundColorPalette,
|
|
202
|
+
paletteColorTooltipMessages: backgroundPaletteTooltipMessages,
|
|
203
|
+
hexToPaletteColor: hexToEditorBackgroundPaletteColor,
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
206
|
+
</div>
|
|
207
|
+
)}
|
|
208
|
+
</div>
|
|
209
|
+
),
|
|
210
|
+
} as MenuItem;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
private createMergeSplitCellItems = () => {
|
|
215
|
+
const {
|
|
216
|
+
allowMergeCells,
|
|
217
|
+
editorView: { state },
|
|
218
|
+
intl: { formatMessage },
|
|
219
|
+
editorView,
|
|
220
|
+
} = this.props;
|
|
221
|
+
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
222
|
+
|
|
223
|
+
if (allowMergeCells) {
|
|
224
|
+
return [
|
|
225
|
+
{
|
|
226
|
+
content: formatMessage(messages.mergeCells),
|
|
227
|
+
value: { name: 'merge' },
|
|
228
|
+
isDisabled: !canMergeCells(state.tr),
|
|
229
|
+
elemBefore: isDragAndDropEnabled ? (
|
|
230
|
+
<span css={elementBeforeIconStyles}>
|
|
231
|
+
<MergeCellsIcon />
|
|
232
|
+
</span>
|
|
233
|
+
) : undefined,
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
content: formatMessage(messages.splitCell),
|
|
237
|
+
value: { name: 'split' },
|
|
238
|
+
isDisabled: !splitCell(state),
|
|
239
|
+
elemBefore: isDragAndDropEnabled ? (
|
|
240
|
+
<span css={elementBeforeIconStyles}>
|
|
241
|
+
<SplitCellIcon />
|
|
242
|
+
</span>
|
|
243
|
+
) : undefined,
|
|
244
|
+
},
|
|
245
|
+
] as MenuItem[];
|
|
246
|
+
}
|
|
247
|
+
return [];
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
private createInsertColumnItem = () => {
|
|
251
|
+
const {
|
|
252
|
+
intl: { formatMessage },
|
|
253
|
+
editorView,
|
|
254
|
+
} = this.props;
|
|
255
|
+
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
content: formatMessage(
|
|
259
|
+
isDragAndDropEnabled ? messages.addColumnRight : messages.insertColumn,
|
|
260
|
+
),
|
|
261
|
+
value: { name: 'insert_column' },
|
|
262
|
+
elemAfter: <div css={shortcutStyle}>{tooltip(addColumnAfter)}</div>,
|
|
263
|
+
elemBefore: isDragAndDropEnabled ? (
|
|
264
|
+
<span css={elementBeforeIconStyles}>
|
|
265
|
+
<AddColRightIcon />
|
|
266
|
+
</span>
|
|
267
|
+
) : undefined,
|
|
268
|
+
} as MenuItem;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
private createInsertRowItem = () => {
|
|
272
|
+
const {
|
|
273
|
+
intl: { formatMessage },
|
|
274
|
+
editorView,
|
|
275
|
+
} = this.props;
|
|
276
|
+
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
content: formatMessage(isDragAndDropEnabled ? messages.addRowBelow : messages.insertRow),
|
|
280
|
+
value: { name: 'insert_row' },
|
|
281
|
+
elemAfter: <div css={shortcutStyle}>{tooltip(addRowAfter)}</div>,
|
|
282
|
+
elemBefore: isDragAndDropEnabled ? (
|
|
283
|
+
<span css={elementBeforeIconStyles}>
|
|
284
|
+
<AddRowBelowIcon />
|
|
285
|
+
</span>
|
|
286
|
+
) : undefined,
|
|
287
|
+
} as MenuItem;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
private createClearCellsItem = () => {
|
|
291
|
+
const {
|
|
292
|
+
selectionRect,
|
|
293
|
+
intl: { formatMessage },
|
|
294
|
+
editorView,
|
|
295
|
+
} = this.props;
|
|
296
|
+
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
297
|
+
const { top, bottom, right, left } = selectionRect;
|
|
298
|
+
const noOfColumns = right - left;
|
|
299
|
+
const noOfRows = bottom - top;
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
content: formatMessage(messages.clearCells, {
|
|
303
|
+
0: Math.max(noOfColumns, noOfRows),
|
|
304
|
+
}),
|
|
305
|
+
value: { name: 'clear' },
|
|
306
|
+
elemAfter: <div css={shortcutStyle}>{tooltip(backspace)}</div>,
|
|
307
|
+
elemBefore: isDragAndDropEnabled ? (
|
|
308
|
+
<span css={elementBeforeIconStyles}>
|
|
309
|
+
<CrossCircleIcon
|
|
310
|
+
label={formatMessage(messages.clearCells, {
|
|
311
|
+
0: Math.max(noOfColumns, noOfRows),
|
|
312
|
+
})}
|
|
313
|
+
/>
|
|
314
|
+
</span>
|
|
315
|
+
) : undefined,
|
|
316
|
+
} as MenuItem;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
private createDeleteColumnItem = () => {
|
|
320
|
+
const {
|
|
321
|
+
selectionRect,
|
|
322
|
+
intl: { formatMessage },
|
|
323
|
+
editorView,
|
|
324
|
+
} = this.props;
|
|
325
|
+
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
326
|
+
|
|
327
|
+
const { right, left } = selectionRect;
|
|
328
|
+
const noOfColumns = right - left;
|
|
329
|
+
|
|
330
|
+
return {
|
|
331
|
+
content: formatMessage(messages.removeColumns, {
|
|
332
|
+
0: noOfColumns,
|
|
333
|
+
}),
|
|
334
|
+
value: { name: 'delete_column' },
|
|
335
|
+
elemBefore: isDragAndDropEnabled ? (
|
|
336
|
+
<span css={elementBeforeIconStyles}>
|
|
337
|
+
<RemoveIcon
|
|
338
|
+
label={formatMessage(messages.removeColumns, {
|
|
339
|
+
0: noOfColumns,
|
|
340
|
+
})}
|
|
341
|
+
/>
|
|
342
|
+
</span>
|
|
343
|
+
) : undefined,
|
|
344
|
+
} as MenuItem;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
private createDeleteRowItem = () => {
|
|
348
|
+
const {
|
|
349
|
+
selectionRect,
|
|
350
|
+
intl: { formatMessage },
|
|
351
|
+
editorView,
|
|
352
|
+
} = this.props;
|
|
353
|
+
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
354
|
+
|
|
355
|
+
const { bottom, top } = selectionRect;
|
|
356
|
+
const noOfRows = bottom - top;
|
|
357
|
+
|
|
358
|
+
return {
|
|
359
|
+
content: formatMessage(messages.removeRows, {
|
|
360
|
+
0: noOfRows,
|
|
361
|
+
}),
|
|
362
|
+
value: { name: 'delete_row' },
|
|
363
|
+
elemBefore: isDragAndDropEnabled ? (
|
|
364
|
+
<span css={elementBeforeIconStyles}>
|
|
365
|
+
<RemoveIcon
|
|
366
|
+
label={formatMessage(messages.removeRows, {
|
|
367
|
+
0: noOfRows,
|
|
368
|
+
})}
|
|
369
|
+
/>
|
|
370
|
+
</span>
|
|
371
|
+
) : undefined,
|
|
372
|
+
} as MenuItem;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
private createDistributeColumnsItem = () => {
|
|
376
|
+
const {
|
|
377
|
+
selectionRect,
|
|
378
|
+
intl: { formatMessage },
|
|
379
|
+
editorView,
|
|
380
|
+
getEditorContainerWidth,
|
|
381
|
+
} = this.props;
|
|
382
|
+
const {
|
|
383
|
+
isDragAndDropEnabled,
|
|
384
|
+
pluginConfig: { allowDistributeColumns },
|
|
385
|
+
} = getPluginState(editorView.state);
|
|
386
|
+
if (allowDistributeColumns && !isDragAndDropEnabled) {
|
|
387
|
+
const { isTableScalingEnabled = false } = getPluginState(editorView.state);
|
|
388
|
+
const newResizeState = getNewResizeStateFromSelectedColumns(
|
|
389
|
+
selectionRect,
|
|
390
|
+
editorView.state,
|
|
391
|
+
editorView.domAtPos.bind(editorView),
|
|
392
|
+
getEditorContainerWidth,
|
|
393
|
+
isTableScalingEnabled,
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
const wouldChange = newResizeState?.changed ?? false;
|
|
397
|
+
|
|
398
|
+
return {
|
|
399
|
+
content: formatMessage(messages.distributeColumns),
|
|
400
|
+
value: { name: 'distribute_columns' },
|
|
401
|
+
isDisabled: !wouldChange,
|
|
402
|
+
} as MenuItem;
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
private createSortColumnItems = () => {
|
|
408
|
+
const {
|
|
409
|
+
intl: { formatMessage },
|
|
410
|
+
editorView,
|
|
411
|
+
allowColumnSorting,
|
|
412
|
+
} = this.props;
|
|
413
|
+
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
414
|
+
|
|
415
|
+
if (allowColumnSorting && !isDragAndDropEnabled) {
|
|
416
|
+
const hasMergedCellsInTable = getMergedCellsPositions(editorView.state.tr).length > 0;
|
|
417
|
+
const warning = hasMergedCellsInTable
|
|
418
|
+
? {
|
|
419
|
+
tooltipDescription: formatMessage(messages.canNotSortTable),
|
|
420
|
+
isDisabled: true,
|
|
421
|
+
}
|
|
422
|
+
: {};
|
|
423
|
+
|
|
424
|
+
return [
|
|
425
|
+
{
|
|
426
|
+
content: formatMessage(messages.sortColumnASC),
|
|
427
|
+
value: { name: 'sort_column_asc' },
|
|
428
|
+
...warning,
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
content: formatMessage(messages.sortColumnDESC),
|
|
432
|
+
value: { name: 'sort_column_desc' },
|
|
433
|
+
...warning,
|
|
434
|
+
},
|
|
435
|
+
] as MenuItem[];
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return null;
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
private createOriginalContextMenuItems = () => {
|
|
442
|
+
let items: MenuItem[] = [];
|
|
443
|
+
const backgroundColorItem = this.createBackgroundColorItem();
|
|
444
|
+
backgroundColorItem && items.push(backgroundColorItem);
|
|
445
|
+
|
|
446
|
+
items.push(this.createInsertColumnItem());
|
|
447
|
+
|
|
448
|
+
items.push(this.createInsertRowItem());
|
|
449
|
+
|
|
450
|
+
items.push(this.createDeleteColumnItem());
|
|
451
|
+
|
|
452
|
+
items.push(this.createDeleteRowItem());
|
|
453
|
+
|
|
454
|
+
items.push(...this.createMergeSplitCellItems());
|
|
455
|
+
|
|
456
|
+
const distributeColumnsItem = this.createDistributeColumnsItem();
|
|
457
|
+
distributeColumnsItem && items.push(distributeColumnsItem);
|
|
458
|
+
|
|
459
|
+
const sortColumnItems = this.createSortColumnItems();
|
|
460
|
+
sortColumnItems && items.push(...sortColumnItems);
|
|
461
|
+
|
|
462
|
+
items.push(this.createClearCellsItem());
|
|
463
|
+
|
|
464
|
+
return [{ items }];
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
private createNewContextMenuItems = () => {
|
|
468
|
+
const backgroundColorItem = this.createBackgroundColorItem();
|
|
469
|
+
const mergeSplitCellItems = this.createMergeSplitCellItems();
|
|
470
|
+
const insertColumnItem = this.createInsertColumnItem();
|
|
471
|
+
const insertRowItem = this.createInsertRowItem();
|
|
472
|
+
const clearCellsItem = this.createClearCellsItem();
|
|
473
|
+
const deleteColumnItem = this.createDeleteColumnItem();
|
|
474
|
+
const deleteRowItem = this.createDeleteRowItem();
|
|
475
|
+
|
|
476
|
+
// Group items so when table.menu.group-items FF is enabled, a divider shows under split cell, above add column
|
|
477
|
+
let items: { items: MenuItem[] }[] = [
|
|
478
|
+
{
|
|
479
|
+
items: [],
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
items: [],
|
|
483
|
+
},
|
|
484
|
+
];
|
|
485
|
+
|
|
486
|
+
backgroundColorItem && items[0].items.push(backgroundColorItem);
|
|
487
|
+
items[0].items.push(...mergeSplitCellItems);
|
|
488
|
+
items[1].items.push(insertColumnItem);
|
|
489
|
+
items[1].items.push(insertRowItem);
|
|
490
|
+
items[1].items.push(clearCellsItem);
|
|
491
|
+
items[1].items.push(deleteColumnItem);
|
|
492
|
+
items[1].items.push(deleteRowItem);
|
|
493
|
+
|
|
494
|
+
return items;
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
private onMenuItemActivated = ({ item }: { item: DropdownItem }) => {
|
|
498
|
+
const {
|
|
499
|
+
editorView,
|
|
500
|
+
selectionRect,
|
|
501
|
+
editorAnalyticsAPI,
|
|
502
|
+
getEditorContainerWidth,
|
|
503
|
+
getEditorFeatureFlags,
|
|
504
|
+
} = this.props;
|
|
505
|
+
// TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
|
|
506
|
+
const { state, dispatch } = editorView;
|
|
507
|
+
const { targetCellPosition, isTableScalingEnabled = false } = getPluginState(state);
|
|
508
|
+
|
|
509
|
+
const { tableDuplicateCellColouring = false } = getEditorFeatureFlags
|
|
510
|
+
? getEditorFeatureFlags()
|
|
511
|
+
: {};
|
|
512
|
+
|
|
513
|
+
switch (item.value.name) {
|
|
514
|
+
case 'sort_column_desc':
|
|
515
|
+
sortColumnWithAnalytics(editorAnalyticsAPI)(
|
|
516
|
+
INPUT_METHOD.CONTEXT_MENU,
|
|
517
|
+
selectionRect.left,
|
|
518
|
+
SortOrder.DESC,
|
|
519
|
+
)(state, dispatch);
|
|
520
|
+
this.toggleOpen();
|
|
521
|
+
break;
|
|
522
|
+
case 'sort_column_asc':
|
|
523
|
+
sortColumnWithAnalytics(editorAnalyticsAPI)(
|
|
524
|
+
INPUT_METHOD.CONTEXT_MENU,
|
|
525
|
+
selectionRect.left,
|
|
526
|
+
SortOrder.ASC,
|
|
527
|
+
)(state, dispatch);
|
|
528
|
+
this.toggleOpen();
|
|
529
|
+
break;
|
|
530
|
+
case 'merge':
|
|
531
|
+
mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU)(state, dispatch);
|
|
532
|
+
this.toggleOpen();
|
|
533
|
+
break;
|
|
534
|
+
case 'split':
|
|
535
|
+
splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU)(state, dispatch);
|
|
536
|
+
this.toggleOpen();
|
|
537
|
+
break;
|
|
538
|
+
case 'distribute_columns':
|
|
539
|
+
const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
|
|
540
|
+
selectionRect,
|
|
541
|
+
state,
|
|
542
|
+
editorView.domAtPos.bind(editorView),
|
|
543
|
+
getEditorContainerWidth,
|
|
544
|
+
isTableScalingEnabled,
|
|
545
|
+
);
|
|
546
|
+
|
|
547
|
+
if (newResizeStateWithAnalytics) {
|
|
548
|
+
distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(
|
|
549
|
+
INPUT_METHOD.CONTEXT_MENU,
|
|
550
|
+
newResizeStateWithAnalytics,
|
|
551
|
+
)(state, dispatch);
|
|
552
|
+
this.toggleOpen();
|
|
553
|
+
}
|
|
554
|
+
break;
|
|
555
|
+
case 'clear':
|
|
556
|
+
emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(
|
|
557
|
+
INPUT_METHOD.CONTEXT_MENU,
|
|
558
|
+
targetCellPosition,
|
|
559
|
+
)(state, dispatch);
|
|
560
|
+
this.toggleOpen();
|
|
561
|
+
break;
|
|
562
|
+
case 'insert_column':
|
|
563
|
+
insertColumnWithAnalytics(
|
|
564
|
+
editorAnalyticsAPI,
|
|
565
|
+
isTableScalingEnabled,
|
|
566
|
+
tableDuplicateCellColouring,
|
|
567
|
+
)(INPUT_METHOD.CONTEXT_MENU, selectionRect.right)(state, dispatch, editorView);
|
|
568
|
+
this.toggleOpen();
|
|
569
|
+
break;
|
|
570
|
+
case 'insert_row':
|
|
571
|
+
insertRowWithAnalytics(editorAnalyticsAPI, tableDuplicateCellColouring)(
|
|
572
|
+
INPUT_METHOD.CONTEXT_MENU,
|
|
573
|
+
{
|
|
574
|
+
index: selectionRect.bottom,
|
|
575
|
+
moveCursorToInsertedRow: true,
|
|
576
|
+
},
|
|
577
|
+
)(state, dispatch);
|
|
578
|
+
this.toggleOpen();
|
|
579
|
+
break;
|
|
580
|
+
case 'delete_column':
|
|
581
|
+
deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, selectionRect)(
|
|
582
|
+
state,
|
|
583
|
+
dispatch,
|
|
584
|
+
editorView,
|
|
585
|
+
);
|
|
586
|
+
this.toggleOpen();
|
|
587
|
+
break;
|
|
588
|
+
case 'delete_row':
|
|
589
|
+
const {
|
|
590
|
+
pluginConfig: { isHeaderRowRequired },
|
|
591
|
+
} = getPluginState(state);
|
|
592
|
+
|
|
593
|
+
deleteRowsWithAnalytics(editorAnalyticsAPI)(
|
|
594
|
+
INPUT_METHOD.CONTEXT_MENU,
|
|
595
|
+
selectionRect,
|
|
596
|
+
!!isHeaderRowRequired,
|
|
597
|
+
)(state, dispatch);
|
|
598
|
+
this.toggleOpen();
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
private toggleOpen = () => {
|
|
604
|
+
const {
|
|
605
|
+
isOpen,
|
|
606
|
+
editorView: { state, dispatch },
|
|
607
|
+
} = this.props;
|
|
608
|
+
toggleContextualMenu()(state, dispatch);
|
|
609
|
+
if (!isOpen) {
|
|
610
|
+
this.setState({
|
|
611
|
+
isSubmenuOpen: false,
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
private handleOpenChange = () => {
|
|
617
|
+
const {
|
|
618
|
+
editorView: { state, dispatch },
|
|
619
|
+
} = this.props;
|
|
620
|
+
toggleContextualMenu()(state, dispatch);
|
|
621
|
+
this.setState({ isSubmenuOpen: false });
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
private handleItemMouseEnter = ({ item }: { item: any }) => {
|
|
625
|
+
const {
|
|
626
|
+
editorView: { state, dispatch },
|
|
627
|
+
selectionRect,
|
|
628
|
+
} = this.props;
|
|
629
|
+
|
|
630
|
+
if (item.value.name === 'background') {
|
|
631
|
+
if (!this.state.isSubmenuOpen) {
|
|
632
|
+
this.setState({ isSubmenuOpen: true });
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (item.value.name === 'delete_column') {
|
|
637
|
+
hoverColumns(getSelectedColumnIndexes(selectionRect), true)(state, dispatch);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (item.value.name === 'delete_row') {
|
|
641
|
+
hoverRows(getSelectedRowIndexes(selectionRect), true)(state, dispatch);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
if (
|
|
645
|
+
['sort_column_asc', 'sort_column_desc'].indexOf(item.value.name) > -1 &&
|
|
646
|
+
getMergedCellsPositions(state.tr).length !== 0
|
|
647
|
+
) {
|
|
648
|
+
hoverMergedCells()(state, dispatch);
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
private handleItemMouseLeave = ({ item }: { item: any }) => {
|
|
653
|
+
const { state, dispatch } = this.props.editorView;
|
|
654
|
+
if (item.value.name === 'background') {
|
|
655
|
+
this.closeSubmenu();
|
|
656
|
+
}
|
|
657
|
+
if (
|
|
658
|
+
['sort_column_asc', 'sort_column_desc', 'delete_column', 'delete_row'].indexOf(
|
|
659
|
+
item.value.name,
|
|
660
|
+
) > -1
|
|
661
|
+
) {
|
|
662
|
+
clearHoverSelection()(state, dispatch);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
private closeSubmenu = () => {
|
|
667
|
+
if (this.state.isSubmenuOpen) {
|
|
668
|
+
this.setState({ isSubmenuOpen: false });
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
private setColor = (color: string) => {
|
|
673
|
+
const { editorView, editorAnalyticsAPI } = this.props;
|
|
674
|
+
// TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
|
|
675
|
+
const { targetCellPosition } = getPluginState(editorView.state);
|
|
676
|
+
const { state, dispatch } = editorView;
|
|
677
|
+
setColorWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, color, targetCellPosition)(
|
|
678
|
+
state,
|
|
679
|
+
dispatch,
|
|
680
|
+
);
|
|
681
|
+
this.toggleOpen();
|
|
682
|
+
};
|
|
743
683
|
}
|
|
744
684
|
|
|
745
685
|
export default injectIntl(ContextualMenu);
|