@atlaskit/editor-plugin-table 7.31.0 → 7.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +9 -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/utils/decoration.js +28 -8
  13. package/dist/es2019/commands/column-resize.js +10 -8
  14. package/dist/es2019/commands/misc.js +4 -4
  15. package/dist/es2019/event-handlers.js +4 -4
  16. package/dist/es2019/plugin.js +12 -7
  17. package/dist/es2019/pm-plugins/decorations/utils/column-resizing.js +2 -2
  18. package/dist/es2019/pm-plugins/keymap.js +7 -4
  19. package/dist/es2019/pm-plugins/main.js +2 -2
  20. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +2 -2
  21. package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
  22. package/dist/es2019/pm-plugins/view-mode-sort/index.js +33 -10
  23. package/dist/es2019/utils/decoration.js +26 -9
  24. package/dist/esm/commands/column-resize.js +10 -8
  25. package/dist/esm/commands/misc.js +4 -4
  26. package/dist/esm/event-handlers.js +69 -65
  27. package/dist/esm/plugin.js +52 -48
  28. package/dist/esm/pm-plugins/decorations/utils/column-resizing.js +2 -2
  29. package/dist/esm/pm-plugins/keymap.js +18 -15
  30. package/dist/esm/pm-plugins/main.js +2 -2
  31. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +2 -2
  32. package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
  33. package/dist/esm/pm-plugins/view-mode-sort/index.js +35 -10
  34. package/dist/esm/utils/decoration.js +28 -8
  35. package/dist/types/commands/column-resize.d.ts +5 -2
  36. package/dist/types/commands/misc.d.ts +3 -2
  37. package/dist/types/event-handlers.d.ts +2 -1
  38. package/dist/types/pm-plugins/decorations/utils/column-resizing.d.ts +2 -1
  39. package/dist/types/pm-plugins/keymap.d.ts +2 -1
  40. package/dist/types/pm-plugins/main.d.ts +1 -1
  41. package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +2 -1
  42. package/dist/types/pm-plugins/table-resizing/plugin.d.ts +2 -1
  43. package/dist/types/pm-plugins/view-mode-sort/index.d.ts +2 -1
  44. package/dist/types/utils/decoration.d.ts +2 -1
  45. package/dist/types-ts4.5/commands/column-resize.d.ts +5 -2
  46. package/dist/types-ts4.5/commands/misc.d.ts +3 -2
  47. package/dist/types-ts4.5/event-handlers.d.ts +2 -1
  48. package/dist/types-ts4.5/pm-plugins/decorations/utils/column-resizing.d.ts +2 -1
  49. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -1
  50. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  51. package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +2 -1
  52. package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +2 -1
  53. package/dist/types-ts4.5/pm-plugins/view-mode-sort/index.d.ts +2 -1
  54. package/dist/types-ts4.5/utils/decoration.d.ts +2 -1
  55. package/package.json +9 -5
  56. package/src/commands/column-resize.ts +18 -1
  57. package/src/commands/misc.ts +5 -0
  58. package/src/event-handlers.ts +22 -20
  59. package/src/plugin.tsx +10 -4
  60. package/src/pm-plugins/decorations/utils/column-resizing.ts +3 -0
  61. package/src/pm-plugins/keymap.ts +5 -0
  62. package/src/pm-plugins/main.ts +2 -1
  63. package/src/pm-plugins/table-resizing/event-handlers.ts +8 -1
  64. package/src/pm-plugins/table-resizing/plugin.ts +3 -0
  65. package/src/pm-plugins/view-mode-sort/index.ts +73 -34
  66. package/src/utils/decoration.ts +39 -13
@@ -2,6 +2,7 @@ import rafSchedule from 'raf-schd';
2
2
 
3
3
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
4
  import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
