@atlaskit/editor-plugin-table 7.19.0 → 7.19.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 (48) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +7 -2
  3. package/dist/cjs/nodeviews/TableResizer.js +1 -4
  4. package/dist/cjs/plugin.js +3 -2
  5. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +38 -4
  6. package/dist/cjs/pm-plugins/table-resizing/plugin.js +2 -2
  7. package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +2 -1
  8. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +10 -2
  9. package/dist/cjs/toolbar.js +4 -1
  10. package/dist/cjs/utils/alignment.js +9 -1
  11. package/dist/es2019/nodeviews/TableComponent.js +7 -3
  12. package/dist/es2019/nodeviews/TableResizer.js +2 -5
  13. package/dist/es2019/plugin.js +3 -2
  14. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -5
  15. package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
  16. package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +1 -0
  17. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +10 -4
  18. package/dist/es2019/toolbar.js +4 -1
  19. package/dist/es2019/utils/alignment.js +7 -1
  20. package/dist/esm/nodeviews/TableComponent.js +7 -2
  21. package/dist/esm/nodeviews/TableResizer.js +2 -5
  22. package/dist/esm/plugin.js +3 -2
  23. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +38 -5
  24. package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
  25. package/dist/esm/pm-plugins/table-resizing/utils/consts.js +1 -0
  26. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +11 -3
  27. package/dist/esm/toolbar.js +4 -1
  28. package/dist/esm/utils/alignment.js +8 -0
  29. package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
  30. package/dist/types/pm-plugins/table-resizing/plugin.d.ts +1 -1
  31. package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  32. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  33. package/dist/types/utils/alignment.d.ts +5 -0
  34. package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
  35. package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +1 -1
  36. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  37. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  38. package/dist/types-ts4.5/utils/alignment.d.ts +5 -0
  39. package/package.json +2 -2
  40. package/src/nodeviews/TableComponent.tsx +18 -7
  41. package/src/nodeviews/TableResizer.tsx +7 -8
  42. package/src/plugin.tsx +2 -0
  43. package/src/pm-plugins/table-resizing/event-handlers.ts +47 -1
  44. package/src/pm-plugins/table-resizing/plugin.ts +2 -0
  45. package/src/pm-plugins/table-resizing/utils/consts.ts +1 -0
  46. package/src/pm-plugins/table-resizing/utils/resize-column.ts +25 -3
  47. package/src/toolbar.tsx +11 -1
  48. package/src/utils/alignment.ts +18 -0
@@ -1,8 +1,12 @@
1
1
  // Resize a given column by an amount from the current state
2
2
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
3
3
 
4
- import { TableCssClassName as ClassName } from '../../../types';
5
- import { ALIGN_START } from '../../../utils/alignment';
4
+ import { type AlignmentOptions, TableCssClassName as ClassName } from '../../../types';
5
+ import {
6
+ ALIGN_CENTER,
7
+ ALIGN_START,
8
+ shouldChangeAlignmentToCenterResized,
9
+ } from '../../../utils/alignment';
6
10
 
7
11
  import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
8
12
  import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
@@ -56,6 +60,8 @@ export const resizeColumnAndTable = (
56
60
  isTableScalingEnabled = false,
57
61
  originalTableWidth?: number,
58
62
  shouldUseIncreasedScalingPercent = false,
63
+ lineLength?: number,
64
+ isTableAlignmentEnabled = false,
59
65
  ): ResizeState => {
60
66
  // TODO: can we use document state, and apply scaling factor?
61
67
  const tableWidth = tableRef.clientWidth;
@@ -93,7 +99,17 @@ export const resizeColumnAndTable = (
93
99
  const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
94
100
 
95
101
  if (!isOverflowed) {
96
- updateTablePreview(delta, tableRef, tableNode);
102
+ // If the table is aligned to the start and the table width is greater than the line length, we should change the alignment to center
103
+ const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(
104
+ isTableAlignmentEnabled,
105
+ tableNode,
106
+ lineLength,
107
+ newState.tableWidth + delta,
108
+ );
109
+
110
+ shouldChangeAlignment
111
+ ? updateTablePreview(delta, tableRef, tableNode, ALIGN_CENTER)
112
+ : updateTablePreview(delta, tableRef, tableNode);
97
113
  }
98
114
 
99
115
  return {
@@ -107,10 +123,12 @@ const updateTablePreview = (
107
123
  resizeAmount: number,
108
124
  tableRef: HTMLElement | null,
109
125
  tableNode: PmNode,
126
+ tableAligment?: AlignmentOptions,
110
127
  ) => {
111
128
  const currentWidth = getTableContainerElementWidth(tableNode);
112
129
  const resizingContainer = tableRef?.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
113
130
  const resizingItem = resizingContainer?.querySelector('.resizer-item');
131
+ const alignmentContainer = resizingContainer?.parentElement;
114
132
 
115
133
  if (resizingItem) {
116
134
  const newWidth = `${currentWidth + resizeAmount}px`;
@@ -119,5 +137,9 @@ const updateTablePreview = (
119
137
  }
120
138
  (resizingContainer as HTMLElement).style.width = newWidth;
121
139
  (resizingItem as HTMLElement).style.width = newWidth;
140
+
141
+ if (tableAligment && alignmentContainer) {
142
+ alignmentContainer.style.justifyContent = tableAligment;
143
+ }
122
144
  }
123
145
  };
package/src/toolbar.tsx CHANGED
@@ -468,7 +468,17 @@ export const getToolbarConfig =
468
468
  // We don't want to show floating toolbar while resizing the table
469
469
  const isWidthResizing = tableWidthState?.resizing;
470
470
 
471
- if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
471
+ // Hide floating toolbar when resizing column and internal column width is on
472
+ const shouldHideToolbarForInternalColumnWidth = Boolean(
473
+ options?.isNewColumnResizingEnabled && resizeState && resizeState.dragging,
474
+ );
475
+
476
+ if (
477
+ tableObject &&
478
+ pluginState.editorHasFocus &&
479
+ !isWidthResizing &&
480
+ !shouldHideToolbarForInternalColumnWidth
481
+ ) {
472
482
  const nodeType = state.schema.nodes.table;
473
483
  const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
474
484
  const isTableScalingWithFixedColumnWidthsOptionShown =
@@ -1,5 +1,7 @@
1
1
  import type { TableLayout } from '@atlaskit/adf-schema';
2
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
3
 
4
+ import { FULL_WIDTH_EDITOR_CONTENT_WIDTH } from '../pm-plugins/table-resizing/utils/consts';
3
5
  import type { AlignmentOptions } from '../types';
4
6
 
5
7
  export const ALIGN_START = 'align-start';
@@ -11,3 +13,19 @@ export const ALIGN_CENTER = 'center';
11
13
  */
12
14
  export const normaliseAlignment = (layout: TableLayout): AlignmentOptions =>
13
15
  layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
16
+
17
+ /**
18
+ * We don't want to switch alignment in Full-width editor
19
+ */
20
+ export const shouldChangeAlignmentToCenterResized = (
21
+ isTableAlignmentEnabled: boolean | undefined,
22
+ tableNode: PmNode,
23
+ lineLength: number | undefined,
24
+ updatedTableWidth: number,
25
+ ) =>
26
+ isTableAlignmentEnabled &&
27
+ tableNode &&
28
+ tableNode.attrs.layout === ALIGN_START &&
29
+ lineLength &&
30
+ updatedTableWidth > lineLength &&
31
+ lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH;