@atlaskit/editor-plugin-table 12.2.5 → 12.2.7

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 (207) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/ui/TableFloatingControls/NumberColumn/index.js +24 -2
  3. package/dist/es2019/ui/TableFloatingControls/NumberColumn/index.js +23 -1
  4. package/dist/esm/ui/TableFloatingControls/NumberColumn/index.js +24 -2
  5. package/package.json +4 -4
  6. package/afm-cc/tsconfig.json +0 -123
  7. package/afm-dev-agents/tsconfig.json +0 -123
  8. package/afm-jira/tsconfig.json +0 -123
  9. package/afm-passionfruit/tsconfig.json +0 -123
  10. package/afm-post-office/tsconfig.json +0 -123
  11. package/afm-rovo-extension/tsconfig.json +0 -123
  12. package/afm-townsquare/tsconfig.json +0 -123
  13. package/afm-volt/tsconfig.json +0 -114
  14. package/build/tsconfig.json +0 -23
  15. package/docs/0-intro.tsx +0 -57
  16. package/src/index.ts +0 -21
  17. package/src/nodeviews/ExternalDropTargets.tsx +0 -91
  18. package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
  19. package/src/nodeviews/TableCell.ts +0 -134
  20. package/src/nodeviews/TableComponent.tsx +0 -1590
  21. package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
  22. package/src/nodeviews/TableContainer.tsx +0 -926
  23. package/src/nodeviews/TableNodeViewBase.ts +0 -29
  24. package/src/nodeviews/TableResizer.tsx +0 -884
  25. package/src/nodeviews/TableRow.ts +0 -830
  26. package/src/nodeviews/TableStickyScrollbar.ts +0 -211
  27. package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
  28. package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
  29. package/src/nodeviews/table-container-styles.ts +0 -9
  30. package/src/nodeviews/table-node-views.ts +0 -76
  31. package/src/nodeviews/table.tsx +0 -530
  32. package/src/nodeviews/toDOM.ts +0 -244
  33. package/src/nodeviews/types.ts +0 -36
  34. package/src/nodeviews/update-overflow-shadows.ts +0 -11
  35. package/src/pm-plugins/analytics/actions.ts +0 -21
  36. package/src/pm-plugins/analytics/commands.ts +0 -47
  37. package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
  38. package/src/pm-plugins/analytics/plugin-key.ts +0 -5
  39. package/src/pm-plugins/analytics/plugin.ts +0 -80
  40. package/src/pm-plugins/analytics/reducer.ts +0 -27
  41. package/src/pm-plugins/analytics/types.ts +0 -20
  42. package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
  43. package/src/pm-plugins/commands/clear.ts +0 -43
  44. package/src/pm-plugins/commands/collapse.ts +0 -17
  45. package/src/pm-plugins/commands/column-resize.ts +0 -478
  46. package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
  47. package/src/pm-plugins/commands/delete.ts +0 -42
  48. package/src/pm-plugins/commands/display-mode.ts +0 -18
  49. package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
  50. package/src/pm-plugins/commands/hover.ts +0 -242
  51. package/src/pm-plugins/commands/index.ts +0 -51
  52. package/src/pm-plugins/commands/insert.ts +0 -438
  53. package/src/pm-plugins/commands/misc.ts +0 -811
  54. package/src/pm-plugins/commands/referentiality.ts +0 -15
  55. package/src/pm-plugins/commands/selection.ts +0 -537
  56. package/src/pm-plugins/commands/sort.ts +0 -102
  57. package/src/pm-plugins/commands/split-cell.ts +0 -28
  58. package/src/pm-plugins/commands/toggle.ts +0 -109
  59. package/src/pm-plugins/create-plugin-config.ts +0 -17
  60. package/src/pm-plugins/decorations/plugin.ts +0 -107
  61. package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
  62. package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
  63. package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
  64. package/src/pm-plugins/decorations/utils/types.ts +0 -16
  65. package/src/pm-plugins/default-table-selection.ts +0 -14
  66. package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
  67. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
  68. package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
  69. package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
  70. package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
  71. package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
  72. package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
  73. package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
  74. package/src/pm-plugins/drag-and-drop/types.ts +0 -18
  75. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
  76. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
  77. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
  78. package/src/pm-plugins/handlers.ts +0 -161
  79. package/src/pm-plugins/keymap.ts +0 -436
  80. package/src/pm-plugins/main.ts +0 -433
  81. package/src/pm-plugins/plugin-factory.ts +0 -42
  82. package/src/pm-plugins/plugin-key.ts +0 -8
  83. package/src/pm-plugins/reducer.ts +0 -145
  84. package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
  85. package/src/pm-plugins/sticky-headers/commands.ts +0 -8
  86. package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
  87. package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
  88. package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
  89. package/src/pm-plugins/sticky-headers/types.ts +0 -20
  90. package/src/pm-plugins/sticky-headers/util.ts +0 -18
  91. package/src/pm-plugins/table-analytics.ts +0 -100
  92. package/src/pm-plugins/table-local-id.ts +0 -213
  93. package/src/pm-plugins/table-resizing/commands.ts +0 -116
  94. package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
  95. package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
  96. package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
  97. package/src/pm-plugins/table-resizing/plugin.ts +0 -94
  98. package/src/pm-plugins/table-resizing/reducer.ts +0 -37
  99. package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
  100. package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
  101. package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
  102. package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
  103. package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
  104. package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
  105. package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
  106. package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
  107. package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
  108. package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
  109. package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
  110. package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
  111. package/src/pm-plugins/table-selection-keymap.ts +0 -64
  112. package/src/pm-plugins/table-size-selector.ts +0 -39
  113. package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
  114. package/src/pm-plugins/table-width.ts +0 -153
  115. package/src/pm-plugins/transforms/column-width.ts +0 -249
  116. package/src/pm-plugins/transforms/delete-columns.ts +0 -281
  117. package/src/pm-plugins/transforms/delete-rows.ts +0 -154
  118. package/src/pm-plugins/transforms/fix-tables.ts +0 -249
  119. package/src/pm-plugins/transforms/merge.ts +0 -301
  120. package/src/pm-plugins/transforms/replace-table.ts +0 -38
  121. package/src/pm-plugins/transforms/split.ts +0 -90
  122. package/src/pm-plugins/utils/alignment.ts +0 -33
  123. package/src/pm-plugins/utils/analytics.ts +0 -238
  124. package/src/pm-plugins/utils/collapse.ts +0 -93
  125. package/src/pm-plugins/utils/column-controls.ts +0 -250
  126. package/src/pm-plugins/utils/create.ts +0 -64
  127. package/src/pm-plugins/utils/decoration.ts +0 -672
  128. package/src/pm-plugins/utils/dom.ts +0 -251
  129. package/src/pm-plugins/utils/drag-menu.tsx +0 -491
  130. package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
  131. package/src/pm-plugins/utils/guidelines.ts +0 -30
  132. package/src/pm-plugins/utils/merged-cells.ts +0 -239
  133. package/src/pm-plugins/utils/nodes.ts +0 -162
  134. package/src/pm-plugins/utils/paste.ts +0 -386
  135. package/src/pm-plugins/utils/row-controls.ts +0 -211
  136. package/src/pm-plugins/utils/selection.ts +0 -17
  137. package/src/pm-plugins/utils/snapping.ts +0 -136
  138. package/src/pm-plugins/utils/table.ts +0 -60
  139. package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
  140. package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
  141. package/src/pm-plugins/view-mode-sort/index.ts +0 -291
  142. package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
  143. package/src/pm-plugins/view-mode-sort/types.ts +0 -23
  144. package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
  145. package/src/tablePlugin.tsx +0 -971
  146. package/src/tablePluginType.ts +0 -102
  147. package/src/types/index.ts +0 -592
  148. package/src/ui/ColumnResizeWidget/index.tsx +0 -61
  149. package/src/ui/ContentComponent.tsx +0 -311
  150. package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
  151. package/src/ui/DragHandle/index.tsx +0 -391
  152. package/src/ui/DragPreview/index.tsx +0 -51
  153. package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
  154. package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
  155. package/src/ui/FloatingContextualButton/index.tsx +0 -168
  156. package/src/ui/FloatingContextualButton/styles.ts +0 -69
  157. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
  158. package/src/ui/FloatingContextualMenu/index.tsx +0 -141
  159. package/src/ui/FloatingContextualMenu/styles.ts +0 -77
  160. package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
  161. package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
  162. package/src/ui/FloatingDeleteButton/index.tsx +0 -383
  163. package/src/ui/FloatingDeleteButton/types.ts +0 -3
  164. package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
  165. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
  166. package/src/ui/FloatingDragMenu/index.tsx +0 -136
  167. package/src/ui/FloatingDragMenu/styles.ts +0 -83
  168. package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
  169. package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
  170. package/src/ui/FloatingInsertButton/index.tsx +0 -314
  171. package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
  172. package/src/ui/SizeSelector/index.tsx +0 -74
  173. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
  174. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
  175. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
  176. package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
  177. package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
  178. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
  179. package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
  180. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
  181. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -150
  182. package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
  183. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
  184. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
  185. package/src/ui/TableFloatingControls/index.tsx +0 -275
  186. package/src/ui/TableFullWidthLabel/index.tsx +0 -38
  187. package/src/ui/common-styles.ts +0 -1218
  188. package/src/ui/consts.ts +0 -109
  189. package/src/ui/event-handlers.ts +0 -662
  190. package/src/ui/global-styles.tsx +0 -55
  191. package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
  192. package/src/ui/icons/AddColLeftIcon.tsx +0 -37
  193. package/src/ui/icons/AddColRightIcon.tsx +0 -37
  194. package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
  195. package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
  196. package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
  197. package/src/ui/icons/DragHandleIcon.tsx +0 -16
  198. package/src/ui/icons/DragInMotionIcon.tsx +0 -54
  199. package/src/ui/icons/MergeCellsIcon.tsx +0 -26
  200. package/src/ui/icons/MinimisedHandle.tsx +0 -15
  201. package/src/ui/icons/SortingIconWrapper.tsx +0 -43
  202. package/src/ui/icons/SplitCellIcon.tsx +0 -34
  203. package/src/ui/toolbar.tsx +0 -1153
  204. package/src/ui/ui-styles.ts +0 -960
  205. package/tsconfig.app.json +0 -135
  206. package/tsconfig.dev.json +0 -54
  207. package/tsconfig.json +0 -18