5
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
5
6
  import {
6
7
  browser,
7
8
  closestElement,
@@ -347,8 +348,8 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
347
348
 
348
349
  // IMPORTANT: The mouse move handler has been setup with RAF schedule to avoid Reflows which will occur as some methods
349
350
  // need to access the mouse event offset position and also the target clientWidth vallue.
350
- const handleMouseMoveDebounce = rafSchedule(
351
- (view: EditorView, event: MouseEvent, offsetX: number) => {
351
+ const handleMouseMoveDebounce = (nodeViewPortalProviderAPI: PortalProviderAPI) =>
352
+ rafSchedule((view: EditorView, event: MouseEvent, offsetX: number) => {
352
353
  if (!(event.target instanceof HTMLElement)) {
353
354
  return false;
354
355
  }
@@ -413,6 +414,7 @@ const handleMouseMoveDebounce = rafSchedule(
413
414
  rowIndexTarget,
414
415
  columnEndIndexTarget,
415
416
  true,
417
+ nodeViewPortalProviderAPI,
416
418
  )(state, dispatch);
417
419
  }
418
420
  }
@@ -420,26 +422,26 @@ const handleMouseMoveDebounce = rafSchedule(
420
422
  }
421
423
 
422
424
  return false;
423
- },
424
- );
425
+ });
425
426
 
426
- export const handleMouseMove = (view: EditorView, event: Event) => {
427
- if (!(event.target instanceof HTMLElement)) {
428
- return false;
429
- }
427
+ export const handleMouseMove =
428
+ (nodeViewPortalProviderAPI: PortalProviderAPI) => (view: EditorView, event: Event) => {
429
+ if (!(event.target instanceof HTMLElement)) {
430
+ return false;
431
+ }
430
432
 
431
- // NOTE: When accessing offsetX in gecko from a deferred callback, it will return 0. However it will be non-zero if accessed
432
- // within the scope of it's initial mouse move handler. Also Chrome does return the correct value, however it could trigger
433
- // a reflow. So for now this will just grab the offsetX value immediately for gecko and chrome will calculate later
434
- // in the deferred callback handler.
435
- // Bug Tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=1882903
436
- handleMouseMoveDebounce(
437
- view,
438
- event as MouseEvent,
439
- browser.gecko ? (event as MouseEvent).offsetX : NaN,
440
- );
441
- return false;
442
- };
433
+ // NOTE: When accessing offsetX in gecko from a deferred callback, it will return 0. However it will be non-zero if accessed
434
+ // within the scope of it's initial mouse move handler. Also Chrome does return the correct value, however it could trigger
435
+ // a reflow. So for now this will just grab the offsetX value immediately for gecko and chrome will calculate later
436
+ // in the deferred callback handler.
437
+ // Bug Tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=1882903
438
+ handleMouseMoveDebounce(nodeViewPortalProviderAPI)(
439
+ view,
440
+ event as MouseEvent,
441
+ browser.gecko ? (event as MouseEvent).offsetX : NaN,
442
+ );
443
+ return false;
444
+ };
443
445
 
444
446
  export function handleTripleClick(view: EditorView, pos: number) {
445
447
  const { state, dispatch } = view;
package/src/plugin.tsx CHANGED
@@ -335,6 +335,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
335
335
  dispatchAnalyticsEvent,
336
336
  dispatch,
337
337
  portalProviderAPI,
338
+ nodeViewPortalProviderAPI,
338
339
  eventDispatcher,
339
340
  getIntl,
340
341
  }) => {
@@ -356,6 +357,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
356
357
  dispatchAnalyticsEvent,
357
358
  dispatch,
358
359
  portalProviderAPI,
360
+ nodeViewPortalProviderAPI,
359
361
  eventDispatcher,
360
362
  pluginConfig(tableOptions),
361
363
  defaultGetEditorContainerWidth,
@@ -377,7 +379,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
377
379
  },
