@atlaskit/editor-plugin-table 7.4.8 → 7.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/commands/column-resize.js +4 -2
  3. package/dist/cjs/commands/delete.js +2 -1
  4. package/dist/cjs/commands/insert.js +6 -3
  5. package/dist/cjs/commands-with-analytics.js +4 -2
  6. package/dist/cjs/event-handlers.js +2 -1
  7. package/dist/cjs/nodeviews/TableComponent.js +116 -47
  8. package/dist/cjs/nodeviews/TableContainer.js +8 -4
  9. package/dist/cjs/nodeviews/TableResizer.js +6 -5
  10. package/dist/cjs/nodeviews/table.js +12 -4
  11. package/dist/cjs/plugin.js +50 -47
  12. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +9 -6
  13. package/dist/cjs/pm-plugins/keymap.js +6 -3
  14. package/dist/cjs/pm-plugins/main.js +4 -1
  15. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +7 -3
  16. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +32 -11
  17. package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +4 -2
  18. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +24 -0
  19. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +20 -1
  20. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +2 -1
  21. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +52 -11
  22. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +19 -8
  23. package/dist/cjs/toolbar.js +17 -10
  24. package/dist/cjs/transforms/column-width.js +22 -7
  25. package/dist/cjs/transforms/delete-columns.js +2 -1
  26. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +45 -38
  27. package/dist/cjs/ui/FloatingContextualMenu/index.js +5 -3
  28. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +15 -4
  29. package/dist/cjs/ui/FloatingDragMenu/DropdownMenu.js +53 -8
  30. package/dist/cjs/ui/FloatingDragMenu/index.js +15 -6
  31. package/dist/cjs/ui/FloatingInsertButton/index.js +5 -1
  32. package/dist/cjs/ui/consts.js +2 -1
  33. package/dist/cjs/utils/create.js +1 -1
  34. package/dist/cjs/utils/drag-menu.js +4 -3
  35. package/dist/es2019/commands/column-resize.js +4 -3
  36. package/dist/es2019/commands/delete.js +2 -2
  37. package/dist/es2019/commands/insert.js +6 -6
  38. package/dist/es2019/commands-with-analytics.js +4 -4
  39. package/dist/es2019/event-handlers.js +2 -2
  40. package/dist/es2019/nodeviews/TableComponent.js +77 -8
  41. package/dist/es2019/nodeviews/TableContainer.js +8 -4
  42. package/dist/es2019/nodeviews/TableResizer.js +6 -5
  43. package/dist/es2019/nodeviews/table.js +12 -4
  44. package/dist/es2019/plugin.js +14 -8
  45. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +7 -4
  46. package/dist/es2019/pm-plugins/keymap.js +6 -3
  47. package/dist/es2019/pm-plugins/main.js +4 -1
  48. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +7 -3
  49. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +31 -12
  50. package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +3 -1
  51. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +2 -2
  52. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +20 -2
  53. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +2 -2
  54. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +47 -10
  55. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +19 -12
  56. package/dist/es2019/toolbar.js +15 -12
  57. package/dist/es2019/transforms/column-width.js +24 -10
  58. package/dist/es2019/transforms/delete-columns.js +2 -2
  59. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +12 -5
  60. package/dist/es2019/ui/FloatingContextualMenu/index.js +6 -4
  61. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +15 -4
  62. package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +42 -8
  63. package/dist/es2019/ui/FloatingDragMenu/index.js +16 -7
  64. package/dist/es2019/ui/FloatingInsertButton/index.js +5 -1
  65. package/dist/es2019/ui/consts.js +1 -0
  66. package/dist/es2019/utils/create.js +1 -1
  67. package/dist/es2019/utils/drag-menu.js +4 -4
  68. package/dist/esm/commands/column-resize.js +4 -2
  69. package/dist/esm/commands/delete.js +2 -1
  70. package/dist/esm/commands/insert.js +6 -3
  71. package/dist/esm/commands-with-analytics.js +4 -2
  72. package/dist/esm/event-handlers.js +2 -1
  73. package/dist/esm/nodeviews/TableComponent.js +118 -49
  74. package/dist/esm/nodeviews/TableContainer.js +8 -4
  75. package/dist/esm/nodeviews/TableResizer.js +6 -5
  76. package/dist/esm/nodeviews/table.js +12 -4
  77. package/dist/esm/plugin.js +50 -47
  78. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +9 -6
  79. package/dist/esm/pm-plugins/keymap.js +6 -3
  80. package/dist/esm/pm-plugins/main.js +4 -1
  81. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +7 -3
  82. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +32 -11
  83. package/dist/esm/pm-plugins/table-resizing/utils/consts.js +3 -1
  84. package/dist/esm/pm-plugins/table-resizing/utils/index.js +2 -2
  85. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +22 -2
  86. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +2 -1
  87. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +52 -11
  88. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +19 -8
  89. package/dist/esm/toolbar.js +17 -10
  90. package/dist/esm/transforms/column-width.js +23 -8
  91. package/dist/esm/transforms/delete-columns.js +2 -1
  92. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +45 -38
  93. package/dist/esm/ui/FloatingContextualMenu/index.js +6 -4
  94. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +15 -4
  95. package/dist/esm/ui/FloatingDragMenu/DropdownMenu.js +50 -9
  96. package/dist/esm/ui/FloatingDragMenu/index.js +16 -7
  97. package/dist/esm/ui/FloatingInsertButton/index.js +5 -1
  98. package/dist/esm/ui/consts.js +1 -0
  99. package/dist/esm/utils/create.js +1 -1
  100. package/dist/esm/utils/drag-menu.js +4 -3
  101. package/dist/types/commands/column-resize.d.ts +1 -1
  102. package/dist/types/commands/delete.d.ts +1 -1
  103. package/dist/types/commands/insert.d.ts +3 -3
  104. package/dist/types/commands-with-analytics.d.ts +2 -2
  105. package/dist/types/event-handlers.d.ts +1 -1
  106. package/dist/types/nodeviews/TableComponent.d.ts +3 -0
  107. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  108. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  109. package/dist/types/nodeviews/table.d.ts +1 -0
  110. package/dist/types/pm-plugins/drag-and-drop/plugin.d.ts +3 -2
  111. package/dist/types/pm-plugins/keymap.d.ts +2 -2
  112. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
  113. package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +2 -0
  114. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  115. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +7 -0
  116. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  117. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -3
  118. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  119. package/dist/types/toolbar.d.ts +2 -2
  120. package/dist/types/transforms/column-width.d.ts +1 -1
  121. package/dist/types/transforms/delete-columns.d.ts +1 -1
  122. package/dist/types/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -1
  123. package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
  124. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +7 -1
  125. package/dist/types/ui/FloatingDragMenu/DropdownMenu.d.ts +8 -2
  126. package/dist/types/ui/FloatingDragMenu/index.d.ts +3 -2
  127. package/dist/types/ui/FloatingInsertButton/index.d.ts +2 -1
  128. package/dist/types/ui/consts.d.ts +1 -0
  129. package/dist/types/utils/drag-menu.d.ts +1 -1
  130. package/dist/types-ts4.5/commands/column-resize.d.ts +1 -1
  131. package/dist/types-ts4.5/commands/delete.d.ts +1 -1
  132. package/dist/types-ts4.5/commands/insert.d.ts +3 -3
  133. package/dist/types-ts4.5/commands-with-analytics.d.ts +2 -2
  134. package/dist/types-ts4.5/event-handlers.d.ts +1 -1
  135. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +3 -0
  136. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  137. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  138. package/dist/types-ts4.5/nodeviews/table.d.ts +1 -0
  139. package/dist/types-ts4.5/pm-plugins/drag-and-drop/plugin.d.ts +3 -2
  140. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -2
  141. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
  142. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +2 -0
  143. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  144. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +7 -0
  145. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  146. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -3
  147. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  148. package/dist/types-ts4.5/toolbar.d.ts +2 -2
  149. package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
  150. package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
  151. package/dist/types-ts4.5/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -1
  152. package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
  153. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +7 -1
  154. package/dist/types-ts4.5/ui/FloatingDragMenu/DropdownMenu.d.ts +8 -2
  155. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +3 -2
  156. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +2 -1
  157. package/dist/types-ts4.5/ui/consts.d.ts +1 -0
  158. package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
  159. package/package.json +3 -3
  160. package/src/commands/column-resize.ts +3 -0
  161. package/src/commands/delete.ts +2 -1
  162. package/src/commands/insert.ts +15 -6
  163. package/src/commands-with-analytics.ts +9 -3
  164. package/src/event-handlers.ts +2 -0
  165. package/src/nodeviews/TableComponent.tsx +91 -5
  166. package/src/nodeviews/TableContainer.tsx +6 -0
  167. package/src/nodeviews/TableResizer.tsx +6 -0
  168. package/src/nodeviews/table.tsx +15 -10
  169. package/src/plugin.tsx +17 -5
  170. package/src/pm-plugins/drag-and-drop/plugin.ts +16 -8
  171. package/src/pm-plugins/keymap.ts +11 -3
  172. package/src/pm-plugins/main.ts +3 -0
  173. package/src/pm-plugins/table-resizing/event-handlers.ts +11 -1
  174. package/src/pm-plugins/table-resizing/utils/colgroup.ts +49 -17
  175. package/src/pm-plugins/table-resizing/utils/consts.ts +2 -0
  176. package/src/pm-plugins/table-resizing/utils/index.ts +8 -1
  177. package/src/pm-plugins/table-resizing/utils/misc.ts +25 -1
  178. package/src/pm-plugins/table-resizing/utils/resize-column.ts +2 -1
  179. package/src/pm-plugins/table-resizing/utils/resize-state.ts +56 -11
  180. package/src/pm-plugins/table-resizing/utils/scale-table.ts +24 -6
  181. package/src/toolbar.tsx +18 -5
  182. package/src/transforms/column-width.ts +33 -11
  183. package/src/transforms/delete-columns.ts +7 -2
  184. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +20 -5
  185. package/src/ui/FloatingContextualMenu/index.tsx +4 -1
  186. package/src/ui/FloatingDragMenu/DragMenu.tsx +19 -1
  187. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +94 -50
  188. package/src/ui/FloatingDragMenu/index.tsx +17 -4
  189. package/src/ui/FloatingInsertButton/index.tsx +17 -5
  190. package/src/ui/consts.ts +1 -0
  191. package/src/utils/create.ts +1 -3
  192. package/src/utils/drag-menu.ts +4 -1
