@atlaskit/editor-plugin-table 7.31.0 → 7.31.2

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 (92) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/commands/column-resize.js +10 -8
  3. package/dist/cjs/commands/misc.js +4 -4
  4. package/dist/cjs/event-handlers.js +69 -65
  5. package/dist/cjs/plugin.js +52 -48
  6. package/dist/cjs/pm-plugins/decorations/utils/column-resizing.js +2 -2
  7. package/dist/cjs/pm-plugins/keymap.js +18 -15
  8. package/dist/cjs/pm-plugins/main.js +2 -2
  9. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +2 -2
  10. package/dist/cjs/pm-plugins/table-resizing/plugin.js +2 -2
  11. package/dist/cjs/pm-plugins/view-mode-sort/index.js +35 -10
  12. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +12 -17
  13. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +8 -11
  14. package/dist/cjs/ui/FloatingDragMenu/index.js +1 -4
  15. package/dist/cjs/ui/FloatingDragMenu/styles.js +1 -2
  16. package/dist/cjs/utils/decoration.js +28 -8
  17. package/dist/cjs/utils/drag-menu.js +3 -4
  18. package/dist/es2019/commands/column-resize.js +10 -8
  19. package/dist/es2019/commands/misc.js +4 -4
  20. package/dist/es2019/event-handlers.js +4 -4
  21. package/dist/es2019/plugin.js +12 -7
  22. package/dist/es2019/pm-plugins/decorations/utils/column-resizing.js +2 -2
  23. package/dist/es2019/pm-plugins/keymap.js +7 -4
  24. package/dist/es2019/pm-plugins/main.js +2 -2
  25. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +2 -2
  26. package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
  27. package/dist/es2019/pm-plugins/view-mode-sort/index.js +33 -10
  28. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +1 -8
  29. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +8 -9
  30. package/dist/es2019/ui/FloatingDragMenu/index.js +1 -3
  31. package/dist/es2019/ui/FloatingDragMenu/styles.js +2 -2
  32. package/dist/es2019/utils/decoration.js +26 -9
  33. package/dist/es2019/utils/drag-menu.js +2 -2
  34. package/dist/esm/commands/column-resize.js +10 -8
  35. package/dist/esm/commands/misc.js +4 -4
  36. package/dist/esm/event-handlers.js +69 -65
  37. package/dist/esm/plugin.js +52 -48
  38. package/dist/esm/pm-plugins/decorations/utils/column-resizing.js +2 -2
  39. package/dist/esm/pm-plugins/keymap.js +18 -15
  40. package/dist/esm/pm-plugins/main.js +2 -2
  41. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +2 -2
  42. package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
  43. package/dist/esm/pm-plugins/view-mode-sort/index.js +35 -10
  44. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +12 -17
  45. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +8 -11
  46. package/dist/esm/ui/FloatingDragMenu/index.js +1 -4
  47. package/dist/esm/ui/FloatingDragMenu/styles.js +1 -2
  48. package/dist/esm/utils/decoration.js +28 -8
  49. package/dist/esm/utils/drag-menu.js +3 -4
  50. package/dist/types/commands/column-resize.d.ts +5 -2
  51. package/dist/types/commands/misc.d.ts +3 -2
  52. package/dist/types/event-handlers.d.ts +2 -1
  53. package/dist/types/pm-plugins/decorations/utils/column-resizing.d.ts +2 -1
  54. package/dist/types/pm-plugins/keymap.d.ts +2 -1
  55. package/dist/types/pm-plugins/main.d.ts +1 -1
  56. package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +2 -1
  57. package/dist/types/pm-plugins/table-resizing/plugin.d.ts +2 -1
  58. package/dist/types/pm-plugins/view-mode-sort/index.d.ts +2 -1
  59. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +0 -1
  60. package/dist/types/ui/FloatingDragMenu/styles.d.ts +1 -1
  61. package/dist/types/utils/decoration.d.ts +2 -1
  62. package/dist/types/utils/drag-menu.d.ts +1 -1
  63. package/dist/types-ts4.5/commands/column-resize.d.ts +5 -2
  64. package/dist/types-ts4.5/commands/misc.d.ts +3 -2
  65. package/dist/types-ts4.5/event-handlers.d.ts +2 -1
  66. package/dist/types-ts4.5/pm-plugins/decorations/utils/column-resizing.d.ts +2 -1
  67. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -1
  68. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  69. package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +2 -1
  70. package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +2 -1
  71. package/dist/types-ts4.5/pm-plugins/view-mode-sort/index.d.ts +2 -1
  72. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +0 -1
  73. package/dist/types-ts4.5/ui/FloatingDragMenu/styles.d.ts +1 -1
  74. package/dist/types-ts4.5/utils/decoration.d.ts +2 -1
  75. package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
  76. package/package.json +9 -5
  77. package/src/commands/column-resize.ts +18 -1
  78. package/src/commands/misc.ts +5 -0
  79. package/src/event-handlers.ts +22 -20
  80. package/src/plugin.tsx +10 -4
  81. package/src/pm-plugins/decorations/utils/column-resizing.ts +3 -0
  82. package/src/pm-plugins/keymap.ts +5 -0
  83. package/src/pm-plugins/main.ts +2 -1
  84. package/src/pm-plugins/table-resizing/event-handlers.ts +8 -1
  85. package/src/pm-plugins/table-resizing/plugin.ts +3 -0
  86. package/src/pm-plugins/view-mode-sort/index.ts +73 -34
  87. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +1 -5
  88. package/src/ui/FloatingDragMenu/DragMenu.tsx +5 -14
  89. package/src/ui/FloatingDragMenu/index.tsx +2 -6
  90. package/src/ui/FloatingDragMenu/styles.ts +4 -6
  91. package/src/utils/decoration.ts +39 -13
  92. package/src/utils/drag-menu.ts +1 -2