378
380
  {
379
381
  name: 'tablePMColResizing',
380
- plugin: ({ dispatch }) => {
382
+ plugin: ({ dispatch, nodeViewPortalProviderAPI }) => {
381
383
  const {
382
384
  fullWidthEnabled,
383
385
  tableOptions,
@@ -396,6 +398,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
396
398
  defaultGetEditorContainerWidth,
397
399
  getEditorFeatureFlags || defaultGetEditorFeatureFlags,
398
400
  api,
401
+ nodeViewPortalProviderAPI,
399
402
  editorAnalyticsAPI,
400
403
  isTableScalingEnabled || false,
401
404
  isNewColumnResizingEnabled,
@@ -410,7 +413,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
410
413
  // plugin as it is currently swallowing backspace events inside tables
411
414
  {
412
415
  name: 'tableKeymap',
413
- plugin: ({ getIntl }) => {
416
+ plugin: ({ getIntl, nodeViewPortalProviderAPI }) => {
414
417
  const {
415
418
  dragAndDropEnabled,
416
419
  isTableScalingEnabled = false,
@@ -424,6 +427,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
424
427
  return keymapPlugin(
425
428
  defaultGetEditorContainerWidth,
426
429
  api,
430
+ nodeViewPortalProviderAPI,
427
431
  editorAnalyticsAPI,
428
432
  dragAndDropEnabled,
429
433
  isTableScalingEnabled,
@@ -488,8 +492,10 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
488
492
  },
489
493
  {
490
494
  name: 'tableViewModeSort',
491
- plugin: () => {
492
- return api?.editorViewMode ? createViewModeSortPlugin(api) : undefined;
495
+ plugin: ({ nodeViewPortalProviderAPI }) => {
496
+ return api?.editorViewMode
497
+ ? createViewModeSortPlugin(api, nodeViewPortalProviderAPI)
498
+ : undefined;
493
499
  },
494
500
  },
495
501
  {
@@ -1,5 +1,6 @@
1
1
  import type { IntlShape } from 'react-intl-next';
2
2
 
3
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
3
4
  import type { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
5
 
5
6
  import { TableDecorations } from '../../../types';
@@ -36,6 +37,7 @@ export const buildColumnResizingDecorations =
36
37
  columnEndIndex: number,
37
38
  includeTooltip: boolean,
38
39
  getIntl: () => IntlShape,
40
+ nodeViewPortalProviderAPI: PortalProviderAPI,
39
41
  ): DecorationTransformer =>
40
42
  ({ tr, decorationSet }): DecorationSet => {
41
43
  const [columnResizesDecorations, lastCellElementsDecorations] =
@@ -49,6 +51,7 @@ export const buildColumnResizingDecorations =
49
51
  },
50
52
  includeTooltip,
51
53
  getIntl,
54
+ nodeViewPortalProviderAPI,
52
55
  );
53
56
 
54
57
  return composeDecorations([
@@ -30,6 +30,7 @@ import {
30
30
  startColumnResizing,
31
31
  toggleTable,
32
32
  } from '@atlaskit/editor-common/keymaps';
33
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
33
34
  import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
34
35
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
35
36
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
@@ -59,6 +60,7 @@ import type { PluginInjectionAPI, PluginInjectionAPIWithA11y } from '../types';
59
60
  export function keymapPlugin(
60
61
  getEditorContainerWidth: GetEditorContainerWidth,
61
62
  api: PluginInjectionAPI | undefined | null,
63
+ nodeViewPortalProviderAPI: PortalProviderAPI,
62
64
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
63
65
  dragAndDropEnabled?: boolean,
64
66
  isTableScalingEnabled = false,
@@ -263,6 +265,7 @@ export function keymapPlugin(
263
265
  initiateKeyboardColumnResizing({
264
266
  ariaNotify: ariaNotifyPlugin,
265
267
  getIntl: getIntl,
268
+ nodeViewPortalProviderAPI,
266
269
  }),
267
270
  list,
268
271
  );
@@ -273,6 +276,7 @@ export function keymapPlugin(
273
276
  direction: 1,
274
277
  ariaNotify: ariaNotifyPlugin,
275
278
  getIntl: getIntl,
279
+ nodeViewPortalProviderAPI,
276
280
  }),
277
281
  list,
278
282
  );
@@ -283,6 +287,7 @@ export function keymapPlugin(
283
287
  direction: -1,
284
288
  ariaNotify: ariaNotifyPlugin,
285
289
  getIntl: getIntl,
290
+ nodeViewPortalProviderAPI,
286
291
  }),
287
292
  list,
288
293
  );
@@ -79,6 +79,7 @@ export const createPlugin = (
79
79
  dispatchAnalyticsEvent: DispatchAnalyticsEvent,
80
80
  dispatch: Dispatch,
81
81
  portalProviderAPI: PortalProviderAPI,
82
+ nodeViewPortalProviderAPI: PortalProviderAPI,
82
83
  eventDispatcher: EventDispatcher,
83
84
  pluginConfig: PluginConfig,
84
85
  getEditorContainerWidth: GetEditorContainerWidth,
@@ -381,7 +382,7 @@ export const createPlugin = (
381
382
  blur: handleBlur,
382
383
  mousedown: withCellTracking(handleMouseDown),
383
384
  mouseleave: handleMouseLeave,
384
- mousemove: whenTableInFocus(handleMouseMove),
385
+ mousemove: whenTableInFocus(handleMouseMove(nodeViewPortalProviderAPI)),
385
386
  mouseenter: handleMouseEnter,
386
387
  mouseup: whenTableInFocus(handleMouseUp),
387
388
  click: withCellTracking(whenTableInFocus(handleClick)),
@@ -8,6 +8,7 @@ import {
8
8
  TABLE_OVERFLOW_CHANGE_TRIGGER,
9
9
  } from '@atlaskit/editor-common/analytics';
10
10
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
11
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
11
12
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
12
13
  import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
13
14
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -50,6 +51,7 @@ export const handleMouseDown = (
50
51
  getEditorFeatureFlags: GetEditorFeatureFlags,
51
52
  isTableScalingEnabled: boolean,
52
53
  api: PluginInjectionAPI | undefined | null,
54
+ nodeViewPortalProviderAPI: PortalProviderAPI,
53
55
  editorAnalyticsAPI?: EditorAnalyticsAPI,
54
56
  isNewColumnResizingEnabled?: boolean,
55
57
  isTableAlignmentEnabled?: boolean,
@@ -150,7 +152,12 @@ export const handleMouseDown = (
150
152
 
151
153
  // When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
152
154
  // unnecessary tooltips being displayed during drag.
153
- updateResizeHandleDecorations(undefined, undefined, false)(state, dispatch);
155
+ updateResizeHandleDecorations(
156
+ nodeViewPortalProviderAPI,
157
+ undefined,
158
+ undefined,
159
+ false,
160
+ )(state, dispatch);
154
161
 
155
162
  // for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
156
163
  // implication: the scaled version of the table becomes the source of truth
@@ -2,6 +2,7 @@ import classnames from 'classnames';
2
2
 
3
3
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
4
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
5
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
5
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
7
  import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
7
8
 
@@ -21,6 +22,7 @@ export function createPlugin(
21
22
  getEditorContainerWidth: GetEditorContainerWidth,
22
23
  getEditorFeatureFlags: GetEditorFeatureFlags,
23
24
  api: PluginInjectionAPI | undefined | null,
25
+ nodeViewPortalProviderAPI: PortalProviderAPI,
24
26
  editorAnalyticsAPI?: EditorAnalyticsAPI,
25
27
  isTableScalingEnabled?: boolean,
26
28
  isNewColumnResizingEnabled?: boolean,
@@ -76,6 +78,7 @@ export function createPlugin(
76
78
  getEditorFeatureFlags,
77
79
  isTableScalingEnabled || false,
78
80
  api,
81
+ nodeViewPortalProviderAPI,
79
82
  editorAnalyticsAPI,
80
83
  isNewColumnResizingEnabled,
81
84
  isTableAlignmentEnabled,
@@ -8,12 +8,15 @@ import { createElement } from 'react';
8
8
 
9
9
  import ReactDOM from 'react-dom';
10
10
  import { RawIntlProvider } from 'react-intl-next';
11
+ import uuid from 'uuid/v4';
11
12
 
13
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
12
14
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
13
15
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
14
16
  import { SortOrder } from '@atlaskit/editor-common/types';
15
17
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
16
18
  import { TableMap } from '@atlaskit/editor-tables/table-map';
19
+ import { fg } from '@atlaskit/platform-feature-flags';
17
20
 
18
21
  import type tablePlugin from '../../plugin';
19
22
  import { SortingIconWrapper } from '../../ui/icons/SortingIconWrapper';
@@ -28,7 +31,10 @@ import { tableViewModeSortPluginKey as key } from './plugin-key';
28
31
  import type { ViewModeSortPluginState } from './types';
29
32
  import { getTableElements, toggleSort } from './utils';
30
33
 
31
- export const createPlugin = (api: ExtractInjectionAPI<typeof tablePlugin>) => {
34
+ export const createPlugin = (
35
+ api: ExtractInjectionAPI<typeof tablePlugin>,
36
+ nodeViewPortalProviderAPI: PortalProviderAPI,
37
+ ) => {
32
38
  return new SafePlugin({
33
39
  state: {
34
40
  init: () => ({
@@ -84,40 +90,73 @@ export const createPlugin = (api: ExtractInjectionAPI<typeof tablePlugin>) => {
84
90
  const map = TableMap.get(tableNode);
85
91
  const hasMergedCells = new Set(map.map).size !== map.map.length;
86
92
  map.mapByRow[0].forEach((cell, index) => {
93
+ const decorationRenderKey = uuid();
87
94
  decs.push(
88
- Decoration.widget(cell + pos + 2, () => {
89
- const element = document.createElement('div');
90
- element.setAttribute(SORT_INDEX_DATA_ATTRIBUTE, `${index}`);
91
- element.classList.add(SORTING_ICON_CLASS_NAME);
92
- if (hasMergedCells) {
93
- element.classList.add(IS_DISABLED_CLASS_NAME);
94
- }
95
-
96
- let sortOrdered;
97
- if (index === sort[tableId]?.index) {
98
- sortOrdered = sort[tableId]?.direction;
99
- } else {
100
- sortOrdered = SortOrder.NO_ORDER;
101
- }
102
-
103
- const { getIntl } = getPluginState(oldState);
104
-
105
- ReactDOM.render(
106
- createElement(
107
- RawIntlProvider,
108
- { value: getIntl() },
109
- createElement(SortingIconWrapper, {
110
- isSortingAllowed: !hasMergedCells,
111
- sortOrdered,
112
- onClick: () => {},
113
- onKeyDown: () => {},
114
- api,
115
- }),
116
- ),
117
- element,
118
- );
119
- return element;
120
- }),
95
+ Decoration.widget(
96
+ cell + pos + 2,
97
+ () => {
98
+ const element = document.createElement('div');
99
+ element.setAttribute(SORT_INDEX_DATA_ATTRIBUTE, `${index}`);
100
+ element.classList.add(SORTING_ICON_CLASS_NAME);
101
+ if (hasMergedCells) {
102
+ element.classList.add(IS_DISABLED_CLASS_NAME);
103
+ }
104
+
105
+ let sortOrdered;
106
+ if (index === sort[tableId]?.index) {
107
+ sortOrdered = sort[tableId]?.direction;
108
+ } else {
109
+ sortOrdered = SortOrder.NO_ORDER;
110
+ }
111
+
112
+ const { getIntl } = getPluginState(oldState);
113
+
114
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
115
+ nodeViewPortalProviderAPI.render(
116
+ () =>
117
+ createElement(
118
+ RawIntlProvider,
119
+ { value: getIntl() },
120
+ createElement(SortingIconWrapper, {
121
+ isSortingAllowed: !hasMergedCells,
122
+ sortOrdered,
123
+ onClick: () => {},
124
+ onKeyDown: () => {},
125
+ api,
126
+ }),
127
+ ),
128
+ element,
129
+ decorationRenderKey,
130
+ );
131
+ } else {
132
+ ReactDOM.render(
133
+ createElement(
134
+ RawIntlProvider,
135
+ { value: getIntl() },
136
+ createElement(SortingIconWrapper, {
137
+ isSortingAllowed: !hasMergedCells,
138
+ sortOrdered,
139
+ onClick: () => {},
140
+ onKeyDown: () => {},
141
+ api,
142
+ }),
143
+ ),
144
+ element,
145
+ );
146
+ }
147
+
148
+ return element;
149
+ },
150
+ {
151
+ destroy: (node) => {
152
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
153
+ nodeViewPortalProviderAPI.remove(decorationRenderKey);
154
+ } else {
155
+ ReactDOM.unmountComponentAtNode(node as HTMLDivElement);
156
+ }
157
+ },
158
+ },
159
+ ),
121
160
  );
122
161
  });
123
162
  });
@@ -3,8 +3,10 @@ import { createElement } from 'react';
3
3
  import ReactDOM from 'react-dom';
4
4
  import { RawIntlProvider } from 'react-intl-next';
5
5
  import type { IntlShape } from 'react-intl-next';
6
+ import uuid from 'uuid/v4';
6
7
 
7
8
  import type { CellAttributes } from '@atlaskit/adf-schema';
9
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
8
10
  import { nonNullable } from '@atlaskit/editor-common/utils';
9
11
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
10
12
  // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
@@ -18,6 +20,7 @@ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
18
20
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
19
21
  import { TableMap } from '@atlaskit/editor-tables/table-map';
20
22
  import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
23
+ import { fg } from '@atlaskit/platform-feature-flags';
21
24
 
22
25
  import type { Cell, CellColumnPositioning } from '../types';
23
26
  import { TableCssClassName as ClassName, TableDecorations } from '../types';
@@ -308,6 +311,7 @@ export const createResizeHandleDecoration = (
308
311
  columnEndIndexTarget: Omit<CellColumnPositioning, 'left'>,
309
312
  includeTooltip: boolean = false,
310
313
  getIntl: () => IntlShape,
314
+ nodeViewPortalProviderAPI: PortalProviderAPI,
311
315
  ): [Decoration[], Decoration[]] => {
312
316
  const emptyResult: [Decoration[], Decoration[]] = [[], []];
313
317
  const table = findTable(tr.selection);
@@ -327,23 +331,41 @@ export const createResizeHandleDecoration = (
327
331
  cellPos: number,
328
332
  cellNode: PmNode,
329
333
  ): Decoration => {
334
+ const decorationRenderKey = uuid();
330
335
  const position = cellPos + cellNode.nodeSize - 1;
331
336
  return Decoration.widget(
332
337
  position,
333
338
  () => {
334
339
  const element = document.createElement('div');
335
- ReactDOM.render(
336
- createElement(
337
- RawIntlProvider,
338
- { value: getIntl() },
339
- createElement(ColumnResizeWidget, {
340
- startIndex: cellColumnPositioning.left,
341
- endIndex: cellColumnPositioning.right,
342
- includeTooltip,
343
- }),
344
- ),
345
- element,
346
- );
340
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
341
+ nodeViewPortalProviderAPI.render(
342
+ () =>
343
+ createElement(
344
+ RawIntlProvider,
345
+ { value: getIntl() },
346
+ createElement(ColumnResizeWidget, {
347
+ startIndex: cellColumnPositioning.left,
348
+ endIndex: cellColumnPositioning.right,
349
+ includeTooltip,
350
+ }),
351
+ ),
352
+ element,
353
+ decorationRenderKey,
354
+ );
355
+ } else {
356
+ ReactDOM.render(
357
+ createElement(
358
+ RawIntlProvider,
359
+ { value: getIntl() },
360
+ createElement(ColumnResizeWidget, {
361
+ startIndex: cellColumnPositioning.left,
362
+ endIndex: cellColumnPositioning.right,
363
+ includeTooltip,
364
+ }),
365
+ ),
366
+ element,
367
+ );
368
+ }
347
369
  return element;
348
370
  },
349
371
  {
@@ -351,7 +373,11 @@ export const createResizeHandleDecoration = (
351
373
  TableDecorations.COLUMN_RESIZING_HANDLE_WIDGET
352
374
  }_${rowIndex}_${columnIndex}_${includeTooltip ? 'with' : 'no'}-tooltip`,
353
375
  destroy: (node) => {
354
- ReactDOM.unmountComponentAtNode(node as HTMLDivElement);
376
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
377
+ nodeViewPortalProviderAPI.remove(decorationRenderKey);
378
+ } else {
379
+ ReactDOM.unmountComponentAtNode(node as HTMLDivElement);
380
+ }
355
381
  },
356
382
  },
357
383
  );