@@ -249,7 +249,12 @@ function fixRowSpans(table: PMNode): PMNode | null {
249
249
  }
250
250
 
251
251
  export const deleteColumns =
252
- (rect: Rect, allowCustomStep: boolean, view?: EditorView) =>
252
+ (
253
+ rect: Rect,
254
+ allowCustomStep: boolean,
255
+ view?: EditorView,
256
+ tablePreserveWidth = false,
257
+ ) =>
253
258
  (tr: Transaction) => {
254
259
  let updatedTr = tr;
255
260
  updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
@@ -264,7 +269,7 @@ export const deleteColumns =
264
269
  const table = findTable(updatedTr.selection);
265
270
 
266
271
  if (table) {
267
- updatedTr = rescaleColumns()(table, view)(updatedTr);
272
+ updatedTr = rescaleColumns(tablePreserveWidth)(table, view)(updatedTr);
268
273
  }
269
274
  return updatedTr;
270
275
  };
@@ -23,7 +23,10 @@ import {
23
23
  } from '@atlaskit/editor-common/keymaps';
24
24
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
25
25
  import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
26
- import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
26
+ import type {
27
+ GetEditorContainerWidth,
28
+ GetEditorFeatureFlags,
29
+ } from '@atlaskit/editor-common/types';
27
30
  import {
28
31
  backgroundPaletteTooltipMessages,
29
32
  cellBackgroundColorPalette,
@@ -99,6 +102,7 @@ export interface Props {
99
102
  offset?: Array<number>;
100
103
  editorAnalyticsAPI?: EditorAnalyticsAPI;
101
104
  getEditorContainerWidth: GetEditorContainerWidth;
105
+ getEditorFeatureFlags?: GetEditorFeatureFlags;
102
106
  }
103
107
 
104
108
  export interface State {
@@ -464,11 +468,14 @@ export class ContextualMenu extends Component<
464
468
  (!isDragAndDropEnabled ||
465
469
  !getBooleanFF('platform.editor.table.new-cell-context-menu-styling'))
466
470
  ) {
471
+ const { tablePreserveWidth = false } =
472
+ this.props.getEditorFeatureFlags?.() || {};
467
473
  const newResizeState = getNewResizeStateFromSelectedColumns(
468
474
  selectionRect,
469
475
  editorView.state,
470
476
  editorView.domAtPos.bind(editorView),
471
477
  getEditorContainerWidth,
478
+ tablePreserveWidth,
472
479
  );
473
480
 
474
481
  const wouldChange = newResizeState?.changed ?? false;
@@ -583,10 +590,12 @@ export class ContextualMenu extends Component<
583
590
  selectionRect,
584
591
  editorAnalyticsAPI,
585
592
  getEditorContainerWidth,
593
+ getEditorFeatureFlags,
586
594
  } = this.props;
587
595
  // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
588
596
  const { state, dispatch } = editorView;
589
597
  const { targetCellPosition } = getPluginState(state);
598
+ const { tablePreserveWidth = false } = getEditorFeatureFlags?.() || {};
590
599
 
591
600
  switch (item.value.name) {
592
601
  case 'sort_column_desc':
@@ -626,6 +635,7 @@ export class ContextualMenu extends Component<
626
635
  state,
627
636
  editorView.domAtPos.bind(editorView),
628
637
  getEditorContainerWidth,
638
+ tablePreserveWidth,
629
639
  );
630
640
 
631
641
  if (newResizeStateWithAnalytics) {
@@ -644,10 +654,15 @@ export class ContextualMenu extends Component<
644
654
  this.toggleOpen();
645
655
  break;
646
656
  case 'insert_column':
647
- insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI)(
648
- INPUT_METHOD.CONTEXT_MENU,
649
- selectionRect.right,
650
- )(state, dispatch, editorView);
657
+ insertColumnWithAnalytics(
658
+ getEditorContainerWidth,
659
+ editorAnalyticsAPI,
660
+ tablePreserveWidth,
661
+ )(INPUT_METHOD.CONTEXT_MENU, selectionRect.right)(
662
+ state,
663
+ dispatch,
664
+ editorView,
665
+ );
651
666
  this.toggleOpen();
652
667
  break;
653
668
  case 'insert_row':
@@ -25,6 +25,7 @@ import {
25
25
  contextualMenuDropdownWidth,
26
26
  contextualMenuDropdownWidthDnD,
27
27
  contextualMenuTriggerSize,
28
+ tablePopupMenuFitHeight,
28
29
  } from '../consts';
29
30
 
30
31
  import ContextualMenu from './ContextualMenu';
@@ -52,6 +53,7 @@ const FloatingContextualMenu = ({
52
53
  pluginConfig,
53
54
  editorAnalyticsAPI,
54
55
  getEditorContainerWidth,
56
+ getEditorFeatureFlags,
55
57
  }: Props) => {
56
58
  // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
57
59
  const { targetCellPosition, isDragAndDropEnabled } = getPluginState(
@@ -91,7 +93,7 @@ const FloatingContextualMenu = ({
91
93
  mountTo={mountPoint}
92
94
  boundariesElement={boundariesElement}
93
95
  scrollableElement={scrollableElement}
94
- fitHeight={188}
96
+ fitHeight={tablePopupMenuFitHeight}
95
97
  fitWidth={
96
98
  isDragAndDropEnabled
97
99
  ? contextualMenuDropdownWidthDnD
@@ -121,6 +123,7 @@ const FloatingContextualMenu = ({
121
123
  boundariesElement={boundariesElement}
122
124
  editorAnalyticsAPI={editorAnalyticsAPI}
123
125
  getEditorContainerWidth={getEditorContainerWidth}
126
+ getEditorFeatureFlags={getEditorFeatureFlags}
124
127
  />
125
128
  </div>
126
129
  </Popup>
@@ -96,6 +96,12 @@ type DragMenuProps = {
96
96
  pluginConfig?: PluginConfig;
97
97
  getEditorContainerWidth: GetEditorContainerWidth;
98
98
  editorAnalyticsAPI?: EditorAnalyticsAPI;
99
+ fitWidth?: number;
100
+ fitHeight?: number;
101
+ mountPoint?: HTMLElement;
102
+ boundariesElement?: HTMLElement;
103
+ scrollableElement?: HTMLElement;
104
+ tablePreserveWidth?: boolean;
99
105
  };
100
106
 
101
107
  type PluralOptionType = 'noOfCols' | 'noOfRows' | 'noOfCells' | null;
@@ -269,6 +275,12 @@ export const DragMenu = React.memo(
269
275
  editorAnalyticsAPI,
270
276
  pluginConfig,
271
277
  intl: { formatMessage },
278
+ fitHeight,
279
+ fitWidth,
280
+ mountPoint,
281
+ scrollableElement,
282
+ boundariesElement,
283
+ tablePreserveWidth,
272
284
  }: DragMenuProps & WrappedComponentProps) => {
273
285
  const { state, dispatch } = editorView;
274
286
  const { selection } = state;
@@ -301,6 +313,7 @@ export const DragMenu = React.memo(
301
313
  selectionRect,
302
314
  editorAnalyticsAPI,
303
315
  pluginConfig?.isHeaderRowRequired,
316
+ tablePreserveWidth,
304
317
  );
305
318
 
306
319
  const { menuItems, menuCallback } = convertToDropdownItems(
@@ -627,12 +640,17 @@ export const DragMenu = React.memo(
627
640
  <DropdownMenu
628
641
  disableKeyboardHandling={isSubmenuOpen}
629
642
  section={{ hasSeparator: true }}
630
- target={target as HTMLElement | undefined}
631
643
  items={menuItems}
632
644
  onItemActivated={handleMenuItemActivated}
633
645
  onMouseEnter={handleItemMouseEnter}
634
646
  onMouseLeave={handleItemMouseLeave}
635
647
  handleClose={closeMenu}
648
+ fitHeight={fitHeight}
649
+ fitWidth={fitWidth}
650
+ direction={direction}
651
+ mountPoint={mountPoint}
652
+ boundariesElement={boundariesElement}
653
+ scrollableElement={scrollableElement}
636
654
  />
637
655
  );
638
656
  },
@@ -1,6 +1,7 @@
1
- import React from 'react';
1
+ /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
+ import React, { useState } from 'react';
2
3
 
3
- import { DropList } from '@atlaskit/editor-common/ui';
4
+ import { DropList, Popup } from '@atlaskit/editor-common/ui';
4
5
  import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
5
6
  import {
6
7
  ArrowKeyNavigationProvider,
@@ -8,6 +9,7 @@ import {
8
9
  DropdownMenuItem,
9
10
  } from '@atlaskit/editor-common/ui-menu';
10
11
  import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
12
+ import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
11
13
  import { MenuGroup, Section } from '@atlaskit/menu';
12
14
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
13
15
 
@@ -17,7 +19,6 @@ const DropListWithOutsideListeners =
17
19
  withReactEditorViewOuterListeners(DropList);
18
20
 
19
21
  type DropdownMenuProps = {
20
- target?: HTMLElement;
21
22
  items: Array<{
22
23
  items: MenuItem[];
23
24
  }>;
@@ -34,10 +35,16 @@ type DropdownMenuProps = {
34
35
  handleClose: (focusTarget: 'editor' | 'handle') => void;
35
36
  onMouseEnter: (attrs: { item: MenuItem }) => void;
36
37
  onMouseLeave: (attrs: { item: MenuItem }) => void;
38
+ fitWidth?: number;
39
+ fitHeight?: number;
40
+ direction?: string;
41
+ offset?: Array<number>;
42
+ mountPoint?: HTMLElement;
43
+ boundariesElement?: HTMLElement;
44
+ scrollableElement?: HTMLElement;
37
45
  };
38
46
 
39
47
  export const DropdownMenu = ({
40
- target,
41
48
  items,
42
49
  section,
43
50
  disableKeyboardHandling,
@@ -45,13 +52,24 @@ export const DropdownMenu = ({
45
52
  handleClose,
46
53
  onMouseEnter,
47
54
  onMouseLeave,
55
+ fitWidth,
56
+ fitHeight,
57
+ direction,
58
+ mountPoint,
59
+ boundariesElement,
60
+ scrollableElement,
48
61
  }: DropdownMenuProps) => {
62
+ const [popupPlacement, setPopupPlacement] = useState(['bottom', 'left']);
63
+ const [targetRefDiv, setTargetRefDiv] = useState<HTMLDivElement | null>(null);
64
+ const handleRef = (ref: HTMLDivElement | null) => {
65
+ setTargetRefDiv(ref);
66
+ };
49
67
  const innerMenu = () => {
50
68
  return (
51
69
  <DropListWithOutsideListeners
52
70
  isOpen
53
71
  shouldFitContainer
54
- position={['bottom', 'left'].join(' ')}
72
+ position={popupPlacement.join(' ')}
55
73
  handleClickOutside={() => handleClose('editor')}
56
74
  handleEscapeKeydown={() => {
57
75
  if (!disableKeyboardHandling) {
@@ -64,7 +82,7 @@ export const DropdownMenu = ({
64
82
  e.stopPropagation();
65
83
  }
66
84
  }}
67
- targetRef={target}
85
+ targetRef={targetRefDiv}
68
86
  >
69
87
  <div style={{ height: 0, minWidth: dragMenuDropdownWidth }} />
70
88
  <MenuGroup role="menu">
@@ -95,56 +113,82 @@ export const DropdownMenu = ({
95
113
  return innerMenu();
96
114
  }
97
115
 
116
+ // more offsets calculation as offsets depend on the direction and updated placement here
117
+ let offsetY =
118
+ direction === 'row' ? (popupPlacement[0] === 'bottom' ? -8 : -34) : 0;
119
+ let offsetX =
120
+ direction === 'column' ? (popupPlacement[1] === 'left' ? 0 : -7) : 0;
121
+
98
122
  return (
99
- <ArrowKeyNavigationProvider
100
- closeOnTab
101
- type={ArrowKeyNavigationType.MENU}
102
- onSelection={(index) => {
103
- const results = items.flatMap((item) =>
104
- 'items' in item ? item.items : item,
105
- );
123
+ <div className="drag-dropdown-menu-wrapper">
124
+ <div className="drag-dropdown-menu-popup-ref" ref={handleRef}></div>
125
+ <Popup
126
+ target={targetRefDiv as HTMLElement}
127
+ mountTo={mountPoint}
128
+ boundariesElement={boundariesElement}
129
+ scrollableElement={scrollableElement}
130
+ onPlacementChanged={(placement: [string, string]) => {
131
+ setPopupPlacement(placement);
132
+ }}
133
+ fitHeight={fitHeight}
134
+ fitWidth={fitWidth}
135
+ zIndex={akEditorFloatingPanelZIndex}
136
+ offset={[offsetX, offsetY]}
137
+ allowOutOfBounds // required as this popup is child of a parent popup, should be allowed to be out of bound of the parent popup, otherwise horizontal offset is not right
138
+ >
139
+ <ArrowKeyNavigationProvider
140
+ closeOnTab
141
+ type={ArrowKeyNavigationType.MENU}
142
+ onSelection={(index) => {
143
+ const results = items.flatMap((item) =>
144
+ 'items' in item ? item.items : item,
145
+ );
106
146
 
107
- // onSelection is called when any focusable element is 'activated'
108
- // this is an issue as some menu items have toggles, which cause the index value
109
- // in the callback to be outside of array length.
110
- // The logic below normalises the index value based on the number
111
- // of menu items with 2 focusable elements, and adjusts the index to ensure
112
- // the correct menu item is sent in onItemActivated callback
113
- if (
114
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
115
- ) {
116
- const keys = ['row_numbers', 'header_row', 'header_column'];
117
- let doubleItemCount = 0;
147
+ // onSelection is called when any focusable element is 'activated'
148
+ // this is an issue as some menu items have toggles, which cause the index value
149
+ // in the callback to be outside of array length.
150
+ // The logic below normalises the index value based on the number
151
+ // of menu items with 2 focusable elements, and adjusts the index to ensure
152
+ // the correct menu item is sent in onItemActivated callback
153
+ if (
154
+ getBooleanFF(
155
+ 'platform.editor.table.new-cell-context-menu-styling',
156
+ )
157
+ ) {
158
+ const keys = ['row_numbers', 'header_row', 'header_column'];
159
+ let doubleItemCount = 0;
118
160
 
119
- const firstIndex = results.findIndex((value) =>
120
- keys.includes(value.key!),
121
- );
161
+ const firstIndex = results.findIndex((value) =>
162
+ keys.includes(value.key!),
163
+ );
122
164
 
123
- if (firstIndex === -1 || index <= firstIndex) {
124
- onItemActivated && onItemActivated({ item: results[index] });
125
- return;
126
- }
165
+ if (firstIndex === -1 || index <= firstIndex) {
166
+ onItemActivated && onItemActivated({ item: results[index] });
167
+ return;
168
+ }
127
169
 
128
- for (let i = firstIndex; i < results.length; i += 1) {
129
- if (keys.includes(results[i].key!)) {
130
- doubleItemCount += 1;
131
- }
132
- if (firstIndex % 2 === 0 && index - doubleItemCount === i) {
133
- onItemActivated && onItemActivated({ item: results[i] });
134
- return;
135
- }
170
+ for (let i = firstIndex; i < results.length; i += 1) {
171
+ if (keys.includes(results[i].key!)) {
172
+ doubleItemCount += 1;
173
+ }
174
+ if (firstIndex % 2 === 0 && index - doubleItemCount === i) {
175
+ onItemActivated && onItemActivated({ item: results[i] });
176
+ return;
177
+ }
136
178
 
137
- if (firstIndex % 2 === 1 && index - doubleItemCount === i) {
138
- onItemActivated && onItemActivated({ item: results[i] });
139
- return;
179
+ if (firstIndex % 2 === 1 && index - doubleItemCount === i) {
180
+ onItemActivated && onItemActivated({ item: results[i] });
181
+ return;
182
+ }
183
+ }
184
+ } else {
185
+ onItemActivated && onItemActivated({ item: results[index] });
140
186
  }
141
- }
142
- } else {
143
- onItemActivated && onItemActivated({ item: results[index] });
144
- }
145
- }}
146
- >
147
- {innerMenu()}
148
- </ArrowKeyNavigationProvider>
187
+ }}
188
+ >
189
+ {innerMenu()}
190
+ </ArrowKeyNavigationProvider>
191
+ </Popup>
192
+ </div>
149
193
  );
150
194
  };
@@ -1,7 +1,10 @@
1
1
  import React from 'react';
2
2
 
3
3
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
- import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
4
+ import type {
5
+ GetEditorContainerWidth,
6
+ GetEditorFeatureFlags,
7
+ } from '@atlaskit/editor-common/types';
5
8
  import { Popup } from '@atlaskit/editor-common/ui';
6
9
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
7
10
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -13,7 +16,7 @@ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
13
16
 
14
17
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
15
18
  import type { PluginConfig, TableDirection } from '../../types';
16
- import { dragMenuDropdownWidth } from '../consts';
19
+ import { dragMenuDropdownWidth, tablePopupMenuFitHeight } from '../consts';
17
20
 
18
21
  import DragMenu from './DragMenu';
19
22
 
@@ -32,6 +35,7 @@ export interface Props {
32
35
  editorAnalyticsAPI?: EditorAnalyticsAPI;
33
36
  stickyHeaders?: RowStickyState;
34
37
  pluginConfig?: PluginConfig;
38
+ getEditorFeatureFlags: GetEditorFeatureFlags;
35
39
  }
36
40
 
37
41
  const FloatingDragMenu = ({
@@ -48,6 +52,7 @@ const FloatingDragMenu = ({
48
52
  editorAnalyticsAPI,
49
53
  stickyHeaders,
50
54
  pluginConfig,
55
+ getEditorFeatureFlags,
51
56
  }: Props) => {
52
57
  if (
53
58
  !isOpen ||
@@ -63,7 +68,7 @@ const FloatingDragMenu = ({
63
68
  ? document.querySelector('#drag-handle-button-row')
64
69
  : document.querySelector('#drag-handle-button-column');
65
70
 
66
- const offset = direction === 'row' ? [-9, 6] : [0, -7];
71
+ const offset = direction === 'row' ? [-9, 0] : [0, -7];
67
72
 
68
73
  if (
69
74
  !targetHandleRef ||
@@ -72,7 +77,8 @@ const FloatingDragMenu = ({
72
77
  return null;
73
78
  }
74
79
 
75
- // TODO: we will need to adjust the alignment and offset values depending on whether this is a row or column menu.
80
+ const { tablePreserveWidth = false } = getEditorFeatureFlags();
81
+
76
82
  return (
77
83
  <Popup
78
84
  alignX={direction === 'row' ? 'right' : undefined}
@@ -82,6 +88,7 @@ const FloatingDragMenu = ({
82
88
  boundariesElement={boundariesElement}
83
89
  scrollableElement={scrollableElement}
84
90
  fitWidth={dragMenuDropdownWidth}
91
+ fitHeight={tablePopupMenuFitHeight}
85
92
  // z-index value below is to ensure that this menu is above other floating menu
86
93
  // in table, but below floating dialogs like typeaheads, pickers, etc.
87
94
  // In sticky mode, we want to show the menu above the sticky header
@@ -105,6 +112,12 @@ const FloatingDragMenu = ({
105
112
  getEditorContainerWidth={getEditorContainerWidth}
106
113
  editorAnalyticsAPI={editorAnalyticsAPI}
107
114
  pluginConfig={pluginConfig}
115
+ fitWidth={dragMenuDropdownWidth}
116
+ fitHeight={tablePopupMenuFitHeight}
117
+ mountPoint={mountPoint}
118
+ boundariesElement={boundariesElement}
119
+ scrollableElement={scrollableElement}
120
+ tablePreserveWidth={tablePreserveWidth}
108
121
  />
109
122
  </Popup>
110
123
  );
@@ -15,7 +15,10 @@ import {
15
15
  EVENT_TYPE,
16
16
  INPUT_METHOD,
17
17
  } from '@atlaskit/editor-common/analytics';
18
- import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
18
+ import type {
19
+ GetEditorContainerWidth,
20
+ GetEditorFeatureFlags,
21
+ } from '@atlaskit/editor-common/types';
19
22
  import { Popup } from '@atlaskit/editor-common/ui';
20
23
  import { closestElement } from '@atlaskit/editor-common/utils';
21
24
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
@@ -52,6 +55,7 @@ export interface Props {
52
55
  hasStickyHeaders?: boolean;
53
56
  dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
54
57
  editorAnalyticsAPI?: EditorAnalyticsAPI;
58
+ getEditorFeatureFlags?: GetEditorFeatureFlags;
55
59
  }
56
60
 
57
61
  export class FloatingInsertButton extends React.Component<
@@ -284,11 +288,19 @@ export class FloatingInsertButton extends React.Component<
284
288
  if (typeof insertColumnButtonIndex !== 'undefined') {
285
289
  event.preventDefault();
286
290
 
291
+ const { tablePreserveWidth = false } =
292
+ this.props.getEditorFeatureFlags?.() || {};
293
+
287
294
  const { state, dispatch } = editorView;
288
- insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI)(
289
- INPUT_METHOD.BUTTON,
290
- insertColumnButtonIndex,
291
- )(state, dispatch, editorView);
295
+ insertColumnWithAnalytics(
296
+ getEditorContainerWidth,
297
+ editorAnalyticsAPI,
298
+ tablePreserveWidth,
299
+ )(INPUT_METHOD.BUTTON, insertColumnButtonIndex)(
300
+ state,
301
+ dispatch,
302
+ editorView,
303
+ );
292
304
  }
293
305
  }
294
306
  }
package/src/ui/consts.ts CHANGED
@@ -125,6 +125,7 @@ export const stickyRowOffsetTop = 8;
125
125
  export const stickyHeaderBorderBottomWidth = 1;
126
126
  export const tableOverflowShadowWidth = 8;
127
127
  export const tableOverflowShadowWidthWide = 32;
128
+ export const tablePopupMenuFitHeight = 188;
128
129
 
129
130
  export const dropTargetsZIndex = 14;
130
131
 
@@ -14,9 +14,7 @@ export const createTableWithWidth =
14
14
  },
15
15
  ) =>
16
16
  (schema: Schema) => {
17
- const { tablePreserveWidth = false } = getEditorFeatureFlags
18
- ? getEditorFeatureFlags()
19
- : {};
17
+ const { tablePreserveWidth = false } = getEditorFeatureFlags?.() || {};
20
18
 
21
19
  if (tablePreserveWidth && isFullWidthModeEnabled) {
22
20
  return createTable({
@@ -159,6 +159,7 @@ export const getDragMenuConfig = (
159
159
  selectionRect?: Rect,
160
160
  editorAnalyticsAPI?: EditorAnalyticsAPI,
161
161
  isHeaderRowRequired?: boolean,
162
+ tablePreserveWidth = false,
162
163
  ): DragMenuConfig[] => {
163
164
  const addOptions =
164
165
  direction === 'row'
@@ -296,6 +297,7 @@ export const getDragMenuConfig = (
296
297
  insertColumnWithAnalytics(
297
298
  getEditorContainerWidth,
298
299
  editorAnalyticsAPI,
300
+ tablePreserveWidth,
299
301
  )(INPUT_METHOD.TABLE_CONTEXT_MENU, (index ?? 0) + offset)(
300
302
  state,
301
303
  dispatch,
@@ -319,6 +321,7 @@ export const getDragMenuConfig = (
319
321
  state,
320
322
  editorView.domAtPos.bind(editorView),
321
323
  getEditorContainerWidth,
324
+ tablePreserveWidth,
322
325
  );
323
326
 
324
327
  if (newResizeState) {
@@ -359,7 +362,7 @@ export const getDragMenuConfig = (
359
362
  !!isHeaderRowRequired,
360
363
  )(state, dispatch);
361
364
  } else {
362
- deleteColumnsWithAnalytics(editorAnalyticsAPI)(
365
+ deleteColumnsWithAnalytics(editorAnalyticsAPI, tablePreserveWidth)(
363
366
  INPUT_METHOD.TABLE_CONTEXT_MENU,
364
367
  selectionRect ?? defaultSelectionRect,
365
368
  )(state, dispatch, editorView);