@atlaskit/editor-plugin-table 7.30.2 → 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 (83) hide show
  1. package/CHANGELOG.md +25 -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 +94 -53
  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/FloatingContextualButton/FixedButton.js +1 -1
  13. package/dist/cjs/ui/common-styles.js +8 -18
  14. package/dist/cjs/utils/decoration.js +28 -8
  15. package/dist/es2019/commands/column-resize.js +10 -8
  16. package/dist/es2019/commands/misc.js +4 -4
  17. package/dist/es2019/event-handlers.js +4 -4
  18. package/dist/es2019/plugin.js +53 -9
  19. package/dist/es2019/pm-plugins/decorations/utils/column-resizing.js +2 -2
  20. package/dist/es2019/pm-plugins/keymap.js +7 -4
  21. package/dist/es2019/pm-plugins/main.js +2 -2
  22. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +2 -2
  23. package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
  24. package/dist/es2019/pm-plugins/view-mode-sort/index.js +33 -10
  25. package/dist/es2019/ui/FloatingContextualButton/FixedButton.js +1 -1
  26. package/dist/es2019/ui/common-styles.js +0 -15
  27. package/dist/es2019/utils/decoration.js +26 -9
  28. package/dist/esm/commands/column-resize.js +10 -8
  29. package/dist/esm/commands/misc.js +4 -4
  30. package/dist/esm/event-handlers.js +69 -65
  31. package/dist/esm/plugin.js +91 -50
  32. package/dist/esm/pm-plugins/decorations/utils/column-resizing.js +2 -2
  33. package/dist/esm/pm-plugins/keymap.js +18 -15
  34. package/dist/esm/pm-plugins/main.js +2 -2
  35. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +2 -2
  36. package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
  37. package/dist/esm/pm-plugins/view-mode-sort/index.js +35 -10
  38. package/dist/esm/ui/FloatingContextualButton/FixedButton.js +1 -1
  39. package/dist/esm/ui/common-styles.js +8 -18
  40. package/dist/esm/utils/decoration.js +28 -8
  41. package/dist/types/commands/column-resize.d.ts +5 -2
  42. package/dist/types/commands/misc.d.ts +3 -2
  43. package/dist/types/commands/toggle.d.ts +1 -1
  44. package/dist/types/commands-with-analytics.d.ts +2 -2
  45. package/dist/types/event-handlers.d.ts +2 -1
  46. package/dist/types/pm-plugins/decorations/utils/column-resizing.d.ts +2 -1
  47. package/dist/types/pm-plugins/keymap.d.ts +2 -1
  48. package/dist/types/pm-plugins/main.d.ts +1 -1
  49. package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +2 -1
  50. package/dist/types/pm-plugins/table-resizing/plugin.d.ts +2 -1
  51. package/dist/types/pm-plugins/view-mode-sort/index.d.ts +2 -1
  52. package/dist/types/toDOM.d.ts +1 -1
  53. package/dist/types/utils/decoration.d.ts +2 -1
  54. package/dist/types-ts4.5/commands/column-resize.d.ts +5 -2
  55. package/dist/types-ts4.5/commands/misc.d.ts +3 -2
  56. package/dist/types-ts4.5/commands/toggle.d.ts +1 -1
  57. package/dist/types-ts4.5/commands-with-analytics.d.ts +2 -2
  58. package/dist/types-ts4.5/event-handlers.d.ts +2 -1
  59. package/dist/types-ts4.5/pm-plugins/decorations/utils/column-resizing.d.ts +2 -1
  60. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -1
  61. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  62. package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +2 -1
  63. package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +2 -1
  64. package/dist/types-ts4.5/pm-plugins/view-mode-sort/index.d.ts +2 -1
  65. package/dist/types-ts4.5/toDOM.d.ts +1 -1
  66. package/dist/types-ts4.5/utils/decoration.d.ts +2 -1
  67. package/package.json +11 -7
  68. package/src/commands/column-resize.ts +18 -1
  69. package/src/commands/misc.ts +5 -0
  70. package/src/commands-with-analytics.ts +2 -2
  71. package/src/event-handlers.ts +22 -20
  72. package/src/plugin.tsx +63 -6
  73. package/src/pm-plugins/decorations/utils/column-resizing.ts +3 -0
  74. package/src/pm-plugins/keymap.ts +5 -0
  75. package/src/pm-plugins/main.ts +2 -1
  76. package/src/pm-plugins/table-resizing/event-handlers.ts +8 -1
  77. package/src/pm-plugins/table-resizing/plugin.ts +3 -0
  78. package/src/pm-plugins/view-mode-sort/index.ts +73 -34
  79. package/src/toDOM.ts +1 -1
  80. package/src/toolbar.tsx +1 -1
  81. package/src/ui/FloatingContextualButton/FixedButton.tsx +1 -1
  82. package/src/ui/common-styles.ts +0 -17
  83. package/src/utils/decoration.ts +39 -13