@@ -15,7 +15,7 @@ import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resize
15
15
  import { TABLE_OFFSET_IN_COMMENT_EDITOR } from './utils/consts';
16
16
  import { getScalingPercentForTableWithoutWidth, getTableScalingPercent } from './utils/misc';
17
17
  import { scaleResizeState } from './utils/resize-column';
18
- export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, api, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled, isCommentEditor) => {
18
+ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, api, nodeViewPortalProviderAPI, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled, isCommentEditor) => {
19
19
  var _originalTable$attrs;
20
20
  const {
21
21
  state,
@@ -104,7 +104,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
104
104
 
105
105
  // When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
106
106
  // unnecessary tooltips being displayed during drag.
107
- updateResizeHandleDecorations(undefined, undefined, false)(state, dispatch);
107
+ updateResizeHandleDecorations(nodeViewPortalProviderAPI, undefined, undefined, false)(state, dispatch);
108
108
 
109
109
  // for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
110
110
  // implication: the scaled version of the table becomes the source of truth
@@ -9,7 +9,7 @@ import { pluginKey } from './plugin-key';
9
9
  import { getResizeCellPos } from './utils';
10
10
  export function createPlugin(dispatch, {
11
11
  lastColumnResizable = true
12
- }, getEditorContainerWidth, getEditorFeatureFlags, api, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled, isTableAlignmentEnabled, isCommentEditor) {
12
+ }, getEditorContainerWidth, getEditorFeatureFlags, api, nodeViewPortalProviderAPI, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled, isTableAlignmentEnabled, isCommentEditor) {
13
13
  return new SafePlugin({
14
14
  key: pluginKey,
15
15
  state: createPluginState(dispatch, {
@@ -51,7 +51,7 @@ export function createPlugin(dispatch, {
51
51
  isColumnKeyboardResizeStarted = isKeyboardResize;
52
52
  }
53
53
  if (resizeHandlePos !== null && (!dragging || isColumnKeyboardResizeStarted)) {
54
- if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, api, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled, isCommentEditor)) {
54
+ if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, api, nodeViewPortalProviderAPI, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled, isCommentEditor)) {
55
55
  const {
56
56
  state,
57
57
  dispatch
@@ -7,16 +7,18 @@
7
7
  import { createElement } from 'react';
8
8
  import ReactDOM from 'react-dom';
9
9
  import { RawIntlProvider } from 'react-intl-next';
10
+ import uuid from 'uuid/v4';
10
11
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
11
12
  import { SortOrder } from '@atlaskit/editor-common/types';
12
13
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
13
14
  import { TableMap } from '@atlaskit/editor-tables/table-map';
15
+ import { fg } from '@atlaskit/platform-feature-flags';
14
16
  import { SortingIconWrapper } from '../../ui/icons/SortingIconWrapper';
15
17
  import { getPluginState } from '../plugin-factory';
16
18
  import { IS_DISABLED_CLASS_NAME, SORT_INDEX_DATA_ATTRIBUTE, SORTING_ICON_CLASS_NAME } from './consts';
17
19
  import { tableViewModeSortPluginKey as key } from './plugin-key';
18
20
  import { getTableElements, toggleSort } from './utils';
19
- export const createPlugin = api => {
21
+ export const createPlugin = (api, nodeViewPortalProviderAPI) => {
20
22
  return new SafePlugin({
21
23
  state: {
22
24
  init: () => ({
@@ -78,6 +80,7 @@ export const createPlugin = api => {
78
80
  const map = TableMap.get(tableNode);
79
81
  const hasMergedCells = new Set(map.map).size !== map.map.length;
80
82
  map.mapByRow[0].forEach((cell, index) => {
83
+ const decorationRenderKey = uuid();
81
84
  decs.push(Decoration.widget(cell + pos + 2, () => {
82
85
  var _sort$tableId;
83
86
  const element = document.createElement('div');
@@ -96,16 +99,36 @@ export const createPlugin = api => {
96
99
  const {
97
100
  getIntl
98
101
  } = getPluginState(oldState);
99
- ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
100
- value: getIntl()
101
- }, /*#__PURE__*/createElement(SortingIconWrapper, {
102
- isSortingAllowed: !hasMergedCells,
103
- sortOrdered,
104
- onClick: () => {},
105
- onKeyDown: () => {},
106
- api
107
- })), element);
102
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
103
+ nodeViewPortalProviderAPI.render(() => /*#__PURE__*/createElement(RawIntlProvider, {
104
+ value: getIntl()
105
+ }, /*#__PURE__*/createElement(SortingIconWrapper, {
106
+ isSortingAllowed: !hasMergedCells,
107
+ sortOrdered,
108
+ onClick: () => {},
109
+ onKeyDown: () => {},
110
+ api
111
+ })), element, decorationRenderKey);
112
+ } else {
113
+ ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
114
+ value: getIntl()
115
+ }, /*#__PURE__*/createElement(SortingIconWrapper, {
116
+ isSortingAllowed: !hasMergedCells,
117
+ sortOrdered,
118
+ onClick: () => {},
119
+ onKeyDown: () => {},
120
+ api
121
+ })), element);
122
+ }
108
123
  return element;
124
+ }, {
125
+ destroy: node => {
126
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
127
+ nodeViewPortalProviderAPI.remove(decorationRenderKey);
128
+ } else {
129
+ ReactDOM.unmountComponentAtNode(node);
130
+ }
131
+ }
109
132
  }));
110
133
  });
111
134
  });
@@ -450,16 +450,10 @@ export class ContextualMenu extends Component {
450
450
  });
451
451
  _defineProperty(this, "createOriginalContextMenuItems", () => {
452
452
  let items = [];
453
- const {
454
- getEditorFeatureFlags
455
- } = this.props;
456
- const {
457
- tableSortColumnReorder = false
458
- } = getEditorFeatureFlags ? getEditorFeatureFlags() : {};
459
453
  const sortColumnItems = this.createSortColumnItems();
460
454
  const backgroundColorItem = this.createBackgroundColorItem();
461
455
  const distributeColumnsItem = this.createDistributeColumnsItem();
462
- tableSortColumnReorder && sortColumnItems && items.push(...sortColumnItems);
456
+ sortColumnItems && items.push(...sortColumnItems);
463
457
  backgroundColorItem && items.push(backgroundColorItem);
464
458
  items.push(this.createInsertColumnItem());
465
459
  items.push(this.createInsertRowItem());
@@ -467,7 +461,6 @@ export class ContextualMenu extends Component {
467
461
  items.push(this.createDeleteRowItem());
468
462
  items.push(...this.createMergeSplitCellItems());
469
463
  distributeColumnsItem && items.push(distributeColumnsItem);
470
- !tableSortColumnReorder && sortColumnItems && items.push(...sortColumnItems);
471
464
  items.push(this.createClearCellsItem());
472
465
  return [{
473
466
  items
@@ -92,18 +92,18 @@ const MapDragMenuOptionIdToMessage = {
92
92
  plural: null
93
93
  }
94
94
  };
95
- const getGroupedDragMenuConfig = tableSortColumnReorder => {
95
+ const getGroupedDragMenuConfig = () => {
96
96
  let groupedDragMenuConfig = [['add_row_above', 'add_row_below', 'add_column_left', 'add_column_right', 'distribute_columns', 'clear_cells', 'delete_row', 'delete_column'], ['move_column_left', 'move_column_right', 'move_row_up', 'move_row_down']];
97
97
  const sortColumnItems = ['sort_column_asc', 'sort_column_desc'];
98
- tableSortColumnReorder ? groupedDragMenuConfig.unshift(sortColumnItems) : groupedDragMenuConfig.push(sortColumnItems);
98
+ groupedDragMenuConfig.unshift(sortColumnItems);
99
99
  return groupedDragMenuConfig;
100
100
  };
101
101
  const elementBeforeIconStyles = xcss({
102
102
  marginRight: 'space.negative.075',
103
103
  display: 'flex'
104
104
  });
105
- const convertToDropdownItems = (dragMenuConfig, formatMessage, tableSortColumnReorder = false, selectionRect) => {
106
- const groupedDragMenuConfig = getGroupedDragMenuConfig(tableSortColumnReorder);
105
+ const convertToDropdownItems = (dragMenuConfig, formatMessage, selectionRect) => {
106
+ const groupedDragMenuConfig = getGroupedDragMenuConfig();
107
107
  let menuItemsArr = [...Array(groupedDragMenuConfig.length)].map(() => []);
108
108
  let menuCallback = {};
109
109
  dragMenuConfig.forEach(item => {
@@ -199,7 +199,6 @@ const DragMenu = /*#__PURE__*/React.memo(({
199
199
  tableDuplicateCellColouring,
200
200
  shouldUseIncreasedScalingPercent,
201
201
  isTableFixedColumnWidthsOptionEnabled,
202
- tableSortColumnReorder,
203
202
  ariaNotifyPlugin,
204
203
  isCommentEditor
205
204
  }) => {
@@ -219,11 +218,11 @@ const DragMenu = /*#__PURE__*/React.memo(({
219
218
  const selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
220
219
  const hasMergedCellsInTable = (_tableMap$hasMergedCe = tableMap === null || tableMap === void 0 ? void 0 : tableMap.hasMergedCells()) !== null && _tableMap$hasMergedCe !== void 0 ? _tableMap$hasMergedCe : false;
221
220
  const allowBackgroundColor = (_pluginConfig$allowBa = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.allowBackgroundColor) !== null && _pluginConfig$allowBa !== void 0 ? _pluginConfig$allowBa : false;
222
- const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, hasMergedCellsInTable, editorView, api, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.isHeaderRowRequired, isTableScalingEnabled, tableDuplicateCellColouring, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, tableSortColumnReorder, ariaNotifyPlugin, isCommentEditor);
221
+ const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, hasMergedCellsInTable, editorView, api, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.isHeaderRowRequired, isTableScalingEnabled, tableDuplicateCellColouring, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, ariaNotifyPlugin, isCommentEditor);
223
222
  const {
224
223
  menuItems,
225
224
  menuCallback
226
- } = convertToDropdownItems(dragMenuConfig, formatMessage, tableSortColumnReorder, selectionRect);
225
+ } = convertToDropdownItems(dragMenuConfig, formatMessage, selectionRect);
227
226
  const handleSubMenuRef = ref => {
228
227
  const parent = closestElement(editorView.dom, '.fabric-editor-popup-scroll-parent');
229
228
  if (!(parent && ref)) {
@@ -274,7 +273,7 @@ const DragMenu = /*#__PURE__*/React.memo(({
274
273
  className: DropdownMenuSharedCssClassName.SUBMENU
275
274
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
276
275
  ,
277
- css: dragMenuBackgroundColorStyles(tableSortColumnReorder)
276
+ css: dragMenuBackgroundColorStyles()
278
277
  }, jsx("div", {
279
278
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
280
279
  css: cellColourPreviewStyles(background)
@@ -477,7 +476,7 @@ const DragMenu = /*#__PURE__*/React.memo(({
477
476
  return null;
478
477
  }
479
478
  if (allowBackgroundColor) {
480
- tableSortColumnReorder ? menuItems[1].items.unshift(createBackgroundColorMenuItem()) : menuItems[0].items.unshift(createBackgroundColorMenuItem());
479
+ menuItems[1].items.unshift(createBackgroundColorMenuItem());
481
480
  }
482
481
 
483
482
  // If first row, add toggle for Header row, default is true
@@ -35,8 +35,7 @@ const FloatingDragMenu = ({
35
35
  }
36
36
  const {
37
37
  tableDuplicateCellColouring = false,
38
- tableWithFixedColumnWidthsOption = false,
39
- tableSortColumnReorder = false
38
+ tableWithFixedColumnWidthsOption = false
40
39
  } = getEditorFeatureFlags ? getEditorFeatureFlags() : {};
41
40
  const shouldUseIncreasedScalingPercent = isTableScalingEnabled && (tableWithFixedColumnWidthsOption || isCommentEditor);
42
41
  return /*#__PURE__*/React.createElement(Popup, {
@@ -76,7 +75,6 @@ const FloatingDragMenu = ({
76
75
  tableDuplicateCellColouring: tableDuplicateCellColouring,
77
76
  shouldUseIncreasedScalingPercent: shouldUseIncreasedScalingPercent,
78
77
  isTableFixedColumnWidthsOptionEnabled: tableWithFixedColumnWidthsOption,
79
- tableSortColumnReorder: tableSortColumnReorder,
80
78
  ariaNotifyPlugin: ariaNotifyPlugin,
81
79
  api: api,
82
80
  isCommentEditor: isCommentEditor || false
@@ -12,14 +12,14 @@ export const cellColourPreviewStyles = selectedColor => css({
12
12
  });
13
13
 
14
14
  // eslint-disable-next-line @atlaskit/design-system/no-css-tagged-template-expression -- needs manual remediation
15
- export const dragMenuBackgroundColorStyles = (tableSortColumnReorder = false) => css`
15
+ export const dragMenuBackgroundColorStyles = () => css`
16
16
  .${ClassName.DRAG_SUBMENU} {
17
17
  border-radius: ${"var(--ds-border-radius, 3px)"};
18
18
  background: ${"var(--ds-surface-overlay, white)"};
19
19
  box-shadow: ${`var(--ds-shadow-overlay, ${`0 4px 8px -2px ${N60A}, 0 0 1px ${N60A}`})`};
20
20
  display: block;
21
21
  position: absolute;
22
- top: ${tableSortColumnReorder ? TABLE_DRAG_MENU_PADDING_TOP + TABLE_DRAG_MENU_SORT_GROUP_HEIGHT + TABLE_DRAG_MENU_MENU_GROUP_BEFORE_HEIGHT : 0}px; // move the submenu down when 'sort increasing/decreasing' appear before background color picker
22
+ top: ${TABLE_DRAG_MENU_PADDING_TOP + TABLE_DRAG_MENU_SORT_GROUP_HEIGHT + TABLE_DRAG_MENU_MENU_GROUP_BEFORE_HEIGHT}px; // move the submenu down when 'sort increasing/decreasing' appear before background color picker
23
23
  left: ${dragMenuDropdownWidth}px;
24
24
  padding: ${"var(--ds-space-100, 8px)"};
25
25
 
@@ -1,6 +1,7 @@
1
1
  import { createElement } from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import { RawIntlProvider } from 'react-intl-next';
4
+ import uuid from 'uuid/v4';
4
5
  import { nonNullable } from '@atlaskit/editor-common/utils';
5
6
 
6
7
  // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
@@ -8,6 +9,7 @@ import { nonNullable } from '@atlaskit/editor-common/utils';
8
9
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
9
10
  import { TableMap } from '@atlaskit/editor-tables/table-map';
10
11
  import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
12
+ import { fg } from '@atlaskit/platform-feature-flags';
11
13
  import { TableCssClassName as ClassName, TableDecorations } from '../types';
12
14
  import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
13
15
  const filterDecorationByKey = (key, decorationSet) => decorationSet.find(undefined, undefined, spec => spec.key.indexOf(key) > -1);
@@ -221,7 +223,7 @@ const makeArray = n => Array.from(Array(n).keys());
221
223
  * we will add a new class on the last item for each cell,
222
224
  * hence the second media will receive this class `ClassName.LAST_ITEM_IN_CELL`
223
225
  */
224
- export const createResizeHandleDecoration = (tr, rowIndexTarget, columnEndIndexTarget, includeTooltip = false, getIntl) => {
226
+ export const createResizeHandleDecoration = (tr, rowIndexTarget, columnEndIndexTarget, includeTooltip = false, getIntl, nodeViewPortalProviderAPI) => {
225
227
  const emptyResult = [[], []];
226
228
  const table = findTable(tr.selection);
227
229
  if (!table || !table.node) {
@@ -232,21 +234,36 @@ export const createResizeHandleDecoration = (tr, rowIndexTarget, columnEndIndexT
232
234
  return emptyResult;
233
235
  }
234
236
  const createResizerHandleDecoration = (cellColumnPositioning, columnIndex, rowIndex, cellPos, cellNode) => {
237
+ const decorationRenderKey = uuid();
235
238
  const position = cellPos + cellNode.nodeSize - 1;
236
239
  return Decoration.widget(position, () => {
237
240
  const element = document.createElement('div');
238
- ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
239
- value: getIntl()
240
- }, /*#__PURE__*/createElement(ColumnResizeWidget, {
241
- startIndex: cellColumnPositioning.left,
242
- endIndex: cellColumnPositioning.right,
243
- includeTooltip
244
- })), element);
241
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
242
+ nodeViewPortalProviderAPI.render(() => /*#__PURE__*/createElement(RawIntlProvider, {
243
+ value: getIntl()
244
+ }, /*#__PURE__*/createElement(ColumnResizeWidget, {
245
+ startIndex: cellColumnPositioning.left,
246
+ endIndex: cellColumnPositioning.right,
247
+ includeTooltip
248
+ })), element, decorationRenderKey);
249
+ } else {
250
+ ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
251
+ value: getIntl()
252
+ }, /*#__PURE__*/createElement(ColumnResizeWidget, {
253
+ startIndex: cellColumnPositioning.left,
254
+ endIndex: cellColumnPositioning.right,
255
+ includeTooltip
256
+ })), element);
257
+ }
245
258
  return element;
246
259
  }, {
247
260
  key: `${TableDecorations.COLUMN_RESIZING_HANDLE_WIDGET}_${rowIndex}_${columnIndex}_${includeTooltip ? 'with' : 'no'}-tooltip`,
248
261
  destroy: node => {
249
- ReactDOM.unmountComponentAtNode(node);
262
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
263
+ nodeViewPortalProviderAPI.remove(decorationRenderKey);
264
+ } else {
265
+ ReactDOM.unmountComponentAtNode(node);
266
+ }
250
267
  }
251
268
  });
252
269
  };
@@ -72,7 +72,7 @@ const defaultSelectionRect = {
72
72
  right: 0,
73
73
  bottom: 0
74
74
  };
75
- export const getDragMenuConfig = (direction, getEditorContainerWidth, hasMergedCellsInTable, editorView, api, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, isHeaderRowRequired, isTableScalingEnabled = false, tableDuplicateCellColouring = false, isTableFixedColumnWidthsOptionEnabled = false, shouldUseIncreasedScalingPercent = false, tableSortColumnReorder = false, ariaNotifyPlugin, isCommentEditor = false) => {
75
+ export const getDragMenuConfig = (direction, getEditorContainerWidth, hasMergedCellsInTable, editorView, api, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, isHeaderRowRequired, isTableScalingEnabled = false, tableDuplicateCellColouring = false, isTableFixedColumnWidthsOptionEnabled = false, shouldUseIncreasedScalingPercent = false, ariaNotifyPlugin, isCommentEditor = false) => {
76
76
  var _tableMap$height, _tableMap$height2, _tableMap$width, _tableMap$width2;
77
77
  const {
78
78
  selection
@@ -256,6 +256,6 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, hasMergedC
256
256
  keymap: keymap && tooltip(keymap)
257
257
  }))];
258
258
  let allConfigs = [...restConfigs];
259
- tableSortColumnReorder ? allConfigs.unshift(...sortConfigs) : allConfigs.push(...sortConfigs);
259
+ allConfigs.unshift(...sortConfigs);
260
260
  return allConfigs.filter(Boolean);
261
261
  };
@@ -19,7 +19,7 @@ var getTablePluginCommand = function getTablePluginCommand(actionPayload, origin
19
19
  return (originalTr || tr).setMeta('addToHistory', false);
20
20
  });
21
21
  };
22
- var updateResizeHandleAndStatePosition = function updateResizeHandleAndStatePosition(rowIndex, columnIndex, nextResizeHandlePos) {
22
+ var updateResizeHandleAndStatePosition = function updateResizeHandleAndStatePosition(rowIndex, columnIndex, nextResizeHandlePos, nodeViewPortalProviderAPI) {
23
23
  return function (state, dispatch) {
24
24
  var customTr = state.tr;
25
25
  var _getPluginState = getPluginState(state),
@@ -31,7 +31,7 @@ var updateResizeHandleAndStatePosition = function updateResizeHandleAndStatePosi
31
31
  if (!allowColumnResizing) {
32
32
  return false;
33
33
  }
34
- var decorationsWithWidget = buildColumnResizingDecorations(rowIndex, columnIndex, true, getIntl)({
34
+ var decorationsWithWidget = buildColumnResizingDecorations(rowIndex, columnIndex, true, getIntl, nodeViewPortalProviderAPI)({
35
35
  tr: customTr,
36
36
  decorationSet: getDecorations(state)
37
37
  });
@@ -63,7 +63,8 @@ var updateResizeHandleAndStatePosition = function updateResizeHandleAndStatePosi
63
63
  };
64
64
  export var initiateKeyboardColumnResizing = function initiateKeyboardColumnResizing(_ref) {
65
65
  var ariaNotify = _ref.ariaNotify,
66
- getIntl = _ref.getIntl;
66
+ getIntl = _ref.getIntl,
67
+ nodeViewPortalProviderAPI = _ref.nodeViewPortalProviderAPI;
67
68
  return function (state, dispatch, view) {
68
69
  var selection = state.selection;
69
70
  var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
@@ -74,7 +75,7 @@ export var initiateKeyboardColumnResizing = function initiateKeyboardColumnResiz
74
75
  });
75
76
  }
76
77
  if (selectionRect && cell && view) {
77
- return updateResizeHandleAndStatePosition(selectionRect.top, selectionRect.right, cell.pos)(state, dispatch);
78
+ return updateResizeHandleAndStatePosition(selectionRect.top, selectionRect.right, cell.pos, nodeViewPortalProviderAPI)(state, dispatch);
78
79
  }
79
80
  return false;
80
81
  };
@@ -82,7 +83,8 @@ export var initiateKeyboardColumnResizing = function initiateKeyboardColumnResiz
82
83
  export var activateNextResizeArea = function activateNextResizeArea(_ref2) {
83
84
  var direction = _ref2.direction,
84
85
  ariaNotify = _ref2.ariaNotify,
85
- getIntl = _ref2.getIntl;
86
+ getIntl = _ref2.getIntl,
87
+ nodeViewPortalProviderAPI = _ref2.nodeViewPortalProviderAPI;
86
88
  return function (state, dispatch, view) {
87
89
  var _ref3 = getTableResizingPluginState(state) || {},
88
90
  resizeHandlePos = _ref3.resizeHandlePos;
@@ -128,17 +130,17 @@ export var activateNextResizeArea = function activateNextResizeArea(_ref2) {
128
130
  // we are somewhere in between the side columns of the table
129
131
  var offset = $nextCell.pos - $nextCell.start(-1);
130
132
  var rectForNextCell = tableMap.findCell(offset);
131
- return updateResizeHandleAndStatePosition(rectForNextCell.top, rectForNextCell.right, $nextCell.pos)(state, dispatch, view);
133
+ return updateResizeHandleAndStatePosition(rectForNextCell.top, rectForNextCell.right, $nextCell.pos, nodeViewPortalProviderAPI)(state, dispatch, view);
132
134
  } else {
133
135
  // current position is in the one of the side columns of the table(left or right)
134
136
  if (currentCellRect.left === 0) {
135
137
  var lastCellInCurrentRow = tableMap.positionAt(currentCellRect.top, tableMap.width - 1, tableNode) + closestTable.start;
136
138
  var $lastCell = state.doc.resolve(lastCellInCurrentRow);
137
- return updateResizeHandleAndStatePosition(currentCellRect.top, tableMap.width, $lastCell.pos)(state, dispatch, view);
139
+ return updateResizeHandleAndStatePosition(currentCellRect.top, tableMap.width, $lastCell.pos, nodeViewPortalProviderAPI)(state, dispatch, view);
138
140
  } else if (tableMap.width === currentCellRect.right) {
139
141
  var firsCellInCurrentRow = tableMap.positionAt(currentCellRect.top, 0, tableNode) + closestTable.start;
140
142
  var _$nextCell = state.doc.resolve(firsCellInCurrentRow);
141
- return updateResizeHandleAndStatePosition(currentCellRect.top, 1, _$nextCell.pos)(state, dispatch);
143
+ return updateResizeHandleAndStatePosition(currentCellRect.top, 1, _$nextCell.pos, nodeViewPortalProviderAPI)(state, dispatch);
142
144
  }
143
145
  }
144
146
  return false;
@@ -462,7 +462,7 @@ export var hideInsertColumnOrRowButton = function hideInsertColumnOrRowButton()
462
462
  return tr.setMeta('addToHistory', false);
463
463
  });
464
464
  };
465
- export var addResizeHandleDecorations = function addResizeHandleDecorations(rowIndex, columnIndex, includeTooltip, isKeyboardResize) {
465
+ export var addResizeHandleDecorations = function addResizeHandleDecorations(rowIndex, columnIndex, includeTooltip, nodeViewPortalProviderAPI, isKeyboardResize) {
466
466
  return createCommand(function (state) {
467
467
  var tableNode = findTable(state.selection);
468
468
  var _getPluginState3 = getPluginState(state),
@@ -474,7 +474,7 @@ export var addResizeHandleDecorations = function addResizeHandleDecorations(rowI
474
474
  return {
475
475
  type: 'ADD_RESIZE_HANDLE_DECORATIONS',
476
476
  data: {
477
- decorationSet: buildColumnResizingDecorations(rowIndex, columnIndex, includeTooltip, getIntl)({
477
+ decorationSet: buildColumnResizingDecorations(rowIndex, columnIndex, includeTooltip, getIntl, nodeViewPortalProviderAPI)({
478
478
  tr: state.tr,
479
479
  decorationSet: getDecorations(state)
480
480
  }),
@@ -488,7 +488,7 @@ export var addResizeHandleDecorations = function addResizeHandleDecorations(rowI
488
488
  return tr.setMeta('addToHistory', false);
489
489
  });
490
490
  };
491
- export var updateResizeHandleDecorations = function updateResizeHandleDecorations(rowIndex, columnIndex, includeTooltip) {
491
+ export var updateResizeHandleDecorations = function updateResizeHandleDecorations(nodeViewPortalProviderAPI, rowIndex, columnIndex, includeTooltip) {
492
492
  return createCommand(function (state) {
493
493
  var tableNode = findTable(state.selection);
494
494
  var _getPluginState4 = getPluginState(state),
@@ -509,7 +509,7 @@ export var updateResizeHandleDecorations = function updateResizeHandleDecoration
509
509
  return {
510
510
  type: 'UPDATE_RESIZE_HANDLE_DECORATIONS',
511
511
  data: {
512
- decorationSet: buildColumnResizingDecorations(resolvedRowIndex, resolvedColumnIndex, resolvedIncludeTooltip, getIntl)({
512
+ decorationSet: buildColumnResizingDecorations(resolvedRowIndex, resolvedColumnIndex, resolvedIncludeTooltip, getIntl, nodeViewPortalProviderAPI)({
513
513
  tr: state.tr,
514
514
  decorationSet: getDecorations(state)
515
515
  }),
@@ -245,78 +245,82 @@ export var handleMouseLeave = function handleMouseLeave(view, event) {
245
245
 
246
246
  // IMPORTANT: The mouse move handler has been setup with RAF schedule to avoid Reflows which will occur as some methods
247
247
  // need to access the mouse event offset position and also the target clientWidth vallue.
248
- var handleMouseMoveDebounce = rafSchedule(function (view, event, offsetX) {
249
- if (!(event.target instanceof HTMLElement)) {
250
- return false;
251
- }
252
- var element = event.target;
253
- if (isColumnControlsDecorations(element) || isDragColumnFloatingInsertDot(element)) {
254
- var state = view.state,
255
- dispatch = view.dispatch;
256
- var _getPluginState6 = getPluginState(state),
257
- insertColumnButtonIndex = _getPluginState6.insertColumnButtonIndex;
258
- var _getColumnOrRowIndex9 = getColumnOrRowIndex(element),
259
- _getColumnOrRowIndex10 = _slicedToArray(_getColumnOrRowIndex9, 2),
260
- startIndex = _getColumnOrRowIndex10[0],
261
- endIndex = _getColumnOrRowIndex10[1];
262
- var positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, undefined) === 'right' ? endIndex : startIndex;
263
- if (positionColumn !== insertColumnButtonIndex) {
264
- return showInsertColumnButton(positionColumn)(state, dispatch);
248
+ var handleMouseMoveDebounce = function handleMouseMoveDebounce(nodeViewPortalProviderAPI) {
249
+ return rafSchedule(function (view, event, offsetX) {
250
+ if (!(event.target instanceof HTMLElement)) {
251
+ return false;
265
252
  }
266
- }
267
- if (isRowControlsButton(element) || isDragRowFloatingInsertDot(element)) {
268
- var _state3 = view.state,
269
- _dispatch4 = view.dispatch;
270
- var _getPluginState7 = getPluginState(_state3),
271
- insertRowButtonIndex = _getPluginState7.insertRowButtonIndex;
272
- var _getColumnOrRowIndex11 = getColumnOrRowIndex(element),
273
- _getColumnOrRowIndex12 = _slicedToArray(_getColumnOrRowIndex11, 2),
274
- _startIndex3 = _getColumnOrRowIndex12[0],
275
- _endIndex2 = _getColumnOrRowIndex12[1];
276
- var positionRow = getMousePositionVerticalRelativeByElement(event) === 'bottom' ? _endIndex2 : _startIndex3;
277
- if (positionRow !== insertRowButtonIndex) {
278
- return showInsertRowButton(positionRow)(_state3, _dispatch4);
253
+ var element = event.target;
254
+ if (isColumnControlsDecorations(element) || isDragColumnFloatingInsertDot(element)) {
255
+ var state = view.state,
256
+ dispatch = view.dispatch;
257
+ var _getPluginState6 = getPluginState(state),
258
+ insertColumnButtonIndex = _getPluginState6.insertColumnButtonIndex;
259
+ var _getColumnOrRowIndex9 = getColumnOrRowIndex(element),
260
+ _getColumnOrRowIndex10 = _slicedToArray(_getColumnOrRowIndex9, 2),
261
+ startIndex = _getColumnOrRowIndex10[0],
262
+ endIndex = _getColumnOrRowIndex10[1];
263
+ var positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, undefined) === 'right' ? endIndex : startIndex;
264
+ if (positionColumn !== insertColumnButtonIndex) {
265
+ return showInsertColumnButton(positionColumn)(state, dispatch);
266
+ }
279
267
  }
280
- }
281
- if (!isResizeHandleDecoration(element) && isCell(element)) {
282
- var _positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, RESIZE_HANDLE_AREA_DECORATION_GAP);
283
- if (_positionColumn !== null) {
284
- var _state4 = view.state,
285
- _dispatch5 = view.dispatch;
286
- var _getPluginState8 = getPluginState(_state4),
287
- resizeHandleColumnIndex = _getPluginState8.resizeHandleColumnIndex,
288
- resizeHandleRowIndex = _getPluginState8.resizeHandleRowIndex;
289
- var isKeyboardResize = getPluginState(_state4).isKeyboardResize;
290
- var tableCell = closestElement(element, 'td, th');
291
- var cellStartPosition = view.posAtDOM(tableCell, 0);
292
- var rect = findCellRectClosestToPos(_state4.doc.resolve(cellStartPosition));
293
- if (rect) {
294
- var columnEndIndexTarget = _positionColumn === 'left' ? rect.left : rect.right;
295
- var rowIndexTarget = rect.top;
296
- if ((columnEndIndexTarget !== resizeHandleColumnIndex || rowIndexTarget !== resizeHandleRowIndex || !hasResizeHandler({
297
- target: element,
298
- columnEndIndexTarget: columnEndIndexTarget
299
- })) && !isKeyboardResize // if initiated by keyboard don't need to react on hover for other resize sliders
300
- ) {
301
- return addResizeHandleDecorations(rowIndexTarget, columnEndIndexTarget, true)(_state4, _dispatch5);
268
+ if (isRowControlsButton(element) || isDragRowFloatingInsertDot(element)) {
269
+ var _state3 = view.state,
270
+ _dispatch4 = view.dispatch;
271
+ var _getPluginState7 = getPluginState(_state3),
272
+ insertRowButtonIndex = _getPluginState7.insertRowButtonIndex;
273
+ var _getColumnOrRowIndex11 = getColumnOrRowIndex(element),
274
+ _getColumnOrRowIndex12 = _slicedToArray(_getColumnOrRowIndex11, 2),
275
+ _startIndex3 = _getColumnOrRowIndex12[0],
276
+ _endIndex2 = _getColumnOrRowIndex12[1];
277
+ var positionRow = getMousePositionVerticalRelativeByElement(event) === 'bottom' ? _endIndex2 : _startIndex3;
278
+ if (positionRow !== insertRowButtonIndex) {
279
+ return showInsertRowButton(positionRow)(_state3, _dispatch4);
280
+ }
281
+ }
282
+ if (!isResizeHandleDecoration(element) && isCell(element)) {
283
+ var _positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, RESIZE_HANDLE_AREA_DECORATION_GAP);
284
+ if (_positionColumn !== null) {
285
+ var _state4 = view.state,
286
+ _dispatch5 = view.dispatch;
287
+ var _getPluginState8 = getPluginState(_state4),
288
+ resizeHandleColumnIndex = _getPluginState8.resizeHandleColumnIndex,
289
+ resizeHandleRowIndex = _getPluginState8.resizeHandleRowIndex;
290
+ var isKeyboardResize = getPluginState(_state4).isKeyboardResize;
291
+ var tableCell = closestElement(element, 'td, th');
292
+ var cellStartPosition = view.posAtDOM(tableCell, 0);
293
+ var rect = findCellRectClosestToPos(_state4.doc.resolve(cellStartPosition));
294
+ if (rect) {
295
+ var columnEndIndexTarget = _positionColumn === 'left' ? rect.left : rect.right;
296
+ var rowIndexTarget = rect.top;
297
+ if ((columnEndIndexTarget !== resizeHandleColumnIndex || rowIndexTarget !== resizeHandleRowIndex || !hasResizeHandler({
298
+ target: element,
299
+ columnEndIndexTarget: columnEndIndexTarget
300
+ })) && !isKeyboardResize // if initiated by keyboard don't need to react on hover for other resize sliders
301
+ ) {
302
+ return addResizeHandleDecorations(rowIndexTarget, columnEndIndexTarget, true, nodeViewPortalProviderAPI)(_state4, _dispatch5);
303
+ }
302
304
  }
303
305
  }
304
306
  }
305
- }
306
- return false;
307
- });
308
- export var handleMouseMove = function handleMouseMove(view, event) {
309
- if (!(event.target instanceof HTMLElement)) {
310
307
  return false;
311
- }
308
+ });
309
+ };
310
+ export var handleMouseMove = function handleMouseMove(nodeViewPortalProviderAPI) {
311
+ return function (view, event) {
312
+ if (!(event.target instanceof HTMLElement)) {
313
+ return false;
314
+ }
312
315
 
313
- // NOTE: When accessing offsetX in gecko from a deferred callback, it will return 0. However it will be non-zero if accessed
314
- // within the scope of it's initial mouse move handler. Also Chrome does return the correct value, however it could trigger
315
- // a reflow. So for now this will just grab the offsetX value immediately for gecko and chrome will calculate later
316
- // in the deferred callback handler.
317
- // Bug Tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=1882903
318
- handleMouseMoveDebounce(view, event, browser.gecko ? event.offsetX : NaN);
319
- return false;
316
+ // NOTE: When accessing offsetX in gecko from a deferred callback, it will return 0. However it will be non-zero if accessed
317
+ // within the scope of it's initial mouse move handler. Also Chrome does return the correct value, however it could trigger
318
+ // a reflow. So for now this will just grab the offsetX value immediately for gecko and chrome will calculate later
319
+ // in the deferred callback handler.
320
+ // Bug Tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=1882903
321
+ handleMouseMoveDebounce(nodeViewPortalProviderAPI)(view, event, browser.gecko ? event.offsetX : NaN);
322
+ return false;
323
+ };
320
324
  };
321
325
  export function handleTripleClick(view, pos) {
322
326
  var state = view.state,