@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.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/nodeviews/TableComponent.js +7 -2
- package/dist/cjs/nodeviews/TableResizer.js +1 -4
- package/dist/cjs/plugin.js +3 -2
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +38 -4
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +2 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +10 -2
- package/dist/cjs/toolbar.js +4 -1
- package/dist/cjs/utils/alignment.js +9 -1
- package/dist/es2019/nodeviews/TableComponent.js +7 -3
- package/dist/es2019/nodeviews/TableResizer.js +2 -5
- package/dist/es2019/plugin.js +3 -2
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -5
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +1 -0
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +10 -4
- package/dist/es2019/toolbar.js +4 -1
- package/dist/es2019/utils/alignment.js +7 -1
- package/dist/esm/nodeviews/TableComponent.js +7 -2
- package/dist/esm/nodeviews/TableResizer.js +2 -5
- package/dist/esm/plugin.js +3 -2
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +38 -5
- package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/esm/pm-plugins/table-resizing/utils/consts.js +1 -0
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +11 -3
- package/dist/esm/toolbar.js +4 -1
- package/dist/esm/utils/alignment.js +8 -0
- package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/plugin.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
- package/dist/types/utils/alignment.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
- package/dist/types-ts4.5/utils/alignment.d.ts +5 -0
- package/package.json +2 -2
- package/src/nodeviews/TableComponent.tsx +18 -7
- package/src/nodeviews/TableResizer.tsx +7 -8
- package/src/plugin.tsx +2 -0
- package/src/pm-plugins/table-resizing/event-handlers.ts +47 -1
- package/src/pm-plugins/table-resizing/plugin.ts +2 -0
- package/src/pm-plugins/table-resizing/utils/consts.ts +1 -0
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +25 -3
- package/src/toolbar.tsx +11 -1
- 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 {
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
package/src/utils/alignment.ts
CHANGED
|
@@ -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;
|