@atlaskit/editor-plugin-table 2.10.8 → 2.11.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 (86) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/plugins/table/commands/misc.js +58 -5
  3. package/dist/cjs/plugins/table/event-handlers.js +3 -6
  4. package/dist/cjs/plugins/table/index.js +3 -2
  5. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +13 -19
  6. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-resizing.js +18 -5
  7. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/index.js +6 -0
  8. package/dist/cjs/plugins/table/pm-plugins/main.js +7 -3
  9. package/dist/cjs/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -0
  10. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +2 -0
  11. package/dist/cjs/plugins/table/reducer.js +26 -2
  12. package/dist/cjs/plugins/table/types.js +1 -0
  13. package/dist/cjs/plugins/table/ui/ColumnResizeWidget/index.js +44 -0
  14. package/dist/cjs/plugins/table/ui/messages.js +5 -0
  15. package/dist/cjs/plugins/table/utils/decoration.js +17 -4
  16. package/dist/es2019/plugins/table/commands/misc.js +49 -5
  17. package/dist/es2019/plugins/table/event-handlers.js +3 -6
  18. package/dist/es2019/plugins/table/index.js +3 -2
  19. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +14 -17
  20. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-resizing.js +12 -2
  21. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/index.js +1 -1
  22. package/dist/es2019/plugins/table/pm-plugins/main.js +6 -3
  23. package/dist/es2019/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -0
  24. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +2 -0
  25. package/dist/es2019/plugins/table/reducer.js +29 -2
  26. package/dist/es2019/plugins/table/types.js +1 -0
  27. package/dist/es2019/plugins/table/ui/ColumnResizeWidget/index.js +35 -0
  28. package/dist/es2019/plugins/table/ui/messages.js +5 -0
  29. package/dist/es2019/plugins/table/utils/decoration.js +16 -5
  30. package/dist/esm/plugins/table/commands/misc.js +56 -5
  31. package/dist/esm/plugins/table/event-handlers.js +3 -6
  32. package/dist/esm/plugins/table/index.js +3 -2
  33. package/dist/esm/plugins/table/nodeviews/TableResizer.js +13 -19
  34. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-resizing.js +15 -3
  35. package/dist/esm/plugins/table/pm-plugins/decorations/utils/index.js +1 -1
  36. package/dist/esm/plugins/table/pm-plugins/main.js +8 -4
  37. package/dist/esm/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -0
  38. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +2 -0
  39. package/dist/esm/plugins/table/reducer.js +26 -2
  40. package/dist/esm/plugins/table/types.js +1 -0
  41. package/dist/esm/plugins/table/ui/ColumnResizeWidget/index.js +35 -0
  42. package/dist/esm/plugins/table/ui/messages.js +5 -0
  43. package/dist/esm/plugins/table/utils/decoration.js +17 -4
  44. package/dist/types/plugins/table/commands/misc.d.ts +8 -6
  45. package/dist/types/plugins/table/event-handlers.d.ts +3 -3
  46. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +4 -2
  47. package/dist/types/plugins/table/pm-plugins/decorations/utils/index.d.ts +1 -1
  48. package/dist/types/plugins/table/pm-plugins/main.d.ts +2 -1
  49. package/dist/types/plugins/table/pm-plugins/table-resizing/plugin.d.ts +2 -2
  50. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -3
  51. package/dist/types/plugins/table/reducer.d.ts +1 -1
  52. package/dist/types/plugins/table/types.d.ts +18 -0
  53. package/dist/types/plugins/table/ui/ColumnResizeWidget/index.d.ts +9 -0
  54. package/dist/types/plugins/table/ui/messages.d.ts +5 -0
  55. package/dist/types/plugins/table/utils/decoration.d.ts +2 -1
  56. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +8 -6
  57. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +3 -3
  58. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +4 -2
  59. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/index.d.ts +1 -1
  60. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +2 -1
  61. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/plugin.d.ts +2 -2
  62. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -3
  63. package/dist/types-ts4.5/plugins/table/reducer.d.ts +1 -1
  64. package/dist/types-ts4.5/plugins/table/types.d.ts +18 -0
  65. package/dist/types-ts4.5/plugins/table/ui/ColumnResizeWidget/index.d.ts +9 -0
  66. package/dist/types-ts4.5/plugins/table/ui/messages.d.ts +5 -0
  67. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -1
  68. package/package.json +2 -2
  69. package/src/__tests__/unit/event-handlers.ts +1 -1
  70. package/src/__tests__/unit/nodeviews/TableContainer.tsx +17 -8
  71. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +2 -0
  72. package/src/plugins/table/commands/misc.ts +84 -7
  73. package/src/plugins/table/event-handlers.ts +11 -16
  74. package/src/plugins/table/index.tsx +2 -0
  75. package/src/plugins/table/nodeviews/TableResizer.tsx +12 -20
  76. package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +34 -7
  77. package/src/plugins/table/pm-plugins/decorations/utils/index.ts +4 -1
  78. package/src/plugins/table/pm-plugins/main.ts +7 -1
  79. package/src/plugins/table/pm-plugins/table-resizing/event-handlers.ts +5 -0
  80. package/src/plugins/table/pm-plugins/table-resizing/plugin.ts +3 -5
  81. package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +5 -3
  82. package/src/plugins/table/reducer.ts +51 -3
  83. package/src/plugins/table/types.ts +19 -0
  84. package/src/plugins/table/ui/ColumnResizeWidget/index.tsx +53 -0
  85. package/src/plugins/table/ui/messages.ts +5 -0
  86. package/src/plugins/table/utils/decoration.ts +27 -5