@@ -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
  });
package/src/toDOM.ts CHANGED
@@ -2,7 +2,7 @@ import kebabCase from 'lodash/kebabCase';
2
2
 
3
3
  import { table, tableWithNestedTable } from '@atlaskit/adf-schema';
4
4
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
5
- import type { GetEditorContainerWidth } from '@atlaskit/editor-common/src/types';
5
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
6
6
  import type { DOMOutputSpec, NodeSpec, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
7
7
  import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
package/src/toolbar.tsx CHANGED
@@ -11,7 +11,7 @@ import { CHANGE_ALIGNMENT_REASON, INPUT_METHOD } from '@atlaskit/editor-common/a
11
11
  import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
12
12
  import commonMessages, { tableMessages as messages } from '@atlaskit/editor-common/messages';
13
13
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
14
- import type { typeOption } from '@atlaskit/editor-common/src/types/floating-toolbar';
14
+ import type { typeOption } from '@atlaskit/editor-common/types';
15
15
  import type {
16
16
  Command,
17
17
  CommandDispatch,
@@ -137,7 +137,7 @@ export const FixedButton = ({
137
137
  return 0;
138
138
  }
139
139
 
140
- const container = targetCellRef.closest('[data-testid="ak-editor-fp-content-area"]');
140
+ const container = targetCellRef.closest('[data-editor-container="true"]');
141
141
  return container?.getBoundingClientRect().left || 0;
142
142
  }, [targetCellRef]);
143
143
 
@@ -21,7 +21,6 @@ import {
21
21
  SelectionStyle,
22
22
  } from '@atlaskit/editor-shared-styles';
23
23
  import { scrollbarStyles } from '@atlaskit/editor-shared-styles/scrollbar';
24
- import { fg } from '@atlaskit/platform-feature-flags';
25
24
  import { N0, N40A, R500 } from '@atlaskit/theme/colors';
26
25
  import { fontSize } from '@atlaskit/theme/constants';
27
26
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -193,19 +192,6 @@ const breakoutWidthStyling = () => {
193
192
  `;
194
193
  };
195
194
 
196
- const stickyHeaderMarginTop = () => {
197
- // Exceptional case: can't add this FF to package.json as a new ratcheting rule was added to prevent new LD flags.
198
- // This LD flag existed in other packages before the rule was introduced.
199
- // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration
200
- if (!fg('platform.confluence.frontend.narrow-full-page-editor-toolbar')) {
201
- return css`
202
- margin-top: 2px;
203
- `;
204
- }
205
-
206
- return css``;
207
- };
208
-
209
195
  const viewModeSortStyles = () => {
210
196
  return css`
211
197
  th {
@@ -402,9 +388,6 @@ export const baseTableStyles = (props: { featureFlags?: FeatureFlags }) => css`
402
388
  /* background for where controls apply */
403
389
  background: ${token('elevation.surface', 'white')};
404
390
  box-sizing: content-box;
405
-
406
- ${stickyHeaderMarginTop()}
407
-
408
391
  box-shadow: 0 6px 4px -4px ${token('elevation.shadow.overflow.perimeter', N40A)};
409
392
  margin-left: -1px;
410
393
 
@@ -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
  );