@@ -1,931 +0,0 @@
1
- /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
- /**
3
- * @jsxRuntime classic
4
- * @jsx jsx
5
- */
6
- import React, { Component } from 'react';
7
- import type { PointerEvent } from 'react';
8
-
9
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
10
- import { jsx } from '@emotion/react';
11
- import type { WrappedComponentProps } from 'react-intl-next';
12
- import { injectIntl } from 'react-intl-next';
13
-
14
- type DropdownItem = MenuItem & {
15
- value: {
16
- name: string;
17
- };
18
- };
19
-
20
- import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
21
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
22
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
23
- import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
24
- import { tableMessages as messages } from '@atlaskit/editor-common/messages';
25
- import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
26
- import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
27
- import {
28
- backgroundPaletteTooltipMessages,
29
- cellBackgroundColorPalette,
30
- ColorPalette,
31
- getSelectedRowAndColumnFromPalette,
32
- } from '@atlaskit/editor-common/ui-color';
33
- import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
34
- import {
35
- ArrowKeyNavigationProvider,
36
- ArrowKeyNavigationType,
37
- DropdownMenu,
38
- } from '@atlaskit/editor-common/ui-menu';
39
- import { closestElement } from '@atlaskit/editor-common/utils';
40
- import { hexToEditorBackgroundPaletteColor } from '@atlaskit/editor-palette';
41
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
42
- import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
43
- import type { Rect } from '@atlaskit/editor-tables/table-map';
44
- import { splitCell } from '@atlaskit/editor-tables/utils';
45
- import PaintBucketIcon from '@atlaskit/icon/core/migration/paint-bucket--editor-background-color';
46
- import TableCellClearIcon from '@atlaskit/icon/core/table-cell-clear';
47
- import TableCellMergeIcon from '@atlaskit/icon/core/table-cell-merge';
48
- import TableCellSplitIcon from '@atlaskit/icon/core/table-cell-split';
49
- import TableColumnAddRightIcon from '@atlaskit/icon/core/table-column-add-right';
50
- import TableColumnDeleteIcon from '@atlaskit/icon/core/table-column-delete';
51
- import TableColumnsDistributeIcon from '@atlaskit/icon/core/table-columns-distribute';
52
- import TableRowAddBelowIcon from '@atlaskit/icon/core/table-row-add-below';
53
- import TableRowDeleteIcon from '@atlaskit/icon/core/table-row-delete';
54
- import CrossCircleIcon from '@atlaskit/icon/glyph/cross-circle';
55
- import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
56
- // eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss
57
- import { Box, xcss } from '@atlaskit/primitives';
58
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
59
-
60
- import {
61
- clearHoverSelection,
62
- hoverColumns,
63
- hoverMergedCells,
64
- hoverRows,
65
- setFocusToCellMenu,
66
- toggleContextualMenu,
67
- } from '../../pm-plugins/commands';
68
- import {
69
- deleteColumnsWithAnalytics,
70
- deleteRowsWithAnalytics,
71
- distributeColumnsWidthsWithAnalytics,
72
- emptyMultipleCellsWithAnalytics,
73
- insertColumnWithAnalytics,
74
- insertRowWithAnalytics,
75
- mergeCellsWithAnalytics,
76
- setColorWithAnalytics,
77
- sortColumnWithAnalytics,
78
- splitCellWithAnalytics,
79
- } from '../../pm-plugins/commands/commands-with-analytics';
80
- import { getPluginState } from '../../pm-plugins/plugin-factory';
81
- import { pluginKey as tablePluginKey } from '../../pm-plugins/plugin-key';
82
- import { getNewResizeStateFromSelectedColumns } from '../../pm-plugins/table-resizing/utils/resize-state';
83
- import { canMergeCells } from '../../pm-plugins/transforms/merge';
84
- import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../pm-plugins/utils/selection';
85
- import { getMergedCellsPositions } from '../../pm-plugins/utils/table';
86
- import { TableCssClassName as ClassName } from '../../types';
87
- import type { PluginInjectionAPI } from '../../types';
88
- import {
89
- colorPalletteColumns,
90
- contextualMenuDropdownWidth,
91
- contextualMenuDropdownWidthDnD,
92
- } from '../consts';
93
- import { AddColRightIcon } from '../icons/AddColRightIcon';
94
- import { AddRowBelowIcon } from '../icons/AddRowBelowIcon';
95
- import { MergeCellsIcon } from '../icons/MergeCellsIcon';
96
- import { SplitCellIcon } from '../icons/SplitCellIcon';
97
-
98
- import { cellColourPreviewStyles } from './styles';
99
-
100
- interface Props {
101
- editorView: EditorView;
102
- isOpen: boolean;
103
- selectionRect: Rect;
104
- targetCellPosition?: number; // We keep this because we need to know when to rerender
105
- mountPoint?: HTMLElement;
106
- allowMergeCells?: boolean;
107
- allowColumnSorting?: boolean;
108
- allowBackgroundColor?: boolean;
109
- boundariesElement?: HTMLElement;
110
- offset?: Array<number>;
111
- api: PluginInjectionAPI | undefined | null;
112
- editorAnalyticsAPI?: EditorAnalyticsAPI;
113
- getEditorContainerWidth: GetEditorContainerWidth;
114
- getEditorFeatureFlags?: GetEditorFeatureFlags;
115
- isCellMenuOpenByKeyboard?: boolean;
116
- isCommentEditor?: boolean;
117
- }
118
-
119
- interface State {
120
- isSubmenuOpen: boolean;
121
- isOpenAllowed: boolean;
122
- }
123
- const arrowsList = new Set(['ArrowRight', 'ArrowLeft']);
124
-
125
- const elementBeforeIconStyles = xcss({
126
- marginRight: 'space.negative.075',
127
- display: 'flex',
128
- });
129
- // eslint-disable-next-line @repo/internal/react/no-class-components
130
- export class ContextualMenu extends Component<Props & WrappedComponentProps, State> {
131
- state: State = {
132
- isSubmenuOpen: false,
133
- isOpenAllowed: false,
134
- };
135
-
136
- static defaultProps = {
137
- boundariesElement: typeof document !== 'undefined' ? document.body : undefined,
138
- };
139
- private dropdownMenuRef = React.createRef<HTMLDivElement>();
140
-
141
- componentDidMount() {
142
- // ArrowKeyNavigationProvider in DropdownMenu expects that menu handle will stay focused
143
- // until user pressed ArrowDown.
144
- // Behavior above fails the A11Y requirement about first item in menu should be focused immediately.
145
- // so here is triggering componentDidUpdate inside dropdown to set focus on first element
146
- const { isCellMenuOpenByKeyboard } = this.props;
147
- if (isCellMenuOpenByKeyboard) {
148
- this.setState({
149
- ...this.state,
150
- isOpenAllowed: isCellMenuOpenByKeyboard,
151
- });
152
- }
153
- }
154
-
155
- render() {
156
- const { isOpen, mountPoint, offset, boundariesElement, editorView, isCellMenuOpenByKeyboard } =
157
- this.props;
158
- const { isDragAndDropEnabled } = getPluginState(editorView.state);
159
- const items = isDragAndDropEnabled
160
- ? this.createNewContextMenuItems()
161
- : this.createOriginalContextMenuItems();
162
- let isOpenAllowed = false;
163
-
164
- isOpenAllowed = isCellMenuOpenByKeyboard ? this.state.isOpenAllowed : isOpen;
165
-
166
- return (
167
- // eslint-disable-next-line jsx-a11y/no-static-element-interactions
168
- <div
169
- data-testid="table-cell-contextual-menu"
170
- onMouseLeave={this.closeSubmenu}
171
- ref={this.dropdownMenuRef}
172
- >
173
- <DropdownMenu
174
- mountTo={mountPoint}
175
- //This needs be removed when the a11y is completely handled
176
- //Disabling key navigation now as it works only partially
177
- arrowKeyNavigationProviderOptions={{
178
- type: ArrowKeyNavigationType.MENU,
179
- disableArrowKeyNavigation: !isCellMenuOpenByKeyboard || this.state.isSubmenuOpen,
180
- }}
181
- items={items}
182
- isOpen={isOpenAllowed}
183
- onOpenChange={this.handleOpenChange}
184
- onItemActivated={this.onMenuItemActivated}
185
- onMouseEnter={this.handleItemMouseEnter}
186
- onMouseLeave={this.handleItemMouseLeave}
187
- fitHeight={188}
188
- fitWidth={
189
- isDragAndDropEnabled ? contextualMenuDropdownWidthDnD : contextualMenuDropdownWidth
190
- }
191
- shouldFocusFirstItem={() => {
192
- return Boolean(isCellMenuOpenByKeyboard);
193
- }}
194
- boundariesElement={boundariesElement}
195
- offset={offset}
196
- section={isDragAndDropEnabled ? { hasSeparator: true } : undefined}
197
- allowEnterDefaultBehavior={this.state.isSubmenuOpen}
198
- />
199
- </div>
200
- );
201
- }
202
-
203
- private handleSubMenuRef = (ref: HTMLDivElement | null) => {
204
- const parent = closestElement(
205
- // Ignored via go/ees005
206
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
207
- this.props.editorView.dom as HTMLElement,
208
- '.fabric-editor-popup-scroll-parent',
209
- );
210
- if (!(parent && ref)) {
211
- return;
212
- }
213
- const boundariesRect = parent.getBoundingClientRect();
214
- const rect = ref.getBoundingClientRect();
215
- if (rect.left + rect.width > boundariesRect.width) {
216
- ref.style.left = `-${rect.width}px`;
217
- }
218
- };
219
-
220
- private createBackgroundColorItem = () => {
221
- const {
222
- allowBackgroundColor,
223
- editorView: { state },
224
- isOpen,
225
- intl: { formatMessage },
226
- editorView,
227
- isCellMenuOpenByKeyboard,
228
- } = this.props;
229
- const { isSubmenuOpen } = this.state;
230
- const { targetCellPosition, isDragAndDropEnabled } = getPluginState(editorView.state);
231
-
232
- if (allowBackgroundColor) {
233
- const node = isOpen && targetCellPosition ? state.doc.nodeAt(targetCellPosition) : null;
234
- const background = hexToEditorBackgroundPaletteColor(node?.attrs?.background || '#ffffff');
235
-
236
- const selectedRowAndColumnFromPalette = getSelectedRowAndColumnFromPalette(
237
- cellBackgroundColorPalette,
238
- // Ignored via go/ees005
239
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
240
- background!,
241
- colorPalletteColumns,
242
- );
243
- const selectedRowIndex = selectedRowAndColumnFromPalette.selectedRowIndex;
244
- const selectedColumnIndex = selectedRowAndColumnFromPalette.selectedColumnIndex;
245
- return {
246
- content: isDragAndDropEnabled
247
- ? formatMessage(messages.backgroundColor)
248
- : formatMessage(messages.cellBackground),
249
- value: { name: 'background' },
250
- elemBefore: isDragAndDropEnabled ? (
251
- <Box xcss={elementBeforeIconStyles}>
252
- <PaintBucketIcon
253
- color="currentColor"
254
- spacing="spacious"
255
- label={formatMessage(messages.backgroundColor)}
256
- />
257
- </Box>
258
- ) : undefined,
259
- elemAfter: (
260
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
261
- <div className={DropdownMenuSharedCssClassName.SUBMENU}>
262
- <div
263
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
264
- css={cellColourPreviewStyles(background)}
265
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
266
- className={
267
- isDragAndDropEnabled
268
- ? ClassName.CONTEXTUAL_MENU_ICON_SMALL
269
- : ClassName.CONTEXTUAL_MENU_ICON
270
- }
271
- />
272
- {isSubmenuOpen && (
273
- <div
274
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
275
- className={ClassName.CONTEXTUAL_SUBMENU}
276
- ref={this.handleSubMenuRef}
277
- >
278
- <ArrowKeyNavigationProvider
279
- type={ArrowKeyNavigationType.COLOR}
280
- selectedRowIndex={selectedRowIndex || 0}
281
- selectedColumnIndex={selectedColumnIndex || 0}
282
- handleClose={() => {
283
- this.setState({ isSubmenuOpen: false });
284
- if (this.dropdownMenuRef && this.dropdownMenuRef.current) {
285
- const focusableItems = this.dropdownMenuRef.current.querySelectorAll(
286
- 'div[tabindex="-1"]:not([disabled])',
287
- ) as NodeListOf<HTMLElement>;
288
- if (focusableItems && focusableItems.length) {
289
- focusableItems[0].focus();
290
- }
291
- }
292
- }}
293
- isPopupPositioned={true}
294
- // Ignored via go/ees005
295
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
296
- isOpenedByKeyboard={isCellMenuOpenByKeyboard!}
297
- >
298
- <ColorPalette
299
- cols={7}
300
- onClick={this.setColor}
301
- selectedColor={node?.attrs?.background || '#ffffff'}
302
- paletteOptions={{
303
- palette: cellBackgroundColorPalette,
304
- paletteColorTooltipMessages: backgroundPaletteTooltipMessages,
305
- hexToPaletteColor: hexToEditorBackgroundPaletteColor,
306
- }}
307
- />
308
- </ArrowKeyNavigationProvider>
309
- </div>
310
- )}
311
- </div>
312
- ),
313
- 'aria-expanded': isSubmenuOpen,
314
- } as MenuItem;
315
- }
316
- };
317
-
318
- // Used in the NewContextMenuItems object
319
- private newDistributeColumnsItem = () => {
320
- const {
321
- intl: { formatMessage },
322
- } = this.props;
323
- return this.createDistributeColumnsItemInternal({
324
- elemBefore: (
325
- <Box xcss={elementBeforeIconStyles}>
326
- <TableColumnsDistributeIcon
327
- color="currentColor"
328
- spacing="spacious"
329
- label={formatMessage(messages.distributeColumns)}
330
- LEGACY_fallbackIcon={MergeCellsIcon}
331
- />
332
- </Box>
333
- ),
334
- });
335
- };
336
-
337
- private createMergeSplitCellItems = () => {
338
- const {
339
- allowMergeCells,
340
- editorView: { state },
341
- intl: { formatMessage },
342
- editorView,
343
- } = this.props;
344
- const { isDragAndDropEnabled } = getPluginState(editorView.state);
345
-
346
- if (allowMergeCells) {
347
- return [
348
- {
349
- content: formatMessage(messages.mergeCells),
350
- value: { name: 'merge' },
351
- isDisabled: !canMergeCells(state.tr),
352
- elemBefore: isDragAndDropEnabled ? (
353
- <Box xcss={elementBeforeIconStyles}>
354
- <TableCellMergeIcon
355
- color="currentColor"
356
- spacing="spacious"
357
- label={formatMessage(messages.mergeCells)}
358
- LEGACY_fallbackIcon={MergeCellsIcon}
359
- />
360
- </Box>
361
- ) : undefined,
362
- },
363
- {
364
- content: formatMessage(messages.splitCell),
365
- value: { name: 'split' },
366
- isDisabled: !splitCell(state),
367
- elemBefore: isDragAndDropEnabled ? (
368
- <Box xcss={elementBeforeIconStyles}>
369
- <TableCellSplitIcon
370
- color="currentColor"
371
- spacing="spacious"
372
- label={formatMessage(messages.splitCell)}
373
- LEGACY_fallbackIcon={SplitCellIcon}
374
- />
375
- </Box>
376
- ) : undefined,
377
- },
378
- ] as MenuItem[];
379
- }
380
- return [];
381
- };
382
-
383
- private createInsertColumnItem = () => {
384
- const {
385
- intl: { formatMessage },
386
- editorView,
387
- } = this.props;
388
- const { isDragAndDropEnabled } = getPluginState(editorView.state);
389
- const content = formatMessage(
390
- isDragAndDropEnabled ? messages.addColumnRight : messages.insertColumn,
391
- );
392
-
393
- return {
394
- content,
395
- value: { name: 'insert_column' },
396
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
397
- elemAfter: <div css={shortcutStyle}>{tooltip(addColumnAfter)}</div>,
398
- elemBefore: isDragAndDropEnabled ? (
399
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
400
- <Box xcss={elementBeforeIconStyles}>
401
- <TableColumnAddRightIcon
402
- color="currentColor"
403
- spacing="spacious"
404
- label={formatMessage(messages.addColumnRight)}
405
- LEGACY_fallbackIcon={AddColRightIcon}
406
- />
407
- </Box>
408
- ) : undefined,
409
- 'aria-label': tooltip(addColumnAfter, String(content)),
410
- } as MenuItem;
411
- };
412
-
413
- private createInsertRowItem = () => {
414
- const {
415
- intl: { formatMessage },
416
- editorView,
417
- } = this.props;
418
- const { isDragAndDropEnabled } = getPluginState(editorView.state);
419
- const content = formatMessage(isDragAndDropEnabled ? messages.addRowBelow : messages.insertRow);
420
-
421
- return {
422
- content,
423
- value: { name: 'insert_row' },
424
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
425
- elemAfter: <div css={shortcutStyle}>{tooltip(addRowAfter)}</div>,
426
- elemBefore: isDragAndDropEnabled ? (
427
- <Box xcss={elementBeforeIconStyles}>
428
- <TableRowAddBelowIcon
429
- color="currentColor"
430
- spacing="spacious"
431
- label={formatMessage(messages.addRowBelow)}
432
- LEGACY_fallbackIcon={AddRowBelowIcon}
433
- />
434
- </Box>
435
- ) : undefined,
436
- 'aria-label': tooltip(addRowAfter, String(content)),
437
- } as MenuItem;
438
- };
439
-
440
- private createClearCellsItem = () => {
441
- const {
442
- selectionRect,
443
- intl: { formatMessage },
444
- editorView,
445
- } = this.props;
446
- const { isDragAndDropEnabled } = getPluginState(editorView.state);
447
- const { top, bottom, right, left } = selectionRect;
448
- const noOfColumns = right - left;
449
- const noOfRows = bottom - top;
450
-
451
- const content = formatMessage(messages.clearCells, {
452
- 0: Math.max(noOfColumns, noOfRows),
453
- });
454
-
455
- return {
456
- content,
457
- value: { name: 'clear' },
458
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
459
- elemAfter: <div css={shortcutStyle}>{tooltip(backspace)}</div>,
460
- elemBefore: isDragAndDropEnabled ? (
461
- <Box xcss={elementBeforeIconStyles}>
462
- <TableCellClearIcon
463
- color="currentColor"
464
- spacing="spacious"
465
- label={formatMessage(messages.clearCells, {
466
- 0: Math.max(noOfColumns, noOfRows),
467
- })}
468
- LEGACY_fallbackIcon={CrossCircleIcon}
469
- />
470
- </Box>
471
- ) : undefined,
472
- 'aria-label': tooltip(backspace, String(content)),
473
- } as MenuItem;
474
- };
475
-
476
- private createDeleteColumnItem = () => {
477
- const {
478
- selectionRect,
479
- intl: { formatMessage },
480
- editorView,
481
- } = this.props;
482
- const { isDragAndDropEnabled } = getPluginState(editorView.state);
483
-
484
- const { right, left } = selectionRect;
485
- const noOfColumns = right - left;
486
-
487
- return {
488
- content: formatMessage(messages.removeColumns, {
489
- 0: noOfColumns,
490
- }),
491
- value: { name: 'delete_column' },
492
- elemBefore: isDragAndDropEnabled ? (
493
- <Box xcss={elementBeforeIconStyles}>
494
- <TableColumnDeleteIcon
495
- color="currentColor"
496
- spacing="spacious"
497
- label={formatMessage(messages.removeColumns, {
498
- 0: noOfColumns,
499
- })}
500
- LEGACY_fallbackIcon={RemoveIcon}
501
- />
502
- </Box>
503
- ) : undefined,
504
- } as MenuItem;
505
- };
506
-
507
- private createDeleteRowItem = () => {
508
- const {
509
- selectionRect,
510
- intl: { formatMessage },
511
- editorView,
512
- } = this.props;
513
- const { isDragAndDropEnabled } = getPluginState(editorView.state);
514
-
515
- const { bottom, top } = selectionRect;
516
- const noOfRows = bottom - top;
517
-
518
- return {
519
- content: formatMessage(messages.removeRows, {
520
- 0: noOfRows,
521
- }),
522
- value: { name: 'delete_row' },
523
- elemBefore: isDragAndDropEnabled ? (
524
- <Box xcss={elementBeforeIconStyles}>
525
- <TableRowDeleteIcon
526
- color="currentColor"
527
- spacing="spacious"
528
- label={formatMessage(messages.removeRows, {
529
- 0: noOfRows,
530
- })}
531
- LEGACY_fallbackIcon={RemoveIcon}
532
- />
533
- </Box>
534
- ) : undefined,
535
- } as MenuItem;
536
- };
537
-
538
- private createDistributeColumnsItemInternal = (partialMenuItem?: Partial<MenuItem>) => {
539
- const {
540
- selectionRect,
541
- editorView,
542
- getEditorContainerWidth,
543
- getEditorFeatureFlags,
544
- intl: { formatMessage },
545
- } = this.props;
546
-
547
- const { isTableScalingEnabled = false } = getPluginState(editorView.state);
548
- const { tableWithFixedColumnWidthsOption = false } = getEditorFeatureFlags
549
- ? getEditorFeatureFlags()
550
- : {};
551
-
552
- const newResizeState = getNewResizeStateFromSelectedColumns(
553
- selectionRect,
554
- editorView.state,
555
- editorView.domAtPos.bind(editorView),
556
- getEditorContainerWidth,
557
- isTableScalingEnabled,
558
- tableWithFixedColumnWidthsOption,
559
- );
560
-
561
- const wouldChange = newResizeState?.changed ?? false;
562
-
563
- return {
564
- content: formatMessage(messages.distributeColumns),
565
- value: { name: 'distribute_columns' },
566
- isDisabled: !wouldChange,
567
- ...partialMenuItem,
568
- } as MenuItem;
569
- };
570
-
571
- private createDistributeColumnsItem = () => {
572
- const { editorView } = this.props;
573
- const {
574
- isDragAndDropEnabled,
575
- pluginConfig: { allowDistributeColumns },
576
- } = getPluginState(editorView.state);
577
- if (allowDistributeColumns && !isDragAndDropEnabled) {
578
- return this.createDistributeColumnsItemInternal();
579
- }
580
- return null;
581
- };
582
-
583
- private createSortColumnItems = () => {
584
- const {
585
- intl: { formatMessage },
586
- editorView,
587
- allowColumnSorting,
588
- } = this.props;
589
- const { isDragAndDropEnabled } = getPluginState(editorView.state);
590
-
591
- if (allowColumnSorting && !isDragAndDropEnabled) {
592
- const hasMergedCellsInTable = getMergedCellsPositions(editorView.state.tr).length > 0;
593
- const warning = hasMergedCellsInTable
594
- ? {
595
- tooltipDescription: formatMessage(messages.canNotSortTable),
596
- isDisabled: true,
597
- }
598
- : {};
599
-
600
- return [
601
- {
602
- content: formatMessage(messages.sortColumnASC),
603
- value: { name: 'sort_column_asc' },
604
- ...warning,
605
- },
606
- {
607
- content: formatMessage(messages.sortColumnDESC),
608
- value: { name: 'sort_column_desc' },
609
- ...warning,
610
- },
611
- ] as MenuItem[];
612
- }
613
-
614
- return null;
615
- };
616
-
617
- private createOriginalContextMenuItems = () => {
618
- const items: MenuItem[] = [];
619
- const sortColumnItems = this.createSortColumnItems();
620
- const backgroundColorItem = this.createBackgroundColorItem();
621
- const distributeColumnsItem = this.createDistributeColumnsItem();
622
-
623
- sortColumnItems && items.push(...sortColumnItems);
624
-
625
- backgroundColorItem && items.push(backgroundColorItem);
626
-
627
- items.push(this.createInsertColumnItem());
628
-
629
- items.push(this.createInsertRowItem());
630
-
631
- items.push(this.createDeleteColumnItem());
632
-
633
- items.push(this.createDeleteRowItem());
634
-
635
- items.push(...this.createMergeSplitCellItems());
636
-
637
- distributeColumnsItem && items.push(distributeColumnsItem);
638
-
639
- items.push(this.createClearCellsItem());
640
-
641
- return [{ items }];
642
- };
643
-
644
- private createNewContextMenuItems = () => {
645
- const backgroundColorItem = this.createBackgroundColorItem();
646
- const mergeSplitCellItems = this.createMergeSplitCellItems();
647
- const insertColumnItem = this.createInsertColumnItem();
648
- const insertRowItem = this.createInsertRowItem();
649
- const clearCellsItem = this.createClearCellsItem();
650
- const deleteColumnItem = this.createDeleteColumnItem();
651
- const deleteRowItem = this.createDeleteRowItem();
652
-
653
- // Group items so when table.menu.group-items FF is enabled, a divider shows under split cell, above add column
654
- const items: { items: MenuItem[] }[] = [
655
- {
656
- items: [],
657
- },
658
- {
659
- items: [],
660
- },
661
- ];
662
-
663
- backgroundColorItem && items[0].items.push(backgroundColorItem);
664
- items[0].items.push(...mergeSplitCellItems);
665
- items[1].items.push(insertColumnItem);
666
- items[1].items.push(insertRowItem);
667
- if (editorExperiment('platform_editor_controls', 'variant1')) {
668
- items[1].items.push(this.newDistributeColumnsItem());
669
- }
670
- items[1].items.push(clearCellsItem);
671
- items[1].items.push(deleteColumnItem);
672
- items[1].items.push(deleteRowItem);
673
-
674
- return items;
675
- };
676
-
677
- private onMenuItemActivated = ({ item }: { item: DropdownItem }) => {
678
- const {
679
- editorView,
680
- selectionRect,
681
- editorAnalyticsAPI,
682
- getEditorContainerWidth,
683
- getEditorFeatureFlags,
684
- isCellMenuOpenByKeyboard,
685
- isCommentEditor,
686
- } = this.props;
687
- // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
688
- const { state, dispatch } = editorView;
689
- const { targetCellPosition, isTableScalingEnabled = false } = getPluginState(state);
690
-
691
- const { tableWithFixedColumnWidthsOption = false } = getEditorFeatureFlags
692
- ? getEditorFeatureFlags()
693
- : {};
694
- // context menu opened by keyboard and any item except 'background' activated
695
- // or color has been chosen from color palette
696
- if (
697
- isCellMenuOpenByKeyboard &&
698
- (item.value.name !== 'background' ||
699
- (item.value.name === 'background' && this.state.isSubmenuOpen))
700
- ) {
701
- const { tr } = state;
702
- tr.setMeta(tablePluginKey, {
703
- type: 'SET_CELL_MENU_OPEN',
704
- data: {
705
- isCellMenuOpenByKeyboard: false,
706
- },
707
- });
708
- dispatch(tr);
709
- editorView.dom.focus(); // otherwise cursor disappears from cell
710
- }
711
-
712
- const shouldUseIncreasedScalingPercent =
713
- isTableScalingEnabled &&
714
- (tableWithFixedColumnWidthsOption ||
715
- // When in comment editor, we need the scaling percent to be 40% while tableWithFixedColumnWidthsOption is not visible
716
- isCommentEditor);
717
-
718
- switch (item.value.name) {
719
- case 'sort_column_desc':
720
- sortColumnWithAnalytics(editorAnalyticsAPI)(
721
- INPUT_METHOD.CONTEXT_MENU,
722
- selectionRect.left,
723
- SortOrder.DESC,
724
- )(state, dispatch);
725
- this.toggleOpen();
726
- break;
727
- case 'sort_column_asc':
728
- sortColumnWithAnalytics(editorAnalyticsAPI)(
729
- INPUT_METHOD.CONTEXT_MENU,
730
- selectionRect.left,
731
- SortOrder.ASC,
732
- )(state, dispatch);
733
- this.toggleOpen();
734
- break;
735
- case 'merge':
736
- mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU)(state, dispatch);
737
- this.toggleOpen();
738
- break;
739
- case 'split':
740
- splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU)(state, dispatch);
741
- this.toggleOpen();
742
- break;
743
- case 'distribute_columns':
744
- const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
745
- selectionRect,
746
- state,
747
- editorView.domAtPos.bind(editorView),
748
- getEditorContainerWidth,
749
- isTableScalingEnabled,
750
- tableWithFixedColumnWidthsOption,
751
- isCommentEditor,
752
- );
753
-
754
- if (newResizeStateWithAnalytics) {
755
- distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI, this.props.api)(
756
- INPUT_METHOD.CONTEXT_MENU,
757
- newResizeStateWithAnalytics,
758
- )(state, dispatch);
759
- this.toggleOpen();
760
- }
761
- break;
762
- case 'clear':
763
- emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(
764
- INPUT_METHOD.CONTEXT_MENU,
765
- targetCellPosition,
766
- )(state, dispatch);
767
- this.toggleOpen();
768
- break;
769
- case 'insert_column':
770
- insertColumnWithAnalytics(
771
- this.props.api,
772
- editorAnalyticsAPI,
773
- isTableScalingEnabled,
774
- tableWithFixedColumnWidthsOption,
775
- shouldUseIncreasedScalingPercent,
776
- isCommentEditor,
777
- )(INPUT_METHOD.CONTEXT_MENU, selectionRect.right)(state, dispatch, editorView);
778
- this.toggleOpen();
779
- break;
780
- case 'insert_row':
781
- insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, {
782
- index: selectionRect.bottom,
783
- moveCursorToInsertedRow: true,
784
- })(state, dispatch);
785
- this.toggleOpen();
786
- break;
787
- case 'delete_column':
788
- deleteColumnsWithAnalytics(
789
- editorAnalyticsAPI,
790
- this.props.api,
791
- isTableScalingEnabled,
792
- tableWithFixedColumnWidthsOption,
793
- shouldUseIncreasedScalingPercent,
794
- isCommentEditor,
795
- )(INPUT_METHOD.CONTEXT_MENU, selectionRect)(state, dispatch, editorView);
796
- this.toggleOpen();
797
- break;
798
- case 'delete_row':
799
- const {
800
- pluginConfig: { isHeaderRowRequired },
801
- } = getPluginState(state);
802
-
803
- deleteRowsWithAnalytics(editorAnalyticsAPI)(
804
- INPUT_METHOD.CONTEXT_MENU,
805
- selectionRect,
806
- !!isHeaderRowRequired,
807
- )(state, dispatch);
808
- this.toggleOpen();
809
- break;
810
- case 'background': {
811
- // This is called twice.
812
- // 1st time when user chooses the background color item.
813
- // 2nd when color has been chosen from color palette.
814
- // here we are handling the 1st call relying on the isSubmenuOpen state value
815
- if (isCellMenuOpenByKeyboard && !this.state.isSubmenuOpen) {
816
- this.setState({ isSubmenuOpen: true });
817
- }
818
- break;
819
- }
820
- }
821
- };
822
-
823
- private toggleOpen = () => {
824
- const {
825
- isOpen,
826
- editorView: { state, dispatch },
827
- } = this.props;
828
- toggleContextualMenu()(state, dispatch);
829
- if (!isOpen) {
830
- this.setState({
831
- isSubmenuOpen: false,
832
- });
833
- }
834
- };
835
-
836
- private handleOpenChange = (payload?: {
837
- event: PointerEvent | KeyboardEvent;
838
- isOpen: boolean;
839
- }) => {
840
- const {
841
- editorView: { state, dispatch, dom },
842
- isCellMenuOpenByKeyboard,
843
- } = this.props;
844
-
845
- if (payload) {
846
- const { event } = payload;
847
- if (event && event instanceof KeyboardEvent) {
848
- if (!this.state.isSubmenuOpen) {
849
- if (arrowsList.has(event.key)) {
850
- // preventing default behavior for avoiding cursor jump to next/previous table column
851
- // when left/right arrow pressed.
852
- event.preventDefault();
853
- }
854
-
855
- toggleContextualMenu()(state, dispatch);
856
- this.setState({ isSubmenuOpen: false });
857
- setFocusToCellMenu(false)(state, dispatch);
858
- dom.focus();
859
- }
860
- } else {
861
- // mouse click outside
862
- toggleContextualMenu()(state, dispatch);
863
- this.setState({ isSubmenuOpen: false });
864
- if (isCellMenuOpenByKeyboard) {
865
- setFocusToCellMenu(false)(state, dispatch);
866
- }
867
- }
868
- }
869
- };
870
-
871
- // Ignored via go/ees005
872
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
873
- private handleItemMouseEnter = ({ item }: { item: any }) => {
874
- const {
875
- editorView: { state, dispatch },
876
- selectionRect,
877
- } = this.props;
878
-
879
- if (item.value.name === 'background') {
880
- if (!this.state.isSubmenuOpen) {
881
- this.setState({ isSubmenuOpen: true });
882
- }
883
- }
884
-
885
- if (item.value.name === 'delete_column') {
886
- hoverColumns(getSelectedColumnIndexes(selectionRect), true)(state, dispatch);
887
- }
888
-
889
- if (item.value.name === 'delete_row') {
890
- hoverRows(getSelectedRowIndexes(selectionRect), true)(state, dispatch);
891
- }
892
-
893
- if (
894
- ['sort_column_asc', 'sort_column_desc'].indexOf(item.value.name) > -1 &&
895
- getMergedCellsPositions(state.tr).length !== 0
896
- ) {
897
- hoverMergedCells()(state, dispatch);
898
- }
899
- };
900
-
901
- // Ignored via go/ees005
902
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
903
- private handleItemMouseLeave = ({ item }: { item: any }) => {
904
- const { state, dispatch } = this.props.editorView;
905
- if (item.value.name === 'background') {
906
- this.closeSubmenu();
907
- }
908
- if (
909
- ['sort_column_asc', 'sort_column_desc', 'delete_column', 'delete_row'].indexOf(
910
- item.value.name,
911
- ) > -1
912
- ) {
913
- clearHoverSelection()(state, dispatch);
914
- }
915
- };
916
-
917
- private closeSubmenu = () => {
918
- if (this.state.isSubmenuOpen) {
919
- this.setState({ isSubmenuOpen: false });
920
- }
921
- };
922
-
923
- private setColor = (color: string) => {
924
- const { editorView, editorAnalyticsAPI } = this.props;
925
- const { state, dispatch } = editorView;
926
- setColorWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, color)(state, dispatch);
927
- this.toggleOpen();
928
- };
929
- }
930
-
931
- export default injectIntl(ContextualMenu);