@@ -1,20 +1,21 @@
1
1
  // #region Imports
2
- import { CellAttributes } from '@atlaskit/adf-schema';
3
- import { Command } from '@atlaskit/editor-common/types';
2
+ import type { CellAttributes } from '@atlaskit/adf-schema';
3
+ import type { Command } from '@atlaskit/editor-common/types';
4
4
  import {
5
5
  closestElement,
6
6
  isParagraph,
7
7
  isTextSelection,
8
8
  mapSlice,
9
9
  } from '@atlaskit/editor-common/utils';
10
- import {
10
+ import type {
11
11
  Node as PMNode,
12
12
  Schema,
13
13
  Slice,
14
14
  } from '@atlaskit/editor-prosemirror/model';
15
- import { TextSelection, Transaction } from '@atlaskit/editor-prosemirror/state';
16
- import { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
17
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
15
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
16
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
17
+ import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
18
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
18
19
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
19
20
  import { TableMap } from '@atlaskit/editor-tables/table-map';
20
21
  import {
@@ -33,7 +34,10 @@ import {
33
34
  } from '@atlaskit/editor-tables/utils';
34
35
 
35
36
  import { getDecorations } from '../pm-plugins/decorations/plugin';
36
- import { buildColumnResizingDecorations } from '../pm-plugins/decorations/utils';
37
+ import {
38
+ buildColumnResizingDecorations,
39
+ clearColumnResizingDecorations,
40
+ } from '../pm-plugins/decorations/utils';
37
41
  import { createCommand, getPluginState } from '../pm-plugins/plugin-factory';
38
42
  import { fixAutoSizedTable } from '../transforms';
39
43
  import { TableCssClassName as ClassName, TableDecorations } from '../types';
@@ -436,12 +440,14 @@ export const hideInsertColumnOrRowButton = () =>
436
440
  export const addResizeHandleDecorations = (
437
441
  rowIndex: number,
438
442
  columnIndex: number,
443
+ includeTooltip: boolean,
439
444
  ) =>
440
445
  createCommand(
441
446
  (state) => {
442
447
  const tableNode = findTable(state.selection);
443
448
  const {
444
449
  pluginConfig: { allowColumnResizing },
450
+ getIntl,
445
451
  } = getPluginState(state);
446
452
 
447
453
  if (!tableNode || !allowColumnResizing) {
@@ -454,18 +460,89 @@ export const addResizeHandleDecorations = (
454
460
  decorationSet: buildColumnResizingDecorations(
455
461
  rowIndex,
456
462
  columnIndex,
463
+ includeTooltip,
464
+ getIntl,
465
+ )({
466
+ tr: state.tr,
467
+ decorationSet: getDecorations(state),
468
+ }),
469
+ resizeHandleRowIndex: rowIndex,
470
+ resizeHandleColumnIndex: columnIndex,
471
+ resizeHandleIncludeTooltip: includeTooltip,
472
+ },
473
+ };
474
+ },
475
+ (tr: Transaction) => tr.setMeta('addToHistory', false),
476
+ );
477
+
478
+ export const updateResizeHandleDecorations = (
479
+ rowIndex?: number,
480
+ columnIndex?: number,
481
+ includeTooltip?: boolean,
482
+ ) =>
483
+ createCommand(
484
+ (state) => {
485
+ const tableNode = findTable(state.selection);
486
+ const {
487
+ resizeHandleRowIndex,
488
+ resizeHandleColumnIndex,
489
+ resizeHandleIncludeTooltip,
490
+ pluginConfig: { allowColumnResizing },
491
+ getIntl,
492
+ } = getPluginState(state);
493
+
494
+ if (!tableNode || !allowColumnResizing) {
495
+ return false;
496
+ }
497
+
498
+ const resolvedRowIndex = rowIndex ?? resizeHandleRowIndex;
499
+ const resolvedColumnIndex = columnIndex ?? resizeHandleColumnIndex;
500
+ const resolvedIncludeTooltip =
501
+ includeTooltip ?? resizeHandleIncludeTooltip;
502
+
503
+ if (
504
+ resolvedRowIndex === undefined ||
505
+ resolvedColumnIndex === undefined ||
506
+ resolvedIncludeTooltip === undefined
507
+ ) {
508
+ return false;
509
+ }
510
+
511
+ return {
512
+ type: 'UPDATE_RESIZE_HANDLE_DECORATIONS',
513
+ data: {
514
+ decorationSet: buildColumnResizingDecorations(
515
+ resolvedRowIndex,
516
+ resolvedColumnIndex,
517
+ resolvedIncludeTooltip,
518
+ getIntl,
457
519
  )({
458
520
  tr: state.tr,
459
521
  decorationSet: getDecorations(state),
460
522
  }),
461
523
  resizeHandleRowIndex: rowIndex,
462
524
  resizeHandleColumnIndex: columnIndex,
525
+ resizeHandleIncludeTooltip: includeTooltip,
463
526
  },
464
527
  };
465
528
  },
466
529
  (tr: Transaction) => tr.setMeta('addToHistory', false),
467
530
  );
468
531
 
532
+ export const removeResizeHandleDecorations = () =>
533
+ createCommand(
534
+ (state) => ({
535
+ type: 'REMOVE_RESIZE_HANDLE_DECORATIONS',
536
+ data: {
537
+ decorationSet: clearColumnResizingDecorations()({
538
+ tr: state.tr,
539
+ decorationSet: getDecorations(state),
540
+ }),
541
+ },
542
+ }),
543
+ (tr) => tr.setMeta('addToHistory', false),
544
+ );
545
+
469
546
  export const autoSizeTable = (
470
547
  view: EditorView,
471
548
  node: PMNode,
@@ -11,14 +11,13 @@ import {
11
11
  isLastItemMediaGroup,
12
12
  setNodeSelection,
13
13
  } from '@atlaskit/editor-common/utils';
14
- import { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
15
- import {
14
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
15
+ import type {
16
16
  EditorState,
17
- Selection,
18
- TextSelection,
19
17
  Transaction,
20
18
  } from '@atlaskit/editor-prosemirror/state';
21
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
19
+ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
20
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
22
21
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
23
22
  import { TableMap } from '@atlaskit/editor-tables/table-map';
24
23
  import {
@@ -44,10 +43,8 @@ import {
44
43
  import { getPluginState } from './pm-plugins/plugin-factory';
45
44
  import { getPluginState as getResizePluginState } from './pm-plugins/table-resizing/plugin-factory';
46
45
  import { deleteColumns, deleteRows } from './transforms';
47
- import {
48
- ElementContentRects,
49
- RESIZE_HANDLE_AREA_DECORATION_GAP,
50
- } from './types';
46
+ import type { ElementContentRects } from './types';
47
+ import { RESIZE_HANDLE_AREA_DECORATION_GAP } from './types';
51
48
  import {
52
49
  getColumnOrRowIndex,
53
50
  getMousePositionHorizontalRelativeByElement,
@@ -375,6 +372,7 @@ export const handleMouseMove = (
375
372
  return addResizeHandleDecorations(
376
373
  rowIndexTarget,
377
374
  columnEndIndexTarget,
375
+ true,
378
376
  )(state, dispatch);
379
377
  }
380
378
  }
@@ -486,13 +484,10 @@ export const whenTableInFocus =
486
484
  elementContentRects?: ElementContentRects,
487
485
  ) =>
488
486
  (view: EditorView, mouseEvent: Event): boolean => {
489
- const tableResizePluginState = getResizePluginState(view.state);
490
- const tablePluginState = getPluginState(view.state);
491
- const isDragging =
492
- tableResizePluginState && !!tableResizePluginState.dragging;
493
- const hasTableNode = tablePluginState && tablePluginState.tableNode;
494
-
495
- if (!hasTableNode || isDragging) {
487
+ if (
488
+ !getPluginState(view.state)?.tableNode ||
489
+ !!getResizePluginState(view.state)?.dragging
490
+ ) {
496
491
  return false;
497
492
  }
498
493
 
@@ -162,6 +162,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
162
162
  dispatch,
163
163
  portalProviderAPI,
164
164
  eventDispatcher,
165
+ getIntl,
165
166
  }) => {
166
167
  const {
167
168
  fullWidthEnabled,
@@ -179,6 +180,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
179
180
  pluginConfig(tableOptions),
180
181
  defaultGetEditorContainerWidth,
181
182
  getEditorFeatureFlags || defaultGetEditorFeatureFlags,
183
+ getIntl,
182
184
  breakoutEnabled,
183
185
  fullWidthEnabled,
184
186
  tableResizingEnabled,
@@ -2,6 +2,7 @@ import type { PropsWithChildren } from 'react';
2
2
  import React, { useCallback, useMemo, useRef, useState } from 'react';
3
3
 
4
4
  import rafSchd from 'raf-schd';
5
+ import { defineMessages, useIntl } from 'react-intl-next';
5
6
 
6
7
  import type { TableEventPayload } from '@atlaskit/editor-common/analytics';
7
8
  import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
@@ -11,7 +12,6 @@ import type {
11
12
  HandleResize,
12
13
  } from '@atlaskit/editor-common/resizer';
13
14
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
14
- import { resizerHandleShadowClassName } from '@atlaskit/editor-common/styles';
15
15
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
16
16
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
17
17
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -53,6 +53,14 @@ interface TableResizerProps {
53
53
  ) => ((tr: Transaction) => boolean) | undefined;
54
54
  }
55
55
 
56
+ const messages = defineMessages({
57
+ resizeTable: {
58
+ id: 'fabric.editor.tables.resizeTable',
59
+ defaultMessage: 'Resize table',
60
+ description: 'Tooltip displayed on custom table width resize hande',
61
+ },
62
+ });
63
+
56
64
  const handles = { right: true };
57
65
  const tableHandleMarginTop = 12;
58
66
  const tableHandlePosition = 14;
@@ -129,6 +137,7 @@ export const TableResizer = ({
129
137
  }: PropsWithChildren<TableResizerProps>) => {
130
138
  const currentGap = useRef(0);
131
139
  const [snappingEnabled, setSnappingEnabled] = useState(false);
140
+ const { formatMessage } = useIntl();
132
141
 
133
142
  const resizerMinWidth = getResizerMinWidth(node);
134
143
  const handleHeightSize = getResizerHandleHeight(tableRef);
@@ -301,24 +310,6 @@ export const TableResizer = ({
301
310
  ],
302
311
  );
303
312
 
304
- const handleComponent = useMemo(
305
- () => ({
306
- left: (
307
- <div
308
- className={resizerHandleShadowClassName}
309
- style={{ height: 'calc(100% - 24px)' }}
310
- />
311
- ),
312
- right: (
313
- <div
314
- className={resizerHandleShadowClassName}
315
- style={{ height: 'calc(100% - 24px)' }}
316
- />
317
- ),
318
- }),
319
- [],
320
- );
321
-
322
313
  return (
323
314
  <ResizerNext
324
315
  enable={handles}
@@ -337,8 +328,9 @@ export const TableResizer = ({
337
328
  handlePositioning="adjacent"
338
329
  innerPadding={tableHandlePosition}
339
330
  isHandleVisible={findTable(editorView.state?.selection)?.pos === getPos()}
340
- handleComponent={handleComponent}
341
331
  appearance={isInDanger ? 'danger' : undefined}
332
+ handleHighlight="shadow"
333
+ handleTooltipContent={formatMessage(messages.resizeTable)}
342
334
  >
343
335
  {children}
344
336
  </ResizerNext>
@@ -1,4 +1,9 @@
1
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
1
+ import type { IntlShape } from 'react-intl-next';
2
+
3
+ import type {
4
+ Decoration,
5
+ DecorationSet,
6
+ } from '@atlaskit/editor-prosemirror/view';
2
7
 
3
8
  import { TableDecorations } from '../../../types';
4
9
  import {
@@ -7,7 +12,7 @@ import {
7
12
  } from '../../../utils/decoration';
8
13
 
9
14
  import { composeDecorations } from './compose-decorations';
10
- import { DecorationTransformer } from './types';
15
+ import type { DecorationTransformer } from './types';
11
16
 
12
17
  const emptyDecorations = [[], []];
13
18
 
@@ -18,7 +23,7 @@ const updateColumnResizeHandle =
18
23
  tr.doc,
19
24
  decorationSet,
20
25
  columnResizesDecorations,
21
- TableDecorations.COLUMN_RESIZING_HANDLE,
26
+ TableDecorations.COLUMN_RESIZING_HANDLE_WIDGET,
22
27
  );
23
28
 
24
29
  const updateLastCellElement =
@@ -32,17 +37,39 @@ const updateLastCellElement =
32
37
  );
33
38
 
34
39
  export const buildColumnResizingDecorations =
35
- (rowEndIndex: number, columnEndIndex: number): DecorationTransformer =>
40
+ (
41
+ rowEndIndex: number,
42
+ columnEndIndex: number,
43
+ includeTooltip: boolean,
44
+ getIntl: () => IntlShape,
45
+ ): DecorationTransformer =>
36
46
  ({ tr, decorationSet }): DecorationSet => {
37
47
  const [columnResizesDecorations, lastCellElementsDecorations] =
38
48
  columnEndIndex < 0
39
49
  ? emptyDecorations
40
- : createResizeHandleDecoration(tr, rowEndIndex, {
41
- right: columnEndIndex,
42
- });
50
+ : createResizeHandleDecoration(
51
+ tr,
52
+ rowEndIndex,
53
+ {
54
+ right: columnEndIndex,
55
+ },
56
+ includeTooltip,
57
+ getIntl,
58
+ );
43
59
 
44
60
  return composeDecorations([
45
61
  updateColumnResizeHandle(columnResizesDecorations),
46
62
  updateLastCellElement(lastCellElementsDecorations),
47
63
  ])({ decorationSet, tr });
48
64
  };
65
+
66
+ export const clearColumnResizingDecorations =
67
+ (): DecorationTransformer =>
68
+ ({ tr, decorationSet }): DecorationSet => {
69
+ const [columnResizesDecorations, lastCellElementsDecorations] =
70
+ emptyDecorations;
71
+ return composeDecorations([
72
+ updateColumnResizeHandle(columnResizesDecorations),
73
+ updateLastCellElement(lastCellElementsDecorations),
74
+ ])({ decorationSet, tr });
75
+ };
@@ -2,5 +2,8 @@ export {
2
2
  buildColumnControlsDecorations,
3
3
  maybeUpdateColumnControlsSelectedDecoration,
4
4
  } from './column-controls';
5
- export { buildColumnResizingDecorations } from './column-resizing';
5
+ export {
6
+ buildColumnResizingDecorations,
7
+ clearColumnResizingDecorations,
8
+ } from './column-resizing';
6
9
  export { composeDecorations } from './compose-decorations';
@@ -1,3 +1,5 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+
1
3
  import {
2
4
  ACTION,
3
5
  ACTION_SUBJECT,
@@ -46,6 +48,7 @@ import {
46
48
  setTableRef,
47
49
  } from '../commands';
48
50
  import {
51
+ removeResizeHandleDecorations,
49
52
  transformSliceRemoveCellBackgroundColor,
50
53
  transformSliceToAddTableHeaders,
51
54
  transformSliceToRemoveColumnsWidths,
@@ -100,6 +103,7 @@ export const createPlugin = (
100
103
  pluginConfig: PluginConfig,
101
104
  getEditorContainerWidth: GetEditorContainerWidth,
102
105
  getEditorFeatureFlags: GetEditorFeatureFlags,
106
+ getIntl: () => IntlShape,
103
107
  breakoutEnabled?: boolean,
104
108
  fullWidthModeEnabled?: boolean,
105
109
  tableResizingEnabled?: boolean,
@@ -120,6 +124,7 @@ export const createPlugin = (
120
124
  isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
121
125
  isHeaderColumnEnabled: false,
122
126
  ...defaultTableSelection,
127
+ getIntl,
123
128
  });
124
129
 
125
130
  let elementContentRects: ElementContentRects = {};
@@ -211,7 +216,6 @@ export const createPlugin = (
211
216
  const pluginState = getPluginState(state);
212
217
  let tableRef: HTMLTableElement | undefined;
213
218
  let tableNode;
214
-
215
219
  if (pluginState.editorHasFocus) {
216
220
  const parent = findParentDomRefOfType(
217
221
  state.schema.nodes.table,
@@ -255,6 +259,8 @@ export const createPlugin = (
255
259
  addBoldInEmptyHeaderCells(tableCellHeader)(state, dispatch);
256
260
  }
257
261
  }
262
+ } else if (pluginState.isResizeHandleWidgetAdded) {
263
+ removeResizeHandleDecorations()(state, dispatch);
258
264
  }
259
265
  },
260
266
  destroy: () => {
@@ -17,6 +17,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
17
17
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
18
18
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
19
19
 
20
+ import { updateResizeHandleDecorations } from '../../commands/misc';
20
21
  import { updateColumnWidths } from '../../transforms';
21
22
  import { getSelectedColumnIndexes, updateResizeHandles } from '../../utils';
22
23
 
@@ -115,6 +116,10 @@ export const handleMouseDown = (
115
116
 
116
117
  setDragging({ startX: event.clientX, startWidth: width })(state, dispatch);
117
118
 
119
+ // When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
120
+ // unnecessary tooltips being displayed during drag.
121
+ updateResizeHandleDecorations(undefined, undefined, false)(state, dispatch);
122
+
118
123
  function finish(event: MouseEvent) {
119
124
  window.removeEventListener('mouseup', finish);
120
125
  window.removeEventListener('mousemove', move);
@@ -1,17 +1,15 @@
1
1
  import classnames from 'classnames';
2
2
 
3
3
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
- import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
4
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import type {
7
7
  GetEditorContainerWidth,
8
8
  GetEditorFeatureFlags,
9
9
  } from '@atlaskit/editor-common/types';
10
10
 
11
- import {
12
- TableCssClassName as ClassName,
13
- ColumnResizingPluginState,
14
- } from '../../types';
11
+ import { TableCssClassName as ClassName } from '../../types';
12
+ import type { ColumnResizingPluginState } from '../../types';
15
13
 
16
14
  import { setResizeHandlePos } from './commands';
17
15
  import { handleMouseDown } from './event-handlers';
@@ -1,7 +1,7 @@
1
1
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
2
2
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
3
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
5
5
  import type { DomAtPos } from '@atlaskit/editor-prosemirror/utils';
6
6
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
7
7
 
@@ -15,9 +15,10 @@ import {
15
15
  getTotalWidth,
16
16
  updateColgroup,
17
17
  } from '../utils/resize-state';
18
- import { ResizeState } from '../utils/types';
18
+ import type { ResizeState } from '../utils/types';
19
19
 
20
20
  import { hasTableBeenResized, insertColgroupFromNode } from './colgroup';
21
+ import { syncStickyRowToTable } from './dom';
21
22
 
22
23
  export interface ScaleOptions {
23
24
  node: PMNode;
@@ -169,6 +170,7 @@ export const previewScaleTable = (
169
170
  }
170
171
 
171
172
  if (!hasTableBeenResized(node)) {
173
+ syncStickyRowToTable(tableRef);
172
174
  return;
173
175
  }
174
176
 
@@ -1,5 +1,5 @@
1
1
  import { defaultTableSelection } from './pm-plugins/default-table-selection';
2
- import { TablePluginAction, TablePluginState } from './types';
2
+ import type { TablePluginAction, TablePluginState } from './types';
3
3
 
4
4
  export default (
5
5
  pluginState: TablePluginState,
@@ -87,11 +87,59 @@ export default (
87
87
  if (
88
88
  action.data.resizeHandleColumnIndex ===
89
89
  pluginState.resizeHandleColumnIndex &&
90
- action.data.resizeHandleRowIndex === pluginState.resizeHandleRowIndex
90
+ action.data.resizeHandleRowIndex === pluginState.resizeHandleRowIndex &&
91
+ action.data.resizeHandleIncludeTooltip ===
92
+ pluginState.resizeHandleIncludeTooltip
91
93
  ) {
92
94
  return pluginState;
93
95
  }
94
- return { ...pluginState, ...action.data };
96
+ return {
97
+ ...pluginState,
98
+ ...action.data,
99
+ isResizeHandleWidgetAdded: true,
100
+ };
101
+
102
+ case 'UPDATE_RESIZE_HANDLE_DECORATIONS':
103
+ const {
104
+ resizeHandleColumnIndex,
105
+ resizeHandleRowIndex,
106
+ resizeHandleIncludeTooltip,
107
+ } = action.data;
108
+
109
+ if (
110
+ (resizeHandleColumnIndex === pluginState.resizeHandleColumnIndex ||
111
+ !Number.isFinite(resizeHandleColumnIndex)) &&
112
+ (resizeHandleRowIndex === pluginState.resizeHandleRowIndex ||
113
+ !Number.isFinite(resizeHandleRowIndex)) &&
114
+ (resizeHandleIncludeTooltip ===
115
+ pluginState.resizeHandleIncludeTooltip ||
116
+ resizeHandleIncludeTooltip === undefined)
117
+ ) {
118
+ return pluginState;
119
+ }
120
+
121
+ return {
122
+ ...pluginState,
123
+ resizeHandleColumnIndex:
124
+ resizeHandleColumnIndex ?? pluginState.resizeHandleColumnIndex,
125
+ resizeHandleRowIndex:
126
+ resizeHandleRowIndex ?? pluginState.resizeHandleRowIndex,
127
+ resizeHandleIncludeTooltip:
128
+ resizeHandleIncludeTooltip ?? pluginState.resizeHandleIncludeTooltip,
129
+ };
130
+
131
+ case 'REMOVE_RESIZE_HANDLE_DECORATIONS':
132
+ if (!pluginState.isResizeHandleWidgetAdded) {
133
+ return pluginState;
134
+ }
135
+
136
+ return {
137
+ ...pluginState,
138
+ ...action.data,
139
+ resizeHandleColumnIndex: undefined,
140
+ resizeHandleRowIndex: undefined,
141
+ isResizeHandleWidgetAdded: false,
142
+ };
95
143
 
96
144
  case 'SET_TABLE_REF':
97
145
  case 'HOVER_ROWS':
@@ -115,11 +115,15 @@ export interface TablePluginState {
115
115
  isFullWidthModeEnabled?: boolean;
116
116
  layout?: TableLayout;
117
117
  ordering?: TableColumnOrdering;
118
+ isResizeHandleWidgetAdded?: boolean;
118
119
  resizeHandleRowIndex?: number;
119
120
  resizeHandleColumnIndex?: number;
121
+ resizeHandleIncludeTooltip?: boolean;
120
122
  // for table wrap/collapse
121
123
  isTableCollapsed?: boolean; // is the current table already in an expand?
122
124
  canCollapseTable?: boolean; // enabled/disabled state of collapse option
125
+
126
+ getIntl: () => IntlShape;
123
127
  }
124
128
 
125
129
  export type TablePluginAction =
@@ -175,8 +179,22 @@ export type TablePluginAction =
175
179
  decorationSet: DecorationSet;
176
180
  resizeHandleRowIndex: number;
177
181
  resizeHandleColumnIndex: number;
182
+ resizeHandleIncludeTooltip: boolean;
183
+ };
184
+ }
185
+ | {
186
+ type: 'UPDATE_RESIZE_HANDLE_DECORATIONS';
187
+ data: {
188
+ decorationSet: DecorationSet;
189
+ resizeHandleRowIndex: number | undefined;
190
+ resizeHandleColumnIndex: number | undefined;
191
+ resizeHandleIncludeTooltip: boolean | undefined;
178
192
  };
179
193
  }
194
+ | {
195
+ type: 'REMOVE_RESIZE_HANDLE_DECORATIONS';
196
+ data: { decorationSet: DecorationSet };
197
+ }
180
198
  | { type: 'CLEAR_HOVER_SELECTION'; data: { decorationSet: DecorationSet } }
181
199
  | { type: 'SHOW_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
182
200
  | { type: 'HIDE_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
@@ -224,6 +242,7 @@ export enum TableDecorations {
224
242
  COLUMN_CONTROLS_DECORATIONS = 'COLUMN_CONTROLS_DECORATIONS',
225
243
  COLUMN_SELECTED = 'COLUMN_SELECTED',
226
244
  COLUMN_RESIZING_HANDLE = 'COLUMN_RESIZING_HANDLE',
245
+ COLUMN_RESIZING_HANDLE_WIDGET = 'COLUMN_RESIZING_HANDLE_WIDGET',
227
246
  COLUMN_RESIZING_HANDLE_LINE = 'COLUMN_RESIZING_HANDLE_LINE',
228
247
 
229
248
  LAST_CELL_ELEMENT = 'LAST_CELL_ELEMENT',
@@ -0,0 +1,53 @@
1
+ /** @jsx jsx */
2
+ import React from 'react';
3
+
4
+ import { jsx } from '@emotion/react';
5
+ import { useIntl } from 'react-intl-next';
6
+
7
+ import Tooltip from '@atlaskit/tooltip';
8
+
9
+ import { TableCssClassName } from '../../types';
10
+ import messages from '../messages';
11
+
12
+ type Props = {
13
+ startIndex: number;
14
+ endIndex: number;
15
+ includeTooltip?: boolean;
16
+ };
17
+
18
+ export const ColumnResizeWidget: React.FC<Props> = ({
19
+ startIndex,
20
+ endIndex,
21
+ includeTooltip,
22
+ }) => {
23
+ const { formatMessage } = useIntl();
24
+
25
+ if (!includeTooltip) {
26
+ return (
27
+ <div
28
+ className={TableCssClassName.RESIZE_HANDLE_DECORATION}
29
+ data-start-index={startIndex}
30
+ data-end-index={endIndex}
31
+ />
32
+ );
33
+ }
34
+
35
+ return (
36
+ <Tooltip
37
+ content={formatMessage(messages.adjustColumns)}
38
+ hideTooltipOnClick
39
+ hideTooltipOnMouseDown
40
+ position="mouse"
41
+ mousePosition="auto-start"
42
+ >
43
+ {(tooltipProps) => (
44
+ <div
45
+ className={TableCssClassName.RESIZE_HANDLE_DECORATION}
46
+ data-start-index={startIndex}
47
+ data-end-index={endIndex}
48
+ {...tooltipProps}
49
+ />
50
+ )}
51
+ </Tooltip>
52
+ );
53
+ };
@@ -60,4 +60,9 @@ export default defineMessages({
60
60
  defaultMessage: 'this element',
61
61
  description: 'The current element without preset name been selected',
62
62
  },
63
+ adjustColumns: {
64
+ id: 'fabric.editor.tables.adjustColumn',
65
+ defaultMessage: 'Adjust column',
66
+ description: 'Tooltip displayed on table column resize handle',
67
+ },
63
68
  });